New gkofoto module persistentstate for storing state that should be
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 19 Aug 2004 19:48:42 +0000 (19:48 +0000)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 19 Aug 2004 19:48:42 +0000 (19:48 +0000)
remembered between runs.

Made the filter text persistent.

src/gkofoto/gkofoto/controller.py
src/gkofoto/gkofoto/mainwindow.py
src/gkofoto/gkofoto/persistentstate.py [new file with mode: 0644]
src/gkofoto/glade/gkofoto.glade

index 9bc9091..9f25f86 100644 (file)
@@ -48,16 +48,16 @@ class Controller:
             result = quitDialog.run()
             if result == 0:
                 env.shelf.commit()
-                gtk.main_quit()
+                self._doQuit()
             elif result == 1:
                 env.shelf.rollback()
-                gtk.main_quit()
+                self._doQuit()
             else:
                 quitDialog.destroy()
                 return
         else:
             env.shelf.rollback()
-            gtk.main_quit()
+            self._doQuit()
 
     def save(self, app):
         env.shelf.commit()
@@ -73,3 +73,7 @@ class Controller:
             env.shelf.begin()
             self.__mainWindow.reload()
         dialog.destroy()
+
+    def _doQuit(self):
+        self.__mainWindow.saveState()
+        gtk.main_quit()
index 9ed2b65..e9c08ac 100644 (file)
@@ -13,6 +13,7 @@ from gkofoto.objectcollection import *
 from gkofoto.registerimagesdialog import RegisterImagesDialog
 from gkofoto.handleimagesdialog import HandleImagesDialog
 from gkofoto.generatehtmldialog import GenerateHTMLDialog
+from gkofoto.persistentstate import PersistentState
 
 class MainWindow(gtk.Window):
     def __init__(self):
@@ -20,8 +21,10 @@ class MainWindow(gtk.Window):
         self._toggleLock = False
         self.__currentObjectCollection = None
         self._currentView = None
+        self.__persistentState = PersistentState()
         self.__sourceEntry = env.widgets["sourceEntry"]
         self.__filterEntry = env.widgets["filterEntry"]
+        self.__filterEntry.set_text(self.__persistentState.filterText)
         self.__isFilterEnabledCheckbox = env.widgets["isFilterEnabledCheckbox"]
         env.widgets["expandViewToggleButton"].connect("toggled", self._toggleExpandView)
         env.widgets["expandViewToggleButton"].get_child().add(self.getIconImage("fullscreen-24.png"))
@@ -81,25 +84,27 @@ class MainWindow(gtk.Window):
         self.__singleObjectView = SingleObjectView()
         self.__showTableView()
 
+    def saveState(self):
+        self.__persistentState.save()
+
     def _queryChanged(self, *foo):
         query = self.__sourceEntry.get_text().decode("utf-8")
         self.loadQuery(query)
         self.__sourceEntry.grab_remove()
+        self.__persistentState.filterText = self.__filterEntry.get_text()
 
     def loadQuery(self, query):
         self.__query = query
         self.__sourceEntry.set_text(query)
         useFilter = self.__isFilterEnabledCheckbox.get_active()
-        filter = self.__filterEntry.get_text().decode("utf-8")
+        filterText = self.__filterEntry.get_text().decode("utf-8")
         self.__filterEntry.set_sensitive(useFilter)
-        if useFilter and len(filter) > 0:
-            self.__setObjectCollection(
-                self.__factory.getObjectCollection("(" + query +
-                                                   u") and (" +
-                                                   filter + ")"))
+        if useFilter and len(filterText) > 0:
+            queryWithFilter = "(%s) and (%s)" % (query, filterText)
         else:
-            self.__setObjectCollection(
-                self.__factory.getObjectCollection(query))
+            queryWithFilter = query
+        self.__setObjectCollection(
+            self.__factory.getObjectCollection(queryWithFilter))
 
     def reload(self):
         self.__albums.loadAlbumTree()
diff --git a/src/gkofoto/gkofoto/persistentstate.py b/src/gkofoto/gkofoto/persistentstate.py
new file mode 100644 (file)
index 0000000..e5c4db3
--- /dev/null
@@ -0,0 +1,33 @@
+import ConfigParser
+import os
+import sys
+
+class PersistentState(object):
+    def __init__(self):
+        self.__configParser = ConfigParser.ConfigParser()
+        cp = self.__configParser
+
+        # Defaults:
+        cp.add_section("state")
+        cp.set("state", "filter-text", "")
+
+        home = os.path.expanduser("~")
+        if sys.platform.startswith("win"):
+            self.__stateFile = os.path.join(
+                home, "KofotoData", "gkofoto-state.ini")
+        else:
+            self.__stateFile = os.path.join(
+                home, ".kofoto", "gkofoto-state")
+        if os.path.isfile(self.__stateFile):
+            self.__configParser.read(self.__stateFile)
+
+    def save(self):
+        self.__configParser.write(open(self.__stateFile, "w"))
+
+    def getFilterText(self):
+        return self.__configParser.get("state", "filter-text")
+
+    def setFilterText(self, text):
+        self.__configParser.set("state", "filter-text", text)
+
+    filterText = property(getFilterText, setFilterText)
index 150e32f..b5b3e73 100644 (file)
              <property name="editable">True</property>
              <property name="visibility">True</property>
              <property name="max_length">0</property>
-             <property name="text" translatable="yes">not ignore</property>
+             <property name="text" translatable="yes"></property>
              <property name="has_frame">True</property>
              <property name="invisible_char" translatable="yes">*</property>
              <property name="activates_default">False</property>