changeset 2442:44df6c17411b trunk

[svn] - split out albumart locating functions into a seperate file and make the public API available in util.h
author nenolod
date Mon, 29 Jan 2007 10:11:01 -0800
parents af8b86badfdb
children 93686e8815a4
files ChangeLog src/audacious/Makefile src/audacious/ui_albumart.c src/audacious/ui_fileinfo.c src/audacious/ui_fileinfopopup.c src/audacious/util.h
diffstat 6 files changed, 210 insertions(+), 322 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Jan 29 09:55:26 2007 -0800
+++ b/ChangeLog	Mon Jan 29 10:11:01 2007 -0800
@@ -1,3 +1,13 @@
+2007-01-29 17:55:26 +0000  Michael Farber <01mf02@gmail.com>
+  revision [3892]
+  - Cleaned up a bit
+  
+  trunk/src/audacious/Makefile                |   19 +++++++++----------
+  trunk/src/audacious/platform/smartinclude.h |    6 ------
+  trunk/src/audacious/widgets/playlist_list.c |    2 --
+  3 files changed, 9 insertions(+), 18 deletions(-)
+
+
 2007-01-29 15:08:18 +0000  Giacomo Lozito <james@develia.org>
   revision [3890]
   - set the gtk2 fileopener position to the center of the screen
--- a/src/audacious/Makefile	Mon Jan 29 09:55:26 2007 -0800
+++ b/src/audacious/Makefile	Mon Jan 29 10:11:01 2007 -0800
@@ -77,6 +77,7 @@
 	strings.c \
 	titlestring.c \
 	ui_about.c \
+	ui_albumart.c \
 	ui_credits.c \
 	ui_equalizer.c \
 	ui_fileinfo.c \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/audacious/ui_albumart.c	Mon Jan 29 10:11:01 2007 -0800
