annotate Preferences.py @ 85:479e8c06de49

look at the bozo value of the result to determine if something went wrong with the HTTP call
author Dirk Olmes <dirk@xanthippe.ping.de>
date Thu, 09 Sep 2010 16:36:29 +0200
parents e8c2730eb444
children b8bfd1bd6c55
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43
12ed8b5fa08c first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
1
12ed8b5fa08c first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
2 from Preference import Preference
12ed8b5fa08c first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
3 import util
12ed8b5fa08c first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
4
12ed8b5fa08c first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
5 START_MAXIMIZED = "START_MAXIMIZED"
61
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 46
diff changeset
6 HIDE_READ_ENTRIES = "HIDE_READ_FEED_ENTRIES"
72
e8c2730eb444 control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 61
diff changeset
7 SHOW_ONLY_UNREAD_FEEDS = "SHOW_ONLY_UNREAD_FEEDS"
43
12ed8b5fa08c first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
8
12ed8b5fa08c first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
9 class Preferences(object):
12ed8b5fa08c first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
10 def __init__(self, session):
12ed8b5fa08c first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
11 self.session = session
44
be990ac6e478 saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 43
diff changeset
12 self.cache = {}
be990ac6e478 saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 43
diff changeset
13
be990ac6e478 saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 43
diff changeset
14 def _cachedPreference(self, key, defaultValue=None):
be990ac6e478 saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 43
diff changeset
15 if self.cache.has_key(key):
be990ac6e478 saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 43
diff changeset
16 return self.cache[key]
be990ac6e478 saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 43
diff changeset
17 else:
be990ac6e478 saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 43
diff changeset
18 pref = Preference.forKey(key, self.session)
be990ac6e478 saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 43
diff changeset
19 if pref is None:
46
03358c113170 Better preferences handling: the GUI's responsibility is to convert the input from the event into a boolean value
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 44
diff changeset
20 pref = Preference(key, str(defaultValue))
44
be990ac6e478 saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 43
diff changeset
21 self.session.add(pref)
be990ac6e478 saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 43
diff changeset
22 self.cache[key] = pref
be990ac6e478 saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 43
diff changeset
23 return pref
43
12ed8b5fa08c first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
24
12ed8b5fa08c first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
25 def startMaximized(self):
44
be990ac6e478 saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 43
diff changeset
26 pref = self._cachedPreference(START_MAXIMIZED, False)
be990ac6e478 saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 43
diff changeset
27 return util.str2bool(pref.value)
be990ac6e478 saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 43
diff changeset
28
be990ac6e478 saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 43
diff changeset
29 def setStartMaximized(self, flag):
be990ac6e478 saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 43
diff changeset
30 pref = self._cachedPreference(START_MAXIMIZED)
46
03358c113170 Better preferences handling: the GUI's responsibility is to convert the input from the event into a boolean value
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 44
diff changeset
31 pref.value = util.bool2str(flag)
61
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 46
diff changeset
32
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 46
diff changeset
33 def hideReadFeedEntries(self):
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 46
diff changeset
34 pref = self._cachedPreference(HIDE_READ_ENTRIES, False)
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 46
diff changeset
35 return util.str2bool(pref.value)
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 46
diff changeset
36
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 46
diff changeset
37 def setHideReadFeedEntries(self, flag):
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 46
diff changeset
38 pref = self._cachedPreference(HIDE_READ_ENTRIES)
db35ab7753f0 add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 46
diff changeset
39 pref.value = util.bool2str(flag)
72
e8c2730eb444 control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 61
diff changeset
40
e8c2730eb444 control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 61
diff changeset
41 def showOnlyUnreadFeeds(self):
e8c2730eb444 control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 61
diff changeset
42 pref = self._cachedPreference(SHOW_ONLY_UNREAD_FEEDS, False)
e8c2730eb444 control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 61
diff changeset
43 return util.str2bool(pref.value)
e8c2730eb444 control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 61
diff changeset
44
e8c2730eb444 control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 61
diff changeset
45 def setShowOnlyUnreadFeeds(self, flag):
e8c2730eb444 control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 61
diff changeset
46 pref = self._cachedPreference(SHOW_ONLY_UNREAD_FEEDS)
e8c2730eb444 control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 61
diff changeset
47 pref.value = util.bool2str(flag)