changeset 3345:67951f8f9d83 trunk

merged with master
author Ben Tucker <ben.tucker@gmail.com>
date Sun, 12 Aug 2007 13:28:09 -0700
parents c03055ef8822 (current diff) f5a413804217 (diff)
children 71d8d93f1bad
files
diffstat 8 files changed, 214 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/Makefile	Sun Aug 12 13:26:02 2007 -0700
+++ b/src/audacious/Makefile	Sun Aug 12 13:28:09 2007 -0700
@@ -36,6 +36,7 @@
 HEADERS = \
 	auddrct.h \
 	configdb.h \
+	custom_uri.h \
 	dbus.h \
 	eventqueue.h \
 	formatter.h \
@@ -67,6 +68,7 @@
 	auddrct.c \
 	build_stamp.c \
 	configdb.c \
+	custom_uri.c \
 	discovery.c \
 	dnd.c \
 	dock.c \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/audacious/custom_uri.c	Sun Aug 12 13:28:09 2007 -0700
@@ -0,0 +1,59 @@
+/*
+ * Audacious
+ * Copyright (c) 2007 William Pitcock
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses>.
+ *
+ * The Audacious team does not consider modular code linking to
+ * Audacious or using our public API to be a derived work.
+ */
+
+#include "custom_uri.h"
+
+mowgli_dictionary_t *uri_type_dict = NULL;
+
+void uri_set_plugin(const gchar *uri, InputPlugin *ip)
+{
+    g_return_if_fail(uri != NULL);
+    g_return_if_fail(ip != NULL);
+
+    if (uri_type_dict == NULL)
+        uri_type_dict = mowgli_dictionary_create(strcasecmp);
+    else if (mowgli_dictionary_find(uri_type_dict, uri))
+        mowgli_dictionary_delete(uri_type_dict, uri);
+    mowgli_dictionary_add(uri_type_dict, uri, ip);
+}
+
+InputPlugin *uri_get_plugin(const gchar *filename)
+{
+    gchar *uri, *pos;
+    InputPlugin *ip;
+
+    if (filename == NULL)
+        return NULL;
+
+    if (uri_type_dict == NULL)
+        return NULL;
+
+    pos = strstr(filename, "://");
+    if (pos)
+        uri = g_strndup(filename, pos - filename + 3);
+    else
+        return NULL;
+
+    ip = mowgli_dictionary_retrieve(uri_type_dict, uri);
+ 
+    g_free(uri);
+    
+    return ip;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/audacious/custom_uri.h	Sun Aug 12 13:28:09 2007 -0700
@@ -0,0 +1,36 @@
+/*
+ * Audacious
+ * Copyright (c) 2007 William Pitcock
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses>.
+ *
+ * The Audacious team does not consider modular code linking to
+ * Audacious or using our public API to be a derived work.
+ */
+
+#include <glib.h>
+#include <mowgli.h>
+
+#include <audacious/plugin.h>
+
+#ifndef __AUDACIOUS_CUSTOM_URI_H__
+#define __AUDACIOUS_CUSTOM_URI_H__
+
+G_BEGIN_DECLS
+
+InputPlugin *uri_get_plugin(const gchar *filename);
+void uri_set_plugin(const gchar *uri, InputPlugin *ip);
+
+G_END_DECLS
+
+#endif
--- a/src/audacious/input.c	Sun Aug 12 13:26:02 2007 -0700
+++ b/src/audacious/input.c	Sun Aug 12 13:28:09 2007 -0700
@@ -369,10 +369,30 @@
     if (tmp != NULL && g_ascii_isdigit(*(tmp + 1)))
         *tmp = '\0';
 
+    /* Check for plugins with custom URI:// strings */
+    /* cue:// cdda:// tone:// tact:// */
+    if ((ip = uri_get_plugin(filename)) != NULL &&
+        input_is_enabled(ip->filename) == TRUE)
+    {
+        if (ip->is_our_file != NULL)
+            ret = ip->is_our_file(filename_proxy);
+        else
+            ret = 0;
+        if (ret > 0)
+        {
+            g_free(filename_proxy);
+            pr = g_new0(ProbeResult, 1);
+            pr->ip = ip;
+            return pr;
+        }
+        g_free(filename_proxy);
+        return NULL;
+    }
+
     /* CD-Audio uses cdda:// dummy paths, no filedescriptor handling for it */
     /* also cuesheet uses cue:// */
-    if (!g_strncasecmp(filename, "cdda://", 7) ||
-        !g_strncasecmp(filename, "cue://", 6)) {
+/*
+    if (!g_strncasecmp(filename, "cue://", 6)) {
         for (node = get_input_list(); node != NULL; node = g_list_next(node))
         {
             ip = INPUT_PLUGIN(node->data);
@@ -393,7 +413,7 @@
         g_free(filename_proxy);
         return NULL;
     }
-
+*/
     fd = vfs_buffered_file_new_from_uri(tmp_uri);
     g_free(tmp_uri);
 
--- a/src/audacious/playlist.c	Sun Aug 12 13:26:02 2007 -0700
+++ b/src/audacious/playlist.c	Sun Aug 12 13:28:09 2007 -0700
@@ -921,7 +921,10 @@
 guint
 playlist_add_url(Playlist * playlist, const gchar * url)
 {
-    return playlist_ins_url(playlist, url, -1);
+    guint entries;
+    entries = playlist_ins_url(playlist, url, -1);
+//    printf("playlist_add_url: entries = %d\n", entries);
+    return entries;
 }
 
 guint
@@ -967,19 +970,17 @@
                     gint pos)
 {
     gchar *tmp;
-    gint i = 1, entries = 0;
-    gboolean first = TRUE;
-    guint firstpos = 0;
-    gboolean success = FALSE;
+    gint entries = 0;
     gchar *decoded = NULL;
 
     g_return_val_if_fail(playlist != NULL, 0);
     g_return_val_if_fail(string != NULL, 0);
 
-    playlistwin_update_list(playlist);
+//    playlistwin_update_list(playlist); // is this necessary? --yaz
 
     while (*string) {
         GList *node;
+        guint i = 0;
         tmp = strchr(string, '\n');
         if (tmp) {
             if (*(tmp - 1) == '\r')
@@ -996,8 +997,7 @@
             if (is_playlist_name(decoded)) {
                 i = playlist_load_ins(playlist, decoded, pos);
             }
-            else {
-                success = playlist_ins(playlist, decoded, pos);
+            else if (playlist_ins(playlist, decoded, pos)) {
                 i = 1;
             }
         }
@@ -1010,11 +1010,6 @@
 
         entries += i;
 
-        if (first) {
-            first = FALSE;
-            firstpos = pos;
-        }
-
         if (pos >= 0)
             pos += i;
         if (!tmp)
@@ -1603,14 +1598,14 @@
 gboolean
 playlist_load(Playlist * playlist, const gchar * filename)
 {
-    gboolean ret = FALSE;
+    guint ret = 0;
     g_return_val_if_fail(playlist != NULL, FALSE);
 
     playlist->loading_playlist = TRUE;
     ret = playlist_load_ins(playlist, filename, -1);
     playlist->loading_playlist = FALSE;
 
-    return ret;
+    return ret ? TRUE : FALSE;
 }
 
 void
@@ -1753,7 +1748,8 @@
 {
     PlaylistContainer *plc;
     gchar *ext;
-
+    gint old_len, new_len;
+    
     g_return_val_if_fail(playlist != NULL, 0);
     g_return_val_if_fail(filename != NULL, 0);
 
@@ -1763,12 +1759,14 @@
     g_return_val_if_fail(plc != NULL, 0);
     g_return_val_if_fail(plc->plc_read != NULL, 0);
 
+    old_len = playlist_get_length(playlist);
     plc->plc_read(filename, pos);
+    new_len = playlist_get_length(playlist);
 
     playlist_generate_shuffle_list(playlist);
     playlistwin_update_list(playlist);
 
-    return 1;
+    return new_len - old_len;
 }
 
 GList *
--- a/src/audacious/plugin.h	Sun Aug 12 13:26:02 2007 -0700
+++ b/src/audacious/plugin.h	Sun Aug 12 13:28:09 2007 -0700
@@ -329,5 +329,6 @@
 G_END_DECLS
 
 #include "audacious/mime.h"
+#include "audacious/custom_uri.h"
 
 #endif
--- a/src/audacious/tuple_formatter.c	Sun Aug 12 13:26:02 2007 -0700
+++ b/src/audacious/tuple_formatter.c	Sun Aug 12 13:28:09 2007 -0700
@@ -380,35 +380,64 @@
     return (tuple_get_value_type(tuple, expression) != TUPLE_UNKNOWN) ? TRUE : FALSE;
 }
 
-/* builtin-keyword: ${==arg1,arg2}, returns TRUE if <arg1> and <arg2> match. */
+/* builtin-keyword: ${==arg1,arg2}, returns TRUE if <arg1> and <arg2> match.
+   <arg1> and <arg2> can also be raw text, which should be enclosed in "double quotes". */
 static gboolean
 tuple_formatter_expression_match(Tuple *tuple, const gchar *expression)
 {
     gchar **args = g_strsplit(expression, ",", 2);
-    gchar *arg1, *arg2;
+    gchar *arg1 = NULL, *arg2 = NULL;
     gint ret;
 
-    if (tuple_get_value_type(tuple, args[0]) == TUPLE_UNKNOWN)
+    if (args[0][0] == '\"') /* check if arg1 is "raw text" */
+    {
+        if ( strlen(args[0]) > 1 )
+        {
+            args[0][strlen(args[0]) - 1] = '\0';
+            arg1 = g_strdup(&(args[0][1]));
+            args[0][strlen(args[0]) - 1] = '\"';
+        }
+        else /* bad formatted arg */
+            return FALSE;
+    }
+    else if (tuple_get_value_type(tuple, args[0]) == TUPLE_UNKNOWN)
+    {
+        g_strfreev(args);
+        return FALSE;
+    }
+    
+    if (args[1][0] == '\"') /* check if arg2 is "raw text" */
+    {
+        if ( strlen(args[1]) > 1 )
+        {
+            args[1][strlen(args[1]) - 1] = '\0';
+            arg2 = g_strdup(&(args[1][1]));
+            args[1][strlen(args[1]) - 1] = '\"';
+        }
+        else /* bad formatted arg */
+            return FALSE;
+    }
+    else if (tuple_get_value_type(tuple, args[1]) == TUPLE_UNKNOWN)
     {
         g_strfreev(args);
         return FALSE;
     }
 
-    if (tuple_get_value_type(tuple, args[1]) == TUPLE_UNKNOWN)
+    if (!arg1) /* if arg1 is not "raw text", get the tuple value */
     {
-        g_strfreev(args);
-        return FALSE;
+        if (tuple_get_value_type(tuple, args[0]) == TUPLE_STRING)
+            arg1 = g_strdup(tuple_get_string(tuple, args[0]));
+        else
+            arg1 = g_strdup_printf("%d", tuple_get_int(tuple, args[0]));
     }
 
-    if (tuple_get_value_type(tuple, args[0]) == TUPLE_STRING)
-        arg1 = g_strdup(tuple_get_string(tuple, args[0]));
-    else
-        arg1 = g_strdup_printf("%d", tuple_get_int(tuple, args[0]));
-
-    if (tuple_get_value_type(tuple, args[1]) == TUPLE_STRING)
-        arg2 = g_strdup(tuple_get_string(tuple, args[1]));
-    else
-        arg2 = g_strdup_printf("%d", tuple_get_int(tuple, args[1]));
+    if (!arg2) /* if arg2 is not "raw text", get the tuple value */
+    {
+        if (tuple_get_value_type(tuple, args[1]) == TUPLE_STRING)
+            arg2 = g_strdup(tuple_get_string(tuple, args[1]));
+        else
+            arg2 = g_strdup_printf("%d", tuple_get_int(tuple, args[1]));
+    }
 
     ret = g_ascii_strcasecmp(arg1, arg2);
     g_free(arg1);
@@ -418,7 +447,8 @@
     return ret ? FALSE : TRUE;
 }
 
-/* builtin-keyword: ${!=arg1,arg2}. returns TRUE if <arg1> and <arg2> don't match. */
+/* builtin-keyword: ${!=arg1,arg2}. returns TRUE if <arg1> and <arg2> don't match.
+   <arg1> and <arg2> can also be raw text, which should be enclosed in "double quotes". */
 static gboolean
 tuple_formatter_expression_nonmatch(Tuple *tuple, const gchar *expression)
 {
--- a/src/tests/tuple_formatter_test.c	Sun Aug 12 13:26:02 2007 -0700
+++ b/src/tests/tuple_formatter_test.c	Sun Aug 12 13:28:09 2007 -0700
@@ -148,6 +148,38 @@
     }
     g_free(tstr);
 
+    tstr = tuple_formatter_process_string(tuple, "${==splork,\"moo\":const text field matches}");
+    if (g_ascii_strcasecmp(tstr, "const text field matches"))
+    {
+        g_print("fail 15: '%s'\n", tstr);
+        return EXIT_FAILURE;
+    }
+    g_free(tstr);
+
+    tstr = tuple_formatter_process_string(tuple, "${==\"moo\",\"moo\":const text fields match}");
+    if (g_ascii_strcasecmp(tstr, "const text fields match"))
+    {
+        g_print("fail 16: '%s'\n", tstr);
+        return EXIT_FAILURE;
+    }
+    g_free(tstr);
+
+    tstr = tuple_formatter_process_string(tuple, "${!=splork,\"muu\":const text field doesn't match}");
+    if (g_ascii_strcasecmp(tstr, "const text field doesn't match"))
+    {
+        g_print("fail 17: '%s'\n", tstr);
+        return EXIT_FAILURE;
+    }
+    g_free(tstr);
+
+    tstr = tuple_formatter_process_string(tuple, "${!=\"moo\",\"muu\":const text fields do not match}");
+    if (g_ascii_strcasecmp(tstr, "const text fields do not match"))
+    {
+        g_print("fail 18: '%s'\n", tstr);
+        return EXIT_FAILURE;
+    }
+    g_free(tstr);
+
     mowgli_object_unref(tuple);
 
     return EXIT_SUCCESS;