From cd4d5a2e0cb5e65389e4b12b3ba79645e236a825 Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Thu, 2 Jun 2016 13:07:39 +0300 Subject: 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. --- garcon/garcon-menu-item-action.c | 66 +++++++++++++++++++++++++++++++++++++++- garcon/garcon-menu-item-action.h | 5 ++- garcon/garcon-menu-item.c | 15 +++++++-- 3 files changed, 82 insertions(+), 4 deletions(-) (limited to 'garcon') 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); -- cgit v1.2.1