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 = {}
def get_window(key):
if key in _windows:
- return _windows[key]
+ return _windows[key]["winwrap"]
else:
return None
if key in _windows:
return False
- winwrap.window.connect("destroy", on_window_destroy, key)
- _windows[key] = winwrap
+ handler_id = winwrap.window.connect("destroy", on_window_destroy, key)
+ _windows[key] = {"winwrap": winwrap, "handler_id": handler_id}
print "regist to _windows", key
return True
if key not in _windows:
return
+ do_on_window_destroy(key, get_window(key))
+
del _windows[key]
print "unregist from _windows", key
on_all_window_destroy()
def on_all_window_destroy():
- gtk.main_quit()
+ main_quit()
def thread_idx_updated(thread_uri, idx_dic):
if not thread_uri or not idx_dic:
winwrap = get_window(bbs_type.get_uri_base())
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()
+ 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
+
+ for uri, value in _windows.iteritems():
+ value["winwrap"].window.disconnect(value["handler_id"])
+ value["winwrap"].window.destroy()
+ do_on_window_destroy(uri, value["winwrap"])
+
+ 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()