Use list.sort's keyword parameters
[joel/kofoto.git] / src / packages / kofoto / gkofoto / persistentstate.py
1 import codecs
2 import os
3 import sys
4 from kofoto.clientutils import expanduser
5 from kofoto.config import Config
6
7 class PersistentState(object):
8     def __init__(self, env):
9         self.__configParser = Config(env.localeEncoding)
10         self.__env = env
11         cp = self.__configParser
12
13         # Defaults:
14         cp.add_section("state")
15         cp.set("state", "filter-text", "")
16
17         home = expanduser("~")
18         if sys.platform.startswith("win"):
19             self.__stateFile = os.path.join(
20                 home, u"KofotoData", u"state", u"gkofoto.ini")
21         else:
22             self.__stateFile = os.path.join(
23                 home, u".kofoto", u"state", u"gkofoto")
24         if not os.path.isdir(os.path.dirname(self.__stateFile)):
25             os.mkdir(os.path.dirname(self.__stateFile))
26         if os.path.isfile(self.__stateFile):
27             cp.read(self.__stateFile)
28
29     def save(self):
30         fp = codecs.open(self.__stateFile, "w", self.__env.localeEncoding)
31         self.__configParser.write(fp)
32
33     def getFilterText(self):
34         return self.__configParser.get("state", "filter-text")
35
36     def setFilterText(self, text):
37         self.__configParser.set("state", "filter-text", text)
38
39     filterText = property(getFilterText, setFilterText)