X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-application.c;h=91555b9708d8c8392006acd62cbc68658300b115;hb=5f03f96e78d00dd631bbf21225721a0f1dc2d353;hp=49ffe0c91c17b57cace57d805b786a594911c45f;hpb=6936524259e0f4209a2ef61bde8570062c074dbf;p=evince.git diff --git a/shell/ev-application.c b/shell/ev-application.c index 49ffe0c9..91555b97 100644 --- a/shell/ev-application.c +++ b/shell/ev-application.c @@ -91,8 +91,6 @@ G_DEFINE_TYPE (EvApplication, ev_application, G_TYPE_OBJECT); #define EVINCE_DAEMON_INTERFACE "org.gnome.evince.Daemon" #endif -static const gchar *userdir = NULL; - static void _ev_application_open_uri_at_dest (EvApplication *application, const gchar *uri, GdkScreen *screen, @@ -751,49 +749,66 @@ method_call_cb (GDBusConnection *connection, const gchar *search_string = NULL; GdkScreen *screen = NULL; - if (g_strcmp0 (method_name, "Reload") != 0) - return; + if (g_strcmp0 (method_name, "Reload") == 0) { + g_variant_get (parameters, "(a{sv}u)", &iter, ×tamp); + + while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) { + if (strcmp (key, "display") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) { + display = ev_display_open_if_needed (g_variant_get_string (value, NULL)); + } else if (strcmp (key, "screen") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) { + screen_number = g_variant_get_int32 (value); + } else if (strcmp (key, "mode") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) { + mode = g_variant_get_uint32 (value); + } else if (strcmp (key, "page-label") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) { + dest = ev_link_dest_new_page_label (g_variant_get_string (value, NULL)); + } else if (strcmp (key, "find-string") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) { + search_string = g_variant_get_string (value, NULL); + } + } + g_variant_iter_free (iter); - g_variant_get (parameters, "(a{sv}u)", &iter, ×tamp); - - while (g_variant_iter_loop (iter, "{&sv}", &key, &value)) { - if (strcmp (key, "display") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) { - display = ev_display_open_if_needed (g_variant_get_string (value, NULL)); - } else if (strcmp (key, "screen") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) { - screen_number = g_variant_get_int32 (value); - } else if (strcmp (key, "mode") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_UINT32) { - mode = g_variant_get_uint32 (value); - } else if (strcmp (key, "page-label") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) { - dest = ev_link_dest_new_page_label (g_variant_get_string (value, NULL)); - } else if (strcmp (key, "find-string") == 0 && g_variant_classify (value) == G_VARIANT_CLASS_STRING) { - search_string = g_variant_get_string (value, NULL); - } - } - g_variant_iter_free (iter); - - if (display != NULL && - screen_number >= 0 && - screen_number < gdk_display_get_n_screens (display)) - screen = gdk_display_get_screen (display, screen_number); - else - screen = gdk_screen_get_default (); - - windows = ev_application_get_windows (application); - for (l = windows; l != NULL; l = g_list_next (l)) { - EvWindow *ev_window = EV_WINDOW (l->data); - - ev_application_open_uri_in_window (application, application->uri, - ev_window, - screen, dest, mode, - search_string, - timestamp); - } - g_list_free (windows); + if (display != NULL && + screen_number >= 0 && + screen_number < gdk_display_get_n_screens (display)) + screen = gdk_display_get_screen (display, screen_number); + else + screen = gdk_screen_get_default (); + + windows = ev_application_get_windows (application); + for (l = windows; l != NULL; l = g_list_next (l)) { + EvWindow *ev_window = EV_WINDOW (l->data); + + ev_application_open_uri_in_window (application, application->uri, + ev_window, + screen, dest, mode, + search_string, + timestamp); + } + g_list_free (windows); - if (dest) - g_object_unref (dest); + if (dest) + g_object_unref (dest); - g_dbus_method_invocation_return_value (invocation, g_variant_new ("()")); + g_dbus_method_invocation_return_value (invocation, g_variant_new ("()")); + } else if (g_strcmp0 (method_name, "GetWindowList") == 0) { + GList *windows = ev_application_get_windows (application); + GVariantBuilder builder; + GList *l; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("(ao)")); + g_variant_builder_open (&builder, G_VARIANT_TYPE ("ao")); + + for (l = windows; l; l = g_list_next (l)) { + EvWindow *window = (EvWindow *)l->data; + + g_variant_builder_add (&builder, "o", ev_window_get_dbus_object_path (window)); + } + + g_variant_builder_close (&builder); + g_list_free (windows); + + g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (&builder)); + } } static const char introspection_xml[] = @@ -803,6 +818,9 @@ static const char introspection_xml[] = "" "" "" + "" + "" + "" "" ""; @@ -837,15 +855,7 @@ ev_application_accel_map_save (EvApplication *application) gchar *tmp_filename; gint fd; - if (userdir) { - accel_map_file = g_build_filename (userdir, "accels", - "evince", NULL); - } else { - accel_map_file = g_build_filename (g_get_home_dir (), - ".gnome2", "accels", - "evince", NULL); - } - + accel_map_file = g_build_filename (application->dot_dir, "accels", NULL); tmp_filename = g_strdup_printf ("%s.XXXXXX", accel_map_file); fd = g_mkstemp (tmp_filename); @@ -858,6 +868,7 @@ ev_application_accel_map_save (EvApplication *application) gtk_accel_map_save_fd (fd); close (fd); + g_mkdir_with_parents (application->dot_dir, 0700); if (g_rename (tmp_filename, accel_map_file) == -1) { /* FIXME: win32? */ g_unlink (tmp_filename); @@ -872,19 +883,107 @@ ev_application_accel_map_load (EvApplication *application) { gchar *accel_map_file; - if (userdir) { - accel_map_file = g_build_filename (userdir, "accels", - "evince", NULL); - } else { - accel_map_file = g_build_filename (g_get_home_dir (), - ".gnome2", "accels", - "evince", NULL); - } - + accel_map_file = g_build_filename (application->dot_dir, "accels", NULL); gtk_accel_map_load (accel_map_file); g_free (accel_map_file); } +static void +ev_application_migrate_config_dir (EvApplication *application) +{ + const gchar *userdir; + gchar *old_dot_dir; + gchar *old_accels; + GError *error; + gint i; + gboolean dir_created = FALSE; + static const gchar *config_files[] = { + "evince_toolbar.xml", + "print-settings", + NULL + }; + + userdir = g_getenv ("GNOME22_USER_DIR"); + if (userdir) { + old_dot_dir = g_build_filename (userdir, "evince", NULL); + old_accels = g_build_filename (userdir, "accels", "evince", NULL); + } else { + old_dot_dir = g_build_filename (g_get_home_dir (), + ".gnome2", + "evince", + NULL); + old_accels = g_build_filename (g_get_home_dir (), + ".gnome2", "accels", + "evince", NULL); + } + + if (g_file_test (old_dot_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { + for (i = 0; config_files[i]; i++) { + gchar *old_filename; + gchar *new_filename; + GFile *old_file; + GFile *new_file; + + old_filename = g_build_filename (old_dot_dir, config_files[i], NULL); + if (!g_file_test (old_filename, G_FILE_TEST_EXISTS)) { + g_free (old_filename); + continue; + } + + if (!dir_created) { + g_mkdir_with_parents (application->dot_dir, 0700); + dir_created = TRUE; + } + + new_filename = g_build_filename (application->dot_dir, config_files[i], NULL); + old_file = g_file_new_for_path (old_filename); + new_file = g_file_new_for_path (new_filename); + + error = NULL; + g_file_move (old_file, new_file, 0, NULL, NULL, NULL, &error); + if (error) { + g_warning ("Error migrating config file %s: %s\n", + old_filename, error->message); + g_error_free (error); + } + + g_free (old_filename); + g_free (new_filename); + g_object_unref (old_file); + g_object_unref (new_file); + } + } + + g_free (old_dot_dir); + + if (g_file_test (old_accels, G_FILE_TEST_EXISTS)) { + gchar *new_accels; + GFile *old_accels_file; + GFile *new_accels_file; + + if (!dir_created) + g_mkdir_with_parents (application->dot_dir, 0700); + + new_accels = g_build_filename (application->dot_dir, "accels", NULL); + old_accels_file = g_file_new_for_path (old_accels); + new_accels_file = g_file_new_for_path (new_accels); + + error = NULL; + g_file_move (old_accels_file, new_accels_file, 0, NULL, NULL, NULL, &error); + if (error) { + g_warning ("Error migrating accelerator specifications file %s: %s\n", + old_accels, error->message); + g_error_free (error); + } + + g_free (new_accels); + g_object_unref (old_accels_file); + g_object_unref (new_accels_file); + } + + g_free (old_accels); +} + void ev_application_shutdown (EvApplication *application) { @@ -947,14 +1046,10 @@ ev_application_init (EvApplication *ev_application) { GError *error = NULL; - userdir = g_getenv ("GNOME22_USER_DIR"); - if (userdir) - ev_application->dot_dir = g_build_filename (userdir, "evince", NULL); - else - ev_application->dot_dir = g_build_filename (g_get_home_dir (), - ".gnome2", - "evince", - NULL); + ev_application->dot_dir = g_build_filename (g_get_user_config_dir (), + "evince", NULL); + if (!g_file_test (ev_application->dot_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) + ev_application_migrate_config_dir (ev_application); #ifdef G_OS_WIN32 { @@ -965,7 +1060,7 @@ ev_application_init (EvApplication *ev_application) g_free (dir); } #else - ev_application->data_dir = g_strdup (DATADIR); + ev_application->data_dir = g_strdup (EVINCEDATADIR); #endif ev_application_init_session (ev_application); @@ -1016,10 +1111,35 @@ ev_application_get_dbus_connection (EvApplication *application) gboolean ev_application_has_window (EvApplication *application) { - GList *windows = ev_application_get_windows (application); - gboolean retval = windows != NULL; + GList *l, *toplevels; + gboolean retval = FALSE; - g_list_free (windows); + toplevels = gtk_window_list_toplevels (); + + for (l = toplevels; l != NULL && !retval; l = l->next) { + if (EV_IS_WINDOW (l->data)) + retval = TRUE; + } + + g_list_free (toplevels); + + return retval; +} + +guint +ev_application_get_n_windows (EvApplication *application) +{ + GList *l, *toplevels; + guint retval = 0; + + toplevels = gtk_window_list_toplevels (); + + for (l = toplevels; l != NULL; l = l->next) { + if (EV_IS_WINDOW (l->data)) + retval++; + } + + g_list_free (toplevels); return retval; }