1 #!/usr/bin/env python2.5
4 # Copyright (c) 2007-2008 INdT.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # ============================================================================
21 # Author : Yves Marcoz
23 # Description : Simple RSS Reader
24 # ============================================================================
28 from ConfigParser import RawConfigParser
29 from gobject import idle_add
30 from gconf import client_get_default
31 from urllib2 import ProxyHandler
36 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]}
37 titles = {"updateInterval":"Auto-update Interval", "expiry":"Expiry For Articles", "fontSize":"Font Size For Article Listing", "orientation":"Display Orientation", "artFontSize":"Font Size For Articles"}
38 subtitles = {"updateInterval":"Update every %s hours", "expiry":"Delete articles after %s hours", "fontSize":"%s pixels", "orientation":"%s", "artFontSize":"%s pixels"}
41 def __init__(self, parent, configFilename):
42 self.configFilename = configFilename
47 def createDialog(self):
49 self.window = gtk.Dialog("Preferences", self.parent)
50 self.window.set_default_size(-1, 600)
51 panArea = hildon.PannableArea()
53 vbox = gtk.VBox(False, 10)
55 settings = ["fontSize", "artFontSize", "expiry", "orientation", "updateInterval",]
56 for setting in settings:
57 picker = hildon.PickerButton(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
58 selector = self.create_selector(ranges[setting], setting)
59 picker.set_selector(selector)
60 picker.set_title(titles[setting])
61 picker.set_text(titles[setting], subtitles[setting] % self.config[setting])
62 picker.set_name('HildonButton-finger')
63 picker.set_alignment(0,0,1,1)
64 self.buttons[setting] = picker
65 vbox.pack_start(picker, expand=False)
67 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
68 button.set_label("Auto-update Enabled.")
69 button.set_active(self.config["autoupdate"])
70 button.connect("toggled", self.button_toggled, "autoupdate")
71 vbox.pack_start(button, expand=False)
73 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
74 button.set_label("Image Caching Enabled")
75 button.set_active(self.config["imageCache"])
76 button.connect("toggled", self.button_toggled, "imageCache")
77 vbox.pack_start(button, expand=False)
79 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
80 button.set_label("Proxy Support Enabled")
81 button.set_active(self.config["proxy"])
82 button.connect("toggled", self.button_toggled, "proxy")
83 vbox.pack_start(button, expand=False)
85 button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
86 button.set_label("View Known Issues and Tips")
87 button.connect("clicked", self.button_tips_clicked)
88 button.set_alignment(0,0,1,1)
89 vbox.pack_start(button, expand=False)
92 panArea.add_with_viewport(vbox)
94 self.window.vbox.add(panArea)
95 self.window.connect("destroy", self.onExit)
96 #self.window.add(self.vbox)
97 self.window.show_all()
100 def button_tips_clicked(self, *widget):
102 bus = dbus.SessionBus()
103 proxy = bus.get_object("com.nokia.osso_browser", "/com/nokia/osso_browser/request")
104 iface = dbus.Interface(proxy, 'com.nokia.osso_browser')
105 iface.open_new_window("http://feedingit.marcoz.org/%s.html" % VERSION)
107 def onExit(self, *widget):
109 self.window.destroy()
111 def button_toggled(self, widget, configName):
112 #print "widget", widget.get_active()
113 if (widget.get_active()):
114 self.config[configName] = True
116 self.config[configName] = False
117 #print "autoup", self.autoupdate
120 def selection_changed(self, selector, button, setting):
121 current_selection = selector.get_current_text()
122 if current_selection:
123 self.config[setting] = current_selection
124 gobject.idle_add(self.updateButton, setting)
127 def updateButton(self, setting):
128 self.buttons[setting].set_text(titles[setting], subtitles[setting] % self.config[setting])
130 def loadConfig(self):
133 configParser = RawConfigParser()
134 configParser.read(self.configFilename)
135 self.config["fontSize"] = configParser.getint(section, "fontSize")
136 self.config["artFontSize"] = configParser.getint(section, "artFontSize")
137 self.config["expiry"] = configParser.getint(section, "expiry")
138 self.config["autoupdate"] = configParser.getboolean(section, "autoupdate")
139 self.config["updateInterval"] = configParser.getfloat(section, "updateInterval")
140 self.config["orientation"] = configParser.get(section, "orientation")
141 self.config["imageCache"] = configParser.getboolean(section, "imageCache")
143 self.config["fontSize"] = 17
144 self.config["artFontSize"] = 14
145 self.config["expiry"] = 24
146 self.config["autoupdate"] = False
147 self.config["updateInterval"] = 4
148 self.config["orientation"] = "Automatic"
149 self.config["imageCache"] = False
151 self.config["proxy"] = configParser.getboolean(section, "proxy")
153 self.config["proxy"] = True
155 def saveConfig(self):
156 configParser = RawConfigParser()
157 configParser.add_section(section)
158 configParser.set(section, 'fontSize', str(self.config["fontSize"]))
159 configParser.set(section, 'artFontSize', str(self.config["artFontSize"]))
160 configParser.set(section, 'expiry', str(self.config["expiry"]))
161 configParser.set(section, 'autoupdate', str(self.config["autoupdate"]))
162 configParser.set(section, 'updateInterval', str(self.config["updateInterval"]))
163 configParser.set(section, 'orientation', str(self.config["orientation"]))
164 configParser.set(section, 'imageCache', str(self.config["imageCache"]))
165 configParser.set(section, 'proxy', str(self.config["proxy"]))
167 # Writing our configuration file
168 file = open(self.configFilename, 'wb')
169 configParser.write(file)
172 def create_selector(self, choices, setting):
173 #self.pickerDialog = hildon.PickerDialog(self.parent)
174 selector = hildon.TouchSelector(text=True)
177 iter = selector.append_text(str(item))
178 if str(self.config[setting]) == str(item):
179 selector.set_active(0, index)
181 selector.connect("changed", self.selection_changed, setting)
182 #self.pickerDialog.set_selector(selector)
184 #self.pickerDialog.show_all()
186 def getFontSize(self):
187 return self.config["fontSize"]
188 def getArtFontSize(self):
189 return self.config["artFontSize"]
191 return self.config["expiry"]
192 def isAutoUpdateEnabled(self):
193 return self.config["autoupdate"]
194 def getUpdateInterval(self):
195 return float(self.config["updateInterval"])
196 def getReadFont(self):
197 return "sans italic %s" % self.config["fontSize"]
198 def getUnreadFont(self):
199 return "sans %s" % self.config["fontSize"]
200 def getOrientation(self):
201 return ranges["orientation"].index(self.config["orientation"])
202 def getImageCache(self):
203 return self.config["imageCache"]
205 if self.config["proxy"] == False:
207 if client_get_default().get_bool('/system/http_proxy/use_http_proxy'):
208 port = client_get_default().get_int('/system/http_proxy/port')
209 http = client_get_default().get_string('/system/http_proxy/host')
210 proxy = ProxyHandler( {"http":"http://%s:%s/"% (http,port)} )