From 83a7a11ba109b8aee5cdc047dec8b93967ccfc0e Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Sun, 31 Aug 2008 15:20:43 +0000 Subject: EggSMClient copied from libegg 2008-08-31 Carlos Garcia Campos * configure.ac: * cut-n-paste/Makefile.am: * cut-n-paste/smclient/Makefile.am: * cut-n-paste/smclient/eggdesktopfile.[ch]: * cut-n-paste/smclient/eggsmclient-private.h: * cut-n-paste/smclient/eggsmclient-xsmp.c: * cut-n-paste/smclient/eggsmclient.[ch]: EggSMClient copied from libegg * libdocument/ev-file-helpers.c: (ev_dot_dir): * shell/Makefile.am: * shell/ev-application.[ch]: (ev_application_load_session), (smclient_save_state_cb), (smclient_quit_cb), (ev_application_init_session), (ev_application_shutdown), (ev_application_init): * shell/main.c: (main): Use EggSMClient instead of gnome-client and remove libgnome and libgnomeui dependencies. svn path=/trunk/; revision=3130 --- (limited to 'shell') diff --git a/shell/Makefile.am b/shell/Makefile.am index d2c14a9..16eeaf1 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -6,6 +6,7 @@ INCLUDES= \ -I$(top_srcdir)/cut-n-paste/totem-screensaver/ \ -I$(top_srcdir)/cut-n-paste/gedit-message-area/ \ -I$(top_srcdir)/cut-n-paste/evmountoperation/ \ + -I$(top_srcdir)/cut-n-paste/smclient/ \ -I$(top_srcdir)/libdocument \ -I$(top_srcdir)/properties \ -DGNOMELOCALEDIR=\"$(datadir)/locale\" \ @@ -102,6 +103,7 @@ evince_LDADD= \ $(top_builddir)/cut-n-paste/totem-screensaver/libtotemscrsaver.la \ $(top_builddir)/cut-n-paste/gedit-message-area/libgeditmsgarea.la \ $(top_builddir)/cut-n-paste/evmountoperation/libevmountoperation.la \ + $(top_builddir)/cut-n-paste/smclient/libsmclient.la \ $(top_builddir)/properties/libevproperties.la \ $(top_builddir)/libdocument/libevbackend.la \ $(SHELL_LIBS) diff --git a/shell/ev-application.c b/shell/ev-application.c index 9dee998..eda6d0c 100644 --- a/shell/ev-application.c +++ b/shell/ev-application.c @@ -28,11 +28,9 @@ #include #include -#if WITH_GNOME -#include -#endif - #include "totem-scrsaver.h" +#include "eggsmclient.h" +#include "eggdesktopfile.h" #include "ev-application.h" #include "ev-document-factory.h" @@ -53,12 +51,16 @@ static void ev_application_add_icon_path_for_screen (GdkScreen *screen); struct _EvApplication { GObject base_instance; + gchar *accel_map_file; + gchar *toolbars_file; EggToolbarsModel *toolbars_model; TotemScrsaver *scr_saver; + EggSMClient *smclient; + gchar *last_chooser_uri; #ifdef ENABLE_DBUS @@ -151,55 +153,91 @@ ev_application_get_instance (void) return instance; } -#if WITH_GNOME -static void -removed_from_session (GnomeClient *client, EvApplication *application) +/* Session */ +gboolean +ev_application_load_session (EvApplication *application) { - ev_application_shutdown (application); + GKeyFile *state_file; + gchar **uri_list; + + if (!egg_sm_client_is_resumed (application->smclient)) + return FALSE; + + state_file = egg_sm_client_get_state_file (application->smclient); + if (!state_file) + return FALSE; + + uri_list = g_key_file_get_string_list (state_file, + "Evince", + "documents", + NULL, NULL); + if (uri_list) { + gint i; + + for (i = 0; uri_list[i]; i++) { + if (g_ascii_strcasecmp (uri_list[i], "empty-window") == 0) + ev_application_open_window (application, NULL, GDK_CURRENT_TIME, NULL); + else + ev_application_open_uri (application, uri_list[i], NULL, GDK_CURRENT_TIME, NULL); + } + g_strfreev (uri_list); + } + g_key_file_free (state_file); + + return TRUE; } -static gint -save_session (GnomeClient *client, gint phase, GnomeSaveStyle save_style, gint shutdown, - GnomeInteractStyle interact_style, gint fast, EvApplication *application) +static void +smclient_save_state_cb (EggSMClient *client, + GKeyFile *state_file, + EvApplication *application) { GList *windows, *l; - char **restart_argv; - int argc = 0, k; + gint i; + const gchar **uri_list; + const gchar *empty = "empty-window"; windows = ev_application_get_windows (application); - restart_argv = g_new (char *, g_list_length (windows) + 1); - restart_argv[argc++] = g_strdup ("evince"); + if (!windows) + return; - for (l = windows; l != NULL; l = l->next) { + uri_list = g_new (const gchar *, g_list_length (windows)); + for (l = windows, i = 0; l != NULL; l = g_list_next (l), i++) { 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]); + if (ev_window_is_empty (window)) + uri_list[i] = empty; + else + uri_list[i] = ev_window_get_uri (window); } - - g_list_free (windows); - g_free (restart_argv); - - return TRUE; + g_key_file_set_string_list (state_file, + "Evince", + "documents", + (const char **)uri_list, + i); + g_free (uri_list); } static void -init_session (EvApplication *application) +smclient_quit_cb (EggSMClient *client, + EvApplication *application) { - GnomeClient *client; - - client = gnome_master_client (); + ev_application_shutdown (application); +} - g_signal_connect (client, "save_yourself", - G_CALLBACK (save_session), application); - g_signal_connect (client, "die", - G_CALLBACK (removed_from_session), application); +static void +ev_application_init_session (EvApplication *application) +{ + egg_set_desktop_file (GNOMEDATADIR "/applications/evince.desktop"); + + application->smclient = egg_sm_client_get (); + g_signal_connect (application->smclient, "save_state", + G_CALLBACK (smclient_save_state_cb), + application); + g_signal_connect (application->smclient, "quit", + G_CALLBACK (smclient_quit_cb), + application); } -#endif /** * ev_display_open_if_needed: @@ -635,6 +673,12 @@ ev_application_open_uri_list (EvApplication *application, void ev_application_shutdown (EvApplication *application) { + if (application->accel_map_file) { + gtk_accel_map_save (application->accel_map_file); + g_free (application->accel_map_file); + application->accel_map_file = NULL; + } + if (application->toolbars_model) { g_object_unref (application->toolbars_model); g_free (application->toolbars_file); @@ -684,11 +728,20 @@ static void ev_application_init (EvApplication *ev_application) { gint i; + const gchar *home_dir; + + ev_application_init_session (ev_application); + + home_dir = g_get_home_dir (); + if (home_dir) { + ev_application->accel_map_file = g_build_filename (home_dir, + ".gnome2", + "accels" + "evince", + NULL); + gtk_accel_map_load (ev_application->accel_map_file); + } -#if WITH_GNOME - init_session (ev_application); -#endif - ev_application->toolbars_model = egg_toolbars_model_new (); ev_application->toolbars_file = g_build_filename diff --git a/shell/ev-application.h b/shell/ev-application.h index 8454665..108fd82 100644 --- a/shell/ev-application.h +++ b/shell/ev-application.h @@ -53,7 +53,7 @@ EvApplication *ev_application_get_instance (void); gboolean ev_application_register_service (EvApplication *application); void ev_application_shutdown (EvApplication *application); - +gboolean ev_application_load_session (EvApplication *application); gboolean ev_application_open_window (EvApplication *application, GHashTable *args, guint32 timestamp, diff --git a/shell/main.c b/shell/main.c index 3aeb1a1..ff8eafa 100644 --- a/shell/main.c +++ b/shell/main.c @@ -26,12 +26,6 @@ #include #include -#if WITH_GNOME -#include -#include -#include -#endif - #ifdef ENABLE_DBUS #include #endif @@ -42,6 +36,7 @@ #include "ev-file-helpers.h" #include "ev-metadata-manager.h" #include "ev-stock-icons.h" +#include "eggsmclient.h" static gchar *ev_page_label; static gchar *ev_find_string; @@ -318,64 +313,55 @@ load_files_remote (const char **files, int main (int argc, char *argv[]) { - gboolean enable_metadata = FALSE; GOptionContext *context; GHashTable *args; -#if WITH_GNOME - GnomeProgram *program; -#else - char *accel_filename; + gboolean enable_metadata = FALSE; GError *error = NULL; -#endif + + /* Init glib threads asap */ + if (!g_thread_supported ()) + g_thread_init (NULL); context = g_option_context_new (_("GNOME Document Viewer")); #ifdef ENABLE_NLS /* Initialize the i18n stuff */ - bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR); - bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); - textdomain(GETTEXT_PACKAGE); + bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); g_option_context_add_main_entries (context, goption_options, GETTEXT_PACKAGE); g_option_context_set_translation_domain(context, GETTEXT_PACKAGE); #else g_option_context_add_main_entries (context, goption_options, NULL); -#endif - -#if WITH_GNOME - program = gnome_program_init (PACKAGE, VERSION, - LIBGNOMEUI_MODULE, argc, argv, - GNOME_PARAM_GOPTION_CONTEXT, context, - GNOME_PARAM_HUMAN_READABLE_NAME, _("Evince"), - GNOME_PARAM_APP_DATADIR, GNOMEDATADIR, - NULL); -#else +#endif /* ENABLE_NLS */ + + g_option_context_add_group (context, egg_sm_client_get_option_group ()); g_option_context_add_group (context, gtk_get_option_group (TRUE)); + + gtk_init (&argc, &argv); + if (!g_option_context_parse (context, &argc, &argv, &error)) { g_warning ("Cannot parse arguments: %s", error->message); g_error_free (error); + g_option_context_free (context); + return 1; } g_option_context_free (context); - accel_filename = g_build_filename (ev_dot_dir (), "accels", NULL); - gtk_accel_map_load (accel_filename); -#endif - args = arguments_parse (); #ifdef ENABLE_DBUS if (!ev_application_register_service (EV_APP)) { if (load_files_remote (file_arguments, args)) { g_hash_table_destroy (args); -#if WITH_GNOME - g_object_unref (program); -#endif + return 0; } } else { enable_metadata = TRUE; } -#endif +#endif /* ENABLE_DBUS */ ev_debug_init (); ev_backends_manager_init (); @@ -384,24 +370,16 @@ main (int argc, char *argv[]) ev_metadata_manager_init (); } - g_set_application_name (_("Evince Document Viewer")); - ev_file_helpers_init (); ev_stock_icons_init (); gtk_window_set_default_icon_name ("evince"); - load_files (file_arguments, args); + if (!ev_application_load_session (EV_APP)) + load_files (file_arguments, args); g_hash_table_destroy (args); gtk_main (); -#if WITH_GNOME - gnome_accelerators_sync (); -#else - gtk_accel_map_save (accel_filename); - g_free (accel_filename); -#endif - ev_file_helpers_shutdown (); if (enable_metadata) { @@ -412,9 +390,5 @@ main (int argc, char *argv[]) ev_debug_shutdown (); -#if WITH_GNOME - g_object_unref (program); -#endif - return 0; } -- cgit v0.9.1