]> www.fi.muni.cz Git - evince.git/commitdiff
Add a function to retrieve window list and share it where necessary.
authorMarco Pesenti Gritti <mpg@redhat.com>
Fri, 23 Sep 2005 09:37:37 +0000 (09:37 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Fri, 23 Sep 2005 09:37:37 +0000 (09:37 +0000)
2005-09-23  Marco Pesenti Gritti  <mpg@redhat.com>

        * 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
shell/ev-application.c
shell/ev-application.h
shell/ev-window.c

index ecddb7258ec52e12724b11ba5238523905f12f38..9028b9a61a5588d1cba5d61e25b702560c51d8d0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2005-09-23  Marco Pesenti Gritti  <mpg@redhat.com>
+
+       * 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  <nshmyrev@yandex.ru>
 
        * shell/ev-password.c: (ev_password_item_created_callback),
index 209d70637d7b6c71dfccd524ddff386fbef5b50e..eed7be8b7cfd5596af9f9452f0a8150f71effc96 100644 (file)
@@ -36,6 +36,7 @@
 #include <gtk/gtkstock.h>
 #include <gtk/gtkwidget.h>
 #include <gtk/gtkmain.h>
+#include <libgnomeui/gnome-client.h>
 #include <string.h>
 
 #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;
index 87e2bf10a747521a0ef1c0621ed1da32054f55f8..8dcd2f7cc5869baddb36ef86a2748148a5f30444 100644 (file)
@@ -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);
index 47ee1e89aca27f4132e7173e4cb3eb90f6efee60..19b78f33f203de36e7b6dd5a412b31a7c481f989 100644 (file)
@@ -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);