When the user is active, reduce the download parallelism.
authorNeal H. Walfield <neal@walfield.org>
Fri, 29 Jul 2011 10:27:12 +0000 (12:27 +0200)
committerNeal H. Walfield <neal@walfield.org>
Sun, 31 Jul 2011 19:58:35 +0000 (21:58 +0200)
src/FeedingIt.py

index a36d663..55c0497 100644 (file)
@@ -1133,7 +1133,35 @@ class FeedingIt:
                               )
         iface = dbus.Interface(remote_object, 'org.marcoz.feedingit')
         iface.StopUpdate()
-    
+
+    def increase_download_parallelism(self):
+        # The system has been idle for a while.  Enable parallel
+        # downloads.
+        JobManager().num_threads = 4
+        gobject.source_remove (self.increase_download_parallelism_id)
+        del self.increase_download_parallelism_id
+        return False
+
+    def system_inactivity_ind(self, idle):
+        # The system's idle state changed.
+        if (self.am_idle and idle) or (not self.am_idle and not idle):
+            # No change.
+            return
+
+        if not idle:
+            if hasattr (self, 'increase_download_parallelism_id'):
+                gobject.source_remove (self.increase_download_parallelism_id)
+                del self.increase_download_parallelism_id
+        else:
+            self.increase_download_parallelism_id = \
+                gobject.timeout_add_seconds(
+                    60, self.increase_download_parallelism)
+
+        if not idle:
+            JobManager().num_threads = 1
+
+        self.am_idle = idle
+
     def late_init(self):
         self.dbusHandler = ServerObject(self)
         self.updateDbusHandler = UpdateServerObject(self)
@@ -1141,8 +1169,18 @@ class FeedingIt:
         jm = JobManager()
         jm.stats_hook_register (self.job_manager_update,
                                 run_in_main_thread=True)
+        jm.num_threads = 1
+        self.am_idle = False
         JobManager(True)
 
+        import dbus
+        bus = dbus.SystemBus()
+        proxy = bus.get_object('com.nokia.mce',
+                               '/com/nokia/mce/signal')
+        iface = dbus.Interface(proxy, 'com.nokia.mce.signal')
+        iface.connect_to_signal('system_inactivity_ind',
+                                self.system_inactivity_ind)
+
     def button_markAll(self, button):
         for key in self.listing.getListOfFeeds():
             feed = self.listing.getFeed(key)