changeset 4227:206378f34610

update titles when formatter template changes even if tuples is up to date
author Eugene Zagidullin <e.asphyx@gmail.com>
date Wed, 30 Jan 2008 19:41:03 +0300
parents 708b5473f8d6
children 9f3cc7f3aaf6
files src/audacious/playlist.c src/audacious/playlist.h src/audacious/ui_preferences.c
diffstat 3 files changed, 43 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/playlist.c	Wed Jan 30 05:10:19 2008 +0300
+++ b/src/audacious/playlist.c	Wed Jan 30 19:41:03 2008 +0300
@@ -26,7 +26,7 @@
  *  Audacious or using our public API to be a derived work.
  */
 
-/* #define AUD_DEBUG 1 */
+#define AUD_DEBUG 1
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
@@ -228,7 +228,18 @@
     /* renew tuple if file mtime is newer than tuple mtime. */
     if (entry->tuple){
         if (tuple_get_int(entry->tuple, FIELD_MTIME, NULL) == modtime) {
-            g_free(pr);
+            if (pr != NULL) g_free(pr);
+            
+            if (entry->title_is_valid == FALSE) { /* update title even tuple is present and up to date --asphyx */
+                AUDDBG("updating title from actual tuple\n");
+                formatter = tuple_get_string(entry->tuple, FIELD_FORMATTER, NULL);
+                if (entry->title != NULL) g_free(entry->title);
+                entry->title = tuple_formatter_make_title_string(entry->tuple, formatter ?
+                                                  formatter : get_gentitle_format());
+                entry->title_is_valid = TRUE;
+                AUDDBG("new title: \"%s\"\n", entry->title);
+            }
+
             return TRUE;
         } else {
             mowgli_object_unref(entry->tuple);
@@ -242,7 +253,7 @@
         tuple = entry->decoder->get_song_tuple(entry->filename);
 
     if (tuple == NULL) {
-        g_free(pr);
+        if (pr != NULL) g_free(pr);
         return FALSE;
     }
 
@@ -253,10 +264,11 @@
     formatter = tuple_get_string(tuple, FIELD_FORMATTER, NULL);
     entry->title = tuple_formatter_make_title_string(tuple, formatter ?
                                                   formatter : get_gentitle_format());
+    entry->title_is_valid = TRUE;
     entry->length = tuple_get_int(tuple, FIELD_LENGTH, NULL);
     entry->tuple = tuple;
 
-    g_free(pr);
+    if (pr != NULL) g_free(pr);
 
     return TRUE;
 }
@@ -743,6 +755,7 @@
             g_free(entry->title);
             entry->title = tuple_formatter_make_title_string(tuple,
                 formatter ? formatter : get_gentitle_format());
+            entry->title_is_valid = TRUE;
             entry->length = tuple_get_int(tuple, FIELD_LENGTH, NULL);
             entry->tuple = tuple;
         }
@@ -2564,7 +2577,7 @@
 
                 if(playlist->attribute & PLAYLIST_STATIC || // live lock fix
                    (entry->tuple && tuple_get_int(entry->tuple, FIELD_LENGTH, NULL) > -1 &&
-                    tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1)) {
+                    tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1 && entry->title_is_valid)) {
                     update_playlistwin = TRUE;
                     continue;
                 }
@@ -2579,7 +2592,7 @@
                     tuple_get_int(entry->tuple, FIELD_LENGTH, NULL) > -1 &&
                     tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1) {
                     update_playlistwin = TRUE;
-                    break;
+                    break; /* hmmm... --asphyx */
                 }
             }
             
@@ -2609,7 +2622,7 @@
 
                  if(playlist->attribute & PLAYLIST_STATIC ||
                    (entry->tuple && tuple_get_int(entry->tuple, FIELD_LENGTH, NULL) > -1 &&
-                    tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1)) {
+                    tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1 && entry->title_is_valid)) {
                     continue;
                  }
 
@@ -2696,6 +2709,7 @@
 void
 playlist_start_get_info_scan(void)
 {
+    AUDDBG("waking up scan thread\n");
     g_mutex_lock(mutex_scan);
     playlist_get_info_scan_active = TRUE;
     g_mutex_unlock(mutex_scan);
@@ -2704,6 +2718,23 @@
 }
 
 void
+playlist_update_all_titles(void) /* update titles after format changing --asphyx */
+{
+    PlaylistEntry *entry;
+    GList *node;
+    Playlist *playlist = playlist_get_active();
+    
+    AUDDBG("invalidating titles\n");
+    PLAYLIST_LOCK(playlist);
+    for (node = playlist->entries; node; node = g_list_next(node)) {
+        entry = node->data;
+        entry->title_is_valid = FALSE;
+    }
+    PLAYLIST_UNLOCK(playlist);
+    playlist_start_get_info_scan();
+}
+
+void
 playlist_remove_dead_files(Playlist *playlist)
 {
     GList *node, *next_node;
--- a/src/audacious/playlist.h	Wed Jan 30 05:10:19 2008 +0300
+++ b/src/audacious/playlist.h	Wed Jan 30 19:41:03 2008 +0300
@@ -70,6 +70,7 @@
     gboolean selected;
     InputPlugin *decoder;
     Tuple *tuple;		/* cached entry tuple, if available */
+    gboolean title_is_valid;    /* set it to FALSE after title format changing to update title even if tuple is present --asphyx */
 };
 
 #define PLAYLIST(x)  ((Playlist *)(x))
@@ -165,6 +166,7 @@
 void playlist_start_get_info_thread(void);
 void playlist_stop_get_info_thread();
 void playlist_start_get_info_scan(void);
+void playlist_update_all_titles(void);
 
 void playlist_sort(Playlist *playlist, PlaylistSortType type);
 void playlist_sort_selected(Playlist *playlist, PlaylistSortType type);
--- a/src/audacious/ui_preferences.c	Wed Jan 30 05:10:19 2008 +0300
+++ b/src/audacious/ui_preferences.c	Wed Jan 30 19:41:03 2008 +0300
@@ -44,6 +44,7 @@
 #include "general.h"
 #include "output.h"
 #include "visualization.h"
+#include "playlist.h"
 
 #include "main.h"
 #include "ui_skinned_textbox.h"
@@ -588,6 +589,8 @@
 
     cfg.titlestring_preset = position;
     gtk_widget_set_sensitive(GTK_WIDGET(data), (position == 6));
+
+    playlist_update_all_titles(); /* update titles */
 }
 
 static void