diff options
Diffstat (limited to 'libmenu/matemenu-tree.c')
-rw-r--r-- | libmenu/matemenu-tree.c | 139 |
1 files changed, 73 insertions, 66 deletions
diff --git a/libmenu/matemenu-tree.c b/libmenu/matemenu-tree.c index 370025b..0260a6d 100644 --- a/libmenu/matemenu-tree.c +++ b/libmenu/matemenu-tree.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2003, 2004 Red Hat, Inc. + * Copyright (C) 2012-2021 MATE Developers * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -17,6 +18,9 @@ * Boston, MA 02110-1301, USA. */ +/* used for realpath() */ +#define _XOPEN_SOURCE 500 + #include <config.h> #include "matemenu-tree.h" @@ -47,6 +51,7 @@ enum { PROP_FLAGS }; +#ifdef WITH_COLLECTION typedef enum { OBJECT_DRAWER, @@ -57,6 +62,7 @@ typedef enum OBJECT_MENU_BAR, OBJECT_SEPARATOR, } ObjectType; +#endif /* WITH_COLLECTION */ /* Signals */ enum @@ -75,7 +81,13 @@ struct _MateMenuTree char *non_prefixed_basename; char *path; char *canonical_path; + +#ifdef WITH_COLLECTION GPtrArray *collection_applet; + GSettings *settings; + guint emit_changed_signal; +#endif /* WITH_COLLECTION */ + MateMenuTreeFlags flags; GSList *menu_file_monitors; @@ -86,7 +98,6 @@ struct _MateMenuTree guint canonical : 1; guint loaded : 1; - GSettings *settings; }; G_DEFINE_TYPE (MateMenuTree, matemenu_tree, G_TYPE_OBJECT) @@ -179,9 +190,11 @@ static void matemenu_tree_invoke_monitors (MateMenuTree *tree); static void matemenu_tree_item_unref_and_unset_parent (gpointer itemp); +#ifdef WITH_COLLECTION static void collection_applet_changed (GSettings *settings, gchar *key, MateMenuTree *self); +#endif /* WITH_COLLECTION */ typedef enum { @@ -635,20 +648,28 @@ matemenu_tree_finalize (GObject *object) g_hash_table_destroy (tree->entries_by_id); tree->entries_by_id = NULL; + +#ifdef WITH_COLLECTION if (tree->collection_applet != NULL) { - g_ptr_array_foreach (tree->collection_applet, (GFunc) g_free, NULL); g_ptr_array_free (tree->collection_applet, TRUE); tree->collection_applet = NULL; } + g_signal_handlers_disconnect_by_func (tree->settings, G_CALLBACK (collection_applet_changed), tree); g_object_unref (tree->settings); + if (tree->emit_changed_signal != 0) + g_source_remove (tree->emit_changed_signal); + tree->emit_changed_signal = 0; +#endif /* WITH_COLLECTION */ + G_OBJECT_CLASS (matemenu_tree_parent_class)->finalize (object); } +#ifdef WITH_COLLECTION static void load_object (char *id, MateMenuTree *self) @@ -667,7 +688,7 @@ load_object (char *id, char *desktop_name; if (self->collection_applet == NULL) - self->collection_applet = g_ptr_array_new (); + self->collection_applet = g_ptr_array_new_with_free_func ((GDestroyNotify) g_free); location = g_settings_get_string (settings, "launcher-location"); desktop_name = g_path_get_basename (location); @@ -691,6 +712,8 @@ static gboolean emit_changed_signal (gpointer data) { MateMenuTree *self = data; + self->emit_changed_signal = 0; + matemenu_tree_force_rebuild (self); matemenu_tree_invoke_monitors (self); @@ -718,24 +741,28 @@ collection_applet_changed (GSettings *settings, { if (self->collection_applet != NULL) { - g_ptr_array_foreach (self->collection_applet, (GFunc) g_free, NULL); g_ptr_array_free (self->collection_applet, TRUE); self->collection_applet = NULL; } get_panel_collection_applet (self); - g_idle_add (emit_changed_signal, (gpointer)self); + if (self->emit_changed_signal == 0) + self->emit_changed_signal = g_idle_add (emit_changed_signal, (gpointer)self); } +#endif /* WITH_COLLECTION */ static void matemenu_tree_init (MateMenuTree *self) { self->entries_by_id = g_hash_table_new (g_str_hash, g_str_equal); +#ifdef WITH_COLLECTION self->collection_applet = NULL; self->settings = g_settings_new ("org.mate.panel"); get_panel_collection_applet (self); g_signal_connect (self->settings, "changed::object-id-list", G_CALLBACK (collection_applet_changed), self); + self->emit_changed_signal = 0; +#endif /* WITH_COLLECTION */ } static void @@ -1078,8 +1105,7 @@ matemenu_tree_iter_unref (MateMenuTreeIter *iter) if (!g_atomic_int_dec_and_test (&iter->refcount)) return; - g_slist_foreach (iter->contents, (GFunc)matemenu_tree_item_unref, NULL); - g_slist_free (iter->contents); + g_slist_free_full (iter->contents, (GDestroyNotify)matemenu_tree_item_unref); g_slice_free (MateMenuTreeIter, iter); } @@ -1588,34 +1614,24 @@ matemenu_tree_directory_finalize (MateMenuTreeDirectory *directory) { g_assert (directory->item.refcount == 0); - g_slist_foreach (directory->contents, - (GFunc) matemenu_tree_item_unref_and_unset_parent, - NULL); - g_slist_free (directory->contents); + g_slist_free_full (directory->contents, + (GDestroyNotify) matemenu_tree_item_unref_and_unset_parent); directory->contents = NULL; - g_slist_foreach (directory->default_layout_info, - (GFunc) menu_layout_node_unref, - NULL); - g_slist_free (directory->default_layout_info); + g_slist_free_full (directory->default_layout_info, + (GDestroyNotify) menu_layout_node_unref); directory->default_layout_info = NULL; - g_slist_foreach (directory->layout_info, - (GFunc) menu_layout_node_unref, - NULL); - g_slist_free (directory->layout_info); + g_slist_free_full (directory->layout_info, + (GDestroyNotify) menu_layout_node_unref); directory->layout_info = NULL; - g_slist_foreach (directory->subdirs, - (GFunc) matemenu_tree_item_unref_and_unset_parent, - NULL); - g_slist_free (directory->subdirs); + g_slist_free_full (directory->subdirs, + (GDestroyNotify) matemenu_tree_item_unref_and_unset_parent); directory->subdirs = NULL; - g_slist_foreach (directory->entries, - (GFunc) matemenu_tree_item_unref_and_unset_parent, - NULL); - g_slist_free (directory->entries); + g_slist_free_full (directory->entries, + (GDestroyNotify) matemenu_tree_item_unref_and_unset_parent); directory->entries = NULL; if (directory->directory_entry) @@ -1790,14 +1806,13 @@ matemenu_tree_entry_compare_by_id (MateMenuTreeItem *a, gpointer matemenu_tree_item_ref (gpointer itemp) { - MateMenuTreeItem* item = (MateMenuTreeItem*) itemp; - - g_return_val_if_fail(item != NULL, NULL); - g_return_val_if_fail(item->refcount > 0, NULL); + MateMenuTreeItem* item = (MateMenuTreeItem*) itemp; + g_return_val_if_fail(item != NULL, NULL); + g_return_val_if_fail(item->refcount > 0, NULL); g_atomic_int_inc (&item->refcount); - return item; + return item; } void @@ -1897,15 +1912,12 @@ matemenu_tree_item_compare_get_name_helper (MateMenuTreeItem *item, } static int -matemenu_tree_item_compare (MateMenuTreeItem *a, - MateMenuTreeItem *b, - gpointer flags_p) +matemenu_tree_item_compare (MateMenuTreeItem *a, + MateMenuTreeItem *b, + MateMenuTreeFlags flags) { const char *name_a; const char *name_b; - MateMenuTreeFlags flags; - - flags = GPOINTER_TO_INT (flags_p); name_a = matemenu_tree_item_compare_get_name_helper (a, flags); name_b = matemenu_tree_item_compare_get_name_helper (b, flags); @@ -2628,8 +2640,7 @@ add_menu_for_legacy_dir (MenuLayoutNode *parent, desktop_entry_set_unref (desktop_entries); - g_slist_foreach (subdirs, (GFunc) g_free, NULL); - g_slist_free (subdirs); + g_slist_free_full (subdirs, (GDestroyNotify) g_free); return menu_added; } @@ -3243,6 +3254,7 @@ get_by_category_foreach (const char *file_id, desktop_entry_set_add_entry (data->set, entry, file_id); } +#ifdef WITH_COLLECTION static void get_by_desktop_foreach (const char *file_id, DesktopEntry *entry, @@ -3251,6 +3263,7 @@ get_by_desktop_foreach (const char *file_id, if (g_strcmp0 (file_id, data->category) == 0) desktop_entry_set_add_entry (data->set, entry, file_id); } +#endif /* WITH_COLLECTION */ static void get_by_category (DesktopEntrySet *entry_pool, @@ -3267,6 +3280,7 @@ get_by_category (DesktopEntrySet *entry_pool, &data); } +#ifdef WITH_COLLECTION static void get_by_desktop (DesktopEntrySet *entry_pool, DesktopEntrySet *set, @@ -3281,6 +3295,7 @@ get_by_desktop (DesktopEntrySet *entry_pool, (DesktopEntrySetForeachFunc) get_by_desktop_foreach, &data); } +#endif /* WITH_COLLECTION */ static DesktopEntrySet * process_include_rules (MenuLayoutNode *layout, @@ -3574,7 +3589,6 @@ process_layout (MateMenuTree *tree, menu_verbose ("=== Menu name = %s ===\n", directory->name); - deleted = FALSE; only_unallocated = FALSE; @@ -3790,6 +3804,8 @@ process_layout (MateMenuTree *tree, matemenu_tree_item_unref (directory); return NULL; } + +#ifdef WITH_COLLECTION if (tree->collection_applet && !g_strcmp0 (directory->name, "Collection")) { guint i; @@ -3799,6 +3815,7 @@ process_layout (MateMenuTree *tree, get_by_desktop (entry_pool, entries, desktop_name); } } +#endif /* WITH_COLLECTION */ desktop_entry_set_foreach (entries, (DesktopEntrySetForeachFunc) entries_listify_foreach, @@ -4095,10 +4112,8 @@ preprocess_layout_info_subdir_helper (MateMenuTree *tree, alias = matemenu_tree_alias_new (directory, subdir, item); - g_slist_foreach (list, - (GFunc) matemenu_tree_item_unref_and_unset_parent, - NULL); - g_slist_free (list); + g_slist_free_full (list, + (GDestroyNotify) matemenu_tree_item_unref_and_unset_parent); subdir->subdirs = NULL; subdir->entries = NULL; @@ -4505,8 +4520,8 @@ merge_subdirs (MateMenuTree *tree, directory->subdirs = NULL; subdirs = g_slist_sort_with_data (subdirs, - (GCompareDataFunc) matemenu_tree_item_compare, - GINT_TO_POINTER (MATEMENU_TREE_FLAGS_NONE)); + (GCompareDataFunc) matemenu_tree_item_compare, + (void *) MATEMENU_TREE_FLAGS_NONE); tmp = subdirs; while (tmp != NULL) @@ -4551,7 +4566,7 @@ merge_entries (MateMenuTree *tree, entries = g_slist_sort_with_data (entries, (GCompareDataFunc) matemenu_tree_item_compare, - GINT_TO_POINTER (tree->flags)); + (void *) tree->flags); tmp = entries; while (tmp != NULL) @@ -4599,8 +4614,8 @@ merge_subdirs_and_entries (MateMenuTree *tree, directory->entries = NULL; items = g_slist_sort_with_data (items, - (GCompareDataFunc) matemenu_tree_item_compare, - GINT_TO_POINTER (tree->flags)); + (GCompareDataFunc) matemenu_tree_item_compare, + (void *) tree->flags); tmp = items; while (tmp != NULL) @@ -4818,28 +4833,20 @@ process_layout_info (MateMenuTree *tree, } } - g_slist_foreach (directory->subdirs, - (GFunc) matemenu_tree_item_unref, - NULL); - g_slist_free (directory->subdirs); + g_slist_free_full (directory->subdirs, + matemenu_tree_item_unref); directory->subdirs = NULL; - g_slist_foreach (directory->entries, - (GFunc) matemenu_tree_item_unref, - NULL); - g_slist_free (directory->entries); + g_slist_free_full (directory->entries, + matemenu_tree_item_unref); directory->entries = NULL; - g_slist_foreach (directory->default_layout_info, - (GFunc) menu_layout_node_unref, - NULL); - g_slist_free (directory->default_layout_info); + g_slist_free_full (directory->default_layout_info, + (GDestroyNotify) menu_layout_node_unref); directory->default_layout_info = NULL; - g_slist_foreach (directory->layout_info, - (GFunc) menu_layout_node_unref, - NULL); - g_slist_free (directory->layout_info); + g_slist_free_full (directory->layout_info, + (GDestroyNotify) menu_layout_node_unref); directory->layout_info = NULL; } |