OSDN Git Service

Saving windows to gconf is done everytime on window opening and closing.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Sat, 25 Apr 2009 05:43:00 +0000 (14:43 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Sat, 25 Apr 2009 05:43:00 +0000 (14:43 +0900)
src/FukuiNoNamari/session.py

index df0faf4..2f8deb2 100644 (file)
@@ -30,6 +30,53 @@ import config
 # key: /bbs/board/thread value: toplevel window widget
 _windows = {}
 
+
+class Gconf:
+
+    def __init__(self):
+        self._enable = False
+
+    def _is_enable_to_save(self):
+        return self._enable
+
+    def set_enable(self, enable):
+        self._enable = enable
+
+    def restore(self):
+        self.set_enable(False)
+
+        gconf_client = gconf.client_get_default()
+
+        gconf_key_windows = config.gconf_app_key_base() + "/windows"
+        uris = gconf_client.get_list(gconf_key_windows, gconf.VALUE_STRING)
+        for uri in uris:
+            try:
+                uri_opener.open_uri(uri)
+            except bbs_type_exception.BbsTypeError, msg:
+                print msg
+        self.set_enable(True)
+
+    def save(self):
+        if not self._is_enable_to_save():
+            print "save to gconf not enable"
+            return
+        uris = _windows.keys()
+        try:
+            gconf_client = gconf.client_get_default()
+            gconf_key_windows = config.gconf_app_key_base() + "/windows"
+            if uris:
+                gconf_client.set_list(
+                    gconf_key_windows, gconf.VALUE_STRING, uris)
+                print "save windows", uris
+            else:
+                gconf_client.unset(gconf_key_windows)
+                print "save no window"
+        except:
+            pass
+
+
+_gconf = Gconf()
+
 def get_window(key):
     if key in _windows:
         return _windows[key]
@@ -49,6 +96,7 @@ def regist(winwrap):
 
     _windows[key] = winwrap
     print "regist to _windows", key
+    _gconf.save()
     return True
 
 def unregist(winwrap):
@@ -63,6 +111,8 @@ def unregist(winwrap):
     if not _windows:
         print "all window unregist"
         on_all_window_destroy()
+    else:
+        _gconf.save()
 
 def on_all_window_destroy():
     gtk.main_quit()
@@ -82,20 +132,8 @@ def on_thread_idx_updated(thread_uri, idx_dic):
 def main_quit():
     print "session main quit"
 
-    uris = _windows.keys()
-    try:
-        gconf_client = gconf.client_get_default()
-        gconf_key_windows = config.gconf_app_key_base() + "/windows"
-        if uris:
-            gconf_client.set_list(
-                gconf_key_windows, gconf.VALUE_STRING, uris)
-            print "save windows", uris
-        else:
-            gconf_client.unset(gconf_key_windows)
-            print "save no window"
-    except:
-        pass
-
+    _gconf.save()
+    _gconf.set_enable(False)
     temp = dict(_windows)
     for uri, winwrap in temp.iteritems():
         try:
@@ -106,21 +144,10 @@ def main_quit():
     # not reach here.
     gtk.main_quit()
 
-def restore():
-    gconf_client = gconf.client_get_default()
-
-    gconf_key_windows = config.gconf_app_key_base() + "/windows"
-    uris = gconf_client.get_list(gconf_key_windows, gconf.VALUE_STRING)
-    for uri in uris:
-        try:
-            uri_opener.open_uri(uri)
-        except bbs_type_exception.BbsTypeError, msg:
-            print msg
-
 def start():
-    restore()
+    _gconf.restore()
     if not _windows:
-        uri_opener.open_uri("http://ex11.2ch.net/morningcoffee/")
+        uri_opener.open_uri("http://dubai.2ch.net/morningcoffee/")
     gtk.gdk.threads_enter()
     gtk.main()
     gtk.gdk.threads_leave()