Mercurial > audlegacy
comparison src/audacious/playlist.c @ 3337:99f34db2c3fc trunk
- fix a bug that playlist_ins_url() always returns 1 even if no url has been added. now playlist_ins_url() returns number of new entries which actually added to the playlist.
- modify playlist_load_ins() to return number of new entries.
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Sun, 12 Aug 2007 21:21:46 +0900 |
parents | ea806daf3ef0 |
children | 71d8d93f1bad |
comparison
equal
deleted
inserted
replaced
3336:904c58081f0a | 3337:99f34db2c3fc |
---|---|
919 } | 919 } |
920 | 920 |
921 guint | 921 guint |
922 playlist_add_url(Playlist * playlist, const gchar * url) | 922 playlist_add_url(Playlist * playlist, const gchar * url) |
923 { | 923 { |
924 return playlist_ins_url(playlist, url, -1); | 924 guint entries; |
925 entries = playlist_ins_url(playlist, url, -1); | |
926 // printf("playlist_add_url: entries = %d\n", entries); | |
927 return entries; | |
925 } | 928 } |
926 | 929 |
927 guint | 930 guint |
928 playlist_ins_dir(Playlist * playlist, const gchar * path, | 931 playlist_ins_dir(Playlist * playlist, const gchar * path, |
929 gint pos, | 932 gint pos, |
965 guint | 968 guint |
966 playlist_ins_url(Playlist * playlist, const gchar * string, | 969 playlist_ins_url(Playlist * playlist, const gchar * string, |
967 gint pos) | 970 gint pos) |
968 { | 971 { |
969 gchar *tmp; | 972 gchar *tmp; |
970 gint i = 1, entries = 0; | 973 gint entries = 0; |
971 gboolean first = TRUE; | |
972 guint firstpos = 0; | |
973 gboolean success = FALSE; | |
974 gchar *decoded = NULL; | 974 gchar *decoded = NULL; |
975 | 975 |
976 g_return_val_if_fail(playlist != NULL, 0); | 976 g_return_val_if_fail(playlist != NULL, 0); |
977 g_return_val_if_fail(string != NULL, 0); | 977 g_return_val_if_fail(string != NULL, 0); |
978 | 978 |
979 playlistwin_update_list(playlist); | 979 // playlistwin_update_list(playlist); // is this necessary? --yaz |
980 | 980 |
981 while (*string) { | 981 while (*string) { |
982 GList *node; | 982 GList *node; |
983 guint i = 0; | |
983 tmp = strchr(string, '\n'); | 984 tmp = strchr(string, '\n'); |
984 if (tmp) { | 985 if (tmp) { |
985 if (*(tmp - 1) == '\r') | 986 if (*(tmp - 1) == '\r') |
986 *(tmp - 1) = '\0'; | 987 *(tmp - 1) = '\0'; |
987 *tmp = '\0'; | 988 *tmp = '\0'; |
994 } | 995 } |
995 else { | 996 else { |
996 if (is_playlist_name(decoded)) { | 997 if (is_playlist_name(decoded)) { |
997 i = playlist_load_ins(playlist, decoded, pos); | 998 i = playlist_load_ins(playlist, decoded, pos); |
998 } | 999 } |
999 else { | 1000 else if (playlist_ins(playlist, decoded, pos)) { |
1000 success = playlist_ins(playlist, decoded, pos); | |
1001 i = 1; | 1001 i = 1; |
1002 } | 1002 } |
1003 } | 1003 } |
1004 | 1004 |
1005 g_free(decoded); | 1005 g_free(decoded); |
1007 PLAYLIST_LOCK(playlist->mutex); | 1007 PLAYLIST_LOCK(playlist->mutex); |
1008 node = g_list_nth(playlist->entries, pos); | 1008 node = g_list_nth(playlist->entries, pos); |
1009 PLAYLIST_UNLOCK(playlist->mutex); | 1009 PLAYLIST_UNLOCK(playlist->mutex); |
1010 | 1010 |
1011 entries += i; | 1011 entries += i; |
1012 | |
1013 if (first) { | |
1014 first = FALSE; | |
1015 firstpos = pos; | |
1016 } | |
1017 | 1012 |
1018 if (pos >= 0) | 1013 if (pos >= 0) |
1019 pos += i; | 1014 pos += i; |
1020 if (!tmp) | 1015 if (!tmp) |
1021 break; | 1016 break; |
1601 } | 1596 } |
1602 | 1597 |
1603 gboolean | 1598 gboolean |
1604 playlist_load(Playlist * playlist, const gchar * filename) | 1599 playlist_load(Playlist * playlist, const gchar * filename) |
1605 { | 1600 { |
1606 gboolean ret = FALSE; | 1601 guint ret = 0; |
1607 g_return_val_if_fail(playlist != NULL, FALSE); | 1602 g_return_val_if_fail(playlist != NULL, FALSE); |
1608 | 1603 |
1609 playlist->loading_playlist = TRUE; | 1604 playlist->loading_playlist = TRUE; |
1610 ret = playlist_load_ins(playlist, filename, -1); | 1605 ret = playlist_load_ins(playlist, filename, -1); |
1611 playlist->loading_playlist = FALSE; | 1606 playlist->loading_playlist = FALSE; |
1612 | 1607 |
1613 return ret; | 1608 return ret ? TRUE : FALSE; |
1614 } | 1609 } |
1615 | 1610 |
1616 void | 1611 void |
1617 playlist_load_ins_file(Playlist *playlist, | 1612 playlist_load_ins_file(Playlist *playlist, |
1618 const gchar * filename_p, | 1613 const gchar * filename_p, |
1751 static guint | 1746 static guint |
1752 playlist_load_ins(Playlist * playlist, const gchar * filename, gint pos) | 1747 playlist_load_ins(Playlist * playlist, const gchar * filename, gint pos) |
1753 { | 1748 { |
1754 PlaylistContainer *plc; | 1749 PlaylistContainer *plc; |
1755 gchar *ext; | 1750 gchar *ext; |
1756 | 1751 gint old_len, new_len; |
1752 | |
1757 g_return_val_if_fail(playlist != NULL, 0); | 1753 g_return_val_if_fail(playlist != NULL, 0); |
1758 g_return_val_if_fail(filename != NULL, 0); | 1754 g_return_val_if_fail(filename != NULL, 0); |
1759 | 1755 |
1760 ext = strrchr(filename, '.') + 1; | 1756 ext = strrchr(filename, '.') + 1; |
1761 plc = playlist_container_find(ext); | 1757 plc = playlist_container_find(ext); |
1762 | 1758 |
1763 g_return_val_if_fail(plc != NULL, 0); | 1759 g_return_val_if_fail(plc != NULL, 0); |
1764 g_return_val_if_fail(plc->plc_read != NULL, 0); | 1760 g_return_val_if_fail(plc->plc_read != NULL, 0); |
1765 | 1761 |
1762 old_len = playlist_get_length(playlist); | |
1766 plc->plc_read(filename, pos); | 1763 plc->plc_read(filename, pos); |
1764 new_len = playlist_get_length(playlist); | |
1767 | 1765 |
1768 playlist_generate_shuffle_list(playlist); | 1766 playlist_generate_shuffle_list(playlist); |
1769 playlistwin_update_list(playlist); | 1767 playlistwin_update_list(playlist); |
1770 | 1768 |
1771 return 1; | 1769 return new_len - old_len; |
1772 } | 1770 } |
1773 | 1771 |
1774 GList * | 1772 GList * |
1775 get_playlist_nth(Playlist *playlist, guint nth) | 1773 get_playlist_nth(Playlist *playlist, guint nth) |
1776 { | 1774 { |