From 0dc76c03d545792ae0c90487edff633a94bf87f4 Mon Sep 17 00:00:00 2001 From: infirit Date: Mon, 28 Jul 2014 15:15:47 +0200 Subject: Add "Edit Image" toolbar button Add a conditionally-enabled "Edit Image" toolbar button. The toolbar is only enabled if a specific image editor is specified in GSettings. Eog bug https://bugzilla.gnome.org/show_bug.cgi?id=609958 Based on eog commit b5e6b7d31181ab87f788921f751a6550bddb5bcf From Ryan Lortie --- configure.ac | 1 + data/org.mate.eom.gschema.xml.in.in | 5 ++ src/eom-config-keys.h | 1 + src/eom-window.c | 121 ++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) diff --git a/configure.ac b/configure.ac index ad6932b..dbfb953 100644 --- a/configure.ac +++ b/configure.ac @@ -120,6 +120,7 @@ EOM_MODULES="gtk+-$GTK_API_VERSION >= $GTK_REQUIRED \ glib-2.0 >= $GLIB_REQUIRED \ $GMODULE_ADD \ gio-2.0 >= $GLIB_REQUIRED \ + gio-unix-2.0 >= $GLIB_REQUIRED \ gthread-2.0 >= $GLIB_REQUIRED \ mate-desktop-2.0 >= $MATE_DESKTOP_REQUIRED \ gdk-pixbuf-2.0 >= $GDKPIXBUF_REQUIRED \ diff --git a/data/org.mate.eom.gschema.xml.in.in b/data/org.mate.eom.gschema.xml.in.in index 7e7f0b4..fbf8e0b 100644 --- a/data/org.mate.eom.gschema.xml.in.in +++ b/data/org.mate.eom.gschema.xml.in.in @@ -117,6 +117,11 @@ <_summary>Whether the metadata list in the properties dialog should have its own page. <_description>If activated, the detailed metadata list in the properties dialog will be moved to its own page in the dialog. This should make the dialog more usable on smaller screens, e.g. as used by netbooks. If disabled, the widget will be embedded on the "Metadata" page. + + '' + <_summary>External program to use for editing images + <_description>The desktop file name (including the ".desktop") of the application to use for editing images (when the "Edit Image" toolbar button is clicked). Set to the empty string to disable this feature. + true <_summary>Whether the file chooser should show the user's pictures folder if no images are loaded. diff --git a/src/eom-config-keys.h b/src/eom-config-keys.h index f91295a..cfc2ede 100644 --- a/src/eom-config-keys.h +++ b/src/eom-config-keys.h @@ -67,6 +67,7 @@ #define EOM_CONF_UI_DISABLE_TRASH_CONFIRMATION "disable-trash-confirmation" #define EOM_CONF_UI_FILECHOOSER_XDG_FALLBACK "filechooser-xdg-fallback" #define EOM_CONF_UI_PROPSDIALOG_NETBOOK_MODE "propsdialog-netbook-mode" +#define EOM_CONF_UI_EXTERNAL_EDITOR "external-editor" #define EOM_CONF_PLUGINS_ACTIVE_PLUGINS "active-plugins" diff --git a/src/eom-window.c b/src/eom-window.c index 7daa08f..3efc91a 100644 --- a/src/eom-window.c +++ b/src/eom-window.c @@ -65,6 +65,7 @@ #include #include #include +#include #include #if HAVE_LCMS @@ -213,6 +214,7 @@ static void eom_window_list_store_image_removed (GtkTreeModel *tree_model, static void eom_window_set_wallpaper (EomWindow *window, const gchar *filename, const gchar *visible_filename); static gboolean eom_window_save_images (EomWindow *window, GList *images); static void eom_window_finish_saving (EomWindow *window); +static GAppInfo *get_appinfo_for_editor (EomWindow *window); static GQuark eom_window_error_quark (void) @@ -926,6 +928,8 @@ open_with_launch_application_cb (GtkAction *action, gpointer data) { static void eom_window_update_openwith_menu (EomWindow *window, EomImage *image) { + gboolean edit_button_active; + GAppInfo *editor_app; GFile *file; GFileInfo *file_info; GList *iter; @@ -941,6 +945,9 @@ eom_window_update_openwith_menu (EomWindow *window, EomImage *image) priv = window->priv; + edit_button_active = FALSE; + editor_app = get_appinfo_for_editor (window); + file = eom_image_get_file (image); file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, @@ -983,6 +990,10 @@ eom_window_update_openwith_menu (EomWindow *window, EomImage *image) GAppInfo *app = iter->data; gchar name[64]; + if (g_app_info_equal (editor_app, app)) { + edit_button_active = TRUE; + } + /* Do not include eom itself */ if (g_ascii_strcasecmp (g_app_info_get_executable (app), g_get_prgname ()) == 0) { @@ -1070,6 +1081,12 @@ eom_window_update_openwith_menu (EomWindow *window, EomImage *image) } g_list_free (apps); + + action = gtk_action_group_get_action (window->priv->actions_image, + "OpenEditor"); + if (action != NULL) { + gtk_action_set_sensitive (action, edit_button_active); + } } static void @@ -4129,6 +4146,108 @@ eom_window_finish_saving (EomWindow *window) } while (priv->save_job != NULL); } +static GAppInfo * +get_appinfo_for_editor (EomWindow *window) +{ + /* We want this function to always return the same thing, not + * just for performance reasons, but because if someone edits + * GConf while eom is running, the application could get into an + * inconsistent state. If the editor exists once, it gets added + * to the "available" list of the EggToolbarsModel (for which + * there is no API to remove it). If later the editor no longer + * existed when constructing a new window, we'd be unable to + * construct a GtkAction for the editor for that window, causing + * assertion failures when viewing the "Edit Toolbars" dialog + * (item is available, but can't find the GtkAction for it). + * + * By ensuring we keep the GAppInfo around, we avoid the + * possibility of that situation occuring. + */ + static GDesktopAppInfo *app_info = NULL; + static gboolean initialised; + + if (!initialised) { + gchar *editor; + + editor = g_settings_get_string (window->priv->ui_settings, + EOM_CONF_UI_EXTERNAL_EDITOR); + + if (editor != NULL) { + app_info = g_desktop_app_info_new (editor); + } + + initialised = TRUE; + g_free (editor); + } + + return (GAppInfo *) app_info; +} + +static void +eom_window_open_editor (GtkAction *action, + EomWindow *window) +{ + GdkAppLaunchContext *context; + GAppInfo *app_info; + GList files; + + app_info = get_appinfo_for_editor (window); + + if (app_info == NULL) + return; + + context = gdk_app_launch_context_new (); + gdk_app_launch_context_set_screen (context, + gtk_widget_get_screen (GTK_WIDGET (window))); + gdk_app_launch_context_set_icon (context, + g_app_info_get_icon (app_info)); + gdk_app_launch_context_set_timestamp (context, + gtk_get_current_event_time ()); + + { + GList f = { eom_image_get_file (window->priv->image) }; + files = f; + } + + g_app_info_launch (app_info, &files, + G_APP_LAUNCH_CONTEXT (context), NULL); + + g_object_unref (files.data); + g_object_unref (context); +} + +static void +eom_window_add_open_editor_action (EomWindow *window) +{ + EggToolbarsModel *model; + GAppInfo *app_info; + GtkAction *action; + gchar *tooltip; + + app_info = get_appinfo_for_editor (window); + + if (app_info == NULL) + return; + + model = eom_application_get_toolbars_model (EOM_APP); + egg_toolbars_model_set_name_flags (model, "OpenEditor", + EGG_TB_MODEL_NAME_KNOWN); + + tooltip = g_strdup_printf (_("Edit the current image using %s"), + g_app_info_get_name (app_info)); + action = gtk_action_new ("OpenEditor", _("Edit Image"), tooltip, NULL); + gtk_action_set_gicon (action, g_app_info_get_icon (app_info)); + gtk_action_set_is_important (action, TRUE); + + g_signal_connect (action, "activate", + G_CALLBACK (eom_window_open_editor), window); + + gtk_action_group_add_action (window->priv->actions_image, action); + + g_object_unref (action); + g_free (tooltip); +} + static void eom_window_construct_ui (EomWindow *window) { @@ -4178,6 +4297,8 @@ eom_window_construct_ui (EomWindow *window) G_N_ELEMENTS (action_entries_image), window); + eom_window_add_open_editor_action (window); + gtk_action_group_add_toggle_actions (priv->actions_image, toggle_entries_image, G_N_ELEMENTS (toggle_entries_image), -- cgit v1.2.1