diff src/audacious/tuple.c @ 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 b78d3197c70d
children eaf68ed98166
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)
 {