@@ -0,0 +1,195 @@
+/*
+ * Audacious: A cross-platform multimedia player
+ * Copyright (c) 2007 William Pitcock, Tony Vroon, George Averill,
+ *                    Giacomo Lozito, Derek Pomery and Yoshiki Yazawa.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; under version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <string.h>
+
+#include "titlestring.h"
+#include "ui_fileinfopopup.h"
+#include "main.h"
+#include "ui_main.h"
+#include "playlist.h"
+#include "playback.h"
+
+static gboolean
+has_front_cover_extension(const gchar *name)
+{
+	char *ext;
+
+	ext = strrchr(name, '.');
+	if (!ext) {
+		/* No file extension */
+		return FALSE;
+	}
+
+	return g_strcasecmp(ext, ".jpg") == 0 ||
+	       g_strcasecmp(ext, ".jpeg") == 0 ||
+	       g_strcasecmp(ext, ".png") == 0;
+}
+
+static gboolean
+cover_name_filter(const gchar *name, const gchar *filter, const gboolean ret_on_empty)
+{
+	gboolean result = FALSE;
+	gchar **splitted;
+	gchar *current;
+	gchar *lname;
+	gint i;
+
+	if (!filter || strlen(filter) == 0) {
+		return ret_on_empty;
+	}
+
+	splitted = g_strsplit(filter, ",", 0);
+
+	lname = g_strdup(name);
+	g_strdown(lname);
+
+	for (i = 0; !result && (current = splitted[i]); i++) {
+		gchar *stripped = g_strstrip(g_strdup(current));
+		g_strdown(stripped);
+
+		result = result || strstr(lname, stripped);
+
+		g_free(stripped);
+	}
+
+	g_free(lname);
+	g_strfreev(splitted);
+
+	return result;
+}
+
+/* Check wether it's an image we want */
+static gboolean
+is_front_cover_image(const gchar *imgfile)
+{
+	return cover_name_filter(imgfile, cfg.cover_name_include, TRUE) &&
+	       !cover_name_filter(imgfile, cfg.cover_name_exclude, FALSE);
+}
+
+static gboolean
+is_file_image(const gchar *imgfile, const gchar *file_name)
+{
+	char *imgfile_ext, *file_name_ext;
+	size_t imgfile_len, file_name_len;
+
+	imgfile_ext = strrchr(imgfile, '.');
+	if (!imgfile_ext) {
+		/* No file extension */
+		return FALSE;
+	}
+
+	file_name_ext = strrchr(file_name, '.');
+	if (!file_name_ext) {
+		/* No file extension */
+		return FALSE;
+	}
+
+	imgfile_len = (imgfile_ext - imgfile);
+	file_name_len = (file_name_ext - file_name);
+
+	if (imgfile_len == file_name_len) {
+		return (g_ascii_strncasecmp(imgfile, file_name, imgfile_len) == 0);
+	} else {
+		return FALSE;
+	}
+}
+
+gchar*
+fileinfo_recursive_get_image(const gchar* path,
+	const gchar* file_name, gint depth)
+{
+	GDir *d;
+
+	if (cfg.recurse_for_cover && depth > cfg.recurse_for_cover_depth)
+		return NULL;
+	
+	d = g_dir_open(path, 0, NULL);
+
+	if (d) {
+		const gchar *f;
+
+		if (cfg.use_file_cover && file_name) {
+			/* Look for images matching file name */
+			while((f = g_dir_read_name(d))) { 
+				gchar *newpath = g_strconcat(path, "/", f, NULL);
+
+				if (!g_file_test(newpath, G_FILE_TEST_IS_DIR) &&
+				    has_front_cover_extension(f) &&
+				    is_file_image(f, file_name)) {
+					g_dir_close(d);
+					return newpath;
+				}
+
+				g_free(newpath);
+			}
+			g_dir_rewind(d);
+		}
+		
+		/* Search for files using filter */
+		while ((f = g_dir_read_name(d))) {
+			gchar *newpath = g_strconcat(path, "/", f, NULL);
+
+			if (!g_file_test(newpath, G_FILE_TEST_IS_DIR) &&
+			    has_front_cover_extension(f) &&
+			    is_front_cover_image(f)) {
+				g_dir_close(d);
+				return newpath;
+			}
+
+			g_free(newpath);
+		}
+		g_dir_rewind(d);
+
+		/* checks whether recursive or not. */
+		if (!cfg.recurse_for_cover) {
+			g_dir_close(d);
+			return NULL;
+		}
+
+		/* Descend into directories recursively. */
+		while ((f = g_dir_read_name(d))) {
+			gchar *newpath = g_strconcat(path, "/", f, NULL);
+			
+			if(g_file_test(newpath, G_FILE_TEST_IS_DIR)) {
+				gchar *tmp = fileinfo_recursive_get_image(newpath,
+					NULL, depth + 1);
+				if(tmp) {
+					g_free(newpath);
+					g_dir_close(d);
+					return tmp;
+				}
+			}
+
+			g_free(newpath);
+		}
+
+		g_dir_close(d);
+	}
+
+	return NULL;
+}
--- a/src/audacious/ui_fileinfo.c	Mon Jan 29 09:55:26 2007 -0800
+++ b/src/audacious/ui_fileinfo.c	Mon Jan 29 10:11:01 2007 -0800
@@ -217,166 +217,6 @@
 	gtk_widget_show(fileinfo_win);
 }
 
