0.6.1-5 ArchivedArticles can now be purged manually
authorYves <ymarcoz@n900-sdk.(none)>
Fri, 30 Apr 2010 05:18:41 +0000 (22:18 -0700)
committerYves <ymarcoz@n900-sdk.(none)>
Fri, 30 Apr 2010 05:18:41 +0000 (22:18 -0700)
debian/changelog
src/FeedingIt.py
src/feedingit_widget.py
src/rss.py

index 2f31e00..bed2810 100644 (file)
@@ -1,3 +1,23 @@
+feedingit (0.6.1-5) unstable; urgency=low
+
+  * Small performance fixes
+  * Bugfix for unread messages
+  * ArchivedArticles can now be cleaned up manually
+
+ -- Yves <yves@marcoz.org>  Thu, 29 Apr 2010 22:18:19 -0800
+
+feedingit (0.6.1-3) unstable; urgency=low
+
+  * Fixed module import issue in widget
+
+ -- Yves <yves@marcoz.org>  Sun, 25 Apr 2010 23:13:19 -0800
+
+feedingit (0.6.1-2) unstable; urgency=low
+
+  * Some improvements for Archived Articles
+
+ -- Yves <yves@marcoz.org>  Sun, 25 Apr 2010 23:13:19 -0800
+
 feedingit (0.6.1-1) unstable; urgency=low
 
   * Now use dbus as lock mechanisms
index 27f978a..d1deb5a 100644 (file)
@@ -46,6 +46,8 @@ from cgi import escape
 from rss import Listing
 from opml import GetOpmlData, ExportOpmlData
 
+from urllib2 import install_opener, build_opener
+
 from socket import setdefaulttimeout
 timeout = 5
 setdefaulttimeout(timeout)
@@ -161,8 +163,6 @@ class Download(Thread):
         key_lock = get_lock(self.key)
         if key_lock != None:
             if use_proxy:
-                from urllib2 import install_opener, build_opener
-                install_opener(build_opener(proxy))
                 self.listing.updateFeed(self.key, self.config.getExpiry(), proxy=proxy, imageCache=self.config.getImageCache() )
             else:
                 self.listing.updateFeed(self.key, self.config.getExpiry(), imageCache=self.config.getImageCache() )
@@ -181,6 +181,15 @@ class DownloadBar(gtk.ProgressBar):
             self.config = config
             self.current = 0
             self.single = single
+            (use_proxy, proxy) = self.config.getProxy()
+            if use_proxy:
+                opener = build_opener(proxy)
+                opener.addheaders = [('User-agent', 'Mozilla/5.0 (compatible; Maemo 5;) FeedingIt 0.6.1')]
+                install_opener(opener)
+            else:
+                opener = build_opener()
+                opener.addheaders = [('User-agent', 'Mozilla/5.0 (compatible; Maemo 5;) FeedingIt 0.6.1')]
+                install_opener(opener)
 
             if self.total>0:
                 self.set_text("Updating...")
@@ -373,6 +382,7 @@ class DisplayArticle(hildon.StackableWindow):
         #self.set_title(feed.getTitle(id))
         self.set_title(self.listing.getFeedTitle(key))
         self.config = config
+        self.set_for_removal = False
         
         # Init the article display
         #if self.config.getWebkitSupport():
@@ -423,9 +433,14 @@ class DisplayArticle(hildon.StackableWindow):
         button.connect("clicked", self._signal_link_clicked, self.feed.getExternalLink(self.id))
         menu.append(button)
         
-        button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
-        button.set_label("Add to Archived Articles")
-        button.connect("clicked", self.archive_button)
+        if key == "ArchivedArticles":
+            button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
+            button.set_label("Remove from Archived Articles")
+            button.connect("clicked", self.remove_archive_button)
+        else:
+            button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
+            button.set_label("Add to Archived Articles")
+            button.connect("clicked", self.archive_button)
         menu.append(button)
         
         self.set_app_menu(menu)
@@ -476,7 +491,10 @@ class DisplayArticle(hildon.StackableWindow):
 
     def destroyWindow(self, *args):
         self.disconnect(self.destroyId)
