[hamster-applet] preference to notify on idle too. fixes bug 581564



commit e36558a09387473c7908428384c5655e7a8904d4
Author: Toms Bauģis <toms baugis gmail com>
Date:   Wed May 6 11:23:45 2009 +0100

    preference to notify on idle too. fixes bug 581564
---
 data/hamster-applet.schemas.in |   14 ++++++++++++
 data/preferences.ui            |   47 ++++++++++++++++++++++++++++++++-------
 hamster/Configuration.py       |    9 +++++++
 hamster/applet.py              |   40 ++++++++++++++++++++++------------
 hamster/preferences.py         |    8 ++++++-
 5 files changed, 94 insertions(+), 24 deletions(-)

diff --git a/data/hamster-applet.schemas.in b/data/hamster-applet.schemas.in
index 4d7525e..edf5d93 100644
--- a/data/hamster-applet.schemas.in
+++ b/data/hamster-applet.schemas.in
@@ -51,5 +51,19 @@
                 </long>
             </locale>
         </schema>
+        <schema>
+            <key>/schemas/apps/hamster-applet/general/notify_on_idle</key>
+            <applyto>/apps/hamster-applet/general/notify_on_idle</applyto>
+            <owner>hamster-applet</owner>
+            <type>bool</type>
+            <default>false</default>
+            <locale name="C">
+                <short>Remind also when no activity is set</short>
+                <long>
+                    Remind every notify_interval minutes also if no activity
+                    has been started.
+                </long>
+            </locale>
+        </schema>
     </schemalist>
 </gconfschemafile>
diff --git a/data/preferences.ui b/data/preferences.ui
index eaa8661..6607f36 100644
--- a/data/preferences.ui
+++ b/data/preferences.ui
@@ -437,16 +437,45 @@
                             <property name="visible">True</property>
                             <property name="left_padding">12</property>
                             <child>
-                              <object class="GtkHScale" id="notify_interval">
+                              <object class="GtkVBox" id="vbox2">
                                 <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <property name="adjustment">adjustment1</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">bottom</property>
-                                <signal name="value_changed" handler="on_notify_interval_value_changed"/>
-                                <signal name="format_value" handler="on_notify_interval_format_value"/>
+                                <property name="orientation">vertical</property>
+                                <child>
+                                  <object class="GtkHScale" id="notify_interval">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="adjustment">adjustment1</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">bottom</property>
+                                    <signal name="value_changed" handler="on_notify_interval_value_changed"/>
+                                    <signal name="format_value" handler="on_notify_interval_format_value"/>
+                                  </object>
+                                  <packing>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkAlignment" id="alignment2">
+                                    <property name="visible">True</property>
+                                    <property name="top_padding">8</property>
+                                    <property name="left_padding">4</property>
+                                    <child>
+                                      <object class="GtkCheckButton" id="notify_on_idle">
+                                        <property name="label" translatable="yes">remind also when no activity is set</property>
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">False</property>
+                                        <property name="draw_indicator">True</property>
+                                        <signal name="toggled" handler="on_notify_on_idle_toggled"/>
+                                      </object>
+                                    </child>
+                                  </object>
+                                  <packing>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
                               </object>
                             </child>
                           </object>
diff --git a/hamster/Configuration.py b/hamster/Configuration.py
index a85fcba..99c0392 100644
--- a/hamster/Configuration.py
+++ b/hamster/Configuration.py
@@ -34,6 +34,7 @@ class GconfStore(object):
     GCONF_ENABLE_TIMEOUT = GCONF_DIR + "/enable_timeout"
     GCONF_STOP_ON_SHUTDOWN = GCONF_DIR + "/stop_on_shutdown"  
     GCONF_NOTIFY_INTERVAL = GCONF_DIR + "/notify_interval" 
+    GCONF_NOTIFY_ON_IDLE = GCONF_DIR + "/notify_on_idle"
 
     __instance = None
         
@@ -58,6 +59,7 @@ class GconfStore(object):
         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()))
+        self._client.notify_add(self.GCONF_NOTIFY_ON_IDLE, lambda x, y, z, a: dispatcher.dispatch("gconf_notify_on_idle_changed", z.value.get_bool()))
 
     
     def get_keybinding(self):
@@ -72,6 +74,9 @@ class GconfStore(object):
     def get_notify_interval(self):
     	return self._client.get_int(self.GCONF_NOTIFY_INTERVAL) or 27
 
