Added destroy for widget when removed from homescreen
authorYves <ymarcoz@n900-sdk.(none)>
Thu, 13 May 2010 15:00:19 +0000 (08:00 -0700)
committerYves <ymarcoz@n900-sdk.(none)>
Thu, 13 May 2010 15:00:19 +0000 (08:00 -0700)
debian/changelog
src/FeedingIt.py
src/feedingit_widget.py
src/rss.py
src/update_feeds.py

index 1433525..d62be70 100644 (file)
@@ -1,8 +1,15 @@
-feedingit (0.6.1-8) unstable; urgency=low
+feedingit (0.6.2-0) unstable; urgency=low
+
+  * Added icons to feeds
+  * Added timeout to widget updates to prevent hanging
+
+ -- Yves <yves@marcoz.org>  Tue, 12 May 2010 07:21:19 -0800
+
+feedingit (0.6.1-9) unstable; urgency=low
 
   * Fixed bug triggering updates from widgets too often
 
- -- Yves <yves@marcoz.org>  Mon, 03 May 2010 21:44:19 -0800
+ -- Yves <yves@marcoz.org>  Mon, 10 May 2010 21:55:19 -0800
 
 feedingit (0.6.1-7) unstable; urgency=low
 
index b30d0e9..56bc40e 100644 (file)
@@ -868,6 +868,7 @@ class FeedingIt:
         self.buttons = {}
         list = self.listing.getListOfFeeds()[:]
         #list.reverse()
+        icon_theme = gtk.icon_theme_get_default()
         for key in list:
             #button = gtk.Button(item)
             unreadItems = self.listing.getFeedNumberOfUnreadItems(key)
@@ -875,6 +876,16 @@ class FeedingIt:
                               hildon.BUTTON_ARRANGEMENT_VERTICAL)
             button.set_text(self.listing.getFeedTitle(key), self.listing.getFeedUpdateTime(key) + " / " 
                             + str(unreadItems) + " Unread Items")
+            icon = self.listing.getFavicon(key)
+            image = gtk.Image()
+            try:
+                pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon, 32, 32)
+            except:
+                pixbuf = icon_theme.load_icon("feedingit", 32, gtk.ICON_LOOKUP_USE_BUILTIN )
+
+            image.set_from_pixbuf(pixbuf)
+            button.set_image(image)
+            button.set_image_position(gtk.POS_LEFT)
             button.set_alignment(0,0,1,1)
             button.connect("clicked", self.buttonFeedClicked, self, self.window, key)
             self.vboxListing.pack_start(button, expand=False)
@@ -891,7 +902,7 @@ class FeedingIt:
                 unreadItems = self.listing.getFeedNumberOfUnreadItems(key)
                 button.set_text(self.listing.getFeedTitle(key), self.listing.getFeedUpdateTime(key) + " / " 
                             + str(unreadItems) + " Unread Items")
-                label = button.child.child.get_children()[0].get_children()[1]
+                label = button.child.child.get_children()[1].get_children()[1]
                 if unreadItems == 0:
                     label.modify_fg(gtk.STATE_NORMAL, read_color)
                 else:
index dd3a924..716da87 100644 (file)
@@ -34,8 +34,9 @@ from dbus.mainloop.glib import DBusGMainLoop
 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
 #bus = dbus.SessionBus()
 
-from os import environ
+from os import environ, remove
 bus = dbus.bus.BusConnection(environ["DBUS_SESSION_BUS_ADDRESS"])
+from os.path import isfile
 
 color_style = gtk.rc_get_style_by_paths(gtk.settings_get_default() , 'GtkButton', 'osso-logical-colors', gtk.Button)
 active_color = color_style.lookup_color('ActiveTextColor')
@@ -43,6 +44,7 @@ default_color = color_style.lookup_color('DefaultTextColor')
 del color_style
 
 CONFIGDIR="/home/user/.feedingit/"
+SOURCE=CONFIGDIR + "source"
 
 #DBusConnection *hd_home_plugin_item_get_dbus_connection ( HDHomePluginItem *item, DBusBusType type, DBusError *error);
 #import ctypes
@@ -51,13 +53,22 @@ CONFIGDIR="/home/user/.feedingit/"
 
 class FeedingItHomePlugin(hildondesktop.HomePluginItem):
     def __init__(self):
+      __gsignals__ = {
+      'destroy' : 'override'
+      }
+
       try:
         hildondesktop.HomePluginItem.__init__(self)
         self.set_settings(True)
         self.connect("show-settings", self.show_settings)
         self.feed_list = {}
         self.total = 0
-        self.autoupdateID=False
+        if isfile(SOURCE):
+            file = open(SOURCE)
+            self.autoupdateId = int(file.read())
+            file.close() 
+        else:
+            self.autoupdateId=False
         
         vbox = gtk.VBox(False, 0)
         
@@ -102,6 +113,18 @@ class FeedingItHomePlugin(hildondesktop.HomePluginItem):
           file = open("/home/user/.feedingit/feedingit_widget.log", "a")
           traceback.print_exc(file=file)
           file.close()
+          
+    def do_destroy(self):
+        file = open("/home/user/.feedingit/feedingit_widget.log", "a")
+        file.write("Do_destroy: ")
+        if (not self.autoupdateId==False):
+            gobject.source_remove(self.autoupdateId)
+            self.autoupdateId=False
+            file.write("Destroyed %s\n" %self.autoupdateId)
+            remove(SOURCE)
+        hildondesktop.HomePluginItem.do_destroy(self)
+        file.write("End destroy\n")
+        file.close()
 
     def button_clicked(self, *widget):
         self.button.set_sensitive(False)
