diff options
author | Shaun McCance <shaunm@gnome.org> | 2011-02-13 14:56:41 -0500 |
---|---|---|
committer | Shaun McCance <shaunm@gnome.org> | 2011-02-13 14:57:26 -0500 |
commit | a4e46163c569c9882c2fc9984fc245839c11d6dc (patch) | |
tree | 9458413b29735bd4a5138d1ffcdf28c69f3e411f | |
parent | 585642d05f6b92949e04304beb722f3079dfe8d7 (diff) | |
download | yelp-a4e46163c569c9882c2fc9984fc245839c11d6dc.tar.gz |
yelp-settings: Putting symbolic icon loading into YelpSettings
-rw-r--r-- | libyelp/yelp-location-entry.c | 115 | ||||
-rw-r--r-- | libyelp/yelp-settings.c | 60 | ||||
-rw-r--r-- | libyelp/yelp-settings.h | 4 |
3 files changed, 99 insertions, 80 deletions
diff --git a/libyelp/yelp-location-entry.c b/libyelp/yelp-location-entry.c index 3002a02e..8518116a 100644 --- a/libyelp/yelp-location-entry.c +++ b/libyelp/yelp-location-entry.c @@ -192,10 +192,6 @@ struct _YelpLocationEntryPrivate guint pulse; gulong bookmarks_changed; - GdkPixbuf *icon_edit_clear; - GdkPixbuf *icon_edit_find; - GdkPixbuf *icon_bookmark_add; - GdkPixbuf *icon_bookmark_remove; gboolean icon_is_clear; }; @@ -375,55 +371,10 @@ yelp_location_entry_class_init (YelpLocationEntryClass *klass) static void yelp_location_entry_init (YelpLocationEntry *entry) { - YelpSettings *settings; - GtkIconTheme *theme; - GtkIconInfo *icon; - gchar *color; - GdkRGBA gray, white, border, fill; YelpLocationEntryPrivate *priv = GET_PRIV (entry); priv->search_mode = FALSE; g_object_set (entry, "entry-text-column", HISTORY_COL_TITLE, NULL); - - settings = yelp_settings_get_default (); - g_object_get (settings, "gtk-icon-theme", &theme, NULL); - - color = yelp_settings_get_color (settings, YELP_SETTINGS_COLOR_GRAY_BORDER); - gdk_rgba_parse (&gray, color); - g_free (color); - color = yelp_settings_get_color (settings, YELP_SETTINGS_COLOR_BASE); - gdk_rgba_parse (&white, color); - g_free (color); - color = yelp_settings_get_color (settings, YELP_SETTINGS_COLOR_YELLOW_BORDER); - gdk_rgba_parse (&border, color); - g_free (color); - color = yelp_settings_get_color (settings, YELP_SETTINGS_COLOR_YELLOW_BASE); - gdk_rgba_parse (&fill, color); - g_free (color); - - icon = gtk_icon_theme_lookup_icon (theme, "edit-clear-symbolic", 16, - GTK_ICON_LOOKUP_FORCE_SVG); - priv->icon_edit_clear = gtk_icon_info_load_symbolic (icon, &gray, - NULL, NULL, NULL, - NULL, NULL); - gtk_icon_info_free (icon); - - icon = gtk_icon_theme_lookup_icon (theme, "edit-find-symbolic", 16, - GTK_ICON_LOOKUP_FORCE_SVG); - priv->icon_edit_find = gtk_icon_info_load_symbolic (icon, &gray, - NULL, NULL, NULL, - NULL, NULL); - gtk_icon_info_free (icon); - - icon = gtk_icon_theme_lookup_icon (theme, "yelp-bookmark-symbolic", 16, - GTK_ICON_LOOKUP_FORCE_SVG); - priv->icon_bookmark_add = gtk_icon_info_load_symbolic (icon, &gray, &white, - NULL, NULL, NULL, NULL); - priv->icon_bookmark_remove = gtk_icon_info_load_symbolic (icon, &border, &fill, - NULL, NULL, NULL, NULL); - gtk_icon_info_free (icon); - - g_object_unref (theme); } static void @@ -580,26 +531,6 @@ location_entry_dispose (GObject *object) priv->pulse = 0; } - if (priv->icon_edit_clear) { - g_object_unref (priv->icon_edit_clear); - priv->icon_edit_clear = NULL; - } - - if (priv->icon_edit_find) { - g_object_unref (priv->icon_edit_find); - priv->icon_edit_find = NULL; - } - - if (priv->icon_bookmark_add) { - g_object_unref (priv->icon_bookmark_add); - priv->icon_bookmark_add = NULL; - } - - if (priv->icon_bookmark_remove) { - g_object_unref (priv->icon_bookmark_remove); - priv->icon_bookmark_remove = NULL; - } - G_OBJECT_CLASS (yelp_location_entry_parent_class)->dispose (object); } @@ -828,12 +759,18 @@ location_entry_set_entry (YelpLocationEntry *entry, gboolean emit) gchar *icon_name; if (priv->search_mode) { + YelpSettings *settings = yelp_settings_get_default (); + GdkPixbuf *pixbuf; + pixbuf = yelp_settings_get_icon_pixbuf (settings, "system-search"); gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (priv->text_entry), GTK_ENTRY_ICON_PRIMARY, - priv->icon_edit_find); + pixbuf); + g_object_unref (pixbuf); + pixbuf = yelp_settings_get_icon_pixbuf (settings, "edit-clear"); gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (priv->text_entry), GTK_ENTRY_ICON_SECONDARY, - priv->icon_edit_clear); + pixbuf); + g_object_unref (pixbuf); gtk_entry_set_icon_tooltip_text (GTK_ENTRY (priv->text_entry), GTK_ENTRY_ICON_SECONDARY, _("Clear the search text")); @@ -873,18 +810,25 @@ location_entry_set_entry (YelpLocationEntry *entry, gboolean emit) icon_name); } if (priv->bookmarks && doc_uri && page_id) { + GdkPixbuf *pixbuf; if (!yelp_bookmarks_is_bookmarked (priv->bookmarks, doc_uri, page_id)) { + pixbuf = yelp_settings_get_icon_pixbuf (yelp_settings_get_default (), + "yelp-bookmark-add"); gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (priv->text_entry), GTK_ENTRY_ICON_SECONDARY, - priv->icon_bookmark_add); + pixbuf); + g_object_unref (pixbuf); gtk_entry_set_icon_tooltip_text (GTK_ENTRY (priv->text_entry), GTK_ENTRY_ICON_SECONDARY, _("Bookmark this page")); } else { + pixbuf = yelp_settings_get_icon_pixbuf (yelp_settings_get_default (), + "yelp-bookmark-remove"); gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (priv->text_entry), GTK_ENTRY_ICON_SECONDARY, - priv->icon_bookmark_remove); + pixbuf); + g_object_unref (pixbuf); gtk_entry_set_icon_tooltip_text (GTK_ENTRY (priv->text_entry), GTK_ENTRY_ICON_SECONDARY, _("Remove bookmark")); @@ -1130,13 +1074,13 @@ cell_set_bookmark_icon (GtkCellLayout *layout, YelpLocationEntryPrivate *priv = GET_PRIV (entry); if (priv->bookmarks == NULL) { - g_object_set (cell, "icon-name", NULL, NULL); + g_object_set (cell, "pixbuf", NULL, NULL); return; } gtk_tree_model_get (model, iter, HISTORY_COL_FLAGS, &flags, -1); if (flags & (LOCATION_ENTRY_IS_SEPARATOR | LOCATION_ENTRY_IS_SEARCH)) { - g_object_set (cell, "icon-name", NULL, NULL); + g_object_set (cell, "pixbuf", NULL, NULL); return; } @@ -1145,10 +1089,14 @@ cell_set_bookmark_icon (GtkCellLayout *layout, HISTORY_COL_PAGE, &page_id, -1); if (doc_uri && page_id && - yelp_bookmarks_is_bookmarked (priv->bookmarks, doc_uri, page_id)) - g_object_set (cell, "icon-name", "bookmark", NULL); + yelp_bookmarks_is_bookmarked (priv->bookmarks, doc_uri, page_id)) { + GdkPixbuf *pixbuf = yelp_settings_get_icon_pixbuf (yelp_settings_get_default (), + "yelp-bookmark-remove"); + g_object_set (cell, "pixbuf", pixbuf, NULL); + g_object_unref (pixbuf); + } else - g_object_set (cell, "icon-name", NULL, NULL); + g_object_set (cell, "pixbuf", NULL, NULL); g_free (doc_uri); g_free (page_id); @@ -1565,18 +1513,25 @@ bookmarks_changed (YelpBookmarks *bookmarks, HISTORY_COL_PAGE, &page_id, -1); if (this_uri && g_str_equal (this_uri, doc_uri) && page_id) { + GdkPixbuf *pixbuf; if (!yelp_bookmarks_is_bookmarked (priv->bookmarks, doc_uri, page_id)) { + pixbuf = yelp_settings_get_icon_pixbuf (yelp_settings_get_default (), + "yelp-bookmark-add"); gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (priv->text_entry), GTK_ENTRY_ICON_SECONDARY, - priv->icon_bookmark_add); + pixbuf); + g_object_unref (pixbuf); gtk_entry_set_icon_tooltip_text (GTK_ENTRY (priv->text_entry), GTK_ENTRY_ICON_SECONDARY, _("Bookmark this page")); } else { + pixbuf = yelp_settings_get_icon_pixbuf (yelp_settings_get_default (), + "yelp-bookmark-remove"); gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (priv->text_entry), GTK_ENTRY_ICON_SECONDARY, - priv->icon_bookmark_remove); + pixbuf); + g_object_unref (pixbuf); gtk_entry_set_icon_tooltip_text (GTK_ENTRY (priv->text_entry), GTK_ENTRY_ICON_SECONDARY, _("Remove bookmark")); diff --git a/libyelp/yelp-settings.c b/libyelp/yelp-settings.c index b1f2f909..1b8f4d01 100644 --- a/libyelp/yelp-settings.c +++ b/libyelp/yelp-settings.c @@ -36,6 +36,8 @@ struct _YelpSettingsPriv { gchar *icons[YELP_SETTINGS_NUM_ICONS]; gint icon_size; + GHashTable *pixbufs; + GtkSettings *gtk_settings; GtkIconTheme *gtk_icon_theme; @@ -223,6 +225,9 @@ yelp_settings_init (YelpSettings *settings) settings->priv->mutex = g_mutex_new (); settings->priv->icon_size = 24; + settings->priv->pixbufs = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, g_object_unref); + for (i = 0; i < YELP_SETTINGS_NUM_ICONS; i++) settings->priv->icons[i] = NULL; for (i = 0; i < YELP_SETTINGS_NUM_FONTS; i++) { @@ -239,6 +244,11 @@ yelp_settings_dispose (GObject *object) { YelpSettings *settings = YELP_SETTINGS (object); + if (settings->priv->pixbufs != NULL) { + g_hash_table_destroy (settings->priv->pixbufs); + settings->priv->pixbufs; + } + G_OBJECT_CLASS (yelp_settings_parent_class)->dispose (object); } @@ -676,6 +686,20 @@ yelp_settings_get_icon_param (YelpSettingsIcon icon) /******************************************************************************/ +GdkPixbuf * +yelp_settings_get_icon_pixbuf (YelpSettings *settings, + const gchar *icon_name) +{ + GdkPixbuf *pixbuf; + + pixbuf = g_hash_table_lookup (settings->priv->pixbufs, icon_name); + if (pixbuf != NULL) + return g_object_ref (pixbuf); + + return gtk_icon_theme_load_icon (settings->priv->gtk_icon_theme, + icon_name, 16, 0, NULL); +} + gboolean yelp_settings_get_show_text_cursor (YelpSettings *settings) { @@ -916,9 +940,12 @@ icon_theme_changed (GtkIconTheme *theme, { GtkIconInfo *info; gint i; + GdkPixbuf *pixbuf; + GdkRGBA base, gray_border, yellow_border; g_mutex_lock (settings->priv->mutex); + /* Set Yelp's note icons */ for (i = 0; i < YELP_SETTINGS_NUM_ICONS; i++) { if (settings->priv->icons[i] != NULL) g_free (settings->priv->icons[i]); @@ -936,6 +963,39 @@ icon_theme_changed (GtkIconTheme *theme, } } + /* Set pixbufs for named icons */ + gdk_rgba_parse (&base, settings->priv->colors[YELP_SETTINGS_COLOR_BASE]); + gdk_rgba_parse (&gray_border, settings->priv->colors[YELP_SETTINGS_COLOR_GRAY_BORDER]); + gdk_rgba_parse (&yellow_border, settings->priv->colors[YELP_SETTINGS_COLOR_YELLOW_BORDER]); + + info = gtk_icon_theme_lookup_icon (theme, "edit-clear-symbolic", 16, + GTK_ICON_LOOKUP_FORCE_SVG); + pixbuf = gtk_icon_info_load_symbolic (info, &gray_border, + NULL, NULL, NULL, + NULL, NULL); + g_hash_table_replace (settings->priv->pixbufs, g_strdup ("edit-clear"), pixbuf); + gtk_icon_info_free (info); + + info = gtk_icon_theme_lookup_icon (theme, "edit-find-symbolic", 16, + GTK_ICON_LOOKUP_FORCE_SVG); + pixbuf = gtk_icon_info_load_symbolic (info, &gray_border, + NULL, NULL, NULL, + NULL, NULL); + g_hash_table_replace (settings->priv->pixbufs, g_strdup ("system-search"), pixbuf); + gtk_icon_info_free (info); + + info = gtk_icon_theme_lookup_icon (theme, "yelp-bookmark-symbolic", 16, + GTK_ICON_LOOKUP_FORCE_SVG); + pixbuf = gtk_icon_info_load_symbolic (info, + &gray_border, &base, + NULL, NULL, NULL, NULL); + g_hash_table_replace (settings->priv->pixbufs, g_strdup ("yelp-bookmark-add"), pixbuf); + pixbuf = gtk_icon_info_load_symbolic (info, + &gray_border, &yellow_border, + NULL, NULL, NULL, NULL); + g_hash_table_replace (settings->priv->pixbufs, g_strdup ("yelp-bookmark-remove"), pixbuf); + gtk_icon_info_free (info); + g_mutex_unlock (settings->priv->mutex); g_signal_emit (settings, settings_signals[ICONS_CHANGED], 0); diff --git a/libyelp/yelp-settings.h b/libyelp/yelp-settings.h index bf6af532..c43f10ab 100644 --- a/libyelp/yelp-settings.h +++ b/libyelp/yelp-settings.h @@ -24,6 +24,7 @@ #define __YELP_SETTINGS_H__ #include <glib-object.h> +#include <gtk/gtk.h> G_BEGIN_DECLS @@ -118,6 +119,9 @@ gchar ** yelp_settings_get_all_params (YelpSettings *sett gint extra, gint *end); +GdkPixbuf * yelp_settings_get_icon_pixbuf (YelpSettings *settings, + const gchar *icon_name); + gboolean yelp_settings_get_show_text_cursor (YelpSettings *settings); void yelp_settings_set_show_text_cursor (YelpSettings *settings, gboolean show); |