udapted vi.po
[rhythmbox.git] / lib / rb-stock-icons.c
blob99f58b1e7d7ffec8d94d0c5bdffc8b6d05a46471
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 /* inline pixbuf data */
33 #include "rhythmbox-set-star-inline.h"
34 #include "rhythmbox-unset-star-inline.h"
35 #include "rhythmbox-no-star-inline.h"
36 #include "rhythmbox-podcast-inline.h"
37 #include "rhythmbox-tray-icon-inline.h"
38 #include "media-eject-inline.h"
40 typedef struct {
41 const guint8 *data;
42 const char *name;
43 } RBInlineIconData;
45 static GtkIconFactory *factory = NULL;
47 const char RB_APP_ICON[] = "rhythmbox";
48 const char RB_STOCK_TRAY_ICON[] = "rhythmbox-tray-icon";
49 const char RB_STOCK_SET_STAR[] = "rhythmbox-set-star";
50 const char RB_STOCK_UNSET_STAR[] = "rhythmbox-unset-star";
51 const char RB_STOCK_NO_STAR[] = "rhythmbox-no-star";
52 const char RB_STOCK_PODCAST[] = "rhythmbox-podcast";
53 const char RB_STOCK_BROWSER[] = "stock_music-library";
54 const char GNOME_MEDIA_SHUFFLE[] = "stock_shuffle";
55 const char GNOME_MEDIA_REPEAT[] = "stock_repeat";
56 const char GNOME_MEDIA_PLAYLIST[] = "stock_playlist";
57 const char GNOME_MEDIA_AUTO_PLAYLIST[] = "stock_smart-playlist";
58 const char GNOME_MEDIA_EJECT[] = "media-eject";
60 static RBInlineIconData inline_icons[] = {
61 { rhythmbox_set_star_inline, RB_STOCK_SET_STAR },
62 { rhythmbox_unset_star_inline, RB_STOCK_UNSET_STAR },
63 { rhythmbox_no_star_inline, RB_STOCK_NO_STAR },
64 { rhythmbox_podcast_inline, RB_STOCK_PODCAST },
65 { rhythmbox_tray_icon_inline, RB_STOCK_TRAY_ICON },
66 { media_eject_inline, GNOME_MEDIA_EJECT }
69 static const char* icons[] =
71 /* Rhythmbox custom icons */
72 RB_STOCK_TRAY_ICON,
73 RB_STOCK_SET_STAR,
74 RB_STOCK_UNSET_STAR,
75 RB_STOCK_PODCAST,
76 RB_STOCK_NO_STAR,
78 /* gnome-icon-theme icons */
79 GNOME_MEDIA_SHUFFLE,
80 GNOME_MEDIA_REPEAT,
81 GNOME_MEDIA_PLAYLIST,
82 GNOME_MEDIA_AUTO_PLAYLIST,
83 GNOME_MEDIA_EJECT,
84 RB_STOCK_BROWSER
87 void
88 rb_stock_icons_init (void)
90 GtkIconTheme *theme = gtk_icon_theme_get_default ();
91 int i;
92 int icon_size;
94 g_return_if_fail (factory == NULL);
96 factory = gtk_icon_factory_new ();
97 gtk_icon_factory_add_default (factory);
99 /* we should really add all the sizes */
100 gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR, &icon_size, NULL);
102 /* add inline icons */
103 for (i = 0; i < (int) G_N_ELEMENTS (inline_icons); i++) {
104 GdkPixbuf *pixbuf;
106 pixbuf = gdk_pixbuf_new_from_inline (-1,
107 inline_icons[i].data,
108 FALSE,
109 NULL);
110 g_assert (pixbuf);
112 gtk_icon_theme_add_builtin_icon (inline_icons[i].name,
113 icon_size,
114 pixbuf);
117 for (i = 0; i < (int) G_N_ELEMENTS (icons); i++) {
118 GtkIconSet *icon_set;
119 GdkPixbuf *pixbuf;
121 pixbuf = gtk_icon_theme_load_icon (theme,
122 icons[i],
123 icon_size,
125 NULL);
126 if (pixbuf == NULL) {
127 char *fn;
128 const char *path;
130 fn = g_strconcat (icons[i], ".png", NULL);
131 path = rb_file (fn);
132 if (path != NULL) {
133 pixbuf = gdk_pixbuf_new_from_file (path, NULL);
135 g_free (fn);
138 if (pixbuf) {
139 icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
140 gtk_icon_factory_add (factory, icons[i], icon_set);
141 gtk_icon_set_unref (icon_set);
143 g_object_unref (G_OBJECT (pixbuf));
144 } else {
145 g_warning ("Unable to load icon %s", icons[i]);
149 /* register the app icon as a builtin if the theme can't find it */
150 if (!gtk_icon_theme_has_icon (theme, RB_APP_ICON)) {
151 int i;
152 GdkPixbuf *pixbuf;
153 char *path;
154 static char *search_paths[] = {
155 #ifdef SHARE_UNINSTALLED_DIR
156 SHARE_UNINSTALLED_DIR "/",
157 #endif
158 DATADIR "/icons/hicolor/48x48/apps/",
161 for (i = 0; i < (int) G_N_ELEMENTS (search_paths); i++) {
162 path = g_strconcat (search_paths[i], RB_APP_ICON, ".png", NULL);
163 if (g_file_test (path, G_FILE_TEST_EXISTS) == TRUE)
164 break;
165 g_free (path);
166 path = NULL;
169 if (path) {
170 pixbuf = gdk_pixbuf_new_from_file (path, NULL);
171 if (pixbuf) {
172 gtk_icon_theme_add_builtin_icon (RB_APP_ICON, icon_size, pixbuf);
175 g_free (path);
180 void
181 rb_stock_icons_shutdown (void)
183 g_return_if_fail (factory != NULL);
185 gtk_icon_factory_remove_default (factory);
187 g_object_unref (G_OBJECT (factory));