[hamster-applet] replace libegg global keybindings with gnome keyboard shortcuts. most probably this means that the k



commit 907d02985ee2f00251e9433b9f95e69ebaa5bce1
Author: Toms Bauģis <toms baugis gmail com>
Date:   Tue May 25 14:35:47 2010 +0100

    replace libegg global keybindings with gnome keyboard shortcuts. most probably this means that the keybindings won't work in non-gnome environments, but is better than attacking random keystrokes

 configure.ac                              |    1 -
 data/.gitignore                           |    1 +
 data/90-hamster-applet.xml.in             |    4 +
 data/99-hamster-applet.xml                |    4 -
 data/Makefile.am                          |   10 +-
 data/applet.ui                            |    5 +-
 data/hamster-applet.schemas.in            |   46 ++-
 src/hamster-client                        |   11 +-
 src/hamster-standalone                    |   37 +--
 src/hamster/Makefile.am                   |    2 +-
 src/hamster/applet.py                     |   32 +--
 src/hamster/client.py                     |    8 +
 src/hamster/keybinder/.gitignore          |    8 -
 src/hamster/keybinder/Makefile.am         |   35 --
 src/hamster/keybinder/__init__.py         |   13 -
 src/hamster/keybinder/_keybinder.defs     |   40 --
 src/hamster/keybinder/_keybinder.override |  139 ------
 src/hamster/keybinder/_keybindermodule.c  |   48 ---
 src/hamster/keybinder/eggaccelerators.c   |  657 -----------------------------
 src/hamster/keybinder/eggaccelerators.h   |   87 ----
 src/hamster/keybinder/gen-defs.sh         |    6 -
 src/hamster/keybinder/tomboykeybinder.c   |  341 ---------------
 src/hamster/keybinder/tomboykeybinder.h   |   43 --
 src/hamster/storage.py                    |   12 +-
 24 files changed, 88 insertions(+), 1502 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d70e203..13e34f0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -167,7 +167,6 @@ AC_CONFIG_FILES([
 Makefile
 src/Makefile
 src/hamster/defs.py
-src/hamster/keybinder/Makefile
 data/Makefile
 data/art/Makefile
 po/Makefile.in
diff --git a/data/.gitignore b/data/.gitignore
index f288dba..b0ea01a 100644
--- a/data/.gitignore
+++ b/data/.gitignore
@@ -3,3 +3,4 @@ Hamster_Applet.server.in
 hamster-standalone.desktop
 hamster-standalone.desktop.in
 hamster-applet.schemas
+90-hamster-applet.xml
diff --git a/data/90-hamster-applet.xml.in b/data/90-hamster-applet.xml.in
new file mode 100644
index 0000000..ba62d3b
--- /dev/null
+++ b/data/90-hamster-applet.xml.in
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<KeyListEntries _name="Project Hamster (Gnome Time Tracker)" package="hamster-applet">
+    <KeyListEntry name="/desktop/gnome/keybindings/hamster-applet/binding" />
+</KeyListEntries>
diff --git a/data/Makefile.am b/data/Makefile.am
index 8b41ccb..4963dba 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -39,13 +39,15 @@ resources_DATA = \
         applet.ui \
 	hamster.db
 
-xml_in_files = 99-hamster-applet.xml
+xml_in_files = 90-hamster-applet.xml.in
 
 if CUSTOM_KEYBINDINGS
 xmldir = $(KEYBINDINGS_DIR)
-xml_DATA = $(xml_in_files)
+xml_DATA = $(xml_in_files:.xml.in=.xml)
 endif
 
+ INTLTOOL_XML_NOMERGE_RULE@
+
 hamsterbindir = $(libdir)/hamster-applet
 
 # ******************************************************************************
@@ -68,6 +70,7 @@ endif
 DISTCLEANFILES = \
 	$(schema_DATA) \
 	$(server_DATA) \
+	$(xml_in_files)	\
 	$(server_in_files)
 
 EXTRA_DIST = \
@@ -75,6 +78,7 @@ EXTRA_DIST = \
 	$(xml_in_files) \
 	Hamster_Applet.server.in.in \
 	hamster-standalone.desktop.in.in \
-	$(resources_DATA)
+	$(resources_DATA) \
+	$(xml_in_files)
 
 CLEANFILES = hamster-standalone.desktop
diff --git a/data/applet.ui b/data/applet.ui
index 00690cb..43d30bd 100644
--- a/data/applet.ui
+++ b/data/applet.ui
@@ -6,7 +6,6 @@
     <property name="can_focus">True</property>
     <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
     <property name="resizable">False</property>
-    <property name="window_position">mouse</property>
     <property name="destroy_with_parent">True</property>
     <property name="icon_name">hamster-applet</property>
     <property name="skip_taskbar_hint">True</property>
@@ -29,10 +28,12 @@
                 <property name="visible">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                 <property name="border_width">12</property>
+                <property name="orientation">vertical</property>
                 <property name="spacing">6</property>
                 <child>
                   <object class="GtkVBox" id="vbox2">
                     <property name="visible">True</property>
+                    <property name="orientation">vertical</property>
                     <child>
                       <object class="GtkHBox" id="current_activity_box">
                         <property name="visible">True</property>
@@ -40,6 +41,7 @@
                           <object class="GtkVBox" id="vbox6">
                             <property name="width_request">520</property>
                             <property name="visible">True</property>
+                            <property name="orientation">vertical</property>
                             <child>
                               <object class="GtkHBox" id="hbox1">
                                 <property name="visible">True</property>
@@ -85,6 +87,7 @@
                                 <child>
                                   <object class="GtkVBox" id="activity_info_box">
                                     <property name="visible">True</property>
+                                    <property name="orientation">vertical</property>
                                     <child>
                                       <object class="GtkLabel" id="last_activity_duration">
                                         <property name="visible">True</property>
diff --git a/data/hamster-applet.schemas.in b/data/hamster-applet.schemas.in
index c7bb73c..fd7a5d1 100644
--- a/data/hamster-applet.schemas.in
+++ b/data/hamster-applet.schemas.in
@@ -1,17 +1,6 @@
 <gconfschemafile>
     <schemalist>
         <schema>
-            <key>/schemas/apps/hamster-applet/keybinding</key>
-            <applyto>/apps/hamster-applet/keybinding</applyto>
-            <owner>hamster-applet</owner>
-            <type>string</type>
-            <default>&lt;Super&gt;H</default>
-            <locale name="C">
-                <short>Show window</short>
-                <long>Keyboard shortcut for showing the Time Tracker window.</long>
-            </locale>
-        </schema>
-        <schema>
             <key>/schemas/apps/hamster-applet/enable_timeout</key>
             <applyto>/apps/hamster-applet/enable_timeout</applyto>
             <owner>hamster-applet</owner>
@@ -115,5 +104,40 @@
                 </long>
             </locale>
         </schema>
+
+
+        <schema>
+            <key>/schemas/desktop/gnome/keybindings/hamster-applet/binding</key>
+            <applyto>/desktop/gnome/keybindings/hamster-applet/binding</applyto>
+            <owner>hamster-applet</owner>
+            <type>string</type>
+            <default>&lt;Super&gt;h</default>
+            <locale name="C">
+                <short>Show / hide Time Tracker Window</short>
+                <long>Keyboard shortcut for showing / hiding the Time Tracker window.</long>
+            </locale>
+        </schema>
+        <schema>
+            <key>/schemas/desktop/gnome/keybindings/hamster-applet/action</key>
+            <applyto>/desktop/gnome/keybindings/hamster-applet/action</applyto>
+            <owner>hamster-applet</owner>
+            <type>string</type>
+            <default>hamster-client toggle</default>
+            <locale name="C">
+                <short>Toggle hamster application window action</short>
+                <long>Command for toggling visibility of the hamster application window.</long>
+            </locale>
+        </schema>
+        <schema>
+            <key>/schemas/desktop/gnome/keybindings/hamster-applet/name</key>
+            <applyto>/desktop/gnome/keybindings/hamster-applet/name</applyto>
+            <owner>hamster-applet</owner>
+            <type>string</type>
+            <default>Toggle hamster application window</default>
+            <locale name="C">
+                <short>Toggle hamster application window</short>
+                <long>Toggle visibility of the hamster application window.</long>
+            </locale>
+        </schema>
     </schemalist>
 </gconfschemafile>
diff --git a/src/hamster-client b/src/hamster-client
index bad9ab9..e55c22a 100755
--- a/src/hamster-client
+++ b/src/hamster-client
@@ -39,6 +39,9 @@ class HamsterClient(object):
     def __init__(self):
         self.storage = client.Storage()
 
+    def toggle(self):
+        self.storage.toggle()
+
 
     def start_tracking(self, activity, start_time = None, end_time = None):
         '''Start a new activity.'''
@@ -257,15 +260,17 @@ Time formats:
 
     command, args = sys.argv[1], sys.argv[2:]
 
-
-    if command not in ['start', 'stop', 'list', 'list-activities', 'list-categories']:
+    if command not in ['toggle', 'start', 'stop', 'list', 'list-activities', 'list-categories']:
         # unknown command - print usage, go home
         sys.exit(usage % {'prog': sys.argv[0]})
 
 
     hamster_client = HamsterClient()
 
-    if command == 'start':
+    if command == 'toggle':
+        hamster_client.toggle()
+
+    elif command == 'start':
         if not args: # mandatory is only the activity name
             sys.exit(usage % {'prog': sys.argv[0]})
 
diff --git a/src/hamster-standalone b/src/hamster-standalone
index a9faae3..55b7c06 100755
--- a/src/hamster-standalone
+++ b/src/hamster-standalone
@@ -31,7 +31,7 @@ import dbus, dbus.service, dbus.mainloop.glib
 
 from hamster.configuration import conf, runtime, dialogs
 
-from hamster import stuff, keybinder
+from hamster import stuff
 
 # controllers for other windows
 from hamster import widgets
@@ -97,9 +97,6 @@ class ProjectHamster(object):
         self.notify_interval = conf.get("notify_interval")
         self.workspace_tracking = conf.get("workspace_tracking")
 
-        self.hotkey = conf.get("keybinding")
-        self.bind_hotkey()
-
         conf.connect('conf-changed', self.on_conf_changed)
 
         # Load today's data, activities and set label
@@ -111,6 +108,7 @@ class ProjectHamster(object):
 
         runtime.storage.connect('activities-changed',self.after_activity_update)
         runtime.storage.connect('facts-changed',self.after_fact_update)
+        runtime.storage.connect('toggle-called', self.on_toggle_called)
 
         self.screen = None
         if self.workspace_tracking:
@@ -268,24 +266,6 @@ class ProjectHamster(object):
         fact = self.treeview.get_selected_fact()
         runtime.storage.remove_fact(fact["id"])
 
-    def bind_hotkey(self):
-        try:
-            print 'Binding shortcut %s to popup hamster' % self.hotkey
-            keybinder.bind(self.hotkey, self.on_keybinding_activated)
-        except KeyError:
-            pass # don't care
-
-    def on_keybinding_activated(self):
-        print "boink"
-        self.window.present()
-
-
-    def _delayed_display(self):
-        """show window only when gtk has become idle. otherwise we get
-        mixed results. TODO - this looks like a hack though"""
-        self.window.present()
-        self.new_name.grab_focus()
-
 
     """events"""
     def on_todays_keys(self, tree, event):
@@ -422,7 +402,9 @@ class ProjectHamster(object):
                                      "hamster-applet")
             self.notification.show()
 
-    """global shortcuts"""
+    def on_toggle_called(self, client):
+        self.window.present()
+
     def on_conf_changed(self, event, key, value):
         if key == "enable_timeout":
             self.timeout_enabled = value
@@ -441,15 +423,6 @@ class ProjectHamster(object):
                 if self.screen:
                     self.screen.disconnect(self.screen.workspace_handler)
                     self.screen = None
-        elif key == "keybinding":
-            try:
-                keybinder.unbind(self.hotkey)
-            except KeyError:
-                pass # don't care
-
-            self.hotkey = value
-            self.bind_hotkey()
-
 
     def on_activity_text_changed(self, widget):
         self.get_widget("switch_activity").set_sensitive(widget.get_text() != "")
diff --git a/src/hamster/Makefile.am b/src/hamster/Makefile.am
index c52a38a..e9c59f5 100644
--- a/src/hamster/Makefile.am
+++ b/src/hamster/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = keybinder widgets
+SUBDIRS = widgets
 ACLOCAL_AMFLAGS = -I m4
 
 CPPFLAGS = \
diff --git a/src/hamster/applet.py b/src/hamster/applet.py
index 03e0ee9..882579f 100755
--- a/src/hamster/applet.py
+++ b/src/hamster/applet.py
@@ -34,7 +34,6 @@ import locale
 from configuration import conf, runtime, dialogs
 
 import stuff
-import keybinder
 
 # controllers for other windows
 import widgets
@@ -238,9 +237,6 @@ class HamsterApplet(object):
         self.notify_interval = conf.get("notify_interval")
         self.workspace_tracking = conf.get("workspace_tracking")
 
-        self.hotkey = conf.get("keybinding")
-        self.bind_hotkey()
-
         conf.connect('conf-changed', self.on_conf_changed)
 
         # Load today's data, activities and set label
@@ -251,8 +247,9 @@ class HamsterApplet(object):
 
         # refresh hamster every 60 seconds to update duration
         gobject.timeout_add_seconds(60, self.refresh_hamster)
-        runtime.storage.connect('activities-changed',self.after_activity_update)
-        runtime.storage.connect('facts-changed',self.after_fact_update)
+        runtime.storage.connect('activities-changed', self.after_activity_update)
+        runtime.storage.connect('facts-changed', self.after_fact_update)
+        runtime.storage.connect('toggle-called', self.on_toggle_called)
 
         self.screen = None
         if self.workspace_tracking:
@@ -268,15 +265,6 @@ class HamsterApplet(object):
 
         self.prev_size = None
 
-
-    def bind_hotkey(self):
-        try:
-            print 'Binding shortcut %s to popup hamster' % self.hotkey
-            keybinder.bind(self.hotkey, self.on_keybinding_activated)
-        except KeyError:
-            pass # don't care
-
-
     def init_workspace_tracking(self):
         if not wnck: # can't track if we don't have the trackable
             return
@@ -652,11 +640,9 @@ class HamsterApplet(object):
                                      "hamster-applet")
             self.notification.show()
 
