pre-inst should install 'installer' group rather than the hardcoded plover-gtkui
2 * Copyright (C) 2010 J. Ali Harlow <ali@juiblex.co.uk>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <plover-gtk/stockicons.h>
28 /* Checks whether a loader for SVG files has been registered
31 static gboolean plover_pixbuf_supports_svg(void)
35 static gint found_svg=-1;
36 gchar **mime_types,**mime_type;
37 if (g_getenv("PLOVER_IGNORE_SVG_SUPPORT"))
41 formats=gdk_pixbuf_get_formats();
43 for (tmp_list=formats;tmp_list && !found_svg;tmp_list=tmp_list->next)
45 mime_types=gdk_pixbuf_format_get_mime_types(tmp_list->data);
46 for (mime_type=mime_types;*mime_type && !found_svg;mime_type++)
47 if (!strcmp(*mime_type,"image/svg"))
49 g_strfreev(mime_types);
51 g_slist_free(formats);
55 static void plover_install_icon_at_size(const char *icon_name,
56 GtkIconSet *icon_set,GtkIconSize size,const char *filename)
60 GtkSettings *settings;
61 GtkIconSource *source;
63 settings=gtk_settings_get_default();
65 g_warning("plover: Can't add icons without a default screen");
66 else if (gtk_icon_size_lookup_for_settings(settings,size,&w,&h))
68 pixbuf=gdk_pixbuf_new_from_file_at_size(filename,w,h,&err);
71 source=gtk_icon_source_new();
72 gtk_icon_source_set_size_wildcarded(source,FALSE);
73 gtk_icon_source_set_size(source,size);
74 gtk_icon_source_set_pixbuf(source,pixbuf);
75 gtk_icon_set_add_source(icon_set,source);
76 gtk_icon_source_free(source);
77 g_object_unref(pixbuf);
81 g_warning("%s: %s",filename,err->message);
88 * plover_icons_add_to_stock:
89 * @type: The icon type, typically "apps" or "mimetype"
90 * @name: The icon name (the basename of files containing the icons)
92 * Find icons in <datadir>/icons/hicolor and add them to the stock images
93 * so that, for example, gtk_image_new_from_stock() will be able find them.
95 * If there is an SVG loader registered with GdkPixbuf, then:
96 * <datadir>/icons/hicolor/scalable/@type/@name.svg will be used. Otherwise,
97 * <datadir>/icons/hicolor/24x24/@type/@name.png and
98 * <datadir>/icons/hicolor/48x48/@type/@name.png will be used.
100 void plover_icons_add_to_stock(const char *type,const char *name)
102 gchar *datadir,*prefix,*s,*filename;
103 GtkIconSource *source;
104 GtkIconSet *icon_set;
105 GtkIconFactory *factory;
106 factory=gtk_icon_factory_new();
107 icon_set=gtk_icon_set_new();
108 datadir=g_strdup(g_getenv("PLOVER_ICONS_DATADIR"));
112 prefix=g_win32_get_package_installation_directory_of_module(NULL);
117 prefix=g_strdup("/usr");
118 datadir=g_strconcat(prefix,"share",NULL);
121 if (plover_pixbuf_supports_svg())
123 source=gtk_icon_source_new();
124 s=g_strconcat(name,".svg",NULL);
125 filename=g_build_filename(datadir,"icons/hicolor/scalable",type,s,NULL);
127 gtk_icon_source_set_filename(source,filename);
129 gtk_icon_set_add_source(icon_set,source);
130 gtk_icon_source_free(source);
134 s=g_strconcat(name,".png",NULL);
135 filename=g_build_filename(datadir,"icons/hicolor/24x24",type,s,NULL);
136 plover_install_icon_at_size(name,icon_set,GTK_ICON_SIZE_MENU,
138 plover_install_icon_at_size(name,icon_set,GTK_ICON_SIZE_BUTTON,
140 plover_install_icon_at_size(name,icon_set,GTK_ICON_SIZE_SMALL_TOOLBAR,
142 plover_install_icon_at_size(name,icon_set,GTK_ICON_SIZE_LARGE_TOOLBAR,
145 filename=g_build_filename(datadir,"icons/hicolor/48x48",type,s,NULL);
146 plover_install_icon_at_size(name,icon_set,GTK_ICON_SIZE_DND,
148 plover_install_icon_at_size(name,icon_set,GTK_ICON_SIZE_DIALOG,
154 gtk_icon_factory_add(factory,name,icon_set);
155 gtk_icon_set_unref(icon_set);
156 //icon_set=gtk_icon_factory_lookup(factory,name);
157 gtk_icon_factory_add_default(factory);
158 g_object_unref(factory);