Merge pull request #9255 from jdgleaver/manage-history-favourites

Add history/favourites to 'Playlist Management' menu
This commit is contained in:
Twinaphex 2019-08-06 23:11:17 +02:00 committed by GitHub
commit b322acd935
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 163 additions and 35 deletions

View File

@ -56,17 +56,43 @@ static int action_bind_label_playlist_collection_entry(
const char *label, const char *path,
char *s, size_t len)
{
if (string_is_equal_noncase(path_get_extension(path),
const char *playlist_file = NULL;
if (string_is_empty(path))
return 0;
playlist_file = path_basename(path);
if (string_is_empty(playlist_file))
return 0;
if (string_is_equal_noncase(path_get_extension(playlist_file),
file_path_str(FILE_PATH_LPL_EXTENSION_NO_DOT)))
{
char path_base[PATH_MAX_LENGTH];
path_base[0] = '\0';
/* Handle content history */
if (string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_HISTORY)))
strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_HISTORY_TAB), len);
/* Handle favourites */
else if (string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_FAVORITES)))
strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_FAVORITES_TAB), len);
/* Handle collection playlists */
else
{
char playlist_name[PATH_MAX_LENGTH];
fill_short_pathname_representation_noext(path_base, path,
sizeof(path_base));
playlist_name[0] = '\0';
strlcpy(s, path_base, len);
strlcpy(playlist_name, playlist_file, sizeof(playlist_name));
path_remove_extension(playlist_name);
strlcpy(s, playlist_name, len);
}
}
/* This should never happen, but if it does just set
* the label to the file name (it's better than nothing...) */
else
strlcpy(s, playlist_file, len);
return 0;
}

View File

@ -90,8 +90,43 @@ static int action_get_title_mixer_stream_actions(const char *path, const char *l
static int action_get_title_deferred_playlist_list(const char *path, const char *label, unsigned menu_type, char *s, size_t len)
{
if (!string_is_empty(path))
fill_pathname_base_noext(s, path, len);
const char *playlist_file = NULL;
if (string_is_empty(path))
return 0;
playlist_file = path_basename(path);
if (string_is_empty(playlist_file))
return 0;
if (string_is_equal_noncase(path_get_extension(playlist_file),
file_path_str(FILE_PATH_LPL_EXTENSION_NO_DOT)))
{
/* Handle content history */
if (string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_HISTORY)))
strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_HISTORY_TAB), len);
/* Handle favourites */
else if (string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_FAVORITES)))
strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_FAVORITES_TAB), len);
/* Handle collection playlists */
else
{
char playlist_name[PATH_MAX_LENGTH];
playlist_name[0] = '\0';
strlcpy(playlist_name, playlist_file, sizeof(playlist_name));
path_remove_extension(playlist_name);
strlcpy(s, playlist_name, len);
}
}
/* This should never happen, but if it does just set
* the label to the file name (it's better than nothing...) */
else
strlcpy(s, playlist_file, len);
return 0;
}

View File

