From d8264ef4e6ab48b5d203093bb1c66ae2ae1ad9e0 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 23 Sep 2005 09:37:37 +0000 Subject: [PATCH] Add a function to retrieve window list and share it where necessary. 2005-09-23 Marco Pesenti Gritti * shell/ev-application.c: (removed_from_session), (save_session), (init_session), (ev_application_get_empty_window), (ev_application_init), (ev_application_get_windows): * shell/ev-application.h: * shell/ev-window.c: (ev_window_finalize): Add a function to retrieve window list and share it where necessary. Implement session handling, works pretty well thanks to the metadata system. --- ChangeLog | 13 +++++++ shell/ev-application.c | 82 ++++++++++++++++++++++++++++++++++++++---- shell/ev-application.h | 2 +- shell/ev-window.c | 18 +++------- 4 files changed, 94 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index ecddb725..9028b9a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2005-09-23 Marco Pesenti Gritti + + * shell/ev-application.c: (removed_from_session), (save_session), + (init_session), (ev_application_get_empty_window), + (ev_application_init), (ev_application_get_windows): + * shell/ev-application.h: + * shell/ev-window.c: (ev_window_finalize): + + Add a function to retrieve window list and share it where + necessary. + Implement session handling, works pretty well thanks to the + metadata system. + 2005-09-22 Nickolay V. Shmyrev * shell/ev-password.c: (ev_password_item_created_callback), diff --git a/shell/ev-application.c b/shell/ev-application.c index 209d7063..eed7be8b 100644 --- a/shell/ev-application.c +++ b/shell/ev-application.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #ifdef ENABLE_DBUS @@ -111,6 +112,54 @@ ev_application_get_instance (void) return instance; } +static void +removed_from_session (GnomeClient *client, EvApplication *application) +{ + ev_application_shutdown (application); +} + +static gint +save_session (GnomeClient *client, gint phase, GnomeSaveStyle save_style, gint shutdown, + GnomeInteractStyle interact_style, gint fast, EvApplication *application) +{ + GList *windows, *l; + char **restart_argv; + int argc = 0, k; + + windows = ev_application_get_windows (application); + restart_argv = g_new (char *, g_list_length (windows) + 1); + restart_argv[argc++] = g_strdup ("evince"); + + for (l = windows; l != NULL; l = l->next) { + EvWindow *window = EV_WINDOW (l->data); + restart_argv[argc++] = g_strdup (ev_window_get_uri (window)); + } + + gnome_client_set_restart_command (client, argc, restart_argv); + + for (k = 0; k < argc; k++) { + g_free (restart_argv[k]); + } + + g_list_free (windows); + g_free (restart_argv); + + return TRUE; +} + +static void +init_session (EvApplication *application) +{ + GnomeClient *client; + + client = gnome_master_client (); + + g_signal_connect (client, "save_yourself", + G_CALLBACK (save_session), application); + g_signal_connect (client, "die", + G_CALLBACK (removed_from_session), application); +} + gboolean ev_application_open_window (EvApplication *application, guint32 timestamp, @@ -134,17 +183,15 @@ static EvWindow * ev_application_get_empty_window (EvApplication *application) { EvWindow *empty_window = NULL; - GList *windows = gtk_window_list_toplevels (); + GList *windows = ev_application_get_windows (application); GList *l; for (l = windows; l != NULL; l = l->next) { - if (EV_IS_WINDOW (l->data)) { - EvWindow *window = EV_WINDOW (l->data); + EvWindow *window = EV_WINDOW (l->data); - if (ev_window_is_empty (window)) { - empty_window = window; - break; - } + if (ev_window_is_empty (window)) { + empty_window = window; + break; } } @@ -269,6 +316,8 @@ ev_application_class_init (EvApplicationClass *ev_application_class) static void ev_application_init (EvApplication *ev_application) { + init_session (ev_application); + ev_application->toolbars_model = egg_toolbars_model_new (); ev_application->toolbars_file = g_build_filename @@ -292,6 +341,25 @@ ev_application_init (EvApplication *ev_application) "Evince", NULL); } +GList * +ev_application_get_windows (EvApplication *application) +{ + GList *l, *toplevels; + GList *windows = NULL; + + toplevels = gtk_window_list_toplevels (); + + for (l = toplevels; l != NULL; l = l->next) { + if (EV_IS_WINDOW (l->data)) { + windows = g_list_append (windows, l->data); + } + } + + g_list_free (toplevels); + + return windows; +} + EggToolbarsModel *ev_application_get_toolbars_model (EvApplication *application) { return application->toolbars_model; diff --git a/shell/ev-application.h b/shell/ev-application.h index 87e2bf10..8dcd2f7c 100644 --- a/shell/ev-application.h +++ b/shell/ev-application.h @@ -76,7 +76,7 @@ gboolean ev_application_open_uri (EvApplication *applicati void ev_application_open_uri_list (EvApplication *application, GSList *uri_list, guint32 timestamp); - +GList *ev_application_get_windows (EvApplication *application); EggToolbarsModel *ev_application_get_toolbars_model (EvApplication *application); void ev_application_save_toolbars_model (EvApplication *application); diff --git a/shell/ev-window.c b/shell/ev-window.c index 47ee1e89..19b78f33 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -2691,21 +2691,13 @@ zoom_control_changed_cb (EphyZoomAction *action, static void ev_window_finalize (GObject *object) { - gboolean empty = TRUE; - GList *list, *windows; + GList *windows = ev_application_get_windows (EV_APP); - - windows = gtk_window_list_toplevels (); - - for (list = windows; list; list = list->next) { - if (EV_IS_WINDOW (list->data)) { - empty = FALSE; - break; - } - } - - if (empty) + if (windows == NULL) { ev_application_shutdown (EV_APP); + } else { + g_list_free (windows); + } g_list_free (windows); G_OBJECT_CLASS (ev_window_parent_class)->finalize (object); -- 2.43.5