]> git.0d.be Git - empathy.git/blob - libempathy-gtk/gossip-stock.c
[darcs-to-svn @ Save/restore window geometry]
[empathy.git] / libempathy-gtk / gossip-stock.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2003-2007 Imendio AB
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  * 
20  * Authors: Mikael Hallendal <micke@imendio.com>
21  *          Richard Hult <richard@imendio.com>
22  *          Martyn Russell <martyn@imendio.com>
23  */
24
25 #include "config.h"
26
27 #include <gtk/gtk.h>
28
29 #include <libempathy/gossip-paths.h>
30
31 #include "gossip-stock.h"
32
33 static GtkIconFactory *icon_factory = NULL;
34 static GtkWidget      *main_widget = NULL;
35
36 static GtkStockItem stock_items[] = {
37         { GOSSIP_STOCK_OFFLINE,                 NULL },
38         { GOSSIP_STOCK_AVAILABLE,               NULL },
39         { GOSSIP_STOCK_BUSY,                    NULL },
40         { GOSSIP_STOCK_AWAY,                    NULL },
41         { GOSSIP_STOCK_EXT_AWAY,                NULL },
42         { GOSSIP_STOCK_PENDING,                 NULL },
43         { GOSSIP_STOCK_MESSAGE,                 NULL },
44         { GOSSIP_STOCK_TYPING,                  NULL },
45         { GOSSIP_STOCK_CONTACT_INFORMATION,     NULL },
46         { GOSSIP_STOCK_GROUP_MESSAGE,           NULL }
47 };
48
49 void
50 gossip_stock_init (GtkWidget *widget)
51 {
52         GtkIconSet *icon_set;
53         gint        i;
54
55         g_assert (icon_factory == NULL);
56
57         main_widget = g_object_ref (widget);
58
59         gtk_stock_add (stock_items, G_N_ELEMENTS (stock_items));
60
61         icon_factory = gtk_icon_factory_new ();
62         gtk_icon_factory_add_default (icon_factory);
63         g_object_unref (icon_factory);
64
65         for (i = 0; i < G_N_ELEMENTS (stock_items); i++) {
66                 gchar     *path, *filename;
67                 GdkPixbuf *pixbuf;
68
69                 filename = g_strdup_printf ("%s.png", stock_items[i].stock_id);
70                 path = gossip_paths_get_image_path (filename);
71                 pixbuf = gdk_pixbuf_new_from_file (path, NULL);
72                 g_free (path);
73                 g_free (filename);
74
75                 icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
76
77                 gtk_icon_factory_add (icon_factory,
78                                       stock_items[i].stock_id,
79                                       icon_set);
80
81                 gtk_icon_set_unref (icon_set);
82
83                 g_object_unref (pixbuf);
84         }
85 }
86
87 void
88 gossip_stock_finalize (void)
89 {
90         g_assert (icon_factory != NULL);
91
92         gtk_icon_factory_remove_default (icon_factory);
93         g_object_unref (main_widget);
94
95         main_widget = NULL;
96         icon_factory = NULL;
97 }
98
99 GdkPixbuf *
100 gossip_stock_render (const gchar *stock,
101                      GtkIconSize  size)
102 {
103         return gtk_widget_render_icon (main_widget, stock, size, NULL);
104 }
105