summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mate-panel/main.c1
-rw-r--r--mate-panel/menu.c517
-rw-r--r--mate-panel/panel-addto.c53
-rw-r--r--mate-panel/panel-run-dialog.c180
-rw-r--r--mate-panel/panel-stock-icons.c10
-rw-r--r--mate-panel/panel-stock-icons.h3
-rw-r--r--mate-panel/panel-util.c22
-rw-r--r--mate-panel/panel-util.h1
8 files changed, 121 insertions, 666 deletions
diff --git a/mate-panel/main.c b/mate-panel/main.c
index bde5ec13..8a9c3b5d 100644
--- a/mate-panel/main.c
+++ b/mate-panel/main.c
@@ -123,6 +123,7 @@ main (int argc, char **argv)
/* open the run dialog and exit */
if (run_dialog == TRUE)
{
+ panel_init_stock_icons_and_items ();
panel_multiscreen_init ();
panel_global_config_load ();
panel_lockdown_init ();
diff --git a/mate-panel/menu.c b/mate-panel/menu.c
index fa655668..368c416c 100644
--- a/mate-panel/menu.c
+++ b/mate-panel/menu.c
@@ -55,31 +55,6 @@
#include "panel-icon-names.h"
#include "panel-schemas.h"
-typedef struct {
- GtkWidget *pixmap;
- const char *stock_id;
- GIcon *gicon;
- char *image;
- char *fallback_image;
- GtkIconTheme *icon_theme;
- GtkIconSize icon_size;
-} IconToLoad;
-
-typedef struct {
- GtkWidget *image;
- const char *stock_id;
- GIcon *gicon;
- GdkPixbuf *pixbuf;
- GtkIconSize icon_size;
-} IconToAdd;
-
-static guint load_icons_id = 0;
-static GHashTable *loaded_icons = NULL;
-static GList *icons_to_load = NULL;
-static GList *icons_to_add = NULL;
-
-static GSList *image_menu_items = NULL;
-
static GtkWidget *populate_menu_from_directory (GtkWidget *menu,
MateMenuTreeDirectory *directory);
@@ -192,47 +167,10 @@ menuitem_to_screen (GtkWidget *menuitem)
return gtk_window_get_screen (GTK_WINDOW (panel_widget->toplevel));
}
-static void
-reload_image_menu_items (void)
-{
- GSList* l;
-
- for (l = image_menu_items; l; l = l->next) {
- GtkWidget *image = l->data;
- gboolean is_mapped;
-
- is_mapped = gtk_widget_get_mapped (image);
-
- if (is_mapped)
- gtk_widget_unmap (image);
-
- gtk_image_set_from_pixbuf (GTK_IMAGE (image), NULL);
-
- if (is_mapped)
- gtk_widget_map (image);
-
- }
-}
-
-static void
-icon_theme_changed (GtkIconTheme *icon_theme,
- gpointer data)
-{
- reload_image_menu_items ();
-}
-
GtkWidget *
panel_create_menu (void)
{
GtkWidget *retval;
- static gboolean registered_icon_theme_changer = FALSE;
-
- if (!registered_icon_theme_changer) {
- registered_icon_theme_changer = TRUE;
-
- g_signal_connect (gtk_icon_theme_get_default (), "changed",
- G_CALLBACK (icon_theme_changed), NULL);
- }
retval = gtk_menu_new ();
gtk_widget_set_name (retval, "mate-panel-main-menu");
@@ -262,336 +200,6 @@ create_empty_menu (void)
}
static void
-icon_to_load_free (IconToLoad *icon)
-{
- if (!icon)
- return;
-
- if (icon->pixmap)
- g_object_unref (icon->pixmap);
- icon->pixmap = NULL;
-
- if (icon->gicon)
- g_object_unref (icon->gicon);
- icon->gicon = NULL;
-
- g_free (icon->image); icon->image = NULL;
- g_free (icon->fallback_image); icon->fallback_image = NULL;
- g_free (icon);
-}
-
-static IconToLoad *
-icon_to_load_copy (IconToLoad *icon)
-{
- IconToLoad *retval;
-
- if (!icon)
- return NULL;
-
- retval = g_new0 (IconToLoad, 1);
-
- retval->pixmap = g_object_ref (icon->pixmap);
- if (icon->gicon)
- retval->gicon = g_object_ref (icon->gicon);
- else
- retval->gicon = NULL;
- retval->image = g_strdup (icon->image);
- retval->fallback_image = g_strdup (icon->fallback_image);
- retval->stock_id = icon->stock_id;
- retval->icon_size = icon->icon_size;
-
- return retval;
-}
-
-static void
-remove_pixmap_from_loaded (gpointer data, GObject *where_the_object_was)
-{
- char *key = data;
-
- if (loaded_icons != NULL)
- g_hash_table_remove (loaded_icons, key);
-
- g_free (key);
-}
-
-GdkPixbuf *
-panel_make_menu_icon (GtkIconTheme *icon_theme,
- const char *icon,
- const char *fallback,
- int size,
- gboolean *long_operation)
-{
- GdkPixbuf *pb;
- char *file, *key;
- gboolean loaded;
-
- g_return_val_if_fail (size > 0, NULL);
-
- file = NULL;
- if (icon != NULL)
- file = panel_find_icon (icon_theme, icon, size);
- if (file == NULL && fallback != NULL)
- file = panel_find_icon (icon_theme, fallback, size);
-
- if (file == NULL)
- return NULL;
-
- if (long_operation != NULL)
- *long_operation = TRUE;
-
- pb = NULL;
-
- loaded = FALSE;
-
- key = g_strdup_printf ("%d:%s", size, file);
-
- if (loaded_icons != NULL &&
- (pb = g_hash_table_lookup (loaded_icons, key)) != NULL) {
- if (pb != NULL)
- g_object_ref (G_OBJECT (pb));
- }
-
- if (pb == NULL) {
- pb = gdk_pixbuf_new_from_file (file, NULL);
- if (pb) {
- gint width, height;
-
- width = gdk_pixbuf_get_width (pb);
- height = gdk_pixbuf_get_height (pb);
-
- /* if we want 24 and we get 22, do nothing;
- * else scale */
- if (!(size - 2 <= width && width <= size &&
- size - 2 <= height && height <= size)) {
- GdkPixbuf *tmp;
-
- tmp = gdk_pixbuf_scale_simple (pb, size, size,
- GDK_INTERP_BILINEAR);
-
- g_object_unref (pb);
- pb = tmp;
- }
- }
-
- /* add icon to the hash table so we don't load it again */
- loaded = TRUE;
- }
-
- if (pb == NULL) {
- g_free (file);
- g_free (key);
- return NULL;
- }
-
- if (loaded &&
- (gdk_pixbuf_get_width (pb) != size &&
- gdk_pixbuf_get_height (pb) != size)) {
- GdkPixbuf *pb2;
- int dest_width;
- int dest_height;
- int width;
- int height;
-
- width = gdk_pixbuf_get_width (pb);
- height = gdk_pixbuf_get_height (pb);
-
- if (height > width) {
- dest_width = (size * width) / height;
- dest_height = size;
- } else {
- dest_width = size;
- dest_height = (size * height) / width;
- }
-
- pb2 = gdk_pixbuf_scale_simple (pb, dest_width, dest_height,
- GDK_INTERP_BILINEAR);
- g_object_unref (G_OBJECT (pb));
- pb = pb2;
- }
-
- if (loaded) {
- if (loaded_icons == NULL)
- loaded_icons = g_hash_table_new_full
- (g_str_hash, g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) g_object_unref);
- g_hash_table_replace (loaded_icons,
- g_strdup (key),
- g_object_ref (G_OBJECT (pb)));
- g_object_weak_ref (G_OBJECT (pb),
- (GWeakNotify) remove_pixmap_from_loaded,
- g_strdup (key));
- } else {
- /* we didn't load from disk */
- if (long_operation != NULL)
- *long_operation = FALSE;
- }
-
- g_free (file);
- g_free (key);
-
- return pb;
-}
-
-static void
-menu_item_style_set (GtkImage *image,
- gpointer data)
-{
- GtkWidget *widget;
- GdkPixbuf *pixbuf;
- GtkIconSize icon_size = (GtkIconSize) GPOINTER_TO_INT (data);
- int icon_height;
- gboolean is_mapped;
-
- if (!gtk_icon_size_lookup (icon_size, NULL, &icon_height))
- return;
-
- pixbuf = gtk_image_get_pixbuf (image);
- if (!pixbuf)
- return;
-
- if (gdk_pixbuf_get_height (pixbuf) == icon_height)
- return;
-
- widget = GTK_WIDGET (image);
-
- is_mapped = gtk_widget_get_mapped (widget);
- if (is_mapped)
- gtk_widget_unmap (widget);
-
- gtk_image_set_from_pixbuf (image, NULL);
-
- if (is_mapped)
- gtk_widget_map (widget);
-}
-
-static void
-do_icons_to_add (void)
-{
- while (icons_to_add) {
- IconToAdd *icon_to_add = icons_to_add->data;
-
- icons_to_add = g_list_delete_link (icons_to_add, icons_to_add);
-
- if (icon_to_add->stock_id) {
- gtk_image_set_from_stock (
- GTK_IMAGE (icon_to_add->image),
- icon_to_add->stock_id,
- icon_to_add->icon_size);
- } else if (icon_to_add->gicon) {
- gtk_image_set_from_gicon (
- GTK_IMAGE (icon_to_add->image),
- icon_to_add->gicon,
- icon_to_add->icon_size);
- } else {
- g_assert (icon_to_add->pixbuf);
-
- gtk_image_set_from_pixbuf (
- GTK_IMAGE (icon_to_add->image),
- icon_to_add->pixbuf);
-
- g_signal_connect (icon_to_add->image, "style-set",
- G_CALLBACK (menu_item_style_set),
- GINT_TO_POINTER (icon_to_add->icon_size));
-
- g_object_unref (icon_to_add->pixbuf);
- }
-
- if (icon_to_add->gicon)
- g_object_unref (icon_to_add->gicon);
- g_object_unref (icon_to_add->image);
- g_free (icon_to_add);
- }
-}
-
-static gboolean
-load_icons_handler (gpointer data)
-{
- IconToLoad *icon;
- gboolean long_operation = FALSE;
-
-load_icons_handler_again:
-
- if (!icons_to_load) {
- load_icons_id = 0;
- do_icons_to_add ();
-
- return FALSE;
- }
-
- icon = icons_to_load->data;
- icons_to_load->data = NULL;
- /* pop */
- icons_to_load = g_list_delete_link (icons_to_load, icons_to_load);
-
- /* if not visible anymore, just ignore */
- if ( ! gtk_widget_get_visible (icon->pixmap)) {
- icon_to_load_free (icon);
- /* we didn't do anything long/hard, so just do this again,
- * this is fun, don't go back to main loop */
- goto load_icons_handler_again;
- }
-
- if (icon->stock_id || icon->gicon) {
- IconToAdd *icon_to_add;
-
- icon_to_add = g_new (IconToAdd, 1);
- icon_to_add->image = g_object_ref (icon->pixmap);
- icon_to_add->stock_id = icon->stock_id;
- icon_to_add->pixbuf = NULL;
- icon_to_add->icon_size = icon->icon_size;
- if (icon->gicon)
- icon_to_add->gicon = g_object_ref (icon->gicon);
- else
- icon_to_add->gicon = NULL;
-
- icons_to_add = g_list_prepend (icons_to_add, icon_to_add);
- } else {
- IconToAdd *icon_to_add;
- GdkPixbuf *pb;
- int icon_height = PANEL_DEFAULT_MENU_ICON_SIZE;
-
- gtk_icon_size_lookup (icon->icon_size, NULL, &icon_height);
-
- pb = panel_make_menu_icon (icon->icon_theme,
- icon->image,
- icon->fallback_image,
- icon_height,
- &long_operation);
- if (!pb) {
- icon_to_load_free (icon);
- if (long_operation)
- /* this may have been a long operation so jump back to
- * the main loop for a while */
- return TRUE;
- else
- /* we didn't do anything long/hard, so just do this again,
- * this is fun, don't go back to main loop */
- goto load_icons_handler_again;
- }
-
- icon_to_add = g_new (IconToAdd, 1);
- icon_to_add->image = g_object_ref (icon->pixmap);
- icon_to_add->stock_id = NULL;
- icon_to_add->gicon = NULL;
- icon_to_add->pixbuf = pb;
- icon_to_add->icon_size = icon->icon_size;
-
- icons_to_add = g_list_prepend (icons_to_add, icon_to_add);
- }
-
- icon_to_load_free (icon);
-
- if (!long_operation)
- /* we didn't do anything long/hard, so just do this again,
- * this is fun, don't go back to main loop */
- goto load_icons_handler_again;
-
- /* if still more we'll come back */
- return TRUE;
-}
-
-static void
add_app_to_panel (GtkWidget *item,
MateMenuTreeEntry *entry)
{
@@ -1128,38 +736,6 @@ drag_data_get_menu_cb (GtkWidget *widget,
g_free (uri_list);
}
-static void
-#if GTK_CHECK_VERSION (3, 0, 0)
-image_menuitem_set_size_request (GtkWidget *menuitem,
- GtkIconSize icon_size)
-#else
-image_menuitem_size_request (GtkWidget *menuitem,
- GtkRequisition *requisition,
- gpointer data)
-#endif
-{
-#if !GTK_CHECK_VERSION (3, 0, 0)
- GtkIconSize icon_size = (GtkIconSize) GPOINTER_TO_INT (data);
-#endif
- int icon_height;
- int req_height;
-
- if (!gtk_icon_size_lookup (icon_size, NULL, &icon_height))
- return;
-
- /* If we don't have a pixmap for this menuitem
- * at least make sure its the same height as
- * the rest.
- * This is a bit ugly, since we should keep this in sync with what's in
- * gtk_menu_item_size_request()
- */
- req_height = icon_height;
- req_height += (gtk_container_get_border_width (GTK_CONTAINER (menuitem)) +
- (gtk_widget_get_style (menuitem))->ythickness) * 2;
-
- gtk_widget_set_size_request (menuitem, -1, req_height);
-}
-
static char *
menu_escape_underscores_and_prepend (const char *text)
{
@@ -1222,21 +798,10 @@ setup_menuitem (GtkWidget *menuitem,
gtk_container_add (GTK_CONTAINER (menuitem), label);
if (image) {
- g_object_set_data_full (G_OBJECT (menuitem),
- "Panel:Image",
- g_object_ref (image),
- (GDestroyNotify) g_object_unref);
gtk_widget_show (image);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem),
image);
- } else if (icon_size != GTK_ICON_SIZE_INVALID)
-#if GTK_CHECK_VERSION (3, 0, 0)
- image_menuitem_set_size_request (menuitem, icon_size);
-#else
- g_signal_connect (menuitem, "size_request",
- G_CALLBACK (image_menuitem_size_request),
- GINT_TO_POINTER (icon_size));
-#endif
+ }
gtk_widget_show (menuitem);
}
@@ -1850,45 +1415,6 @@ GtkWidget* create_main_menu(PanelWidget* panel)
return main_menu;
}
-static GList *
-find_in_load_list (GtkWidget *image)
-{
- GList *li;
- for (li = icons_to_load; li != NULL; li = li->next) {
- IconToLoad *icon = li->data;
- if (icon->pixmap == image)
- return li;
- }
- return NULL;
-}
-
-static void
-image_menu_shown (GtkWidget *image, gpointer data)
-{
- IconToLoad *new_icon;
- IconToLoad *icon;
-
- icon = (IconToLoad *) data;
-
- /* if we've already handled this */
- if (gtk_image_get_storage_type (GTK_IMAGE (image)) != GTK_IMAGE_EMPTY)
- return;
-
- if (find_in_load_list (image) == NULL) {
- new_icon = icon_to_load_copy (icon);
- new_icon->icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (image));
- icons_to_load = g_list_append (icons_to_load, new_icon);
- }
- if (load_icons_id == 0)
- load_icons_id = g_idle_add (load_icons_handler, NULL);
-}
-
-static void
-image_menu_destroy (GtkWidget *image, gpointer data)
-{
- image_menu_items = g_slist_remove (image_menu_items, image);
-}
-
static void
panel_load_menu_image_deferred (GtkWidget *image_menu_item,
GtkIconSize icon_size,
@@ -1897,47 +1423,32 @@ panel_load_menu_image_deferred (GtkWidget *image_menu_item,
const char *image_filename,
const char *fallback_image_filename)
{
- IconToLoad *icon;
GtkWidget *image;
int icon_height = PANEL_DEFAULT_MENU_ICON_SIZE;
- icon = g_new (IconToLoad, 1);
-
gtk_icon_size_lookup (icon_size, NULL, &icon_height);
image = gtk_image_new ();
- gtk_widget_set_size_request (image, icon_height, icon_height);
+ g_object_set (image, "icon-size", icon_size, NULL);
+ gtk_image_set_pixel_size (GTK_IMAGE(image), icon_height);
- /* this takes over the floating ref */
- icon->pixmap = g_object_ref_sink (G_OBJECT (image));
+ GIcon *icon = NULL;
- icon->stock_id = stock_id;
- if (gicon)
- icon->gicon = g_object_ref (gicon);
- else
- icon->gicon = NULL;
- icon->image = g_strdup (image_filename);
- icon->fallback_image = g_strdup (fallback_image_filename);
- icon->icon_size = icon_size;
+ if (gicon != NULL) {
+ icon = g_object_ref (gicon);
+ } else if (stock_id != NULL ) {
+ icon = g_themed_icon_new (stock_id);
+ } else if (image_filename != NULL) {
+ icon = panel_gicon_from_icon_name (image_filename);
+ }
- gtk_widget_show (image);
+ gtk_image_set_from_gicon (GTK_IMAGE(image), icon, icon_size);
+ g_object_unref (icon);
- g_object_set_data_full (G_OBJECT (image_menu_item),
- "Panel:Image",
- g_object_ref (image),
- (GDestroyNotify) g_object_unref);
+ gtk_widget_show (image);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (image_menu_item),
image);
-
- g_signal_connect_data (image, "map",
- G_CALLBACK (image_menu_shown), icon,
- (GClosureNotify) icon_to_load_free, 0);
-
- g_signal_connect (image, "destroy",
- G_CALLBACK (image_menu_destroy), NULL);
-
- image_menu_items = g_slist_prepend (image_menu_items, image);
}
static gboolean
diff --git a/mate-panel/panel-addto.c b/mate-panel/panel-addto.c
index 5a06df8c..1c614a4d 100644
--- a/mate-panel/panel-addto.c
+++ b/mate-panel/panel-addto.c
@@ -50,6 +50,7 @@
#include "panel-addto.h"
#include "panel-icon-names.h"
#include "panel-schemas.h"
+#include "panel-stock-icons.h"
typedef struct {
PanelWidget *panel_widget;
@@ -183,7 +184,7 @@ static PanelAddtoItemInfo internal_addto_items [] = {
};
enum {
- COLUMN_ICON,
+ COLUMN_ICON_NAME,
COLUMN_TEXT,
COLUMN_DATA,
COLUMN_SEARCH,
@@ -266,18 +267,6 @@ panel_addto_make_text (const char *name,
return result;
}
-#define ICON_SIZE 32
-
-static GdkPixbuf *
-panel_addto_make_pixbuf (const char *filename)
-{
- //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);
-}
-
static void
panel_addto_drag_data_get_cb (GtkWidget *widget,
GdkDragContext *context,
@@ -301,7 +290,7 @@ panel_addto_drag_begin_cb (GtkWidget *widget,
GtkTreePath *path;
GtkTreeIter iter;
GtkTreeIter filter_iter;
- GdkPixbuf *pixbuf;
+ gchar *icon_name;
filter_model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
@@ -313,11 +302,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_NAME, &icon_name,
-1);
- gtk_drag_set_icon_pixbuf (context, pixbuf, 0, 0);
- g_object_unref (pixbuf);
+ gtk_drag_set_icon_name (context, icon_name, 0, 0);
+ g_free (icon_name);
}
static void
@@ -426,39 +415,29 @@ panel_addto_append_item (PanelAddtoDialog *dialog,
PanelAddtoItemInfo *applet)
{
char *text;
- GdkPixbuf *pixbuf;
GtkTreeIter iter;
if (applet == NULL) {
gtk_list_store_append (model, &iter);
gtk_list_store_set (model, &iter,
- COLUMN_ICON, NULL,
+ COLUMN_ICON_NAME, NULL,
COLUMN_TEXT, NULL,
COLUMN_DATA, NULL,
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_NAME, applet->icon,
COLUMN_TEXT, text,
COLUMN_DATA, applet,
COLUMN_SEARCH, applet->name,
-1);
- if (pixbuf)
- g_object_unref (pixbuf);
-
g_free (text);
}
}
@@ -504,7 +483,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_STRING,
G_TYPE_STRING,
G_TYPE_POINTER,
G_TYPE_STRING);
@@ -652,7 +631,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) {
@@ -661,17 +639,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_NAME, 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)
@@ -690,7 +664,7 @@ static void panel_addto_make_application_model(PanelAddtoDialog* dialog)
if (dialog->filter_application_model != NULL)
return;
- store = gtk_tree_store_new(NUMBER_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_STRING);
+ 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);
@@ -713,7 +687,7 @@ static void panel_addto_make_application_model(PanelAddtoDialog* dialog)
GtkTreeIter iter;
gtk_tree_store_append(store, &iter, NULL);
- gtk_tree_store_set(store, &iter, COLUMN_ICON, NULL, COLUMN_TEXT, NULL, COLUMN_DATA, NULL, COLUMN_SEARCH, NULL, -1);
+ gtk_tree_store_set(store, &iter, COLUMN_ICON_NAME, NULL, COLUMN_TEXT, NULL, COLUMN_DATA, NULL, COLUMN_SEARCH, NULL, -1);
panel_addto_make_application_list(&dialog->settings_list, root, "mate-settings.menu");
panel_addto_populate_application_model(store, NULL, dialog->settings_list);
@@ -1332,12 +1306,13 @@ panel_addto_dialog_new (PanelWidget *panel_widget)
renderer = g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF,
"xpad", 4,
"ypad", 4,
+ "stock-size", panel_add_to_icon_get_size(),
NULL);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (dialog->tree_view),
-1, NULL,
renderer,
- "pixbuf", COLUMN_ICON,
+ "icon_name", COLUMN_ICON_NAME,
NULL);
renderer = gtk_cell_renderer_text_new ();
g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
diff --git a/mate-panel/panel-run-dialog.c b/mate-panel/panel-run-dialog.c
index 01c35deb..51a6be7c 100644
--- a/mate-panel/panel-run-dialog.c
+++ b/mate-panel/panel-run-dialog.c
@@ -87,14 +87,12 @@ typedef struct {
GList *completion_items;
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 *icon;
char *desktop_path;
char *item_name;
@@ -102,8 +100,7 @@ typedef struct {
} PanelRunDialog;
enum {
- COLUMN_ICON,
- COLUMN_ICON_FILE,
+ COLUMN_GICON,
COLUMN_NAME,
COLUMN_COMMENT,
COLUMN_PATH,
@@ -188,21 +185,12 @@ panel_run_dialog_destroy (PanelRunDialog *dialog)
g_object_unref (dialog->program_list_box);
- g_slist_foreach (dialog->add_icon_paths, (GFunc) gtk_tree_path_free, NULL);
- g_slist_free (dialog->add_icon_paths);
- dialog->add_icon_paths = NULL;
-
- g_free (dialog->icon_path);
- dialog->icon_path = NULL;
+ g_clear_object (&(dialog->icon));
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;
@@ -255,39 +243,34 @@ 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 *icon,
gboolean force)
{
GdkPixbuf *pixbuf = NULL;
- if (!force && icon_path && dialog->icon_path &&
- !strcmp (icon_path, dialog->icon_path))
+ if (!force && g_icon_equal(icon, dialog->icon))
return;
- g_free (dialog->icon_path);
- dialog->icon_path = NULL;
+ g_clear_object(&(dialog->icon));
- if (icon_path) {
- GdkScreen *screen;
- GtkSettings *settings;
+ if (icon) {
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);
+ gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &size, NULL);
+
+ GtkIconTheme *icon_theme = gtk_icon_theme_get_default ();
+ GtkIconInfo *icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme, icon, size, 0);
+ pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
+#if GTK_CHECK_VERSION (3, 8, 0)
+ g_object_unref (icon_info);
+#else
+ gtk_icon_info_free (icon_info);
+#endif
+
}
if (pixbuf) {
- dialog->icon_path = g_strdup (icon_path);
+ dialog->icon = g_object_ref (icon);
/* Don't bother scaling the image if it's too small.
* Scaled looks worse than a smaller image.
@@ -298,7 +281,11 @@ panel_run_dialog_set_icon (PanelRunDialog *dialog,
//(ditto for the drag icon?)
gtk_window_set_icon (GTK_WINDOW (dialog->run_dialog), pixbuf);
+#if GTK_CHECK_VERSION (3, 2, 0)
+ gtk_drag_source_set_icon_gicon (dialog->run_dialog, dialog->icon);
+#else
gtk_drag_source_set_icon_pixbuf (dialog->run_dialog, pixbuf);
+#endif
g_object_unref (pixbuf);
} else {
panel_run_dialog_set_default_icon (dialog, TRUE);
@@ -667,7 +654,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;
@@ -691,23 +678,23 @@ panel_run_dialog_find_command_idle (PanelRunDialog *dialog)
do {
char *exec = NULL;
- char *icon = NULL;
+ GIcon *icon = NULL;
char *name = NULL;
char *comment = NULL;
gtk_tree_model_get (model, &iter,
COLUMN_EXEC, &exec,
- COLUMN_ICON_FILE, &icon,
+ COLUMN_GICON, &icon,
COLUMN_NAME, &name,
COLUMN_COMMENT, &comment,
-1);
if (!fuzzy && exec && icon &&
fuzzy_command_match (text, exec, &fuzzy)) {
- g_free (found_icon);
+ g_clear_object (&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,
@@ -729,7 +716,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);
@@ -745,7 +732,7 @@ 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);
+ g_clear_object (&found_icon);
g_free (text);
g_free (dialog->item_name);
@@ -755,56 +742,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 (MateMenuTreeEntry *a,
MateMenuTreeEntry *b)
@@ -912,8 +849,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,
@@ -943,12 +879,12 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog)
for (l = all_applications; l; l = l->next) {
MateMenuTreeEntry *entry = l->data;
GtkTreeIter iter;
- GtkTreePath *path;
+ const gchar *icon = matemenu_tree_entry_get_icon (entry);
+ GIcon *gicon = panel_gicon_from_icon_name (icon);
gtk_list_store_append (dialog->program_list_store, &iter);
gtk_list_store_set (dialog->program_list_store, &iter,
- COLUMN_ICON, NULL,
- COLUMN_ICON_FILE, matemenu_tree_entry_get_icon (entry),
+ 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),
@@ -956,9 +892,7 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog)
COLUMN_VISIBLE, TRUE,
-1);
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (dialog->program_list_store), &iter);
- if (path != NULL)
- dialog->add_icon_paths = g_slist_prepend (dialog->add_icon_paths, path);
+ g_object_unref (gicon);
matemenu_tree_item_unref (entry);
}
@@ -976,10 +910,11 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog)
COLUMN_NAME);
renderer = gtk_cell_renderer_pixbuf_new ();
+ g_object_set (renderer, "stock-size", panel_menu_icon_get_size(), NULL);
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_GICON,
NULL);
renderer = gtk_cell_renderer_text_new ();
@@ -990,15 +925,8 @@ panel_run_dialog_add_items_idle (PanelRunDialog *dialog)
gtk_tree_view_append_column (GTK_TREE_VIEW (dialog->program_list), column);
- 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;
+ return G_SOURCE_REMOVE;
}
static char *
@@ -1104,7 +1032,9 @@ 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);
+ GIcon *icon = panel_gicon_from_icon_name (temp);
+ panel_run_dialog_set_icon (dialog, icon, FALSE);
+ g_object_unref (icon);
g_free (temp);
temp = panel_key_file_get_locale_string (key_file, "Comment");
@@ -1842,9 +1772,11 @@ 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)
- panel_key_file_set_locale_string (key_file, "Icon",
- dialog->icon_path);
+ if (dialog->icon) {
+ gchar *icon_path = g_icon_to_string (dialog->icon);
+ panel_key_file_set_locale_string (key_file, "Icon", icon_path);
+ g_free (icon_path);
+ }
else
panel_key_file_set_locale_string (key_file, "Icon",
PANEL_ICON_LAUNCHER);
@@ -1893,12 +1825,12 @@ panel_run_dialog_style_set (GtkWidget *widget,
GtkStyle *prev_style,
PanelRunDialog *dialog)
{
- if (dialog->icon_path) {
- char *icon_path;
+ if (dialog->icon) {
+ GIcon *icon;
- icon_path = g_strdup (dialog->icon_path);
- panel_run_dialog_set_icon (dialog, icon_path, TRUE);
- g_free (icon_path);
+ icon = g_object_ref (dialog->icon);
+ panel_run_dialog_set_icon (dialog, icon, TRUE);
+ g_object_unref (icon);
}
}
@@ -1907,12 +1839,12 @@ panel_run_dialog_screen_changed (GtkWidget *widget,
GdkScreen *prev_screen,
PanelRunDialog *dialog)
{
- if (dialog->icon_path) {
- char *icon_path;
+ if (dialog->icon) {
+ GIcon *icon;
- icon_path = g_strdup (dialog->icon_path);
- panel_run_dialog_set_icon (dialog, icon_path, TRUE);
- g_free (icon_path);
+ icon = g_object_ref (dialog->icon);
+ panel_run_dialog_set_icon (dialog, icon, TRUE);
+ g_object_unref (icon);;
}
}
diff --git a/mate-panel/panel-stock-icons.c b/mate-panel/panel-stock-icons.c
index 2758c0a1..26639784 100644
--- a/mate-panel/panel-stock-icons.c
+++ b/mate-panel/panel-stock-icons.c
@@ -33,6 +33,7 @@
static GtkIconSize panel_menu_icon_size = 0;
static GtkIconSize panel_menu_bar_icon_size = 0;
+static GtkIconSize panel_add_to_icon_size = 0;
GtkIconSize
panel_menu_icon_get_size (void)
@@ -46,6 +47,11 @@ panel_menu_bar_icon_get_size (void)
return panel_menu_bar_icon_size;
}
+GtkIconSize panel_add_to_icon_get_size(void)
+{
+ return panel_add_to_icon_size;
+}
+
typedef struct {
char *stock_id;
char *icon;
@@ -131,6 +137,10 @@ panel_init_stock_icons_and_items (void)
PANEL_DEFAULT_MENU_BAR_ICON_SIZE,
PANEL_DEFAULT_MENU_BAR_ICON_SIZE);
+ panel_add_to_icon_size = gtk_icon_size_register ("panel-add-to",
+ PANEL_ADD_TO_DEFAULT_ICON_SIZE,
+ PANEL_ADD_TO_DEFAULT_ICON_SIZE);
+
factory = gtk_icon_factory_new ();
gtk_icon_factory_add_default (factory);
diff --git a/mate-panel/panel-stock-icons.h b/mate-panel/panel-stock-icons.h
index e5ba5942..0d07d4f3 100644
--- a/mate-panel/panel-stock-icons.h
+++ b/mate-panel/panel-stock-icons.h
@@ -38,6 +38,8 @@ extern "C" {
* Applications item in the menu bar */
#define PANEL_DEFAULT_MENU_BAR_ICON_SIZE 24
+#define PANEL_ADD_TO_DEFAULT_ICON_SIZE 32
+
/* stock icons */
#define PANEL_STOCK_FORCE_QUIT "mate-panel-force-quit"
@@ -54,6 +56,7 @@ extern "C" {
void panel_init_stock_icons_and_items (void);
GtkIconSize panel_menu_icon_get_size (void);
GtkIconSize panel_menu_bar_icon_get_size (void);
+GtkIconSize panel_add_to_icon_get_size (void);
#ifdef __cplusplus
}
diff --git a/mate-panel/panel-util.c b/mate-panel/panel-util.c
index 4406b755..850ea8c1 100644
--- a/mate-panel/panel-util.c
+++ b/mate-panel/panel-util.c
@@ -256,6 +256,28 @@ panel_uri_exists (const char *uri)
return ret;
}
+GIcon *
+panel_gicon_from_icon_name (const char *icon_name) {
+ GIcon *icon = NULL;
+ if (g_path_is_absolute(icon_name)) {
+ if (!g_file_test (icon_name, G_FILE_TEST_EXISTS)) {
+ gchar *name = g_path_get_basename (icon_name);
+ icon = g_themed_icon_new (name);
+ g_free (name);
+ } else {
+ GFile *gfile = g_file_new_for_path (icon_name);
+ icon = g_file_icon_new (gfile);
+ g_object_unref (gfile);
+ }
+ }
+ else {
+ gchar *name = panel_xdg_icon_remove_extension (icon_name);
+ icon = g_themed_icon_new (name);
+ g_free (name);
+ }
+ return icon;
+}
+
char *
panel_find_icon (GtkIconTheme *icon_theme,
const char *icon_name,
diff --git a/mate-panel/panel-util.h b/mate-panel/panel-util.h
index 364e8b57..d30c9810 100644
--- a/mate-panel/panel-util.h
+++ b/mate-panel/panel-util.h
@@ -27,6 +27,7 @@ void panel_lock_screen_action (GdkScreen *screen,
const char *action);
gboolean panel_lock_screen_action_available (const char *action);
+GIcon * panel_gicon_from_icon_name (const char *icon_name);
char * panel_find_icon (GtkIconTheme *icon_theme,
const char *icon_name,
int size);