-static gboolean
-has_front_cover_extension(const gchar *name)
-{
-	char *ext;
-
-	ext = strrchr(name, '.');
-	if (!ext) {
-		/* No file extension */
-		return FALSE;
-	}
-
-	return g_strcasecmp(ext, ".jpg") == 0 ||
-	       g_strcasecmp(ext, ".jpeg") == 0 ||
-	       g_strcasecmp(ext, ".png") == 0;
-}
-
-static gboolean
-cover_name_filter(const gchar *name, const gchar *filter, const gboolean ret_on_empty)
-{
-	gboolean result = FALSE;
-	gchar **splitted;
-	gchar *current;
-	gchar *lname;
-	gint i;
-
-	if (!filter || strlen(filter) == 0) {
-		return ret_on_empty;
-	}
-
-	splitted = g_strsplit(filter, ",", 0);
-
-	lname = g_strdup(name);
-	g_strdown(lname);
-
-	for (i = 0; !result && (current = splitted[i]); i++) {
-		gchar *stripped = g_strstrip(g_strdup(current));
-		g_strdown(stripped);
-
-		result = result || strstr(lname, stripped);
-
-		g_free(stripped);
-	}
-
-	g_free(lname);
-	g_strfreev(splitted);
-
-	return result;
-}
-
-/* Check wether it's an image we want */
-static gboolean
-is_front_cover_image(const gchar *imgfile)
-{
-	return cover_name_filter(imgfile, cfg.cover_name_include, TRUE) &&
-	       !cover_name_filter(imgfile, cfg.cover_name_exclude, FALSE);
-}
-
-static gboolean
-is_file_image(const gchar *imgfile, const gchar *file_name)
-{
-	char *imgfile_ext, *file_name_ext;
-	size_t imgfile_len, file_name_len;
-
-	imgfile_ext = strrchr(imgfile, '.');
-	if (!imgfile_ext) {
-		/* No file extension */
-		return FALSE;
-	}
-
-	file_name_ext = strrchr(file_name, '.');
-	if (!file_name_ext) {
-		/* No file extension */
-		return FALSE;
-	}
-
-	imgfile_len = (imgfile_ext - imgfile);
-	file_name_len = (file_name_ext - file_name);
-
-	if (imgfile_len == file_name_len) {
-		return (g_ascii_strncasecmp(imgfile, file_name, imgfile_len) == 0);
-	} else {
-		return FALSE;
-	}
-}
-
-gchar*
-fileinfo_recursive_get_image(const gchar* path,
-	const gchar* file_name, gint depth)
-{
-	GDir *d;
-
-	if (cfg.recurse_for_cover && depth > cfg.recurse_for_cover_depth)
-		return NULL;
-	
-	d = g_dir_open(path, 0, NULL);
-
-	if (d) {
-		const gchar *f;
-
-		if (cfg.use_file_cover && file_name) {
-			/* Look for images matching file name */
-			while((f = g_dir_read_name(d))) { 
-				gchar *newpath = g_strconcat(path, "/", f, NULL);
-
-				if (!g_file_test(newpath, G_FILE_TEST_IS_DIR) &&
-				    has_front_cover_extension(f) &&
-				    is_file_image(f, file_name)) {
-					g_dir_close(d);
-					return newpath;
-				}
-
-				g_free(newpath);
-			}
-			g_dir_rewind(d);
-		}
-		
-		/* Search for files using filter */
-		while ((f = g_dir_read_name(d))) {
-			gchar *newpath = g_strconcat(path, "/", f, NULL);
-
-			if (!g_file_test(newpath, G_FILE_TEST_IS_DIR) &&
-			    has_front_cover_extension(f) &&
-			    is_front_cover_image(f)) {
-				g_dir_close(d);
-				return newpath;
-			}
-
-			g_free(newpath);
-		}
-		g_dir_rewind(d);
-
-		/* checks whether recursive or not. */
-		if (!cfg.recurse_for_cover) {
-			g_dir_close(d);
-			return NULL;
-		}
-
-		/* Descend into directories recursively. */
-		while ((f = g_dir_read_name(d))) {
-			gchar *newpath = g_strconcat(path, "/", f, NULL);
-			
-			if(g_file_test(newpath, G_FILE_TEST_IS_DIR)) {
-				gchar *tmp = fileinfo_recursive_get_image(newpath,
-					NULL, depth + 1);
-				if(tmp) {
-					g_free(newpath);
-					g_dir_close(d);
-					return tmp;
-				}
-			}
-
-			g_free(newpath);
-		}
-
-		g_dir_close(d);
-	}
-
-	return NULL;
-}
-
 void
 fileinfo_show_for_path(gchar *path)
 {
--- a/src/audacious/ui_fileinfopopup.c	Mon Jan 29 09:55:26 2007 -0800
+++ b/src/audacious/ui_fileinfopopup.c	Mon Jan 29 10:11:01 2007 -0800
@@ -33,7 +33,7 @@
 #include "ui_main.h"
 #include "playlist.h"
 #include "playback.h"
-
+#include "util.h"
 
 static void
 filepopup_entry_set_text(GtkWidget *filepopup_win, const char *entry_name, const char *text)
@@ -102,167 +102,6 @@
 }
 
 static gboolean
