changeset 18731:6976a6dae441

Add support for auto-refreshing. There should be some way to change the refresh timeout for each feed, though.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Tue, 31 Jul 2007 12:03:46 +0000
parents 54a28e05e8af
children a03c8b79f39b
files finch/libgnt/pygnt/example/rss/gnthtml.py finch/libgnt/pygnt/example/rss/gntrss.py
diffstat 2 files changed, 42 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/finch/libgnt/pygnt/example/rss/gnthtml.py	Tue Jul 31 12:01:42 2007 +0000
+++ b/finch/libgnt/pygnt/example/rss/gnthtml.py	Tue Jul 31 12:03:46 2007 +0000
@@ -41,7 +41,7 @@
         self.close()
 
     def unknown_starttag(self, tag, attrs):
-        if tag in ["b", "i", "blockquote"]:
+        if tag in ["b", "i", "blockquote", "strong"]:
             self.flag = self.flag | gnt.TEXT_FLAG_BOLD
         elif tag in ["p", "hr", "br"]:
             self.view.append_text_with_flags("\n", self.flag)
@@ -49,7 +49,7 @@
             print tag
 
     def unknown_endtag(self, tag):
-        if tag in ["b", "i", "blockquote"]:
+        if tag in ["b", "i", "blockquote", "strong"]:
             self.flag = self.flag & ~gnt.TEXT_FLAG_BOLD
         elif tag in ["p", "hr", "br"]:
             self.view.append_text_with_flags("\n", self.flag)
--- a/finch/libgnt/pygnt/example/rss/gntrss.py	Tue Jul 31 12:01:42 2007 +0000
+++ b/finch/libgnt/pygnt/example/rss/gntrss.py	Tue Jul 31 12:03:46 2007 +0000
@@ -56,7 +56,8 @@
             self.date_parsed = feedparser._parse_date(self.date)
 
         self.title = item['title']
-        self.summary = item['summary']
+        sum = item['summary']
+        self.summary = item['summary'].encode('utf8')
         self.link = item['link']
         self.parent = parent
         self.unread = True
@@ -111,16 +112,20 @@
         'added' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_OBJECT,))
     }
 
-    def __init__(self, url):
+    def __init__(self, feed):
         self.__gobject_init__()
+        url = feed['link']
+        name = feed['name']
         self.url = url           # The url of the feed itself
         self.link = url          # The web page associated with the feed
         self.desc = url
-        self.title = url
+        self.title = (name, url)[not name]
+        self.customtitle = name
         self.unread = 0
         self.items = []
         self.hash = {}
         self.pending = False
+        self._refresh = {'time' : 30, 'id' : 0}
 
     def do_set_property(self, property, value):
         if property.name == 'link':
@@ -162,11 +167,13 @@
                 self.hash[item_hash(item)] = itm
                 unread = unread + 1
 
+        if unread != self.unread:
+            self.set_property('unread', unread)
+
         for hv in tmp:
             tmp[hv].remove()
+            "Also notify the UI about the count change"
 
-        if unread != self.unread:
-            self.set_property('unread', unread)
         self.pending = False
         return False
 
@@ -175,11 +182,25 @@
             return
         self.pending = True
         FeedReader(self).run()
+        return True
 
     def mark_read(self):
         for item in self.items:
             item.mark_unread(False)
 
+    def set_auto_refresh(self, auto):
+        if auto:
+            if self._refresh['id']:
+                return
+            if self._refresh['time'] < 1:
+                self._refresh['time'] = 1
+            self.id = gobject.timeout_add(self._refresh['time'] * 1000 * 60, self.refresh)
+        else:
+            if not self._refresh['id']:
+                return
+            gobject.source_remove(self._refresh['id'])
+            self._refresh['id'] = 0
+
 gobject.type_register(Feed)
 
 """
@@ -208,13 +229,20 @@
         gobject.child_watch_add(self.pid, self.reap_child)
 
 feeds = []
-urls = ("http://rss.slashdot.org/Slashdot/slashdot",
-        "http://kerneltrap.org/node/feed",
-        "http://pidgin.im/rss.php",
-        "http://www.formula1.com/rss/news/latest.rss",
-        "http://www.pheedo.com/f/freshmeatnet_announcements_unix",
-        "http://www.cricinfo.com/rss/livescores.xml"
-        )
+urls = (
+    {'name': '/.',
+     'link': "http://rss.slashdot.org/Slashdot/slashdot"},
+    {'name': 'KernelTrap',
+     'link': "http://kerneltrap.org/node/feed"},
+    {'name': None,
+     'link': "http://pidgin.im/rss.php"},
+    {'name': "F1",
+     'link': "http://www.formula1.com/rss/news/latest.rss"},
+    {'name': "Freshmeat",
+     'link': "http://www.pheedo.com/f/freshmeatnet_announcements_unix"},
+    {'name': "Cricinfo",
+     'link': "http://www.cricinfo.com/rss/livescores.xml"}
+)
 
 for url in urls:
     feed = Feed(url)