Mercurial > audlegacy
comparison src/audacious/playlist.c @ 3639:8b1c6c301d7f
Branch merge.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 25 Sep 2007 23:49:11 +0300 |
parents | 8d2f06fc841c |
children | d5309028af21 |
comparison
equal
deleted
inserted
replaced
3632:ffe7a2346055 | 3639:8b1c6c301d7f |
---|---|
203 | 203 |
204 if (str_has_prefix_nocase(entry->filename, "http:") && | 204 if (str_has_prefix_nocase(entry->filename, "http:") && |
205 g_thread_self() != playlist_get_info_thread) | 205 g_thread_self() != playlist_get_info_thread) |
206 return FALSE; | 206 return FALSE; |
207 | 207 |
208 if (entry->decoder == NULL) | 208 if (entry->decoder == NULL) { |
209 { | |
210 pr = input_check_file(entry->filename, FALSE); | 209 pr = input_check_file(entry->filename, FALSE); |
211 if (pr) | 210 if (pr) |
212 entry->decoder = pr->ip; | 211 entry->decoder = pr->ip; |
213 } | 212 } |
214 | 213 |
215 /* renew tuple if file mtime is newer than tuple mtime. */ | 214 /* renew tuple if file mtime is newer than tuple mtime. */ |
216 if(entry->tuple){ | 215 if (entry->tuple){ |
217 if(tuple_get_int(entry->tuple, FIELD_MTIME, NULL) == modtime) | 216 if (tuple_get_int(entry->tuple, FIELD_MTIME, NULL) == modtime) |
218 return TRUE; | 217 return TRUE; |
219 else { | 218 else { |
220 mowgli_object_unref(entry->tuple); | 219 mowgli_object_unref(entry->tuple); |
221 entry->tuple = NULL; | 220 entry->tuple = NULL; |
222 } | 221 } |
369 /* This function now sets the playlist title, not the playlist filename. | 368 /* This function now sets the playlist title, not the playlist filename. |
370 * See playlist_filename_set */ | 369 * See playlist_filename_set */ |
371 gboolean | 370 gboolean |
372 playlist_set_current_name(Playlist *playlist, const gchar * title) | 371 playlist_set_current_name(Playlist *playlist, const gchar * title) |
373 { | 372 { |
374 gchar *oldtitle; | 373 gchar *oldtitle = playlist->title; |
375 oldtitle = playlist->title; | |
376 | 374 |
377 if (!title) { | 375 if (!title) { |
378 playlist->title = NULL; | 376 playlist->title = NULL; |
379 if(oldtitle) g_free(oldtitle); | 377 g_free(oldtitle); |
380 playlist_manager_update(); | 378 playlist_manager_update(); |
381 return FALSE; | 379 return FALSE; |
382 } | 380 } |
383 | 381 |
384 playlist->title = str_to_utf8(title); | 382 playlist->title = str_to_utf8(title); |
385 if(oldtitle) g_free(oldtitle); | 383 g_free(oldtitle); |
386 playlist_manager_update(); | 384 playlist_manager_update(); |
387 return TRUE; | 385 return TRUE; |
388 } | 386 } |
389 | 387 |
390 /* Setting the filename allows the original playlist to be modified later */ | 388 /* Setting the filename allows the original playlist to be modified later */ |
392 playlist_filename_set(Playlist *playlist, const gchar * filename) | 390 playlist_filename_set(Playlist *playlist, const gchar * filename) |
393 { | 391 { |
394 gchar *old; | 392 gchar *old; |
395 old = playlist->filename; | 393 old = playlist->filename; |
396 | 394 |
397 if(!filename) { | 395 if (!filename) { |
398 playlist->filename = NULL; | 396 playlist->filename = NULL; |
399 if(old) g_free(old); | 397 g_free(old); |
400 return FALSE; | 398 return FALSE; |
401 } | 399 } |
402 | 400 |
403 playlist->filename = filename_to_utf8(filename); | 401 playlist->filename = filename_to_utf8(filename); |
404 if(old) g_free(old); | 402 g_free(old); |
405 return TRUE; | 403 return TRUE; |
406 } | 404 } |
407 | 405 |
408 gchar * | 406 gchar * |
409 playlist_filename_get(Playlist *playlist) | 407 playlist_filename_get(Playlist *playlist) |
410 { | 408 { |
411 if(!playlist->filename) return NULL; | 409 if (!playlist->filename) return NULL; |
412 return g_filename_from_utf8(playlist->filename, -1, NULL, NULL, NULL); | 410 return g_filename_from_utf8(playlist->filename, -1, NULL, NULL, NULL); |
413 } | 411 } |
414 | 412 |
415 static GList * | 413 static GList * |
416 find_playlist_position_list(Playlist *playlist) | 414 find_playlist_position_list(Playlist *playlist) |
433 static void | 431 static void |
434 play_queued(Playlist *playlist) | 432 play_queued(Playlist *playlist) |
435 { | 433 { |
436 GList *tmp = playlist->queue; | 434 GList *tmp = playlist->queue; |
437 | 435 |
438 REQUIRE_LOCK( playlist->mutex ); | 436 REQUIRE_LOCK(playlist->mutex); |
439 | 437 |
440 playlist->position = playlist->queue->data; | 438 playlist->position = playlist->queue->data; |
441 playlist->queue = g_list_remove_link(playlist->queue, playlist->queue); | 439 playlist->queue = g_list_remove_link(playlist->queue, playlist->queue); |
442 g_list_free_1(tmp); | 440 g_list_free_1(tmp); |
443 } | 441 } |
554 | 552 |
555 playlistwin_update_list(playlist); | 553 playlistwin_update_list(playlist); |
556 if (restart_playing) { | 554 if (restart_playing) { |
557 if (playlist->position) | 555 if (playlist->position) |
558 playback_initiate(); | 556 playback_initiate(); |
559 else { | 557 else |
560 mainwin_clear_song_info(); | 558 mainwin_clear_song_info(); |
561 } | |
562 } | 559 } |
563 | 560 |
564 playlist_manager_update(); | 561 playlist_manager_update(); |
565 } | 562 } |
566 | 563 |
592 playlistwin_update_list(playlist); | 589 playlistwin_update_list(playlist); |
593 | 590 |
594 if (restart_playing) { | 591 if (restart_playing) { |
595 if (playlist->position) | 592 if (playlist->position) |
596 playback_initiate(); | 593 playback_initiate(); |
597 else { | 594 else |
598 mainwin_clear_song_info(); | 595 mainwin_clear_song_info(); |
599 } | |
600 } | 596 } |
601 | 597 |
602 playlist_manager_update(); | 598 playlist_manager_update(); |
603 } | 599 } |
604 | 600 |
632 playlist_recalc_total_time(playlist); | 628 playlist_recalc_total_time(playlist); |
633 | 629 |
634 if (restart_playing) { | 630 if (restart_playing) { |
635 if (playlist->position) | 631 if (playlist->position) |
636 playback_initiate(); | 632 playback_initiate(); |
637 else { | 633 else |
638 mainwin_clear_song_info(); | 634 mainwin_clear_song_info(); |
639 } | |
640 } | 635 } |
641 | 636 |
642 playlistwin_update_list(playlist); | 637 playlistwin_update_list(playlist); |
643 playlist_manager_update(); | 638 playlist_manager_update(); |
644 } | 639 } |
671 gint pos, | 666 gint pos, |
672 Tuple *tuple, | 667 Tuple *tuple, |
673 InputPlugin * dec) | 668 InputPlugin * dec) |
674 { | 669 { |
675 PlaylistEntry *entry; | 670 PlaylistEntry *entry; |
676 gint subtunes_num = 0, i = 0; | 671 Tuple *main_tuple = NULL; |
672 gint nsubtunes = 0, i = 0; | |
673 gboolean add_flag = TRUE; | |
677 | 674 |
678 g_return_if_fail(playlist != NULL); | 675 g_return_if_fail(playlist != NULL); |
679 g_return_if_fail(filename != NULL); | 676 g_return_if_fail(filename != NULL); |
680 | 677 |
681 if (tuple != NULL) | 678 if (tuple != NULL) { |
682 { | 679 nsubtunes = tuple->nsubtunes; |
683 subtunes_num = tuple_get_int(tuple, FIELD_SUBSONG_NUM, NULL); | 680 if (nsubtunes > 0) { |
684 if (subtunes_num > 0) | 681 main_tuple = tuple; |
685 { | |
686 i = 1; | 682 i = 1; |
687 tuple_free(tuple); /* will be replaced by subtune tuples */ | 683 } |
688 } | 684 } |
689 } | 685 |
690 | 686 for (; add_flag && i <= nsubtunes; i++) { |
691 for (; i <= subtunes_num; i++) | |
692 { | |
693 gchar *filename_entry; | 687 gchar *filename_entry; |
694 if (subtunes_num > 0) | 688 |
695 { | 689 if (nsubtunes > 0) { |
696 filename_entry = g_strdup_printf("%s?%d", filename, i); | 690 filename_entry = g_strdup_printf("%s?%d", filename, main_tuple->subtunes[i]); |
697 /* we're dealing with subtune, let's ask again tuple information | 691 /* We're dealing with subtune, let's ask again tuple information |
698 to plugin, by passing the ?subsong suffix; this way we may get | 692 * to plugin, by passing the ?subtune suffix; this way we get |
699 specific subtune information in the tuple, if available */ | 693 * specific subtune information in the tuple, if available. |
694 */ | |
700 tuple = dec->get_song_tuple(filename_entry); | 695 tuple = dec->get_song_tuple(filename_entry); |
701 } | 696 } else |
702 else | |
703 filename_entry = g_strdup(filename); | 697 filename_entry = g_strdup(filename); |
704 | 698 |
705 | 699 |
706 entry = playlist_entry_new(filename_entry, | 700 entry = playlist_entry_new(filename_entry, |
707 tuple ? tuple_get_string(tuple, FIELD_TITLE, NULL) : NULL, | 701 tuple ? tuple_get_string(tuple, FIELD_TITLE, NULL) : NULL, |
708 tuple ? tuple_get_int(tuple, FIELD_LENGTH, NULL) : -1, dec); | 702 tuple ? tuple_get_int(tuple, FIELD_LENGTH, NULL) : -1, dec); |
709 g_free(filename_entry); | 703 g_free(filename_entry); |
710 | 704 |
711 if(!playlist->tail) | 705 if (!playlist->tail) |
712 playlist->tail = g_list_last(playlist->entries); | 706 playlist->tail = g_list_last(playlist->entries); |
713 | 707 |
714 PLAYLIST_LOCK(playlist); | 708 PLAYLIST_LOCK(playlist); |
715 | 709 |
716 if ((pos == -1) && (i < 2)) { // the common case | 710 if ((pos == -1) && (i < 2)) { // the common case |
721 element->next = NULL; | 715 element->next = NULL; |
722 | 716 |
723 if(!playlist->entries) { // this is the first element | 717 if(!playlist->entries) { // this is the first element |
724 playlist->entries = element; | 718 playlist->entries = element; |
725 playlist->tail = element; | 719 playlist->tail = element; |
720 } else { // the rests | |
721 if (playlist->tail != NULL) { | |
722 playlist->tail->next = element; | |
723 playlist->tail = element; | |
724 } else | |
725 add_flag = FALSE; | |
726 } | 726 } |
727 else { // the rests | 727 } else { |
728 g_return_if_fail(playlist->tail != NULL); | |
729 playlist->tail->next = element; | |
730 playlist->tail = element; | |
731 } | |
732 } | |
733 else { | |
734 playlist->entries = g_list_insert(playlist->entries, entry, pos); | 728 playlist->entries = g_list_insert(playlist->entries, entry, pos); |
735 } | 729 } |
736 | 730 |
737 PLAYLIST_UNLOCK(playlist); | 731 PLAYLIST_UNLOCK(playlist); |
738 | 732 |
739 if (tuple != NULL) { | 733 if (tuple != NULL) { |
740 const gchar *formatter = tuple_get_string(tuple, FIELD_FORMATTER, NULL); | 734 const gchar *formatter = tuple_get_string(tuple, FIELD_FORMATTER, NULL); |
741 entry->title = tuple_formatter_make_title_string(tuple, formatter ? | 735 entry->title = tuple_formatter_make_title_string(tuple, |
742 formatter : get_gentitle_format()); | 736 formatter ? formatter : get_gentitle_format()); |
743 entry->length = tuple_get_int(tuple, FIELD_LENGTH, NULL); | 737 entry->length = tuple_get_int(tuple, FIELD_LENGTH, NULL); |
744 entry->tuple = tuple; | 738 entry->tuple = tuple; |
745 } | 739 } |
746 } | 740 } |
747 | 741 |
748 if(tuple != NULL && tuple_get_int(tuple, FIELD_MTIME, NULL) == -1) { // kick the scanner thread only if mtime = -1 (uninitialized). | 742 if (main_tuple) |
743 tuple_free(main_tuple); | |
744 | |
745 if (tuple != NULL && tuple_get_int(tuple, FIELD_MTIME, NULL) == -1) { | |
746 // kick the scanner thread only if mtime = -1 (uninitialized) | |
749 g_mutex_lock(mutex_scan); | 747 g_mutex_lock(mutex_scan); |
750 playlist_get_info_scan_active = TRUE; | 748 playlist_get_info_scan_active = TRUE; |
751 g_mutex_unlock(mutex_scan); | 749 g_mutex_unlock(mutex_scan); |
752 g_cond_signal(cond_scan); | 750 g_cond_signal(cond_scan); |
753 } | 751 } |
774 } | 772 } |
775 | 773 |
776 if (playlist->loading_playlist == TRUE || cfg.playlist_detect == TRUE) | 774 if (playlist->loading_playlist == TRUE || cfg.playlist_detect == TRUE) |
777 dec = NULL; | 775 dec = NULL; |
778 else if (!str_has_prefix_nocase(filename, "http://") && | 776 else if (!str_has_prefix_nocase(filename, "http://") && |
779 !str_has_prefix_nocase(filename, "https://")) | 777 !str_has_prefix_nocase(filename, "https://")) { |
780 { | |
781 pr = input_check_file(filename, TRUE); | 778 pr = input_check_file(filename, TRUE); |
782 | 779 |
783 if (pr) | 780 if (pr) { |
784 { | |
785 dec = pr->ip; | 781 dec = pr->ip; |
786 tuple = pr->tuple; | 782 tuple = pr->tuple; |
787 } | 783 } |
788 | |
789 g_free(pr); | 784 g_free(pr); |
790 } | 785 } |
791 | 786 |
792 if (cfg.playlist_detect == TRUE || playlist->loading_playlist == TRUE || (playlist->loading_playlist == FALSE && dec != NULL) || (playlist->loading_playlist == FALSE && !is_playlist_name(filename) && str_has_prefix_nocase(filename, "http"))) | 787 if (cfg.playlist_detect == TRUE || playlist->loading_playlist == TRUE || |
793 { | 788 (playlist->loading_playlist == FALSE && dec != NULL) || |
789 (playlist->loading_playlist == FALSE && !is_playlist_name(filename) && | |
790 str_has_prefix_nocase(filename, "http"))) { | |
794 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, dec); | 791 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, dec); |
795 playlist_generate_shuffle_list(playlist); | 792 playlist_generate_shuffle_list(playlist); |
796 playlistwin_update_list(playlist); | 793 playlistwin_update_list(playlist); |
797 playlist_manager_update(); | 794 playlist_manager_update(); |
798 return TRUE; | 795 return TRUE; |
810 | 807 |
811 /* FIXME: bah, FIFOs actually pass this regular file test */ | 808 /* FIXME: bah, FIFOs actually pass this regular file test */ |
812 if (!vfs_file_test(filename, G_FILE_TEST_IS_REGULAR)) | 809 if (!vfs_file_test(filename, G_FILE_TEST_IS_REGULAR)) |
813 return FALSE; | 810 return FALSE; |
814 | 811 |
815 if (!(file = vfs_fopen(filename, "rb"))) | 812 if ((file = vfs_fopen(filename, "rb")) == NULL) |
816 return FALSE; | 813 return FALSE; |
817 | 814 |
818 r = vfs_fread(buf, 1, sizeof(buf), file); | 815 r = vfs_fread(buf, 1, sizeof(buf), file); |
819 vfs_fclose(file); | 816 vfs_fclose(file); |
820 | 817 |
846 devino_new(dev_t device, | 843 devino_new(dev_t device, |
847 ino_t inode) | 844 ino_t inode) |
848 { | 845 { |
849 DeviceInode *devino = g_new0(DeviceInode, 1); | 846 DeviceInode *devino = g_new0(DeviceInode, 1); |
850 | 847 |
851 if (devino) | 848 if (devino) { |
852 { | |
853 devino->dev = device; | 849 devino->dev = device; |
854 devino->ino = inode; | 850 devino->ino = inode; |
855 } | 851 } |
856 | 852 |
857 return devino; | 853 return devino; |
1110 g_free(playlist->position->title); | 1106 g_free(playlist->position->title); |
1111 playlist->position->title = g_strdup(title); | 1107 playlist->position->title = g_strdup(title); |
1112 playlist->position->length = length; | 1108 playlist->position->length = length; |
1113 | 1109 |
1114 // overwrite tuple::title, mainly for streaming. it may incur side effects. --yaz | 1110 // overwrite tuple::title, mainly for streaming. it may incur side effects. --yaz |
1115 if(playlist->position->tuple && tuple_get_int(playlist->position->tuple, FIELD_LENGTH, NULL) == -1){ | 1111 if (playlist->position->tuple && tuple_get_int(playlist->position->tuple, FIELD_LENGTH, NULL) == -1){ |
1116 tuple_disassociate(playlist->position->tuple, FIELD_TITLE, NULL); | 1112 tuple_disassociate(playlist->position->tuple, FIELD_TITLE, NULL); |
1117 tuple_associate_string(playlist->position->tuple, FIELD_TITLE, NULL, title); | 1113 tuple_associate_string(playlist->position->tuple, FIELD_TITLE, NULL, title); |
1118 } | 1114 } |
1119 } | 1115 } |
1120 | 1116 |
1149 | 1145 |
1150 playlist_recalc_total_time(playlist); | 1146 playlist_recalc_total_time(playlist); |
1151 | 1147 |
1152 mainwin_set_song_info(rate, freq, nch); | 1148 mainwin_set_song_info(rate, freq, nch); |
1153 | 1149 |
1154 if ( playlist->position ) | 1150 if (playlist->position) |
1155 hook_call( "playlist set info" , playlist->position ); | 1151 hook_call( "playlist set info" , playlist->position ); |
1156 } | 1152 } |
1157 | 1153 |
1158 void | 1154 void |
1159 playlist_check_pos_current(Playlist *playlist) | 1155 playlist_check_pos_current(Playlist *playlist) |
1187 void | 1183 void |
1188 playlist_next(Playlist *playlist) | 1184 playlist_next(Playlist *playlist) |
1189 { | 1185 { |
1190 GList *plist_pos_list; | 1186 GList *plist_pos_list; |
1191 gboolean restart_playing = FALSE; | 1187 gboolean restart_playing = FALSE; |
1188 | |
1192 if (!playlist_get_length(playlist)) | 1189 if (!playlist_get_length(playlist)) |
1193 return; | 1190 return; |
1194 | 1191 |
1195 PLAYLIST_LOCK(playlist); | 1192 PLAYLIST_LOCK(playlist); |
1196 | 1193 |
1197 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | 1194 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) { |
1198 { | |
1199 playlist->position = playlist_position_before_jump; | 1195 playlist->position = playlist_position_before_jump; |
1200 playlist_position_before_jump = NULL; | 1196 playlist_position_before_jump = NULL; |
1201 } | 1197 } |
1202 | 1198 |
1203 plist_pos_list = find_playlist_position_list(playlist); | 1199 plist_pos_list = find_playlist_position_list(playlist); |
1228 if (cfg.shuffle) | 1224 if (cfg.shuffle) |
1229 playlist->position = playlist->shuffle->data; | 1225 playlist->position = playlist->shuffle->data; |
1230 else | 1226 else |
1231 playlist->position = playlist->entries->data; | 1227 playlist->position = playlist->entries->data; |
1232 } | 1228 } |
1233 PLAYLIST_UNLOCK(playlist); | 1229 |
1230 PLAYLIST_UNLOCK(playlist); | |
1231 | |
1234 playlist_check_pos_current(playlist); | 1232 playlist_check_pos_current(playlist); |
1235 | 1233 |
1236 if (restart_playing) | 1234 if (restart_playing) |
1237 playback_initiate(); | 1235 playback_initiate(); |
1238 | 1236 |
1249 if (!playlist_get_length(playlist)) | 1247 if (!playlist_get_length(playlist)) |
1250 return; | 1248 return; |
1251 | 1249 |
1252 PLAYLIST_LOCK(playlist); | 1250 PLAYLIST_LOCK(playlist); |
1253 | 1251 |
1254 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | 1252 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) { |
1255 { | |
1256 playlist->position = playlist_position_before_jump; | 1253 playlist->position = playlist_position_before_jump; |
1257 playlist_position_before_jump = NULL; | 1254 playlist_position_before_jump = NULL; |
1258 } | 1255 } |
1259 | 1256 |
1260 plist_pos_list = find_playlist_position_list(playlist); | 1257 plist_pos_list = find_playlist_position_list(playlist); |
1308 GList *list = playlist_get_selected(playlist); | 1305 GList *list = playlist_get_selected(playlist); |
1309 GList *it = list; | 1306 GList *it = list; |
1310 | 1307 |
1311 PLAYLIST_LOCK(playlist); | 1308 PLAYLIST_LOCK(playlist); |
1312 | 1309 |
1313 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | 1310 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) { |
1314 { | |
1315 /* Shuffling and this is our first manual jump. */ | 1311 /* Shuffling and this is our first manual jump. */ |
1316 playlist_position_before_jump = playlist->position; | 1312 playlist_position_before_jump = playlist->position; |
1317 } | 1313 } |
1318 | 1314 |
1319 while (it) { | 1315 while (it) { |
1584 * if playlist is properly maintained */ | 1580 * if playlist is properly maintained */ |
1585 if (playlist->position->title) { | 1581 if (playlist->position->title) { |
1586 title = str_to_utf8(playlist->position->title); | 1582 title = str_to_utf8(playlist->position->title); |
1587 } | 1583 } |
1588 else { | 1584 else { |
1589 gchar *realfn = NULL; | 1585 gchar *realfn = g_filename_from_uri(playlist->position->filename, NULL, NULL); |
1590 gchar *basename = NULL; | 1586 gchar *basename = g_path_get_basename(realfn ? realfn : playlist->position->filename); |
1591 realfn = g_filename_from_uri(playlist->position->filename, NULL, NULL); | |
1592 basename = g_path_get_basename(realfn ? realfn : playlist->position->filename); | |
1593 title = filename_to_utf8(basename); | 1587 title = filename_to_utf8(basename); |
1594 g_free(realfn); realfn = NULL; | 1588 g_free(realfn); |
1595 g_free(basename); basename = NULL; | 1589 g_free(basename); |
1596 } | 1590 } |
1597 | 1591 |
1598 /* | 1592 /* |
1599 * If the user don't want numbers in the playlist, don't | 1593 * If the user don't want numbers in the playlist, don't |
1600 * display them in other parts of XMMS | 1594 * display them in other parts of XMMS |
1700 g_return_if_fail(playlist != NULL); | 1694 g_return_if_fail(playlist != NULL); |
1701 g_return_if_fail(playlist_name != NULL); | 1695 g_return_if_fail(playlist_name != NULL); |
1702 | 1696 |
1703 filename = g_strchug(g_strdup(filename_p)); | 1697 filename = g_strchug(g_strdup(filename_p)); |
1704 | 1698 |
1705 if(cfg.convert_slash) | 1699 if (cfg.convert_slash) |
1706 while ((tmp = strchr(filename, '\\')) != NULL) | 1700 while ((tmp = strchr(filename, '\\')) != NULL) |
1707 *tmp = '/'; | 1701 *tmp = '/'; |
1708 | 1702 |
1709 if (filename[0] != '/' && !strstr(filename, "://")) { | 1703 if (filename[0] != '/' && !strstr(filename, "://")) { |
1710 path = g_strdup(playlist_name); | 1704 path = g_strdup(playlist_name); |
1768 g_return_if_fail(playlist_name != NULL); | 1762 g_return_if_fail(playlist_name != NULL); |
1769 g_return_if_fail(playlist != NULL); | 1763 g_return_if_fail(playlist != NULL); |
1770 | 1764 |
1771 filename = g_strchug(g_strdup(filename_p)); | 1765 filename = g_strchug(g_strdup(filename_p)); |
1772 | 1766 |
1773 if(cfg.convert_slash) | 1767 if (cfg.convert_slash) |
1774 while ((tmp = strchr(filename, '\\')) != NULL) | 1768 while ((tmp = strchr(filename, '\\')) != NULL) |
1775 *tmp = '/'; | 1769 *tmp = '/'; |
1776 | 1770 |
1777 if (filename[0] != '/' && !strstr(filename, "://")) { | 1771 if (filename[0] != '/' && !strstr(filename, "://")) { |
1778 path = g_strdup(playlist_name); | 1772 path = g_strdup(playlist_name); |
2003 time_t mtime; | 1997 time_t mtime; |
2004 | 1998 |
2005 if (!playlist) | 1999 if (!playlist) |
2006 return -1; | 2000 return -1; |
2007 | 2001 |
2008 if (!(node = g_list_nth(playlist->entries, pos))) { | 2002 if (!(node = g_list_nth(playlist->entries, pos))) |
2009 return -1; | 2003 return -1; |
2010 } | |
2011 | 2004 |
2012 entry = node->data; | 2005 entry = node->data; |
2013 | 2006 |
2014 if (entry->tuple) | 2007 if (entry->tuple) |
2015 mtime = tuple_get_int(entry->tuple, FIELD_MTIME, NULL); | 2008 mtime = tuple_get_int(entry->tuple, FIELD_MTIME, NULL); |
2019 if (entry->tuple == NULL || | 2012 if (entry->tuple == NULL || |
2020 (mtime != 0 && (mtime == -1 || mtime != playlist_get_mtime(entry->filename)))) { | 2013 (mtime != 0 && (mtime == -1 || mtime != playlist_get_mtime(entry->filename)))) { |
2021 | 2014 |
2022 if (playlist_entry_get_info(entry)) | 2015 if (playlist_entry_get_info(entry)) |
2023 song_time = entry->length; | 2016 song_time = entry->length; |
2024 } | 2017 } else |
2025 else { | |
2026 song_time = entry->length; | 2018 song_time = entry->length; |
2027 } | |
2028 | 2019 |
2029 return song_time; | 2020 return song_time; |
2030 } | 2021 } |
2031 | 2022 |
2032 static gint | 2023 static gint |
2054 | 2045 |
2055 return (tracknumber_a && tracknumber_b ? | 2046 return (tracknumber_a && tracknumber_b ? |
2056 tracknumber_a - tracknumber_b : 0); | 2047 tracknumber_a - tracknumber_b : 0); |
2057 } | 2048 } |
2058 | 2049 |
2050 static void | |
2051 playlist_get_entry_title(PlaylistEntry * e, const gchar ** title) | |
2052 { | |
2053 if (e->title) | |
2054 *title = e->title; | |
2055 else { | |
2056 if (strrchr(e->filename, '/')) | |
2057 *title = strrchr(e->filename, '/') + 1; | |
2058 else | |
2059 *title = e->filename; | |
2060 } | |
2061 } | |
2062 | |
2059 static gint | 2063 static gint |
2060 playlist_compare_playlist(PlaylistEntry * a, | 2064 playlist_compare_playlist(PlaylistEntry * a, |
2061 PlaylistEntry * b) | 2065 PlaylistEntry * b) |
2062 { | 2066 { |
2063 const gchar *a_title = NULL, *b_title = NULL; | 2067 const gchar *a_title = NULL, *b_title = NULL; |
2064 | 2068 |
2065 g_return_val_if_fail(a != NULL, 0); | 2069 g_return_val_if_fail(a != NULL, 0); |
2066 g_return_val_if_fail(b != NULL, 0); | 2070 g_return_val_if_fail(b != NULL, 0); |
2067 | 2071 |
2068 if (a->title != NULL) | 2072 playlist_get_entry_title(a, &a_title); |
2069 a_title = a->title; | 2073 playlist_get_entry_title(b, &b_title); |
2070 else { | |
2071 if (strrchr(a->filename, '/')) | |
2072 a_title = strrchr(a->filename, '/') + 1; | |
2073 else | |
2074 a_title = a->filename; | |
2075 } | |
2076 | |
2077 if (b->title != NULL) | |
2078 b_title = b->title; | |
2079 else { | |
2080 if (strrchr(a->filename, '/')) | |
2081 b_title = strrchr(b->filename, '/') + 1; | |
2082 else | |
2083 b_title = b->filename; | |
2084 } | |
2085 | 2074 |
2086 return strcasecmp(a_title, b_title); | 2075 return strcasecmp(a_title, b_title); |
2087 } | 2076 } |
2088 | 2077 |
2089 static gint | 2078 static gint |
2093 const gchar *a_title = NULL, *b_title = NULL; | 2082 const gchar *a_title = NULL, *b_title = NULL; |
2094 | 2083 |
2095 g_return_val_if_fail(a != NULL, 0); | 2084 g_return_val_if_fail(a != NULL, 0); |
2096 g_return_val_if_fail(b != NULL, 0); | 2085 g_return_val_if_fail(b != NULL, 0); |
2097 | 2086 |
2098 if(!a->tuple) | 2087 if (a->tuple == NULL) |
2099 playlist_entry_get_info(a); | 2088 playlist_entry_get_info(a); |
2100 if(!b->tuple) | 2089 if (b->tuple == NULL) |
2101 playlist_entry_get_info(b); | 2090 playlist_entry_get_info(b); |
2102 | 2091 |
2103 if (a->tuple != NULL) | 2092 if (a->tuple != NULL) |
2104 a_title = tuple_get_string(a->tuple, FIELD_TITLE, NULL); | 2093 a_title = tuple_get_string(a->tuple, FIELD_TITLE, NULL); |
2105 if (b->tuple != NULL) | 2094 if (b->tuple != NULL) |
2106 b_title = tuple_get_string(b->tuple, FIELD_TITLE, NULL); | 2095 b_title = tuple_get_string(b->tuple, FIELD_TITLE, NULL); |
2107 | 2096 |
2108 if (a_title != NULL && b_title != NULL) | 2097 if (a_title != NULL && b_title != NULL) |
2109 return strcasecmp(a_title, b_title); | 2098 return strcasecmp(a_title, b_title); |
2110 | 2099 |
2111 if (a->title != NULL) | 2100 playlist_get_entry_title(a, &a_title); |
2112 a_title = a->title; | 2101 playlist_get_entry_title(b, &b_title); |
2113 else { | |
2114 if (strrchr(a->filename, '/')) | |
2115 a_title = strrchr(a->filename, '/') + 1; | |
2116 else | |
2117 a_title = a->filename; | |
2118 } | |
2119 | |
2120 if (b->title != NULL) | |
2121 b_title = b->title; | |
2122 else { | |
2123 if (strrchr(a->filename, '/')) | |
2124 b_title = strrchr(b->filename, '/') + 1; | |
2125 else | |
2126 b_title = b->filename; | |
2127 } | |
2128 | 2102 |
2129 return strcasecmp(a_title, b_title); | 2103 return strcasecmp(a_title, b_title); |
2130 } | 2104 } |
2131 | 2105 |
2132 static gint | 2106 static gint |
2825 const gchar *a_title, *b_title; | 2799 const gchar *a_title, *b_title; |
2826 | 2800 |
2827 g_return_val_if_fail(a != NULL, 0); | 2801 g_return_val_if_fail(a != NULL, 0); |
2828 g_return_val_if_fail(b != NULL, 0); | 2802 g_return_val_if_fail(b != NULL, 0); |
2829 | 2803 |
2830 if (a->title) | 2804 playlist_get_entry_title(a, &a_title); |
2831 a_title = a->title; | 2805 playlist_get_entry_title(b, &b_title); |
2832 else { | |
2833 if (strrchr(a->filename, '/')) | |
2834 a_title = strrchr(a->filename, '/') + 1; | |
2835 else | |
2836 a_title = a->filename; | |
2837 } | |
2838 | |
2839 if (b->title) | |
2840 b_title = b->title; | |
2841 else { | |
2842 if (strrchr(a->filename, '/')) | |
2843 b_title = strrchr(b->filename, '/') + 1; | |
2844 else | |
2845 b_title = b->filename; | |
2846 } | |
2847 | 2806 |
2848 return strcmp(a_title, b_title); | 2807 return strcmp(a_title, b_title); |
2849 } | 2808 } |
2850 | 2809 |
2851 static gint | 2810 static gint |