OSDN Git Service

Add saving and restoring windows
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Wed, 23 Aug 2006 13:14:06 +0000 (22:14 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Wed, 23 Aug 2006 13:14:06 +0000 (22:14 +0900)
src/Hage1/board_window.py
src/Hage1/session.py
src/Hage1/thread_window.py
src/hage1

index 9871b89..adbdb02 100644 (file)
@@ -146,7 +146,7 @@ class WinWrap:
         pass
 
     def on_quit_activate(self, widget):
-        gtk.main_quit()
+        session.main_quit()
 
     def on_close_activate(self, widget):
         self.window.destroy()
index 8ae272a..84483bd 100644 (file)
@@ -19,7 +19,14 @@ import pygtk
 pygtk.require('2.0')
 import gtk
 import gobject
+import gconf
+
+import uri_opener
 from BbsType import bbs_type_judge_uri
+from BbsType import bbs_type_exception
+import config
+
+_gconf_key_windows = "/apps/" + config.APPNAME + "/windows"
 
 # key: /bbs/board/thread value: toplevel window widget
 _windows = {}
@@ -66,3 +73,39 @@ def on_thread_idx_updated(thread_uri, idx_dic):
     winwrap = get_window(bbs_type.get_uri_base())
     if winwrap:
         winwrap.on_thread_idx_updated(thread_uri, idx_dic)
+
+def main_quit():
+    print "session main quit"
+
+    tmp_win_dict = dict(_windows)
+    uris = _windows.keys()
+    if uris:
+        gconf_client = gconf.client_get_default()
+        try:
+            gconf_client.set_list(
+                _gconf_key_windows, gconf.VALUE_STRING, uris)
+            print "save windows", uris
+        except:
+            pass
+
+    for uri, winwrap in tmp_win_dict.iteritems():
+        winwrap.window.destroy()
+
+    # do not reach here
+    gtk.main_quit()
+
+def restore():
+    gconf_client = gconf.client_get_default()
+
+    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()
+    if not _windows:
+        uri_opener.open_uri("http://ex11.2ch.net/morningcoffee/")
+    gtk.main()    
index 98177e1..9ba6261 100644 (file)
@@ -95,7 +95,7 @@ class WinWrap:
         -1
 
     def on_quit_activate(self, widget):
-        gtk.main_quit()
+        session.main_quit()
 
     def on_show_board_activate(self, widget):
         board_window.open_board(self.bbs_type.get_uri_base())
index 3c7a1ac..0e325f7 100755 (executable)
--- a/src/hage1
+++ b/src/hage1
@@ -32,6 +32,7 @@ from Hage1 import board_window
 from Hage1 import config
 from Hage1 import dbus_object
 from Hage1 import uri_opener
+from Hage1 import session
 
 APPNAME = 'Hage1'
 APPVERSION = '0.1'
@@ -100,7 +101,9 @@ if __name__ == "__main__":
                     uri_opener.open_uri(uri)
                 except bbs_type_exception.BbsTypeError, msg:
                     print msg
-            gtk.main()
+
+        session.start()
+
     else:
         # the instance exists. send message and exit.