@ -952,11 +952,10 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info,
if (string_is_empty(entry->label))
fill_short_pathname_representation(menu_entry_label, entry->path, sizeof(menu_entry_label));
else
{
strlcpy(menu_entry_label, entry->label, sizeof(menu_entry_label));
if (sanitization)
(*sanitization)(menu_entry_label);
}
if (sanitization)
(*sanitization)(menu_entry_label);
if (show_inline_core_name)
{
@ -2416,11 +2415,9 @@ static unsigned menu_displaylist_parse_playlists(
for (i = 0; i < list_size; i++)
{
char label[64];
const char *path = NULL;
enum msg_file_type file_type = FILE_TYPE_NONE;
label[0] = '\0';
const char *path = str_list->elems[i].data;
const char *playlist_file = NULL;
enum msg_file_type file_type = FILE_TYPE_NONE;
switch (str_list->elems[i].attr.i)
{
@ -2436,20 +2433,33 @@ static unsigned menu_displaylist_parse_playlists(
if (file_type == FILE_TYPE_DIRECTORY)
continue;
/* Need to preserve slash first time. */
path = str_list->elems[i].data;
if (string_is_empty(path))
continue;
if (!strstr(path, file_path_str(FILE_PATH_LPL_EXTENSION)) ||
((strcasestr(path, "content") && strcasestr(path, "history"))))
playlist_file = path_basename(path);
if (string_is_empty(playlist_file))
continue;
/* Ignore non-playlist files */
if (!string_is_equal_noncase(path_get_extension(playlist_file),
file_path_str(FILE_PATH_LPL_EXTENSION_NO_DOT)))
continue;
/* Ignore history/favourites */
if (string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_HISTORY)) ||
string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_MUSIC_HISTORY)) ||
string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_VIDEO_HISTORY)) ||
string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_IMAGE_HISTORY)) ||
string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_FAVORITES)))
continue;
file_type = FILE_TYPE_PLAYLIST_COLLECTION;
if (horizontal)
if (!string_is_empty(path))
path = path_basename(path);
path = playlist_file;
if (menu_entries_append_enum(info->list, path, label,
if (menu_entries_append_enum(info->list, path, "",
MENU_ENUM_LABEL_PLAYLIST_COLLECTION_ENTRY,
file_type, 0, 0))
count++;
@ -2676,6 +2686,7 @@ static unsigned menu_displaylist_parse_playlist_manager_list(
if (!settings)
return count;
/* Add collection playlists */
str_list = dir_list_new_special(
settings->paths.directory_playlist,
DIR_LIST_COLLECTIONS, NULL);
@ -2688,7 +2699,8 @@ static unsigned menu_displaylist_parse_playlist_manager_list(
for (i = 0; i < str_list->size; i++)
{
const char *path = str_list->elems[i].data;
const char *path = str_list->elems[i].data;
const char *playlist_file = NULL;
if (str_list->elems[i].attr.i == FILE_TYPE_DIRECTORY)
continue;
@ -2696,8 +2708,24 @@ static unsigned menu_displaylist_parse_playlist_manager_list(
if (string_is_empty(path))
continue;
if (!string_is_equal_noncase(path_get_extension(path),
file_path_str(FILE_PATH_LPL_EXTENSION_NO_DOT)))
playlist_file = path_basename(path);
if (string_is_empty(playlist_file))
continue;
/* Ignore non-playlist files */
if (!string_is_equal_noncase(path_get_extension(playlist_file),
file_path_str(FILE_PATH_LPL_EXTENSION_NO_DOT)))
continue;
/* Ignore history/favourites
* > content_history + favorites are handled separately
* > music/video/image_history are ignored */
if (string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_HISTORY)) ||
string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_MUSIC_HISTORY)) ||
string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_VIDEO_HISTORY)) ||
string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_IMAGE_HISTORY)) ||
string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_FAVORITES)))
continue;
menu_entries_append_enum(info->list,
@ -2713,6 +2741,29 @@ static unsigned menu_displaylist_parse_playlist_manager_list(
/* Not necessary to check for NULL here */
string_list_free(str_list);
/* Add content history */
if (settings->bools.history_list_enable)
if (g_defaults.content_history)
if (playlist_size(g_defaults.content_history) > 0)
if (menu_entries_append_enum(info->list,
playlist_get_conf_path(g_defaults.content_history),
"",
MENU_ENUM_LABEL_PLAYLIST_MANAGER_SETTINGS,
MENU_SETTING_ACTION,
0, 0))
count++;
/* Add favourites */
if (g_defaults.content_favorites)
if (playlist_size(g_defaults.content_favorites) > 0)
if (menu_entries_append_enum(info->list,
playlist_get_conf_path(g_defaults.content_favorites),
"",
MENU_ENUM_LABEL_PLAYLIST_MANAGER_SETTINGS,
MENU_SETTING_ACTION,
0, 0))
count++;
return count;
}
@ -2721,21 +2772,37 @@ static bool menu_displaylist_parse_playlist_manager_settings(
menu_displaylist_info_t *info,
const char *playlist_path)
{
playlist_t *playlist = NULL;
const char *playlist_file = NULL;
playlist_t *playlist = NULL;
if (string_is_empty(playlist_path))
return false;
playlist_file = path_basename(playlist_path);
if (string_is_empty(playlist_file))
return false;
menu_displaylist_set_new_playlist(menu, playlist_path);
playlist = playlist_get_cached();
playlist = playlist_get_cached();
if (!playlist)
return false;
/* Default core association */
menu_entries_append_enum(info->list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_MANAGER_DEFAULT_CORE),
msg_hash_to_str(MENU_ENUM_LABEL_PLAYLIST_MANAGER_DEFAULT_CORE),
MENU_ENUM_LABEL_PLAYLIST_MANAGER_DEFAULT_CORE,
MENU_SETTING_PLAYLIST_MANAGER_DEFAULT_CORE, 0, 0);
/* Default core association
* > This is only shown for collection playlists
* (i.e. it is not relevant for history/favourites) */
if (!string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_HISTORY)) &&
!string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_MUSIC_HISTORY)) &&
!string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_VIDEO_HISTORY)) &&
!string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_IMAGE_HISTORY)) &&
!string_is_equal(playlist_file, file_path_str(FILE_PATH_CONTENT_FAVORITES)))
menu_entries_append_enum(info->list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PLAYLIST_MANAGER_DEFAULT_CORE),
msg_hash_to_str(MENU_ENUM_LABEL_PLAYLIST_MANAGER_DEFAULT_CORE),
MENU_ENUM_LABEL_PLAYLIST_MANAGER_DEFAULT_CORE,
MENU_SETTING_PLAYLIST_MANAGER_DEFAULT_CORE, 0, 0);
/* Reset core associations */
menu_entries_append_enum(info->list,