diff -r 3ee18a3a0f58 -r 772ff096a326 plover-gtk/stockicons.c --- a/plover-gtk/stockicons.c Mon Nov 02 19:01:50 2015 +0000 +++ b/plover-gtk/stockicons.c Fri Jul 08 08:33:44 2016 +0100 @@ -34,6 +34,8 @@ GSList *tmp_list; static gint found_svg=-1; gchar **mime_types,**mime_type; + if (g_getenv("PLOVER_IGNORE_SVG_SUPPORT")) + return FALSE; if (found_svg!=-1) return found_svg; formats=gdk_pixbuf_get_formats(); @@ -55,10 +57,15 @@ { int w,h; GdkPixbuf *pixbuf; + GtkSettings *settings; GtkIconSource *source; - if (gtk_icon_size_lookup(size,&w,&h)) + GError *err=NULL; + settings=gtk_settings_get_default(); + if (!settings) + g_warning("plover: Can't add icons without a default screen"); + else if (gtk_icon_size_lookup_for_settings(settings,size,&w,&h)) { - pixbuf=gdk_pixbuf_new_from_file_at_size(filename,w,h,NULL); + pixbuf=gdk_pixbuf_new_from_file_at_size(filename,w,h,&err); if (pixbuf) { source=gtk_icon_source_new(); @@ -69,6 +76,11 @@ gtk_icon_source_free(source); g_object_unref(pixbuf); } + else + { + g_warning("%s: %s",filename,err->message); + g_error_free(err); + } } } @@ -87,23 +99,30 @@ */ void plover_icons_add_to_stock(const char *type,const char *name) { - gchar *prefix,*s,*filename; + gchar *datadir,*prefix,*s,*filename; GtkIconSource *source; GtkIconSet *icon_set; GtkIconFactory *factory; factory=gtk_icon_factory_new(); icon_set=gtk_icon_set_new(); + datadir=g_strdup(g_getenv("PLOVER_ICONS_DATADIR")); + if (!datadir) + { #ifdef WIN32 - prefix=g_win32_get_package_installation_directory_of_module(NULL); + prefix=g_win32_get_package_installation_directory_of_module(NULL); #else - prefix=NULL; + prefix=NULL; #endif + if (!prefix) + prefix=g_strdup("/usr"); + datadir=g_strconcat(prefix,"share",NULL); + g_free(prefix); + } if (plover_pixbuf_supports_svg()) { source=gtk_icon_source_new(); s=g_strconcat(name,".svg",NULL); - filename=g_build_filename(prefix?prefix:"/usr", - "share/icons/hicolor/scalable",type,s,NULL); + filename=g_build_filename(datadir,"icons/hicolor/scalable",type,s,NULL); g_free(s); gtk_icon_source_set_filename(source,filename); g_free(filename); @@ -113,8 +132,7 @@ else { s=g_strconcat(name,".png",NULL); - filename=g_build_filename(prefix?prefix:"/usr", - "share/icons/hicolor/24x24",type,s,NULL); + filename=g_build_filename(datadir,"icons/hicolor/24x24",type,s,NULL); plover_install_icon_at_size(name,icon_set,GTK_ICON_SIZE_MENU, filename); plover_install_icon_at_size(name,icon_set,GTK_ICON_SIZE_BUTTON, @@ -124,8 +142,7 @@ plover_install_icon_at_size(name,icon_set,GTK_ICON_SIZE_LARGE_TOOLBAR, filename); g_free(filename); - filename=g_build_filename(prefix?prefix:"/usr", - "share/icons/hicolor/48x48",type,s,NULL); + filename=g_build_filename(datadir,"icons/hicolor/48x48",type,s,NULL); plover_install_icon_at_size(name,icon_set,GTK_ICON_SIZE_DND, filename); plover_install_icon_at_size(name,icon_set,GTK_ICON_SIZE_DIALOG, @@ -133,6 +150,7 @@ g_free(filename); g_free(s); } + g_free(datadir); gtk_icon_factory_add(factory,name,icon_set); gtk_icon_set_unref(icon_set); //icon_set=gtk_icon_factory_lookup(factory,name);