Added proxy support
[feedingit] / src / config.py
index 91be2dc..cb7aaa0 100644 (file)
@@ -19,7 +19,7 @@
 # ============================================================================
 # Name        : FeedingIt.py
 # Author      : Yves Marcoz
-# Version     : 0.4.1
+# Version     : 0.4.3
 # Description : Simple RSS Reader
 # ============================================================================
 
@@ -27,25 +27,35 @@ import gtk
 import hildon
 import ConfigParser
 import gobject
+import gconf
+import urllib2
 
 section = "FeedingIt"
-ranges = { "updateInterval":[0.02, 0.5, 1, 2, 4, 12, 24], "expiry":[24, 48, 72], "fontSize":range(12,24) }
-titles = {"updateInterval":"Auto-update Interval", "expiry":"Expiry For Articles", "fontSize":"Font Size For Article Listing"}
-subtitles = {"updateInterval":"Update every %s hours", "expiry":"Delete articles after %s hours", "fontSize":"%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]}
+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"}
 
 class Config():
-    def __init__(self, parent, configFilename):
+    def __init__(self, parent, configFilename, has_webkit):
         self.configFilename = configFilename
         self.parent = parent
+        self.has_webkit = has_webkit
         # Load config
         self.loadConfig()
         
     def createDialog(self):
         
         self.window = gtk.Dialog("Preferences", self.parent)
-        #self.vbox = gtk.VBox(False, 10)
+        self.window.set_default_size(-1, 600)
+        panArea = hildon.PannableArea()
+        
+        vbox = gtk.VBox(False, 10)
         self.buttons = {}
-        for setting in ["fontSize", "expiry", "updateInterval"]:
+        if self.has_webkit:
+            settings = ["fontSize", "artFontSize", "expiry", "orientation", "updateInterval",]
+        else:
+            settings = ["fontSize", "expiry", "orientation", "updateInterval",]
+        for setting in settings:
             picker = hildon.PickerButton(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
             selector = self.create_selector(ranges[setting], setting)
             picker.set_selector(selector)
@@ -54,15 +64,24 @@ class Config():
             picker.set_name('HildonButton-finger')
             picker.set_alignment(0,0,1,1)
             self.buttons[setting] = picker
-            self.window.vbox.pack_start(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)
+        button.connect("toggled", self.button_toggled, "autoupdate")
+        vbox.pack_start(button, expand=False)
+
+        if self.has_webkit:
+            button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
+            button.set_label("Webkit Articles Enabled")
+            button.set_active(self.config["webkit"])
+            button.connect("toggled", self.button_toggled, "webkit")
+            vbox.pack_start(button, expand=False)
         
-        self.window.vbox.pack_start(button)
+        panArea.add_with_viewport(vbox)
         
+        self.window.vbox.add(panArea)        
         self.window.connect("destroy", self.onExit)
         #self.window.add(self.vbox)
         self.window.show_all()
@@ -72,12 +91,12 @@ class Config():
         self.saveConfig()
         self.window.destroy()
 
-    def button_toggled(self, widget):
+    def button_toggled(self, widget, configName):
         #print "widget", widget.get_active()
         if (widget.get_active()):
-            self.config["autoupdate"] = True
+            self.config[configName] = True
         else:
-            self.config["autoupdate"] = False
+            self.config[configName] = False
         #print "autoup",  self.autoupdate
         self.saveConfig()
         
@@ -97,22 +116,31 @@ class Config():
             configParser = ConfigParser.RawConfigParser()
             configParser.read(self.configFilename)
             self.config["fontSize"] = configParser.getint(section, "fontSize")
+            self.config["artFontSize"] = configParser.getint(section, "artFontSize")
             self.config["expiry"] = configParser.getint(section, "expiry")
             self.config["autoupdate"] = configParser.getboolean(section, "autoupdate")
             self.config["updateInterval"] = configParser.getfloat(section, "updateInterval")
+            self.config["orientation"] = configParser.get(section, "orientation")
+            self.config["webkit"] = configParser.getboolean(section, "webkit")
         except:
-            self.config["fontSize"] = 16
+            self.config["fontSize"] = 17
+            self.config["artFontSize"] = 14
             self.config["expiry"] = 24
             self.config["autoupdate"] = False
             self.config["updateInterval"] = 4
+            self.config["orientation"] = "Automatic"
+            self.config["webkit"] = self.has_webkit
         
     def saveConfig(self):
         configParser = ConfigParser.RawConfigParser()
         configParser.add_section(section)
         configParser.set(section, 'fontSize', str(self.config["fontSize"]))
+        configParser.set(section, 'artFontSize', str(self.config["artFontSize"]))
         configParser.set(section, 'expiry', str(self.config["expiry"]))
         configParser.set(section, 'autoupdate', str(self.config["autoupdate"]))
         configParser.set(section, 'updateInterval', str(self.config["updateInterval"]))
+        configParser.set(section, 'orientation', str(self.config["orientation"]))
+        configParser.set(section, 'webkit', str(self.config["webkit"]))
 
         # Writing our configuration file
         file = open(self.configFilename, 'wb')
@@ -135,6 +163,8 @@ class Config():
 
     def getFontSize(self):
         return self.config["fontSize"]
+    def getArtFontSize(self):
+        return self.config["artFontSize"]
     def getExpiry(self):
         return self.config["expiry"]
     def isAutoUpdateEnabled(self):
@@ -144,4 +174,18 @@ class Config():
     def getReadFont(self):
         return "sans %s" % self.config["fontSize"]
     def getUnreadFont(self):
-        return "sans bold %s" % self.config["fontSize"]
\ No newline at end of file
+        return "sans bold %s" % self.config["fontSize"]
+    def getOrientation(self):
+        return ranges["orientation"].index(self.config["orientation"])
+    def getWebkitSupport(self):
+        if self.has_webkit:
+            return self.config["webkit"]
+        else:
+            return False
+    def getProxy(self):
+        if gconf.client_get_default().get_bool('/system/http_proxy/use_http_proxy'):
+            port = gconf.client_get_default().get_int('/system/http_proxy/port')
+            http = gconf.client_get_default().get_string('/system/http_proxy/host')
+            proxy = proxy = urllib2.ProxyHandler( {"http":"http://%s:%s/"% (http,port)} )
+            return (True, proxy)
+        return (False, None)
\ No newline at end of file