[gnome-panel] panel: Port to new gnome-menus API
- From: Vincent Untz <vuntz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel] panel: Port to new gnome-menus API
- Date: Mon, 1 Aug 2011 17:41:30 +0000 (UTC)
commit 7fb52d0c7dd322c40e840a6808727031638ae69b
Author: Colin Walters <walters verbum org>
Date: Tue May 3 17:49:40 2011 -0400
panel: Port to new gnome-menus API
This port is a bit suboptimal in that we call gmenu_tree_new()
in multiple places. But other than that, tested and appears to
work in a jhbuild on Fedora 14.
https://bugzilla.gnome.org/show_bug.cgi?id=649327
configure.ac | 2 +-
gnome-panel/menu.c | 140 ++++++++++---------
gnome-panel/panel-addto.c | 312 ++++++++++++++++++++++------------------
gnome-panel/panel-run-dialog.c | 81 ++++++-----
4 files changed, 290 insertions(+), 245 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 6cc1c97..74f9f7e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -64,7 +64,7 @@ GLIB_REQUIRED=2.25.12
GTK_REQUIRED=3.0
LIBWNCK_REQUIRED=2.91.0
GCONF_REQUIRED=2.6.1
-LIBGNOME_MENU_REQUIRED=2.27.92
+LIBGNOME_MENU_REQUIRED=4.0.0
TELEPATHY_GLIB_REQUIRED=0.14.0
LIBECAL_REQUIRED=2.91.2
LIBEDATASERVER_REQUIRED=2.91.2
diff --git a/gnome-panel/menu.c b/gnome-panel/menu.c
index 6cb104b..8f2dafb 100644
--- a/gnome-panel/menu.c
+++ b/gnome-panel/menu.c
@@ -1,4 +1,4 @@
-/*
+/* -*- c-basic-offset: 8; indent-tabs-mode: t -*-
* Copyright (C) 1997 - 2000 The Free Software Foundation
* Copyright (C) 2000 Helix Code, Inc.
* Copyright (C) 2000 Eazel, Inc.
@@ -1074,36 +1074,43 @@ create_menuitem (GtkWidget *menu,
menuitem = panel_image_menu_item_new ();
- panel_load_menu_image_deferred (menuitem,
- panel_menu_icon_get_size (),
- NULL, NULL,
- alias_directory ? gmenu_tree_directory_get_icon (alias_directory) :
- gmenu_tree_entry_get_icon (entry),
- NULL);
+ if (alias_directory)
+ panel_load_menu_image_deferred (menuitem,
+ panel_menu_icon_get_size (),
+ NULL, NULL,
+ gmenu_tree_directory_get_icon (alias_directory),
+ NULL);
+ else
+ panel_load_menu_image_deferred (menuitem,
+ panel_menu_icon_get_size (),
+ NULL, g_app_info_get_icon (G_APP_INFO (gmenu_tree_entry_get_app_info (entry))),
+ NULL, NULL);
setup_menuitem (menuitem,
panel_menu_icon_get_size (),
NULL,
alias_directory ? gmenu_tree_directory_get_name (alias_directory) :
- gmenu_tree_entry_get_display_name (entry));
+ g_app_info_get_display_name (G_APP_INFO (gmenu_tree_entry_get_app_info (entry))));
if (alias_directory &&
gmenu_tree_directory_get_comment (alias_directory))
panel_util_set_tooltip_text (menuitem,
gmenu_tree_directory_get_comment (alias_directory));
- else if (!alias_directory &&
- gmenu_tree_entry_get_comment (entry))
- panel_util_set_tooltip_text (menuitem,
- gmenu_tree_entry_get_comment (entry));
- else if (!alias_directory &&
- gmenu_tree_entry_get_generic_name (entry))
- panel_util_set_tooltip_text (menuitem,
- gmenu_tree_entry_get_generic_name (entry));
+ else if (!alias_directory) {
+ const char *description = g_app_info_get_description (G_APP_INFO (gmenu_tree_entry_get_app_info (entry)));
+ if (!description)
+ description = g_desktop_app_info_get_generic_name (gmenu_tree_entry_get_app_info (entry));
+ if (description)
+ panel_util_set_tooltip_text (menuitem,
+ description);
+ }
g_signal_connect_after (menuitem, "button_press_event",
G_CALLBACK (menu_dummy_button_press_event), NULL);
if (!panel_lockdown_get_panels_locked_down_s ()) {
+ GIcon *icon;
+
static GtkTargetEntry menu_item_targets[] = {
{ "text/uri-list", 0, 0 }
};
@@ -1113,17 +1120,9 @@ create_menuitem (GtkWidget *menu,
menu_item_targets, 1,
GDK_ACTION_COPY);
- if (gmenu_tree_entry_get_icon (entry) != NULL) {
- const char *icon;
- char *icon_no_ext;
-
- icon = gmenu_tree_entry_get_icon (entry);
- if (!g_path_is_absolute (icon)) {
- icon_no_ext = panel_xdg_icon_remove_extension (icon);
- gtk_drag_source_set_icon_name (menuitem,
- icon_no_ext);
- g_free (icon_no_ext);
- }
+ icon = g_app_info_get_icon (G_APP_INFO (gmenu_tree_entry_get_app_info (entry)));
+ if (icon != NULL) {
+ gtk_drag_source_set_icon_gicon (menuitem, icon);
}
g_signal_connect (G_OBJECT (menuitem), "drag_begin",
@@ -1146,28 +1145,31 @@ static void
create_menuitem_from_alias (GtkWidget *menu,
GMenuTreeAlias *alias)
{
- GMenuTreeItem *aliased_item;
-
- aliased_item = gmenu_tree_alias_get_item (alias);
-
- switch (gmenu_tree_item_get_type (aliased_item)) {
- case GMENU_TREE_ITEM_DIRECTORY:
+ GMenuTreeDirectory *src = gmenu_tree_alias_get_directory (alias);
+ switch (gmenu_tree_alias_get_item_type (alias)) {
+ case GMENU_TREE_ITEM_DIRECTORY: {
+ GMenuTreeDirectory *directory = gmenu_tree_alias_get_aliased_directory (alias);
create_submenu (menu,
- GMENU_TREE_DIRECTORY (aliased_item),
- gmenu_tree_alias_get_directory (alias));
+ directory,
+ src);
+ gmenu_tree_item_unref (directory);
break;
+ }
- case GMENU_TREE_ITEM_ENTRY:
+ case GMENU_TREE_ITEM_ENTRY: {
+ GMenuTreeEntry *entry = gmenu_tree_alias_get_aliased_entry (alias);
create_menuitem (menu,
- GMENU_TREE_ENTRY (aliased_item),
- gmenu_tree_alias_get_directory (alias));
+ entry,
+ src);
+ gmenu_tree_item_unref (entry);
break;
+ }
default:
break;
}
- gmenu_tree_item_unref (aliased_item);
+ gmenu_tree_item_unref (src);
}
static void
@@ -1205,9 +1207,9 @@ static void
remove_gmenu_tree_monitor (GtkWidget *menu,
GMenuTree *tree)
{
- gmenu_tree_remove_monitor (tree,
- (GMenuTreeChangedFunc) handle_gmenu_tree_changed,
- menu);
+ g_signal_handlers_disconnect_by_func (tree,
+ G_CALLBACK (handle_gmenu_tree_changed),
+ menu);
}
GtkWidget *
@@ -1218,6 +1220,7 @@ create_applications_menu (const char *menu_file,
GMenuTree *tree;
GtkWidget *menu;
guint idle_id;
+ GError *error = NULL;
menu = create_empty_menu ();
@@ -1226,13 +1229,18 @@ create_applications_menu (const char *menu_file,
"panel-menu-force-icon-for-categories",
GINT_TO_POINTER (TRUE));
- tree = gmenu_tree_lookup (menu_file, GMENU_TREE_FLAGS_NONE);
- gmenu_tree_set_sort_key (tree, GMENU_TREE_SORT_DISPLAY_NAME);
+ tree = gmenu_tree_new (menu_file, GMENU_TREE_FLAGS_NONE);
+
+ if (!gmenu_tree_load_sync (tree, &error)) {
+ g_warning ("Failed to load applications: %s", error->message);
+ g_clear_error (&error);
+ return menu;
+ }
g_object_set_data_full (G_OBJECT (menu),
"panel-menu-tree",
- gmenu_tree_ref (tree),
- (GDestroyNotify) gmenu_tree_unref);
+ g_object_ref (tree),
+ (GDestroyNotify) g_object_unref);
g_object_set_data_full (G_OBJECT (menu),
"panel-menu-tree-path",
@@ -1258,13 +1266,10 @@ create_applications_menu (const char *menu_file,
g_signal_connect (menu, "button_press_event",
G_CALLBACK (menu_dummy_button_press_event), NULL);
- gmenu_tree_add_monitor (tree,
- (GMenuTreeChangedFunc) handle_gmenu_tree_changed,
- menu);
- g_signal_connect (menu, "destroy",
- G_CALLBACK (remove_gmenu_tree_monitor), tree);
+ g_signal_connect (tree, "changed", G_CALLBACK (handle_gmenu_tree_changed), menu);
+ g_signal_connect (menu, "destroy", G_CALLBACK (remove_gmenu_tree_monitor), tree);
- gmenu_tree_unref (tree);
+ g_object_unref (tree);
return menu;
}
@@ -1274,32 +1279,34 @@ populate_menu_from_directory (GtkWidget *menu,
GMenuTreeDirectory *directory)
{
GList *children;
- GSList *l;
- GSList *items;
gboolean add_separator;
+ GMenuTreeIter *iter;
+ GMenuTreeItemType next_type;
children = gtk_container_get_children (GTK_CONTAINER (menu));
add_separator = (children != NULL);
g_list_free (children);
- items = gmenu_tree_directory_get_contents (directory);
+ iter = gmenu_tree_directory_iter (directory);
- for (l = items; l; l = l->next) {
- GMenuTreeItem *item = l->data;
+ while ((next_type = gmenu_tree_iter_next (iter)) != GMENU_TREE_ITEM_INVALID) {
+ gpointer item = NULL;
if (add_separator ||
- gmenu_tree_item_get_type (item) == GMENU_TREE_ITEM_SEPARATOR) {
+ next_type == GMENU_TREE_ITEM_SEPARATOR) {
add_menu_separator (menu);
add_separator = FALSE;
}
- switch (gmenu_tree_item_get_type (item)) {
+ switch (next_type) {
case GMENU_TREE_ITEM_DIRECTORY:
- create_submenu (menu, GMENU_TREE_DIRECTORY (item), NULL);
+ item = gmenu_tree_iter_get_directory (iter);
+ create_submenu (menu, item, NULL);
break;
case GMENU_TREE_ITEM_ENTRY:
- create_menuitem (menu, GMENU_TREE_ENTRY (item), NULL);
+ item = gmenu_tree_iter_get_entry (iter);
+ create_menuitem (menu, item, NULL);
break;
case GMENU_TREE_ITEM_SEPARATOR :
@@ -1307,21 +1314,24 @@ populate_menu_from_directory (GtkWidget *menu,
break;
case GMENU_TREE_ITEM_ALIAS:
- create_menuitem_from_alias (menu, GMENU_TREE_ALIAS (item));
+ item = gmenu_tree_iter_get_alias (iter);
+ create_menuitem_from_alias (menu, item);
break;
case GMENU_TREE_ITEM_HEADER:
- create_header (menu, GMENU_TREE_HEADER (item));
+ item = gmenu_tree_iter_get_header (iter);
+ create_header (menu, item);
break;
default:
break;
}
- gmenu_tree_item_unref (item);
+ if (item)
+ gmenu_tree_item_unref (item);
}
- g_slist_free (items);
+ gmenu_tree_iter_unref (iter);
return menu;
}
diff --git a/gnome-panel/panel-addto.c b/gnome-panel/panel-addto.c
index e5b1568..03d7f2d 100644
--- a/gnome-panel/panel-addto.c
+++ b/gnome-panel/panel-addto.c
@@ -1,4 +1,4 @@
-/*
+/* -*- c-basic-offset: 8; indent-tabs-mode: t -*-
* panel-addto.c:
*
* Copyright (C) 2004 Vincent Untz
@@ -95,7 +95,7 @@ typedef struct {
PanelAddtoItemType type;
char *name;
char *description;
- char *icon;
+ GIcon *icon;
PanelActionButtonType action_type;
char *launcher_path;
char *menu_filename;
@@ -109,80 +109,6 @@ typedef struct {
PanelAddtoItemInfo item_info;
} PanelAddtoAppList;
-static PanelAddtoItemInfo special_addto_items [] = {
-
- { PANEL_ADDTO_LAUNCHER_NEW,
- N_("Custom Application Launcher"),
- N_("Create a new launcher"),
- PANEL_ICON_LAUNCHER,
- PANEL_ACTION_NONE,
- NULL,
- NULL,
- NULL,
- "LAUNCHER:ASK",
- TRUE },
-
- { PANEL_ADDTO_LAUNCHER_MENU,
- N_("Application Launcher..."),
- N_("Copy a launcher from the applications menu"),
- PANEL_ICON_LAUNCHER,
- PANEL_ACTION_NONE,
- NULL,
- NULL,
- NULL,
- "LAUNCHER:MENU",
- TRUE }
-
-};
-
-static PanelAddtoItemInfo internal_addto_items [] = {
-
- { PANEL_ADDTO_MENU,
- N_("Main Menu"),
- N_("The main GNOME menu"),
- PANEL_ICON_MAIN_MENU,
- PANEL_ACTION_NONE,
- NULL,
- NULL,
- NULL,
- "MENU:MAIN",
- TRUE },
-
- { PANEL_ADDTO_MENUBAR,
- N_("Menu Bar"),
- N_("A custom menu bar"),
- PANEL_ICON_MAIN_MENU,
- PANEL_ACTION_NONE,
- NULL,
- NULL,
- NULL,
- "MENUBAR:NEW",
- TRUE },
-
- { PANEL_ADDTO_SEPARATOR,
- N_("Separator"),
- N_("A separator to organize the panel items"),
- PANEL_ICON_SEPARATOR,
- PANEL_ACTION_NONE,
- NULL,
- NULL,
- NULL,
- "SEPARATOR:NEW",
- TRUE },
-
- { PANEL_ADDTO_USER_MENU,
- N_("User Menu"),
- N_("Menu to change your settings and your online status"),
- PANEL_ICON_USER_AVAILABLE,
- PANEL_ACTION_NONE,
- NULL,
- NULL,
- NULL,
- "USERMENU:NEW",
- TRUE }
-
-};
-
enum {
COLUMN_ICON,
COLUMN_TEXT,
@@ -209,23 +135,74 @@ panel_addto_applet_info_sort_func (PanelAddtoItemInfo *a,
return g_utf8_collate (a->name, b->name);
}
+static PanelAddtoItemInfo *
+get_internal_applets (void)
+{
+ static PanelAddtoItemInfo *internals = NULL;
+ const int n_internals = 4;
+ int i;
+
+ if (internals != NULL)
+ return internals;
+
+
+ internals = g_new0 (PanelAddtoItemInfo, n_internals + 1);
+ i = 0;
+
+ internals[i].type = PANEL_ADDTO_MENU;
+ internals[i].name = _("Main Menu");
+ internals[i].description = _("The main GNOME menu");
+ internals[i].icon = g_themed_icon_new (PANEL_ICON_MAIN_MENU);
+ internals[i].action_type = PANEL_ACTION_NONE;
+ internals[i].iid = "MENU:MAIN";
+ internals[i].static_data = TRUE;
+
+ i++;
+ internals[i].type = PANEL_ADDTO_MENUBAR;
+ internals[i].name = _("Menu Bar");
+ internals[i].description = _("A custom menu bar");
+ internals[i].icon = g_themed_icon_new (PANEL_ICON_MAIN_MENU);
+ internals[i].action_type = PANEL_ACTION_NONE;
+ internals[i].iid = "MENUBAR:NEW";
+ internals[i].static_data = TRUE;
+
+ i++;
+ internals[i].type = PANEL_ADDTO_SEPARATOR;
+ internals[i].name = _("Separator");
+ internals[i].description = _("A separator to organize the panel items");
+ internals[i].icon = g_themed_icon_new (PANEL_ICON_SEPARATOR);
+ internals[i].action_type = PANEL_ACTION_NONE;
+ internals[i].iid = "SEPARATOR:NEW";
+ internals[i].static_data = TRUE;
+
+ i++;
+ internals[i].type = PANEL_ADDTO_USER_MENU;
+ internals[i].name = _("User menu");
+ internals[i].description = _("Menu to change your settings and your online status");
+ internals[i].icon = g_themed_icon_new (PANEL_ICON_USER_AVAILABLE);
+ internals[i].action_type = PANEL_ACTION_NONE;
+ internals[i].iid = "USERMENU:NEW";
+ internals[i].static_data = TRUE;
+
+ i++;
+ g_assert (i == n_internals);
+ internals[i].name = NULL;
+
+ return internals;
+}
+
static GSList *
panel_addto_prepend_internal_applets (GSList *list)
{
- static gboolean translated = FALSE;
+ PanelAddtoItemInfo *internal;
int i;
- for (i = 0; i < G_N_ELEMENTS (internal_addto_items); i++) {
- if (!translated) {
- internal_addto_items [i].name = _(internal_addto_items [i].name);
- internal_addto_items [i].description = _(internal_addto_items [i].description);
- }
+ internal = get_internal_applets ();
- list = g_slist_prepend (list, &internal_addto_items [i]);
+ for (; internal->name; internal++) {
+ list = g_slist_prepend (list, internal);
}
- translated = TRUE;
-
for (i = PANEL_ACTION_LOCK; i < PANEL_ACTION_LAST; i++) {
PanelAddtoItemInfo *info;
@@ -237,7 +214,7 @@ panel_addto_prepend_internal_applets (GSList *list)
info->action_type = i;
info->name = g_strdup (panel_action_get_text (i));
info->description = g_strdup (panel_action_get_tooltip (i));
- info->icon = g_strdup (panel_action_get_icon_name (i));
+ info->icon = g_themed_icon_new (panel_action_get_icon_name (i));
info->iid = g_strdup (panel_action_get_drag_id (i));
info->static_data = FALSE;
@@ -270,13 +247,19 @@ panel_addto_make_text (const char *name,
#define ICON_SIZE 32
static GdkPixbuf *
-panel_addto_make_pixbuf (const char *filename)
+panel_addto_make_pixbuf (GIcon *icon)
{
+ GtkIconInfo *icon_info;
+ GdkPixbuf *pixbuf;
+
//FIXME: size shouldn't be fixed but should depend on the font size
- return panel_load_icon (gtk_icon_theme_get_default (),
- filename,
- ICON_SIZE, ICON_SIZE, ICON_SIZE,
- NULL);
+ icon_info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
+ icon, ICON_SIZE, 0);
+ if (!icon_info)
+ return NULL;
+ pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
+ gtk_icon_info_free (icon_info);
+ return pixbuf;
}
static void
@@ -411,7 +394,7 @@ panel_addto_query_applets (GSList *list)
applet->type = PANEL_ADDTO_APPLET;
applet->name = g_strdup (name);
applet->description = g_strdup (description);
- applet->icon = g_strdup (icon);
+ applet->icon = g_themed_icon_new (icon);
applet->iid = g_strdup (iid);
applet->static_data = FALSE;
@@ -466,27 +449,55 @@ panel_addto_append_item (PanelAddtoDialog *dialog,
}
}
+static PanelAddtoItemInfo *
+get_special_items (void)
+{
+ static PanelAddtoItemInfo *specials = NULL;
+
+ if (!specials) {
+ const int n_specials = 2;
+ int i = 0;
+
+ specials = g_new0 (PanelAddtoItemInfo, n_specials + 1);
+
+ specials[i].type = PANEL_ADDTO_LAUNCHER_NEW;
+ specials[i].name = _("Custom Application Launcher");
+ specials[i].description = _("Create a new launcher");
+ specials[i].icon = g_themed_icon_new (PANEL_ICON_LAUNCHER);
+ specials[i].action_type = PANEL_ACTION_NONE;
+ specials[i].iid = "LAUNCHER:ASK";
+ specials[i].static_data = TRUE;
+
+ i++;
+ specials[i].type = PANEL_ADDTO_LAUNCHER_MENU;
+ specials[i].name = _("Application Launcher...");
+ specials[i].description = _("Copy a launcher from the applications menu");
+ specials[i].iid = "LAUNCHER:MENU";
+ specials[i].static_data = TRUE;
+
+ i++;
+ g_assert (i == n_specials);
+ specials[i].name = NULL;
+ }
+
+ return specials;
+}
+
static void
panel_addto_append_special_applets (PanelAddtoDialog *dialog,
GtkListStore *model)
{
- static gboolean translated = FALSE;
- int i;
-
- for (i = 0; i < G_N_ELEMENTS (special_addto_items); i++) {
- if (!translated) {
- special_addto_items [i].name = _(special_addto_items [i].name);
- special_addto_items [i].description = _(special_addto_items [i].description);
- }
+ PanelAddtoItemInfo *special;
- if (special_addto_items [i].type == PANEL_ADDTO_LAUNCHER_NEW
+ special = get_special_items ();
+
+ for (; special->name; special++) {
+ if (special->type == PANEL_ADDTO_LAUNCHER_NEW
&& panel_lockdown_get_disable_command_line_s ())
continue;
- panel_addto_append_item (dialog, model, &special_addto_items [i]);
+ panel_addto_append_item (dialog, model, special);
}
-
- translated = TRUE;
}
static void
@@ -553,7 +564,7 @@ panel_addto_prepend_directory (GSList **parent_list,
data->item_info.type = PANEL_ADDTO_MENU;
data->item_info.name = g_strdup (gmenu_tree_directory_get_name (directory));
data->item_info.description = g_strdup (gmenu_tree_directory_get_comment (directory));
- data->item_info.icon = g_strdup (gmenu_tree_directory_get_icon (directory));
+ data->item_info.icon = g_themed_icon_new (gmenu_tree_directory_get_icon (directory));
data->item_info.menu_filename = g_strdup (filename);
data->item_info.menu_path = gmenu_tree_directory_make_path (directory, NULL);
data->item_info.static_data = FALSE;
@@ -579,13 +590,16 @@ panel_addto_prepend_entry (GSList **parent_list,
const char *filename)
{
PanelAddtoAppList *data;
+ GDesktopAppInfo *app_info;
data = g_new0 (PanelAddtoAppList, 1);
+ app_info = gmenu_tree_entry_get_app_info (entry);
+
data->item_info.type = PANEL_ADDTO_LAUNCHER;
- data->item_info.name = g_strdup (gmenu_tree_entry_get_display_name (entry));
- data->item_info.description = g_strdup (gmenu_tree_entry_get_comment (entry));
- data->item_info.icon = g_strdup (gmenu_tree_entry_get_icon (entry));
+ data->item_info.name = g_strdup (g_app_info_get_display_name (G_APP_INFO (app_info)));
+ data->item_info.description = g_strdup (g_app_info_get_description (G_APP_INFO (app_info)));
+ data->item_info.icon = g_object_ref (g_app_info_get_icon (G_APP_INFO (app_info)));
data->item_info.launcher_path = g_strdup (gmenu_tree_entry_get_desktop_file_path (entry));
data->item_info.static_data = FALSE;
@@ -597,28 +611,26 @@ panel_addto_prepend_alias (GSList **parent_list,
GMenuTreeAlias *alias,
const char *filename)
{
- GMenuTreeItem *aliased_item;
-
- aliased_item = gmenu_tree_alias_get_item (alias);
-
- switch (gmenu_tree_item_get_type (aliased_item)) {
- case GMENU_TREE_ITEM_DIRECTORY:
+ switch (gmenu_tree_alias_get_item_type (alias)) {
+ case GMENU_TREE_ITEM_DIRECTORY: {
+ GMenuTreeDirectory *directory = gmenu_tree_alias_get_aliased_directory (alias);
panel_addto_prepend_directory (parent_list,
- GMENU_TREE_DIRECTORY (aliased_item),
+ directory,
filename);
+ gmenu_tree_item_unref (directory);
break;
-
- case GMENU_TREE_ITEM_ENTRY:
+ }
+ case GMENU_TREE_ITEM_ENTRY: {
+ GMenuTreeEntry *entry = gmenu_tree_alias_get_aliased_entry (alias);
panel_addto_prepend_entry (parent_list,
- GMENU_TREE_ENTRY (aliased_item),
+ entry,
filename);
+ gmenu_tree_item_unref (entry);
break;
-
+ }
default:
break;
}
-
- gmenu_tree_item_unref (aliased_item);
}
static void
@@ -627,36 +639,42 @@ panel_addto_make_application_list (GSList **parent_list,
const char *filename,
PanelAddtoMenuShowFlags show_flags)
{
- GSList *items;
- GSList *l;
+ GMenuTreeIter *iter;
+ GMenuTreeItemType next_type;
- items = gmenu_tree_directory_get_contents (directory);
+ iter = gmenu_tree_directory_iter (directory);
- for (l = items; l; l = l->next) {
- switch (gmenu_tree_item_get_type (l->data)) {
+ while ((next_type = gmenu_tree_iter_next (iter)) != GMENU_TREE_ITEM_INVALID) {
+ switch (next_type) {
case GMENU_TREE_ITEM_DIRECTORY:
- if (show_flags & PANEL_ADDTO_MENU_SHOW_DIRECTORIES)
- panel_addto_prepend_directory (parent_list, l->data, filename);
+ if (show_flags & PANEL_ADDTO_MENU_SHOW_DIRECTORIES) {
+ GMenuTreeDirectory *dir = gmenu_tree_iter_get_directory (iter);
+ panel_addto_prepend_directory (parent_list, dir, filename);
+ gmenu_tree_item_unref (dir);
+ }
break;
case GMENU_TREE_ITEM_ENTRY:
- if (show_flags & PANEL_ADDTO_MENU_SHOW_ENTRIES)
- panel_addto_prepend_entry (parent_list, l->data, filename);
+ if (show_flags & PANEL_ADDTO_MENU_SHOW_ENTRIES) {
+ GMenuTreeEntry *entry = gmenu_tree_iter_get_entry (iter);
+ panel_addto_prepend_entry (parent_list, entry, filename);
+ gmenu_tree_item_unref (entry);
+ }
break;
case GMENU_TREE_ITEM_ALIAS:
- if (show_flags & PANEL_ADDTO_MENU_SHOW_ALIAS)
- panel_addto_prepend_alias (parent_list, l->data, filename);
+ if (show_flags & PANEL_ADDTO_MENU_SHOW_ALIAS) {
+ GMenuTreeAlias *alias = gmenu_tree_iter_get_alias (iter);
+ panel_addto_prepend_alias (parent_list, alias, filename);
+ gmenu_tree_item_unref (alias);
+ }
break;
default:
break;
}
-
- gmenu_tree_item_unref (l->data);
}
-
- g_slist_free (items);
+ gmenu_tree_iter_unref (iter);
*parent_list = g_slist_reverse (*parent_list);
}
@@ -714,8 +732,12 @@ panel_addto_make_application_model (PanelAddtoDialog *dialog)
G_TYPE_POINTER,
G_TYPE_STRING);
- tree = gmenu_tree_lookup ("applications.menu", GMENU_TREE_FLAGS_NONE);
- gmenu_tree_set_sort_key (tree, GMENU_TREE_SORT_DISPLAY_NAME);
+ tree = gmenu_tree_new ("applications.menu", GMENU_TREE_FLAGS_NONE);
+
+ if (!gmenu_tree_load_sync (tree, NULL)) {
+ g_object_unref (tree);
+ return;
+ }
if ((root = gmenu_tree_get_root_directory (tree))) {
panel_addto_make_application_list (&dialog->application_list,
@@ -726,10 +748,14 @@ panel_addto_make_application_model (PanelAddtoDialog *dialog)
gmenu_tree_item_unref (root);
}
- gmenu_tree_unref (tree);
+ g_object_unref (tree);
- tree = gmenu_tree_lookup ("gnomecc.menu", GMENU_TREE_FLAGS_NONE);
- gmenu_tree_set_sort_key (tree, GMENU_TREE_SORT_DISPLAY_NAME);
+ tree = gmenu_tree_new ("gnomecc.menu", GMENU_TREE_FLAGS_NONE);
+
+ if (!gmenu_tree_load_sync (tree, NULL)) {
+ g_object_unref (tree);
+ return;
+ }
if ((root = gmenu_tree_get_root_directory (tree))) {
GtkTreeIter iter;
@@ -753,7 +779,7 @@ panel_addto_make_application_model (PanelAddtoDialog *dialog)
gmenu_tree_item_unref (root);
}
- gmenu_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),
@@ -1036,7 +1062,7 @@ panel_addto_dialog_free (PanelAddtoDialog *dialog)
dialog->application_model = NULL;
if (dialog->menu_tree)
- gmenu_tree_unref (dialog->menu_tree);
+ g_object_unref (dialog->menu_tree);
dialog->menu_tree = NULL;
g_free (dialog);
diff --git a/gnome-panel/panel-run-dialog.c b/gnome-panel/panel-run-dialog.c
index 81ee3fd..1e6d795 100644
--- a/gnome-panel/panel-run-dialog.c
+++ b/gnome-panel/panel-run-dialog.c
@@ -1,4 +1,4 @@
-/*
+/* -*- c-basic-offset: 8; indent-tabs-mode: t -*-
* panel-run-dialog.c:
*
* Copyright (C) 2003 Frank Worsley <fworsley shaw ca>
@@ -791,8 +791,8 @@ static int
compare_applications (GMenuTreeEntry *a,
GMenuTreeEntry *b)
{
- return g_utf8_collate (gmenu_tree_entry_get_display_name (a),
- gmenu_tree_entry_get_display_name (b));
+ return g_utf8_collate (g_app_info_get_display_name ((GAppInfo*)(gmenu_tree_entry_get_app_info (a))),
+ g_app_info_get_display_name ((GAppInfo*)(gmenu_tree_entry_get_app_info (b))));
}
static GSList *get_all_applications_from_dir (GMenuTreeDirectory *directory,
@@ -802,26 +802,23 @@ static GSList *
get_all_applications_from_alias (GMenuTreeAlias *alias,
GSList *list)
{
- GMenuTreeItem *aliased_item;
-
- aliased_item = gmenu_tree_alias_get_item (alias);
-
- switch (gmenu_tree_item_get_type (aliased_item)) {
+ switch (gmenu_tree_alias_get_item_type (alias)) {
case GMENU_TREE_ITEM_ENTRY:
- list = g_slist_append (list, gmenu_tree_item_ref (aliased_item));
+ /* pass on the reference */
+ list = g_slist_append (list, gmenu_tree_alias_get_aliased_entry (alias));
break;
- case GMENU_TREE_ITEM_DIRECTORY:
- list = get_all_applications_from_dir (GMENU_TREE_DIRECTORY (aliased_item),
- list);
+ case GMENU_TREE_ITEM_DIRECTORY: {
+ GMenuTreeDirectory *directory = gmenu_tree_alias_get_aliased_directory (alias);
+ list = get_all_applications_from_dir (directory, list);
+ gmenu_tree_item_unref (directory);
break;
+ }
default:
break;
}
- gmenu_tree_item_unref (aliased_item);
-
return list;
}
@@ -829,33 +826,37 @@ static GSList *
get_all_applications_from_dir (GMenuTreeDirectory *directory,
GSList *list)
{
- GSList *items;
- GSList *l;
+ GMenuTreeIter *iter;
+ GMenuTreeItemType next_type;
- items = gmenu_tree_directory_get_contents (directory);
+ iter = gmenu_tree_directory_iter (directory);
- for (l = items; l; l = l->next) {
- switch (gmenu_tree_item_get_type (l->data)) {
+ while ((next_type = gmenu_tree_iter_next (iter)) != GMENU_TREE_ITEM_INVALID) {
+ switch (next_type) {
case GMENU_TREE_ITEM_ENTRY:
- list = g_slist_append (list, gmenu_tree_item_ref (l->data));
+ list = g_slist_append (list, gmenu_tree_iter_get_entry (iter));
break;
- case GMENU_TREE_ITEM_DIRECTORY:
- list = get_all_applications_from_dir (l->data, list);
+ case GMENU_TREE_ITEM_DIRECTORY: {
+ GMenuTreeDirectory *dir = gmenu_tree_iter_get_directory (iter);
+ list = get_all_applications_from_dir (dir, list);
+ gmenu_tree_item_unref (dir);
break;
+ }
- case GMENU_TREE_ITEM_ALIAS:
- list = get_all_applications_from_alias (l->data, list);
+ case GMENU_TREE_ITEM_ALIAS: {
+ GMenuTreeAlias *alias = gmenu_tree_iter_get_alias (iter);
+ list = get_all_applications_from_alias (alias, list);
+ gmenu_tree_item_unref (alias);
break;
+ }
default:
break;
}
-
- gmenu_tree_item_unref (l->data);
}
- g_slist_free (items);
+ gmenu_tree_iter_unref (iter);
return list;
}
@@ -867,15 +868,17 @@ get_all_applications (void)
GMenuTreeDirectory *root;
GSList *retval;
- tree = gmenu_tree_lookup ("applications.menu", GMENU_TREE_FLAGS_NONE);
- gmenu_tree_set_sort_key (tree, GMENU_TREE_SORT_DISPLAY_NAME);
+ tree = gmenu_tree_new ("applications.menu", GMENU_TREE_FLAGS_NONE);
+
+ if (!gmenu_tree_load_sync (tree, NULL))
+ return NULL;
root = gmenu_tree_get_root_directory (tree);
retval = get_all_applications_from_dir (root, NULL);
gmenu_tree_item_unref (root);
- gmenu_tree_unref (tree);
+ g_object_unref (tree);
retval = g_slist_sort (retval,
(GCompareFunc) compare_applications);
@@ -911,10 +914,13 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog)
for (l = all_applications; l; l = next) {
GMenuTreeEntry *entry = l->data;
const char *entry_name;
+ GDesktopAppInfo *app_info;
+
next = l->next;
+ app_info = gmenu_tree_entry_get_app_info (entry);
- entry_name = gmenu_tree_entry_get_display_name (entry);
+ entry_name = g_app_info_get_display_name (G_APP_INFO (app_info));
if (prev_name && entry_name && strcmp (entry_name, prev_name) == 0) {
gmenu_tree_item_unref (entry);
@@ -928,14 +934,17 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog)
GMenuTreeEntry *entry = l->data;
GtkTreeIter iter;
GtkTreePath *path;
+ GDesktopAppInfo *app_info;
+
+ app_info = gmenu_tree_entry_get_app_info (entry);
gtk_list_store_append (dialog->program_list_store, &iter);
gtk_list_store_set (dialog->program_list_store, &iter,
- COLUMN_ICON, NULL,
- COLUMN_ICON_FILE, gmenu_tree_entry_get_icon (entry),
- COLUMN_NAME, gmenu_tree_entry_get_display_name (entry),
- COLUMN_COMMENT, gmenu_tree_entry_get_comment (entry),
- COLUMN_EXEC, gmenu_tree_entry_get_exec (entry),
+ COLUMN_ICON, g_app_info_get_icon (G_APP_INFO (app_info)),
+ COLUMN_ICON_FILE, NULL,
+ COLUMN_NAME, g_app_info_get_display_name (G_APP_INFO (app_info)),
+ COLUMN_COMMENT, g_app_info_get_description (G_APP_INFO (app_info)),
+ COLUMN_EXEC, g_app_info_get_executable (G_APP_INFO (app_info)),
COLUMN_PATH, gmenu_tree_entry_get_desktop_file_path (entry),
COLUMN_VISIBLE, TRUE,
-1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]