diff options
-rw-r--r-- | ChangeLog | 29 | ||||
-rw-r--r-- | embed/ephy-embed.h | 5 | ||||
-rw-r--r-- | idl/EphyAutomation.idl | 8 | ||||
-rw-r--r-- | src/ephy-automation.c | 74 | ||||
-rw-r--r-- | src/ephy-completion-model.c | 2 | ||||
-rw-r--r-- | src/ephy-main.c | 9 | ||||
-rw-r--r-- | src/ephy-shell.c | 85 | ||||
-rw-r--r-- | src/ephy-shell.h | 6 | ||||
-rw-r--r-- | src/ephy-tab.c | 16 | ||||
-rw-r--r-- | src/ephy-window.c | 4 | ||||
-rw-r--r-- | src/session.c | 427 | ||||
-rw-r--r-- | src/session.h | 22 | ||||
-rw-r--r-- | src/window-commands.c | 15 |
13 files changed, 369 insertions, 333 deletions
@@ -1,3 +1,32 @@ +2003-11-09 Marco Pesenti Gritti <marco@gnome.org> + + * embed/ephy-embed.h: + * idl/EphyAutomation.idl: + * src/ephy-automation.c: (impl_ephy_automation_loadurl), + (impl_ephy_automation_open_bookmarks_editor), + (ephy_automation_init), (ephy_automation_object_finalize), + (ephy_automation_class_init): + * src/ephy-completion-model.c: (root_child_removed_cb): + * src/ephy-main.c: (ephy_main_start): + * src/ephy-shell.c: (ephy_shell_get_active_window), + (toolwindow_show_cb), (toolwindow_hide_cb), + (ephy_shell_get_bookmarks_editor), (ephy_shell_get_history_window): + * src/ephy-shell.h: + * src/ephy-tab.c: (ephy_tab_net_state_cb), (ephy_tab_size_to_cb): + * src/ephy-window.c: (remove_from_session), (ephy_window_init): + * src/session.c: (session_autoresume), (session_close), + (session_dispose), (save_window_geometry), (save_tool_window), + (save_ephy_window), (session_save), (session_load), + (session_get_windows), (net_stop_cb), (tab_added_cb), + (tab_removed_cb), (tabs_reordered_cb), (session_add_window), + (session_remove_window), (save_yourself_cb), (session_die_cb), + (gnome_session_init), (session_init): + * src/session.h: + * src/window-commands.c: (window_cmd_go_bookmarks), + (window_cmd_go_history): + + Cleanup session. Persist also history and bookmarks. + 2003-11-09 Christian Persch <chpe@cvs.gnome.org> * src/window-commands.c: (window_cmd_help_about): diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h index 0ee52025c..bf2486953 100644 --- a/embed/ephy-embed.h +++ b/embed/ephy-embed.h @@ -152,6 +152,11 @@ struct EphyEmbedClass { GTypeInterface base_iface; + /* Signals that we inherit from gtkmozembed + * + * void (* net_stop) (GtkMozEmbed *embed); + */ + gint (* context_menu) (EphyEmbed *embed, EphyEmbedEvent *event); void (* favicon) (EphyEmbed *embed, diff --git a/idl/EphyAutomation.idl b/idl/EphyAutomation.idl index 074b341c8..c0aab2f9e 100644 --- a/idl/EphyAutomation.idl +++ b/idl/EphyAutomation.idl @@ -14,14 +14,6 @@ module GNOME { void importBookmarks (in string filename); - /** - * Closes all opened windows. - * if disableServer is true, - * server mode is disbaled - * (and Epiphany exits) - */ - void quit (); - void loadSession (in string filename); void openBookmarksEditor (); diff --git a/src/ephy-automation.c b/src/ephy-automation.c index 4f5b8b1b4..43bd1eef7 100644 --- a/src/ephy-automation.c +++ b/src/ephy-automation.c @@ -32,30 +32,7 @@ #include <bonobo/bonobo-context.h> static void -impl_ephy_automation_add_bookmark (PortableServer_Servant _servant, - const CORBA_char * url, - CORBA_Environment * ev); -static void -impl_ephy_automation_import_bookmarks (PortableServer_Servant _servant, - const CORBA_char * filename, - CORBA_Environment * ev); -static void -impl_ephy_automation_quit (PortableServer_Servant _servant, - CORBA_Environment * ev); -static void -impl_ephy_automation_load_session (PortableServer_Servant _servant, - const CORBA_char * filename, - CORBA_Environment * ev); -static void ephy_automation_class_init (EphyAutomationClass *klass); -static void -ephy_automation_init (EphyAutomation *a); -static void -ephy_automation_object_finalize (GObject *object); -static BonoboObject * -ephy_automation_factory (BonoboGenericFactory *this_factory, - const char *iid, - gpointer user_data); static GObjectClass *ephy_automation_parent_class; @@ -105,14 +82,11 @@ impl_ephy_automation_loadurl (PortableServer_Servant _servant, session = EPHY_SESSION (ephy_shell_get_session (ephy_shell)); - /* no window open, let's try to autoresume */ - if (session_get_windows (session) == NULL) + if (session_autoresume (session) && *url == '\0') { - gboolean res; - res = session_autoresume (session); /* no need to open the homepage, * we did already open session windows */ - if (res && *url == '\0') return; + return; } window = ephy_shell_get_active_window (ephy_shell); @@ -169,17 +143,6 @@ impl_ephy_automation_import_bookmarks (PortableServer_Servant _servant, } static void -impl_ephy_automation_quit (PortableServer_Servant _servant, - CORBA_Environment * ev) -{ - Session *session; - - session = EPHY_SESSION (ephy_shell_get_session (ephy_shell)); - - session_close (session); -} - -static void impl_ephy_automation_load_session (PortableServer_Servant _servant, const CORBA_char * filename, CORBA_Environment * ev) @@ -194,7 +157,24 @@ static void impl_ephy_automation_open_bookmarks_editor (PortableServer_Servant _servant, CORBA_Environment * ev) { - ephy_shell_show_bookmarks_editor (ephy_shell, NULL); + GtkWidget *editor; + + editor = ephy_shell_get_bookmarks_editor (ephy_shell); + + gtk_window_present (GTK_WINDOW (editor)); +} + +static void +ephy_automation_init (EphyAutomation *c) +{ +} + +static void +ephy_automation_object_finalize (GObject *object) +{ + EphyAutomation *a = EPHY_AUTOMATION (object); + + ephy_automation_parent_class->finalize (G_OBJECT (a)); } static void @@ -211,24 +191,10 @@ ephy_automation_class_init (EphyAutomationClass *klass) epv->loadurl = impl_ephy_automation_loadurl; epv->addBookmark = impl_ephy_automation_add_bookmark; epv->importBookmarks = impl_ephy_automation_import_bookmarks; - epv->quit = impl_ephy_automation_quit; epv->loadSession = impl_ephy_automation_load_session; epv->openBookmarksEditor = impl_ephy_automation_open_bookmarks_editor; } -static void -ephy_automation_init (EphyAutomation *c) -{ -} - -static void -ephy_automation_object_finalize (GObject *object) -{ - EphyAutomation *a = EPHY_AUTOMATION (object); - - ephy_automation_parent_class->finalize (G_OBJECT (a)); -} - BONOBO_TYPE_FUNC_FULL ( EphyAutomation, GNOME_EphyAutomation, diff --git a/src/ephy-completion-model.c b/src/ephy-completion-model.c index ec5bd3aaf..f407bb45b 100644 --- a/src/ephy-completion-model.c +++ b/src/ephy-completion-model.c @@ -164,12 +164,10 @@ root_child_removed_cb (EphyNode *node, path = gtk_tree_path_new (); index = old_index; - g_print ("Node index %d\n", index); if (node == model->priv->bookmarks) { index += ephy_node_get_n_children (model->priv->history); } - g_print ("List index %d\n", index); gtk_tree_path_append_index (path, index); gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path); diff --git a/src/ephy-main.c b/src/ephy-main.c index 5bd37115d..80627736c 100644 --- a/src/ephy-main.c +++ b/src/ephy-main.c @@ -48,7 +48,6 @@ static gboolean open_fullscreen = FALSE; /* open ephy in full screen ? */ static gchar *session_filename = NULL; /* the session filename */ static gchar *bookmark_url = NULL; /* the temp bookmark to add */ static gchar *bookmarks_file = NULL; /* the bookmarks file to import */ -static gboolean close_option = FALSE; /* --close */ static gboolean open_as_bookmarks_editor = FALSE; /* --bookmarks-editor */ static gboolean open_as_nautilus_view = FALSE; @@ -85,9 +84,6 @@ static struct poptOption popt_options[] = { "import-bookmarks", '\0', POPT_ARG_STRING, &bookmarks_file, 0, N_("Import bookmarks from the given file"), N_("FILE") }, - { "close", 'c', POPT_ARG_NONE, &close_option, 0, - N_("Close all Epiphany windows"), - NULL }, { "nautilus-view", 'v', POPT_ARG_NONE, &open_as_nautilus_view, 0, N_("Used internally by the nautilus view"), NULL }, @@ -209,11 +205,6 @@ ephy_main_start (gpointer data) GNOME_EphyAutomation_addBookmark (gaserver, bookmark_url, &corba_env); } - else if (close_option) - { - GNOME_EphyAutomation_quit - (gaserver, &corba_env); - } /* provided with urls? */ else if (!open_as_nautilus_view) { diff --git a/src/ephy-shell.c b/src/ephy-shell.c index a2e825372..806b8ca47 100644 --- a/src/ephy-shell.c +++ b/src/ephy-shell.c @@ -412,14 +412,25 @@ EphyWindow * ephy_shell_get_active_window (EphyShell *gs) { Session *session; - const GList *windows; + GList *windows, *l; + EphyWindow *window = NULL; session = EPHY_SESSION (ephy_shell_get_session (gs)); + windows = session_get_windows (session); - if (windows == NULL) return NULL; + for (l = windows; l != NULL; l = l->next) + { + if (EPHY_IS_WINDOW (l->data)) + { + window = EPHY_WINDOW (l->data); + break; + } + } + + g_list_free (windows); - return EPHY_WINDOW(windows->data); + return window; } /** @@ -628,15 +639,23 @@ ephy_shell_get_toolbars_model (EphyShell *gs, gboolean fullscreen) } static void -bookmarks_hide_cb (GtkWidget *widget, gpointer data) +toolwindow_show_cb (GtkWidget *widget) +{ + LOG ("Ref shell for %s", G_OBJECT_TYPE_NAME (widget)) + session_add_window (ephy_shell->priv->session, GTK_WINDOW (widget)); + g_object_ref (ephy_shell); +} + +static void +toolwindow_hide_cb (GtkWidget *widget) { - LOG ("Unref shell for bookmarks editor") + LOG ("Unref shell for %s", G_OBJECT_TYPE_NAME (widget)) + session_remove_window (ephy_shell->priv->session, GTK_WINDOW (widget)); g_object_unref (ephy_shell); } -void -ephy_shell_show_bookmarks_editor (EphyShell *gs, - GtkWidget *parent) +GtkWidget * +ephy_shell_get_bookmarks_editor (EphyShell *gs) { EphyBookmarks *bookmarks; @@ -645,35 +664,18 @@ ephy_shell_show_bookmarks_editor (EphyShell *gs, bookmarks = ephy_shell_get_bookmarks (ephy_shell); g_assert (bookmarks != NULL); gs->priv->bme = ephy_bookmarks_editor_new (bookmarks); - g_signal_connect (gs->priv->bme, "hide", - G_CALLBACK (bookmarks_hide_cb), NULL); - } - - if (!GTK_WIDGET_VISIBLE (gs->priv->bme)) - { - LOG ("Ref shell for bookmarks editor") - g_object_ref (ephy_shell); - } - if (parent) - { - ephy_bookmarks_editor_set_parent - (EPHY_BOOKMARKS_EDITOR (gs->priv->bme), parent); + g_signal_connect (gs->priv->bme, "show", + G_CALLBACK (toolwindow_show_cb), NULL); + g_signal_connect (gs->priv->bme, "hide", + G_CALLBACK (toolwindow_hide_cb), NULL); } - gtk_window_present (GTK_WINDOW (gs->priv->bme)); -} - -static void -history_window_hide_cb (GtkWidget *widget, gpointer data) -{ - LOG ("Unref shell for history window") - g_object_unref (ephy_shell); + return gs->priv->bme; } -void -ephy_shell_show_history_window (EphyShell *gs, - GtkWidget *parent) +GtkWidget * +ephy_shell_get_history_window (EphyShell *gs) { EphyHistory *history; @@ -683,23 +685,14 @@ ephy_shell_show_history_window (EphyShell *gs, (EPHY_EMBED_SHELL (ephy_shell)); g_assert (history != NULL); gs->priv->history_window = ephy_history_window_new (history); - g_signal_connect (gs->priv->history_window, "hide", - G_CALLBACK (history_window_hide_cb), NULL); - } - if (!GTK_WIDGET_VISIBLE (gs->priv->history_window)) - { - LOG ("Ref shell for history window") - g_object_ref (ephy_shell); - } - - if (parent) - { - ephy_history_window_set_parent - (EPHY_HISTORY_WINDOW (gs->priv->history_window), parent); + g_signal_connect (gs->priv->history_window, "show", + G_CALLBACK (toolwindow_show_cb), NULL); + g_signal_connect (gs->priv->history_window, "hide", + G_CALLBACK (toolwindow_hide_cb), NULL); } - gtk_window_present (GTK_WINDOW (gs->priv->history_window)); + return gs->priv->history_window; } void diff --git a/src/ephy-shell.h b/src/ephy-shell.h index 381277f53..772a357f6 100644 --- a/src/ephy-shell.h +++ b/src/ephy-shell.h @@ -96,11 +96,9 @@ EphyBookmarks *ephy_shell_get_bookmarks (EphyShell *gs); GObject *ephy_shell_get_toolbars_model (EphyShell *gs, gboolean fullscreen); -void ephy_shell_show_bookmarks_editor (EphyShell *gs, - GtkWidget *parent); +GtkWidget *ephy_shell_get_bookmarks_editor (EphyShell *gs); -void ephy_shell_show_history_window (EphyShell *gs, - GtkWidget *parent); +GtkWidget *ephy_shell_get_history_window (EphyShell *gs); void ephy_shell_delete_on_exit (EphyShell *gs, const char *path); diff --git a/src/ephy-tab.c b/src/ephy-tab.c index 822405d04..3f016a7a5 100644 --- a/src/ephy-tab.c +++ b/src/ephy-tab.c @@ -32,7 +32,6 @@ #include "ephy-notebook.h" #include "ephy-file-helpers.h" #include "ephy-zoom.h" -#include "session.h" #include "ephy-favicon-cache.h" #include <glib/gi18n.h> @@ -853,12 +852,6 @@ ephy_tab_net_state_cb (EphyEmbed *embed, const char *uri, } else if (state & EMBED_STATE_STOP) { - /* tab load completed, save in session */ - Session *s; - - s = EPHY_SESSION (ephy_shell_get_session (ephy_shell)); - session_save (s, SESSION_CRASHED); - ephy_tab_set_load_percent (tab, 0); ephy_tab_set_load_status (tab, FALSE); ephy_tab_update_navigation_flags (tab); @@ -932,7 +925,7 @@ static void ephy_tab_size_to_cb (EphyEmbed *embed, gint width, gint height, EphyTab *tab) { - GList *tabs = NULL; + GtkWidget *notebook; EphyWindow *window; GtkWidget *widget; EmbedChromeMask chromemask; @@ -941,7 +934,7 @@ ephy_tab_size_to_cb (EphyEmbed *embed, gint width, gint height, tab->priv->height = height; window = tab->priv->window; - tabs = ephy_window_get_tabs (window); + notebook = ephy_window_get_notebook (window); widget = GTK_WIDGET (embed); chromemask = ephy_window_get_chrome (window); @@ -949,7 +942,8 @@ ephy_tab_size_to_cb (EphyEmbed *embed, gint width, gint height, * Do not resize window already showed because * it's not possible to calculate a sensible window * size based on the embed size */ - if (g_list_length (tabs) == 1 && !tab->priv->visibility) + if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) == 1 && + !tab->priv->visibility) { gtk_widget_set_size_request (widget, width, height); @@ -966,8 +960,6 @@ ephy_tab_size_to_cb (EphyEmbed *embed, gint width, gint height, g_idle_add (let_me_resize_hack, embed); } } - - g_list_free (tabs); } static void diff --git a/src/ephy-window.c b/src/ephy-window.c index 461134ede..a32c218e7 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -356,7 +356,7 @@ remove_from_session (EphyWindow *window) session = EPHY_SESSION (ephy_shell_get_session (ephy_shell)); g_return_if_fail (session != NULL); - session_remove_window (session, window); + session_remove_window (session, GTK_WINDOW (window)); } static void @@ -1501,7 +1501,7 @@ ephy_window_init (EphyWindow *window) window->priv->bmk_menu = ephy_bookmarks_menu_new (window); /* Once window is fully created, add it to the session list*/ - session_add_window (session, window); + session_add_window (session, GTK_WINDOW (window)); } static void diff --git a/src/session.c b/src/session.c index 74c888012..958e804b8 100644 --- a/src/session.c +++ b/src/session.c @@ -26,6 +26,8 @@ #include "ephy-shell.h" #include "ephy-tab.h" #include "ephy-window.h" +#include "ephy-history-window.h" +#include "ephy-bookmarks-editor.h" #include "ephy-string.h" #include "ephy-file-helpers.h" #include "eel-gconf-extensions.h" @@ -44,18 +46,6 @@ #include <libgnomevfs/gnome-vfs-ops.h> #include <libgnomeui/gnome-client.h> -enum -{ - RESTORE_TYPE_PROP -}; - -enum -{ - RESTORE_SESSION, - RESTORE_AS_BOOKMARKS, - DISCARD_SESSION -}; - static void session_class_init (SessionClass *klass); static void session_init (Session *t); static void session_finalize (GObject *object); @@ -63,12 +53,14 @@ static void session_dispose (GObject *object); static GObjectClass *parent_class = NULL; +#define BOOKMARKS_EDITOR_ID "BookmarksEditor" +#define HISTORY_WINDOW_ID "HistoryWindow" + #define EPHY_SESSION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_SESSION, SessionPrivate)) struct SessionPrivate { GList *windows; - gboolean dont_remove_crashed; }; enum @@ -255,25 +247,24 @@ crashed_resume_dialog (Session *session) * * Resume a crashed session when necessary (interactive) * - * Return value: return false if no window has been opened + * Return value: TRUE if at least a window has been opened **/ gboolean session_autoresume (Session *session) { char *saved_session; - gboolean loaded = FALSE; + + if (session->priv->windows != NULL) return FALSE; saved_session = get_session_filename (SESSION_CRASHED); if (g_file_test (saved_session, G_FILE_TEST_EXISTS)) { crashed_resume_dialog (session); - loaded = TRUE; } g_free (saved_session); - /* return false if no window has been opened */ return (session->priv->windows != NULL); } @@ -297,89 +288,14 @@ create_session_directory (void) g_free (dir); } -static gboolean -save_yourself_cb (GnomeClient *client, - gint phase, - GnomeSaveStyle save_style, - gboolean shutdown, - GnomeInteractStyle interact_style, - gboolean fast, - Session *session) -{ - char *argv[] = { "epiphany", "--load-session", NULL }; - char *discard_argv[] = { "rm", "-r", NULL }; - - argv[2] = get_session_filename (SESSION_GNOME); - gnome_client_set_restart_command - (client, 3, argv); - - discard_argv[2] = argv[2]; - gnome_client_set_discard_command (client, 3, - discard_argv); - - session_save (session, argv[2]); - - g_free (argv[2]); - - return TRUE; -} - -static void -session_die_cb (GnomeClient* client, - Session *session) -{ - session_close (session); -} - -static void -gnome_session_init (Session *session) -{ - GnomeClient *client; - - client = gnome_master_client (); - - g_signal_connect (G_OBJECT (client), - "save_yourself", - G_CALLBACK (save_yourself_cb), - session); - - g_signal_connect (G_OBJECT (client), - "die", - G_CALLBACK (session_die_cb), - session); -} - static void -session_init (Session *session) -{ - session->priv = EPHY_SESSION_GET_PRIVATE (session); - - session->priv->windows = NULL; - session->priv->dont_remove_crashed = FALSE; - - create_session_directory (); - - gnome_session_init (session); -} - -/* - * session_close: - * @session: a #Session - * - * Close the session and all the owned windows - **/ -void session_close (Session *session) { - GList *l, *windows; + GList *windows; /* close all windows */ windows = g_list_copy (session->priv->windows); - for (l = windows; l != NULL; l = l->next) - { - EphyWindow *window = EPHY_WINDOW(l->data); - gtk_widget_destroy (GTK_WIDGET(window)); - } + g_list_foreach (windows, (GFunc)gtk_widget_destroy, NULL); g_list_free (windows); } @@ -401,10 +317,7 @@ session_dispose (GObject *object) { Session *session = EPHY_SESSION(object); - if (!session->priv->dont_remove_crashed) - { - session_delete (session, SESSION_CRASHED); - } + session_delete (session, SESSION_CRASHED); } static void @@ -459,23 +372,76 @@ save_tab (EphyWindow *window, xmlAddChild (window_node, embed_node); } -/* - * session_save: - * @session: a #Session - * @filename: path of the xml file where the session is saved. - * - * Save the session on disk. Keep information about window size, - * opened urls ... - **/ -void +static void +save_window_geometry (GtkWindow *window, xmlNodePtr window_node) +{ + int x = 0, y = 0, width = 0, height = 0; + gchar buffer[32]; + + /* get window geometry */ + gtk_window_get_size (window, &width, &height); + gtk_window_get_position (window, &x, &y); + + /* set window properties */ + g_snprintf(buffer, 32, "%d", x); + xmlSetProp (window_node, "x", buffer); + g_snprintf(buffer, 32, "%d", y); + + xmlSetProp (window_node, "y", buffer); + g_snprintf(buffer, 32, "%d", width); + xmlSetProp (window_node, "width", buffer); + g_snprintf(buffer, 32, "%d", height); + xmlSetProp (window_node, "height", buffer); +} + +static void +save_tool_window (GtkWindow *window, + xmlDocPtr doc, + xmlNodePtr root_node, + const char *id) +{ + xmlNodePtr window_node; + + window_node = xmlNewDocNode (doc, NULL, "toolwindow", NULL); + xmlSetProp (window_node, "id", id); + save_window_geometry (window, window_node); + + xmlAddChild (root_node, window_node); +} + +static void +save_ephy_window (EphyWindow *window, + xmlDocPtr doc, + xmlNodePtr root_node) +{ + GList *tabs, *l; + xmlNodePtr window_node; + + tabs = ephy_window_get_tabs (window); + + /* Do not save empty EphyWindow */ + if (tabs == NULL) return; + + window_node = xmlNewDocNode (doc, NULL, "window", NULL); + save_window_geometry (GTK_WINDOW (window), window_node); + + for (l = tabs; l != NULL; l = l->next) + { + EphyTab *tab = EPHY_TAB(l->data); + save_tab (window, tab, doc, window_node); + } + g_list_free (tabs); + + xmlAddChild (root_node, window_node); +} + +static void session_save (Session *session, const char *filename) { - const GList *w; + GList *w; xmlNodePtr root_node; - xmlNodePtr window_node; xmlDocPtr doc; - gchar buffer[32]; char *save_to; save_to = get_session_filename (filename); @@ -486,46 +452,26 @@ session_save (Session *session, root_node = xmlNewDocNode (doc, NULL, "session", NULL); xmlDocSetRootElement (doc, root_node); - w = session_get_windows (session); - /* iterate through all the windows */ - for (; w != NULL; w = w->next) + for (w = session->priv->windows; w != NULL; w = w->next) { - GList *tabs, *l; - int x = 0, y = 0, width = 0, height = 0; - EphyWindow *window = EPHY_WINDOW(w->data); - GtkWidget *wmain; - - tabs = ephy_window_get_tabs (window); - g_return_if_fail (tabs != NULL); - - /* make a new XML node */ - window_node = xmlNewDocNode (doc, NULL, "window", NULL); - - /* get window geometry */ - wmain = GTK_WIDGET (window); - gtk_window_get_size (GTK_WINDOW(wmain), &width, &height); - gtk_window_get_position (GTK_WINDOW(wmain), &x, &y); - - /* set window properties */ - g_snprintf(buffer, 32, "%d", x); - xmlSetProp (window_node, "x", buffer); - g_snprintf(buffer, 32, "%d", y); - - xmlSetProp (window_node, "y", buffer); - g_snprintf(buffer, 32, "%d", width); - xmlSetProp (window_node, "width", buffer); - g_snprintf(buffer, 32, "%d", height); - xmlSetProp (window_node, "height", buffer); - - for (l = tabs; l != NULL; l = l->next) - { - EphyTab *tab = EPHY_TAB(l->data); - save_tab (window, tab, doc, window_node); + GtkWindow *window = w->data; + + if (EPHY_IS_WINDOW (window)) + { + save_ephy_window (EPHY_WINDOW (window), + doc, root_node); + } + else if (EPHY_IS_BOOKMARKS_EDITOR (window)) + { + save_tool_window (window, doc, root_node, + BOOKMARKS_EDITOR_ID); + } + else if (EPHY_IS_HISTORY_WINDOW (window)) + { + save_tool_window (window, doc, root_node, + HISTORY_WINDOW_ID); } - g_list_free (tabs); - - xmlAddChild (root_node, window_node); } /* save it all out to disk */ @@ -573,13 +519,15 @@ session_load (Session *session, { xmlDocPtr doc; xmlNodePtr child; - GtkWidget *wmain; - EphyWindow *window; - char *save_to; + GtkWidget *widget = NULL; + char *path; - save_to = get_session_filename (filename); + path = get_session_filename (filename); - doc = xmlParseFile (save_to); + doc = xmlParseFile (filename); + g_free (path); + + if (doc == NULL) return; child = xmlDocGetRootElement (doc); @@ -588,10 +536,31 @@ session_load (Session *session, while (child != NULL) { - if (strcmp (child->name, "window") == 0) + if (xmlStrEqual (child->name, "window")) + { + widget = GTK_WIDGET (ephy_window_new ()); + parse_embed (child->children, EPHY_WINDOW (widget)); + } + else if (xmlStrEqual (child->name, "toolwindow")) + { + xmlChar *id; + + id = xmlGetProp (child, "id"); + + if (id && xmlStrEqual (BOOKMARKS_EDITOR_ID, id)) + { + widget = ephy_shell_get_bookmarks_editor (ephy_shell); + } + else if (id && xmlStrEqual (HISTORY_WINDOW_ID, id)) + { + widget = ephy_shell_get_history_window (ephy_shell); + } + } + + if (widget) { - gulong x = 0, y = 0, width = 0, height = 0; xmlChar *tmp; + gulong x = 0, y = 0, width = 0, height = 0; tmp = xmlGetProp (child, "x"); ephy_string_to_int (tmp, &x); @@ -605,32 +574,52 @@ session_load (Session *session, tmp = xmlGetProp (child, "height"); ephy_string_to_int (tmp, &height); xmlFree (tmp); - - window = ephy_window_new (); - wmain = GTK_WIDGET (window); - gtk_widget_show (GTK_WIDGET(window)); - - gtk_window_move (GTK_WINDOW(wmain), x, y); - gtk_window_set_default_size (GTK_WINDOW (wmain), + gtk_window_move (GTK_WINDOW (widget), x, y); + gtk_window_set_default_size (GTK_WINDOW (widget), width, height); - - parse_embed (child->children, window); + gtk_widget_show (widget); } child = child->next; } xmlFreeDoc (doc); - - g_free (save_to); } -const GList * +GList * session_get_windows (Session *session) { g_return_val_if_fail (EPHY_IS_SESSION (session), NULL); - return session->priv->windows; + return g_list_copy (session->priv->windows); +} + +static void +net_stop_cb (EphyEmbed *embed, Session *session) +{ + session_save (session, SESSION_CRASHED); +} + +static void +tab_added_cb (GtkWidget *nb, GtkWidget *child, Session *session) +{ + g_signal_connect (child, "net_stop", + G_CALLBACK (net_stop_cb), session); +} + +static void +tab_removed_cb (GtkWidget *nb, GtkWidget *child, Session *session) +{ + session_save (session, SESSION_CRASHED); + + g_signal_handlers_disconnect_by_func + (child, G_CALLBACK (net_stop_cb), session); +} + +static void +tabs_reordered_cb (GtkWidget *nb, Session *session) +{ + session_save (session, SESSION_CRASHED); } /** @@ -643,13 +632,29 @@ session_get_windows (Session *session) **/ void session_add_window (Session *session, - EphyWindow *window) + GtkWindow *window) { session->priv->windows = g_list_append (session->priv->windows, window); - g_signal_emit (G_OBJECT (session), - session_signals[NEW_WINDOW], - 0, window); + if (EPHY_IS_WINDOW (window)) + { + GtkWidget *nb; + + nb = ephy_window_get_notebook (EPHY_WINDOW (window)); + g_signal_connect (nb, "tab_added", + G_CALLBACK (tab_added_cb), session); + g_signal_connect (nb, "tab_removed", + G_CALLBACK (tab_removed_cb), session); + g_signal_connect (nb, "tabs_reordered", + G_CALLBACK (tabs_reordered_cb), session); + + /* FIXME do not break the extensions until we figure out better api */ + g_signal_emit (G_OBJECT (session), + session_signals[NEW_WINDOW], + 0, window); + } + + session_save (session, SESSION_CRASHED); } /** @@ -662,18 +667,84 @@ session_add_window (Session *session, **/ void session_remove_window (Session *session, - EphyWindow *window) + GtkWindow *window) { - g_object_ref (window); - session->priv->windows = g_list_remove (session->priv->windows, window); - g_signal_emit (G_OBJECT (session), - session_signals[CLOSE_WINDOW], - 0, window); + if (EPHY_IS_WINDOW (window)) + { + g_object_ref (window); + + /* FIXME do not break the extensions until we figure out better api */ + g_signal_emit (G_OBJECT (session), + session_signals[CLOSE_WINDOW], + 0, window); - g_object_unref (window); + g_object_unref (window); + } session_save (session, SESSION_CRASHED); } +static gboolean +save_yourself_cb (GnomeClient *client, + gint phase, + GnomeSaveStyle save_style, + gboolean shutdown, + GnomeInteractStyle interact_style, + gboolean fast, + Session *session) +{ + char *argv[] = { "epiphany", "--load-session", NULL }; + char *discard_argv[] = { "rm", "-r", NULL }; + + argv[2] = get_session_filename (SESSION_GNOME); + gnome_client_set_restart_command + (client, 3, argv); + + discard_argv[2] = argv[2]; + gnome_client_set_discard_command (client, 3, + discard_argv); + + session_save (session, argv[2]); + + g_free (argv[2]); + + return TRUE; +} + +static void +session_die_cb (GnomeClient* client, + Session *session) +{ + session_close (session); +} + +static void +gnome_session_init (Session *session) +{ + GnomeClient *client; + + client = gnome_master_client (); + + g_signal_connect (G_OBJECT (client), + "save_yourself", + G_CALLBACK (save_yourself_cb), + session); + g_signal_connect (G_OBJECT (client), + "die", + G_CALLBACK (session_die_cb), + session); +} + +static void +session_init (Session *session) +{ + session->priv = EPHY_SESSION_GET_PRIVATE (session); + + session->priv->windows = NULL; + + create_session_directory (); + + gnome_session_init (session); +} diff --git a/src/session.h b/src/session.h index 0926a0f50..6e7711a16 100644 --- a/src/session.h +++ b/src/session.h @@ -19,10 +19,7 @@ #ifndef SESSION_H #define SESSION_H -#include "ephy-window.h" - -#include <glib-object.h> -#include <glib.h> +#include <gtk/gtkwindow.h> G_BEGIN_DECLS @@ -51,34 +48,27 @@ struct SessionClass GObjectClass parent_class; void ( *new_window) (Session *session, - EphyWindow *window); + GtkWindow *window); void ( *close_window) (Session *session, - EphyWindow *window); + GtkWindow *window); }; GType session_get_type (void); Session *session_new (void); -void session_close (Session *session); - void session_load (Session *session, const char *filename); -void session_save (Session *session, - const char *filename); - gboolean session_autoresume (Session *session); -const GList *session_get_windows (Session *session); +GList *session_get_windows (Session *session); void session_add_window (Session *session, - EphyWindow *window); + GtkWindow *window); void session_remove_window (Session *session, - EphyWindow *window); - -EphyWindow *session_get_active_window (Session *session); + GtkWindow *window); G_END_DECLS diff --git a/src/window-commands.c b/src/window-commands.c index b360fb40d..0aae5ad76 100644 --- a/src/window-commands.c +++ b/src/window-commands.c @@ -32,6 +32,7 @@ #include "ephy-prefs.h" #include "pdm-dialog.h" #include "ephy-bookmarks-editor.h" +#include "ephy-history-window.h" #include "ephy-new-bookmark.h" #include "ephy-file-chooser.h" #include "ephy-file-helpers.h" @@ -275,7 +276,12 @@ void window_cmd_go_bookmarks (GtkAction *action, EphyWindow *window) { - ephy_shell_show_bookmarks_editor (ephy_shell, GTK_WIDGET (window)); + GtkWidget *bwindow; + + bwindow = ephy_shell_get_bookmarks_editor (ephy_shell); + ephy_bookmarks_editor_set_parent (EPHY_BOOKMARKS_EDITOR (bwindow), + GTK_WIDGET (window)); + gtk_window_present (GTK_WINDOW (bwindow)); } void @@ -770,7 +776,12 @@ void window_cmd_go_history (GtkAction *action, EphyWindow *window) { - ephy_shell_show_history_window (ephy_shell, GTK_WIDGET (window)); + GtkWidget *hwindow; + + hwindow = ephy_shell_get_history_window (ephy_shell); + ephy_history_window_set_parent (EPHY_HISTORY_WINDOW (hwindow), + GTK_WIDGET (window)); + gtk_window_present (GTK_WINDOW (hwindow)); } void |