2006-06-07 James Livingston <doclivingston@gmail.com>
[rhythmbox.git] / lib / rb-stock-icons.c
blob0cb5b75cafe2a13630e7b89c7d7f5ec4c46bbc53
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3 * arch-tag: Implementation of Rhythmbox icon loading
5 * Copyright (C) 2002 Jorn Baayen
6 * Copyright (C) 2003,2004 Colin Walters <walters@verbum.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <gtk/gtk.h>
25 #include <glib.h>
26 #include <stdio.h>
27 #include <string.h>
29 #include "rb-file-helpers.h"
30 #include "rb-stock-icons.h"
32 static GtkIconFactory *factory = NULL;
34 const char RB_APP_ICON[] = "rhythmbox";
35 const char RB_STOCK_TRAY_ICON[] = "rhythmbox-tray-icon";
36 const char RB_STOCK_SET_STAR[] = "rhythmbox-set-star";
37 const char RB_STOCK_UNSET_STAR[] = "rhythmbox-unset-star";
38 const char RB_STOCK_NO_STAR[] = "rhythmbox-no-star";
39 const char RB_STOCK_PODCAST[] = "rhythmbox-podcast";
40 const char RB_STOCK_BROWSER[] = "stock_music-library";
41 const char GNOME_MEDIA_SHUFFLE[] = "stock_shuffle";
42 const char GNOME_MEDIA_REPEAT[] = "stock_repeat";
43 const char GNOME_MEDIA_PLAYLIST[] = "stock_playlist";
44 const char GNOME_MEDIA_AUTO_PLAYLIST[] = "stock_smart-playlist";
45 const char GNOME_MEDIA_EJECT[] = "media-eject";
47 void
48 rb_stock_icons_init (void)
50 GtkIconTheme *theme = gtk_icon_theme_get_default ();
51 int i;
52 int icon_size;
54 static const char* items[] =
56 /* Rhythmbox custom icons */
57 RB_STOCK_TRAY_ICON,
58 RB_STOCK_SET_STAR,
59 RB_STOCK_UNSET_STAR,
60 RB_STOCK_PODCAST,
61 RB_STOCK_NO_STAR,
63 /* gnome-icon-theme icons */
64 GNOME_MEDIA_SHUFFLE,
65 GNOME_MEDIA_REPEAT,
66 GNOME_MEDIA_PLAYLIST,
67 GNOME_MEDIA_AUTO_PLAYLIST,
68 GNOME_MEDIA_EJECT,
69 RB_STOCK_BROWSER
72 g_return_if_fail (factory == NULL);
74 factory = gtk_icon_factory_new ();
75 gtk_icon_factory_add_default (factory);
77 /* we should really add all the sizes */
78 gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR, &icon_size, NULL);
80 for (i = 0; i < (int) G_N_ELEMENTS (items); i++) {
81 GtkIconSet *icon_set;
82 GdkPixbuf *pixbuf;
84 pixbuf = gtk_icon_theme_load_icon (theme,
85 items[i],
86 icon_size,
88 NULL);
89 if (pixbuf == NULL) {
90 char *fn;
91 const char *path;
93 fn = g_strconcat (items[i], ".png", NULL);
94 path = rb_file (fn);
95 if (path != NULL) {
96 pixbuf = gdk_pixbuf_new_from_file (path, NULL);
98 g_free (fn);
101 if (pixbuf) {
102 icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
103 gtk_icon_factory_add (factory, items[i], icon_set);
104 gtk_icon_set_unref (icon_set);
106 g_object_unref (G_OBJECT (pixbuf));
107 } else {
108 g_warning ("Unable to load icon %s", items[i]);
112 /* register the app icon as a builtin if the theme can't find it */
113 if (!gtk_icon_theme_has_icon (theme, RB_APP_ICON)) {
114 int i;
115 GdkPixbuf *pixbuf;
116 char *path;
117 static char *search_paths[] = {
118 #ifdef SHARE_UNINSTALLED_DIR
119 SHARE_UNINSTALLED_DIR "/",
120 #endif
121 DATADIR "/icons/hicolor/48x48/apps/",
124 for (i = 0; i < (int) G_N_ELEMENTS (search_paths); i++) {
125 path = g_strconcat (search_paths[i], RB_APP_ICON, ".png", NULL);
126 if (g_file_test (path, G_FILE_TEST_EXISTS) == TRUE)
127 break;
128 g_free (path);
129 path = NULL;
132 if (path) {
133 pixbuf = gdk_pixbuf_new_from_file (path, NULL);
134 if (pixbuf) {
135 gtk_icon_theme_add_builtin_icon (RB_APP_ICON, icon_size, pixbuf);
138 g_free (path);
143 void
144 rb_stock_icons_shutdown (void)
146 g_return_if_fail (factory != NULL);
148 gtk_icon_factory_remove_default (factory);
150 g_object_unref (G_OBJECT (factory));