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], "feedsort":["Manual", "Most unread", "Least unread", "Most recent", "Least recent"] }
37 titles = {"updateInterval":"Auto-update interval", "expiry":"Delete articles", "fontSize":"List font size", "orientation":"Display orientation", "artFontSize":"Article font size","feedsort":"Feed sort order"}
38 subtitles = {"updateInterval":"Every %s hours", "expiry":"After %s hours", "fontSize":"%s pixels", "orientation":"%s", "artFontSize":"%s pixels", "feedsort":"%s"}
41 def __init__(self, parent, configFilename):
42 self.configFilename = configFilename
47 # Backup current settings for later restore
48 self.config_backup = dict(self.config)
49 self.do_restore_backup = True
51 def on_save_button_clicked(self, button):
52 self.do_restore_backup = False
55 def createDialog(self):
57 self.window = gtk.Dialog("Settings", self.parent)
58 save_button = self.window.add_button(gtk.STOCK_SAVE, gtk.RESPONSE_OK)
59 save_button.connect('clicked', self.on_save_button_clicked)
60 self.window.set_default_size(-1, 600)
61 panArea = hildon.PannableArea()
63 vbox = gtk.VBox(False, 2)
68 l.set_size_request(-1, 6)
69 vbox.pack_start(l, expand=False)
70 vbox.pack_start(gtk.Frame(text), expand=False)
72 def add_setting(setting):
73 picker = hildon.PickerButton(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
74 selector = self.create_selector(ranges[setting], setting)
75 picker.set_selector(selector)
76 picker.set_title(titles[setting])
77 picker.set_text(titles[setting], subtitles[setting] % self.config[setting])
78 picker.set_name('HildonButton-finger')
79 picker.set_alignment(0,0,1,1)
80 self.buttons[setting] = picker
81 vbox.pack_start(picker, expand=False)
83 button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
84 button.set_label("View Known Issues and Tips")
85 button.connect("clicked", self.button_tips_clicked)
86 button.set_alignment(0,0,1,1)
87 vbox.pack_start(button, expand=False)
90 add_setting('fontSize')
91 add_setting('artFontSize')
92 add_setting('orientation')
93 add_setting('feedsort')
94 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
95 button.set_label("Hide read feeds")
96 button.set_active(self.config["hidereadfeeds"])
97 button.connect("toggled", self.button_toggled, "hidereadfeeds")
98 vbox.pack_start(button, expand=False)
100 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
101 button.set_label("Hide read articles")
102 button.set_active(self.config["hidereadarticles"])
103 button.connect("toggled", self.button_toggled, "hidereadarticles")
104 vbox.pack_start(button, expand=False)
108 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
109 button.set_label("Automatically update feeds")
110 button.set_active(self.config["autoupdate"])
111 button.connect("toggled", self.button_toggled, "autoupdate")
112 vbox.pack_start(button, expand=False)
113 add_setting('updateInterval')
114 add_setting('expiry')
117 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
118 button.set_label('Cache images')
119 button.set_active(self.config["imageCache"])
120 button.connect("toggled", self.button_toggled, "imageCache")
121 vbox.pack_start(button, expand=False)
123 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
124 button.set_label("Use HTTP proxy")
125 button.set_active(self.config["proxy"])
126 button.connect("toggled", self.button_toggled, "proxy")
127 vbox.pack_start(button, expand=False)
129 panArea.add_with_viewport(vbox)
131 self.window.vbox.add(panArea)
132 self.window.connect("destroy", self.onExit)
133 #self.window.add(self.vbox)
134 self.window.show_all()
137 def button_tips_clicked(self, *widget):
139 bus = dbus.SessionBus()
140 proxy = bus.get_object("com.nokia.osso_browser", "/com/nokia/osso_browser/request")
141 iface = dbus.Interface(proxy, 'com.nokia.osso_browser')
142 iface.open_new_window("http://feedingit.marcoz.org/%s.html" % VERSION)
144 def onExit(self, *widget):
145 # When the dialog is closed without hitting
146 # the "Save" button, restore the configuration
147 if self.do_restore_backup:
148 print 'Restoring configuration'
149 self.config = self.config_backup
152 self.window.destroy()
154 def button_toggled(self, widget, configName):
155 #print "widget", widget.get_active()
156 if (widget.get_active()):
157 self.config[configName] = True
159 self.config[configName] = False
160 #print "autoup", self.autoupdate
163 def selection_changed(self, selector, button, setting):
164 current_selection = selector.get_current_text()
165 if current_selection:
166 self.config[setting] = current_selection
167 idle_add(self.updateButton, setting)
170 def updateButton(self, setting):
171 self.buttons[setting].set_text(titles[setting], subtitles[setting] % self.config[setting])
173 def loadConfig(self):
176 configParser = RawConfigParser()
177 configParser.read(self.configFilename)
178 self.config["fontSize"] = configParser.getint(section, "fontSize")
179 self.config["artFontSize"] = configParser.getint(section, "artFontSize")
180 self.config["expiry"] = configParser.getint(section, "expiry")
181 self.config["autoupdate"] = configParser.getboolean(section, "autoupdate")
182 self.config["updateInterval"] = configParser.getfloat(section, "updateInterval")
183 self.config["orientation"] = configParser.get(section, "orientation")
184 self.config["imageCache"] = configParser.getboolean(section, "imageCache")
186 self.config["fontSize"] = 17
187 self.config["artFontSize"] = 14
188 self.config["expiry"] = 24
189 self.config["autoupdate"] = False
190 self.config["updateInterval"] = 4
191 self.config["orientation"] = "Automatic"
192 self.config["imageCache"] = False
194 self.config["proxy"] = configParser.getboolean(section, "proxy")
196 self.config["proxy"] = True
198 self.config["hidereadfeeds"] = configParser.getboolean(section, "hidereadfeeds")
199 self.config["hidereadarticles"] = configParser.getboolean(section, "hidereadarticles")
201 self.config["hidereadfeeds"] = False
202 self.config["hidereadarticles"] = False
204 self.config["feedsort"] = configParser.get(section, "feedsort")
206 self.config["feedsort"] = "Manual"
208 def saveConfig(self):
209 configParser = RawConfigParser()
210 configParser.add_section(section)
211 configParser.set(section, 'fontSize', str(self.config["fontSize"]))
212 configParser.set(section, 'artFontSize', str(self.config["artFontSize"]))
213 configParser.set(section, 'expiry', str(self.config["expiry"]))
214 configParser.set(section, 'autoupdate', str(self.config["autoupdate"]))
215 configParser.set(section, 'updateInterval', str(self.config["updateInterval"]))
216 configParser.set(section, 'orientation', str(self.config["orientation"]))
217 configParser.set(section, 'imageCache', str(self.config["imageCache"]))
218 configParser.set(section, 'proxy', str(self.config["proxy"]))
219 configParser.set(section, 'hidereadfeeds', str(self.config["hidereadfeeds"]))
220 configParser.set(section, 'hidereadarticles', str(self.config["hidereadarticles"]))
221 configParser.set(section, 'feedsort', str(self.config["feedsort"]))
223 # Writing our configuration file
224 file = open(self.configFilename, 'wb')
225 configParser.write(file)
228 def create_selector(self, choices, setting):
229 #self.pickerDialog = hildon.PickerDialog(self.parent)
230 selector = hildon.TouchSelector(text=True)
233 iter = selector.append_text(str(item))
234 if str(self.config[setting]) == str(item):
235 selector.set_active(0, index)
237 selector.connect("changed", self.selection_changed, setting)
238 #self.pickerDialog.set_selector(selector)
240 #self.pickerDialog.show_all()
242 def getFontSize(self):
243 return self.config["fontSize"]
244 def getArtFontSize(self):
245 return self.config["artFontSize"]
247 return self.config["expiry"]
248 def isAutoUpdateEnabled(self):
249 return self.config["autoupdate"]
250 def getUpdateInterval(self):
251 return float(self.config["updateInterval"])
252 def getReadFont(self):
253 return "sans italic %s" % self.config["fontSize"]
254 def getUnreadFont(self):
255 return "sans %s" % self.config["fontSize"]
256 def getOrientation(self):
257 return ranges["orientation"].index(self.config["orientation"])
258 def getImageCache(self):
259 return self.config["imageCache"]
261 if self.config["proxy"] == False:
263 if client_get_default().get_bool('/system/http_proxy/use_http_proxy'):
264 port = client_get_default().get_int('/system/http_proxy/port')
265 http = client_get_default().get_string('/system/http_proxy/host')
266 proxy = ProxyHandler( {"http":"http://%s:%s/"% (http,port)} )
269 def getHideReadFeeds(self):
270 return self.config["hidereadfeeds"]
271 def getHideReadArticles(self):
272 return self.config["hidereadarticles"]
273 def getFeedSortOrder(self):
274 return self.config["feedsort"]