-    """global shortcuts"""
-    def on_keybinding_activated(self):
+    def on_toggle_called(self, client):
         self.__show_toggle(not self.button.get_active())
 
-
     def on_conf_changed(self, event, key, value):
         if key == "enable_timeout":
             self.timeout_enabled = value
@@ -675,16 +661,6 @@ class HamsterApplet(object):
                 if self.screen:
                     self.screen.disconnect(self.screen.workspace_handler)
                     self.screen = None
-        elif key == "keybinding":
-            try:
-                keybinder.unbind(self.hotkey)
-            except KeyError:
-                pass # don't care
-
-            self.hotkey = value
-            self.bind_hotkey()
-
-
 
     def on_activity_text_changed(self, widget):
         self.get_widget("switch_activity").set_sensitive(widget.get_text() != "")
diff --git a/src/hamster/client.py b/src/hamster/client.py
index 5d5d01d..f6f6280 100644
--- a/src/hamster/client.py
+++ b/src/hamster/client.py
@@ -58,6 +58,7 @@ class Storage(gobject.GObject):
         "tags-changed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
         "facts-changed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
         "activities-changed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
+        "toggle-called": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
     }
 
     def __init__(self):
@@ -73,6 +74,7 @@ class Storage(gobject.GObject):
         bus.add_signal_receiver(self._on_tags_changed, 'TagsChanged', 'org.gnome.Hamster')
         bus.add_signal_receiver(self._on_facts_changed, 'FactsChanged', 'org.gnome.Hamster')
         bus.add_signal_receiver(self._on_activities_changed, 'ActivitiesChanged', 'org.gnome.Hamster')
