comparison src/audacious/playlist.c @ 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 4b4810391b05
children 9f3cc7f3aaf6
comparison
equal deleted inserted replaced
4226:708b5473f8d6 4227:206378f34610
24 * 24 *
25 * The Audacious team does not consider modular code linking to 25 * The Audacious team does not consider modular code linking to
26 * Audacious or using our public API to be a derived work. 26 * Audacious or using our public API to be a derived work.
27 */ 27 */
28 28
29 /* #define AUD_DEBUG 1 */ 29 #define AUD_DEBUG 1
30 30
31 #ifdef HAVE_CONFIG_H 31 #ifdef HAVE_CONFIG_H
32 # include "config.h" 32 # include "config.h"
33 #endif 33 #endif
34 34
226 } 226 }
227 227
228 /* renew tuple if file mtime is newer than tuple mtime. */ 228 /* renew tuple if file mtime is newer than tuple mtime. */
229 if (entry->tuple){ 229 if (entry->tuple){
230 if (tuple_get_int(entry->tuple, FIELD_MTIME, NULL) == modtime) { 230 if (tuple_get_int(entry->tuple, FIELD_MTIME, NULL) == modtime) {
231 g_free(pr); 231 if (pr != NULL) g_free(pr);
232
233 if (entry->title_is_valid == FALSE) { /* update title even tuple is present and up to date --asphyx */
234 AUDDBG("updating title from actual tuple\n");
235 formatter = tuple_get_string(entry->tuple, FIELD_FORMATTER, NULL);
236 if (entry->title != NULL) g_free(entry->title);
237 entry->title = tuple_formatter_make_title_string(entry->tuple, formatter ?
238 formatter : get_gentitle_format());
239 entry->title_is_valid = TRUE;
240 AUDDBG("new title: \"%s\"\n", entry->title);
241 }
242
232 return TRUE; 243 return TRUE;
233 } else { 244 } else {
234 mowgli_object_unref(entry->tuple); 245 mowgli_object_unref(entry->tuple);
235 entry->tuple = NULL; 246 entry->tuple = NULL;
236 } 247 }
240 tuple = pr->tuple; 251 tuple = pr->tuple;
241 else if (entry->decoder != NULL && entry->decoder->get_song_tuple != NULL) 252 else if (entry->decoder != NULL && entry->decoder->get_song_tuple != NULL)
242 tuple = entry->decoder->get_song_tuple(entry->filename); 253 tuple = entry->decoder->get_song_tuple(entry->filename);
243 254
244 if (tuple == NULL) { 255 if (tuple == NULL) {
245 g_free(pr); 256 if (pr != NULL) g_free(pr);
246 return FALSE; 257 return FALSE;
247 } 258 }
248 259
249 /* attach mtime */ 260 /* attach mtime */
250 tuple_associate_int(tuple, FIELD_MTIME, NULL, modtime); 261 tuple_associate_int(tuple, FIELD_MTIME, NULL, modtime);
251 262
252 /* entry is still around */ 263 /* entry is still around */
253 formatter = tuple_get_string(tuple, FIELD_FORMATTER, NULL); 264 formatter = tuple_get_string(tuple, FIELD_FORMATTER, NULL);
254 entry->title = tuple_formatter_make_title_string(tuple, formatter ? 265 entry->title = tuple_formatter_make_title_string(tuple, formatter ?
255 formatter : get_gentitle_format()); 266 formatter : get_gentitle_format());
267 entry->title_is_valid = TRUE;
256 entry->length = tuple_get_int(tuple, FIELD_LENGTH, NULL); 268 entry->length = tuple_get_int(tuple, FIELD_LENGTH, NULL);
257 entry->tuple = tuple; 269 entry->tuple = tuple;
258 270
259 g_free(pr); 271 if (pr != NULL) g_free(pr);
260 272
261 return TRUE; 273 return TRUE;
262 } 274 }
263 275
264 /* *********************** playlist selector code ************************* */ 276 /* *********************** playlist selector code ************************* */
741 if (tuple != NULL) { 753 if (tuple != NULL) {
742 const gchar *formatter = tuple_get_string(tuple, FIELD_FORMATTER, NULL); 754 const gchar *formatter = tuple_get_string(tuple, FIELD_FORMATTER, NULL);
743 g_free(entry->title); 755 g_free(entry->title);
744 entry->title = tuple_formatter_make_title_string(tuple, 756 entry->title = tuple_formatter_make_title_string(tuple,
745 formatter ? formatter : get_gentitle_format()); 757 formatter ? formatter : get_gentitle_format());
758 entry->title_is_valid = TRUE;
746 entry->length = tuple_get_int(tuple, FIELD_LENGTH, NULL); 759 entry->length = tuple_get_int(tuple, FIELD_LENGTH, NULL);
747 entry->tuple = tuple; 760 entry->tuple = tuple;
748 } 761 }
749 762
750 PLAYLIST_UNLOCK(playlist); 763 PLAYLIST_UNLOCK(playlist);
2562 for (node = playlist->entries; node; node = g_list_next(node)) { 2575 for (node = playlist->entries; node; node = g_list_next(node)) {
2563 entry = node->data; 2576 entry = node->data;
2564 2577
2565 if(playlist->attribute & PLAYLIST_STATIC || // live lock fix 2578 if(playlist->attribute & PLAYLIST_STATIC || // live lock fix
2566 (entry->tuple && tuple_get_int(entry->tuple, FIELD_LENGTH, NULL) > -1 && 2579 (entry->tuple && tuple_get_int(entry->tuple, FIELD_LENGTH, NULL) > -1 &&
2567 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1)) { 2580 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1 && entry->title_is_valid)) {
2568 update_playlistwin = TRUE; 2581 update_playlistwin = TRUE;
2569 continue; 2582 continue;
2570 } 2583 }
2571 2584
2572 if (!playlist_entry_get_info(entry)) { 2585 if (!playlist_entry_get_info(entry)) {
2577 } 2590 }
2578 else if ((entry->tuple != NULL || entry->title != NULL) && 2591 else if ((entry->tuple != NULL || entry->title != NULL) &&
2579 tuple_get_int(entry->tuple, FIELD_LENGTH, NULL) > -1 && 2592 tuple_get_int(entry->tuple, FIELD_LENGTH, NULL) > -1 &&
2580 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1) { 2593 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1) {
2581 update_playlistwin = TRUE; 2594 update_playlistwin = TRUE;
2582 break; 2595 break; /* hmmm... --asphyx */
2583 } 2596 }
2584 } 2597 }
2585 2598
2586 if (!node) { 2599 if (!node) {
2587 g_mutex_lock(mutex_scan); 2600 g_mutex_lock(mutex_scan);
2607 2620
2608 entry = node->data; 2621 entry = node->data;
2609 2622
2610 if(playlist->attribute & PLAYLIST_STATIC || 2623 if(playlist->attribute & PLAYLIST_STATIC ||
2611 (entry->tuple && tuple_get_int(entry->tuple, FIELD_LENGTH, NULL) > -1 && 2624 (entry->tuple && tuple_get_int(entry->tuple, FIELD_LENGTH, NULL) > -1 &&
2612 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1)) { 2625 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1 && entry->title_is_valid)) {
2613 continue; 2626 continue;
2614 } 2627 }
2615 2628
2616 AUDDBG("len=%d mtime=%d\n", 2629 AUDDBG("len=%d mtime=%d\n",
2617 tuple_get_int(entry->tuple, FIELD_LENGTH, NULL), 2630 tuple_get_int(entry->tuple, FIELD_LENGTH, NULL),
2694 } 2707 }
2695 2708
2696 void 2709 void
2697 playlist_start_get_info_scan(void) 2710 playlist_start_get_info_scan(void)
2698 { 2711 {
2712 AUDDBG("waking up scan thread\n");
2699 g_mutex_lock(mutex_scan); 2713 g_mutex_lock(mutex_scan);
2700 playlist_get_info_scan_active = TRUE; 2714 playlist_get_info_scan_active = TRUE;
2701 g_mutex_unlock(mutex_scan); 2715 g_mutex_unlock(mutex_scan);
2702 2716
2703 g_cond_signal(cond_scan); 2717 g_cond_signal(cond_scan);
2718 }
2719
2720 void
2721 playlist_update_all_titles(void) /* update titles after format changing --asphyx */
2722 {
2723 PlaylistEntry *entry;
2724 GList *node;
2725 Playlist *playlist = playlist_get_active();
2726
2727 AUDDBG("invalidating titles\n");
2728 PLAYLIST_LOCK(playlist);
2729 for (node = playlist->entries; node; node = g_list_next(node)) {
2730 entry = node->data;
2731 entry->title_is_valid = FALSE;
2732 }
2733 PLAYLIST_UNLOCK(playlist);
2734 playlist_start_get_info_scan();
2704 } 2735 }
2705 2736
2706 void 2737 void
2707 playlist_remove_dead_files(Playlist *playlist) 2738 playlist_remove_dead_files(Playlist *playlist)
2708 { 2739 {