changeset 3301:008530664ba1 trunk

Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
author Christian Birchinger <joker@netswarm.net>
date Fri, 10 Aug 2007 14:39:42 +0200
parents 4ced71e14fcb
children 1588a64f0204
files src/audacious/tuple.c src/audacious/tuple.h
diffstat 2 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/tuple.c	Fri Aug 10 05:36:53 2007 -0500
+++ b/src/audacious/tuple.c	Fri Aug 10 14:39:42 2007 +0200
@@ -83,6 +83,35 @@
     return tuple;
 }
 
+Tuple *
+tuple_new_from_filename(gchar *filename)
+{
+    gchar *scratch, *ext;
+    Tuple *tuple;
+
+    g_return_val_if_fail(filename != NULL, NULL);
+
+    tuple = tuple_new();
+    
+    g_return_val_if_fail(tuple != NULL, NULL);
+        
+    scratch = g_path_get_basename(filename);
+    tuple_associate_string(tuple, "file-name", scratch);
+    g_free(scratch);
+
+    scratch = g_path_get_dirname(filename);
+    tuple_associate_string(tuple, "file-path", scratch);
+    g_free(scratch);
+    
+    ext = strrchr(filename, '.');
+    if (ext != NULL) {
+        ++ext;
+        tuple_associate_string(tuple, "file-ext", scratch);
+    }
+    
+    return tuple;
+}        
+
 gboolean
 tuple_associate_string(Tuple *tuple, const gchar *field, const gchar *string)
 {
--- a/src/audacious/tuple.h	Fri Aug 10 05:36:53 2007 -0500
+++ b/src/audacious/tuple.h	Fri Aug 10 14:39:42 2007 +0200
@@ -34,6 +34,7 @@
 } TupleValueType;
 
 Tuple *tuple_new(void);
+Tuple *tuple_new_from_filename(gchar *filename);
 gboolean tuple_associate_string(Tuple *tuple, const gchar *field, const gchar *string);
 gboolean tuple_associate_int(Tuple *tuple, const gchar *field, gint integer);
 void tuple_disassociate(Tuple *tuple, const gchar *field);