Mercurial > hg > Feedworm
view Preferences.py @ 90:a1066e5a8f88
save pending changes when quitting the app
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Fri, 24 Dec 2010 05:06:21 +0100 |
parents | b8bfd1bd6c55 |
children | 43c234c8fe87 |
line wrap: on
line source
from Preference import Preference import util HIDE_READ_ENTRIES = "HIDE_READ_FEED_ENTRIES" PROXY_HOST = "PROXY_HOST" PROXY_PORT = "PROXY_PORT" SHOW_ONLY_UNREAD_FEEDS = "SHOW_ONLY_UNREAD_FEEDS" START_MAXIMIZED = "START_MAXIMIZED" class Preferences(object): def __init__(self, session): self.session = session self.cache = {} def _cachedPreference(self, key, defaultValue=None, addIfMissing=True): if self.cache.has_key(key): return self.cache[key] else: pref = Preference.forKey(key, self.session) if pref is None and addIfMissing: pref = Preference(key, str(defaultValue)) self.session.add(pref) self.cache[key] = pref return pref def startMaximized(self): pref = self._cachedPreference(START_MAXIMIZED, False) return util.str2bool(pref.value) def setStartMaximized(self, flag): pref = self._cachedPreference(START_MAXIMIZED) pref.value = util.bool2str(flag) def hideReadFeedEntries(self): pref = self._cachedPreference(HIDE_READ_ENTRIES, False) return util.str2bool(pref.value) def setHideReadFeedEntries(self, flag): pref = self._cachedPreference(HIDE_READ_ENTRIES) pref.value = util.bool2str(flag) def showOnlyUnreadFeeds(self): pref = self._cachedPreference(SHOW_ONLY_UNREAD_FEEDS, False) return util.str2bool(pref.value) def setShowOnlyUnreadFeeds(self, flag): pref = self._cachedPreference(SHOW_ONLY_UNREAD_FEEDS) pref.value = util.bool2str(flag) def proxyHost(self): pref = self._cachedPreference(PROXY_HOST) return pref.value def setProxyHost(self, hostname): pref = self._cachedPreference(PROXY_HOST) pref.value = hostname def proxyPort(self): pref = self._cachedPreference(PROXY_PORT, 3128) return int(pref.value) def setProxyPort(self, port): pref = self._cachedPreference(PROXY_PORT) pref.value = str(port) def isProxyConfigured(self): pref = self._cachedPreference(PROXY_HOST, addIfMissing=False) return pref is not None