[Kazehakase-cvs] CVS update: kazehakase/src

Back to archive index

Hiroyuki Ikezoe ikezo****@users*****
Tue Jan 2 10:51:42 JST 2007


Index: kazehakase/src/kz-app.c
diff -u kazehakase/src/kz-app.c:1.11 kazehakase/src/kz-app.c:1.12
--- kazehakase/src/kz-app.c:1.11	Tue Jan  2 09:17:34 2007
+++ kazehakase/src/kz-app.c	Tue Jan  2 10:51:42 2007
@@ -345,29 +345,104 @@
 		(kz, G_CALLBACK(cb_window_map), action);
 }
 
-static void
-restore_session (KzApp *app, KzWindow *kz)
+void
+kz_app_restore_session (KzApp *app)
 {
-	GtkAction *action;
-	gchar *current_session_file;
-	KzAppPrivate *priv = KZ_APP_GET_PRIVATE(app);
+	GList *list;
+	const GList *node;
+	gchar *current_session;
+	const GList *window_list, *window_node;
+
+	g_return_if_fail(KZ_IS_APP(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))
+	{
+		g_free(current_session);
+		return;
+	}
 
-	current_session_file  = g_build_filename(g_get_home_dir(),
-						 "."PACKAGE,
-						 "current_session.xml",
-					    	 NULL);
-	kz_root_bookmark_add_current_session_file(priv->bookmarks,
-						  current_session_file);
-	kz_session_set_profile(KZ_SESSION(priv->bookmarks->current_session), priv->profile);
-
-	action = gtk_action_group_get_action(kz->actions,
-			"RestoreSession");
-	if (GTK_WIDGET_MAPPED(kz))
-		gtk_action_activate(action);
-	else
-		g_signal_connect(kz, "map", G_CALLBACK(cb_window_map), action);
-	
-	g_free(current_session_file);
+	/* close all tabs before loading session file */
+	window_list = KZ_GET_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);
+
+	list = kz_bookmark_get_children(KZ_GET_CURRENT_SESSION);
+
+	window_node = window_list;
+	/* windows */
+	for (node = list; node; node = g_list_next(node))
+	{
+		GList *tabs, *tabnode;
+		KzWindow *window;
+		gint pos;
+		KzBookmark *window_bookmark = KZ_BOOKMARK(node->data);
+		tabs = kz_bookmark_get_children(window_bookmark);
+
+		if (!window_node)
+		{
+			window = KZ_WINDOW(kz_app_create_new_window(app, NULL));
+			gtk_widget_show(GTK_WIDGET(window));
+		}
+		else
+		{
+			window = KZ_WINDOW(window_node->data);
+			window_node = g_list_next(window_node);
+		}
+
+		/* tabs */
+		for (tabnode = tabs; tabnode; tabnode = g_list_next(tabnode))
+		{
+			GtkWidget *widget;
+			KzBookmark *child = KZ_BOOKMARK(tabnode->data);
+			KzTabLabel *kztab;
+			widget = kz_window_open_new_tab_at_tail(window, NULL);
+			kz_embed_set_history(KZ_EMBED(widget), child);
+			kztab = KZ_TAB_LABEL(gtk_notebook_get_tab_label(GTK_NOTEBOOK(window->notebook),
+									widget));
+
+			if (kz_bookmark_get_lock(child))
+			{
+				kz_tab_label_set_lock(kztab, TRUE);
+			}
+			if (kz_bookmark_get_auto_refresh(child))
+			{
+				kz_tab_label_set_auto_refresh(kztab, TRUE);
+			}
+			if (kz_bookmark_get_javascript(child))
+			{
+				kz_embed_set_allow_javascript(KZ_EMBED(kztab->kzembed), TRUE);
+				kz_tab_label_set_javascript(kztab, TRUE);
+			}
+			else
+			{
+				kz_embed_set_allow_javascript(KZ_EMBED(kztab->kzembed), FALSE);
+				kz_tab_label_set_javascript(kztab, FALSE);
+			}
+		}
+		g_list_free(tabs);
+		pos = kz_bookmark_get_current(window_bookmark);
+		gtk_notebook_set_current_page(GTK_NOTEBOOK(window->notebook), pos);
+	}
+	g_list_free(list);
+
+	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));
 }
 
 GtkWidget *
@@ -376,14 +451,36 @@
 	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)
-			restore_session (app, KZ_WINDOW(window));
+			kz_app_restore_session(app);
 	}
 
 	g_signal_connect(window, "destroy",
Index: kazehakase/src/kz-app.h
diff -u kazehakase/src/kz-app.h:1.3 kazehakase/src/kz-app.h:1.4
--- kazehakase/src/kz-app.h:1.3	Sun Dec 31 22:19:38 2006
+++ kazehakase/src/kz-app.h	Tue Jan  2 10:51:42 2007
@@ -57,6 +57,8 @@
 
 GtkWidget *kz_app_create_new_window (KzApp *app, const gchar *uri);
 
+void	   kz_app_restore_session   (KzApp *app);
+
 
 KzFavicon      *kz_app_get_favicon       (KzApp *app);
 KzSearch       *kz_app_get_search        (KzApp *app);


More information about the Kazehakase-cvs mailing list
Back to archive index