hamster-applet r590 - in trunk: data hamster



Author: tbaugis
Date: Wed Oct 22 16:25:09 2008
New Revision: 590
URL: http://svn.gnome.org/viewvc/hamster-applet?rev=590&view=rev

Log:
Create option to bug user once in a while
Patch by George Logiotatidis with slight modifications from me.
Fixes bug 529098


Modified:
   trunk/data/hamster-applet.schemas.in
   trunk/data/preferences.glade
   trunk/hamster/Configuration.py
   trunk/hamster/applet.py
   trunk/hamster/preferences.py

Modified: trunk/data/hamster-applet.schemas.in
==============================================================================
--- trunk/data/hamster-applet.schemas.in	(original)
+++ trunk/data/hamster-applet.schemas.in	Wed Oct 22 16:25:09 2008
@@ -37,5 +37,19 @@
                 </long>
             </locale>
         </schema>
+        <schema>
+            <key>/schemas/apps/hamster-applet/general/notify_interval</key>
+            <applyto>/apps/hamster-applet/general/notify_interval</applyto>
+            <owner>hamster-applet</owner>
+            <type>int</type>
+            <default>30</default>
+            <locale name="C">
+                <short>Remind of current task every x minutes</short>
+                <long>
+                    Remind of current task every specified amount of minutes.
+                    Set to 0 or bigger than 120 to disable reminder.
+                </long>
+            </locale>
+        </schema>
     </schemalist>
 </gconfschemafile>

Modified: trunk/data/preferences.glade
==============================================================================
--- trunk/data/preferences.glade	(original)
+++ trunk/data/preferences.glade	Wed Oct 22 16:25:09 2008
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.5 on Mon Oct 20 23:45:26 2008 -->
+<!--Generated with glade3 3.4.5 on Wed Oct 22 17:13:15 2008 -->
 <glade-interface>
   <widget class="GtkWindow" id="preferences_window">
     <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@@ -373,6 +373,47 @@
                             <property name="position">1</property>
                           </packing>
                         </child>
+                        <child>
+                          <widget class="GtkFrame" id="notification_preference_frame">
+                            <property name="visible">True</property>
+                            <property name="no_show_all">True</property>
+                            <property name="label_xalign">0</property>
+                            <property name="shadow_type">GTK_SHADOW_NONE</property>
+                            <child>
+                              <widget class="GtkAlignment" id="alignment1">
+                                <property name="visible">True</property>
+                                <property name="left_padding">12</property>
+                                <child>
+                                  <widget class="GtkHScale" id="notify_interval">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="adjustment">5 5 121 1 0 0</property>
+                                    <property name="show_fill_level">True</property>
+                                    <property name="restrict_to_fill_level">False</property>
+                                    <property name="digits">0</property>
+                                    <property name="value_pos">GTK_POS_BOTTOM</property>
+                                    <signal name="value_changed" handler="on_notify_interval_value_changed"/>
+                                    <signal name="format_value" handler="on_notify_interval_format_value"/>
+                                  </widget>
+                                </child>
+                              </widget>
+                            </child>
+                            <child>
+                              <widget class="GtkLabel" id="label1">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">Remind of current activity every:</property>
+                                <property name="use_markup">True</property>
+                              </widget>
+                              <packing>
+                                <property name="type">label_item</property>
+                              </packing>
+                            </child>
+                          </widget>
+                          <packing>
+                            <property name="padding">8</property>
+                            <property name="position">2</property>
+                          </packing>
+                        </child>
                       </widget>
                     </child>
                   </widget>

Modified: trunk/hamster/Configuration.py
==============================================================================
--- trunk/hamster/Configuration.py	(original)
+++ trunk/hamster/Configuration.py	Wed Oct 22 16:25:09 2008
@@ -32,7 +32,8 @@
     # GConf key for global keybinding
     GCONF_KEYBINDING = GCONF_DIR + "/keybinding"
     GCONF_ENABLE_TIMEOUT = GCONF_DIR + "/enable_timeout"
-    GCONF_STOP_ON_SHUTDOWN = GCONF_DIR + "/stop_on_shutdown"    
+    GCONF_STOP_ON_SHUTDOWN = GCONF_DIR + "/stop_on_shutdown"  
+    GCONF_NOTIFY_INTERVAL = GCONF_DIR + "/notify_interval" 
 
     __instance = None
         