+    def get_notify_on_idle(self):
+    	return self._client.get_bool(self.GCONF_NOTIFY_ON_IDLE) or False
+
     #------------------------    
     def set_keybinding(self, binding):
         self._client.set_string(self.GCONF_KEYBINDING, binding)
@@ -84,3 +89,7 @@ class GconfStore(object):
     
     def set_notify_interval(self, interval):
     	return self._client.set_int(self.GCONF_NOTIFY_INTERVAL, interval)
+
+    def set_notify_on_idle(self, enabled):
+        self._client.set_bool(self.GCONF_NOTIFY_ON_IDLE, enabled)
+        
diff --git a/hamster/applet.py b/hamster/applet.py
index c1d2e99..1e5b173 100755
--- a/hamster/applet.py
+++ b/hamster/applet.py
@@ -278,7 +278,10 @@ class HamsterApplet(object):
 
         # init idle check
         dispatcher.add_handler('gconf_timeout_enabled_changed', self.on_timeout_enabled_changed)
-        self.on_timeout_enabled_changed(None, self.config.get_timeout_enabled())
+        self.timeout_enabled = self.config.get_timeout_enabled()
+
+        dispatcher.add_handler('gconf_notify_on_idle_changed', self.on_notify_on_idle_changed)
+        self.notify_on_idle = self.config.get_notify_on_idle()
         
         
         # init nagging timeout
@@ -426,17 +429,12 @@ Now, start tracking!
                 storage.touch_fact(self.last_activity, end_time = idle_from)
             
 
-        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 self.button.get_active(): # otherwise if we the day view is visible - update day's durations
                 self.load_day()
                     
         self.update_label()
+        self.check_user()
         return True
 
     def update_label(self):
@@ -459,13 +457,23 @@ Now, start tracking!
         self.dbusController.update_activity(label)
 
     def check_user(self):
-        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"Working on <b>%s</b>") % self.last_activity['name']
-            self.notify.msg(msg, self.edit_cb, self.switch_cb)
+        if not self.notify_interval: #no interval means "never"
+            return
+        
+        now = datetime.datetime.now()
+        if self.last_activity:
+            delta = now - self.last_activity['start_time']
+            duration = delta.seconds /  60
+
+            if duration and duration % self.notify_interval == 0:
+                # activity reminder
+                msg = _(u"Working on <b>%s</b>") % self.last_activity['name']
+                self.notify.msg(msg, self.edit_cb, self.switch_cb)
+        elif self.notify_on_idle:
+            #if we have no last activity, let's just calculate duration from 00:00
+            if (now.minute + now.hour *60) % self.notify_interval == 0:
+                msg = _(u"No activity")
+                self.notify.msg(msg, self.edit_cb, self.switch_cb)
 
     def edit_cb(self, n, action):
         custom_fact = CustomFactController(self, None, self.last_activity['id'])
@@ -764,6 +772,10 @@ Now, start tracking!
         # if enabled, set to value, otherwise set to zero, which means disable
         self.timeout_enabled = enabled
 
+    def on_notify_on_idle_changed(self, event, enabled):
+        # if enabled, set to value, otherwise set to zero, which means disable
+        self.notify_on_idle = enabled
+
     def on_notify_interval_changed(self, event, new_interval):
         if PYNOTIFY and 0 < new_interval < 121:
             self.notify_interval = new_interval
diff --git a/hamster/preferences.py b/hamster/preferences.py
index 7210425..543dcb7 100755
--- a/hamster/preferences.py
+++ b/hamster/preferences.py
@@ -179,6 +179,7 @@ class PreferencesEditor:
         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())
+        self.get_widget("notify_on_idle").set_active(self.config.get_notify_on_idle())
 
 
     def drag_data_get_data(self, treeview, context, selection, target_id,
@@ -618,6 +619,9 @@ class PreferencesEditor:
     def on_idle_track_toggled(self, checkbox):
         self.config.set_timeout_enabled(checkbox.get_active())
 
+    def on_notify_on_idle_toggled(self, checkbox):
+        self.config.set_notify_on_idle(checkbox.get_active())
+
     def on_notify_interval_format_value(self, slider, value):
         if value <=120:
             # notify interval slider value label
@@ -629,7 +633,9 @@ class PreferencesEditor:
         return label
     
     def on_notify_interval_value_changed(self, scale):
-        self.config.set_notify_interval(int(scale.get_value()))
+        value = int(scale.get_value())
+        self.config.set_notify_interval(value)
+        self.get_widget("notify_on_idle").set_sensitive(value <= 120)
     
     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]