[hamster-applet] create windows service that serves windows on demand for the little people. the standalone still all



commit 42964d79959d8aef5ac21f0a78cd8c5e79596163
Author: Toms BauÄis <toms baugis gmail com>
Date:   Sat Feb 4 00:35:16 2012 +0200

    create windows service that serves windows on demand for the little people. the standalone still allows passing in window names for backwards compat

 org.gnome.hamster.Windows.service.in |    3 ++
 src/hamster-time-tracker             |   64 +++------------------------------
 src/hamster-windows-service          |   60 +++++++++++++++++++++++++++++++
 wscript                              |    9 ++++-
 4 files changed, 77 insertions(+), 59 deletions(-)
---
diff --git a/org.gnome.hamster.Windows.service.in b/org.gnome.hamster.Windows.service.in
new file mode 100644
index 0000000..8d3946b
--- /dev/null
+++ b/org.gnome.hamster.Windows.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gnome.Hamster.WindowServer
+Exec= prefix@/bin/hamster-windows-service
diff --git a/src/hamster-time-tracker b/src/hamster-time-tracker
index cadae2e..db8bb11 100755
--- a/src/hamster-time-tracker
+++ b/src/hamster-time-tracker
@@ -546,39 +546,6 @@ class ProjectHamster(object):
         self.statusicon.set_visible(True)
 
 
-# maintain just one instance. this code feels hackish
-class WindowServer(dbus.service.Object):
-    __dbus_object_path__ = "/org/gnome/Hamster/WindowServer"
-
-    def __init__(self):
-        self.app = None
-        self.bus = dbus.SessionBus()
-        bus_name = dbus.service.BusName("org.gnome.Hamster.WindowServer", bus=self.bus)
-        dbus.service.Object.__init__(self, bus_name, self.__dbus_object_path__)
-
-    @dbus.service.method("org.gnome.Hamster.WindowServer")
-    def main(self):
-        if self.app:
-            self.app.window.show()
-            self.app.window.present()
-        else:
-            self.app = ProjectHamster()
-
-    @dbus.service.method("org.gnome.Hamster.WindowServer")
-    def edit(self): dialogs.edit.show(self.app)
-
-    @dbus.service.method("org.gnome.Hamster.WindowServer")
-    def overview(self): dialogs.overview.show(self.app)
-
-    @dbus.service.method("org.gnome.Hamster.WindowServer")
-    def about(self): dialogs.about.show(self.app)
-
-    @dbus.service.method("org.gnome.Hamster.WindowServer")
-    def statistics(self): dialogs.stats.show(self.app)
-
-    @dbus.service.method("org.gnome.Hamster.WindowServer")
-    def preferences(self): dialogs.prefs.show(self.app)
-
 
 if __name__ == "__main__":
     from hamster.lib import i18n