-        self.emit("article-closed", self.id)
+        if self.set_for_removal:
+            self.emit("article-deleted", self.id)
+        else:
+            self.emit("article-closed", self.id)
         #self.imageDownloader.stopAll()
         self.destroy()
         
@@ -488,6 +506,9 @@ class DisplayArticle(hildon.StackableWindow):
         # Call the listing.addArchivedArticle
         self.listing.addArchivedArticle(self.key, self.id)
         
+    def remove_archive_button(self, *widget):
+        self.set_for_removal = True
+        
     #def reloadArticle(self, *widget):
     #    if threading.activeCount() > 1:
             # Image thread are still running, come back in a bit
@@ -516,7 +537,7 @@ class DisplayArticle(hildon.StackableWindow):
 
 
 class DisplayFeed(hildon.StackableWindow):
-    def __init__(self, listing, feed, title, key, config):
+    def __init__(self, listing, feed, title, key, config, updateDbusHandler):
         hildon.StackableWindow.__init__(self)
         self.listing = listing
         self.feed = feed
@@ -524,10 +545,11 @@ class DisplayFeed(hildon.StackableWindow):
         self.set_title(title)
         self.key=key
         self.config = config
+        self.updateDbusHandler = updateDbusHandler
         
         self.downloadDialog = False
         
-        self.listing.setCurrentlyDisplayedFeed(self.key)
+        #self.listing.setCurrentlyDisplayedFeed(self.key)
         
         self.disp = False
         
@@ -541,6 +563,13 @@ class DisplayFeed(hildon.StackableWindow):
         button.set_label("Mark All As Read")
         button.connect("clicked", self.buttonReadAllClicked)
         menu.append(button)
+        
+        if key=="ArchivedArticles":
+            button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
+            button.set_label("Purge Read Articles")
+            button.connect("clicked", self.buttonPurgeArticles)
+            menu.append(button)
+        
         self.set_app_menu(menu)
         menu.show_all()
         
@@ -549,12 +578,13 @@ class DisplayFeed(hildon.StackableWindow):
         self.connect("destroy", self.destroyWindow)
         
     def destroyWindow(self, *args):
-        self.feed.saveUnread(CONFIGDIR)
+        #self.feed.saveUnread(CONFIGDIR)
+        gobject.idle_add(self.feed.saveUnread, CONFIGDIR)
         self.listing.updateUnread(self.key, self.feed.getNumberOfUnreadItems())
         self.emit("feed-closed", self.key)
         self.destroy()
         #gobject.idle_add(self.feed.saveFeed, CONFIGDIR)
-        self.listing.closeCurrentlyDisplayedFeed()
+        #self.listing.closeCurrentlyDisplayedFeed()
 
     def displayFeed(self):
         self.vboxFeed = gtk.VBox(False, 10)
@@ -613,10 +643,19 @@ class DisplayFeed(hildon.StackableWindow):
             self.disp.show_all()
         
         self.ids = []
+        if self.key == "ArchivedArticles":
+            self.ids.append(self.disp.connect("article-deleted", self.onArticleDeleted))
         self.ids.append(self.disp.connect("article-closed", self.onArticleClosed))
         self.ids.append(self.disp.connect("article-next", self.nextArticle))
         self.ids.append(self.disp.connect("article-previous", self.previousArticle))
 
+    def buttonPurgeArticles(self, *widget):
+        self.clear()
+        self.feed.purgeReadArticles()
+        self.feed.saveUnread(CONFIGDIR)
+        self.feed.saveFeed(CONFIGDIR)
+        self.displayFeed()
+
     def destroyArticle(self, handle):
         handle.destroyWindow()
 
@@ -639,6 +678,13 @@ class DisplayFeed(hildon.StackableWindow):
         label.modify_font(FontDescription(self.config.getReadFont()))
         label.modify_fg(gtk.STATE_NORMAL, read_color) # gtk.gdk.color_parse("white"))
         self.buttons[index].show()
+        
+    def onArticleDeleted(self, object, index):
+        self.clear()
+        self.feed.removeArticle(index)
+        self.feed.saveUnread(CONFIGDIR)
+        self.feed.saveFeed(CONFIGDIR)
+        self.displayFeed()
 
     def button_update_clicked(self, button):
         #bar = DownloadBar(self, self.listing, [self.key,], self.config ) 
