Changed external page version, and some widget usability modifications
[feedingit] / src / config.py
index a38787f..091dcb9 100644 (file)
@@ -30,12 +30,12 @@ from gobject import idle_add
 from gconf import client_get_default
 from urllib2 import ProxyHandler
 
-VERSION = "0.6.1"
+VERSION = "52"
 
 section = "FeedingIt"
-ranges = { "updateInterval":[0.5, 1, 2, 4, 12, 24], "expiry":[24, 48, 72], "fontSize":range(12,24), "orientation":["Automatic", "Landscape", "Portrait"], "artFontSize":[10, 12, 14, 16, 18, 20]}
-titles = {"updateInterval":"Auto-update Interval", "expiry":"Expiry For Articles", "fontSize":"Font Size For Article Listing", "orientation":"Display Orientation", "artFontSize":"Font Size For Articles"}
-subtitles = {"updateInterval":"Update every %s hours", "expiry":"Delete articles after %s hours", "fontSize":"%s pixels", "orientation":"%s", "artFontSize":"%s pixels"}
+ranges = { "updateInterval":[0.5, 1, 2, 4, 12, 24], "expiry":[24, 48, 72], "fontSize":range(12,24), "orientation":["Automatic", "Landscape", "Portrait"], "artFontSize":[10, 12, 14, 16, 18, 20], "feedsort":["Manual", "Most unread", "Least unread", "Most recent", "Least recent"] }
+titles = {"updateInterval":"Auto-update interval", "expiry":"Delete articles", "fontSize":"List font size", "orientation":"Display orientation", "artFontSize":"Article font size","feedsort":"Feed sort order"}
+subtitles = {"updateInterval":"Every %s hours", "expiry":"After %s hours", "fontSize":"%s pixels", "orientation":"%s", "artFontSize":"%s pixels", "feedsort":"%s"}
 
 class Config():
     def __init__(self, parent, configFilename):
@@ -43,30 +43,35 @@ class Config():
         self.parent = parent
         # Load config
         self.loadConfig()
-        
+
+        # Backup current settings for later restore
+        self.config_backup = dict(self.config)
+        self.do_restore_backup = True
+
+    def on_save_button_clicked(self, button):
+        self.do_restore_backup = False
+        self.window.destroy()
+
     def createDialog(self):
         
-        self.window = gtk.Dialog("Preferences", self.parent)
-        self.window.set_default_size(-1, 600)
+        self.window = gtk.Dialog("Settings", self.parent)
+        self.window.set_geometry_hints(min_height=600)
+
+        save_button = self.window.add_button(gtk.STOCK_SAVE, gtk.RESPONSE_OK)
+        save_button.connect('clicked', self.on_save_button_clicked)
+        #self.window.set_default_size(-1, 600)
         panArea = hildon.PannableArea()
         
-        vbox = gtk.VBox(False, 10)
+        vbox = gtk.VBox(False, 2)
         self.buttons = {}
 
-        button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
-        button.set_label("View Known Issues and Tips")
-        button.connect("clicked", self.button_tips_clicked)
-        button.set_alignment(0,0,1,1)
-        vbox.pack_start(button, expand=False)  
+        def heading(text):
+            l = gtk.Label()
+            l.set_size_request(-1, 6)
+            vbox.pack_start(l, expand=False)
+            vbox.pack_start(gtk.Frame(text), expand=False)
 
