[Xfce4-commits] [xfce/garcon] 12/12: Desktop actions custom icon support
noreply at xfce.org
noreply at xfce.org
Fri Jun 3 07:52:09 CEST 2016
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository xfce/garcon.
commit cd4d5a2e0cb5e65389e4b12b3ba79645e236a825
Author: Eric Koegel <eric.koegel at gmail.com>
Date: Thu Jun 2 13:07:39 2016 +0300
Desktop actions custom icon support
The FDO spec allows for actions in the desktop file to supply
a custom icon to use. This patch adds that support into the
GarconMenuItemAction as well as to garcon-gtk.
---
docs/reference/garcon-sections.txt | 2 ++
garcon-gtk/garcon-gtk-menu.c | 12 ++++++-
garcon/garcon-menu-item-action.c | 66 +++++++++++++++++++++++++++++++++++++-
garcon/garcon-menu-item-action.h | 5 ++-
garcon/garcon-menu-item.c | 15 +++++++--
5 files changed, 95 insertions(+), 5 deletions(-)
diff --git a/docs/reference/garcon-sections.txt b/docs/reference/garcon-sections.txt
index 5035148..848046c 100644
--- a/docs/reference/garcon-sections.txt
+++ b/docs/reference/garcon-sections.txt
@@ -178,6 +178,8 @@ garcon_menu_item_action_get_command
garcon_menu_item_action_set_command
garcon_menu_item_action_get_name
garcon_menu_item_action_set_name
+garcon_menu_item_action_get_icon_name
+garcon_menu_item_action_set_icon_name
garcon_menu_item_action_ref
garcon_menu_item_action_unref
<SUBSECTION Standard>
diff --git a/garcon-gtk/garcon-gtk-menu.c b/garcon-gtk/garcon-gtk-menu.c
index 2b59e42..32b1887 100644
--- a/garcon-gtk/garcon-gtk-menu.c
+++ b/garcon-gtk/garcon-gtk-menu.c
@@ -686,13 +686,23 @@ garcon_gtk_menu_add_actions (GarconGtkMenu *menu,
for (iter = g_list_first(actions); iter != NULL; iter = g_list_next (iter))
{
GarconMenuItemAction *action = garcon_menu_item_get_action (menu_item, iter->data);
+ const gchar *action_icon_name;
if (action == NULL)
continue;
+ /* If there's a custom icon associated with the action, use it.
+ * Otherwise default to the parent's icon.
+ */
+ action_icon_name = garcon_menu_item_action_get_icon_name (action);
+ if (action_icon_name == NULL)
+ {
+ action_icon_name = parent_icon_name;
+ }
+
mi = garcon_gtk_menu_create_menu_item (menu,
garcon_menu_item_action_get_name (action),
- parent_icon_name);
+ action_icon_name);
gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mi);
g_signal_connect (G_OBJECT (mi), "activate",
diff --git a/garcon/garcon-menu-item-action.c b/garcon/garcon-menu-item-action.c
index b416895..dd21a0e 100644
--- a/garcon/garcon-menu-item-action.c
+++ b/garcon/garcon-menu-item-action.c
@@ -35,6 +35,7 @@ enum
PROP_0,
PROP_NAME,
PROP_COMMAND,
+ PROP_ICON_NAME,
};
static void garcon_menu_item_action_finalize (GObject *object);
@@ -54,6 +55,9 @@ struct _GarconMenuItemActionPrivate
/* Command to be executed when the action is clicked */
gchar *command;
+
+ /* Name of the icon associated with the action */
+ gchar *icon_name;
};
G_DEFINE_TYPE (GarconMenuItemAction, garcon_menu_item_action, G_TYPE_OBJECT)
@@ -97,6 +101,20 @@ garcon_menu_item_action_class_init (GarconMenuItemActionClass *klass)
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GarconMenuItemAction:icon-name:
+ *
+ * Name of the custom icon associated with this action.
+ **/
+ g_object_class_install_property (gobject_class,
+ PROP_ICON_NAME,
+ g_param_spec_string ("icon-name",
+ "icon-name",
+ "Custom icon name",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
}
static void
@@ -114,6 +132,7 @@ garcon_menu_item_action_finalize (GObject *object)
g_free (action->priv->name);
g_free (action->priv->command);
+ g_free (action->priv->icon_name);
(*G_OBJECT_CLASS (garcon_menu_item_action_parent_class)->finalize) (object);
}
@@ -138,6 +157,10 @@ garcon_menu_item_action_get_property (GObject *object,
g_value_set_string (value, garcon_menu_item_action_get_command (action));
break;
+ case PROP_ICON_NAME:
+ g_value_set_string (value, garcon_menu_item_action_get_icon_name (action));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -164,6 +187,10 @@ garcon_menu_item_action_set_property (GObject *object,
garcon_menu_item_action_set_command (action, g_value_get_string (value));
break;
+ case PROP_ICON_NAME:
+ garcon_menu_item_action_set_icon_name (action, g_value_get_string (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -200,6 +227,43 @@ garcon_menu_item_action_set_name (GarconMenuItemAction *action,
}
+
+const gchar*
+garcon_menu_item_action_get_icon_name (GarconMenuItemAction *action)
+{
+ g_return_val_if_fail (GARCON_IS_MENU_ITEM_ACTION (action), NULL);
+ return action->priv->icon_name;
+}
+
+
+
+void
+garcon_menu_item_action_set_icon_name (GarconMenuItemAction *action,
+ const gchar *icon_name)
+{
+ g_return_if_fail (GARCON_IS_MENU_ITEM_ACTION (action));
+
+ /* Abort if old and new name are equal */
+ if (g_strcmp0 (action->priv->icon_name, icon_name) == 0)
+ return;
+
+ /* Assign new name */
+ g_free (action->priv->icon_name);
+ if (icon_name != NULL)
+ {
+ action->priv->icon_name = g_strdup (icon_name);
+ }
+ else
+ {
+ action->priv->icon_name = NULL;
+ }
+
+ /* Notify listeners */
+ g_object_notify (G_OBJECT (action), "icon-name");
+}
+
+
+
const gchar*
garcon_menu_item_action_get_command (GarconMenuItemAction *action)
{
@@ -246,4 +310,4 @@ garcon_menu_item_action_unref (GarconMenuItemAction *action)
/* Decrement the reference counter */
g_object_unref (G_OBJECT (action));
-}
\ No newline at end of file
+}
diff --git a/garcon/garcon-menu-item-action.h b/garcon/garcon-menu-item-action.h
index 2069aaa..a519984 100644
--- a/garcon/garcon-menu-item-action.h
+++ b/garcon/garcon-menu-item-action.h
@@ -66,9 +66,12 @@ void garcon_menu_item_action_set_command (GarconMenuItem
const gchar *garcon_menu_item_action_get_name (GarconMenuItemAction *action);
void garcon_menu_item_action_set_name (GarconMenuItemAction *action,
const gchar *name);
+const gchar *garcon_menu_item_action_get_icon_name (GarconMenuItemAction *action);
+void garcon_menu_item_action_set_icon_name (GarconMenuItemAction *action,
+ const gchar *icon_name);
void garcon_menu_item_action_ref (GarconMenuItemAction *action);
void garcon_menu_item_action_unref (GarconMenuItemAction *action);
G_END_DECLS
-#endif /* !__GARCON_MENU_ITEM_ACTION_H__ */
\ No newline at end of file
+#endif /* !__GARCON_MENU_ITEM_ACTION_H__ */
diff --git a/garcon/garcon-menu-item.c b/garcon/garcon-menu-item.c
index 3f6f676..e5af887 100644
--- a/garcon/garcon-menu-item.c
+++ b/garcon/garcon-menu-item.c
@@ -820,14 +820,16 @@ garcon_menu_item_new (GFile *file)
/* Parse name and exec command */
name = xfce_rc_read_entry (rc, G_KEY_FILE_DESKTOP_KEY_NAME, NULL);
exec = xfce_rc_read_entry_untranslated (rc, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
+ icon = xfce_rc_read_entry_untranslated (rc, G_KEY_FILE_DESKTOP_KEY_ICON, NULL);
- /* Validate Name and Exec fields */
+ /* Validate Name and Exec fields, icon is optional */
if (G_LIKELY (exec != NULL && name != NULL))
{
/* Allocate a new action instance */
action = g_object_new (GARCON_TYPE_MENU_ITEM_ACTION,
"name", name,
"command", exec,
+ "icon-name", icon,
NULL);
garcon_menu_item_set_action (item, *mt, action);
@@ -857,12 +859,15 @@ garcon_menu_item_new (GFile *file)
name = xfce_rc_read_entry (rc, G_KEY_FILE_DESKTOP_KEY_NAME, NULL);
exec = xfce_rc_read_entry_untranslated (rc, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
+ icon = xfce_rc_read_entry_untranslated (rc, G_KEY_FILE_DESKTOP_KEY_ICON, NULL);
+ /* Validate Name and Exec fields, icon is optional */
if (G_LIKELY (exec != NULL && name != NULL))
{
action = g_object_new (GARCON_TYPE_MENU_ITEM_ACTION,
"name", name,
"command", exec,
+ "icon-name", icon,
NULL);
garcon_menu_item_set_action (item, *mt, action);
@@ -952,6 +957,7 @@ garcon_menu_item_reload_from_file (GarconMenuItem *item,
const gchar *string;
const gchar *name;
const gchar *exec;
+ const gchar *icon;
gchar *filename;
gchar *action_group;
gchar *url_exec = NULL;
@@ -1096,14 +1102,16 @@ garcon_menu_item_reload_from_file (GarconMenuItem *item,
/* Parse name and exec command */
name = xfce_rc_read_entry (rc, G_KEY_FILE_DESKTOP_KEY_NAME, NULL);
exec = xfce_rc_read_entry_untranslated (rc, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
+ icon = xfce_rc_read_entry_untranslated (rc, G_KEY_FILE_DESKTOP_KEY_ICON, NULL);
- /* Validate Name and Exec fields */
+ /* Validate Name and Exec fields, icon is optional */
if (G_LIKELY (exec != NULL && name != NULL))
{
/* Allocate a new action instance */
action = g_object_new (GARCON_TYPE_MENU_ITEM_ACTION,
"name", name,
"command", exec,
+ "icon-name", icon,
NULL);
garcon_menu_item_set_action (item, *mt, action);
@@ -1132,12 +1140,15 @@ garcon_menu_item_reload_from_file (GarconMenuItem *item,
name = xfce_rc_read_entry (rc, G_KEY_FILE_DESKTOP_KEY_NAME, NULL);
exec = xfce_rc_read_entry_untranslated (rc, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
+ icon = xfce_rc_read_entry_untranslated (rc, G_KEY_FILE_DESKTOP_KEY_ICON, NULL);
+ /* Validate Name and Exec fields, icon is optional */
if (G_LIKELY (exec != NULL && name != NULL))
{
action = g_object_new (GARCON_TYPE_MENU_ITEM_ACTION,
"name", name,
"command", exec,
+ "icon-name", icon,
NULL);
garcon_menu_item_set_action (item, *mt, action);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list