OSDN Git Service

Use progressbar of board window.
[fukui-no-namari/fukui-no-namari.git] / src / FukuiNoNamari / session.py
index 9f97563..99b2319 100644 (file)
@@ -20,40 +20,43 @@ pygtk.require('2.0')
 import gtk
 import gobject
 import gconf
+import traceback
 
 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 = {}
 
 def get_window(key):
     if key in _windows:
-        return _windows[key]["winwrap"]
+        return _windows[key]
     else:
         return None
 
-def window_created(key, winwrap):
-    if not key or not winwrap:
+def regist(winwrap):
+    if not winwrap:
         raise ValueError, "parameter must not be empty"
 
+    key = winwrap.get_uri()
+    if not key:
+        raise ValueError, "uri must not be empty"
+
     if key in _windows:
         return False
-    handler_id = winwrap.window.connect("destroy", on_window_destroy, key)
-    _windows[key] = {"winwrap": winwrap, "handler_id": handler_id}
+
+    _windows[key] = winwrap
     print "regist to _windows", key
     return True
 
-def on_window_destroy(widget, key):
+def unregist(winwrap):
+    key = winwrap.get_uri()
     if key not in _windows:
+        print key, "is not found in _windows"
         return
 
-    do_on_window_destroy(key, get_window(key))
-
     del _windows[key]
     print "unregist from _windows", key
 
@@ -62,7 +65,7 @@ def on_window_destroy(widget, key):
         on_all_window_destroy()
 
 def on_all_window_destroy():
-    main_quit()
+    gtk.main_quit()
 
 def thread_idx_updated(thread_uri, idx_dic):
     if not thread_uri or not idx_dic:
@@ -76,36 +79,38 @@ def on_thread_idx_updated(thread_uri, idx_dic):
     if winwrap:
         winwrap.on_thread_idx_updated(thread_uri, idx_dic)
 
-def do_on_window_destroy(uri, winwrap):
-    print "window destroyed:", uri
-    
 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)
+                gconf_key_windows, gconf.VALUE_STRING, uris)
             print "save windows", uris
         else:
-            gconf_client.unset(_gconf_key_windows)
+            gconf_client.unset(gconf_key_windows)
             print "save no window"
     except:
         pass
 
-    for uri, value in _windows.iteritems():
-        value["winwrap"].window.disconnect(value["handler_id"])
-        value["winwrap"].window.destroy()
-        do_on_window_destroy(uri, value["winwrap"])
+    temp = dict(_windows)
+    for uri, winwrap in temp.iteritems():
+        try:
+            winwrap.destroy()
+        except:
+            traceback.print_exc()
 
+    # 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)
+    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)
@@ -116,4 +121,6 @@ def start():
     restore()
     if not _windows:
         uri_opener.open_uri("http://ex11.2ch.net/morningcoffee/")
-    gtk.main()    
+    gtk.threads_enter()
+    gtk.main()
+    gtk.threads_leave()