psa: adding toggle to show/hide specific feed on Event Feed stream
[feedingit] / psa_harmattan / feedingit / pysrc / feedingit.py
index 7c4ed25..b401a0c 100644 (file)
@@ -31,6 +31,7 @@ from cgi import escape
 from re import sub
 
 class Controller(QtCore.QObject):
+    cachedList = None
     
     def __init__(self, listing):
         QtCore.QObject.__init__(self)
@@ -41,6 +42,11 @@ class Controller(QtCore.QObject):
                         completed, in_progress, queued,
                         bytes_downloaded, bytes_updated, bytes_per_second,
                         feed_updated):
+        total = completed + in_progress + queued
+        root.updateProgress(int(total), int(completed))
+        
+    def articleCountUpdated(self):
+        #print "article updated"
         pass
     
     def update_started(self):
@@ -66,9 +72,31 @@ class Controller(QtCore.QObject):
     
     @QtCore.Slot(str,result=str)
     def getArticlesXml(self, key):
+        feed = listing.getFeed(key)
+        self.cachedList = feed.getIds(onlyUnread=True)
         #onlyUnread = arguments.get("onlyUnread","False")
         return self._handler.generateArticlesXml(key, config.getHideReadArticles())
     
+    @QtCore.Slot(str,str,bool,result=str)
+    def getNextId(self, key, articleid, onlyUnread):
+        if (onlyUnread):
+            #print self.cachedList, articleid
+            index = self.cachedList.index(articleid)
+            return self.cachedList[(index + 1) % len(self.cachedList)]
+        else:
+            feed = listing.getFeed(key)
+            return feed.getNextId(articleid)
+        
+    @QtCore.Slot(str,str,bool,result=str)
+    def getPreviousId(self, key, articleid, onlyUnread):
+        if (onlyUnread):
+            #print self.cachedList, articleid
+            index = self.cachedList.index(articleid)
+            return self.cachedList[(index - 1) % len(self.cachedList)]
+        else:
+            feed = listing.getFeed(key)
+            return feed.getPreviousId(articleid)
+    
     @QtCore.Slot(result=str)
     def getCategoryXml(self):
         return self._handler.generateCategoryXml()
@@ -114,6 +142,7 @@ class Controller(QtCore.QObject):
     def markAllAsRead(self, key):
         feed = listing.getFeed(key)
         feed.markAllAsRead()
+        listing.updateUnread(key)
 
     @QtCore.Slot(str, str)
     def setEntryRead(self, key, articleid):
@@ -176,6 +205,15 @@ class Controller(QtCore.QObject):
         else:
             return 'True'
         
+    @QtCore.Slot(str, result=int)
+    def getIntSetting(self, setting):
+        if (setting == "artFontSize"):
+            return config.getArtFontSize()
+        elif (setting == "fontSize" ):
+            return config.getFontSize()
+        else:
+            return -1
+        
     @QtCore.Slot(str, bool)
     def setBooleanSetting(self, setting, value):
         if (setting == "theme"):
@@ -189,9 +227,51 @@ class Controller(QtCore.QObject):
         elif (setting == "autoupdate"):
             config.setAutoUpdateEnabled(value)
         config.saveConfig()
+        
+    @QtCore.Slot(str, int)
+    def setIntSetting(self, setting, value):
+        if (setting == "artFontSize"):
+            config.setArtFontSize(value)
+        elif (setting == "fontSize" ):
+            config.setFontSize(value)
+        config.saveConfig()
+    
+    @QtCore.Slot(str, str)
+    def openSettings(self):
+        bus = dbus.SessionBus()
+        settingService = bus.get_object('com.nokia.DuiControlPanel', '/')
+        setting = shareService.get_dbus_method('appletPage', 'com.nokia.DuiControlPanelIf')
+        setting("FeedingIt")
 
-def main():
+    @QtCore.Slot(str, str)
+    def share(self, key, articleid):
+        feed = listing.getFeed(key)
+        title = feed.getTitle(articleid)
+        link = feed.getExternalLink(articleid)
+        description = 'Shared%20via%20FeedingIt%20on%20Meego'
+        import urllib
+        bus = dbus.SessionBus()
+        shareService = bus.get_object('com.nokia.ShareUi', '/')
+        share = shareService.get_dbus_method('share', 'com.nokia.maemo.meegotouch.ShareUiInterface')
+        #share([u'data:text/x-url;description=Support%20for%20Nokia%20Developers;title=Forum%20Nokia,http%3A%2F%2Fforum.nokia.com',])
+        share( ['data:text/x-url;title=%s;description=%s,%s' %(urllib.quote(title), description, urllib.quote(link)),] )
+        
+    @QtCore.Slot(str, result=bool)
+    def getFeedEventStatus(self, key):
+        from gconf import client_get_defaults
+        return client_get_default().get_bool('/apps/ControlPanel/FeedingIt/EnableFeed/'+key)
+    
+    @QtCore.Slot(str)
+    def switchEventFeedStatus(self, key):
+        from gconf import client_get_defaults
+        value = client_get_default().get_bool('/apps/ControlPanel/FeedingIt/EventFeed/Hide/'+key)
+        if value:
+            client_get_default().unset('/apps/ControlPanel/FeedingIt/EventFeed/Hide/'+key)
+        else:
+            client_get_default().set_bool('/apps/ControlPanel/FeedingIt/EventFeed/Hide/'+key, True)
+    
 
+def main():
     if not isdir(CONFIGDIR):
         try:
             mkdir(CONFIGDIR)
@@ -219,13 +299,19 @@ def main():
     controller = Controller(listing)
  
     # listen on dbus for download update progress
-    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
     bus = dbus.SessionBus()
-#        bus.add_signal_receiver(handler_function=self.update_progress,
-#                                bus_name=None,
-#                                signal_name='UpdateProgress',
-#                                dbus_interface='org.marcoz.feedingit',
-#                                path='/org/marcoz/feedingit/update')
+    
+    bus.add_signal_receiver(handler_function=controller.update_progress,
+                            bus_name=None,
+                            signal_name='UpdateProgress',
+                            dbus_interface='org.marcoz.feedingit',
+                            path='/org/marcoz/feedingit/update')
+    
+    bus.add_signal_receiver(handler_function=controller.articleCountUpdated,
+                            bus_name=None,
+                            signal_name='ArticleCountUpdated',
+                            dbus_interface='org.marcoz.feedingit',
+                            path='/org/marcoz/feedingit/update')
     bus.add_signal_receiver(handler_function=controller.update_started,
                             bus_name=None,
                             signal_name='UpdateStarted',
@@ -261,6 +347,5 @@ def main():
     #view.show()
     sys.exit(app.exec_())
 
-if __name__ == "__main__":
-    
+if __name__ == "__main__": 
     main()