@@ -858,13 +904,19 @@ class FeedingIt:
         except:
             # If feed_lock doesn't exist, we can open the feed, else we do nothing
             self.feed_lock = get_lock(key)
-            self.disp = DisplayFeed(self.listing, self.listing.getFeed(key), self.listing.getFeedTitle(key), key, self.config)
+            self.disp = DisplayFeed(self.listing, self.listing.getFeed(key), self.listing.getFeedTitle(key), key, self.config, self.updateDbusHandler)
             self.disp.connect("feed-closed", self.onFeedClosed)
 
     def onFeedClosed(self, object, key):
+        #self.listing.saveConfig()
+        #del self.feed_lock
+        gobject.idle_add(self.onFeedClosedTimeout)
+        self.refreshList()
+        #self.updateDbusHandler.ArticleCountUpdated()
+        
+    def onFeedClosedTimeout(self):
         self.listing.saveConfig()
         del self.feed_lock
-        self.refreshList()
         self.updateDbusHandler.ArticleCountUpdated()
      
     def run(self):
@@ -897,6 +949,10 @@ class FeedingIt:
         # Need to check for internet connection
         # If no internet connection, try again in 10 minutes:
         # gobject.timeout_add(int(5*3600000), self.automaticUpdate)
+        file = open("/home/user/.feedingit/feedingit_widget.log", "a")
+        from time import localtime, strftime
+        file.write("App: %s\n" % strftime("%a, %d %b %Y %H:%M:%S +0000", localtime()))
+        file.close()
         self.button_update_clicked(None, None)
         return True
     