+        bus.add_signal_receiver(self._on_toggle_called, 'ToggleCalled', 'org.gnome.Hamster')
 
 
     def _on_tags_changed(self):
@@ -84,6 +86,12 @@ class Storage(gobject.GObject):
     def _on_activities_changed(self):
         self.emit("activities-changed")
 
+    def _on_toggle_called(self):
+        self.emit("toggle-called")
+
+    def toggle(self):
+        """toggle visibility of the main application window if any"""
+        self.conn.Toggle()
 
     def get_todays_facts(self):
         """returns facts of the current date, respecting hamster midnight
diff --git a/src/hamster/storage.py b/src/hamster/storage.py
index 0e76967..f7bf879 100644
--- a/src/hamster/storage.py
+++ b/src/hamster/storage.py
@@ -60,6 +60,9 @@ class Storage(dbus.service.Object):
     @dbus.service.signal("org.gnome.Hamster")
     def ActivitiesChanged(self): pass
 
+    @dbus.service.signal("org.gnome.Hamster")
+    def ToggleCalled(self): pass
+
     def dispatch_overwrite(self):
         self.TagsChanged()
         self.FactsChanged()
@@ -81,8 +84,15 @@ class Storage(dbus.service.Object):
         self.mainloop.quit()
 
 
-    # facts
+    @dbus.service.method("org.gnome.Hamster")
+    def Toggle(self):
+        """Toggle visibility of the main application window.
+           If several instances are available, it will toggle them all.
+        """
+        #log.logger.info("Hamster Service is being shutdown")
+        self.ToggleCalled()
 
+    # facts
     @dbus.service.method("org.gnome.Hamster", in_signature='ssiissb', out_signature='i')
     def AddFact(self, activity_name, tags, start_time, end_time,
                 category_name = None, description = None, temporary = False):



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