Mercurial > hg > Feedworm
comparison Preferences.py @ 87:b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Wed, 17 Nov 2010 21:22:31 +0100 |
parents | e8c2730eb444 |
children | 43c234c8fe87 |
comparison
equal
deleted
inserted
replaced
86:94118d504d2b | 87:b8bfd1bd6c55 |
---|---|
1 | 1 |
2 from Preference import Preference | 2 from Preference import Preference |
3 import util | 3 import util |
4 | 4 |
5 HIDE_READ_ENTRIES = "HIDE_READ_FEED_ENTRIES" | |
6 PROXY_HOST = "PROXY_HOST" | |
7 PROXY_PORT = "PROXY_PORT" | |
8 SHOW_ONLY_UNREAD_FEEDS = "SHOW_ONLY_UNREAD_FEEDS" | |
5 START_MAXIMIZED = "START_MAXIMIZED" | 9 START_MAXIMIZED = "START_MAXIMIZED" |
6 HIDE_READ_ENTRIES = "HIDE_READ_FEED_ENTRIES" | |
7 SHOW_ONLY_UNREAD_FEEDS = "SHOW_ONLY_UNREAD_FEEDS" | |
8 | 10 |
9 class Preferences(object): | 11 class Preferences(object): |
10 def __init__(self, session): | 12 def __init__(self, session): |
11 self.session = session | 13 self.session = session |
12 self.cache = {} | 14 self.cache = {} |
13 | 15 |
14 def _cachedPreference(self, key, defaultValue=None): | 16 def _cachedPreference(self, key, defaultValue=None, addIfMissing=True): |
15 if self.cache.has_key(key): | 17 if self.cache.has_key(key): |
16 return self.cache[key] | 18 return self.cache[key] |
17 else: | 19 else: |
18 pref = Preference.forKey(key, self.session) | 20 pref = Preference.forKey(key, self.session) |
19 if pref is None: | 21 if pref is None and addIfMissing: |
20 pref = Preference(key, str(defaultValue)) | 22 pref = Preference(key, str(defaultValue)) |
21 self.session.add(pref) | 23 self.session.add(pref) |
22 self.cache[key] = pref | 24 self.cache[key] = pref |
23 return pref | 25 return pref |
24 | 26 |
25 def startMaximized(self): | 27 def startMaximized(self): |
26 pref = self._cachedPreference(START_MAXIMIZED, False) | 28 pref = self._cachedPreference(START_MAXIMIZED, False) |
27 return util.str2bool(pref.value) | 29 return util.str2bool(pref.value) |
28 | 30 |
29 def setStartMaximized(self, flag): | 31 def setStartMaximized(self, flag): |
31 pref.value = util.bool2str(flag) | 33 pref.value = util.bool2str(flag) |
32 | 34 |
33 def hideReadFeedEntries(self): | 35 def hideReadFeedEntries(self): |
34 pref = self._cachedPreference(HIDE_READ_ENTRIES, False) | 36 pref = self._cachedPreference(HIDE_READ_ENTRIES, False) |
35 return util.str2bool(pref.value) | 37 return util.str2bool(pref.value) |
36 | 38 |
37 def setHideReadFeedEntries(self, flag): | 39 def setHideReadFeedEntries(self, flag): |
38 pref = self._cachedPreference(HIDE_READ_ENTRIES) | 40 pref = self._cachedPreference(HIDE_READ_ENTRIES) |
39 pref.value = util.bool2str(flag) | 41 pref.value = util.bool2str(flag) |
40 | 42 |
41 def showOnlyUnreadFeeds(self): | 43 def showOnlyUnreadFeeds(self): |
42 pref = self._cachedPreference(SHOW_ONLY_UNREAD_FEEDS, False) | 44 pref = self._cachedPreference(SHOW_ONLY_UNREAD_FEEDS, False) |
43 return util.str2bool(pref.value) | 45 return util.str2bool(pref.value) |
44 | 46 |
45 def setShowOnlyUnreadFeeds(self, flag): | 47 def setShowOnlyUnreadFeeds(self, flag): |
46 pref = self._cachedPreference(SHOW_ONLY_UNREAD_FEEDS) | 48 pref = self._cachedPreference(SHOW_ONLY_UNREAD_FEEDS) |
47 pref.value = util.bool2str(flag) | 49 pref.value = util.bool2str(flag) |
50 | |
51 def proxyHost(self): | |
52 pref = self._cachedPreference(PROXY_HOST) | |
53 return pref.value | |
54 | |
55 def setProxyHost(self, hostname): | |
56 pref = self._cachedPreference(PROXY_HOST) | |
57 pref.value = hostname | |
58 | |
59 def proxyPort(self): | |
60 pref = self._cachedPreference(PROXY_PORT, 3128) | |
61 return int(pref.value) | |
62 | |
63 def setProxyPort(self, port): | |
64 pref = self._cachedPreference(PROXY_PORT) | |
65 pref.value = str(port) | |
66 | |
67 def isProxyConfigured(self): | |
68 pref = self._cachedPreference(PROXY_HOST, addIfMissing=False) | |
69 return pref is not None |