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 # ============================================================================
32 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]}
33 titles = {"updateInterval":"Auto-update Interval", "expiry":"Expiry For Articles", "fontSize":"Font Size For Article Listing", "orientation":"Display Orientation", "artFontSize":"Font Size For Articles"}
34 subtitles = {"updateInterval":"Update every %s hours", "expiry":"Delete articles after %s hours", "fontSize":"%s pixels", "orientation":"%s", "artFontSize":"%s pixels"}
37 def __init__(self, parent, configFilename, has_webkit):
38 self.configFilename = configFilename
40 self.has_webkit = has_webkit
44 def createDialog(self):
46 self.window = gtk.Dialog("Preferences", self.parent)
47 self.window.set_default_size(-1, 600)
48 panArea = hildon.PannableArea()
50 vbox = gtk.VBox(False, 10)
53 settings = ["fontSize", "artFontSize", "expiry", "orientation", "updateInterval",]
55 settings = ["fontSize", "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)
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)
74 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
75 button.set_label("Webkit Articles Enabled")
76 button.set_active(self.config["webkit"])
77 button.connect("toggled", self.button_toggled, "webkit")
78 vbox.pack_start(button)
80 panArea.add_with_viewport(vbox)
82 self.window.vbox.add(panArea)
83 self.window.connect("destroy", self.onExit)
84 #self.window.add(self.vbox)
85 self.window.show_all()
88 def onExit(self, *widget):
92 def button_toggled(self, widget, configName):
93 #print "widget", widget.get_active()
94 if (widget.get_active()):
95 self.config[configName] = True
97 self.config[configName] = False
98 #print "autoup", self.autoupdate
101 def selection_changed(self, selector, button, setting):
102 current_selection = selector.get_current_text()
103 if current_selection:
104 self.config[setting] = current_selection
105 gobject.idle_add(self.updateButton, setting)
108 def updateButton(self, setting):
109 self.buttons[setting].set_text(titles[setting], subtitles[setting] % self.config[setting])
111 def loadConfig(self):
114 configParser = ConfigParser.RawConfigParser()
115 configParser.read(self.configFilename)
116 self.config["fontSize"] = configParser.getint(section, "fontSize")
117 self.config["artFontSize"] = configParser.getint(section, "artFontSize")
118 self.config["expiry"] = configParser.getint(section, "expiry")
119 self.config["autoupdate"] = configParser.getboolean(section, "autoupdate")
120 self.config["updateInterval"] = configParser.getfloat(section, "updateInterval")
121 self.config["orientation"] = configParser.get(section, "orientation")
122 self.config["webkit"] = configParser.getboolean(section, "webkit")
124 self.config["fontSize"] = 17
125 self.config["artFontSize"] = 14
126 self.config["expiry"] = 24
127 self.config["autoupdate"] = False
128 self.config["updateInterval"] = 4
129 self.config["orientation"] = "Automatic"
130 self.config["webkit"] = self.has_webkit
132 def saveConfig(self):
133 configParser = ConfigParser.RawConfigParser()
134 configParser.add_section(section)
135 configParser.set(section, 'fontSize', str(self.config["fontSize"]))
136 configParser.set(section, 'artFontSize', str(self.config["artFontSize"]))
137 configParser.set(section, 'expiry', str(self.config["expiry"]))
138 configParser.set(section, 'autoupdate', str(self.config["autoupdate"]))
139 configParser.set(section, 'updateInterval', str(self.config["updateInterval"]))
140 configParser.set(section, 'orientation', str(self.config["orientation"]))
141 configParser.set(section, 'webkit', str(self.config["webkit"]))
143 # Writing our configuration file
144 file = open(self.configFilename, 'wb')
145 configParser.write(file)
148 def create_selector(self, choices, setting):
149 #self.pickerDialog = hildon.PickerDialog(self.parent)
150 selector = hildon.TouchSelector(text=True)
153 iter = selector.append_text(str(item))
154 if str(self.config[setting]) == str(item):
155 selector.set_active(0, index)
157 selector.connect("changed", self.selection_changed, setting)
158 #self.pickerDialog.set_selector(selector)
160 #self.pickerDialog.show_all()
162 def getFontSize(self):
163 return self.config["fontSize"]
164 def getArtFontSize(self):
165 return self.config["artFontSize"]
167 return self.config["expiry"]
168 def isAutoUpdateEnabled(self):
169 return self.config["autoupdate"]
170 def getUpdateInterval(self):
171 return float(self.config["updateInterval"])
172 def getReadFont(self):
173 return "sans %s" % self.config["fontSize"]
174 def getUnreadFont(self):
175 return "sans bold %s" % self.config["fontSize"]
176 def getOrientation(self):
177 return ranges["orientation"].index(self.config["orientation"])
178 def getWebkitSupport(self):
180 return self.config["webkit"]