[Xfce4-commits] <thunar:master> Use GIcons in the UCA plugin (bug #8979).
Nick Schermer
noreply at xfce.org
Tue Sep 25 20:52:01 CEST 2012
Updating branch refs/heads/master
to 098ee25529c04957d93ac42969271f47585e507e (commit)
from 370c97f880470133fd3e974308e2cfe0703515a5 (commit)
commit 098ee25529c04957d93ac42969271f47585e507e
Author: Nick Schermer <nick at xfce.org>
Date: Tue Sep 25 20:49:27 2012 +0200
Use GIcons in the UCA plugin (bug #8979).
This removed the icon lookup code, we cache the GIcon and
it makes custom icon locations work again.
plugins/thunar-uca/thunar-uca-chooser.c | 2 +-
plugins/thunar-uca/thunar-uca-editor.c | 44 +++++++---------------------
plugins/thunar-uca/thunar-uca-model.c | 47 +++++++++++++++++++++---------
plugins/thunar-uca/thunar-uca-model.h | 3 +-
plugins/thunar-uca/thunar-uca-provider.c | 11 +++++--
5 files changed, 55 insertions(+), 52 deletions(-)
diff --git a/plugins/thunar-uca/thunar-uca-chooser.c b/plugins/thunar-uca/thunar-uca-chooser.c
index f58799d..aef9014 100644
--- a/plugins/thunar-uca/thunar-uca-chooser.c
+++ b/plugins/thunar-uca/thunar-uca-chooser.c
@@ -159,7 +159,7 @@ thunar_uca_chooser_init (ThunarUcaChooser *uca_chooser)
renderer = g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF, "stock-size", GTK_ICON_SIZE_DND, "xpad", 2, "ypad", 2, NULL);
gtk_tree_view_column_pack_start (column, renderer, FALSE);
- gtk_tree_view_column_set_attributes (column, renderer, "icon-name", THUNAR_UCA_MODEL_COLUMN_ICON, NULL);
+ gtk_tree_view_column_set_attributes (column, renderer, "gicon", THUNAR_UCA_MODEL_COLUMN_GICON, NULL);
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column, renderer, TRUE);
diff --git a/plugins/thunar-uca/thunar-uca-editor.c b/plugins/thunar-uca/thunar-uca-editor.c
index 00add99..39e119e 100644
--- a/plugins/thunar-uca/thunar-uca-editor.c
+++ b/plugins/thunar-uca/thunar-uca-editor.c
@@ -647,11 +647,9 @@ static void
thunar_uca_editor_set_icon_name (ThunarUcaEditor *uca_editor,
const gchar *icon_name)
{
- GtkIconTheme *icon_theme;
- GdkPixbuf *icon_scaled;
- GdkPixbuf *icon = NULL;
- GtkWidget *image;
- GtkWidget *label;
+ GIcon *icon = NULL;
+ GtkWidget *image;
+ GtkWidget *label;
g_return_if_fail (THUNAR_UCA_IS_EDITOR (uca_editor));
@@ -659,34 +657,14 @@ thunar_uca_editor_set_icon_name (ThunarUcaEditor *uca_editor,
if (GTK_BIN (uca_editor->icon_button)->child != NULL)
gtk_widget_destroy (GTK_BIN (uca_editor->icon_button)->child);
- /* try to load the icon */
- if (G_LIKELY (icon_name != NULL && g_path_is_absolute (icon_name)))
- {
- /* load the icon from the file */
- icon = exo_gdk_pixbuf_new_from_file_at_max_size (icon_name, 48, 48, TRUE, NULL);
- }
- else if (icon_name != NULL)
- {
- /* determine the appropriate icon theme */
- if (G_LIKELY (gtk_widget_has_screen (GTK_WIDGET (uca_editor))))
- icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (uca_editor)));
- else
- icon_theme = gtk_icon_theme_get_default ();
-
- /* try to load the named icon */
- icon = gtk_icon_theme_load_icon (icon_theme, icon_name, 48, 0, NULL);
- }
-
/* setup the icon button */
+ if (icon_name != NULL)
+ icon = g_icon_new_for_string (icon_name, NULL);
+
if (G_LIKELY (icon != NULL))
{
- /* scale down the icon if required */
- icon_scaled = exo_gdk_pixbuf_scale_down (icon, TRUE, 48, 48);
- g_object_unref (G_OBJECT (icon));
- icon = icon_scaled;
-
/* setup an image for the icon */
- image = gtk_image_new_from_pixbuf (icon);
+ image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
gtk_container_add (GTK_CONTAINER (uca_editor->icon_button), image);
gtk_widget_show (image);
@@ -769,7 +747,7 @@ thunar_uca_editor_load (ThunarUcaEditor *uca_editor,
gchar *description;
gchar *patterns;
gchar *command;
- gchar *icon;
+ gchar *icon_name;
gchar *name;
gboolean startup_notify;
@@ -783,7 +761,7 @@ thunar_uca_editor_load (ThunarUcaEditor *uca_editor,
THUNAR_UCA_MODEL_COLUMN_PATTERNS, &patterns,
THUNAR_UCA_MODEL_COLUMN_COMMAND, &command,
THUNAR_UCA_MODEL_COLUMN_TYPES, &types,
- THUNAR_UCA_MODEL_COLUMN_ICON, &icon,
+ THUNAR_UCA_MODEL_COLUMN_ICON_NAME, &icon_name,
THUNAR_UCA_MODEL_COLUMN_NAME, &name,
THUNAR_UCA_MODEL_COLUMN_STARTUP_NOTIFY, &startup_notify,
-1);
@@ -792,7 +770,7 @@ thunar_uca_editor_load (ThunarUcaEditor *uca_editor,
thunar_uca_editor_set_types (uca_editor, types);
/* setup the new icon */
- thunar_uca_editor_set_icon_name (uca_editor, icon);
+ thunar_uca_editor_set_icon_name (uca_editor, icon_name);
/* apply the new values */
gtk_entry_set_text (GTK_ENTRY (uca_editor->description_entry), (description != NULL) ? description : "");
@@ -805,7 +783,7 @@ thunar_uca_editor_load (ThunarUcaEditor *uca_editor,
g_free (description);
g_free (patterns);
g_free (command);
- g_free (icon);
+ g_free (icon_name);
g_free (name);
}
diff --git a/plugins/thunar-uca/thunar-uca-model.c b/plugins/thunar-uca/thunar-uca-model.c
index aa388b0..d084b28 100644
--- a/plugins/thunar-uca/thunar-uca-model.c
+++ b/plugins/thunar-uca/thunar-uca-model.c
@@ -49,6 +49,8 @@
#include <gtk/gtk.h>
+#include <exo/exo.h>
+
#include <libxfce4util/libxfce4util.h>
#include <thunar-uca/thunar-uca-model.h>
@@ -160,7 +162,8 @@ struct _ThunarUcaModelItem
{
gchar *name;
gchar *description;
- gchar *icon;
+ gchar *icon_name;
+ GIcon *gicon;
gchar *command;
guint startup_notify : 1;
gchar **patterns;
@@ -180,7 +183,7 @@ typedef struct
GString *name;
gboolean name_use;
guint name_match;
- GString *icon;
+ GString *icon_name;
GString *command;
GString *patterns;
GString *description;
@@ -319,7 +322,10 @@ thunar_uca_model_get_column_type (GtkTreeModel *tree_model,
case THUNAR_UCA_MODEL_COLUMN_DESCRIPTION:
return G_TYPE_STRING;
- case THUNAR_UCA_MODEL_COLUMN_ICON:
+ case THUNAR_UCA_MODEL_COLUMN_GICON:
+ return G_TYPE_ICON;
+
+ case THUNAR_UCA_MODEL_COLUMN_ICON_NAME:
return G_TYPE_STRING;
case THUNAR_UCA_MODEL_COLUMN_COMMAND:
@@ -409,8 +415,18 @@ thunar_uca_model_get_value (GtkTreeModel *tree_model,
g_value_set_static_string (value, item->description);
break;
- case THUNAR_UCA_MODEL_COLUMN_ICON:
- g_value_set_static_string (value, item->icon);
+ case THUNAR_UCA_MODEL_COLUMN_GICON:
+ if (item->gicon == NULL && item->icon_name != NULL)
+ {
+ /* cache gicon from the name */
+ item->gicon = g_icon_new_for_string (item->icon_name, NULL);
+ }
+
+ g_value_set_object (value, item->gicon);
+ break;
+
+ case THUNAR_UCA_MODEL_COLUMN_ICON_NAME:
+ g_value_set_static_string (value, item->icon_name);
break;
case THUNAR_UCA_MODEL_COLUMN_COMMAND:
@@ -554,7 +570,7 @@ thunar_uca_model_load_from_file (ThunarUcaModel *uca_model,
parser.model = uca_model;
parser.locale = g_strdup (setlocale (LC_MESSAGES, NULL));
parser.name = g_string_new (NULL);
- parser.icon = g_string_new (NULL);
+ parser.icon_name = g_string_new (NULL);
parser.command = g_string_new (NULL);
parser.patterns = g_string_new (NULL);
parser.description = g_string_new (NULL);
@@ -571,7 +587,7 @@ thunar_uca_model_load_from_file (ThunarUcaModel *uca_model,
g_string_free (parser.description, TRUE);
g_string_free (parser.patterns, TRUE);
g_string_free (parser.command, TRUE);
- g_string_free (parser.icon, TRUE);
+ g_string_free (parser.icon_name, TRUE);
g_string_free (parser.name, TRUE);
g_free (parser.locale);
xfce_stack_free (parser.stack);
@@ -590,7 +606,10 @@ thunar_uca_model_item_reset (ThunarUcaModelItem *item)
g_free (item->description);
g_free (item->command);
g_free (item->name);
- g_free (item->icon);
+ g_free (item->icon_name);
+
+ if (item->gicon != NULL)
+ g_object_unref (item->gicon);
/* ...and reset the item memory */
memset (item, 0, sizeof (*item));
@@ -635,7 +654,7 @@ start_element_handler (GMarkupParseContext *context,
parser->description_match = XFCE_LOCALE_NO_MATCH;
parser->types = 0;
parser->startup_notify = FALSE;
- g_string_truncate (parser->icon, 0);
+ g_string_truncate (parser->icon_name, 0);
g_string_truncate (parser->name, 0);
g_string_truncate (parser->command, 0);
g_string_truncate (parser->patterns, 0);
@@ -678,7 +697,7 @@ start_element_handler (GMarkupParseContext *context,
}
else if (strcmp (element_name, "icon") == 0)
{
- g_string_truncate (parser->icon, 0);
+ g_string_truncate (parser->icon_name, 0);
xfce_stack_push (parser->stack, PARSER_ICON);
}
else if (strcmp (element_name, "command") == 0)
@@ -800,7 +819,7 @@ end_element_handler (GMarkupParseContext *context,
thunar_uca_model_update (parser->model, &iter,
parser->name->str,
parser->description->str,
- parser->icon->str,
+ parser->icon_name->str,
parser->command->str,
parser->startup_notify,
parser->patterns->str,
@@ -901,7 +920,7 @@ text_handler (GMarkupParseContext *context,
break;
case PARSER_ICON:
- g_string_append_len (parser->icon, text, text_len);
+ g_string_append_len (parser->icon_name, text, text_len);
break;
case PARSER_COMMAND:
@@ -1257,7 +1276,7 @@ thunar_uca_model_update (ThunarUcaModel *uca_model,
if (G_LIKELY (name != NULL && *name != '\0'))
item->name = g_strdup (name);
if (G_LIKELY (icon != NULL && *icon != '\0'))
- item->icon = g_strdup (icon);
+ item->icon_name = g_strdup (icon);
if (G_LIKELY (command != NULL && *command != '\0'))
item->command = g_strdup (command);
if (G_LIKELY (description != NULL && *description != '\0'))
@@ -1351,7 +1370,7 @@ thunar_uca_model_save (ThunarUcaModel *uca_model,
"\t<command>%s</command>\n"
"\t<description>%s</description>\n"
"\t<patterns>%s</patterns>\n",
- (item->icon != NULL) ? item->icon : "",
+ (item->icon_name != NULL) ? item->icon_name : "",
(item->name != NULL) ? item->name : "",
(item->command != NULL) ? item->command : "",
(item->description != NULL) ? item->description : "",
diff --git a/plugins/thunar-uca/thunar-uca-model.h b/plugins/thunar-uca/thunar-uca-model.h
index 9bef6df..46b3c37 100644
--- a/plugins/thunar-uca/thunar-uca-model.h
+++ b/plugins/thunar-uca/thunar-uca-model.h
@@ -39,7 +39,8 @@ typedef enum
{
THUNAR_UCA_MODEL_COLUMN_NAME,
THUNAR_UCA_MODEL_COLUMN_DESCRIPTION,
- THUNAR_UCA_MODEL_COLUMN_ICON,
+ THUNAR_UCA_MODEL_COLUMN_GICON,
+ THUNAR_UCA_MODEL_COLUMN_ICON_NAME,
THUNAR_UCA_MODEL_COLUMN_COMMAND,
THUNAR_UCA_MODEL_COLUMN_STARTUP_NOTIFY,
THUNAR_UCA_MODEL_COLUMN_PATTERNS,
diff --git a/plugins/thunar-uca/thunar-uca-provider.c b/plugins/thunar-uca/thunar-uca-provider.c
index 3ac481d..d6d71f3 100644
--- a/plugins/thunar-uca/thunar-uca-provider.c
+++ b/plugins/thunar-uca/thunar-uca-provider.c
@@ -201,6 +201,7 @@ thunar_uca_provider_get_file_actions (ThunarxMenuProvider *menu_provider,
gchar *tooltip;
gchar *label;
gchar *name;
+ GIcon *gicon;
paths = thunar_uca_model_match (uca_provider->model, files);
for (lp = g_list_last (paths); lp != NULL; lp = lp->prev)
@@ -211,7 +212,8 @@ thunar_uca_provider_get_file_actions (ThunarxMenuProvider *menu_provider,
/* determine the label, tooltip and stock-id for the item */
gtk_tree_model_get (GTK_TREE_MODEL (uca_provider->model), &iter,
THUNAR_UCA_MODEL_COLUMN_NAME, &label,
- THUNAR_UCA_MODEL_COLUMN_ICON, &icon_name,
+ THUNAR_UCA_MODEL_COLUMN_ICON_NAME, &icon_name,
+ THUNAR_UCA_MODEL_COLUMN_GICON, &gicon,
THUNAR_UCA_MODEL_COLUMN_DESCRIPTION, &tooltip,
-1);
@@ -220,7 +222,7 @@ thunar_uca_provider_get_file_actions (ThunarxMenuProvider *menu_provider,
/* create the new action with the given parameters */
action = gtk_action_new (name, label, tooltip, NULL);
- gtk_action_set_icon_name (action, icon_name);
+ gtk_action_set_gicon (action, gicon);
/* grab a tree row reference on the given path */
row = gtk_tree_row_reference_new (GTK_TREE_MODEL (uca_provider->model), lp->data);
@@ -247,6 +249,9 @@ thunar_uca_provider_get_file_actions (ThunarxMenuProvider *menu_provider,
g_free (tooltip);
g_free (label);
g_free (name);
+
+ if (gicon != NULL)
+ g_object_unref (G_OBJECT (gicon));
}
/* release the tree path */
@@ -332,7 +337,7 @@ thunar_uca_provider_activated (ThunarUcaProvider *uca_provider,
{
/* get the icon name and whether startup notification is active */
gtk_tree_model_get (GTK_TREE_MODEL (uca_provider->model), &iter,
- THUNAR_UCA_MODEL_COLUMN_ICON, &icon_name,
+ THUNAR_UCA_MODEL_COLUMN_ICON_NAME, &icon_name,
THUNAR_UCA_MODEL_COLUMN_STARTUP_NOTIFY, &startup_notify,
-1);
More information about the Xfce4-commits
mailing list