[Commits] [SCM] claws branch, master, updated. 3.14.1-167-g8e02f3f

mones at claws-mail.org mones at claws-mail.org
Tue Jan 31 12:26:14 CET 2017


The branch, master has been updated
       via  8e02f3f3c6b091009410b081d40d187e76fe45aa (commit)
      from  8925ab226ba8bb18928d61393d45e7d97f32777b (commit)

Summary of changes:
 src/prefs_themes.c |   32 +++++++++++++++++++++++---------
 src/stock_pixmap.c |   15 +++++++++++++--
 src/stock_pixmap.h |    1 +
 3 files changed, 37 insertions(+), 11 deletions(-)


- Log -----------------------------------------------------------------
commit 8e02f3f3c6b091009410b081d40d187e76fe45aa
Author: Ricardo Mones <ricardo at mones.org>
Date:   Tue Jan 31 00:11:47 2017 +0100

    Generalise theme extension handling

diff --git a/src/prefs_themes.c b/src/prefs_themes.c
index c9d2ecc..1d24f18 100644
--- a/src/prefs_themes.c
+++ b/src/prefs_themes.c
@@ -103,6 +103,9 @@ typedef struct _DirInfo {
 	gint bytes;
 	gint files;
 	gint pixms;
+	/* extensions info */
+	const char **supported;
+	gint *length;
 } DirInfo;
 
 typedef struct _CopyInfo {
@@ -157,17 +160,21 @@ static void prefs_themes_file_stats(const gchar *filename, gpointer data)
 	GStatBuf s;
 	DirInfo *di = (DirInfo *)data;
 	gint len;
+	gint i;
 
 	if (0 == g_stat(filename, &s) && 0 != S_ISREG(s.st_mode)) {
 		di->bytes += s.st_size;
 		di->files++;
 		len = strlen(filename);
-		if (len > 4) {
-			const gchar *extension = filename+(len-4);
-			if (!strcmp(extension, ".xpm"))
-				di->pixms++;
-			else if (!strcmp(extension, ".png"))
+		for (i = 0; (di->supported)[i] != NULL; ++i) {
+			gint curlen = (di->length)[i];
+			if (len <= curlen)
+				continue;
+			const gchar *extension = filename + (len - curlen);
+			if (!strcmp(extension, (di->supported)[i])) {
 				di->pixms++;
+				break;
+			}
 		}
 	}
 }
@@ -748,13 +755,20 @@ static gchar *prefs_themes_get_theme_stats(const gchar *dirname)
 {
 	gchar   *stats;
 	DirInfo *dinfo;
+	gint     i;
 
 	dinfo = g_new0(DirInfo, 1);
-	
+	dinfo->supported = stock_pixmap_theme_extensions();
+	for (i = 0; (dinfo->supported)[i] != NULL; ++i);
+	dinfo->length = g_malloc(i * sizeof(gint));
+	for (i = 0; (dinfo->supported)[i] != NULL; ++i) {
+		(dinfo->length)[i] = strlen((dinfo->supported)[i]);
+	}
 	prefs_themes_foreach_file(dirname, prefs_themes_file_stats, dinfo);
-	stats = g_strdup_printf(_("%d files (%d icons), size: %s"), 
-				dinfo->files, dinfo->pixms, to_human_readable((goffset)dinfo->bytes));
-	
+	stats = g_strdup_printf(_("%d files (%d icons), size: %s"),
+				dinfo->files, dinfo->pixms,
+				to_human_readable((goffset)dinfo->bytes));
+	g_free(dinfo->length);
 	g_free(dinfo);
 	return stats;
 }
diff --git a/src/stock_pixmap.c b/src/stock_pixmap.c
index 2fd5a7b..70ff84e 100644
--- a/src/stock_pixmap.c
+++ b/src/stock_pixmap.c
@@ -460,6 +460,19 @@ static StockPixmapData pixmaps[] =
     {empty_xpm                        , NULL, NULL, "empty", NULL, NULL}
 };
 
+/* Supported theme extensions */
+static const char *extension[] = {
+	".png",
+	".xpm",
+	NULL
+};
+
+/* return current supported extensions */
+const char **stock_pixmap_theme_extensions(void)
+{
+	return extension;
+}
+
 /* return newly constructed GtkPixmap from GdkPixmap */
 GtkWidget *stock_pixmap_widget(StockPixmap icon)
 {
@@ -479,7 +492,6 @@ GtkWidget *stock_pixmap_widget(StockPixmap icon)
 gint stock_pixbuf_gdk(StockPixmap icon, GdkPixbuf **pixbuf)
 {
 	StockPixmapData *pix_d;
-	static const char *extension[]={".png", ".xpm", NULL};
 	int i = 0;
 	gboolean theme_changed = FALSE;
 
@@ -556,7 +568,6 @@ static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname)
 	gchar *fullentry;
 	GDir *dp;
 	GError *error = NULL;
-	static const char *extension[]={".png", ".xpm", NULL};
 
 	if ((dp = g_dir_open(dirname, 0, &error)) == NULL) {
 		debug_print("skipping theme scan, dir %s could not be opened: %s (%d)\n",
diff --git a/src/stock_pixmap.h b/src/stock_pixmap.h
index 0e7a96b..447e5da 100644
--- a/src/stock_pixmap.h
+++ b/src/stock_pixmap.h
@@ -245,5 +245,6 @@ GtkWidget *stock_pixmap_widget_with_overlay (StockPixmap	 icon,
 					     gint		 border_x,
 					     gint		 border_y);
 gchar *stock_pixmap_get_system_theme_dir_for_theme(const gchar *theme);
+const char **stock_pixmap_theme_extensions(void);
 
 #endif /* __STOCK_PIXMAP_H__ */

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list