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
40 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"] }
41 titles = {"updateInterval":"Auto-update interval", "expiry":"Delete articles", "fontSize":"List font size", "orientation":"Display orientation", "artFontSize":"Article font size","feedsort":"Feed sort order"}
42 subtitles = {"updateInterval":"Every %s hours", "expiry":"After %s hours", "fontSize":"%s pixels", "orientation":"%s", "artFontSize":"%s pixels", "feedsort":"%s"}
45 def __init__(self, parent, configFilename):
46 self.configFilename = configFilename
51 # Backup current settings for later restore
52 self.config_backup = dict(self.config)
53 self.do_restore_backup = True
55 def on_save_button_clicked(self, button):
56 self.do_restore_backup = False
59 def createDialog(self):
62 from gobject import idle_add
63 self.window = gtk.Dialog("Settings", self.parent)
64 self.window.set_geometry_hints(min_height=600)
66 save_button = self.window.add_button(gtk.STOCK_SAVE, gtk.RESPONSE_OK)
67 save_button.connect('clicked', self.on_save_button_clicked)
68 #self.window.set_default_size(-1, 600)
69 panArea = hildon.PannableArea()
71 vbox = gtk.VBox(False, 2)
76 l.set_size_request(-1, 6)
77 vbox.pack_start(l, expand=False)
78 vbox.pack_start(gtk.Frame(text), expand=False)
80 def add_setting(setting):
81 picker = hildon.PickerButton(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
82 selector = self.create_selector(ranges[setting], setting)
83 picker.set_selector(selector)
84 picker.set_title(titles[setting])
85 picker.set_text(titles[setting], subtitles[setting] % self.config[setting])
86 picker.set_name('HildonButton-finger')
87 picker.set_alignment(0,0,1,1)
88 self.buttons[setting] = picker
89 vbox.pack_start(picker, expand=False)
91 button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
92 button.set_label("View Known Issues and Tips")
93 button.connect("clicked", self.button_tips_clicked)
94 button.set_alignment(0,0,1,1)
95 vbox.pack_start(button, expand=False)
98 add_setting('fontSize')
99 add_setting('artFontSize')
100 add_setting('orientation')
101 add_setting('feedsort')
102 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
103 button.set_label("Hide read feeds")
104 button.set_active(self.config["hidereadfeeds"])
105 button.connect("toggled", self.button_toggled, "hidereadfeeds")
106 vbox.pack_start(button, expand=False)
108 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
109 button.set_label("Hide read articles")
110 button.set_active(self.config["hidereadarticles"])
111 button.connect("toggled", self.button_toggled, "hidereadarticles")
112 vbox.pack_start(button, expand=False)
116 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
117 button.set_label("Automatically update feeds")
118 button.set_active(self.config["autoupdate"])
119 button.connect("toggled", self.button_toggled, "autoupdate")
120 vbox.pack_start(button, expand=False)
121 add_setting('updateInterval')
122 add_setting('expiry')
125 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
126 button.set_label('Cache images')
127 button.set_active(self.config["imageCache"])
128 button.connect("toggled", self.button_toggled, "imageCache")
129 vbox.pack_start(button, expand=False)
131 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
132 button.set_label("Use HTTP proxy")
133 button.set_active(self.config["proxy"])
134 button.connect("toggled", self.button_toggled, "proxy")
135 vbox.pack_start(button, expand=False)
137 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
138 button.set_label('Open links in external browser')
139 button.set_active(self.config["extBrowser"])
140 button.connect("toggled", self.button_toggled, "extBrowser")
141 vbox.pack_start(button, expand=False)
143 panArea.add_with_viewport(vbox)
145 self.window.vbox.add(panArea)
146 self.window.connect("destroy", self.onExit)
147 #self.window.add(self.vbox)
148 self.window.set_default_size(-1, 600)
149 self.window.show_all()
152 def button_tips_clicked(self, *widget):
154 bus = dbus.SessionBus()
155 proxy = bus.get_object("com.nokia.osso_browser", "/com/nokia/osso_browser/request")
156 iface = dbus.Interface(proxy, 'com.nokia.osso_browser')
157 iface.open_new_window("http://feedingit.marcoz.org/news/?page_id=%s" % VERSION)
159 def onExit(self, *widget):
160 # When the dialog is closed without hitting
161 # the "Save" button, restore the configuration
162 if self.do_restore_backup:
163 print 'Restoring configuration'
164 self.config = self.config_backup
167 self.window.destroy()
169 def button_toggled(self, widget, configName):
170 #print "widget", widget.get_active()
171 if (widget.get_active()):
172 self.config[configName] = True
174 self.config[configName] = False
175 #print "autoup", self.autoupdate
178 def selection_changed(self, selector, button, setting):
179 from gobject import idle_add
180 current_selection = selector.get_current_text()
181 if current_selection:
182 self.config[setting] = current_selection
183 idle_add(self.updateButton, setting)
186 def updateButton(self, setting):
187 self.buttons[setting].set_text(titles[setting], subtitles[setting] % self.config[setting])
189 def loadConfig(self):
192 configParser = RawConfigParser()
193 configParser.read(self.configFilename)
194 self.config["fontSize"] = configParser.getint(section, "fontSize")
195 self.config["artFontSize"] = configParser.getint(section, "artFontSize")
196 self.config["expiry"] = configParser.getint(section, "expiry")
197 self.config["autoupdate"] = configParser.getboolean(section, "autoupdate")
198 self.config["updateInterval"] = configParser.getfloat(section, "updateInterval")
199 self.config["orientation"] = configParser.get(section, "orientation")
200 self.config["imageCache"] = configParser.getboolean(section, "imageCache")
202 self.config["fontSize"] = 17
203 self.config["artFontSize"] = 14
204 self.config["expiry"] = 24
205 self.config["autoupdate"] = False
206 self.config["updateInterval"] = 4
207 self.config["orientation"] = "Automatic"
208 self.config["imageCache"] = False
210 self.config["proxy"] = configParser.getboolean(section, "proxy")
212 self.config["proxy"] = True
214 self.config["hidereadfeeds"] = configParser.getboolean(section, "hidereadfeeds")
215 self.config["hidereadarticles"] = configParser.getboolean(section, "hidereadarticles")
217 self.config["hidereadfeeds"] = False
218 self.config["hidereadarticles"] = False
220 self.config["extBrowser"] = configParser.getboolean(section, "extBrowser")
222 self.config["extBrowser"] = False
224 self.config["feedsort"] = configParser.get(section, "feedsort")
226 self.config["feedsort"] = "Manual"
228 def saveConfig(self):
229 configParser = RawConfigParser()
230 configParser.add_section(section)
231 configParser.set(section, 'fontSize', str(self.config["fontSize"]))
232 configParser.set(section, 'artFontSize', str(self.config["artFontSize"]))
233 configParser.set(section, 'expiry', str(self.config["expiry"]))
234 configParser.set(section, 'autoupdate', str(self.config["autoupdate"]))
235 configParser.set(section, 'updateInterval', str(self.config["updateInterval"]))
236 configParser.set(section, 'orientation', str(self.config["orientation"]))
237 configParser.set(section, 'imageCache', str(self.config["imageCache"]))
238 configParser.set(section, 'proxy', str(self.config["proxy"]))
239 configParser.set(section, 'hidereadfeeds', str(self.config["hidereadfeeds"]))
240 configParser.set(section, 'hidereadarticles', str(self.config["hidereadarticles"]))
241 configParser.set(section, 'extBrowser', str(self.config["extBrowser"]))
242 configParser.set(section, 'feedsort', str(self.config["feedsort"]))
244 # Writing our configuration file
245 file = open(self.configFilename, 'wb')
246 configParser.write(file)
249 def create_selector(self, choices, setting):
252 from gobject import idle_add
253 #self.pickerDialog = hildon.PickerDialog(self.parent)
254 selector = hildon.TouchSelector(text=True)
257 iter = selector.append_text(str(item))
258 if str(self.config[setting]) == str(item):
259 selector.set_active(0, index)
261 selector.connect("changed", self.selection_changed, setting)
262 #self.pickerDialog.set_selector(selector)
264 #self.pickerDialog.show_all()
266 def getFontSize(self):
267 return self.config["fontSize"]
268 def getArtFontSize(self):
269 return self.config["artFontSize"]
271 return self.config["expiry"]
272 def isAutoUpdateEnabled(self):
273 return self.config["autoupdate"]
274 def getUpdateInterval(self):
275 return float(self.config["updateInterval"])
276 def getReadFont(self):
277 return "sans italic %s" % self.config["fontSize"]
278 def getUnreadFont(self):
279 return "sans %s" % self.config["fontSize"]
280 def getOrientation(self):
281 return ranges["orientation"].index(self.config["orientation"])
282 def getImageCache(self):
283 return self.config["imageCache"]
286 if self.config["proxy"] == False:
288 if client_get_default().get_bool('/system/http_proxy/use_http_proxy'):
289 port = client_get_default().get_int('/system/http_proxy/port')
290 http = client_get_default().get_string('/system/http_proxy/host')
291 proxy = ProxyHandler( {"http":"http://%s:%s/"% (http,port)} )
294 def getHideReadFeeds(self):
295 return self.config["hidereadfeeds"]
296 def getHideReadArticles(self):
297 return self.config["hidereadarticles"]
298 def getOpenInExternalBrowser(self):
299 return self.config["extBrowser"]
300 def getFeedSortOrder(self):
301 return self.config["feedsort"]