psa: remove old event feed items
[feedingit] / src / FeedingIt.py
index 926f139..f9ab155 100644 (file)
@@ -25,7 +25,6 @@ __description__ = 'A simple RSS Reader for Maemo 5'
 # ============================================================================
 
 import gtk
-from pango import FontDescription
 import pango
 import hildon
 #import gtkhtml2
@@ -40,7 +39,6 @@ from os import mkdir, remove, stat, environ
 import gobject
 from aboutdialog import HeAboutDialog
 from portrait import FremantleRotation
-from threading import Thread, activeCount
 from feedingitdbus import ServerObject
 from config import Config
 from cgi import escape
@@ -151,6 +149,28 @@ def notify(message):
         get_iface()
         doit()
 
+def open_in_browser(link):
+    bus = dbus.SessionBus()
+    b_proxy = bus.get_object("com.nokia.osso_browser",
+                             "/com/nokia/osso_browser/request")
+    b_iface = dbus.Interface(b_proxy, 'com.nokia.osso_browser')
+
+    notify("Opening %s" % link)
+
+    # We open the link asynchronously: if the web browser is not
+    # already running, this can take a while.
+    def error_handler():
+        """
+        Something went wrong opening the URL.
+        """
+        def e(exception):
+            notify("Error opening %s: %s" % (link, str(exception)))
+        return e
+
+    b_iface.open_new_window(link,
+                            reply_handler=lambda *args: None,
+                            error_handler=error_handler())
+
 ##
 # Removes HTML or XML character references and entities from a text string.
 #
@@ -806,26 +826,7 @@ class DisplayArticle(hildon.StackableWindow):
         if link == None:
             link = self.currentUrl
 
-        bus = dbus.SessionBus()
-        b_proxy = bus.get_object("com.nokia.osso_browser",
-                                 "/com/nokia/osso_browser/request")
-        b_iface = dbus.Interface(b_proxy, 'com.nokia.osso_browser')
-
-        notify("Opening %s" % link)
-
-        # We open the link asynchronously: if the web browser is not
-        # already running, this can take a while.
-        def error_handler():
-            """
-            Something went wrong opening the URL.
-            """
-            def e(exception):
-                notify("Error opening %s: %s" % (link, str(exception)))
-            return e
-
-        b_iface.open_new_window(link,
-                                reply_handler=lambda *args: None,
-                                error_handler=error_handler())
+        open_in_browser(link)
 
 class DisplayFeed(hildon.StackableWindow):
     def __init__(self, listing, config):
@@ -1159,51 +1160,18 @@ class FeedingIt:
         self.listing = Listing(self.config, CONFIGDIR)
 
         self.downloadDialog = False
-        
-        menu = hildon.AppMenu()
-        # Create a button and add it to the menu
-        button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
-        button.set_label("Update feeds")
-        button.connect("clicked", self.button_update_clicked, "All")
-        menu.append(button)
-        
-        button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
-        button.set_label("Mark all as read")
-        button.connect("clicked", self.button_markAll)
-        menu.append(button)
-
-        button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
-        button.set_label("Add new feed")
-        button.connect("clicked", lambda b: self.addFeed())
-        menu.append(button)
-
-        button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
-        button.set_label("Manage subscriptions")
-        button.connect("clicked", self.button_organize_clicked)
-        menu.append(button)
 
-        button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
-        button.set_label("Settings")
-        button.connect("clicked", self.button_preferences_clicked)
-        menu.append(button)
-       
-        button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
-        button.set_label("About")
-        button.connect("clicked", self.button_about_clicked)
-        menu.append(button)
-        
-        self.window.set_app_menu(menu)
-        menu.show_all()
-        
-        #self.feedWindow = hildon.StackableWindow()
-        #self.articleWindow = hildon.StackableWindow()
         self.introLabel.destroy()
         self.pannableListing = hildon.PannableArea()
+
+        # The main area is a view consisting of an icon and two
+        # strings.  The view is bound to the Listing's database via a
+        # TreeStore.
+
         self.feedItems = gtk.TreeStore(gtk.gdk.Pixbuf, str, str)
         self.feedList = gtk.TreeView(self.feedItems)
         self.feedList.connect('row-activated', self.on_feedList_row_activated)
