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)
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.
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"
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 */
78 /* gnome-icon-theme icons */
82 GNOME_MEDIA_AUTO_PLAYLIST
,
88 rb_stock_icons_init (void)
90 GtkIconTheme
*theme
= gtk_icon_theme_get_default ();
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
++) {
106 pixbuf
= gdk_pixbuf_new_from_inline (-1,
107 inline_icons
[i
].data
,
112 gtk_icon_theme_add_builtin_icon (inline_icons
[i
].name
,
117 for (i
= 0; i
< (int) G_N_ELEMENTS (icons
); i
++) {
118 GtkIconSet
*icon_set
;
121 pixbuf
= gtk_icon_theme_load_icon (theme
,
126 if (pixbuf
== NULL
) {
130 fn
= g_strconcat (icons
[i
], ".png", NULL
);
133 pixbuf
= gdk_pixbuf_new_from_file (path
, NULL
);
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
));
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
)) {
154 static char *search_paths
[] = {
155 #ifdef SHARE_UNINSTALLED_DIR
156 SHARE_UNINSTALLED_DIR
"/",
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
)
170 pixbuf
= gdk_pixbuf_new_from_file (path
, NULL
);
172 gtk_icon_theme_add_builtin_icon (RB_APP_ICON
, icon_size
, pixbuf
);
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
));