XfceIconTheme fixes

Jasper Huijsmans jasper at xfce.org
Tue Sep 7 13:07:12 CEST 2004


On Tue, Sep 07, 2004 at 08:08:55AM +0200, Jasper Huijsmans wrote:
> Brian J. Tarricone wrote:
> >jasper,
> >
> >this patch looks good, except that there's no need to keep the theme 
> >name around or to compare it to a portion of the pathname (which could 
> >be error-prone, btw).  the XfceIcon struct has a "is_in_theme" boolean 
> >var that you can check.  could you rewrite your patch to use that 
> >instead?  if i'm totally missing the point of what you did, feel free to 
> >smack me ^_~.
> >
> 
> Hmm, yeah, I took the easy way out, I confess ;) The reason of course 
> being that XfceIcon is not exposed to the list lookup function. Nor is 
> an XfceIcon always used in the icon lookup: the fallback search just 
> returns a filename.
> 
> I'll just make a private lookup function that also returns the in_theme 
> boolean. To make it even more 'complicated' I could make the 
> disctinction between inherited and fallback icons, but that does take a 
> little more time.
> 

Revised patch, which uses the is_in_theme flag. The list lookup function now
even makes a distinction between in_theme > inherited > fallback. 

-------------- next part --------------
Index: libxfcegui4/xfce-icontheme.c
===================================================================
RCS file: /var/cvs/xfce/xfce4/libxfcegui4/libxfcegui4/xfce-icontheme.c,v
retrieving revision 1.12
diff -u -r1.12 xfce-icontheme.c
--- libxfcegui4/xfce-icontheme.c	6 Sep 2004 03:18:52 -0000	1.12
+++ libxfcegui4/xfce-icontheme.c	7 Sep 2004 10:59:59 -0000
@@ -600,10 +600,18 @@
 	return filename;
 }
 
-/* these three return filenames if the icon is found, or NULL */
-gchar *
-xfce_icon_theme_lookup(XfceIconTheme *icon_theme, const gchar *icon_name,
-		gint icon_size)
+/* besides the filename this function also returns a 'quality' indicator
+ * that depends on whether the icon is in the current theme, in an 
+ * inherited theme or in a fallback location */
+enum { 
+	XFCE_ICON_FALLBACK, 
+	XFCE_ICON_INHERITED,
+	XFCE_ICON_IN_THEME
+};
+
+static gchar *
+lookup_icon (XfceIconTheme *icon_theme, const gchar *icon_name, 
+		gint icon_size, int *quality)
 {
 	XfceIconThemeSingleton *singleton;
 	GList *icons, *l;
@@ -631,6 +639,8 @@
 		filename = search_fallback_paths(icon_name, icon_size);
 		if(new_icon_name)
 			g_free(new_icon_name);
+		if (quality != NULL)
+			*quality = XFCE_ICON_FALLBACK;
 		return filename;
 	}
 	
@@ -660,13 +670,26 @@
 		}
 	}
 	
-	if(filename)
+	if(filename) {
+		if (quality != NULL)
+			*quality = xicon->is_in_theme ? XFCE_ICON_IN_THEME :
+				XFCE_ICON_INHERITED;
+		
 		filename = g_strdup(filename);
-	
-	if(!filename && fuzzy_xicon)
+	}
+	else if(fuzzy_xicon) {
+		if (quality != NULL)
+			*quality = fuzzy_xicon->is_in_theme ? XFCE_ICON_IN_THEME :
+				XFCE_ICON_INHERITED;
+		
 		filename = g_strdup(fuzzy_xicon->path);
-	else if(!filename)
+	}
+	else {
+		if (quality != NULL)
+			*quality = XFCE_ICON_FALLBACK;
+		
 		filename = search_fallback_paths(icon_name, icon_size);
+	}
 	
 	if(new_icon_name)
 		g_free(new_icon_name);
@@ -674,21 +697,44 @@
 	return filename;
 }
 
+/* these three return filenames if the icon is found, or NULL */
+gchar *
+xfce_icon_theme_lookup(XfceIconTheme *icon_theme, const gchar *icon_name,
+		gint icon_size)
+{
+	return lookup_icon (icon_theme, icon_name, icon_size, NULL);
+}
+
 gchar *
 xfce_icon_theme_lookup_list(XfceIconTheme *icon_theme, GList *icon_names,
 		gint icon_size)
 {
 	XfceIconThemePriv *priv;
 	GList *l;
-	gchar *filename = NULL;
+	gchar *filename = NULL, *lookup = NULL;
+	int quality = XFCE_ICON_FALLBACK - 1, lookup_quality;
 	
 	g_return_val_if_fail(XFCE_IS_ICON_THEME(icon_theme) && icon_names, NULL);
 	priv = icon_theme->priv;
 	
 	for(l = icon_names; l; l = l->next) {
-		filename = xfce_icon_theme_lookup(icon_theme, (gchar *)l->data, icon_size);
-		if(filename)
-			break;
+		lookup = lookup_icon(icon_theme, (gchar *)l->data, icon_size, 
+				&lookup_quality);
+
+		if (lookup) {
+			if (lookup_quality == XFCE_ICON_IN_THEME) {
+				g_free (filename);
+				filename = lookup;
+				break;
+			}
+			else if (lookup_quality > quality) {
+				g_free (filename);
+				filename = lookup;
+				quality = lookup_quality;
+			}
+			else
+				g_free (lookup);
+		}
 	}
 	
 	return filename;


More information about the Xfce4-dev mailing list