Mercurial > hg > Feedworm
annotate Preferences.py @ 99:e59d722439b5
filter out read entries first before sorting
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Wed, 29 Dec 2010 04:27:58 +0100 |
parents | b8bfd1bd6c55 |
children | 43c234c8fe87 |
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 |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
5 HIDE_READ_ENTRIES = "HIDE_READ_FEED_ENTRIES" |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
6 PROXY_HOST = "PROXY_HOST" |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
7 PROXY_PORT = "PROXY_PORT" |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
8 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
|
9 START_MAXIMIZED = "START_MAXIMIZED" |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
10 |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
11 class Preferences(object): |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
12 def __init__(self, session): |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
13 self.session = session |
44
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
14 self.cache = {} |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
15 |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
16 def _cachedPreference(self, key, defaultValue=None, addIfMissing=True): |
44
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
17 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
|
18 return self.cache[key] |
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
19 else: |
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
20 pref = Preference.forKey(key, self.session) |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
21 if pref is None and addIfMissing: |
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
|
22 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
|
23 self.session.add(pref) |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
24 self.cache[key] = pref |
44
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
25 return pref |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
26 |
43
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
27 def startMaximized(self): |
44
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
28 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
|
29 return util.str2bool(pref.value) |
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
30 |
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
31 def setStartMaximized(self, flag): |
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
32 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
|
33 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
|
34 |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
35 def hideReadFeedEntries(self): |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
36 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
|
37 return util.str2bool(pref.value) |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
38 |
61
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
39 def setHideReadFeedEntries(self, flag): |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
40 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
|
41 pref.value = util.bool2str(flag) |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
42 |
72
e8c2730eb444
control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
61
diff
changeset
|
43 def showOnlyUnreadFeeds(self): |
e8c2730eb444
control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
61
diff
changeset
|
44 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
|
45 return util.str2bool(pref.value) |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
46 |
72
e8c2730eb444
control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
61
diff
changeset
|
47 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
|
48 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
|
49 pref.value = util.bool2str(flag) |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
50 |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
51 def proxyHost(self): |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
52 pref = self._cachedPreference(PROXY_HOST) |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
53 return pref.value |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
54 |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
55 def setProxyHost(self, hostname): |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
56 pref = self._cachedPreference(PROXY_HOST) |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
57 pref.value = hostname |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
58 |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
59 def proxyPort(self): |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
60 pref = self._cachedPreference(PROXY_PORT, 3128) |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
61 return int(pref.value) |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
62 |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
63 def setProxyPort(self, port): |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
64 pref = self._cachedPreference(PROXY_PORT) |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
65 pref.value = str(port) |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
66 |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
67 def isProxyConfigured(self): |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
68 pref = self._cachedPreference(PROXY_HOST, addIfMissing=False) |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
69 return pref is not None |