@@ -301,13 +324,24 @@ class FeedingItHomePlugin(hildondesktop.HomePluginItem):
 
     def setup_autoupdate(self):
         if (float(self.autoupdate) > 0):
-            if (not self.autoupdateID==False):
+            if (not self.autoupdateId==False):
+                file = open("/home/user/.feedingit/feedingit_widget.log", "a")
+                file.write("Disabling %s\n" % self.autoupdateId)
+                file.close()
                 gobject.source_remove(self.autoupdateId)
+                remove(SOURCE)
             self.autoupdateId = gobject.timeout_add_seconds(int(float(self.autoupdate)*3600), self.start_update)
+            file = open(SOURCE, "w")
+            file.write(str(self.autoupdateId))
+            file.close()
+            file = open("/home/user/.feedingit/feedingit_widget.log", "a")
+            file.write("Started %s\n" % self.autoupdateId)
+            file.close()
         else:
-            if (not self.autoupdateID==False):
-                gobject.disconnect(self.autoupdateId)
-                self.autoupdateID=False
+            if (not self.autoupdateId==False):
+                gobject.source_remove(self.autoupdateId)
+                self.autoupdateId=False
+                remove(SOURCE)
 
     def load_config(self):
             try:
index 59fa485..3a1ae3f 100644 (file)
@@ -149,6 +149,19 @@ class Feed:
         expiry = float(expiryTime) * 3600.
         # Check if the parse was succesful (number of entries > 0, else do nothing)
         if len(tmp["entries"])>0:
+           try:
+               f = urllib2.urlopen(urljoin(tmp["feed"]["link"],"/favicon.ico"))
+               data = f.read()
+               f.close()
+               outf = open(configdir+self.uniqueId+".d/favicon.ico", "w")
+               outf.write(data)
+               outf.close()
+               del data
+           except:
+                import traceback
+                traceback.print_exc()
+
+
            #reversedEntries = self.getEntries()
            #reversedEntries.reverse()
            if not isdir(configdir+self.uniqueId+".d"):
@@ -577,6 +590,13 @@ class Listing:
     def getListOfFeeds(self):
         return self.sortedKeys
     
+    def getFavicon(self, key):
+        filename = self.configdir+key+".d/favicon.ico"
+        if isfile(filename):
+            return filename
+        else:
+            return False
+    
     def addFeed(self, title, url):
         if not self.listOfFeeds.has_key(getId(title)):
             self.listOfFeeds[getId(title)] = {"title":title, "url":url, "unread":0, "updateTime":"Never"}
index 29f4bb7..b04fe7c 100644 (file)
@@ -31,30 +31,37 @@ import os
 import gobject
 
 CONFIGDIR="/home/user/.feedingit/"
-LOCK = CONFIGDIR + "update.lock"
 #DESKTOP_FILE = "/usr/share/applications/hildon-status-menu/feedingit_status.desktop"
+dbug = True
+
+from socket import setdefaulttimeout
+timeout = 5
+setdefaulttimeout(timeout)
+del timeout
 
 from updatedbus import UpdateServerObject, get_lock
 
 class Download(threading.Thread):
     def __init__(self, listing, config, dbusHandler):
+        global dbug
         threading.Thread.__init__(self)
         self.running = True
         self.listing = listing
         self.config = config
         self.dbusHandler = dbusHandler
-        self.dbug = open(CONFIGDIR+"dbug.log", "w")
-        self.dbug.flush()
+        if dbug:
+            self.dbug = open(CONFIGDIR+"dbug.log", "w")
         
     def run(self):
-        self.dbug.write("Starting updates")
-        self.dbug.flush()
+        global dbug
+        if dbug:
+            self.dbug.write("Starting updates\n")
         try:
             self.dbusHandler.UpdateStarted()
             (use_proxy, proxy) = self.config.getProxy()
             for key in self.listing.getListOfFeeds():
-                self.dbug.write("updating %s\n" %key)
-                self.dbug.flush()
+                if dbug:
+                    self.dbug.write("updating %s\n" %key)
                 try:
                     if use_proxy:
                         from urllib2 import install_opener, build_opener
@@ -73,22 +80,17 @@ class Download(threading.Thread):
                     break
             self.dbusHandler.UpdateFinished()
             self.dbusHandler.ArticleCountUpdated()
-            self.dbug.write("Dbus ArticleCountUpdated signal sent\n")
-            self.dbug.flush()
-            try:
-                os.remove(LOCK)
-                #os.remove(DESKTOP_FILE)
-            except:
-                pass
+            if dbug:
+                self.dbug.write("Dbus ArticleCountUpdated signal sent\n")
         except:
             pass
         self.listing.saveConfig()
-        self.dbug.write("About to main_quit\n")
-        self.dbug.flush()
+        if dbug:
+            self.dbug.write("About to main_quit\n")
         mainloop.quit()
-        file.write("After main_quit\n")
-        self.dbug.flush()
-        self.dbug.close()
+        if dbug:
+            self.dbug.write("After main_quit\n")
+            self.dbug.close()
 
 class FeedUpdate():
     def __init__(self):