diff options
Diffstat (limited to 'apps/tagtree.c')
-rw-r--r-- | apps/tagtree.c | 61 |
1 files changed, 51 insertions, 10 deletions
diff --git a/apps/tagtree.c b/apps/tagtree.c index 11ea8ecf4e..85359cac04 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c | |||
@@ -2069,10 +2069,14 @@ int tagtree_get_filename(struct tree_context* c, char *buf, int buflen) | |||
2069 | return 0; | 2069 | return 0; |
2070 | } | 2070 | } |
2071 | 2071 | ||
2072 | static bool insert_all_playlist(struct tree_context *c, int position, bool queue) | 2072 | |
2073 | static bool insert_all_playlist(struct tree_context *c, | ||
2074 | const char* playlist, bool new_playlist, | ||
2075 | int position, bool queue) | ||
2073 | { | 2076 | { |
2074 | struct tagcache_search tcs; | 2077 | struct tagcache_search tcs; |
2075 | int i, n; | 2078 | int i, n; |
2079 | int fd = -1; | ||
2076 | unsigned long last_tick; | 2080 | unsigned long last_tick; |
2077 | char buf[MAX_PATH]; | 2081 | char buf[MAX_PATH]; |
2078 | 2082 | ||
@@ -2084,7 +2088,7 @@ static bool insert_all_playlist(struct tree_context *c, int position, bool queue | |||
2084 | return false; | 2088 | return false; |
2085 | } | 2089 | } |
2086 | 2090 | ||
2087 | if (position == PLAYLIST_REPLACE) | 2091 | if (playlist == NULL && position == PLAYLIST_REPLACE) |
2088 | { | 2092 | { |
2089 | if (playlist_remove_all_tracks(NULL) == 0) | 2093 | if (playlist_remove_all_tracks(NULL) == 0) |
2090 | position = PLAYLIST_INSERT_LAST; | 2094 | position = PLAYLIST_INSERT_LAST; |
@@ -2094,6 +2098,19 @@ static bool insert_all_playlist(struct tree_context *c, int position, bool queue | |||
2094 | return false; | 2098 | return false; |
2095 | } | 2099 | } |
2096 | } | 2100 | } |
2101 | else if (playlist != NULL) | ||
2102 | { | ||
2103 | if (new_playlist) | ||
2104 | fd = open_utf8(playlist, O_CREAT|O_WRONLY|O_TRUNC); | ||
2105 | else | ||
2106 | fd = open(playlist, O_CREAT|O_WRONLY|O_APPEND, 0666); | ||
2107 | |||
2108 | if(fd < 0) | ||
2109 | { | ||
2110 | cpu_boost(false); | ||
2111 | return false; | ||
2112 | } | ||
2113 | } | ||
2097 | 2114 | ||
2098 | last_tick = current_tick + HZ/2; /* Show splash after 0.5 seconds have passed */ | 2115 | last_tick = current_tick + HZ/2; /* Show splash after 0.5 seconds have passed */ |
2099 | splash_progress_set_delay(HZ / 2); /* wait 1/2 sec before progress */ | 2116 | splash_progress_set_delay(HZ / 2); /* wait 1/2 sec before progress */ |
@@ -2115,26 +2132,36 @@ static bool insert_all_playlist(struct tree_context *c, int position, bool queue | |||
2115 | continue; | 2132 | continue; |
2116 | } | 2133 | } |
2117 | 2134 | ||
2118 | if (playlist_insert_track(NULL, buf, position, queue, false) < 0) | 2135 | if (playlist == NULL) |
2119 | { | 2136 | { |
2120 | logf("playlist_insert_track failed"); | 2137 | if (playlist_insert_track(NULL, buf, position, queue, false) < 0) |
2121 | break; | 2138 | { |
2139 | logf("playlist_insert_track failed"); | ||
2140 | break; | ||
2141 | } | ||
2122 | } | 2142 | } |
2143 | else if (fdprintf(fd, "%s\n", buf) <= 0) | ||
2144 | break; | ||
2145 | |||
2123 | yield(); | 2146 | yield(); |
2124 | 2147 | ||
2125 | if (position == PLAYLIST_INSERT_FIRST) | 2148 | if (playlist == NULL && position == PLAYLIST_INSERT_FIRST) |
2126 | { | 2149 | { |
2127 | position = PLAYLIST_INSERT; | 2150 | position = PLAYLIST_INSERT; |
2128 | } | 2151 | } |
2129 | } | 2152 | } |
2130 | playlist_sync(NULL); | 2153 | if (playlist == NULL) |
2154 | playlist_sync(NULL); | ||
2155 | else | ||
2156 | close(fd); | ||
2131 | tagcache_search_finish(&tcs); | 2157 | tagcache_search_finish(&tcs); |
2132 | cpu_boost(false); | 2158 | cpu_boost(false); |
2133 | 2159 | ||
2134 | return true; | 2160 | return true; |
2135 | } | 2161 | } |
2136 | 2162 | ||
2137 | bool tagtree_insert_selection_playlist(int position, bool queue) | 2163 | static bool tagtree_insert_selection(int position, bool queue, |
2164 | const char* playlist, bool new_playlist) | ||
2138 | { | 2165 | { |
2139 | char buf[MAX_PATH]; | 2166 | char buf[MAX_PATH]; |
2140 | int dirlevel = tc->dirlevel; | 2167 | int dirlevel = tc->dirlevel; |
@@ -2201,7 +2228,7 @@ bool tagtree_insert_selection_playlist(int position, bool queue) | |||
2201 | else | 2228 | else |
2202 | { | 2229 | { |
2203 | logf("insert_all_playlist"); | 2230 | logf("insert_all_playlist"); |
2204 | if (!insert_all_playlist(tc, position, queue)) | 2231 | if (!insert_all_playlist(tc, playlist, new_playlist, position, queue)) |
2205 | splash(HZ*2, ID2P(LANG_FAILED)); | 2232 | splash(HZ*2, ID2P(LANG_FAILED)); |
2206 | } | 2233 | } |
2207 | 2234 | ||
@@ -2214,6 +2241,20 @@ bool tagtree_insert_selection_playlist(int position, bool queue) | |||
2214 | return true; | 2241 | return true; |
2215 | } | 2242 | } |
2216 | 2243 | ||
2244 | |||
2245 | bool tagtree_current_playlist_insert(int position, bool queue) | ||
2246 | { | ||
2247 | return tagtree_insert_selection(position, queue, NULL, false); | ||
2248 | } | ||
2249 | |||
2250 | |||
2251 | int tagtree_add_to_playlist(const char* playlist, bool new_playlist) | ||
2252 | { | ||
2253 | if (!new_playlist) | ||
2254 | tagtree_load(tc); /* because display_playlists was called */ | ||
2255 | return tagtree_insert_selection(0, false, playlist, new_playlist) ? 0 : -1; | ||
2256 | } | ||
2257 | |||
2217 | static int tagtree_play_folder(struct tree_context* c) | 2258 | static int tagtree_play_folder(struct tree_context* c) |
2218 | { | 2259 | { |
2219 | int start_index = c->selected_item; | 2260 | int start_index = c->selected_item; |
@@ -2224,7 +2265,7 @@ static int tagtree_play_folder(struct tree_context* c) | |||
2224 | return -1; | 2265 | return -1; |
2225 | } | 2266 | } |
2226 | 2267 | ||
2227 | if (!insert_all_playlist(c, PLAYLIST_INSERT_LAST, false)) | 2268 | if (!insert_all_playlist(c, NULL, false, PLAYLIST_INSERT_LAST, false)) |
2228 | return -2; | 2269 | return -2; |
2229 | 2270 | ||
2230 | if (global_settings.playlist_shuffle) | 2271 | if (global_settings.playlist_shuffle) |