summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2019-08-17 23:40:45 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2019-08-18 10:18:31 -0500
commit8b7ae89b43ef4c96b55671759869397676ee9e05 (patch)
treefb40f9f121d6d73667221b08d9af558e02bcae74
parent5a4cdb96b91078c7cd3f8d5a389aace68b530437 (diff)
downloadrockbox-8b7ae89b43ef4c96b55671759869397676ee9e05.tar.gz
rockbox-8b7ae89b43ef4c96b55671759869397676ee9e05.zip
Playlist rework
consolidate some of the playlist create functions remove extensions from playlist naming (you can still add it if you desire) switch to strlcpy, strlcpy functions Change-Id: Ibd62912da4d1f68ed5366baa887d92d4c6b1f933
-rw-r--r--apps/menus/playlist_menu.c27
-rw-r--r--apps/playlist_catalog.c30
-rw-r--r--apps/tree.c9
3 files changed, 41 insertions, 25 deletions
diff --git a/apps/menus/playlist_menu.c b/apps/menus/playlist_menu.c
index 2de73415b2..c0a0d48d45 100644
--- a/apps/menus/playlist_menu.c
+++ b/apps/menus/playlist_menu.c
@@ -42,25 +42,30 @@ int save_playlist_screen(struct playlist_info* playlist)
42{ 42{
43 char temp[MAX_PATH+1], *dot; 43 char temp[MAX_PATH+1], *dot;
44 int len; 44 int len;
45 45
46 playlist_get_name(playlist, temp, sizeof(temp)-1); 46 playlist_get_name(playlist, temp, sizeof(temp)-1);
47 len = strlen(temp);
48 47
48 len = strlen(temp);
49 dot = strrchr(temp, '.'); 49 dot = strrchr(temp, '.');
50 if (!dot) 50
51 if (!dot && len <= 1)
51 { 52 {
52 /* folder of some type */ 53 snprintf(temp, sizeof(temp), "%s%s",
53 if (len > 1) 54 catalog_get_directory(), DEFAULT_DYNAMIC_PLAYLIST_NAME);
54 strcpy(&temp[len-1], ".m3u8");
55 else
56 snprintf(temp, sizeof(temp), "%s%s",
57 catalog_get_directory(), DEFAULT_DYNAMIC_PLAYLIST_NAME);
58 } 55 }
59 else if (len > 4 && !strcasecmp(dot, ".m3u")) 56
60 strcat(temp, "8"); 57 dot = strrchr(temp, '.');
58 if (dot) /* remove extension */
59 *dot = '\0';
61 60
62 if (!kbd_input(temp, sizeof(temp))) 61 if (!kbd_input(temp, sizeof(temp)))
63 { 62 {
63 len = strlen(temp);
64 if(len > 4 && !strcasecmp(&temp[len-4], ".m3u"))
65 strlcat(temp, "8", sizeof(temp));
66 else if(len <= 5 || strcasecmp(&temp[len-5], ".m3u8"))
67 strlcat(temp, ".m3u8", sizeof(temp));
68
64 playlist_save(playlist, temp, NULL, 0); 69 playlist_save(playlist, temp, NULL, 0);
65 70
66 /* reload in case playlist was saved to cwd */ 71 /* reload in case playlist was saved to cwd */
diff --git a/apps/playlist_catalog.c b/apps/playlist_catalog.c
index 2147ea990c..7de907c8d0 100644
--- a/apps/playlist_catalog.c
+++ b/apps/playlist_catalog.c
@@ -326,7 +326,7 @@ bool catalog_add_to_a_playlist(const char* sel, int sel_attr,
326 bool new_playlist, char *m3u8name) 326 bool new_playlist, char *m3u8name)
327{ 327{
328 int result; 328 int result;
329 char playlist[MAX_PATH + 6]; 329 char playlist[MAX_PATH + 7]; /* room for /.m3u8\0*/
330 if (in_add_to_playlist) 330 if (in_add_to_playlist)
331 return false; 331 return false;
332 332
@@ -338,24 +338,32 @@ bool catalog_add_to_a_playlist(const char* sel, int sel_attr,
338 size_t len; 338 size_t len;
339 if (m3u8name == NULL) 339 if (m3u8name == NULL)
340 { 340 {
341 /*If sel is a folder, we prefill the text field with its name*/ 341 const char *name;
342 const char *name = strrchr(sel, '/'); 342 /* If sel is empty, root, or playlist directory we use 'all' */
343 snprintf(playlist, sizeof(playlist), "%s/%s.m3u8", 343 if (!sel || !strcmp(sel, "/") || !strcmp(sel, playlist_dir))
344 {
345 if (!sel || !strcmp(sel, PLAYLIST_CATALOG_DEFAULT_DIR))
346 sel = "/";
347 name = "/all";
348 }
349 else /*If sel is a folder, we prefill the text field with its name*/
350 name = strrchr(sel, '/');
351
352 snprintf(playlist, MAX_PATH + 1, "%s/%s",
344 playlist_dir, 353 playlist_dir,
345 (name!=NULL && (sel_attr & ATTR_DIRECTORY))?name+1:""); 354 (name!=NULL && (sel_attr & ATTR_DIRECTORY))?name+1:"");
346 } 355 }
347 else 356 else
348 strcpy(playlist, m3u8name); 357 strlcpy(playlist, m3u8name, MAX_PATH);
349 358
350 len = strlen(playlist); 359 if (kbd_input(playlist, MAX_PATH))
360 return false;
351 361
362 len = strlen(playlist);
352 if(len > 4 && !strcasecmp(&playlist[len-4], ".m3u")) 363 if(len > 4 && !strcasecmp(&playlist[len-4], ".m3u"))
353 strcat(playlist, "8"); 364 strlcat(playlist, "8", sizeof(playlist));
354 else if(len <= 5 || strcasecmp(&playlist[len-5], ".m3u8")) 365 else if(len <= 5 || strcasecmp(&playlist[len-5], ".m3u8"))
355 strcat(playlist, ".m3u8"); 366 strlcat(playlist, ".m3u8", sizeof(playlist));
356
357 if (kbd_input(playlist, sizeof(playlist)))
358 return false;
359 } 367 }
360 else 368 else
361 { 369 {
diff --git a/apps/tree.c b/apps/tree.c
index 8f0abf4a8b..311c3ce543 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -941,9 +941,11 @@ static int dirbrowse(void)
941 941
942int create_playlist(void) 942int create_playlist(void)
943{ 943{
944 bool ret;
945#if 0 /* handled in catalog_add_to_a_playlist() */
944 char filename[MAX_PATH + 16]; /* add enough space for extension */ 946 char filename[MAX_PATH + 16]; /* add enough space for extension */
945 const char *playlist_dir = catalog_get_directory(); 947 const char *playlist_dir = catalog_get_directory();
946 if (strcmp(tc.currdir, playlist_dir) != 0) 948 if (tc.currdir[1] && strcmp(tc.currdir, playlist_dir) != 0)
947 snprintf(filename, sizeof filename, "%s.m3u8", tc.currdir); 949 snprintf(filename, sizeof filename, "%s.m3u8", tc.currdir);
948 else 950 else
949 snprintf(filename, sizeof filename, "%s/all.m3u8", playlist_dir); 951 snprintf(filename, sizeof filename, "%s/all.m3u8", playlist_dir);
@@ -951,12 +953,13 @@ int create_playlist(void)
951 if (kbd_input(filename, MAX_PATH)) 953 if (kbd_input(filename, MAX_PATH))
952 return 0; 954 return 0;
953 splashf(0, "%s %s", str(LANG_CREATING), filename); 955 splashf(0, "%s %s", str(LANG_CREATING), filename);
956#endif
954 957
955 trigger_cpu_boost(); 958 trigger_cpu_boost();
956 catalog_add_to_a_playlist(tc.currdir, ATTR_DIRECTORY, true, filename); 959 ret = catalog_add_to_a_playlist(tc.currdir, ATTR_DIRECTORY, true, NULL);
957 cancel_cpu_boost(); 960 cancel_cpu_boost();
958 961
959 return 1; 962 return (ret) ? 1 : 0;
960} 963}
961 964
962void browse_context_init(struct browse_context *browse, 965void browse_context_init(struct browse_context *browse,