diff options
author | yetist <[email protected]> | 2018-04-27 15:20:40 +0800 |
---|---|---|
committer | raveit65 <[email protected]> | 2018-05-30 15:44:02 +0200 |
commit | 263157786e7881f1c98f0a6d839447d8f0c57dbd (patch) | |
tree | 968ce9df1f0f42f8fabb01efaf2dbb81b46a41c7 | |
parent | 10b2021f0a98f1575400aac2beffd8e3c47ecdd5 (diff) | |
download | mate-panel-263157786e7881f1c98f0a6d839447d8f0c57dbd.tar.bz2 mate-panel-263157786e7881f1c98f0a6d839447d8f0c57dbd.tar.xz |
Support new mate-menus api
-rw-r--r-- | mate-panel/drawer-private.h | 2 | ||||
-rw-r--r-- | mate-panel/drawer.c | 11 | ||||
-rw-r--r-- | mate-panel/drawer.h | 4 | ||||
-rw-r--r-- | mate-panel/menu.c | 289 | ||||
-rw-r--r-- | mate-panel/panel-addto.c | 93 | ||||
-rw-r--r-- | mate-panel/panel-menu-button.c | 8 | ||||
-rw-r--r-- | mate-panel/panel-run-dialog.c | 148 |
7 files changed, 306 insertions, 249 deletions
diff --git a/mate-panel/drawer-private.h b/mate-panel/drawer-private.h index b71ef818..67db7353 100644 --- a/mate-panel/drawer-private.h +++ b/mate-panel/drawer-private.h @@ -133,7 +133,7 @@ static void load_drawer_applet (char *toplevel_id, const char *id); static void panel_drawer_prepare (const char *drawer_id, - const char *custom_icon, + GIcon *custom_icon, gboolean use_custom_icon, const char *tooltip, char **attached_toplevel_id); diff --git a/mate-panel/drawer.c b/mate-panel/drawer.c index 5875ef65..d7d10072 100644 --- a/mate-panel/drawer.c +++ b/mate-panel/drawer.c @@ -568,7 +568,7 @@ load_drawer_applet (char *toplevel_id, static void panel_drawer_prepare (const char *drawer_id, - const char *custom_icon, + GIcon *custom_icon, gboolean use_custom_icon, const char *tooltip, char **attached_toplevel_id) @@ -587,7 +587,10 @@ panel_drawer_prepare (const char *drawer_id, g_settings_set_boolean (settings, PANEL_OBJECT_USE_CUSTOM_ICON_KEY, use_custom_icon); if (custom_icon) { - g_settings_set_string (settings, PANEL_OBJECT_CUSTOM_ICON_KEY, custom_icon); + gchar *icon_name; + icon_name = g_icon_to_string(custom_icon); + g_settings_set_string (settings, PANEL_OBJECT_CUSTOM_ICON_KEY, icon_name); + g_free(icon_name); } if (attached_toplevel_id) { @@ -618,7 +621,7 @@ panel_drawer_prepare (const char *drawer_id, void panel_drawer_create (PanelToplevel *toplevel, int position, - const char *custom_icon, + GIcon *custom_icon, gboolean use_custom_icon, const char *tooltip) { @@ -636,7 +639,7 @@ panel_drawer_create (PanelToplevel *toplevel, char * panel_drawer_create_with_id (const char *toplevel_id, int position, - const char *custom_icon, + GIcon *custom_icon, gboolean use_custom_icon, const char *tooltip) { diff --git a/mate-panel/drawer.h b/mate-panel/drawer.h index 67c7c6d1..891b8dd7 100644 --- a/mate-panel/drawer.h +++ b/mate-panel/drawer.h @@ -25,13 +25,13 @@ typedef struct { void panel_drawer_create (PanelToplevel *toplevel, int position, - const char *custom_icon, + GIcon *custom_icon, gboolean use_custom_icon, const char *tooltip); char *panel_drawer_create_with_id (const char *toplevel_id, int position, - const char *custom_icon, + GIcon *custom_icon, gboolean use_custom_icon, const char *tooltip); diff --git a/mate-panel/menu.c b/mate-panel/menu.c index 28c588ac..975eeb38 100644 --- a/mate-panel/menu.c +++ b/mate-panel/menu.c @@ -265,28 +265,28 @@ static void add_drawers_from_alias (MateMenuTreeAlias *alias, const char *toplevel_id) { - MateMenuTreeItem *aliased_item; + gpointer item; - aliased_item = matemenu_tree_alias_get_item (alias); - - switch (matemenu_tree_item_get_type (aliased_item)) { + switch (matemenu_tree_alias_get_aliased_item_type (alias)) { case MATEMENU_TREE_ITEM_DIRECTORY: - add_drawers_from_dir (MATEMENU_TREE_DIRECTORY (aliased_item), + item = matemenu_tree_alias_get_directory (alias); + add_drawers_from_dir (item, G_MAXINT/2, toplevel_id); + matemenu_tree_item_unref (item); break; case MATEMENU_TREE_ITEM_ENTRY: + item = matemenu_tree_alias_get_aliased_entry (alias); panel_launcher_create_with_id (toplevel_id, G_MAXINT/2, - matemenu_tree_entry_get_desktop_file_path (MATEMENU_TREE_ENTRY (aliased_item))); + matemenu_tree_entry_get_desktop_file_path (item)); + matemenu_tree_item_unref (item); break; default: break; } - - matemenu_tree_item_unref (aliased_item); } static void @@ -295,10 +295,10 @@ add_drawers_from_dir (MateMenuTreeDirectory *directory, const char *toplevel_id) { const char *name; - const char *icon; - GSList *items; - GSList *l; + GIcon *icon; char *attached_toplevel_id; + MateMenuTreeIter *iter; + MateMenuTreeItemType type; name = matemenu_tree_directory_get_name (directory); icon = matemenu_tree_directory_get_icon (directory); @@ -311,36 +311,36 @@ add_drawers_from_dir (MateMenuTreeDirectory *directory, if (!attached_toplevel_id) return; - items = matemenu_tree_directory_get_contents (directory); - for (l = items; l; l = l->next) { - MateMenuTreeItem *item = l->data; - - switch (matemenu_tree_item_get_type (item)) { - case MATEMENU_TREE_ITEM_ENTRY: - panel_launcher_create_with_id (attached_toplevel_id, - G_MAXINT/2, - matemenu_tree_entry_get_desktop_file_path (MATEMENU_TREE_ENTRY (item))); - break; - - case MATEMENU_TREE_ITEM_DIRECTORY: - add_drawers_from_dir (MATEMENU_TREE_DIRECTORY (item), - G_MAXINT/2, - attached_toplevel_id); - break; - - case MATEMENU_TREE_ITEM_ALIAS: - add_drawers_from_alias (MATEMENU_TREE_ALIAS (item), attached_toplevel_id); - break; - - default: - break; + iter = matemenu_tree_directory_iter (directory); + while ((type = matemenu_tree_iter_next (iter)) != MATEMENU_TREE_ITEM_INVALID) { + gpointer item; + switch (type) { + case MATEMENU_TREE_ITEM_ENTRY: + item = matemenu_tree_iter_get_entry (iter); + panel_launcher_create_with_id (attached_toplevel_id, + G_MAXINT/2, + matemenu_tree_entry_get_desktop_file_path (item)); + matemenu_tree_item_unref (item); + break; + + case MATEMENU_TREE_ITEM_DIRECTORY: + item = matemenu_tree_iter_get_directory (iter); + add_drawers_from_dir (item, + G_MAXINT/2, + attached_toplevel_id); + matemenu_tree_item_unref (item); + break; + + case MATEMENU_TREE_ITEM_ALIAS: + item = matemenu_tree_iter_get_alias (iter); + add_drawers_from_alias (item, attached_toplevel_id); + matemenu_tree_item_unref (item); + break; + default: + break; } - - matemenu_tree_item_unref (item); } - - g_slist_free (items); - + matemenu_tree_iter_unref (iter); g_free (attached_toplevel_id); } @@ -354,7 +354,7 @@ add_menudrawer_to_panel (GtkWidget *menuitem, PanelData *pd; int insertion_pos; - directory = matemenu_tree_item_get_parent (MATEMENU_TREE_ITEM (entry)); + directory = matemenu_tree_entry_get_parent (entry); panel = menu_get_panel (menuitem); @@ -380,7 +380,7 @@ add_menu_to_panel (GtkWidget *menuitem, char *menu_path; const char *menu_filename; - directory = matemenu_tree_item_get_parent (MATEMENU_TREE_ITEM (entry)); + directory = matemenu_tree_entry_get_parent (entry); if (!directory) { g_warning ("Cannot find the filename for the menu: no directory"); return; @@ -393,8 +393,8 @@ add_menu_to_panel (GtkWidget *menuitem, return; } - menu_filename = matemenu_tree_get_menu_file (tree); - matemenu_tree_unref (tree); + menu_filename = matemenu_tree_get_canonical_menu_path (tree); + g_object_unref (tree); if (!menu_filename) { matemenu_tree_item_unref (directory); g_warning ("Cannot find the filename for the menu: no filename"); @@ -476,7 +476,7 @@ create_item_context_menu (GtkWidget *item, if (!entry) return NULL; - directory = matemenu_tree_item_get_parent (MATEMENU_TREE_ITEM (entry)); + directory = matemenu_tree_entry_get_parent (entry); if (!directory) return NULL; @@ -485,8 +485,8 @@ create_item_context_menu (GtkWidget *item, if (!tree) return NULL; - menu_filename = matemenu_tree_get_menu_file (tree); - matemenu_tree_unref (tree); + menu_filename = matemenu_tree_get_canonical_menu_path(tree); + g_object_unref (tree); if (!menu_filename) return NULL; @@ -726,7 +726,7 @@ setup_menuitem_with_icon (GtkWidget *menuitem, icon = panel_gicon_from_icon_name (image_filename); gtk_image_set_from_gicon (GTK_IMAGE(image), icon, icon_size); - g_object_unref (icon); + g_clear_object (&icon); gtk_widget_show (image); @@ -980,8 +980,8 @@ create_submenu_entry (GtkWidget *menu, setup_menuitem_with_icon (menuitem, panel_menu_icon_get_size (), - NULL, matemenu_tree_directory_get_icon (directory), + NULL, matemenu_tree_directory_get_name (directory)); gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); @@ -1051,7 +1051,7 @@ create_menuitem (GtkWidget *menu, matemenu_tree_item_ref (entry), (GDestroyNotify) matemenu_tree_item_unref); - if (alias_directory) + if (alias_directory) { //FIXME: we should probably use this data when we do dnd or //context menu for this menu item g_object_set_data_full (G_OBJECT (menuitem), @@ -1059,26 +1059,35 @@ create_menuitem (GtkWidget *menu, matemenu_tree_item_ref (alias_directory), (GDestroyNotify) matemenu_tree_item_unref); - setup_menuitem_with_icon (menuitem, - panel_menu_icon_get_size (), - NULL, - alias_directory ? matemenu_tree_directory_get_icon (alias_directory) : - matemenu_tree_entry_get_icon (entry), - alias_directory ? matemenu_tree_directory_get_name (alias_directory) : - matemenu_tree_entry_get_display_name (entry)); - - if (alias_directory && - matemenu_tree_directory_get_comment (alias_directory)) - panel_util_set_tooltip_text (menuitem, - matemenu_tree_directory_get_comment (alias_directory)); - else if (!alias_directory && - matemenu_tree_entry_get_comment (entry)) - panel_util_set_tooltip_text (menuitem, - matemenu_tree_entry_get_comment (entry)); - else if (!alias_directory && - matemenu_tree_entry_get_generic_name (entry)) - panel_util_set_tooltip_text (menuitem, - matemenu_tree_entry_get_generic_name (entry)); + setup_menuitem_with_icon (menuitem, + panel_menu_icon_get_size (), + matemenu_tree_directory_get_icon (alias_directory), + NULL, + matemenu_tree_directory_get_name (alias_directory)); + if (matemenu_tree_directory_get_comment (alias_directory)) { + panel_util_set_tooltip_text (menuitem, matemenu_tree_directory_get_comment (alias_directory)); + } + } else { + GDesktopAppInfo *ginfo; + const gchar* desc; + const gchar* gename; + + ginfo = matemenu_tree_entry_get_app_info (entry); + desc= g_app_info_get_description(G_APP_INFO(ginfo)); + gename = g_desktop_app_info_get_generic_name(ginfo); + + setup_menuitem_with_icon (menuitem, + panel_menu_icon_get_size (), + g_app_info_get_icon(G_APP_INFO(ginfo)), + NULL, + g_app_info_get_name(G_APP_INFO(ginfo))); + + if (desc != NULL) { + panel_util_set_tooltip_text (menuitem, desc); + } else if ( gename != NULL) { + panel_util_set_tooltip_text (menuitem, gename); + } + } g_signal_connect_after (menuitem, "button_press_event", G_CALLBACK (menuitem_button_press_event), NULL); @@ -1093,12 +1102,12 @@ create_menuitem (GtkWidget *menu, menu_item_targets, 1, GDK_ACTION_COPY); - if (matemenu_tree_entry_get_icon (entry) != NULL) { - const char *icon; + GDesktopAppInfo *ginfo; + ginfo = matemenu_tree_entry_get_app_info (entry); + if (g_app_info_get_icon (G_APP_INFO(ginfo)) != NULL) { GIcon *gicon; - icon = matemenu_tree_entry_get_icon (entry); - gicon = panel_gicon_from_icon_name (icon); + gicon = g_app_info_get_icon (G_APP_INFO(ginfo)); if (gicon != NULL) { gtk_drag_source_set_icon_gicon (menuitem, gicon); } @@ -1124,34 +1133,33 @@ static void create_menuitem_from_alias (GtkWidget *menu, MateMenuTreeAlias *alias) { - MateMenuTreeItem *aliased_item; - - aliased_item = matemenu_tree_alias_get_item (alias); + gpointer item, entry; - switch (matemenu_tree_item_get_type (aliased_item)) { + switch (matemenu_tree_alias_get_aliased_item_type (alias)) { case MATEMENU_TREE_ITEM_DIRECTORY: - create_submenu (menu, - MATEMENU_TREE_DIRECTORY (aliased_item), - matemenu_tree_alias_get_directory (alias)); + item = matemenu_tree_alias_get_directory (alias); + create_submenu (menu, item, item); + matemenu_tree_item_unref (item); break; case MATEMENU_TREE_ITEM_ENTRY: - create_menuitem (menu, - MATEMENU_TREE_ENTRY (aliased_item), - matemenu_tree_alias_get_directory (alias)); + entry = matemenu_tree_alias_get_aliased_entry(alias); + item = matemenu_tree_alias_get_directory (alias); + create_menuitem (menu, entry, item); + matemenu_tree_item_unref (entry); + matemenu_tree_item_unref (item); break; default: break; } - - matemenu_tree_item_unref (aliased_item); } static void handle_matemenu_tree_changed (MateMenuTree *tree, GtkWidget *menu) { + GError *error = NULL; guint idle_id; GList *list, *l; @@ -1160,6 +1168,11 @@ handle_matemenu_tree_changed (MateMenuTree *tree, gtk_widget_destroy (l->data); g_list_free (list); + if (! matemenu_tree_load_sync (tree, &error)) { + g_warning("Menu tree reload got error:%s\n", error->message); + g_error_free(error); + } + g_object_set_data_full (G_OBJECT (menu), "panel-menu-tree-directory", NULL, NULL); @@ -1180,11 +1193,11 @@ handle_matemenu_tree_changed (MateMenuTree *tree, static void remove_matemenu_tree_monitor (GtkWidget *menu, - MateMenuTree *tree) + MateMenuTree *tree) { - matemenu_tree_remove_monitor (tree, - (MateMenuTreeChangedFunc) handle_matemenu_tree_changed, - menu); + g_signal_handlers_disconnect_by_func (tree, + G_CALLBACK (handle_matemenu_tree_changed), + menu); } GtkWidget * @@ -1195,6 +1208,7 @@ create_applications_menu (const char *menu_file, MateMenuTree *tree; GtkWidget *menu; guint idle_id; + GError *error = NULL; menu = create_empty_menu (); @@ -1203,13 +1217,18 @@ create_applications_menu (const char *menu_file, "panel-menu-force-icon-for-categories", GINT_TO_POINTER (TRUE)); - tree = matemenu_tree_lookup (menu_file, MATEMENU_TREE_FLAGS_NONE); - matemenu_tree_set_sort_key (tree, MATEMENU_TREE_SORT_DISPLAY_NAME); + tree = matemenu_tree_new (menu_file, MATEMENU_TREE_FLAGS_SORT_DISPLAY_NAME); + if (! matemenu_tree_load_sync (tree, &error)) { + g_warning("Menu tree loading got error:%s\n", error->message); + g_error_free(error); + g_object_unref(tree); + tree = NULL; + } g_object_set_data_full (G_OBJECT (menu), "panel-menu-tree", - matemenu_tree_ref (tree), - (GDestroyNotify) matemenu_tree_unref); + g_object_ref(tree), + (GDestroyNotify) g_object_unref); g_object_set_data_full (G_OBJECT (menu), "panel-menu-tree-path", @@ -1235,13 +1254,10 @@ create_applications_menu (const char *menu_file, g_signal_connect (menu, "button_press_event", G_CALLBACK (menu_dummy_button_press_event), NULL); - matemenu_tree_add_monitor (tree, - (MateMenuTreeChangedFunc) handle_matemenu_tree_changed, - menu); - g_signal_connect (menu, "destroy", - G_CALLBACK (remove_matemenu_tree_monitor), tree); + g_signal_connect (tree, "changed", G_CALLBACK (handle_matemenu_tree_changed), menu); + g_signal_connect (menu, "destroy", G_CALLBACK (remove_matemenu_tree_monitor), tree); - matemenu_tree_unref (tree); + g_object_unref(tree); /*HACK Fix any failures of compiz/other wm's to communicate with gtk for transparency */ GtkWidget *toplevel = gtk_widget_get_toplevel (menu); @@ -1257,54 +1273,55 @@ populate_menu_from_directory (GtkWidget *menu, MateMenuTreeDirectory *directory) { GList *children; - GSList *l; - GSList *items; gboolean add_separator; + MateMenuTreeIter *iter; + MateMenuTreeItemType type; children = gtk_container_get_children (GTK_CONTAINER (menu)); add_separator = (children != NULL); g_list_free (children); - items = matemenu_tree_directory_get_contents (directory); - - for (l = items; l; l = l->next) { - MateMenuTreeItem *item = l->data; - - if (add_separator || - matemenu_tree_item_get_type (item) == MATEMENU_TREE_ITEM_SEPARATOR) { + iter = matemenu_tree_directory_iter (directory); + while ((type = matemenu_tree_iter_next (iter)) != MATEMENU_TREE_ITEM_INVALID) { + gpointer item; + if (add_separator || type == MATEMENU_TREE_ITEM_SEPARATOR) { add_menu_separator (menu); add_separator = FALSE; } - - switch (matemenu_tree_item_get_type (item)) { - case MATEMENU_TREE_ITEM_DIRECTORY: - create_submenu (menu, MATEMENU_TREE_DIRECTORY (item), NULL); - break; - - case MATEMENU_TREE_ITEM_ENTRY: - create_menuitem (menu, MATEMENU_TREE_ENTRY (item), NULL); - break; - - case MATEMENU_TREE_ITEM_SEPARATOR : - /* already added */ - break; - - case MATEMENU_TREE_ITEM_ALIAS: - create_menuitem_from_alias (menu, MATEMENU_TREE_ALIAS (item)); - break; - - case MATEMENU_TREE_ITEM_HEADER: - create_header (menu, MATEMENU_TREE_HEADER (item)); - break; - - default: - break; + switch (type) { + case MATEMENU_TREE_ITEM_DIRECTORY: + item = matemenu_tree_iter_get_directory(iter); + create_submenu (menu, item, NULL); + matemenu_tree_item_unref (item); + break; + + case MATEMENU_TREE_ITEM_ENTRY: + item = matemenu_tree_iter_get_entry (iter); + create_menuitem (menu, item, NULL); + matemenu_tree_item_unref (item); + break; + + case MATEMENU_TREE_ITEM_SEPARATOR : + /* already added */ + break; + + case MATEMENU_TREE_ITEM_ALIAS: + item = matemenu_tree_iter_get_alias(iter); + create_menuitem_from_alias (menu, item); + matemenu_tree_item_unref (item); + break; + + case MATEMENU_TREE_ITEM_HEADER: + item = matemenu_tree_iter_get_header(iter); + create_header (menu, item); + matemenu_tree_item_unref (item); + break; + + default: + break; } - - matemenu_tree_item_unref (item); } - - g_slist_free (items); + matemenu_tree_iter_unref (iter); return menu; } diff --git a/mate-panel/panel-addto.c b/mate-panel/panel-addto.c index 98064220..dfebba26 100644 --- a/mate-panel/panel-addto.c +++ b/mate-panel/panel-addto.c @@ -517,13 +517,15 @@ panel_addto_prepend_directory (GSList **parent_list, const char *filename) { PanelAddtoAppList *data; + GIcon *gicon; data = g_new0 (PanelAddtoAppList, 1); + gicon = matemenu_tree_directory_get_icon (directory); data->item_info.type = PANEL_ADDTO_MENU; data->item_info.name = g_strdup (matemenu_tree_directory_get_name (directory)); data->item_info.description = g_strdup (matemenu_tree_directory_get_comment (directory)); - data->item_info.icon = g_strdup (matemenu_tree_directory_get_icon (directory)); + data->item_info.icon = gicon ? g_icon_to_string(gicon) : g_strdup(PANEL_ICON_UNKNOWN); data->item_info.menu_filename = g_strdup (filename); data->item_info.menu_path = matemenu_tree_directory_make_path (directory, NULL); data->item_info.static_data = FALSE; @@ -547,13 +549,18 @@ panel_addto_prepend_entry (GSList **parent_list, const char *filename) { PanelAddtoAppList *data; + GDesktopAppInfo *ginfo; + GIcon *gicon; + + ginfo = matemenu_tree_entry_get_app_info (entry); + gicon = g_app_info_get_icon(G_APP_INFO(ginfo)); data = g_new0 (PanelAddtoAppList, 1); data->item_info.type = PANEL_ADDTO_LAUNCHER; - data->item_info.name = g_strdup (matemenu_tree_entry_get_display_name (entry)); - data->item_info.description = g_strdup (matemenu_tree_entry_get_comment (entry)); - data->item_info.icon = g_strdup (matemenu_tree_entry_get_icon (entry)); + data->item_info.name = g_strdup (g_app_info_get_display_name(G_APP_INFO(ginfo))); + data->item_info.description = g_strdup (g_app_info_get_description(G_APP_INFO(ginfo))); + data->item_info.icon = gicon ? g_icon_to_string(gicon) : g_strdup(PANEL_ICON_UNKNOWN); data->item_info.launcher_path = g_strdup (matemenu_tree_entry_get_desktop_file_path (entry)); data->item_info.static_data = FALSE; @@ -565,28 +572,28 @@ panel_addto_prepend_alias (GSList **parent_list, MateMenuTreeAlias *alias, const char *filename) { - MateMenuTreeItem *aliased_item; - - aliased_item = matemenu_tree_alias_get_item (alias); + gpointer item; - switch (matemenu_tree_item_get_type (aliased_item)) { + switch (matemenu_tree_alias_get_aliased_item_type (alias)) { case MATEMENU_TREE_ITEM_DIRECTORY: + item = matemenu_tree_alias_get_directory(alias); panel_addto_prepend_directory (parent_list, - MATEMENU_TREE_DIRECTORY (aliased_item), - filename); + item, + filename); + matemenu_tree_item_unref (item); break; case MATEMENU_TREE_ITEM_ENTRY: + item = matemenu_tree_alias_get_aliased_entry(alias); panel_addto_prepend_entry (parent_list, - MATEMENU_TREE_ENTRY (aliased_item), - filename); + item, + filename); + matemenu_tree_item_unref (item); break; default: break; } - - matemenu_tree_item_unref (aliased_item); } static void @@ -594,33 +601,34 @@ panel_addto_make_application_list (GSList **parent_list, MateMenuTreeDirectory *directory, const char *filename) { - GSList *items; - GSList *l; - - items = matemenu_tree_directory_get_contents (directory); - - for (l = items; l; l = l->next) { - switch (matemenu_tree_item_get_type (l->data)) { + MateMenuTreeIter *iter; + iter = matemenu_tree_directory_iter (directory); + MateMenuTreeItemType type; + while ((type = matemenu_tree_iter_next (iter)) != MATEMENU_TREE_ITEM_INVALID) { + gpointer item; + switch (type) { case MATEMENU_TREE_ITEM_DIRECTORY: - panel_addto_prepend_directory (parent_list, l->data, filename); + item = matemenu_tree_iter_get_directory(iter); + panel_addto_prepend_directory (parent_list, item, filename); + matemenu_tree_item_unref (item); break; case MATEMENU_TREE_ITEM_ENTRY: - panel_addto_prepend_entry (parent_list, l->data, filename); + item = matemenu_tree_iter_get_entry (iter); + panel_addto_prepend_entry (parent_list, item, filename); + matemenu_tree_item_unref (item); break; case MATEMENU_TREE_ITEM_ALIAS: - panel_addto_prepend_alias (parent_list, l->data, filename); + item = matemenu_tree_iter_get_alias(iter); + panel_addto_prepend_alias (parent_list, item, filename); + matemenu_tree_item_unref (item); break; - default: break; } - - matemenu_tree_item_unref (l->data); } - - g_slist_free (items); + matemenu_tree_iter_unref (iter); *parent_list = g_slist_reverse (*parent_list); } @@ -662,16 +670,21 @@ static void panel_addto_make_application_model(PanelAddtoDialog* dialog) GtkTreeStore* store; MateMenuTree* tree; MateMenuTreeDirectory* root; + GError *error = NULL; if (dialog->filter_application_model != NULL) return; store = gtk_tree_store_new(NUMBER_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_STRING); - tree = matemenu_tree_lookup("mate-applications.menu", MATEMENU_TREE_FLAGS_NONE); - matemenu_tree_set_sort_key(tree, MATEMENU_TREE_SORT_DISPLAY_NAME); + tree = matemenu_tree_new ("mate-applications.menu", MATEMENU_TREE_FLAGS_SORT_DISPLAY_NAME); + if (! matemenu_tree_load_sync (tree, &error)) { + g_warning("Applications menu tree loading got error:%s\n", error->message); + g_error_free(error); + g_clear_object(&tree); + } - if ((root = matemenu_tree_get_root_directory (tree))) + if ((root = matemenu_tree_get_root_directory (tree)) != NULL ) { panel_addto_make_application_list(&dialog->application_list, root, "mate-applications.menu"); panel_addto_populate_application_model(store, NULL, dialog->application_list); @@ -679,10 +692,14 @@ static void panel_addto_make_application_model(PanelAddtoDialog* dialog) matemenu_tree_item_unref(root); } - matemenu_tree_unref(tree); + g_clear_object(&tree); - tree = matemenu_tree_lookup("mate-settings.menu", MATEMENU_TREE_FLAGS_NONE); - matemenu_tree_set_sort_key(tree, MATEMENU_TREE_SORT_DISPLAY_NAME); + tree = matemenu_tree_new ("mate-settings.menu", MATEMENU_TREE_FLAGS_SORT_DISPLAY_NAME); + if (! matemenu_tree_load_sync (tree, &error)) { + g_warning("Settings menu tree loading got error:%s\n", error->message); + g_error_free(error); + g_clear_object(&tree); + } if ((root = matemenu_tree_get_root_directory(tree))) { @@ -697,7 +714,7 @@ static void panel_addto_make_application_model(PanelAddtoDialog* dialog) matemenu_tree_item_unref(root); } - matemenu_tree_unref(tree); + g_object_unref(tree); dialog->application_model = GTK_TREE_MODEL(store); dialog->filter_application_model = gtk_tree_model_filter_new(GTK_TREE_MODEL(dialog->application_model), NULL); @@ -970,9 +987,7 @@ panel_addto_dialog_free (PanelAddtoDialog *dialog) g_object_unref (dialog->application_model); dialog->application_model = NULL; - if (dialog->menu_tree) - matemenu_tree_unref (dialog->menu_tree); - dialog->menu_tree = NULL; + g_clear_object (&dialog->menu_tree); g_free (dialog); } diff --git a/mate-panel/panel-menu-button.c b/mate-panel/panel-menu-button.c index b111edff..9f57d139 100644 --- a/mate-panel/panel-menu-button.c +++ b/mate-panel/panel-menu-button.c @@ -716,8 +716,12 @@ panel_menu_button_get_icon (PanelMenuButton *button) } } - if (directory) - retval = g_strdup (matemenu_tree_directory_get_icon (directory)); + if (directory) { + GIcon *gicon; + gicon = matemenu_tree_directory_get_icon (directory); + if (gicon != NULL) + retval = g_icon_to_string(gicon); + } } if (!retval) diff --git a/mate-panel/panel-run-dialog.c b/mate-panel/panel-run-dialog.c index bb7172c7..5a0b55b7 100644 --- a/mate-panel/panel-run-dialog.c +++ b/mate-panel/panel-run-dialog.c @@ -725,7 +725,8 @@ panel_run_dialog_find_command_idle (PanelRunDialog *dialog) } g_free (exec); - g_object_unref (icon); + if (icon != NULL) + g_object_unref (icon); g_free (name); g_free (comment); @@ -755,8 +756,17 @@ static int compare_applications (MateMenuTreeEntry *a, MateMenuTreeEntry *b) { - return g_utf8_collate (matemenu_tree_entry_get_display_name (a), - matemenu_tree_entry_get_display_name (b)); + GDesktopAppInfo *infoa, *infob; + const gchar* name1; + const gchar* name2; + gint compare; + + infoa = matemenu_tree_entry_get_app_info (a); + infob = matemenu_tree_entry_get_app_info (b); + name1 = g_app_info_get_name(G_APP_INFO(infoa)); + name2 = g_app_info_get_name(G_APP_INFO(infob)); + compare = g_utf8_collate(name1, name2); + return compare; } static GSList *get_all_applications_from_dir (MateMenuTreeDirectory *directory, @@ -766,26 +776,20 @@ static GSList * get_all_applications_from_alias (MateMenuTreeAlias *alias, GSList *list) { - MateMenuTreeItem *aliased_item; - - aliased_item = matemenu_tree_alias_get_item (alias); - - switch (matemenu_tree_item_get_type (aliased_item)) { - case MATEMENU_TREE_ITEM_ENTRY: - list = g_slist_append (list, matemenu_tree_item_ref (aliased_item)); - break; - - case MATEMENU_TREE_ITEM_DIRECTORY: - list = get_all_applications_from_dir (MATEMENU_TREE_DIRECTORY (aliased_item), - list); - break; - - default: - break; + gpointer item; + switch (matemenu_tree_alias_get_aliased_item_type (alias)) { + case MATEMENU_TREE_ITEM_ENTRY: + item = matemenu_tree_alias_get_aliased_entry (alias); + list = g_slist_append (list, (MateMenuTreeEntry*) item); + break; + case MATEMENU_TREE_ITEM_DIRECTORY: + item = matemenu_tree_alias_get_aliased_directory (alias); + list = get_all_applications_from_dir ((MateMenuTreeDirectory*) item, list); + matemenu_tree_item_unref(item); + break; + default: + break; } - - matemenu_tree_item_unref (aliased_item); - return list; } @@ -793,34 +797,35 @@ static GSList * get_all_applications_from_dir (MateMenuTreeDirectory *directory, GSList *list) { - GSList *items; - GSList *l; - - items = matemenu_tree_directory_get_contents (directory); - - for (l = items; l; l = l->next) { - switch (matemenu_tree_item_get_type (l->data)) { - case MATEMENU_TREE_ITEM_ENTRY: - list = g_slist_append (list, matemenu_tree_item_ref (l->data)); - break; - - case MATEMENU_TREE_ITEM_DIRECTORY: - list = get_all_applications_from_dir (l->data, list); - break; - - case MATEMENU_TREE_ITEM_ALIAS: - list = get_all_applications_from_alias (l->data, list); - break; - - default: - break; + MateMenuTreeIter *iter; + MateMenuTreeItemType type; + + iter = matemenu_tree_directory_iter (directory); + while ((type = matemenu_tree_iter_next (iter)) != MATEMENU_TREE_ITEM_INVALID) { + gpointer item; + switch (type) { + case MATEMENU_TREE_ITEM_ENTRY: + item = matemenu_tree_iter_get_entry (iter); + list = g_slist_append (list, (MateMenuTreeEntry*) item); + break; + + case MATEMENU_TREE_ITEM_DIRECTORY: + item = matemenu_tree_iter_get_directory (iter); + list = get_all_applications_from_dir ((MateMenuTreeDirectory*)item, list); + matemenu_tree_item_unref(item); + break; + + case MATEMENU_TREE_ITEM_ALIAS: + item = matemenu_tree_iter_get_alias (iter); + list = get_all_applications_from_alias ((MateMenuTreeAlias *)item, list); + matemenu_tree_item_unref(item); + break; + + default: + break; } - - matemenu_tree_item_unref (l->data); } - - g_slist_free (items); - + matemenu_tree_iter_unref (iter); return list; } @@ -828,17 +833,27 @@ static GSList* get_all_applications(void) { MateMenuTree* tree; MateMenuTreeDirectory* root; + GError *error = NULL; GSList* retval; - tree = matemenu_tree_lookup("mate-applications.menu", MATEMENU_TREE_FLAGS_NONE); - matemenu_tree_set_sort_key(tree, MATEMENU_TREE_SORT_DISPLAY_NAME); + tree = matemenu_tree_new ("mate-applications.menu", MATEMENU_TREE_FLAGS_SORT_DISPLAY_NAME); + if (!matemenu_tree_load_sync (tree, &error)) { + g_printerr ("Failed to load tree: %s\n", error->message); + g_error_free(error); + g_object_unref(tree); + return NULL; + } - root = matemenu_tree_get_root_directory(tree); + root = matemenu_tree_get_root_directory (tree); + if (root == NULL){ + g_object_unref(tree); + return NULL; + } retval = get_all_applications_from_dir(root, NULL); matemenu_tree_item_unref(root); - matemenu_tree_unref(tree); + g_object_unref(tree); retval = g_slist_sort(retval, (GCompareFunc) compare_applications); @@ -874,8 +889,10 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog) const char *entry_name; next = l->next; + GDesktopAppInfo *ginfo; + ginfo = matemenu_tree_entry_get_app_info (entry); - entry_name = matemenu_tree_entry_get_display_name (entry); + entry_name = g_app_info_get_display_name(G_APP_INFO(ginfo)); if (prev_name && entry_name && strcmp (entry_name, prev_name) == 0) { matemenu_tree_item_unref (entry); @@ -888,24 +905,23 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog) for (l = all_applications; l; l = l->next) { MateMenuTreeEntry *entry = l->data; GtkTreeIter iter; - const gchar *icon = matemenu_tree_entry_get_icon (entry); - GIcon *gicon = panel_gicon_from_icon_name (icon); + GDesktopAppInfo *ginfo; + GIcon *gicon = NULL; + + ginfo = matemenu_tree_entry_get_app_info (entry); + gicon = g_app_info_get_icon(G_APP_INFO(ginfo)); gtk_list_store_append (dialog->program_list_store, &iter); gtk_list_store_set (dialog->program_list_store, &iter, COLUMN_GICON, gicon, - COLUMN_NAME, matemenu_tree_entry_get_display_name (entry), - COLUMN_COMMENT, matemenu_tree_entry_get_comment (entry), - COLUMN_EXEC, matemenu_tree_entry_get_exec (entry), + COLUMN_NAME, g_app_info_get_display_name(G_APP_INFO(ginfo)), + COLUMN_COMMENT, g_app_info_get_description(G_APP_INFO(ginfo)), + COLUMN_EXEC, g_app_info_get_commandline(G_APP_INFO(ginfo)), COLUMN_PATH, matemenu_tree_entry_get_desktop_file_path (entry), COLUMN_VISIBLE, TRUE, -1); - - g_object_unref (gicon); - - matemenu_tree_item_unref (entry); } - g_slist_free (all_applications); + g_slist_free_full (all_applications, matemenu_tree_item_unref); model_filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (dialog->program_list_store), NULL); @@ -990,6 +1006,7 @@ program_list_selection_changed (GtkTreeSelection *selection, gboolean terminal; GKeyFile *key_file; GtkWidget *entry; + GIcon *icon = NULL; if (!gtk_tree_selection_get_selected (selection, &filter_model, &filter_iter)) @@ -1041,9 +1058,10 @@ program_list_selection_changed (GtkTreeSelection *selection, g_free (temp); temp = panel_key_file_get_locale_string (key_file, "Icon"); - GIcon *icon = panel_gicon_from_icon_name (temp); + icon = panel_gicon_from_icon_name (temp); panel_run_dialog_set_icon (dialog, icon, FALSE); - g_object_unref (icon); + if (icon != NULL) + g_object_unref (icon); g_free (temp); temp = panel_key_file_get_locale_string (key_file, "Comment"); |