Hiroyuki Ikezoe
ikezo****@users*****
Tue Jan 2 18:23:47 JST 2007
Index: kazehakase/src/kz-app.c diff -u kazehakase/src/kz-app.c:1.12 kazehakase/src/kz-app.c:1.13 --- kazehakase/src/kz-app.c:1.12 Tue Jan 2 10:51:42 2007 +++ kazehakase/src/kz-app.c Tue Jan 2 18:23:46 2007 @@ -124,17 +124,17 @@ } static void -kz_app_init (KzApp *kzapp) +kz_app_init (KzApp *app) { gchar *sysconf_file, *conf_file; gchar *bookmark_file, *sys_bookmark_file; - gchar *clip_file; + gchar *clip_file, *current_session_file; gchar *bookmark_bar_file, *sys_bookmark_bar_file; gchar *smartbookmark_file, *sys_smartbookmark_file; gchar *accel_prefs_file; gchar *proxy_file, *sysproxy_file; gchar *search_engine; - KzAppPrivate *priv = KZ_APP_GET_PRIVATE(kzapp); + KzAppPrivate *priv = KZ_APP_GET_PRIVATE(app); priv->window_list = NULL; priv->favicon = kz_favicon_get_instance(); @@ -191,6 +191,11 @@ "smartbookmarks.xml", NULL); + current_session_file = g_build_filename(g_get_home_dir(), + "."PACKAGE, + "current_session.xml", + NULL); + priv->bookmarks = kz_root_bookmark_new(bookmark_file, sys_bookmark_file, clip_file, NULL); @@ -200,6 +205,10 @@ kz_root_bookmark_add_bookmark_bar_file(priv->bookmarks, bookmark_bar_file, sys_bookmark_bar_file); + kz_root_bookmark_add_current_session_file(priv->bookmarks, + current_session_file); + kz_session_set_profile(KZ_SESSION(priv->bookmarks->current_session), + priv->profile); /* Load other prefs... */ accel_prefs_file = g_build_filename(g_get_home_dir(), @@ -214,6 +223,8 @@ "proxyrc", NULL); priv->proxy = kz_profile_open(proxy_file, sysproxy_file); + mozilla_init(priv->profile); + #if USE_MIGEMO priv->migemo = kz_migemo_new(); #endif @@ -226,7 +237,7 @@ gnutls_global_init(); #endif - kz_ext_init(kzapp); + kz_ext_init(app); /* make dirs */ prepare_dir(); @@ -240,6 +251,7 @@ g_free(sys_bookmark_bar_file); g_free(smartbookmark_file); g_free(sys_smartbookmark_file); + g_free(current_session_file); g_free(accel_prefs_file); g_free(sysproxy_file); g_free(proxy_file); @@ -346,39 +358,53 @@ } void +kz_app_save_session (KzApp *app) +{ + KzAppPrivate *priv; + + g_return_if_fail(KZ_IS_APP(app)); + + priv = KZ_APP_GET_PRIVATE(app); + kz_bookmark_file_save(KZ_BOOKMARK_FILE(priv->bookmarks->current_session)); +} + +GtkWidget * kz_app_restore_session (KzApp *app) { GList *list; const GList *node; - gchar *current_session; + gchar *session_file; const GList *window_list, *window_node; + KzAppPrivate *priv; + KzBookmarkFile *tmp_bookmark; - g_return_if_fail(KZ_IS_APP(app)); + g_return_val_if_fail(KZ_IS_APP(app), NULL); + + priv = KZ_APP_GET_PRIVATE(app); /* reload from current session file */ - current_session = g_build_filename(g_get_home_dir(), - "."PACKAGE, - "current_session.xml", - NULL); - if (!g_file_test(current_session, G_FILE_TEST_EXISTS)) + session_file = g_build_filename(g_get_home_dir(), + "."PACKAGE, + "current_session.xml", + NULL); + if (!g_file_test(session_file, G_FILE_TEST_EXISTS)) { - g_free(current_session); - return; + g_free(session_file); + return NULL; } /* close all tabs before loading session file */ - window_list = KZ_GET_WINDOW_LIST; + window_list = priv->window_list; for (node = window_list; node; node = g_list_next(node)) kz_window_close_all_tab(KZ_WINDOW(node->data)); - kz_root_bookmark_add_current_session_file(KZ_GET_ROOT_BOOKMARK, - current_session); - kz_session_set_profile(KZ_SESSION(KZ_GET_CURRENT_SESSION), - KZ_GET_GLOBAL_PROFILE); - kz_session_freeze(KZ_SESSION(KZ_GET_CURRENT_SESSION)); - g_free(current_session); + kz_session_freeze(KZ_SESSION(priv->bookmarks->current_session)); + tmp_bookmark = kz_bookmark_file_new(session_file, "Temporary session bookmark", + "XBEL"); + kz_bookmark_file_load(tmp_bookmark); + g_free(session_file); - list = kz_bookmark_get_children(KZ_GET_CURRENT_SESSION); + list = kz_bookmark_get_children(KZ_BOOKMARK(tmp_bookmark)); window_node = window_list; /* windows */ @@ -393,7 +419,6 @@ if (!window_node) { window = KZ_WINDOW(kz_app_create_new_window(app, NULL)); - gtk_widget_show(GTK_WIDGET(window)); } else { @@ -437,12 +462,18 @@ } g_list_free(list); + /* close extra windows */ for (;window_node; window_node = g_list_next(window_node)) { KzWindow *window = KZ_WINDOW(window_node->data); gtk_widget_destroy(GTK_WIDGET(window)); } - kz_session_thaw(KZ_SESSION(KZ_GET_CURRENT_SESSION)); + + g_object_unref(tmp_bookmark); + kz_session_thaw(KZ_SESSION(priv->bookmarks->current_session)); + kz_bookmark_file_save(KZ_BOOKMARK_FILE(priv->bookmarks->current_session)); + + return GTK_WIDGET(priv->window_list->data); } GtkWidget * @@ -451,38 +482,8 @@ GtkWidget *window; KzAppPrivate *priv = KZ_APP_GET_PRIVATE(app); - if (!priv->window_list) - { - gboolean save = FALSE; - - KZ_CONF_GET("Session", "save", save, BOOL); - if (save) - { - gchar *session_file; - session_file = g_build_filename(g_get_home_dir(), - "."PACKAGE, - "current_session.xml", - NULL); - - kz_root_bookmark_add_current_session_file(KZ_GET_ROOT_BOOKMARK, - session_file); - kz_session_set_profile(KZ_SESSION(KZ_GET_CURRENT_SESSION), - KZ_GET_GLOBAL_PROFILE); - g_free(session_file); - } - } - window = kz_window_new(uri); - if (!priv->window_list) - { - gboolean restore = FALSE; - - KZ_CONF_GET("Session", "restore", restore, BOOL); - if (restore) - kz_app_restore_session(app); - } - g_signal_connect(window, "destroy", G_CALLBACK(cb_destroy_window), app); priv->window_list = g_list_append(priv->window_list, window); Index: kazehakase/src/kz-app.h diff -u kazehakase/src/kz-app.h:1.4 kazehakase/src/kz-app.h:1.5 --- kazehakase/src/kz-app.h:1.4 Tue Jan 2 10:51:42 2007 +++ kazehakase/src/kz-app.h Tue Jan 2 18:23:46 2007 @@ -57,7 +57,8 @@ GtkWidget *kz_app_create_new_window (KzApp *app, const gchar *uri); -void kz_app_restore_session (KzApp *app); +GtkWidget *kz_app_restore_session (KzApp *app); +void kz_app_save_session (KzApp *app); KzFavicon *kz_app_get_favicon (KzApp *app); Index: kazehakase/src/main.c diff -u kazehakase/src/main.c:1.130 kazehakase/src/main.c:1.131 --- kazehakase/src/main.c:1.130 Sun Dec 31 21:21:47 2006 +++ kazehakase/src/main.c Tue Jan 2 18:23:46 2007 @@ -493,6 +493,7 @@ gint argc_copy; gboolean retval; GError *error = NULL; + gboolean restore = FALSE; /* initialize */ setlocale(LC_ALL, ""); @@ -542,10 +543,17 @@ } kz_app = kz_app_new(); - mozilla_init(); /* create window */ - window = kz_app_create_new_window(kz_app, NULL); + KZ_CONF_GET("Session", "restore", restore, BOOL); + if (restore) + { + window = kz_app_restore_session(kz_app); + if (!window) + window = kz_app_create_new_window(kz_app, NULL); + } + else + window = kz_app_create_new_window(kz_app, NULL); /* * gtk_window_pargse_geometry() needs to be called