Update text for reset and donate buttons
[pedometerwidget] / src / usr / lib / hildon-desktop / pedometer_widget_home.py
index 10364fb..627e93d 100644 (file)
@@ -57,7 +57,9 @@ unit = 0
 
 class Singleton(object):
     _instance = None
+    _references = 0
     def __new__(cls, *args, **kwargs):
+        cls._references+=1
         if not cls._instance:
             cls._instance = super(Singleton, cls).__new__(
                                 cls, *args, **kwargs)
@@ -407,8 +409,12 @@ class PedoController(Singleton):
     no_idle_time = False
 
     STEP_LENGTH = 0.7
+
+    #The interval(number of steps) between two file updates
+    BUFFER_STEPS_INTERVAL = 100
     #values for the two views in the widget ( current and day/week/alltime)
-    v = [PedoValues(), PedoValues()]
+    #third value to count the steps that were not yet written to file
+    v = [PedoValues(), PedoValues(), PedoValues()]
 
     last_time = 0
     is_running = False
@@ -472,12 +478,14 @@ class PedoController(Singleton):
             self.v[1] = self.repository.get_this_week_values()
 
     def save_values(self):
-        self.repository.add_values(self.v[0])
+        logger.info("Saving values to file")
+        self.repository.add_values(self.v[2])
         self.repository.save()
         self.load_values()
 
     def start_pedometer(self):
         self.v[0] = PedoValues()
+        self.v[2] = PedoValues()
         self.last_time = time.time()
         self.is_running = True
         self.pedometer.start()
@@ -487,6 +495,7 @@ class PedoController(Singleton):
         self.repository.reset_values()
         self.v[0] = PedoValues()
         self.v[1] = PedoValues()
+        self.v[2] = PedoValues()
         self.notify()
 
     def stop_pedometer(self):
@@ -498,7 +507,7 @@ class PedoController(Singleton):
 
     def get_second(self):
         if self.is_running:
-            return self.v[0] + self.v[1]
+            return self.v[2] + self.v[1]
         else:
             return self.v[1]
 
@@ -517,6 +526,17 @@ class PedoController(Singleton):
             self.v[0].dist += self.get_distance(cnt)
             self.v[0].calories += self.get_calories(self.get_distance(cnt))
             self.v[0].time += time.time() - self.last_time
+
+            self.v[2].steps += cnt
+            self.v[2].dist += self.get_distance(cnt)
+            self.v[2].calories += self.get_calories(self.get_distance(cnt))
+            self.v[2].time += time.time() - self.last_time
+
+            if not last_steps and self.v[2].steps > self.BUFFER_STEPS_INTERVAL:
+                self.save_values()
+                self.notify()
+                self.v[2] = PedoValues()
+
             if last_steps:
                 self.save_values()
                 self.notify()
@@ -1140,8 +1160,10 @@ class Config(Singleton):
     observers = []
 
     def __init__(self):
+        if self._references > 1:
+            return
         self.client = gconf.client_get_default()
-        self.client.add_dir('/apps/pedometerhomewidget', gconf.CLIENT_PRELOAD_NONE)
+        self.client.add_dir('/apps/pedometerhomewidget', gconf.CLIENT_PRELOAD_RECURSIVE)
         self.notify_id = self.client.notify_add('/apps/pedometerhomewidget', self.gconf_changed)
 
     def add_observer(self, func):
@@ -1158,8 +1180,11 @@ class Config(Singleton):
         self.notify()
 
     def notify(self):
+        t1 = time.time()
         for func in self.observers:
             func()
+        t2 = time.time()
+        logger.info("Update took: %f seconds" % (t2-t1))
 
     def get_mode(self):
         return self.client.get_int(MODE)
@@ -1748,7 +1773,8 @@ class PedometerHomePlugin(hildondesktop.HomePluginItem):
         stepLengthButton_value_update()
 
         resetButton = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
-        resetButton.set_title("Reset total counter")
+        resetButton.set_title("Reset")
+        resetButton.set_value("All the stored values will be erased")
         resetButton.set_alignment(0, 0.8, 1, 1)
         resetButton.connect("clicked", reset_total_counter)
 
@@ -1814,6 +1840,7 @@ class PedometerHomePlugin(hildondesktop.HomePluginItem):
 
         donateButton = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
         donateButton.set_title("Donate")
+        donateButton.set_value("Please support the development of this opensource widget!")
         donateButton.set_alignment(0, 0.8, 1, 1)
         donateButton.connect("clicked", donateButton_clicked, dialog)