-has_front_cover_extension(const gchar *name)
-{
-	char *ext;
-
-	ext = strrchr(name, '.');
-	if (!ext) {
-		/* No file extension */
-		return FALSE;
-	}
-
-	return g_strcasecmp(ext, ".jpg") == 0 ||
-	       g_strcasecmp(ext, ".jpeg") == 0 ||
-	       g_strcasecmp(ext, ".png") == 0;
-}
-
-static gboolean
-cover_name_filter(const gchar *name, const gchar *filter, const gboolean ret_on_empty)
-{
-	gboolean result = FALSE;
-	gchar **splitted;
-	gchar *current;
-	gchar *lname;
-	gint i;
-
-	if (!filter || strlen(filter) == 0) {
-		return ret_on_empty;
-	}
-
-	splitted = g_strsplit(filter, ",", 0);
-
-	lname = g_strdup(name);
-	g_strdown(lname);
-
-	for (i = 0; !result && (current = splitted[i]); i++) {
-		gchar *stripped = g_strstrip(g_strdup(current));
-		g_strdown(stripped);
-
-		result = result || strstr(lname, stripped);
-
-		g_free(stripped);
-	}
-
-	g_free(lname);
-	g_strfreev(splitted);
-
-	return result;
-}
-
-/* Check wether it's an image we want */
-static gboolean
-is_front_cover_image(const gchar *imgfile)
-{
-	return cover_name_filter(imgfile, cfg.cover_name_include, TRUE) &&
-	       !cover_name_filter(imgfile, cfg.cover_name_exclude, FALSE);
-}
-
-static gboolean
-is_file_image(const gchar *imgfile, const gchar *file_name)
-{
-	char *imgfile_ext, *file_name_ext;
-	size_t imgfile_len, file_name_len;
-
-	imgfile_ext = strrchr(imgfile, '.');
-	if (!imgfile_ext) {
-		/* No file extension */
-		return FALSE;
-	}
-
-	file_name_ext = strrchr(file_name, '.');
-	if (!file_name_ext) {
-		/* No file extension */
-		return FALSE;
-	}
-
-	imgfile_len = (imgfile_ext - imgfile);
-	file_name_len = (file_name_ext - file_name);
-
-	if (imgfile_len == file_name_len) {
-		return (g_ascii_strncasecmp(imgfile, file_name, imgfile_len) == 0);
-	} else {
-		return FALSE;
-	}
-}
-
-static gchar*
-fileinfo_recursive_get_image(const gchar* path,
-	const gchar* file_name, gint depth)
-{
-	GDir *d;
-
-	if (cfg.recurse_for_cover && depth > cfg.recurse_for_cover_depth)
-		return NULL;
-	
-	d = g_dir_open(path, 0, NULL);
-
-	if (d) {
-		const gchar *f;
-
-		if (cfg.use_file_cover && file_name) {
-			/* Look for images matching file name */
-			while((f = g_dir_read_name(d))) { 
-				gchar *newpath = g_strconcat(path, "/", f, NULL);
-
-				if (!g_file_test(newpath, G_FILE_TEST_IS_DIR) &&
-				    has_front_cover_extension(f) &&
-				    is_file_image(f, file_name)) {
-					g_dir_close(d);
-					return newpath;
-				}
-
-				g_free(newpath);
-			}
-			g_dir_rewind(d);
-		}
-		
-		/* Search for files using filter */
-		while ((f = g_dir_read_name(d))) {
-			gchar *newpath = g_strconcat(path, "/", f, NULL);
-
-			if (!g_file_test(newpath, G_FILE_TEST_IS_DIR) &&
-			    has_front_cover_extension(f) &&
-			    is_front_cover_image(f)) {
-				g_dir_close(d);
-				return newpath;
-			}
-
-			g_free(newpath);
-		}
-		g_dir_rewind(d);
-
-		/* checks whether recursive or not. */
-		if (!cfg.recurse_for_cover) {
-			g_dir_close(d);
-			return NULL;
-		}
-
-		/* Descend into directories recursively. */
-		while ((f = g_dir_read_name(d))) {
-			gchar *newpath = g_strconcat(path, "/", f, NULL);
-			
-			if(g_file_test(newpath, G_FILE_TEST_IS_DIR)) {
-				gchar *tmp = fileinfo_recursive_get_image(newpath,
-					NULL, depth + 1);
-				if(tmp) {
-					g_free(newpath);
-					g_dir_close(d);
-					return tmp;
-				}
-			}
-
-			g_free(newpath);
-		}
-
-		g_dir_close(d);
-	}
-
-	return NULL;
-}
-
-
-static gboolean
 audacious_fileinfopopup_progress_cb ( gpointer filepopup_win )
 {
   GtkWidget *progressbar = g_object_get_data( G_OBJECT(filepopup_win) , "progressbar" );
--- a/src/audacious/util.h	Mon Jan 29 09:55:26 2007 -0800
+++ b/src/audacious/util.h	Mon Jan 29 10:11:01 2007 -0800
@@ -118,6 +118,9 @@
 
 void audacious_menu_main_show( gint x , gint y , guint button , guint time );
 
+gchar* fileinfo_recursive_get_image(const gchar* path,
+        const gchar* file_name, gint depth);
+
 G_END_DECLS
 
 #endif