-        button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
-        button.set_label("Image Caching Enabled")
-        button.set_active(self.config["imageCache"])
-        button.connect("toggled", self.button_toggled, "imageCache")
-        vbox.pack_start(button, expand=False)      
-
-        settings = ["fontSize", "artFontSize", "expiry", "orientation", "updateInterval",]
-        for setting in settings:
+        def add_setting(setting):
             picker = hildon.PickerButton(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
             selector = self.create_selector(ranges[setting], setting)
             picker.set_selector(selector)
@@ -76,13 +81,18 @@ class Config():
             picker.set_alignment(0,0,1,1)
             self.buttons[setting] = picker
             vbox.pack_start(picker, expand=False)
-        
-        button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
-        button.set_label("Auto-update Enabled")
-        button.set_active(self.config["autoupdate"])
-        button.connect("toggled", self.button_toggled, "autoupdate")
-        vbox.pack_start(button, expand=False)
 
+        button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
+        button.set_label("View Known Issues and Tips")
+        button.connect("clicked", self.button_tips_clicked)
+        button.set_alignment(0,0,1,1)
+        vbox.pack_start(button, expand=False)  
+
+        heading('Display')
+        add_setting('fontSize')
+        add_setting('artFontSize')
+        add_setting('orientation')
+        add_setting('feedsort')
         button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
         button.set_label("Hide read feeds")
         button.set_active(self.config["hidereadfeeds"])
@@ -94,18 +104,42 @@ class Config():
         button.set_active(self.config["hidereadarticles"])
         button.connect("toggled", self.button_toggled, "hidereadarticles")
         vbox.pack_start(button, expand=False)
-        
+
+
+        heading('Updating')
+        button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
+        button.set_label("Automatically update feeds")
+        button.set_active(self.config["autoupdate"])
+        button.connect("toggled", self.button_toggled, "autoupdate")
+        vbox.pack_start(button, expand=False)
+        add_setting('updateInterval')
+        add_setting('expiry')
+
+        heading('Network')
+        button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
+        button.set_label('Cache images')
+        button.set_active(self.config["imageCache"])
+        button.connect("toggled", self.button_toggled, "imageCache")
+        vbox.pack_start(button, expand=False)
+
         button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
-        button.set_label("Proxy Support Enabled")
+        button.set_label("Use HTTP proxy")
         button.set_active(self.config["proxy"])
         button.connect("toggled", self.button_toggled, "proxy")
         vbox.pack_start(button, expand=False)
         
+        button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
+        button.set_label('Open links in external browser')
+        button.set_active(self.config["extBrowser"])
+        button.connect("toggled", self.button_toggled, "extBrowser")
+        vbox.pack_start(button, expand=False)
+        
         panArea.add_with_viewport(vbox)
         
-        self.window.vbox.add(panArea)        
+        self.window.vbox.add(panArea)
         self.window.connect("destroy", self.onExit)
         #self.window.add(self.vbox)
+        self.window.set_default_size(-1, 600)
         self.window.show_all()
         return self.window
 
@@ -114,9 +148,15 @@ class Config():
         bus = dbus.SessionBus()
         proxy = bus.get_object("com.nokia.osso_browser", "/com/nokia/osso_browser/request")
         iface = dbus.Interface(proxy, 'com.nokia.osso_browser')
-        iface.open_new_window("http://feedingit.marcoz.org/%s.html" % VERSION)
+        iface.open_new_window("http://feedingit.marcoz.org/news/?page_id=%s" % VERSION)
 
     def onExit(self, *widget):
+        # When the dialog is closed without hitting
+        # the "Save" button, restore the configuration
+        if self.do_restore_backup:
+            print 'Restoring configuration'
+            self.config = self.config_backup
+
         self.saveConfig()
         self.window.destroy()
 
@@ -169,6 +209,14 @@ class Config():
         except:
             self.config["hidereadfeeds"] = False
             self.config["hidereadarticles"] = False
+        try:
+            self.config["extBrowser"] = configParser.getboolean(section, "extBrowser")
+        except:
+            self.config["extBrowser"] = False
+        try:
+            self.config["feedsort"] = configParser.get(section, "feedsort")
+        except:
+            self.config["feedsort"] = "Manual"
         
     def saveConfig(self):
         configParser = RawConfigParser()
@@ -183,6 +231,8 @@ class Config():
         configParser.set(section, 'proxy', str(self.config["proxy"]))
         configParser.set(section, 'hidereadfeeds', str(self.config["hidereadfeeds"]))
         configParser.set(section, 'hidereadarticles', str(self.config["hidereadarticles"]))
+        configParser.set(section, 'extBrowser', str(self.config["extBrowser"]))
+        configParser.set(section, 'feedsort', str(self.config["feedsort"]))
 
         # Writing our configuration file
         file = open(self.configFilename, 'wb')
@@ -234,3 +284,7 @@ class Config():
         return self.config["hidereadfeeds"]
     def getHideReadArticles(self):
         return self.config["hidereadarticles"]
+    def getOpenInExternalBrowser(self):
+        return self.config["extBrowser"]
+    def getFeedSortOrder(self):
+        return self.config["feedsort"]