@@ -919,6 +975,7 @@ class FeedingIt:
 if __name__ == "__main__":
     gobject.signal_new("feed-closed", DisplayFeed, gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
     gobject.signal_new("article-closed", DisplayArticle, gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
+    gobject.signal_new("article-deleted", DisplayArticle, gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
     gobject.signal_new("article-next", DisplayArticle, gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
     gobject.signal_new("article-previous", DisplayArticle, gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
     gobject.signal_new("download-done", DownloadBar, gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
index c6eeb78..9a19a87 100644 (file)
@@ -271,10 +271,9 @@ class FeedingItHomePlugin(hildondesktop.HomePluginItem):
     def start_update(self):
         try:
             if self.autoupdate >0:
-                import traceback
                 file = open("/home/user/.feedingit/feedingit_widget.log", "a")
-                from time import gmtime, strftime
-                file.write(strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
+                from time import localtime, strftime
+                file.write("Widget: %s\n" % strftime("%a, %d %b %Y %H:%M:%S +0000", localtime()))
                 file.close()
                 remote_object = bus.get_object("org.marcoz.feedingit", # Connection name
                               "/org/marcoz/feedingit/update" # Object's path
index 61e910b..e276116 100644 (file)
@@ -32,7 +32,7 @@ import feedparser
 import time
 import urllib2
 from BeautifulSoup import BeautifulSoup
-from urlparse import urlparse
+from urlparse import urljoin
 
 #CONFIGDIR="/home/user/.feedingit/"
 
@@ -65,16 +65,18 @@ class ImageHandler:
         filename = self.configdir+key+".d/"+getId(url)
         if not isfile(filename):
             try:
-                if url.startswith("http"):
-                    f = urllib2.urlopen(url)
-                else:
-                    f = urllib2.urlopen(baseurl+"/"+url)
+                #if url.startswith("http"):
+                #    f = urllib2.urlopen(url)
+                #else:
+                f = urllib2.urlopen(urljoin(baseurl,url))
                 outf = open(filename, "w")
                 outf.write(f.read())
                 f.close()
                 outf.close()
             except:
-                print "Could not download" + url
+                print "Could not download " + url
+        else:
+            open(filename,"a").close()  # "Touch" the file
         if filename in self.images:
             self.images[filename] += 1
         else:
@@ -172,7 +174,7 @@ class Feed:
                if not id in self.ids:
                    soup = BeautifulSoup(self.getArticle(tmpEntry)) #tmpEntry["content"])
                    images = soup('img')
-                   baseurl = ''.join(urlparse(tmpEntry["link"])[:-1])
+                   baseurl = tmpEntry["link"]
                    if imageCache:
                       for img in images:
                           try:
@@ -180,7 +182,7 @@ class Feed:
                             img['src']=filename
                             tmpEntry["images"].append(filename)
                           except:
-                              print "Error downloading image %s" %img
+                              print "Error downloading image %s" % img
                    tmpEntry["contentLink"] = configdir+self.uniqueId+".d/"+id+".html"
                    file = open(tmpEntry["contentLink"], "w")
                    file.write(soup.prettify())
@@ -222,6 +224,10 @@ class Feed:
                    self.readItems[id] = False
                if self.readItems[id]==False:
                   tmpUnread = tmpUnread + 1
+           keys = self.readItems.keys()
+           for id in keys:
+               if not id in self.ids:
+                   del self.readItems[id]
            del tmp
            self.countUnread = tmpUnread
            self.updateTime = time.asctime()
@@ -404,24 +410,9 @@ class ArchivedArticles(Feed):
                     f.close()
                     soup = BeautifulSoup(html)
                     images = soup('img')
-                    baseurl = ''.join(urlparse(entry["link"])[:-1])
+                    baseurl = entry["link"]
                     for img in images:
                         filename = self.imageHandler.addImage(self.uniqueId, baseurl, img['src'])
-                        #filename = configdir+self.uniqueId+".d/"+getId(img['src'])
-                        #if not isfile(filename):
-                        #    try:
-                        #        if img['src'].startswith("http"):
-                        #            f = urllib2.urlopen(img['src'])
-                        #        else:
-                        #            f = urllib2.urlopen(baseurl+"/"+img['src'])
-                        #            #print baseurl+"/"+img['src']
-                        #        print filename
-                        #        outf = open(filename, "w")
-                        #        outf.write(f.read())
-                        #        f.close()
-                        #        outf.close()
-                        #    except:
-                        #        print "Could not download" + img['src']
                         img['src']=filename
                         entry["images"].append(filename)
                     entry["contentLink"] = configdir+self.uniqueId+".d/"+id+".html"
@@ -434,16 +425,26 @@ class ArchivedArticles(Feed):
                         self.setEntryUnread(id)
                 #except:
                 #    pass
-            currentTime = time.time()
-            expiry = float(expiryTime) * 3600
-            if currentTime - entry["time"] > expiry:
-                if self.isEntryRead(id):
-                    self.removeEntry(id)
-                else:
-                    if currentTime - entry["time"] > 2*expiry:
-                        self.removeEntry(id)
+            #currentTime = time.time()
+            #expiry = float(expiryTime) * 3600
+            #if currentTime - entry["time"] > expiry:
+            #    if self.isEntryRead(id):
+            #        self.removeEntry(id)
+            #    else:
+            #        if currentTime - entry["time"] > 2*expiry:
+            #            self.removeEntry(id)
         self.updateTime = time.asctime()
         self.saveFeed(configdir)
+        
+    def purgeReadArticles(self):
+        ids = self.getIds()
+        for id in ids:
+            entry = self.entries[id]
+            if self.isEntryRead(id):
+                self.removeEntry(id)
+                
+    def removeArticle(self, id):
+        self.removeEntry(id)
 
     def getArticle(self, index):
         self.setEntryRead(index)
@@ -478,7 +479,7 @@ class Listing:
                 self.sortedKeys.remove("font")
             self.sortedKeys.sort(key=lambda obj: self.getFeedTitle(obj))
         list = self.sortedKeys[:]
-        self.closeCurrentlyDisplayedFeed()
+        #self.closeCurrentlyDisplayedFeed()
 
     def addArchivedArticle(self, key, index):
         feed = self.getFeed(key)
@@ -600,13 +601,6 @@ class Listing:
         index2 = (index+1)%len(self.sortedKeys)
         self.sortedKeys[index] = self.sortedKeys[index2]
         self.sortedKeys[index2] = key
-        
-    def setCurrentlyDisplayedFeed(self, key):
-        self.currentlyDisplayedFeed = key
-    def closeCurrentlyDisplayedFeed(self):
-        self.currentlyDisplayedFeed = False
-    def getCurrentlyDisplayedFeed(self):
-        return self.currentlyDisplayedFeed
     
 if __name__ == "__main__":
     listing = Listing('/home/user/.feedingit/')