[gnome-commander] Display application icon in the "Open With" menu
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] Display application icon in the "Open With" menu
- Date: Sat, 16 Jul 2016 20:04:35 +0000 (UTC)
commit eaa587b39f674cf947f6f5a7db50e4fc102426e0
Author: Puux <puuxmine gmail com>
Date: Wed Jul 13 11:36:57 2016 +0300
Display application icon in the "Open With" menu
src/gnome-cmd-app.cc | 58 +++++++++++++++++++++++++++++++++++++++-
src/gnome-cmd-file-popmenu.cc | 27 +++++++++++++++---
2 files changed, 78 insertions(+), 7 deletions(-)
---
diff --git a/src/gnome-cmd-app.cc b/src/gnome-cmd-app.cc
index b1b203b..deae69c 100644
--- a/src/gnome-cmd-app.cc
+++ b/src/gnome-cmd-app.cc
@@ -70,18 +70,72 @@ GnomeCmdApp *gnome_cmd_app_new_with_values (const gchar *name,
}
+char* panel_find_icon (GtkIconTheme *icon_theme, const char *icon_name, gint size)
+{
+ char *retval = NULL;
+ GtkIconInfo *icon_info = NULL;
+ char *icon_no_extension;
+ char *p;
+
+ if (icon_name == NULL || strcmp (icon_name, "") == 0)
+ return NULL;
+
+ if (g_path_is_absolute (icon_name)) {
+ if (g_file_test (icon_name, G_FILE_TEST_EXISTS)) {
+ return g_strdup (icon_name);
+ }
+ else
+ {
+ char *basename;
+
+ basename = g_path_get_basename (icon_name);
+ retval = panel_find_icon (icon_theme, basename, size);
+ g_free (basename);
+
+ return retval;
+ }
+ }
+
+ /* This is needed because some .desktop files have an icon name *and*
+ * an extension as icon */
+ icon_no_extension = g_strdup (icon_name);
+ p = strrchr (icon_no_extension, '.');
+ if (p &&
+ (strcmp (p, ".png") == 0 ||
+ strcmp (p, ".xpm") == 0 ||
+ strcmp (p, ".svg") == 0)) {
+ *p = 0;
+ }
+
+ icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_no_extension, size, (GtkIconLookupFlags) 0);
+ if (!icon_info)
+ return NULL;
+ retval = g_strdup (gtk_icon_info_get_filename (icon_info));
+
+ g_free (icon_no_extension);
+ gtk_icon_info_free (icon_info);
+
+ return retval;
+}
+
+
GnomeCmdApp *gnome_cmd_app_new_from_vfs_app (GnomeVFSMimeApplication *vfs_app)
{
g_return_val_if_fail (vfs_app != NULL, NULL);
- return gnome_cmd_app_new_with_values (vfs_app->name,
+ GtkIconTheme *theme = gtk_icon_theme_get_default ();
+ char *icon = panel_find_icon (theme, gnome_vfs_mime_application_get_icon (vfs_app), 16);
+
+ GnomeCmdApp *rel_value = gnome_cmd_app_new_with_values (vfs_app->name,
vfs_app->command,
- NULL,
+ icon,
APP_TARGET_ALL_FILES,
NULL,
vfs_app->expects_uris ==
GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS,
vfs_app->can_open_multiple_files,
vfs_app->requires_terminal);
+ g_free (icon);
+ return rel_value;
}
diff --git a/src/gnome-cmd-file-popmenu.cc b/src/gnome-cmd-file-popmenu.cc
index 75634d0..62517a4 100644
--- a/src/gnome-cmd-file-popmenu.cc
+++ b/src/gnome-cmd-file-popmenu.cc
@@ -440,7 +440,7 @@ inline gchar *string_double_underscores (const gchar *string)
}
-inline gchar *get_default_application_action_name (GList *files)
+inline gchar *get_default_application_action_name (GList *files, gchar **icon_path)
{
if (g_list_length(files)>1)
return g_strdup (_("_Open"));
@@ -448,7 +448,19 @@ inline gchar *get_default_application_action_name (GList *files)
GnomeCmdFile *f = (GnomeCmdFile *) files->data;
gchar *uri_str = f->get_uri_str();
GnomeVFSMimeApplication *app = gnome_vfs_mime_get_default_application_for_uri (uri_str,
f->info->mime_type);
-
+
+ if (icon_path)
+ {
+ GnomeCmdApp *gapp = gnome_cmd_app_new_from_vfs_app (app);
+ if (gapp)
+ {
+ *icon_path = g_strdup (gapp->icon_path);
+ gnome_cmd_app_free (gapp);
+ }
+ else
+ *icon_path = NULL;
+ }
+
g_free (uri_str);
if (!app)
@@ -539,8 +551,11 @@ GtkWidget *gnome_cmd_file_popmenu_new (GnomeCmdFileList *fl)
apps_uiinfo[i].label = g_strdup (gnome_cmd_app_get_name (data->app));
apps_uiinfo[i].moreinfo = (gpointer) cb_exec_with_app;
apps_uiinfo[i].user_data = data;
-
- menu->priv->data_list = g_list_append (menu->priv->data_list, data);
+ if (data->app->icon_path)
+ {
+ apps_uiinfo[i].pixmap_type = GNOME_APP_PIXMAP_FILENAME;
+ apps_uiinfo[i].pixmap_info = g_strdup (data->app->icon_path);
+ }
}
}
@@ -552,6 +567,7 @@ GtkWidget *gnome_cmd_file_popmenu_new (GnomeCmdFileList *fl)
apps_uiinfo[i].label = g_strdup (_("Other _Application..."));
apps_uiinfo[i].moreinfo = (gpointer) on_open_with_other;
apps_uiinfo[i].user_data = files;
+ apps_uiinfo[i].pixmap_type = GNOME_APP_PIXMAP_NONE;
gnome_vfs_mime_application_list_free (tmp);
apps_uiinfo[++i].type = GNOME_APP_UI_ENDOFINFO;
@@ -565,7 +581,8 @@ GtkWidget *gnome_cmd_file_popmenu_new (GnomeCmdFileList *fl)
if (other_uiinfo[i].type == GNOME_APP_UI_ITEM)
other_uiinfo[i].user_data = fl;
- open_uiinfo[0].label = get_default_application_action_name(files); // must be freed after
gnome_app_fill_menu ()
+ open_uiinfo[0].label = get_default_application_action_name(files, (gchar **)
&open_uiinfo[0].pixmap_info); // must be freed after gnome_app_fill_menu ()
+ open_uiinfo[0].pixmap_type = open_uiinfo[0].pixmap_info ? GNOME_APP_PIXMAP_FILENAME :
GNOME_APP_PIXMAP_NONE;
open_uiinfo[0].user_data = files;
exec_uiinfo[0].user_data = files;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]