[gnome-panel] panel: Finish port to new gnome-menus API
- From: Vincent Untz <vuntz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel] panel: Finish port to new gnome-menus API
- Date: Mon, 1 Aug 2011 17:41:35 +0000 (UTC)
commit 10ce6bac116a089cc8982c084f094a3634f076cf
Author: Vincent Untz <vuntz gnome org>
Date: Fri Jul 22 11:01:42 2011 +0200
panel: Finish port to new gnome-menus API
This completes Colin's previous commit, fixing various issues and
cleaning some changes.
We move quite some code to GIcon, which is easier in many cases.
configure.ac | 4 +-
gnome-panel/menu.c | 14 +-
gnome-panel/panel-addto.c | 289 +++++++++++++++-----------------------
gnome-panel/panel-menu-button.c | 30 +++--
gnome-panel/panel-run-dialog.c | 250 +++++++++-------------------------
gnome-panel/panel-util.c | 2 +-
gnome-panel/panel-util.h | 1 +
7 files changed, 208 insertions(+), 382 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 74f9f7e..5126203 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=4.0.0
+LIBGNOME_MENU_REQUIRED=3.1.4
TELEPATHY_GLIB_REQUIRED=0.14.0
LIBECAL_REQUIRED=2.91.2
LIBEDATASERVER_REQUIRED=2.91.2
@@ -77,7 +77,7 @@ dnl pkg-config dependency checks
PKG_CHECK_MODULES(EGG_SMCLIENT, ice sm gtk+-3.0)
-PKG_CHECK_MODULES(PANEL, gdk-pixbuf-2.0 >= $GDK_PIXBUF_REQUIRED pango >= $PANGO_REQUIRED gtk+-3.0 >= $GTK_REQUIRED cairo-xlib glib-2.0 >= $GLIB_REQUIRED gio-2.0 >= $GLIB_REQUIRED gio-unix-2.0 >= $GLIB_REQUIRED gnome-desktop-3.0 >= $LIBGNOME_DESKTOP_REQUIRED gconf-2.0 >= $GCONF_REQUIRED libgnome-menu >= $LIBGNOME_MENU_REQUIRED dconf)
+PKG_CHECK_MODULES(PANEL, gdk-pixbuf-2.0 >= $GDK_PIXBUF_REQUIRED pango >= $PANGO_REQUIRED gtk+-3.0 >= $GTK_REQUIRED cairo-xlib glib-2.0 >= $GLIB_REQUIRED gio-2.0 >= $GLIB_REQUIRED gio-unix-2.0 >= $GLIB_REQUIRED gnome-desktop-3.0 >= $LIBGNOME_DESKTOP_REQUIRED gconf-2.0 >= $GCONF_REQUIRED libgnome-menu-3.0 >= $LIBGNOME_MENU_REQUIRED dconf)
AC_SUBST(PANEL_CFLAGS)
AC_SUBST(PANEL_LIBS)
diff --git a/gnome-panel/menu.c b/gnome-panel/menu.c
index 8f2dafb..a2d69c8 100644
--- a/gnome-panel/menu.c
+++ b/gnome-panel/menu.c
@@ -1008,8 +1008,9 @@ create_submenu_entry (GtkWidget *menu,
panel_load_menu_image_deferred (menuitem,
panel_menu_icon_get_size (),
- NULL, NULL,
+ NULL,
gmenu_tree_directory_get_icon (directory),
+ NULL,
PANEL_ICON_FOLDER);
setup_menuitem (menuitem,
@@ -1077,8 +1078,9 @@ create_menuitem (GtkWidget *menu,
if (alias_directory)
panel_load_menu_image_deferred (menuitem,
panel_menu_icon_get_size (),
- NULL, NULL,
+ NULL,
gmenu_tree_directory_get_icon (alias_directory),
+ NULL,
NULL);
else
panel_load_menu_image_deferred (menuitem,
@@ -1121,9 +1123,8 @@ create_menuitem (GtkWidget *menu,
GDK_ACTION_COPY);
icon = g_app_info_get_icon (G_APP_INFO (gmenu_tree_entry_get_app_info (entry)));
- if (icon != NULL) {
+ if (icon != NULL)
gtk_drag_source_set_icon_gicon (menuitem, icon);
- }
g_signal_connect (G_OBJECT (menuitem), "drag_begin",
G_CALLBACK (drag_begin_menu_cb), NULL);
@@ -1146,7 +1147,8 @@ create_menuitem_from_alias (GtkWidget *menu,
GMenuTreeAlias *alias)
{
GMenuTreeDirectory *src = gmenu_tree_alias_get_directory (alias);
- switch (gmenu_tree_alias_get_item_type (alias)) {
+
+ switch (gmenu_tree_alias_get_aliased_item_type (alias)) {
case GMENU_TREE_ITEM_DIRECTORY: {
GMenuTreeDirectory *directory = gmenu_tree_alias_get_aliased_directory (alias);
create_submenu (menu,
@@ -1229,7 +1231,7 @@ create_applications_menu (const char *menu_file,
"panel-menu-force-icon-for-categories",
GINT_TO_POINTER (TRUE));
- tree = gmenu_tree_new (menu_file, GMENU_TREE_FLAGS_NONE);
+ tree = gmenu_tree_new (menu_file, GMENU_TREE_FLAGS_SORT_DISPLAY_NAME);
if (!gmenu_tree_load_sync (tree, &error)) {
g_warning ("Failed to load applications: %s", error->message);
diff --git a/gnome-panel/panel-addto.c b/gnome-panel/panel-addto.c
index 03d7f2d..1e58194 100644
--- a/gnome-panel/panel-addto.c
+++ b/gnome-panel/panel-addto.c
@@ -101,7 +101,7 @@ typedef struct {
char *menu_filename;
char *menu_path;
char *iid;
- gboolean static_data;
+ gboolean static_strings;
} PanelAddtoItemInfo;
typedef struct {
@@ -135,73 +135,60 @@ panel_addto_applet_info_sort_func (PanelAddtoItemInfo *a,
return g_utf8_collate (a->name, b->name);
}
-static PanelAddtoItemInfo *
-get_internal_applets (void)
+static GSList *
+prepend_internal_applets (GSList *list)
{
- 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;
+ PanelAddtoItemInfo *internal;
- 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;
+ internal = g_new0 (PanelAddtoItemInfo, 1);
+ internal->type = PANEL_ADDTO_MENU;
+ internal->name = _("Main Menu");
+ internal->description = _("The main GNOME menu");
+ internal->icon = g_themed_icon_new (PANEL_ICON_MAIN_MENU);
+ internal->action_type = PANEL_ACTION_NONE;
+ internal->iid = "MENU:MAIN";
+ internal->static_strings = TRUE;
+ list = g_slist_prepend (list, internal);
- 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;
+ internal = g_new0 (PanelAddtoItemInfo, 1);
+ internal->type = PANEL_ADDTO_MENUBAR;
+ internal->name = _("Menu Bar");
+ internal->description = _("A custom menu bar");
+ internal->icon = g_themed_icon_new (PANEL_ICON_MAIN_MENU);
+ internal->action_type = PANEL_ACTION_NONE;
+ internal->iid = "MENUBAR:NEW";
+ internal->static_strings = TRUE;
+ list = g_slist_prepend (list, internal);
+
+ internal = g_new0 (PanelAddtoItemInfo, 1);
+ internal->type = PANEL_ADDTO_SEPARATOR;
+ internal->name = _("Separator");
+ internal->description = _("A separator to organize the panel items");
+ internal->icon = g_themed_icon_new (PANEL_ICON_SEPARATOR);
+ internal->action_type = PANEL_ACTION_NONE;
+ internal->iid = "SEPARATOR:NEW";
+ internal->static_strings = TRUE;
+ list = g_slist_prepend (list, internal);
+
+ internal = g_new0 (PanelAddtoItemInfo, 1);
+ internal->type = PANEL_ADDTO_USER_MENU;
+ internal->name = _("User menu");
+ internal->description = _("Menu to change your settings and your online status");
+ internal->icon = g_themed_icon_new (PANEL_ICON_USER_AVAILABLE);
+ internal->action_type = PANEL_ACTION_NONE;
+ internal->iid = "USERMENU:NEW";
+ internal->static_strings = TRUE;
+ list = g_slist_prepend (list, internal);
+
+ return list;
}
static GSList *
panel_addto_prepend_internal_applets (GSList *list)
{
- PanelAddtoItemInfo *internal;
- int i;
-
- internal = get_internal_applets ();
+ int i;
- for (; internal->name; internal++) {
- list = g_slist_prepend (list, internal);
- }
+ list = prepend_internal_applets (list);
for (i = PANEL_ACTION_LOCK; i < PANEL_ACTION_LAST; i++) {
PanelAddtoItemInfo *info;
@@ -212,11 +199,12 @@ panel_addto_prepend_internal_applets (GSList *list)
info = g_new0 (PanelAddtoItemInfo, 1);
info->type = PANEL_ADDTO_ACTION;
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_themed_icon_new (panel_action_get_icon_name (i));
- info->iid = g_strdup (panel_action_get_drag_id (i));
- info->static_data = FALSE;
+ info->name = (char *) panel_action_get_text (i);
+ info->description = (char *) panel_action_get_tooltip (i);
+ if (panel_action_get_icon_name (i) != NULL)
+ info->icon = g_themed_icon_new (panel_action_get_icon_name (i));
+ info->iid = (char *) panel_action_get_drag_id (i);
+ info->static_strings = TRUE;
list = g_slist_prepend (list, info);
}
@@ -244,24 +232,6 @@ panel_addto_make_text (const char *name,
return result;
}
-#define ICON_SIZE 32
-
-static GdkPixbuf *
-panel_addto_make_pixbuf (GIcon *icon)
-{
- GtkIconInfo *icon_info;
- GdkPixbuf *pixbuf;
-
- //FIXME: size shouldn't be fixed but should depend on the font size
- 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
panel_addto_drag_data_get_cb (GtkWidget *widget,
GdkDragContext *context,
@@ -285,7 +255,7 @@ panel_addto_drag_begin_cb (GtkWidget *widget,
GtkTreePath *path;
GtkTreeIter iter;
GtkTreeIter filter_iter;
- GdkPixbuf *pixbuf;
+ GIcon *gicon;
filter_model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
@@ -297,11 +267,11 @@ panel_addto_drag_begin_cb (GtkWidget *widget,
child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model));
gtk_tree_model_get (child_model, &iter,
- COLUMN_ICON, &pixbuf,
+ COLUMN_ICON, &gicon,
-1);
- gtk_drag_set_icon_pixbuf (context, pixbuf, 0, 0);
- g_object_unref (pixbuf);
+ gtk_drag_set_icon_gicon (context, gicon, 0, 0);
+ g_object_unref (gicon);
}
static void
@@ -394,9 +364,10 @@ panel_addto_query_applets (GSList *list)
applet->type = PANEL_ADDTO_APPLET;
applet->name = g_strdup (name);
applet->description = g_strdup (description);
- applet->icon = g_themed_icon_new (icon);
+ if (icon)
+ applet->icon = g_themed_icon_new (icon);
applet->iid = g_strdup (iid);
- applet->static_data = FALSE;
+ applet->static_strings = FALSE;
list = g_slist_prepend (list, applet);
}
@@ -412,7 +383,6 @@ panel_addto_append_item (PanelAddtoDialog *dialog,
PanelAddtoItemInfo *applet)
{
char *text;
- GdkPixbuf *pixbuf;
GtkTreeIter iter;
if (applet == NULL) {
@@ -424,80 +394,49 @@ panel_addto_append_item (PanelAddtoDialog *dialog,
COLUMN_SEARCH, NULL,
-1);
} else {
- pixbuf = NULL;
-
- if (applet->icon != NULL) {
- pixbuf = panel_addto_make_pixbuf (applet->icon);
- }
-
gtk_list_store_append (model, &iter);
text = panel_addto_make_text (applet->name,
applet->description);
gtk_list_store_set (model, &iter,
- COLUMN_ICON, pixbuf,
+ COLUMN_ICON, applet->icon,
COLUMN_TEXT, text,
COLUMN_DATA, applet,
COLUMN_SEARCH, applet->name,
-1);
- if (pixbuf)
- g_object_unref (pixbuf);
-
g_free (text);
}
}
-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)
{
PanelAddtoItemInfo *special;
- special = get_special_items ();
-
- for (; special->name; special++) {
- if (special->type == PANEL_ADDTO_LAUNCHER_NEW
- && panel_lockdown_get_disable_command_line_s ())
- continue;
-
+ if (!panel_lockdown_get_disable_command_line_s ()) {
+ special = g_new0 (PanelAddtoItemInfo, 1);
+ special->type = PANEL_ADDTO_LAUNCHER_NEW;
+ special->name = _("Custom Application Launcher");
+ special->description = _("Create a new launcher");
+ special->icon = g_themed_icon_new (PANEL_ICON_LAUNCHER);
+ special->action_type = PANEL_ACTION_NONE;
+ special->iid = "LAUNCHER:ASK";
+ special->static_strings = TRUE;
panel_addto_append_item (dialog, model, special);
}
+
+ special = g_new0 (PanelAddtoItemInfo, 1);
+ special->type = PANEL_ADDTO_LAUNCHER_MENU;
+ special->name = _("Application Launcher...");
+ special->description = _("Copy a launcher from the applications menu");
+ special->icon = g_themed_icon_new (PANEL_ICON_LAUNCHER);
+ special->action_type = PANEL_ACTION_NONE;
+ special->iid = "LAUNCHER:MENU";
+ special->static_strings = TRUE;
+ panel_addto_append_item (dialog, model, special);
}
static void
@@ -518,7 +457,7 @@ panel_addto_make_applet_model (PanelAddtoDialog *dialog)
(GCompareFunc) panel_addto_applet_info_sort_func);
model = gtk_list_store_new (NUMBER_COLUMNS,
- GDK_TYPE_PIXBUF,
+ G_TYPE_ICON,
G_TYPE_STRING,
G_TYPE_POINTER,
G_TYPE_STRING);
@@ -564,10 +503,10 @@ 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_themed_icon_new (gmenu_tree_directory_get_icon (directory));
+ data->item_info.icon = g_object_ref (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;
+ data->item_info.static_strings = FALSE;
/* We should set the iid here to something and do
* iid = g_strdup_printf ("MENU:%s", tfr->name)
@@ -590,18 +529,18 @@ panel_addto_prepend_entry (GSList **parent_list,
const char *filename)
{
PanelAddtoAppList *data;
- GDesktopAppInfo *app_info;
+ GAppInfo *app_info;
data = g_new0 (PanelAddtoAppList, 1);
- app_info = gmenu_tree_entry_get_app_info (entry);
+ app_info = G_APP_INFO (gmenu_tree_entry_get_app_info (entry));
data->item_info.type = PANEL_ADDTO_LAUNCHER;
- 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.name = g_strdup (g_app_info_get_display_name (app_info));
+ data->item_info.description = g_strdup (g_app_info_get_description (app_info));
+ data->item_info.icon = g_object_ref (g_app_info_get_icon (app_info));
data->item_info.launcher_path = g_strdup (gmenu_tree_entry_get_desktop_file_path (entry));
- data->item_info.static_data = FALSE;
+ data->item_info.static_strings = FALSE;
*parent_list = g_slist_prepend (*parent_list, data);
}
@@ -611,7 +550,7 @@ panel_addto_prepend_alias (GSList **parent_list,
GMenuTreeAlias *alias,
const char *filename)
{
- switch (gmenu_tree_alias_get_item_type (alias)) {
+ switch (gmenu_tree_alias_get_aliased_item_type (alias)) {
case GMENU_TREE_ITEM_DIRECTORY: {
GMenuTreeDirectory *directory = gmenu_tree_alias_get_aliased_directory (alias);
panel_addto_prepend_directory (parent_list,
@@ -687,7 +626,6 @@ panel_addto_populate_application_model (GtkTreeStore *store,
PanelAddtoAppList *data;
GtkTreeIter iter;
char *text;
- GdkPixbuf *pixbuf;
GSList *app;
for (app = app_list; app != NULL; app = app->next) {
@@ -696,17 +634,13 @@ panel_addto_populate_application_model (GtkTreeStore *store,
text = panel_addto_make_text (data->item_info.name,
data->item_info.description);
- pixbuf = panel_addto_make_pixbuf (data->item_info.icon);
gtk_tree_store_set (store, &iter,
- COLUMN_ICON, pixbuf,
+ COLUMN_ICON, data->item_info.icon,
COLUMN_TEXT, text,
COLUMN_DATA, &(data->item_info),
COLUMN_SEARCH, data->item_info.name,
-1);
- if (pixbuf)
- g_object_unref (pixbuf);
-
g_free (text);
if (data->children != NULL)
@@ -727,19 +661,19 @@ panel_addto_make_application_model (PanelAddtoDialog *dialog)
return;
store = gtk_tree_store_new (NUMBER_COLUMNS,
- GDK_TYPE_PIXBUF,
+ G_TYPE_ICON,
G_TYPE_STRING,
G_TYPE_POINTER,
G_TYPE_STRING);
- tree = gmenu_tree_new ("applications.menu", GMENU_TREE_FLAGS_NONE);
+ tree = gmenu_tree_new ("applications.menu", GMENU_TREE_FLAGS_SORT_DISPLAY_NAME);
if (!gmenu_tree_load_sync (tree, NULL)) {
g_object_unref (tree);
- return;
+ tree = NULL;
}
- if ((root = gmenu_tree_get_root_directory (tree))) {
+ if (tree != NULL && (root = gmenu_tree_get_root_directory (tree))) {
panel_addto_make_application_list (&dialog->application_list,
root, "applications.menu",
PANEL_ADDTO_MENU_SHOW_ALL);
@@ -748,16 +682,17 @@ panel_addto_make_application_model (PanelAddtoDialog *dialog)
gmenu_tree_item_unref (root);
}
- g_object_unref (tree);
+ if (tree != NULL)
+ g_object_unref (tree);
- tree = gmenu_tree_new ("gnomecc.menu", GMENU_TREE_FLAGS_NONE);
+ tree = gmenu_tree_new ("gnomecc.menu", GMENU_TREE_FLAGS_SORT_DISPLAY_NAME);
if (!gmenu_tree_load_sync (tree, NULL)) {
g_object_unref (tree);
- return;
+ tree = NULL;
}
- if ((root = gmenu_tree_get_root_directory (tree))) {
+ if (tree != NULL && (root = gmenu_tree_get_root_directory (tree))) {
GtkTreeIter iter;
gtk_tree_store_append (store, &iter, NULL);
@@ -779,7 +714,8 @@ panel_addto_make_application_model (PanelAddtoDialog *dialog)
gmenu_tree_item_unref (root);
}
- g_object_unref (tree);
+ if (tree != NULL)
+ 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),
@@ -957,7 +893,15 @@ panel_addto_present_applets (PanelAddtoDialog *dialog)
static void
panel_addto_dialog_free_item_info (PanelAddtoItemInfo *item_info)
{
- if (item_info == NULL || item_info->static_data)
+ if (item_info == NULL)
+ return;
+
+ /* the GIcon is never static */
+ if (item_info->icon != NULL)
+ g_object_unref (item_info->icon);
+ item_info->icon = NULL;
+
+ if (item_info->static_strings)
return;
if (item_info->name != NULL)
@@ -968,10 +912,6 @@ panel_addto_dialog_free_item_info (PanelAddtoItemInfo *item_info)
g_free (item_info->description);
item_info->description = NULL;
- if (item_info->icon != NULL)
- g_free (item_info->icon);
- item_info->icon = NULL;
-
if (item_info->iid != NULL)
g_free (item_info->iid);
item_info->iid = NULL;
@@ -1035,10 +975,8 @@ panel_addto_dialog_free (PanelAddtoDialog *dialog)
PanelAddtoItemInfo *applet;
applet = (PanelAddtoItemInfo *) item->data;
- if (!applet->static_data) {
- panel_addto_dialog_free_item_info (applet);
- g_free (applet);
- }
+ panel_addto_dialog_free_item_info (applet);
+ g_free (applet);
}
g_slist_free (dialog->applet_list);
@@ -1372,12 +1310,13 @@ panel_addto_dialog_new (PanelWidget *panel_widget)
renderer = g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF,
"xpad", 4,
"ypad", 4,
+ "stock-size", GTK_ICON_SIZE_DND,
NULL);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (dialog->tree_view),
-1, NULL,
renderer,
- "pixbuf", COLUMN_ICON,
+ "gicon", COLUMN_ICON,
NULL);
renderer = gtk_cell_renderer_text_new ();
g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
diff --git a/gnome-panel/panel-menu-button.c b/gnome-panel/panel-menu-button.c
index 97d5c17..bedf6a6 100644
--- a/gnome-panel/panel-menu-button.c
+++ b/gnome-panel/panel-menu-button.c
@@ -574,16 +574,16 @@ panel_menu_button_load_helper (const char *menu_path,
button);
}
-static char *
+static GIcon *
panel_menu_button_get_icon (PanelMenuButton *button)
{
GMenuTreeDirectory *directory;
- char *retval;
+ GIcon *retval;
retval = NULL;
if (!PANEL_GLIB_STR_EMPTY (button->priv->custom_icon))
- retval = g_strdup (button->priv->custom_icon);
+ retval = g_themed_icon_new (button->priv->custom_icon);
if (!retval &&
!PANEL_GLIB_STR_EMPTY (button->priv->menu_path) &&
@@ -606,11 +606,11 @@ panel_menu_button_get_icon (PanelMenuButton *button)
}
if (directory)
- retval = g_strdup (gmenu_tree_directory_get_icon (directory));
+ retval = g_object_ref (gmenu_tree_directory_get_icon (directory));
}
if (!retval)
- retval = g_strdup (PANEL_ICON_MAIN_MENU);
+ retval = g_themed_icon_new (PANEL_ICON_MAIN_MENU);
return retval;
}
@@ -618,12 +618,16 @@ panel_menu_button_get_icon (PanelMenuButton *button)
static void
panel_menu_button_set_icon (PanelMenuButton *button)
{
- char *icon_path;
+ GIcon *gicon;
+ char *icon;
- icon_path = panel_menu_button_get_icon (button);
- button_widget_set_icon_name (BUTTON_WIDGET (button), icon_path);
+ gicon = panel_menu_button_get_icon (button);
+ icon = panel_util_get_icon_name_from_g_icon (gicon);
- g_free (icon_path);
+ button_widget_set_icon_name (BUTTON_WIDGET (button), icon);
+
+ g_free (icon);
+ g_object_unref (gicon);
}
static const char *
@@ -874,7 +878,7 @@ panel_menu_button_set_dnd_enabled (PanelMenuButton *button,
static GtkTargetEntry dnd_targets [] = {
{ "application/x-panel-applet-internal", 0, 0 }
};
- char *icon;
+ GIcon *icon;
gtk_widget_set_has_window (GTK_WIDGET (button), TRUE);
gtk_drag_source_set (GTK_WIDGET (button), GDK_BUTTON1_MASK,
@@ -883,9 +887,9 @@ panel_menu_button_set_dnd_enabled (PanelMenuButton *button,
icon = panel_menu_button_get_icon (button);
if (icon != NULL) {
- gtk_drag_source_set_icon_name (GTK_WIDGET (button),
- icon);
- g_free (icon);
+ gtk_drag_source_set_icon_gicon (GTK_WIDGET (button),
+ icon);
+ g_object_unref (icon);
}
gtk_widget_set_has_window (GTK_WIDGET (button), FALSE);
diff --git a/gnome-panel/panel-run-dialog.c b/gnome-panel/panel-run-dialog.c
index 1e6d795..c2dcc3e 100644
--- a/gnome-panel/panel-run-dialog.c
+++ b/gnome-panel/panel-run-dialog.c
@@ -49,6 +49,7 @@
#include <libpanel-util/panel-gtk.h>
#include <libpanel-util/panel-keyfile.h>
#include <libpanel-util/panel-show.h>
+#include <libpanel-util/panel-xdg.h>
#include "nothing.h"
#include "panel-util.h"
@@ -88,20 +89,18 @@ typedef struct {
GCompletion *completion;
GSList *add_icon_paths;
- int add_icons_idle_id;
int add_items_idle_id;
int find_command_idle_id;
gboolean use_program_list;
gboolean completion_started;
- char *icon_path;
+ GIcon *gicon;
char *desktop_path;
char *item_name;
} PanelRunDialog;
enum {
COLUMN_ICON,
- COLUMN_ICON_FILE,
COLUMN_NAME,
COLUMN_COMMENT,
COLUMN_PATH,
@@ -112,8 +111,6 @@ enum {
static PanelRunDialog *static_dialog = NULL;
-static void panel_run_dialog_disconnect_pixmap (PanelRunDialog *dialog);
-
#define PANEL_RUN_MAX_HISTORY 20
static GtkTreeModel *
@@ -187,17 +184,15 @@ panel_run_dialog_destroy (PanelRunDialog *dialog)
g_slist_free (dialog->add_icon_paths);
dialog->add_icon_paths = NULL;
- g_free (dialog->icon_path);
- dialog->icon_path = NULL;
+ if (dialog->gicon)
+ g_object_unref (dialog->gicon);
+ dialog->gicon = NULL;
+
g_free (dialog->desktop_path);
dialog->desktop_path = NULL;
g_free (dialog->item_name);
dialog->item_name = NULL;
- if (dialog->add_icons_idle_id)
- g_source_remove (dialog->add_icons_idle_id);
- dialog->add_icons_idle_id = 0;
-
if (dialog->add_items_idle_id)
g_source_remove (dialog->add_items_idle_id);
dialog->add_items_idle_id = 0;
@@ -224,8 +219,6 @@ panel_run_dialog_destroy (PanelRunDialog *dialog)
g_completion_free (dialog->completion);
dialog->completion = NULL;
- panel_run_dialog_disconnect_pixmap (dialog);
-
if (dialog->run_settings)
g_object_unref (dialog->run_settings);
dialog->run_settings = NULL;
@@ -260,51 +253,23 @@ panel_run_dialog_set_default_icon (PanelRunDialog *dialog, gboolean set_drag)
static void
panel_run_dialog_set_icon (PanelRunDialog *dialog,
- const char *icon_path,
+ GIcon *gicon,
gboolean force)
{
- GdkPixbuf *pixbuf = NULL;
-
- if (!force && icon_path && dialog->icon_path &&
- !strcmp (icon_path, dialog->icon_path))
+ if (!force && gicon && dialog->gicon &&
+ gicon == dialog->gicon)
return;
- g_free (dialog->icon_path);
- dialog->icon_path = NULL;
+ if (dialog->gicon)
+ g_object_unref (dialog->gicon);
+ dialog->gicon = NULL;
- if (icon_path) {
- GdkScreen *screen;
- GtkSettings *settings;
- int size;
-
- screen = gtk_widget_get_screen (GTK_WIDGET (dialog->pixmap));
- settings = gtk_settings_get_for_screen (screen);
- gtk_icon_size_lookup_for_settings (settings,
- GTK_ICON_SIZE_DIALOG,
- &size, NULL);
-
- pixbuf = panel_load_icon (gtk_icon_theme_get_default (),
- icon_path,
- size,
- size,
- size,
- NULL);
- }
-
- if (pixbuf) {
- dialog->icon_path = g_strdup (icon_path);
-
- /* Don't bother scaling the image if it's too small.
- * Scaled looks worse than a smaller image.
- */
- gtk_image_set_from_pixbuf (GTK_IMAGE (dialog->pixmap), pixbuf);
-
- //FIXME: it'd be better to set an icon of the correct size,
- //(ditto for the drag icon?)
- gtk_window_set_icon (GTK_WINDOW (dialog->run_dialog), pixbuf);
-
- gtk_drag_source_set_icon_pixbuf (dialog->run_dialog, pixbuf);
- g_object_unref (pixbuf);
+ if (gicon) {
+ dialog->gicon = g_object_ref (gicon);
+ gtk_image_set_from_gicon (GTK_IMAGE (dialog->pixmap),
+ gicon, GTK_ICON_SIZE_DIALOG);
+ //gtk_window_set_icon (GTK_WINDOW (dialog->run_dialog), gicon);
+ gtk_drag_source_set_icon_gicon (dialog->run_dialog, gicon);
} else {
panel_run_dialog_set_default_icon (dialog, TRUE);
}
@@ -649,7 +614,7 @@ panel_run_dialog_find_command_idle (PanelRunDialog *dialog)
GtkTreeModel *model;
GtkTreePath *path;
char *text;
- char *found_icon;
+ GIcon *found_icon;
char *found_name;
gboolean fuzzy;
@@ -673,23 +638,24 @@ panel_run_dialog_find_command_idle (PanelRunDialog *dialog)
do {
char *exec = NULL;
- char *icon = NULL;
char *name = NULL;
char *comment = NULL;
+ GIcon *icon = NULL;
gtk_tree_model_get (model, &iter,
- COLUMN_EXEC, &exec,
- COLUMN_ICON_FILE, &icon,
- COLUMN_NAME, &name,
- COLUMN_COMMENT, &comment,
+ COLUMN_EXEC, &exec,
+ COLUMN_ICON, &icon,
+ COLUMN_NAME, &name,
+ COLUMN_COMMENT, &comment,
-1);
if (!fuzzy && exec && icon &&
fuzzy_command_match (text, exec, &fuzzy)) {
- g_free (found_icon);
+ if (found_icon)
+ g_object_unref (found_icon);
g_free (found_name);
- found_icon = g_strdup (icon);
+ found_icon = g_object_ref (icon);
found_name = g_strdup (name);
gtk_list_store_set (dialog->program_list_store,
@@ -711,7 +677,7 @@ panel_run_dialog_find_command_idle (PanelRunDialog *dialog)
}
g_free (exec);
- g_free (icon);
+ g_object_unref (icon);
g_free (name);
g_free (comment);
@@ -727,7 +693,8 @@ panel_run_dialog_find_command_idle (PanelRunDialog *dialog)
panel_run_dialog_set_icon (dialog, found_icon, FALSE);
//FIXME update dialog->program_label
- g_free (found_icon);
+ if (found_icon)
+ g_object_unref (found_icon);
g_free (text);
g_free (dialog->item_name);
@@ -737,56 +704,6 @@ panel_run_dialog_find_command_idle (PanelRunDialog *dialog)
return FALSE;
}
-static gboolean
-panel_run_dialog_add_icon_idle (PanelRunDialog *dialog)
-{
- GtkTreeIter iter;
- GtkTreePath *path;
- GdkPixbuf *pixbuf;
- char *file;
- int icon_height;
- gboolean long_operation = FALSE;
-
- do {
- if (!dialog->add_icon_paths) {
- dialog->add_icons_idle_id = 0;
- return FALSE;
- }
-
- path = dialog->add_icon_paths->data;
- dialog->add_icon_paths->data = NULL;
- dialog->add_icon_paths = g_slist_delete_link (dialog->add_icon_paths,
- dialog->add_icon_paths);
-
- if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (dialog->program_list_store),
- &iter,
- path)) {
- gtk_tree_path_free (path);
- continue;
- }
-
- gtk_tree_path_free (path);
-
- gtk_tree_model_get (GTK_TREE_MODEL (dialog->program_list_store), &iter,
- COLUMN_ICON_FILE, &file, -1);
-
- if (!gtk_icon_size_lookup (panel_menu_icon_get_size (), NULL, &icon_height)) {
- icon_height = PANEL_DEFAULT_MENU_ICON_SIZE;
- }
-
- pixbuf = panel_make_menu_icon (gtk_icon_theme_get_default (), file, NULL, icon_height, &long_operation);
- if (pixbuf) {
- gtk_list_store_set (dialog->program_list_store, &iter, COLUMN_ICON, pixbuf, -1);
- g_object_unref (pixbuf);
- }
- g_free (file);
-
- /* don't go back into the main loop if this wasn't very hard to do */
- } while (!long_operation);
-
- return TRUE;
-}
-
static int
compare_applications (GMenuTreeEntry *a,
GMenuTreeEntry *b)
@@ -802,7 +719,7 @@ static GSList *
get_all_applications_from_alias (GMenuTreeAlias *alias,
GSList *list)
{
- switch (gmenu_tree_alias_get_item_type (alias)) {
+ switch (gmenu_tree_alias_get_aliased_item_type (alias)) {
case GMENU_TREE_ITEM_ENTRY:
/* pass on the reference */
list = g_slist_append (list, gmenu_tree_alias_get_aliased_entry (alias));
@@ -868,7 +785,7 @@ get_all_applications (void)
GMenuTreeDirectory *root;
GSList *retval;
- tree = gmenu_tree_new ("applications.menu", GMENU_TREE_FLAGS_NONE);
+ tree = gmenu_tree_new ("applications.menu", GMENU_TREE_FLAGS_SORT_DISPLAY_NAME);
if (!gmenu_tree_load_sync (tree, NULL))
return NULL;
@@ -899,8 +816,7 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog)
/* create list store */
dialog->program_list_store = gtk_list_store_new (NUM_COLUMNS,
- GDK_TYPE_PIXBUF,
- G_TYPE_STRING,
+ G_TYPE_ICON,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
@@ -912,8 +828,8 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog)
/* Strip duplicates */
prev_name = NULL;
for (l = all_applications; l; l = next) {
- GMenuTreeEntry *entry = l->data;
- const char *entry_name;
+ GMenuTreeEntry *entry = l->data;
+ const char *entry_name;
GDesktopAppInfo *app_info;
@@ -932,21 +848,20 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog)
for (l = all_applications; l; l = l->next) {
GMenuTreeEntry *entry = l->data;
- GtkTreeIter iter;
- GtkTreePath *path;
- GDesktopAppInfo *app_info;
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ GAppInfo *app_info;
- app_info = gmenu_tree_entry_get_app_info (entry);
+ app_info = G_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, 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,
+ COLUMN_ICON, g_app_info_get_icon (app_info),
+ COLUMN_NAME, g_app_info_get_display_name (app_info),
+ COLUMN_COMMENT, g_app_info_get_description (app_info),
+ COLUMN_EXEC, g_app_info_get_executable (app_info),
+ COLUMN_PATH, gmenu_tree_entry_get_desktop_file_path (entry),
+ COLUMN_VISIBLE, TRUE,
-1);
path = gtk_tree_model_get_path (GTK_TREE_MODEL (dialog->program_list_store), &iter);
@@ -972,7 +887,7 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog)
column = gtk_tree_view_column_new ();
gtk_tree_view_column_pack_start (column, renderer, FALSE);
gtk_tree_view_column_set_attributes (column, renderer,
- "pixbuf", COLUMN_ICON,
+ "gicon", COLUMN_ICON,
NULL);
renderer = gtk_cell_renderer_text_new ();
@@ -985,11 +900,6 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog)
dialog->add_icon_paths = g_slist_reverse (dialog->add_icon_paths);
- if (!dialog->add_icons_idle_id)
- dialog->add_icons_idle_id =
- g_idle_add_full (G_PRIORITY_LOW, (GSourceFunc) panel_run_dialog_add_icon_idle,
- dialog, NULL);
-
dialog->add_items_idle_id = 0;
return FALSE;
}
@@ -1097,7 +1007,17 @@ program_list_selection_changed (GtkTreeSelection *selection,
g_free (temp);
temp = panel_key_file_get_locale_string (key_file, "Icon");
- panel_run_dialog_set_icon (dialog, temp, FALSE);
+ if (!PANEL_GLIB_STR_EMPTY (temp)) {
+ GIcon *gicon;
+
+ stripped = panel_xdg_icon_remove_extension (temp);
+ gicon = g_themed_icon_new (stripped);
+ panel_run_dialog_set_icon (dialog, gicon, FALSE);
+ g_object_unref (gicon);
+ g_free (stripped);
+ } else {
+ panel_run_dialog_set_icon (dialog, NULL, FALSE);
+ }
g_free (temp);
temp = panel_key_file_get_locale_string (key_file, "Comment");
@@ -1778,6 +1698,7 @@ panel_run_dialog_create_desktop_file (PanelRunDialog *dialog)
gboolean exec = FALSE;
char *text;
char *name;
+ char *icon;
char *disk;
char *scheme;
char *save_uri;
@@ -1824,10 +1745,14 @@ panel_run_dialog_create_desktop_file (PanelRunDialog *dialog)
panel_key_file_set_boolean (key_file, "Terminal",
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->terminal_checkbox)));
- if (dialog->icon_path)
+ icon = NULL;
+ if (dialog->gicon)
+ icon = panel_util_get_icon_name_from_g_icon (dialog->gicon);
+ if (icon != NULL) {
panel_key_file_set_locale_string (key_file, "Icon",
- dialog->icon_path);
- else
+ icon);
+ g_free (icon);
+ } else
panel_key_file_set_locale_string (key_file, "Icon",
PANEL_ICON_LAUNCHER);
@@ -1871,45 +1796,11 @@ pixmap_drag_data_get (GtkWidget *run_dialog,
}
static void
-panel_run_dialog_style_updated (GtkWidget *widget,
- PanelRunDialog *dialog)
-{
- if (dialog->icon_path) {
- char *icon_path;
-
- icon_path = g_strdup (dialog->icon_path);
- panel_run_dialog_set_icon (dialog, icon_path, TRUE);
- g_free (icon_path);
- }
-}
-
-static void
-panel_run_dialog_screen_changed (GtkWidget *widget,
- GdkScreen *prev_screen,
- PanelRunDialog *dialog)
-{
- if (dialog->icon_path) {
- char *icon_path;
-
- icon_path = g_strdup (dialog->icon_path);
- panel_run_dialog_set_icon (dialog, icon_path, TRUE);
- g_free (icon_path);
- }
-}
-
-static void
panel_run_dialog_setup_pixmap (PanelRunDialog *dialog,
GtkBuilder *gui)
{
dialog->pixmap = PANEL_GTK_BUILDER_GET (gui, "icon_pixmap");
- g_signal_connect (dialog->pixmap, "style-updated",
- G_CALLBACK (panel_run_dialog_style_updated),
- dialog);
- g_signal_connect (dialog->pixmap, "screen-changed",
- G_CALLBACK (panel_run_dialog_screen_changed),
- dialog);
-
g_signal_connect (dialog->run_dialog, "drag_data_get",
G_CALLBACK (pixmap_drag_data_get),
dialog);
@@ -1969,17 +1860,6 @@ panel_run_dialog_new (GdkScreen *screen,
}
static void
-panel_run_dialog_disconnect_pixmap (PanelRunDialog *dialog)
-{
- g_signal_handlers_disconnect_by_func (dialog->pixmap,
- G_CALLBACK (panel_run_dialog_style_updated),
- dialog);
- g_signal_handlers_disconnect_by_func (dialog->pixmap,
- G_CALLBACK (panel_run_dialog_screen_changed),
- dialog);
-}
-
-static void
panel_run_dialog_static_dialog_destroyed (PanelRunDialog *dialog)
{
/* just reset the static dialog to NULL for next time */
diff --git a/gnome-panel/panel-util.c b/gnome-panel/panel-util.c
index 8877ef1..d8b08ad 100644
--- a/gnome-panel/panel-util.c
+++ b/gnome-panel/panel-util.c
@@ -660,7 +660,7 @@ panel_util_get_gfile_root (GFile *file)
return parent_old;
}
-static char *
+char *
panel_util_get_icon_name_from_g_icon (GIcon *gicon)
{
const char * const *names;
diff --git a/gnome-panel/panel-util.h b/gnome-panel/panel-util.h
index 9f8bc48..fc8e9de 100644
--- a/gnome-panel/panel-util.h
+++ b/gnome-panel/panel-util.h
@@ -46,6 +46,7 @@ GdkPixbuf *panel_util_cairo_rgbdata_to_pixbuf (unsigned char *data,
int width,
int height);
+char *panel_util_get_icon_name_from_g_icon (GIcon *gicon);
char *guess_icon_from_exec (GtkIconTheme *icon_theme,
GKeyFile *key_file);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]