-        #self.feedList.set_enable_tree_lines(True)                                                                                           
-        #self.feedList.set_show_expanders(True)
+
         self.pannableListing.add(self.feedList)
 
         icon_renderer = gtk.CellRendererPixbuf()
@@ -1220,12 +1188,10 @@ class FeedingIt:
         self.mainVbox.show_all()
 
         self.displayListing()
-        self.autoupdate = False
-        self.checkAutoUpdate()
         
         hildon.hildon_gtk_window_set_progress_indicator(self.window, 0)
         gobject.idle_add(self.late_init)
-        
+
     def update_progress(self, percent_complete,
                         completed, in_progress, queued,
                         bytes_downloaded, bytes_updated, bytes_per_second,
@@ -1246,6 +1212,43 @@ class FeedingIt:
             self.displayListing()
 
     def late_init(self):
+        # Finish building the GUI.
+        menu = hildon.AppMenu()
+        # Create a button and add it to the menu
+        button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
+        button.set_label("Update feeds")
+        button.connect("clicked", self.button_update_clicked, "All")
+        menu.append(button)
+        
+        button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
+        button.set_label("Mark all as read")
+        button.connect("clicked", self.button_markAll)
+        menu.append(button)
+
+        button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
+        button.set_label("Add new feed")
+        button.connect("clicked", lambda b: self.addFeed())
+        menu.append(button)
+
+        button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
+        button.set_label("Manage subscriptions")
+        button.connect("clicked", self.button_organize_clicked)
+        menu.append(button)
+
+        button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
+        button.set_label("Settings")
+        button.connect("clicked", self.button_preferences_clicked)
+        menu.append(button)
+       
+        button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
+        button.set_label("About")
+        button.connect("clicked", self.button_about_clicked)
+        menu.append(button)
+        
+        self.window.set_app_menu(menu)
+        menu.show_all()
+
+        # Initialize the DBus interface.
         self.dbusHandler = ServerObject(self)
         bus = dbus.SessionBus()
         bus.add_signal_receiver(handler_function=self.update_progress,
@@ -1254,13 +1257,54 @@ class FeedingIt:
                                 dbus_interface='org.marcoz.feedingit',
                                 path='/org/marcoz/feedingit/update')
 
+        # Check whether auto-update is enabled.
+        self.autoupdate = False
+        #self.checkAutoUpdate()
+
         gobject.idle_add(self.build_feed_display)
+        gobject.idle_add(self.check_for_woodchuck)
 
     def build_feed_display(self):
         if not hasattr(self, 'disp'):
             self.disp = DisplayFeed(self.listing, self.config)
             self.disp.connect("feed-closed", self.onFeedClosed)
 
+    def check_for_woodchuck(self):
+        if self.config.getAskedAboutWoodchuck():
+            return
+
+        try:
+            import woodchuck
+            # It is already installed successfully.
+            self.config.setAskedAboutWoodchuck(True)
+            return
+        except ImportError:
+            pass
+
+        note = hildon.hildon_note_new_confirmation(
+            self.window,
+            "\nFeedingIt can use Woodchuck, a network transfer "
+            + "daemon, to schedule transfers more intelligently.\n"
+            + "You can also use the FeedingIt widget for time-based\n"
+            + "updates.\n\n"
+            + "Install Woodchuck?\n")
+        note.set_button_texts("Install", "Cancel")
+        note.add_button("Learn More", 42)
+
+        while True:
+            response = gtk.Dialog.run(note)
+            if response == 42:
+                open_in_browser("http://hssl.cs.jhu.edu/~neal/woodchuck")
+                continue
+
+            break
+
+        note.destroy()
+
+        if response == gtk.RESPONSE_OK:
+            open_in_browser("http://maemo.org/downloads/product/raw/Maemo5/murmeltier?get_installfile")
+        self.config.setAskedAboutWoodchuck(True)
+
     def button_markAll(self, button):
         for key in self.listing.getListOfFeeds():
             feed = self.listing.getFeed(key)