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 gobject import idle_add
32 from ConfigParser import RawConfigParser
33 from gconf import client_get_default
34 from urllib2 import ProxyHandler
35 from mainthread import mainthread
37 logger = logging.getLogger(__name__)
42 ranges = { "updateInterval":[0.5, 1, 2, 4, 12, 24], "expiry":[24, 48, 72, 144, 288], "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"] }
43 titles = {"updateInterval":"Auto-update interval", "expiry":"Delete articles", "fontSize":"List font size", "orientation":"Display orientation", "artFontSize":"Article font size","feedsort":"Feed sort order"}
44 subtitles = {"updateInterval":"Every %s hours", "expiry":"After %s hours", "fontSize":"%s pixels", "orientation":"%s", "artFontSize":"%s pixels", "feedsort":"%s"}
47 def __init__(self, parent, configFilename):
48 self.configFilename = configFilename
53 # Backup current settings for later restore
54 self.config_backup = dict(self.config)
55 self.do_restore_backup = True
57 def on_save_button_clicked(self, button):
58 self.do_restore_backup = False
61 def createDialog(self):
64 from gobject import idle_add
65 self.window = gtk.Dialog("Settings", self.parent)
66 self.window.set_geometry_hints(min_height=600)
68 save_button = self.window.add_button(gtk.STOCK_SAVE, gtk.RESPONSE_OK)
69 save_button.connect('clicked', self.on_save_button_clicked)
70 #self.window.set_default_size(-1, 600)
71 panArea = hildon.PannableArea()
73 vbox = gtk.VBox(False, 2)
78 l.set_size_request(-1, 6)
79 vbox.pack_start(l, expand=False)
80 vbox.pack_start(gtk.Frame(text), expand=False)
82 def add_setting(setting):
83 picker = hildon.PickerButton(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
84 selector = self.create_selector(ranges[setting], setting)
85 picker.set_selector(selector)
86 picker.set_title(titles[setting])
87 picker.set_text(titles[setting], subtitles[setting] % self.config[setting])
88 picker.set_name('HildonButton-finger')
89 picker.set_alignment(0,0,1,1)
90 self.buttons[setting] = picker
91 vbox.pack_start(picker, expand=False)
93 button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
94 button.set_label("View Known Issues and Tips")
95 button.connect("clicked", self.button_tips_clicked)
96 button.set_alignment(0,0,1,1)
97 vbox.pack_start(button, expand=False)
100 add_setting('fontSize')
101 add_setting('artFontSize')
102 add_setting('orientation')
103 add_setting('feedsort')
104 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
105 button.set_label("Hide read feeds")
106 button.set_active(self.config["hidereadfeeds"])
107 button.connect("toggled", self.button_toggled, "hidereadfeeds")
108 vbox.pack_start(button, expand=False)
110 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
111 button.set_label("Hide read articles")
112 button.set_active(self.config["hidereadarticles"])
113 button.connect("toggled", self.button_toggled, "hidereadarticles")
114 vbox.pack_start(button, expand=False)
118 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
119 button.set_label("Automatically update feeds")
120 button.set_active(self.config["autoupdate"])
121 button.connect("toggled", self.button_toggled, "autoupdate")
122 vbox.pack_start(button, expand=False)
123 add_setting('updateInterval')
124 add_setting('expiry')
127 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
128 button.set_label('Cache images')
129 button.set_active(self.config["imageCache"])
130 button.connect("toggled", self.button_toggled, "imageCache")
131 vbox.pack_start(button, expand=False)
133 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
134 button.set_label("Use HTTP proxy")
135 button.set_active(self.config["proxy"])
136 button.connect("toggled", self.button_toggled, "proxy")
137 vbox.pack_start(button, expand=False)
139 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
140 button.set_label('Open links in external browser')
141 button.set_active(self.config["extBrowser"])
142 button.connect("toggled", self.button_toggled, "extBrowser")
143 vbox.pack_start(button, expand=False)
145 panArea.add_with_viewport(vbox)
147 self.window.vbox.add(panArea)
148 self.window.connect("destroy", self.onExit)
149 #self.window.add(self.vbox)
150 self.window.set_default_size(-1, 600)
151 self.window.show_all()
154 def button_tips_clicked(self, *widget):
156 bus = dbus.SessionBus()
157 proxy = bus.get_object("com.nokia.osso_browser", "/com/nokia/osso_browser/request")
158 iface = dbus.Interface(proxy, 'com.nokia.osso_browser')
159 iface.open_new_window("http://feedingit.marcoz.org/news/?page_id=%s" % VERSION)
161 def onExit(self, *widget):
162 # When the dialog is closed without hitting
163 # the "Save" button, restore the configuration
164 if self.do_restore_backup:
165 logger.debug('Restoring configuration')
166 self.config = self.config_backup
169 self.window.destroy()
171 def button_toggled(self, widget, configName):
172 #print "widget", widget.get_active()
173 if (widget.get_active()):
174 self.config[configName] = True
176 self.config[configName] = False
177 #print "autoup", self.autoupdate
180 def selection_changed(self, selector, button, setting):
181 from gobject import idle_add
182 current_selection = selector.get_current_text()
183 if current_selection:
184 self.config[setting] = current_selection
185 idle_add(self.updateButton, setting)
188 def updateButton(self, setting):
189 self.buttons[setting].set_text(titles[setting], subtitles[setting] % self.config[setting])
191 def loadConfig(self):
194 configParser = RawConfigParser()
195 configParser.read(self.configFilename)
196 self.config["fontSize"] = configParser.getint(section, "fontSize")
197 self.config["artFontSize"] = configParser.getint(section, "artFontSize")
198 self.config["expiry"] = configParser.getint(section, "expiry")
199 self.config["autoupdate"] = configParser.getboolean(section, "autoupdate")
200 self.config["updateInterval"] = configParser.getfloat(section, "updateInterval")
201 self.config["orientation"] = configParser.get(section, "orientation")
202 self.config["imageCache"] = configParser.getboolean(section, "imageCache")
204 self.config["fontSize"] = 17
205 self.config["artFontSize"] = 14
206 self.config["expiry"] = 24
207 self.config["autoupdate"] = False
208 self.config["updateInterval"] = 4
209 self.config["orientation"] = "Automatic"
210 self.config["imageCache"] = False
212 self.config["proxy"] = configParser.getboolean(section, "proxy")
214 self.config["proxy"] = True
216 self.config["hidereadfeeds"] = configParser.getboolean(section, "hidereadfeeds")
217 self.config["hidereadarticles"] = configParser.getboolean(section, "hidereadarticles")
219 self.config["hidereadfeeds"] = False
220 self.config["hidereadarticles"] = False
222 self.config["extBrowser"] = configParser.getboolean(section, "extBrowser")
224 self.config["extBrowser"] = False
226 self.config["feedsort"] = configParser.get(section, "feedsort")
228 self.config["feedsort"] = "Manual"
230 def saveConfig(self):
231 configParser = RawConfigParser()
232 configParser.add_section(section)
233 configParser.set(section, 'fontSize', str(self.config["fontSize"]))
234 configParser.set(section, 'artFontSize', str(self.config["artFontSize"]))
235 configParser.set(section, 'expiry', str(self.config["expiry"]))
236 configParser.set(section, 'autoupdate', str(self.config["autoupdate"]))
237 configParser.set(section, 'updateInterval', str(self.config["updateInterval"]))
238 configParser.set(section, 'orientation', str(self.config["orientation"]))
239 configParser.set(section, 'imageCache', str(self.config["imageCache"]))
240 configParser.set(section, 'proxy', str(self.config["proxy"]))
241 configParser.set(section, 'hidereadfeeds', str(self.config["hidereadfeeds"]))
242 configParser.set(section, 'hidereadarticles', str(self.config["hidereadarticles"]))
243 configParser.set(section, 'extBrowser', str(self.config["extBrowser"]))
244 configParser.set(section, 'feedsort', str(self.config["feedsort"]))
246 # Writing our configuration file
247 file = open(self.configFilename, 'wb')
248 configParser.write(file)
251 def create_selector(self, choices, setting):
254 from gobject import idle_add
255 #self.pickerDialog = hildon.PickerDialog(self.parent)
256 selector = hildon.TouchSelector(text=True)
259 iter = selector.append_text(str(item))
260 if str(self.config[setting]) == str(item):
261 selector.set_active(0, index)
263 selector.connect("changed", self.selection_changed, setting)
264 #self.pickerDialog.set_selector(selector)
266 #self.pickerDialog.show_all()
268 def getFontSize(self):
269 return self.config["fontSize"]
270 def getArtFontSize(self):
271 return self.config["artFontSize"]
273 return self.config["expiry"]
274 def isAutoUpdateEnabled(self):
275 return self.config["autoupdate"]
276 def getUpdateInterval(self):
277 return float(self.config["updateInterval"])
278 def getReadFont(self):
279 return "sans italic %s" % self.config["fontSize"]
280 def getUnreadFont(self):
281 return "sans %s" % self.config["fontSize"]
282 def getOrientation(self):
283 return ranges["orientation"].index(self.config["orientation"])
284 def getImageCache(self):
285 return self.config["imageCache"]
288 if self.config["proxy"] == False:
290 if client_get_default().get_bool('/system/http_proxy/use_http_proxy'):
291 port = client_get_default().get_int('/system/http_proxy/port')
292 http = client_get_default().get_string('/system/http_proxy/host')
293 proxy = ProxyHandler( {"http":"http://%s:%s/"% (http,port)} )
296 def getHideReadFeeds(self):
297 return self.config["hidereadfeeds"]
298 def getHideReadArticles(self):
299 return self.config["hidereadarticles"]
300 def getOpenInExternalBrowser(self):
301 return self.config["extBrowser"]
302 def getFeedSortOrder(self):
303 return self.config["feedsort"]