Added AutoRotateDaemonMonitor which is useful for monitoring the status of a running daemon. rotate-indicator now uses it to refresh its buttons when the daemon is started/stopped.
Added AutoRotateDaemonMonitor which is useful for monitoring the status of a running daemon. rotate-indicator now uses it to refresh its buttons when the daemon is started/stopped.

--- /dev/null
+++ b/librotate/AutoRotateDaemonMonitor.py
@@ -1,1 +1,41 @@
+##
+## AutoRotateDaemonMonitor.py
+## Karol Krizka <kkrizka@gmail.com>
+## Started on  Sun Oct 14 14:28:20 2010 Karol Krizka
+## $Id$
+## 
+## Copyright (C) 2008 Karol Krizka
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+## 
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+## 
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
 
+import xrandr
+
+import dbus
+
+class AutoRotateDaemonMonitor:
+    object_path = "/remote";
+    daemon_status_callback=0;
+
+    def __init__(self,bus=0,object_path=''):
+        self.bus=bus;
+        self.object_path=object_path;
+        
+        bus.watch_name_owner("net.krizka.autorotate",self.handleDaemonStatus);
+
+    def handleDaemonStatus(self,name):
+        if(self.daemon_status_callback):
+            self.daemon_status_callback(name);
+
+

--- a/rotate-indicator.py
+++ b/rotate-indicator.py
@@ -3,15 +3,21 @@
 import gobject
 import gtk
 import appindicator
-import dbus
 import os
 import subprocess
 
-from librotate import AutoRotateController
+import dbus
+import dbus.service
+import dbus.mainloop.glib
+
+from librotate import AutoRotateController,AutoRotateDaemonMonitor
 import xrandr
+
+dbus.mainloop.glib.DBusGMainLoop(set_as_default=True);
 
 class rotateindicator:
     controller=AutoRotateController.AutoRotateController(dbus.SystemBus(),"/rotate");
+    monitor=AutoRotateDaemonMonitor.AutoRotateDaemonMonitor(dbus.SystemBus(),"/rotate");
     auto_menu_item = gtk.MenuItem("  Automatic")
     daemon_menu_item=gtk.MenuItem("Auto-Rotate Daemon");
 
@@ -35,9 +41,14 @@
             print "KILL"
         else:
             os.system("auto-rotate.py -d");
+
+    def serviceCheck(self,name):
         self.refreshLabels();
+        
+    def __init__(self):
+        # Setup some callbacks to update the status of the buttons
+        self.monitor.daemon_status_callback=self.serviceCheck;
 
-    def __init__(self):
         ind = appindicator.Indicator ("autorotate-client", "gsd-xrandr", appindicator.CATEGORY_APPLICATION_STATUS)
         ind.set_status (appindicator.STATUS_ACTIVE)
         ind.set_attention_icon ("indicator-messages-new")
@@ -73,9 +84,6 @@
         menu.append(self.daemon_menu_item);
         self.daemon_menu_item.show();
 
-        # Update the labels
-        self.refreshLabels();
-        
         # Run the indicator!
         ind.set_menu(menu)