This is an automated email from the git hooks/post-receive script. e r i c p u s h e d a c o m m i t t o b r a n c h m a s t e r in repository xfce/garcon.
commit a38922c0892262294c88813c4bf0c72e2f438d54 Author: Gregor Santner <gsant...@mailbox.org> Date: Fri Oct 13 11:45:38 2017 +0200 Support for freedesktop Keyword item (#10683) Signed-off-by: Eric Koegel <eric.koe...@gmail.com> --- garcon/garcon-menu-item.c | 134 ++++++++++++++++++++++++++++++++++++++++++---- garcon/garcon-menu-item.h | 8 +++ 2 files changed, 133 insertions(+), 9 deletions(-) diff --git a/garcon/garcon-menu-item.c b/garcon/garcon-menu-item.c index e5af887..fc569bf 100644 --- a/garcon/garcon-menu-item.c +++ b/garcon/garcon-menu-item.c @@ -3,6 +3,7 @@ * Copyright (c) 2006-2010 Jannis Pohlmann <jan...@xfce.org> * Copyright (c) 2009-2010 Nick Schermer <n...@xfce.org> * Copyright (c) 2015 Danila Poyarkov <dannotem...@gmail.com> + * Copyright (c) 2017 Gregor Santner <gsant...@mailbox.org> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -81,8 +82,8 @@ static gboolean garcon_menu_item_get_element_show_in_environment (GarconMenu static gboolean garcon_menu_item_get_element_no_display (GarconMenuElement *element); static gboolean garcon_menu_item_get_element_equal (GarconMenuElement *element, GarconMenuElement *other); -static gboolean garcon_menu_item_category_lists_equal (GList *categories1, - GList *categories2); +static gboolean garcon_menu_item_lists_equal (GList *list1, + GList *list2); @@ -101,6 +102,9 @@ struct _GarconMenuItemPrivate /* List of categories */ GList *categories; + /* List of keywords */ + GList *keywords; + /* Whether this application requires a terminal to be started in */ guint requires_terminal : 1; @@ -418,6 +422,7 @@ garcon_menu_item_finalize (GObject *object) g_strfreev (item->priv->not_show_in); _garcon_g_list_free_full (item->priv->categories, g_free); + _garcon_g_list_free_full (item->priv->keywords, g_free); if (item->priv->file != NULL) g_object_unref (G_OBJECT (item->priv->file)); @@ -670,18 +675,18 @@ garcon_menu_item_get_element_icon_name (GarconMenuElement *element) static gboolean -garcon_menu_item_category_lists_equal (GList *categories1, - GList *categories2) +garcon_menu_item_lists_equal (GList *list1, + GList *list2) { gboolean element_missing = FALSE; GList *lp; - if (g_list_length (categories1) != g_list_length (categories2)) + if (g_list_length (list1) != g_list_length (list2)) return FALSE; - for (lp = categories1; !element_missing && lp != NULL; lp = lp->next) + for (lp = list1; !element_missing && lp != NULL; lp = lp->next) { - if (g_list_find_custom (categories2, lp->data, (GCompareFunc) g_strcmp0) == NULL) + if (g_list_find_custom (list2, lp->data, (GCompareFunc) g_strcmp0) == NULL) element_missing = TRUE; } @@ -713,6 +718,7 @@ garcon_menu_item_new (GFile *file) GarconMenuItemAction *action = NULL; XfceRc *rc; GList *categories = NULL; + GList *keywords = NULL; gchar *filename; gboolean terminal; gboolean no_display; @@ -801,6 +807,26 @@ garcon_menu_item_new (GFile *file) garcon_menu_item_set_categories (item, categories); } + /* Determine the keywords this application should be shown in */ + str_list = xfce_rc_read_list_entry (rc, G_KEY_FILE_DESKTOP_KEY_KEYWORDS, ";"); + if (G_LIKELY (str_list != NULL)) + { + for (mt = str_list; *mt != NULL; ++mt) + { + /* Try to steal the values */ + if (**mt != '\0') + keywords = g_list_prepend (keywords, *mt); + else + g_free (*mt); + } + + /* Cleanup */ + g_free (str_list); + + /* Assign keywords list to the menu item */ + garcon_menu_item_set_keywords (item, keywords); + } + /* Set the rest of the private data directly */ item->priv->only_show_in = xfce_rc_read_list_entry (rc, G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN, ";"); item->priv->not_show_in = xfce_rc_read_list_entry (rc, G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN, ";"); @@ -950,8 +976,10 @@ garcon_menu_item_reload_from_file (GarconMenuItem *item, GarconMenuItemAction *action = NULL; gboolean boolean; GList *categories = NULL; - GList *lp; GList *old_categories = NULL; + GList *keywords = NULL; + GList *old_keywords = NULL; + GList *lp; gchar **mt; gchar **str_list; const gchar *string; @@ -1075,13 +1103,54 @@ garcon_menu_item_reload_from_file (GarconMenuItem *item, if (affects_the_outside != NULL) { - if (!garcon_menu_item_category_lists_equal (old_categories, categories)) + if (!garcon_menu_item_lists_equal (old_categories, categories)) *affects_the_outside = TRUE; _garcon_g_list_free_full (old_categories, g_free); } + if (affects_the_outside != NULL) + { + /* create a deep copy the old keywords list */ + old_keywords = g_list_copy (item->priv->keywords); + for (lp = old_keywords; lp != NULL; lp = lp->next) + lp->data = g_strdup (lp->data); + } + + /* Determine the keywords this application should be shown in */ + str_list = xfce_rc_read_list_entry (rc, G_KEY_FILE_DESKTOP_KEY_KEYWORDS, ";"); + if (G_LIKELY (str_list != NULL)) + { + for (mt = str_list; *mt != NULL; ++mt) + { + /* Try to steal the values */ + if (**mt != '\0') + keywords = g_list_prepend (keywords, *mt); + else + g_free (*mt); + } + + /* Cleanup */ + g_free (str_list); + + /* Assign keywords list to the menu item */ + garcon_menu_item_set_keywords (item, keywords); + } + else + { + /* Assign empty keywords list to the menu item */ + garcon_menu_item_set_keywords (item, NULL); + } + + if (affects_the_outside != NULL) + { + if (!garcon_menu_item_lists_equal (old_keywords, keywords)) + *affects_the_outside = TRUE; + + _garcon_g_list_free_full (old_keywords, g_free); + } + /* Set the rest of the private data directly */ item->priv->only_show_in = xfce_rc_read_list_entry (rc, G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN, ";"); item->priv->not_show_in = xfce_rc_read_list_entry (rc, G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN, ";"); @@ -1261,6 +1330,34 @@ garcon_menu_item_set_categories (GarconMenuItem *item, +GList* +garcon_menu_item_get_keywords (GarconMenuItem *item) +{ + g_return_val_if_fail (GARCON_IS_MENU_ITEM (item), NULL); + return item->priv->keywords; +} + + + +void +garcon_menu_item_set_keywords (GarconMenuItem *item, + GList *keywords) +{ + g_return_if_fail (GARCON_IS_MENU_ITEM (item)); + + /* Abort if lists are equal */ + if (G_UNLIKELY (item->priv->keywords == keywords)) + return; + + /* Free old list */ + _garcon_g_list_free_full (item->priv->keywords, g_free); + + /* Assign new list */ + item->priv->keywords = keywords; +} + + + const gchar* garcon_menu_item_get_command (GarconMenuItem *item) { @@ -1599,6 +1696,25 @@ garcon_menu_item_has_category (GarconMenuItem *item, +gboolean +garcon_menu_item_has_keyword (GarconMenuItem *item, + const gchar *keyword) +{ + GList *iter; + gboolean found = FALSE; + + g_return_val_if_fail (GARCON_IS_MENU_ITEM (item), FALSE); + g_return_val_if_fail (keyword != NULL, FALSE); + + for (iter = item->priv->keywords; !found && iter != NULL; iter = g_list_next (iter)) + if (g_strcmp0 (iter->data, keyword) == 0) + found = TRUE; + + return found; +} + + + GList * garcon_menu_item_get_actions (GarconMenuItem *item) { diff --git a/garcon/garcon-menu-item.h b/garcon/garcon-menu-item.h index 9b6b7b3..65ecd0f 100644 --- a/garcon/garcon-menu-item.h +++ b/garcon/garcon-menu-item.h @@ -3,6 +3,7 @@ * Copyright (c) 2006-2010 Jannis Pohlmann <jan...@xfce.org> * Copyright (c) 2009 Nick Schermer <n...@xfce.org> * Copyright (c) 2015 Danila Poyarkov <dannotem...@gmail.com> + * Copyright (c) 2017 Gregor Santner <gsant...@mailbox.org> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -44,6 +45,8 @@ typedef struct _GarconMenuItem GarconMenuItem; #define GARCON_IS_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GARCON_TYPE_MENU_ITEM)) #define GARCON_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GARCON_TYPE_MENU_ITEM, GarconMenuItemClass)) +#define G_KEY_FILE_DESKTOP_KEY_KEYWORDS "Keywords" + struct _GarconMenuItemClass { GObjectClass __parent__; @@ -123,6 +126,11 @@ void garcon_menu_item_set_categories (Garcon GList *categories); gboolean garcon_menu_item_has_category (GarconMenuItem *item, const gchar *category); +GList *garcon_menu_item_get_keywords (GarconMenuItem *item); +void garcon_menu_item_set_keywords (GarconMenuItem *item, + GList *keywords); +gboolean garcon_menu_item_has_keyword (GarconMenuItem *item, + const gchar *keyword); GList *garcon_menu_item_get_actions (GarconMenuItem *item); GarconMenuItemAction *garcon_menu_item_get_action (GarconMenuItem *item, const gchar *action_name); -- To stop receiving notification emails like this one, please contact the administrator of this repository. _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits