2007-02-08 04:33:41 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2007-02-13 00:32:17 +00:00
|
|
|
* $Id$
|
2007-02-08 04:33:41 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Jonathan Gordon
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-02-08 04:33:41 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
2007-02-11 07:32:58 +00:00
|
|
|
#include <string.h>
|
2011-07-20 14:11:15 +00:00
|
|
|
#include <stdio.h>
|
2007-02-08 04:33:41 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "lang.h"
|
|
|
|
#include "action.h"
|
|
|
|
#include "settings.h"
|
2021-04-10 14:42:38 +00:00
|
|
|
#include "string-extra.h"
|
2007-02-08 04:33:41 +00:00
|
|
|
#include "menu.h"
|
|
|
|
#include "playlist_menu.h"
|
|
|
|
|
2007-02-11 07:32:58 +00:00
|
|
|
#include "file.h"
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "playlist.h"
|
|
|
|
#include "tree.h"
|
|
|
|
#include "playlist_viewer.h"
|
|
|
|
#include "talk.h"
|
|
|
|
#include "playlist_catalog.h"
|
2011-07-20 14:11:15 +00:00
|
|
|
#include "splash.h"
|
2021-04-18 18:00:41 +00:00
|
|
|
#include "filetree.h"
|
2007-02-11 07:32:58 +00:00
|
|
|
|
2021-04-18 18:00:41 +00:00
|
|
|
/* load a screen to save the playlist passed in (or current playlist if NULL is passed) */
|
2007-02-11 07:32:58 +00:00
|
|
|
int save_playlist_screen(struct playlist_info* playlist)
|
|
|
|
{
|
2021-04-18 18:00:41 +00:00
|
|
|
|
|
|
|
char directoryonly[MAX_PATH+3];
|
|
|
|
char *filename;
|
|
|
|
|
|
|
|
int resume_index;
|
|
|
|
uint32_t resume_elapsed;
|
|
|
|
uint32_t resume_offset;
|
|
|
|
|
2011-07-20 14:11:15 +00:00
|
|
|
char temp[MAX_PATH+1], *dot;
|
2007-02-11 07:32:58 +00:00
|
|
|
int len;
|
2019-08-18 04:40:45 +00:00
|
|
|
|
2010-08-21 16:14:18 +00:00
|
|
|
playlist_get_name(playlist, temp, sizeof(temp)-1);
|
2007-02-11 07:32:58 +00:00
|
|
|
|
2019-08-18 04:40:45 +00:00
|
|
|
len = strlen(temp);
|
2011-07-20 14:11:15 +00:00
|
|
|
dot = strrchr(temp, '.');
|
2019-08-18 04:40:45 +00:00
|
|
|
|
|
|
|
if (!dot && len <= 1)
|
2011-07-20 14:11:15 +00:00
|
|
|
{
|
2022-11-27 02:21:25 +00:00
|
|
|
catalog_get_directory(temp, sizeof(temp));
|
|
|
|
strlcat(temp, DEFAULT_DYNAMIC_PLAYLIST_NAME, sizeof(temp));
|
2011-07-20 14:11:15 +00:00
|
|
|
}
|
2019-08-18 04:40:45 +00:00
|
|
|
|
|
|
|
dot = strrchr(temp, '.');
|
|
|
|
if (dot) /* remove extension */
|
|
|
|
*dot = '\0';
|
2007-02-11 07:32:58 +00:00
|
|
|
|
2020-07-21 06:33:53 +00:00
|
|
|
if (!kbd_input(temp, sizeof(temp), NULL))
|
2007-02-11 07:32:58 +00:00
|
|
|
{
|
2019-08-18 04:40:45 +00:00
|
|
|
len = strlen(temp);
|
|
|
|
if(len > 4 && !strcasecmp(&temp[len-4], ".m3u"))
|
|
|
|
strlcat(temp, "8", sizeof(temp));
|
|
|
|
else if(len <= 5 || strcasecmp(&temp[len-5], ".m3u8"))
|
|
|
|
strlcat(temp, ".m3u8", sizeof(temp));
|
|
|
|
|
2014-04-08 20:52:37 +00:00
|
|
|
playlist_save(playlist, temp, NULL, 0);
|
2007-02-11 07:32:58 +00:00
|
|
|
|
|
|
|
/* reload in case playlist was saved to cwd */
|
|
|
|
reload_directory();
|
2021-04-18 18:00:41 +00:00
|
|
|
|
|
|
|
/* only reload newly saved playlist if:
|
|
|
|
* playlist is null AND setting is turned on
|
|
|
|
*
|
|
|
|
* if playlist is null, we should be dealing with the current playlist,
|
|
|
|
* and thus we got here from the wps screen. That means we want to reload
|
|
|
|
* the current playlist so the user can make bookmarks. */
|
|
|
|
if ((global_settings.playlist_reload_after_save == true) &&
|
|
|
|
(playlist == NULL))
|
|
|
|
{
|
|
|
|
|
|
|
|
/* at least one slash exists in temp */
|
|
|
|
if (strrchr(temp, '/') != NULL)
|
|
|
|
{
|
|
|
|
filename = strrchr(temp, '/') + 1;
|
|
|
|
|
|
|
|
if (temp[0] == '/') /* most common situation - first char is a slash */
|
|
|
|
{
|
|
|
|
strcpy(directoryonly, temp);
|
|
|
|
directoryonly[filename - temp] = '\0';
|
|
|
|
} else /* there is a slash, but not at the beginning of temp - prepend one */
|
|
|
|
{
|
|
|
|
directoryonly[0] = '/';
|
|
|
|
|
|
|
|
strcpy(directoryonly+1, temp);
|
|
|
|
directoryonly[filename - temp + 1] = '\0';
|
|
|
|
}
|
|
|
|
} else /* temp doesn't contain any slashes, uncommon? */
|
|
|
|
{
|
|
|
|
directoryonly[0] = '/';
|
|
|
|
directoryonly[1] = '\0';
|
|
|
|
filename = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* can't trust index from id3 (don't know why), get it from playlist */
|
|
|
|
resume_index = playlist_get_current()->index;
|
|
|
|
|
|
|
|
struct mp3entry* id3 = audio_current_track();
|
|
|
|
|
|
|
|
/* record elapsed and offset so they don't change when we load new playlist */
|
|
|
|
resume_elapsed = id3->elapsed;
|
|
|
|
resume_offset = id3->offset;
|
|
|
|
|
|
|
|
ft_play_playlist(temp, directoryonly, filename, true);
|
|
|
|
playlist_start(resume_index, resume_elapsed, resume_offset);
|
|
|
|
}
|
|
|
|
/* cancelled out of name selection */
|
|
|
|
} else {
|
|
|
|
return 1;
|
2007-02-11 07:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-02-20 19:06:39 +00:00
|
|
|
|
|
|
|
static int playlist_view_(void)
|
|
|
|
{
|
2022-11-22 19:37:47 +00:00
|
|
|
playlist_viewer_ex(NULL, NULL);
|
2022-11-27 00:15:14 +00:00
|
|
|
FOR_NB_SCREENS(i) /* Playlist Viewer defers skin updates when popping its activity */
|
|
|
|
skin_update(CUSTOM_STATUSBAR, i, SKIN_REFRESH_ALL);
|
2011-07-20 14:11:15 +00:00
|
|
|
return 0;
|
2010-02-20 19:06:39 +00:00
|
|
|
}
|
2021-03-12 18:24:58 +00:00
|
|
|
MENUITEM_FUNCTION(create_playlist_item, 0, ID2P(LANG_CREATE_PLAYLIST),
|
2022-12-17 08:27:21 +00:00
|
|
|
create_playlist, NULL, Icon_NOICON);
|
2011-07-20 14:11:15 +00:00
|
|
|
MENUITEM_FUNCTION(view_cur_playlist, 0,
|
2021-03-12 18:24:58 +00:00
|
|
|
ID2P(LANG_VIEW_DYNAMIC_PLAYLIST),
|
2022-12-17 08:27:21 +00:00
|
|
|
playlist_view_, NULL, Icon_NOICON);
|
2022-12-17 07:43:41 +00:00
|
|
|
MENUITEM_FUNCTION_W_PARAM(save_playlist, 0, ID2P(LANG_SAVE_DYNAMIC_PLAYLIST),
|
2022-12-17 08:27:21 +00:00
|
|
|
save_playlist_screen, NULL, NULL, Icon_NOICON);
|
2007-02-11 07:32:58 +00:00
|
|
|
MENUITEM_SETTING(recursive_dir_insert, &global_settings.recursive_dir_insert, NULL);
|
2011-07-20 14:11:15 +00:00
|
|
|
static int clear_catalog_directory(void)
|
|
|
|
{
|
|
|
|
catalog_set_directory(NULL);
|
|
|
|
settings_save();
|
|
|
|
splash(HZ, ID2P(LANG_RESET_DONE_CLEAR));
|
|
|
|
return false;
|
|
|
|
}
|
2021-03-12 18:24:58 +00:00
|
|
|
MENUITEM_FUNCTION(clear_catalog_directory_item, 0, ID2P(LANG_RESET_PLAYLISTCAT_DIR),
|
2022-12-17 08:27:21 +00:00
|
|
|
clear_catalog_directory, NULL, Icon_file_view_menu);
|
2011-07-20 14:11:15 +00:00
|
|
|
|
|
|
|
/* Playlist viewer settings submenu */
|
|
|
|
MENUITEM_SETTING(show_icons, &global_settings.playlist_viewer_icons, NULL);
|
|
|
|
MENUITEM_SETTING(show_indices, &global_settings.playlist_viewer_indices, NULL);
|
2021-03-12 18:24:58 +00:00
|
|
|
MENUITEM_SETTING(track_display,
|
2011-07-20 14:11:15 +00:00
|
|
|
&global_settings.playlist_viewer_track_display, NULL);
|
2021-03-12 18:24:58 +00:00
|
|
|
MAKE_MENU(viewer_settings_menu, ID2P(LANG_PLAYLISTVIEWER_SETTINGS),
|
2011-07-20 14:11:15 +00:00
|
|
|
NULL, Icon_Playlist,
|
|
|
|
&show_icons, &show_indices, &track_display);
|
|
|
|
|
2021-03-12 18:24:58 +00:00
|
|
|
/* Current Playlist submenu */
|
|
|
|
MENUITEM_SETTING(warn_on_erase, &global_settings.warnon_erase_dynplaylist, NULL);
|
2022-04-22 18:26:37 +00:00
|
|
|
MENUITEM_SETTING(keep_current_track_on_replace, &global_settings.keep_current_track_on_replace_playlist, NULL);
|
2021-03-12 18:24:58 +00:00
|
|
|
MENUITEM_SETTING(show_shuffled_adding_options, &global_settings.show_shuffled_adding_options, NULL);
|
|
|
|
MENUITEM_SETTING(show_queue_options, &global_settings.show_queue_options, NULL);
|
2021-04-18 18:00:41 +00:00
|
|
|
MENUITEM_SETTING(playlist_reload_after_save, &global_settings.playlist_reload_after_save, NULL);
|
2021-03-12 18:24:58 +00:00
|
|
|
MAKE_MENU(currentplaylist_settings_menu, ID2P(LANG_CURRENT_PLAYLIST),
|
|
|
|
NULL, Icon_Playlist,
|
2022-04-22 18:26:37 +00:00
|
|
|
&warn_on_erase,
|
|
|
|
&keep_current_track_on_replace,
|
|
|
|
&show_shuffled_adding_options,
|
|
|
|
&show_queue_options,
|
|
|
|
&playlist_reload_after_save);
|
2007-02-11 07:32:58 +00:00
|
|
|
|
2007-08-05 19:19:39 +00:00
|
|
|
MAKE_MENU(playlist_settings, ID2P(LANG_PLAYLISTS), NULL,
|
2007-03-03 13:52:14 +00:00
|
|
|
Icon_Playlist,
|
2021-03-12 18:24:58 +00:00
|
|
|
&viewer_settings_menu, &recursive_dir_insert, ¤tplaylist_settings_menu);
|
2007-08-05 19:19:39 +00:00
|
|
|
MAKE_MENU(playlist_options, ID2P(LANG_PLAYLISTS), NULL,
|
2007-03-03 13:52:14 +00:00
|
|
|
Icon_Playlist,
|
2011-07-20 14:11:15 +00:00
|
|
|
&create_playlist_item, &view_cur_playlist,
|
|
|
|
&save_playlist, &clear_catalog_directory_item);
|