changeset 3349:01a241d35146 trunk

add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Mon, 13 Aug 2007 19:45:52 +0900
parents 2a081105513c
children 1292e4ca0f08
files src/audacious/playlist.c src/audacious/tuple_formatter.c src/audacious/tuple_formatter.h
diffstat 3 files changed, 22 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/playlist.c	Mon Aug 13 00:03:33 2007 -0700
+++ b/src/audacious/playlist.c	Mon Aug 13 19:45:52 2007 +0900
@@ -238,7 +238,7 @@
 
     /* entry is still around */
     formatter = tuple_get_string(tuple, "formatter");
-    entry->title = tuple_formatter_process_string(tuple, formatter ?
+    entry->title = tuple_formatter_make_title_string(tuple, formatter ?
                                                   formatter : get_gentitle_format());
     entry->length = tuple_get_int(tuple, "length");
     entry->tuple = tuple;
@@ -672,7 +672,7 @@
     PLAYLIST_UNLOCK( playlist->mutex );
     if (tuple != NULL) {
         const gchar *formatter = tuple_get_string(tuple, "formatter");
-        entry->title = tuple_formatter_process_string(tuple, formatter ?
+        entry->title = tuple_formatter_make_title_string(tuple, formatter ?
                                                       formatter : get_gentitle_format());
         entry->length = tuple_get_int(tuple, "length");
         entry->tuple = tuple;
--- a/src/audacious/tuple_formatter.c	Mon Aug 13 00:03:33 2007 -0700
+++ b/src/audacious/tuple_formatter.c	Mon Aug 13 19:45:52 2007 +0900
@@ -509,3 +509,22 @@
 
     return tuple_formatter_process_construct(tuple, string);
 }
+
+/* wrapper function for making title string. it falls back to filename
+ * if process_string returns NULL or a blank string. */
+gchar *
+tuple_formatter_make_title_string(Tuple *tuple, const gchar *string)
+{
+    gchar *rv;
+
+    g_return_val_if_fail(tuple != NULL, NULL);
+
+    rv = tuple_formatter_process_construct(tuple, string);
+
+    if(!rv || !strcmp(rv, "")) {
+        g_free(rv);
+        rv = g_strdup(tuple_get_string(tuple, "file-name"));
+    }
+
+    return rv;
+}
--- a/src/audacious/tuple_formatter.h	Mon Aug 13 00:03:33 2007 -0700
+++ b/src/audacious/tuple_formatter.h	Mon Aug 13 19:45:52 2007 +0900
@@ -27,6 +27,7 @@
 #include "tuple.h"
 
 gchar *tuple_formatter_process_string(Tuple *tuple, const gchar *string);
+gchar *tuple_formatter_make_title_string(Tuple *tuple, const gchar *string);
 void tuple_formatter_register_expression(const gchar *keyword,
         gboolean (*func)(Tuple *tuple, const gchar *argument));
 void tuple_formatter_register_function(const gchar *keyword,