[eog] Bug 609958 - add "Edit Image" toolbar button



commit b5e6b7d31181ab87f788921f751a6550bddb5bcf
Author: Ryan Lortie <desrt desrt ca>
Date:   Sun Feb 14 20:48:13 2010 -0500

    Bug 609958 - 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.

 configure.ac                         |    1 +
 data/org.gnome.eog.gschema.xml.in.in |    5 ++
 src/eog-config-keys.h                |    1 +
 src/eog-window.c                     |  121 ++++++++++++++++++++++++++++++++++
 4 files changed, 128 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 58b9bae..dfc0164 100644
--- a/configure.ac
+++ b/configure.ac
@@ -97,6 +97,7 @@ EXEMPI_REQUIRED=1.99.5
 EOG_MODULES="gtk+-3.0 >= $GTK_REQUIRED \
              glib-2.0 >= $GLIB_REQUIRED \
              gio-2.0 >= $GLIB_REQUIRED \
+             gio-unix-2.0 >= $GLIB_REQUIRED \
              gthread-2.0 >= $GLIB_REQUIRED \
              gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED \
              gdk-pixbuf-2.0 >= $GDKPIXBUF_REQUIRED \
diff --git a/data/org.gnome.eog.gschema.xml.in.in b/data/org.gnome.eog.gschema.xml.in.in
index 4f6b7b0..dd258cd 100644
--- a/data/org.gnome.eog.gschema.xml.in.in
+++ b/data/org.gnome.eog.gschema.xml.in.in
@@ -117,6 +117,11 @@
       <_summary>Whether the metadata list in the properties dialog should have its own page.</_summary>
       <_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.</_description>
     </key>
+    <key name="external-editor" type="s">
+      <default>''</default>
+      <_summary>External program to use for editing images</_summary>
+      <_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.</_description>
+    </key>
   </schema>
   <schema id="org.gnome.eog.plugins" path="/apps/eog/plugins/">
     <key name="active-plugins" type="as">
diff --git a/src/eog-config-keys.h b/src/eog-config-keys.h
index 9a2e5ad..ec2a1e1 100644
--- a/src/eog-config-keys.h
+++ b/src/eog-config-keys.h
@@ -62,6 +62,7 @@
 #define EOG_CONF_UI_DISABLE_TRASH_CONFIRMATION	"disable-trash-confirmation"
 #define EOG_CONF_UI_FILECHOOSER_XDG_FALLBACK	"filechooser-xdg-fallback"
 #define EOG_CONF_UI_PROPSDIALOG_NETBOOK_MODE	"propsdialog-netbook-mode"
+#define EOG_CONF_UI_EXTERNAL_EDITOR		"external-editor"
 
 #define EOG_CONF_PLUGINS_ACTIVE_PLUGINS         "active-plugins"
 
diff --git a/src/eog-window.c b/src/eog-window.c
index a67473f..1fc4659 100644
--- a/src/eog-window.c
+++ b/src/eog-window.c
@@ -64,6 +64,7 @@
 #include <glib/gi18n.h>
 #include <gio/gio.h>
 #include <gdk/gdkkeysyms.h>
+#include <gio/gdesktopappinfo.h>
 #include <gtk/gtk.h>
 #include <gconf/gconf-client.h>
 
@@ -214,6 +215,7 @@ static void eog_window_list_store_image_removed (GtkTreeModel *tree_model,
 static void eog_window_set_wallpaper (EogWindow *window, const gchar *filename, const gchar *visible_filename);
 static gboolean eog_window_save_images (EogWindow *window, GList *images);
 static void eog_window_finish_saving (EogWindow *window);
+static GAppInfo *get_appinfo_for_editor (EogWindow *window);
 
 static GQuark
 eog_window_error_quark (void)
@@ -921,6 +923,8 @@ open_with_launch_application_cb (GtkAction *action, gpointer data) {
 static void
 eog_window_update_openwith_menu (EogWindow *window, EogImage *image)
 {
+	gboolean edit_button_active;
+	GAppInfo *editor_app;
 	GFile *file;
 	GFileInfo *file_info;
 	GList *iter;
@@ -936,6 +940,9 @@ eog_window_update_openwith_menu (EogWindow *window, EogImage *image)
 
 	priv = window->priv;
 
+	edit_button_active = FALSE;
+	editor_app = get_appinfo_for_editor (window);
+
 	file = eog_image_get_file (image);
 	file_info = g_file_query_info (file,
 				       G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
@@ -978,6 +985,10 @@ eog_window_update_openwith_menu (EogWindow *window, EogImage *image)
                 GAppInfo *app = iter->data;
                 gchar name[64];
 
+                if (g_app_info_equal (editor_app, app)) {
+                        edit_button_active = TRUE;
+                }
+
                 /* Do not include eog itself */
                 if (g_ascii_strcasecmp (g_app_info_get_executable (app),
                                         g_get_prgname ()) == 0) {
@@ -1065,6 +1076,12 @@ eog_window_update_openwith_menu (EogWindow *window, EogImage *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
@@ -4017,6 +4034,108 @@ eog_window_finish_saving (EogWindow *window)
 	} while (priv->save_job != NULL);
 }
 
+static GAppInfo *
+get_appinfo_for_editor (EogWindow *window)
+{
+	/* We want this function to always return the same thing, not
+	 * just for performance reasons, but because if someone edits
+	 * GConf while eog 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,
+		                                EOG_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
+eog_window_open_editor (GtkAction *action,
+                        EogWindow *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 = { eog_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
+eog_window_add_open_editor_action (EogWindow *window)
+{
+        EggToolbarsModel *model;
+	GAppInfo *app_info;
+	GtkAction *action;
+        gchar *tooltip;
+
+	app_info = get_appinfo_for_editor (window);
+
+	if (app_info == NULL)
+		return;
+
+	model = eog_application_get_toolbars_model (EOG_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 (eog_window_open_editor), window);
+
+	gtk_action_group_add_action (window->priv->actions_image, action);
+
+	g_object_unref (action);
+	g_free (tooltip);
+}
+
 static void
 eog_window_construct_ui (EogWindow *window)
 {
@@ -4067,6 +4186,8 @@ eog_window_construct_ui (EogWindow *window)
 				      G_N_ELEMENTS (action_entries_image),
 				      window);
 
+	eog_window_add_open_editor_action (window);
+
 	gtk_action_group_add_toggle_actions (priv->actions_image,
 					     toggle_entries_image,
 					     G_N_ELEMENTS (toggle_entries_image),



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]