@@ -597,42 +564,23 @@ if __name__ == "__main__":
 """)
         sys.exit(usage % {'prog': sys.argv[0]})
 
-    if window == "toggle":
-        from hamster.client import Storage
-        storage = Storage()
-        storage.toggle()
-        sys.exit()
-
-    from hamster.configuration import runtime, dialogs, conf, load_ui_file
-
-    # if there is windowserver hanging in dbus - call that and exit
-    bus = dbus.SessionBus()
-    if "org.gnome.Hamster.WindowServer" in dbus.SessionBus().list_names():
-        server = bus.get_object("org.gnome.Hamster.WindowServer", WindowServer.__dbus_object_path__)
+    if window != "main":
+        bus = dbus.SessionBus()
+        server = bus.get_object("org.gnome.Hamster.WindowServer",
+                                "/org/gnome/Hamster/WindowServer")
         getattr(server, window)()
         sys.exit(0)
 
-
-    # otherwise proceed and do all the import and everything
-    gtk.gdk.threads_init()
-    gtk.window_set_default_icon_name("hamster-applet")
-
+    from hamster.configuration import runtime, dialogs, conf, load_ui_file
     from hamster import widgets, idle
     from hamster.lib import stuff, trophies
 
     try:
-        import wnck
-    except:
-        logging.warning("Could not import wnck - workspace tracking will be disabled")
-        wnck = None
-
-    try:
         import pynotify
         pynotify.init('Hamster Applet')
     except:
         logging.warning("Could not import pynotify - notifications will be disabled")
         pynotify = None
 
-
-    getattr(WindowServer(), window)()
+    app = ProjectHamster()
     gtk.main()
diff --git a/src/hamster-windows-service b/src/hamster-windows-service
new file mode 100755
index 0000000..cdd33be
--- /dev/null
+++ b/src/hamster-windows-service
@@ -0,0 +1,60 @@
+#!/usr/bin/python
+# nicked off hamster-service
+
+import gobject
+import dbus, dbus.service
+from dbus.mainloop.glib import DBusGMainLoop
+
+DBusGMainLoop(set_as_default=True)
+loop = gobject.MainLoop()
+
+if "org.gnome.Hamster.WindowServer" in dbus.SessionBus().list_names():
+    print "Found hamster-window-service already running, exiting"
+    quit()
+
+
+# maintain just one instance. this code feels hackish again
+class WindowServer(dbus.service.Object):
+    __dbus_object_path__ = "/org/gnome/Hamster/WindowServer"
+
+    def __init__(self, loop):
+        self.app = True
+        self.mainloop = loop
+        self.bus = dbus.SessionBus()
+        bus_name = dbus.service.BusName("org.gnome.Hamster.WindowServer", bus=self.bus)
+        dbus.service.Object.__init__(self, bus_name, self.__dbus_object_path__)
+
+    @dbus.service.method("org.gnome.Hamster")
+    def Quit(self):
+        """Shutdown the service"""
+        self.mainloop.quit()
+
+
+    @dbus.service.method("org.gnome.Hamster.WindowServer")
+    def edit(self, id=None): dialogs.edit.show(self.app, fact_id = id)
+
+    @dbus.service.method("org.gnome.Hamster.WindowServer")
+    def overview(self): dialogs.overview.show(self.app)
+
+    @dbus.service.method("org.gnome.Hamster.WindowServer")
+    def about(self): dialogs.about.show(self.app)
+
+    @dbus.service.method("org.gnome.Hamster.WindowServer")
+    def statistics(self): dialogs.stats.show(self.app)
+
+    @dbus.service.method("org.gnome.Hamster.WindowServer")
+    def preferences(self): dialogs.prefs.show(self.app)
+
+
+
+
+if __name__ == '__main__':
+    from hamster.lib import i18n
+    i18n.setup_i18n()
+
+    from hamster.configuration import runtime, dialogs, conf, load_ui_file
+    window_server = WindowServer(loop)
+
+    print "hamster-window-service up"
+
+    loop.run()
diff --git a/wscript b/wscript
index 3efcf57..38da6f2 100644
--- a/wscript
+++ b/wscript
@@ -47,7 +47,8 @@ def build(bld):
     bld.install_files('${BINDIR}',
                       """src/hamster-time-tracker
                          src/hamster-cli
-                         src/hamster-service""",
+                         src/hamster-service
+                         src/hamster-windows-service""",
                       chmod = 0755)
     bld.symlink_as('${BINDIR}/gnome-time-tracker', 'hamster-time-tracker')
 
@@ -83,6 +84,12 @@ def build(bld):
                      install_path="${DATADIR}/dbus-1/services",
                      dict = bld.env
                     )
+    bld.new_task_gen("subst",
+                     source= "org.gnome.hamster.Windows.service.in",
+                     target= "org.gnome.hamster.Windows.service",
+                     install_path="${DATADIR}/dbus-1/services",
+                     dict = bld.env
+                    )
 
     bld.add_subdirs("po help data")
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]