diff options
Diffstat (limited to 'stock.c')
-rw-r--r-- | stock.c | 124 |
1 files changed, 70 insertions, 54 deletions
@@ -1,64 +1,80 @@ /* - * Based on GAIM's stock.c - * Copyright (C) 2002-2003, Christian Hammond <chipx86@gnupdate.org> + * HardInfo - Displays System Information + * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> * - * Also distributed under GNU GPL version 2. - */ - + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + #include <gtk/gtk.h> -#include "stock.h" -#include "hardinfo.h" -#include "config.h" - -static struct StockIcon { - const char *name; - const char *filename; -} const stock_icons[] = { - { HI_ABOUT, "stock-about-16.png" }, - { HI_DETAILS, "stock-details.png" } -}; +#include <stock.h> +#include <iconcache.h> -const GtkStockItem stock_items[] = { - { HI_ABOUT, "About...", 0, 0, NULL }, - { HI_DETAILS, "_Details...", 0, 0, NULL } +static struct { + gchar *filename; + gchar *stock_id; +} stock_icons[] = { + { "report.png", HI_STOCK_REPORT} }; -static gint stock_icon_count = sizeof stock_icons / sizeof(*stock_icons); -static gint stock_item_count = sizeof stock_items / sizeof(*stock_items); -static gboolean stock_inited = FALSE; +static GtkIconFactory *icon_factory; -void hi_stock_init(void) +void stock_icon_register(gchar *filename, gchar *stock_id) { - GtkIconFactory *ift; - int i; - GtkWidget *win; - - if (stock_inited) return; - - ift = gtk_icon_factory_new(); - gtk_icon_factory_add_default(ift); - - win = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_widget_realize(win); - - for (i = 0; i < stock_icon_count; i++) { - GdkPixbuf *pixbuf; - GtkIconSet *iconset; - gchar *filename; - - filename = g_strdup_printf("%s/%s", IMG_PREFIX, stock_icons[i].filename); - pixbuf = gdk_pixbuf_new_from_file(filename, NULL); - g_free(filename); - - iconset = gtk_icon_set_new_from_pixbuf(pixbuf); - gtk_icon_factory_add(ift, stock_icons[i].name, iconset); - gtk_icon_set_unref(iconset); - } - - gtk_widget_destroy(win); - g_object_unref(G_OBJECT(ift)); - gtk_stock_add_static(stock_items, stock_item_count); - - stock_inited = TRUE; + GtkIconSet *icon_set; + GtkIconSource *icon_source; + + icon_set = gtk_icon_set_new(); + icon_source = gtk_icon_source_new(); + + gtk_icon_source_set_pixbuf(icon_source, icon_cache_get_pixbuf(filename)); + gtk_icon_set_add_source(icon_set, icon_source); + gtk_icon_source_free(icon_source); + + gtk_icon_factory_add(icon_factory, stock_id, icon_set); + + gtk_icon_set_unref(icon_set); } +void stock_icon_register_pixbuf(GdkPixbuf *pixbuf, gchar *stock_id) +{ + GtkIconSet *icon_set; + GtkIconSource *icon_source; + + icon_set = gtk_icon_set_new(); + icon_source = gtk_icon_source_new(); + + gtk_icon_source_set_pixbuf(icon_source, pixbuf); + gtk_icon_set_add_source(icon_set, icon_source); + gtk_icon_source_free(icon_source); + + gtk_icon_factory_add(icon_factory, stock_id, icon_set); + + gtk_icon_set_unref(icon_set); +} + +void stock_icons_init(void) +{ + gint i; + guint n_stock_icons = G_N_ELEMENTS(stock_icons); + + icon_factory = gtk_icon_factory_new(); + + for (i = 0; i < n_stock_icons; i++) { + stock_icon_register(stock_icons[i].filename, stock_icons[i].stock_id); + } + + gtk_icon_factory_add_default(icon_factory); + + g_object_unref(icon_factory); +} |