1 /*
2  |Copyright (C) 2007 P.G. Richardson <phantom_sf at users.sourceforge.net>
3  |Part of the gtkpod project.
4  |
5  |URL: http://www.gtkpod.org/
6  |URL: http://gtkpod.sourceforge.net/
7  |
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 of the License, or
11  |(at your option) any later version.
12  |
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.
17  |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  |
22  |iTunes and iPod are trademarks of Apple
23  |
24  |This product is not supported/written/published by Apple!
25  |
26  */
27 
28 #include "stock_icons.h"
29 
register_stock_icon(const gchar * name,const gchar * stockid)30 static void register_stock_icon (const gchar *name, const gchar *stockid)
31 {
32 	GtkIconSet *pl_iconset;
33 	GtkIconSource *source;
34 
35 	g_return_if_fail (name);
36 	g_return_if_fail (stockid);
37 
38 	pl_iconset = gtk_icon_set_new ();
39 	source = gtk_icon_source_new ();
40 
41 	gtk_icon_source_set_icon_name (source, name);
42 	gtk_icon_set_add_source (pl_iconset, source);
43 	gtk_icon_source_free (source); /* _add_source() copies source */
44 
45 	GtkIconFactory *factory = gtk_icon_factory_new ();
46 	gtk_icon_factory_add (factory, stockid, pl_iconset);
47 
48 	gtk_icon_factory_add_default (factory);
49 }
50 
51 /**
52  * stockid_init
53  *
54  * Initialises paths used for gtkpod specific icons.
55  * This needs to be loaded early as it uses the path
56  * of the binary to determine where to load the file from, in the
57  * same way as main() determines where to load the glade file
58  * from.
59  *
60  * @progpath: path of the gtkpod binary being loaded.
61  *
62  */
stockid_init(gchar * progpath)63 void stockid_init (gchar *progpath)
64 {
65 	gchar *progname = g_find_program_in_path (progpath);
66 	static const gchar *SEPsrcSEPgtkpod = G_DIR_SEPARATOR_S "src" G_DIR_SEPARATOR_S "gtkpod";
67 	gchar *path;
68 
69 	if (!progname)
70 		return;
71 
72 	if (!g_path_is_absolute (progname))
73 	{
74 		gchar *cur_dir = g_get_current_dir ();
75 		gchar *prog_absolute;
76 
77 		if (g_str_has_prefix (progname, "." G_DIR_SEPARATOR_S))
78 			prog_absolute = g_build_filename (cur_dir, progname+2, NULL);
79 		else
80 			prog_absolute = g_build_filename (cur_dir, progname, NULL);
81 
82 		g_free (progname);
83 		g_free (cur_dir);
84 		progname = prog_absolute;
85 	}
86 
87 	if (g_str_has_suffix (progname, SEPsrcSEPgtkpod))
88 	{
89 		gchar *suffix = g_strrstr (progname, SEPsrcSEPgtkpod);
90 
91 		if (suffix)
92 		{
93 			*suffix = 0;
94 		}
95 	}
96 
97 	path = g_build_filename (progname, "data", "icons", NULL);
98 	g_free (progname);
99 
100 	if (path && !g_file_test (path, G_FILE_TEST_EXISTS))
101 	{
102 		g_free (path);
103 		path = NULL;
104 	}
105 
106 	if (!path)
107 		path = g_build_filename (PACKAGE_DATA_DIR, PACKAGE, "icons", NULL);
108 
109 	gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), path);
110 	g_free (path);
111 
112 	register_stock_icon ("playlist-photo", GPHOTO_PLAYLIST_ICON_STOCK_ID);
113 	register_stock_icon ("playlist", TUNES_PLAYLIST_ICON_STOCK_ID);
114 
115 }
116