From: Ed Page Date: Sun, 26 Apr 2009 01:35:42 +0000 (-0500) Subject: Adding the file backend as a choice in the UI X-Git-Url: http://vcs.maemo.org/git/?p=doneit;a=commitdiff_plain;h=0ba4348cb475c8ddfb1ac674995201f09bba8b8e Adding the file backend as a choice in the UI --- diff --git a/src/doneit_glade.py b/src/doneit_glade.py index a699ae5..abedb35 100755 --- a/src/doneit_glade.py +++ b/src/doneit_glade.py @@ -212,7 +212,14 @@ class DoneIt(object): with gtk_toolbox.gtk_lock(): rtmView = rtm_view.RtmView(self._widgetTree, self.__errorDisplay) self._todoUIs[rtmView.name()] = rtmView - self._defaultUIName = rtmView.name() + + import file_view + defaultStoragePath = "%s/data.txt" % self._user_data + with gtk_toolbox.gtk_lock(): + fileView = file_view.FileView(self._widgetTree, self.__errorDisplay, defaultStoragePath) + self._todoUIs[fileView.name()] = fileView + + self._defaultUIName = fileView.name() config = ConfigParser.SafeConfigParser() config.read(self._user_settings) diff --git a/src/file_backend.py b/src/file_backend.py index 78360c2..954e38e 100644 --- a/src/file_backend.py +++ b/src/file_backend.py @@ -19,14 +19,23 @@ class FileBackend(object): "items": self._items, "locations": self._locations, } - pickle.dump(state, self._filename) + with open(self._filename, "wb") as pickleFile: + pickle.dump(state, pickleFile) def load(self): - state = pickle.load(self._filename) + try: + with open(self._filename, "rb") as pickleFile: + state = pickle.load(pickleFile) + except IOError, e: + if e.errno != 2: + raise self._projects = state["projects"] self._items = state["items"] self._locations = state["locations"] + if len(self._projects) == 0: + self.add_project("Inbox") + def add_project(self, name): projId = uuid.uuid4().hex projDetails = { diff --git a/src/file_view.py b/src/file_view.py new file mode 100644 index 0000000..5ba94fe --- /dev/null +++ b/src/file_view.py @@ -0,0 +1,52 @@ +""" +@todo Remove blocking operations from UI thread +""" + +import common_view + +import gtk_toolbox +import file_backend + + +class FileView(common_view.CommonView): + + def __init__(self, widgetTree, errorDisplay, defaultPath): + super(FileView, self).__init__(widgetTree, errorDisplay) + self._path = defaultPath + + @staticmethod + def name(): + return "File" + + def load_settings(self, config): + """ + @note Thread Agnostic + """ + path = config.get(self.name(), "path") + if path is not None: + self._path + + def save_settings(self, config): + """ + @note Thread Agnostic + """ + self._manager.save() + config.add_section(self.name()) + config.set(self.name(), "path", self._path) + + def login(self): + """ + @note UI Thread + """ + if self._manager is not None: + return + + self._manager = file_backend.FileBackend(self._path) + self._manager.load() + + def logout(self): + """ + @note Thread Agnostic + """ + self._manager.save() + self._manager = None