# HG changeset patch # User Christian Birchinger # Date 1186749582 -7200 # Node ID 008530664ba1622215d869a11d66177471c05a34 # Parent 4ced71e14fcba2b6cf6a2db02c7feb758456dfd1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext. diff -r 4ced71e14fcb -r 008530664ba1 src/audacious/tuple.c --- 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) { diff -r 4ced71e14fcb -r 008530664ba1 src/audacious/tuple.h --- 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);