@@ -56,6 +57,8 @@
         self._client.notify_add(self.GCONF_KEYBINDING, lambda x, y, z, a: dispatcher.dispatch("gconf_keybinding_changed", z.value.get_string()))
         self._client.notify_add(self.GCONF_ENABLE_TIMEOUT, lambda x, y, z, a: dispatcher.dispatch("gconf_timeout_enabled_changed", z.value.get_bool()))
         self._client.notify_add(self.GCONF_STOP_ON_SHUTDOWN, lambda x, y, z, a: dispatcher.dispatch("gconf_stop_on_shutdown_changed", z.value.get_bool()))
+        self._client.notify_add(self.GCONF_NOTIFY_INTERVAL, lambda x, y, z, a: dispatcher.dispatch("gconf_notify_interval_changed", z.value.get_int()))
+
     
     def get_keybinding(self):
         return self._client.get_string(self.GCONF_KEYBINDING)
@@ -65,6 +68,9 @@
 
     def get_stop_on_shutdown(self):
         return self._client.get_bool(self.GCONF_STOP_ON_SHUTDOWN)
+        
+    def get_notify_interval(self):
+    	return self._client.get_int(self.GCONF_NOTIFY_INTERVAL)
 
     #------------------------    
     def set_keybinding(self, binding):
@@ -75,3 +81,6 @@
         
     def set_stop_on_shutdown(self, enabled):
         self._client.set_bool(self.GCONF_STOP_ON_SHUTDOWN, enabled)
+    
+    def set_notify_interval(self, interval):
+    	return self._client.set_int(self.GCONF_NOTIFY_INTERVAL, interval)

Modified: trunk/hamster/applet.py
==============================================================================
--- trunk/hamster/applet.py	(original)
+++ trunk/hamster/applet.py	Wed Oct 22 16:25:09 2008
@@ -38,6 +38,30 @@
 
 import idle
 
+try:
+    import pynotify
+    PYNOTIFY = True
+except:
+    PYNOTIFY = False
+    
+class Notifier(object):
+    def __init__(self, app_name, icon, attach):
+        self._icon = icon
+        self._attach = attach
+        self._notify = None
+        # Title of reminder baloon
+        self.summary = _("Time Tracker")
+      
+        if not pynotify.is_initted():
+            pynotify.init(app_name)
+
+    def msg(self, body, switch_cb, stop_cb):
+        self._notify = pynotify.Notification(self.summary, body, self._icon, self._attach)
+        self._notify.add_action("refresh", _("Switch Task"), switch_cb)
+        self._notify.add_action("no", _("Stop Tracking"), stop_cb)
+        self._notify.show()
+
+
 class PanelButton(gtk.ToggleButton):
     def __init__(self):
         gtk.ToggleButton.__init__(self)
@@ -96,14 +120,14 @@
         self.edit_column = gtk.TreeViewColumn("", edit_cell)
         self.treeview.append_column(self.edit_column)
 
-	# DBus Setup
-	try:
-	    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+        # DBus Setup
+        try:
+            dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
             name = dbus.service.BusName(HAMSTER_URI, dbus.SessionBus())
             self.dbusController = HamsterDbusController(bus_name = name)
-	except dbus.DBusException, e:
-	    print "can't init dbus: %s" % e
-
+        except dbus.DBusException, e:
+            print "can't init dbus: %s" % e
+    
         # Load today's data, activities and set label
         self.last_activity = None
         self.today = datetime.date.today()
@@ -112,7 +136,7 @@
         self.update_label()
 
         # Hamster DBusController current fact initialising
-	self.__update_fact()
+        self.__update_fact()
 
         # refresh hamster every 60 seconds to update duration
         gobject.timeout_add_seconds(60, self.refresh_hamster)
@@ -154,11 +178,17 @@
 
         # init hotkey
         dispatcher.add_handler('keybinding_activated', self.on_keybinding_activated)
-        dispatcher.add_handler('gconf_timeout_changed', self.on_timeout_changed)
-        dispatcher.add_handler('gconf_timeout_enabled_changed', self.on_timeout_enabled_changed)
-  
+
         # init idle check
-        self.timeout_enabled = self.config.get_timeout_enabled()
+        dispatcher.add_handler('gconf_timeout_enabled_changed', self.on_timeout_enabled_changed)
+        self.on_timeout_enabled_changed(None, self.config.get_timeout_enabled())
+        
+        # init nagging timeout
+        if PYNOTIFY:
+            self.notify = Notifier('HamsterApplet', gtk.STOCK_DIALOG_QUESTION, self.button)
+            dispatcher.add_handler('gconf_notify_interval_changed', self.on_notify_interval_changed)
+            self.on_notify_interval_changed(None, self.config.get_notify_interval())
+
 
     def on_today_release_event(self, tree, event):
         pointer = event.window.get_pointer() # x, y, flags
@@ -193,6 +223,11 @@
             
 
         if self.last_activity and self.last_activity['end_time'] == None:
+            # if we have running task and nagging is enabled
+            # check if maybe it is time to nag
+            if self.notify_interval:
+                self.check_user()
+
             # if we have date change - let's finish previous task and start a new one
             if prev_date and prev_date != self.today: 
                 storage.touch_fact(self.last_activity)
@@ -217,7 +252,24 @@
         self.button.set_text(label)
         
         # Hamster DBusController current activity updating
-	self.dbusController.update_activity(label)
+        self.dbusController.update_activity(label)
+
+    def check_user(self):
+        print "going for user"
+        delta = datetime.datetime.now() - self.last_activity['start_time']
+        duration = delta.seconds /  60
+                 
+        if duration and duration % self.notify_interval == 0:
+            # activity reminder
+            msg = _(u"Are you still working on <b>%s</b>?") % self.last_activity['name']
+            self.notify.msg(msg, self.switch_cb, self.stop_cb)
+
+    def switch_cb(self, n, action):
+        self.__show_toggle(None, not self.button.get_active())	
+
+    def stop_cb(self, n, action):
+        self.on_stop_tracking(None)
+
 
     def load_day(self):
         """sets up today's tree and fills it with records
@@ -276,11 +328,11 @@
 
 
     def __update_fact(self):
-	"""dbus controller current fact updating"""
-	if self.last_activity and self.last_activity['end_time'] == None:
-	    self.dbusController.update_fact(self.last_activity["name"])
-	else:
-	    self.dbusController.update_fact(_(u'No activity'))
+        """dbus controller current fact updating"""
+        if self.last_activity and self.last_activity['end_time'] == None:
+            self.dbusController.update_fact(self.last_activity["name"])
+        else:
+            self.dbusController.update_fact(_(u'No activity'))
 
 
     def __show_toggle(self, event, is_active):
@@ -413,16 +465,13 @@
         if date.date() == datetime.date.today():
             self.load_day()
             self.update_label()
-
-	self.__update_fact()
+    
+        self.__update_fact()
 
     """global shortcuts"""
     def on_keybinding_activated(self, event, data):
         self.__show_toggle(None, not self.button.get_active())
         
-    def on_timeout_changed(self, event, new_timeout):
-        self.timeout = new_timeout
-        
     def on_timeout_enabled_changed(self, event, enabled):
         # if enabled, set to value, otherwise set to zero, which means disable
         self.timeout_enabled = enabled
@@ -439,3 +488,9 @@
 
         if new_angle != self.button.label.get_angle():
             self.button.label.set_angle(new_angle)
+
+    def on_notify_interval_changed(self, event, new_interval):
+        if PYNOTIFY and 0 < new_interval < 121:
+            self.notify_interval = new_interval
+        else:
+            self.notify_interval = None

Modified: trunk/hamster/preferences.py
==============================================================================
--- trunk/hamster/preferences.py	(original)
+++ trunk/hamster/preferences.py	Wed Oct 22 16:25:09 2008
@@ -166,10 +166,17 @@
         self.prev_selected_activity = None
         self.prev_selected_category = None
         
+        # disable notification thing if pynotify is not available
+        try:
+            import pynotify
+        except:
+            self.get_widget("notification_preference_frame").hide()
+
 
     def load_config(self):
         self.get_widget("shutdown_track").set_active(self.config.get_stop_on_shutdown())
         self.get_widget("idle_track").set_active(self.config.get_timeout_enabled())
+        self.get_widget("notify_interval").set_value(self.config.get_notify_interval())
         self.get_widget("keybinding").set_text(self.config.get_keybinding())
 
 
@@ -460,8 +467,8 @@
             #tree.set_cursor(path, start_editing = True)
 
     def on_preferences_window_key_press(self, widget, event):
-	if event.keyval == gtk.keysyms.Escape:
-	    self.window.destroy()     
+        if event.keyval == gtk.keysyms.Escape:
+            self.window.destroy()     
 
     """button events"""
     def on_add_category_clicked(self, button):
@@ -522,6 +529,19 @@
 
     def on_idle_track_toggled(self, checkbox):
         self.config.set_timeout_enabled(checkbox.get_active())
+
+    def on_notify_interval_format_value(self, slider, value):
+        if value <=120:
+            # notify interval slider value label
+            label = _("%(interval_minutes)d minutes" % {'interval_minutes': value})
+        else:
+            # notify interval slider value label
+            label = _("Never")
+        
+        return label
+    
+    def on_notify_interval_value_changed(self, scale):
+        self.config.set_notify_interval(int(scale.get_value()))
     
     def on_keybinding_changed(self, textbox):
         self.config.set_keybinding(textbox.get_text())



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