]> sigrok.org Git - sigrok-gtk.git/blob - icons.c
gtk: Add 'autostuff' to .gitignore.
[sigrok-gtk.git] / icons.c
1 /*
2  * This file is part of the sigrok project.
3  *
4  * Copyright (C) 2011 Gareth McMullin <gareth@blacksphere.co.nz>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include <sigrok.h>
21 #include <gtk/gtk.h>
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 static struct {
28         gchar *filename;
29         gchar *stock_id;
30 } stock_icons[] = {
31         {"sigrok_logo.png", "sigrok-logo"},
32 };
33
34 static gint n_stock_icons = G_N_ELEMENTS (stock_icons);
35
36 void icons_register(void)
37 {
38         GtkIconFactory *icon_factory;
39         GtkIconSet *icon_set;
40         GtkIconSource *icon_source;
41         gint i;
42         gchar *tmp;
43
44 #ifdef G_OS_WIN32
45         gchar *sysdir;
46         sysdir = g_win32_get_package_installation_directory_of_module(NULL);
47         g_build_filename(sysdir, "share", PACKAGE_TARNAME, "icons", NULL);
48         g_free(sysdir);
49 #else
50         tmp = g_build_filename(PKG_DATA_DIR, "icons", NULL);
51 #endif
52         icon_factory = gtk_icon_factory_new ();
53         gtk_icon_factory_add_default (icon_factory);
54         icon_source = gtk_icon_source_new ();
55
56         for(i = 0; i < n_stock_icons; i++) {
57                 gchar *filename = 
58                         g_build_filename(tmp, stock_icons[i].filename, NULL);
59
60                 icon_set = gtk_icon_set_new ();
61                 gtk_icon_source_set_filename(icon_source, filename);
62                 gtk_icon_source_set_icon_name(icon_source, stock_icons[i].stock_id);
63                 gtk_icon_set_add_source (icon_set, icon_source);
64                 gtk_icon_factory_add (icon_factory, stock_icons[i].stock_id, icon_set);
65
66                 g_free(filename);
67         }
68
69         gtk_icon_source_free (icon_source);
70         g_object_unref (icon_factory);
71         g_free(tmp);
72 }
73