[vlc-devel] [PATCH 2/3] medialibrary: move entry point listing calls to list instead of control
Alaric Senat
dev.asenat at posteo.net
Mon Mar 8 13:34:59 UTC 2021
As theses ml calls actually simply list folders, moving them to the
"VLC_ML_LIST" interface makes more sense.
Also now that theses api calls returns `vlc_ml_folder_list_t` the
VLC_ML_LIST_FOLDER enum value is a bit confusing and is renamed
VLC_ML_LIST_ENTRY_POINTS to better reflect its function.
---
include/vlc_media_library.h | 96 ++++++++++++-------
modules/gui/macosx/library/VLCLibraryModel.m | 7 +-
.../gui/qt/medialibrary/mlfoldersmodel.cpp | 10 +-
modules/misc/medialibrary/medialibrary.cpp | 30 +++---
4 files changed, 86 insertions(+), 57 deletions(-)
diff --git a/include/vlc_media_library.h b/include/vlc_media_library.h
index aa995b1deb..9e3895a7d4 100644
--- a/include/vlc_media_library.h
+++ b/include/vlc_media_library.h
@@ -405,39 +405,41 @@ enum vlc_ml_list_queries
VLC_ML_COUNT_HISTORY_BY_TYPE, /**< arg1 vlc_ml_media_type_t: the media type. arg2 (out): vlc_ml_media_list_t***/
VLC_ML_LIST_STREAM_HISTORY, /**< arg1 (out): vlc_ml_media_list_t** */
VLC_ML_COUNT_STREAM_HISTORY, /**< arg1 (out): size_t* */
+ VLC_ML_LIST_ENTRY_POINTS, /**< arg1 bool: list_banned; arg2 (out): vlc_ml_folder_list_t** */
+ VLC_ML_COUNT_ENTRY_POINTS, /**< arg1 bool: list_banned; arg2 (out): size_t* */
/* Album specific listings */
- VLC_ML_LIST_ALBUM_TRACKS, /**< arg1: The album id. arg2 (out): vlc_ml_media_list_t** */
- VLC_ML_COUNT_ALBUM_TRACKS, /**< arg1: The album id. arg2 (out): size_t* */
- VLC_ML_LIST_ALBUM_ARTISTS, /**< arg1: The album id. arg2 (out): vlc_ml_album_list_t** */
- VLC_ML_COUNT_ALBUM_ARTISTS, /**< arg1: The album id. arg2 (out): size_t* */
+ VLC_ML_LIST_ALBUM_TRACKS, /**< arg1: The album id. arg2 (out): vlc_ml_media_list_t** */
+ VLC_ML_COUNT_ALBUM_TRACKS, /**< arg1: The album id. arg2 (out): size_t* */
+ VLC_ML_LIST_ALBUM_ARTISTS, /**< arg1: The album id. arg2 (out): vlc_ml_album_list_t** */
+ VLC_ML_COUNT_ALBUM_ARTISTS, /**< arg1: The album id. arg2 (out): size_t* */
/* Artist specific listings */
- VLC_ML_LIST_ARTIST_ALBUMS, /**< arg1: The artist id. arg2(out): vlc_ml_album_list_t** */
- VLC_ML_COUNT_ARTIST_ALBUMS, /**< arg1: The artist id. arg2(out): size_t* */
- VLC_ML_LIST_ARTIST_TRACKS, /**< arg1: The artist id. arg2(out): vlc_ml_media_list_t** */
- VLC_ML_COUNT_ARTIST_TRACKS, /**< arg1: The artist id. arg2(out): size_t* */
+ VLC_ML_LIST_ARTIST_ALBUMS, /**< arg1: The artist id. arg2(out): vlc_ml_album_list_t** */
+ VLC_ML_COUNT_ARTIST_ALBUMS, /**< arg1: The artist id. arg2(out): size_t* */
+ VLC_ML_LIST_ARTIST_TRACKS, /**< arg1: The artist id. arg2(out): vlc_ml_media_list_t** */
+ VLC_ML_COUNT_ARTIST_TRACKS, /**< arg1: The artist id. arg2(out): size_t* */
/* Genre specific listings */
- VLC_ML_LIST_GENRE_ARTISTS, /**< arg1: genre id; arg2 (out): vlc_ml_artist_list_t** */
- VLC_ML_COUNT_GENRE_ARTISTS, /**< arg1: genre id; arg2 (out): size_t* */
- VLC_ML_LIST_GENRE_TRACKS, /**< arg1: genre id; arg2 (out): vlc_ml_media_list_t** */
- VLC_ML_COUNT_GENRE_TRACKS, /**< arg1: genre id; arg2 (out): size_t* */
- VLC_ML_LIST_GENRE_ALBUMS, /**< arg1: genre id; arg2 (out): vlc_ml_album_list_t** */
- VLC_ML_COUNT_GENRE_ALBUMS, /**< arg1: genre id; arg2 (out): size_t* */
+ VLC_ML_LIST_GENRE_ARTISTS, /**< arg1: genre id; arg2 (out): vlc_ml_artist_list_t** */
+ VLC_ML_COUNT_GENRE_ARTISTS, /**< arg1: genre id; arg2 (out): size_t* */
+ VLC_ML_LIST_GENRE_TRACKS, /**< arg1: genre id; arg2 (out): vlc_ml_media_list_t** */
+ VLC_ML_COUNT_GENRE_TRACKS, /**< arg1: genre id; arg2 (out): size_t* */
+ VLC_ML_LIST_GENRE_ALBUMS, /**< arg1: genre id; arg2 (out): vlc_ml_album_list_t** */
+ VLC_ML_COUNT_GENRE_ALBUMS, /**< arg1: genre id; arg2 (out): size_t* */
/* Show specific listings */
- VLC_ML_LIST_SHOW_EPISODES, /**< arg1: show id; arg2(out): vlc_ml_media_list_t** */
- VLC_ML_COUNT_SHOW_EPISODES, /**< arg1: show id; arg2(out): size_t* */
+ VLC_ML_LIST_SHOW_EPISODES, /**< arg1: show id; arg2(out): vlc_ml_media_list_t** */
+ VLC_ML_COUNT_SHOW_EPISODES, /**< arg1: show id; arg2(out): size_t* */
/* Media specific listings */
- VLC_ML_LIST_MEDIA_LABELS, /**< arg1: media id; arg2 (out): vlc_ml_label_list_t** */
- VLC_ML_COUNT_MEDIA_LABELS, /**< arg1: media id; arg2 (out): size_t* */
- VLC_ML_LIST_MEDIA_BOOKMARKS, /**< arg1: media id; arg2 (out): vlc_ml_bookmark_list_t** */
+ VLC_ML_LIST_MEDIA_LABELS, /**< arg1: media id; arg2 (out): vlc_ml_label_list_t** */
+ VLC_ML_COUNT_MEDIA_LABELS, /**< arg1: media id; arg2 (out): size_t* */
+ VLC_ML_LIST_MEDIA_BOOKMARKS, /**< arg1: media id; arg2 (out): vlc_ml_bookmark_list_t** */
/* Playlist specific listings */
- VLC_ML_LIST_PLAYLIST_MEDIA, /**< arg1: playlist id; arg2 (out): vlc_ml_media_list_t** */
- VLC_ML_COUNT_PLAYLIST_MEDIA, /**< arg1: playlist id; arg2 (out): size_t* */
+ VLC_ML_LIST_PLAYLIST_MEDIA, /**< arg1: playlist id; arg2 (out): vlc_ml_media_list_t** */
+ VLC_ML_COUNT_PLAYLIST_MEDIA, /**< arg1: playlist id; arg2 (out): size_t* */
/* Children entities listing */
VLC_ML_LIST_MEDIA_OF, /**< arg1: parent entity type; arg2: parent entity id; arg3(out): ml_media_list_t** */
@@ -465,8 +467,6 @@ enum vlc_ml_control
VLC_ML_REMOVE_FOLDER, /**< arg1: mrl (const char*) res: can't fail */
VLC_ML_BAN_FOLDER, /**< arg1: mrl (const char*) res: can't fail */
VLC_ML_UNBAN_FOLDER, /**< arg1: mrl (const char*) res: can't fail */
- VLC_ML_LIST_FOLDERS, /**< arg1: entrypoints (vlc_ml_folder_list_t**); res: can fail */
- VLC_ML_LIST_BANNED_FOLDERS, /**< arg1: entrypoints (vlc_ml_folder_list_t**); res: can fail */
VLC_ML_IS_INDEXED, /**< arg1: mrl (const char*) arg2 (out): bool*; res: can fail */
/**
* Reload a specific folder, or all.
@@ -904,18 +904,6 @@ static inline int vlc_ml_unban_folder( vlc_medialibrary_t* p_ml, const char* psz
return vlc_ml_control( p_ml, VLC_ML_UNBAN_FOLDER, psz_folder );
}
-static inline int vlc_ml_list_folder( vlc_medialibrary_t* p_ml,
- vlc_ml_folder_list_t** pp_entrypoints )
-{
- return vlc_ml_control( p_ml, VLC_ML_LIST_FOLDERS, pp_entrypoints );
-}
-
-static inline int vlc_ml_list_banned_folder( vlc_medialibrary_t* p_ml,
- vlc_ml_folder_list_t** pp_entrypoints )
-{
- return vlc_ml_control( p_ml, VLC_ML_LIST_BANNED_FOLDERS, pp_entrypoints );
-}
-
static inline int vlc_ml_is_indexed( vlc_medialibrary_t* p_ml,
const char* psz_mrl, bool* p_res )
{
@@ -1558,6 +1546,44 @@ static inline size_t vlc_ml_count_playlist_media( vlc_medialibrary_t* p_ml, cons
return count;
}
+static inline vlc_ml_folder_list_t* vlc_ml_list_entry_points( vlc_medialibrary_t* p_ml, const vlc_ml_query_params_t* params )
+{
+ vlc_assert( p_ml != NULL );
+ vlc_ml_folder_list_t* res;
+ if ( vlc_ml_list( p_ml, VLC_ML_LIST_ENTRY_POINTS, params, (int)false, &res ) != VLC_SUCCESS )
+ return NULL;
+ return res;
+}
+
+static inline size_t vlc_ml_count_entry_points( vlc_medialibrary_t* p_ml, const vlc_ml_query_params_t* params )
+{
+ vlc_assert( p_ml != NULL );
+ size_t res;
+ if ( vlc_ml_list( p_ml, VLC_ML_COUNT_ENTRY_POINTS, params, (int)false, &res ) != VLC_SUCCESS )
+ return 0;
+ return res;
+}
+
+static inline vlc_ml_folder_list_t*
+vlc_ml_list_banned_entry_points( vlc_medialibrary_t* p_ml, const vlc_ml_query_params_t* params )
+{
+ vlc_assert( p_ml != NULL );
+ vlc_ml_folder_list_t* res;
+ if ( vlc_ml_list( p_ml, VLC_ML_LIST_ENTRY_POINTS, params, true, &res ) != VLC_SUCCESS )
+ return NULL;
+ return res;
+}
+
+static inline size_t vlc_ml_count_banned_entry_points( vlc_medialibrary_t* p_ml,
+ const vlc_ml_query_params_t* params )
+{
+ vlc_assert( p_ml != NULL );
+ size_t res;
+ if ( vlc_ml_list( p_ml, VLC_ML_COUNT_ENTRY_POINTS, params, true, &res ) != VLC_SUCCESS )
+ return 0;
+ return res;
+}
+
#ifdef __cplusplus
}
#endif /* C++ */
diff --git a/modules/gui/macosx/library/VLCLibraryModel.m b/modules/gui/macosx/library/VLCLibraryModel.m
index 8e797ced85..836f177667 100644
--- a/modules/gui/macosx/library/VLCLibraryModel.m
+++ b/modules/gui/macosx/library/VLCLibraryModel.m
@@ -364,10 +364,9 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
- (NSArray<VLCMediaLibraryEntryPoint *> *)listOfMonitoredFolders
{
- vlc_ml_folder_list_t *pp_entrypoints;
- int ret = vlc_ml_list_folder(_p_mediaLibrary, &pp_entrypoints);
- if (ret != VLC_SUCCESS) {
- msg_Err(getIntf(), "failed to retrieve list of monitored library folders (%i)", ret);
+ vlc_ml_folder_list_t *pp_entrypoints = vlc_ml_list_entry_points(_p_mediaLibrary, NULL);
+ if (pp_entrypoints == NULL) {
+ msg_Err(getIntf(), "failed to retrieve list of monitored library folders");
return @[];
}
diff --git a/modules/gui/qt/medialibrary/mlfoldersmodel.cpp b/modules/gui/qt/medialibrary/mlfoldersmodel.cpp
index 03d49bf2d3..ee724e94ed 100644
--- a/modules/gui/qt/medialibrary/mlfoldersmodel.cpp
+++ b/modules/gui/qt/medialibrary/mlfoldersmodel.cpp
@@ -118,9 +118,8 @@ std::vector<MLFoldersBaseModel::EntryPoint> MLFoldersModel::entryPoints() const
{
std::vector<MLFoldersBaseModel::EntryPoint> r;
- vlc_ml_folder_list_t * entrypoints = nullptr;
- vlc_ml_list_folder( ml() , &entrypoints );
- for ( unsigned int i=0 ; i<entrypoints->i_nb_items ; i++ )
+ vlc_ml_folder_list_t* entrypoints = vlc_ml_list_entry_points( ml(), nullptr );
+ for ( unsigned int i = 0; entrypoints && i < entrypoints->i_nb_items; i++ )
r.emplace_back( entrypoints->p_items[i] );
vlc_ml_release( entrypoints );
@@ -159,9 +158,8 @@ std::vector<MLFoldersBaseModel::EntryPoint> MLBannedFoldersModel::entryPoints()
{
std::vector<MLFoldersBaseModel::EntryPoint> r;
- vlc_ml_folder_list_t * entrypoints = nullptr;
- vlc_ml_list_banned_folder( ml() , &entrypoints );
- for ( unsigned int i=0 ; i<entrypoints->i_nb_items ; i++ )
+ vlc_ml_folder_list_t* entrypoints = vlc_ml_list_banned_entry_points( ml(), nullptr );
+ for ( unsigned int i = 0; entrypoints && i < entrypoints->i_nb_items; i++ )
r.emplace_back( entrypoints->p_items[i] );
vlc_ml_release( entrypoints );
diff --git a/modules/misc/medialibrary/medialibrary.cpp b/modules/misc/medialibrary/medialibrary.cpp
index fd1ec59cb7..a64654218a 100644
--- a/modules/misc/medialibrary/medialibrary.cpp
+++ b/modules/misc/medialibrary/medialibrary.cpp
@@ -548,17 +548,6 @@ int MediaLibrary::Control( int query, va_list args )
}
break;
}
- case VLC_ML_LIST_FOLDERS:
- case VLC_ML_LIST_BANNED_FOLDERS:
- {
- auto entryPoints = ( query == VLC_ML_LIST_FOLDERS )
- ? m_ml->entryPoints()->all()
- : m_ml->bannedEntryPoints()->all();
- auto res = ml_convert_list<vlc_ml_folder_list_t,
- vlc_ml_folder_t>( entryPoints );
- *(va_arg( args, vlc_ml_folder_list_t**) ) = res;
- break;
- }
case VLC_ML_IS_INDEXED:
{
auto mrl = va_arg( args, const char* );
@@ -960,7 +949,24 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l
vlc_assert_unreachable();
}
}
-
+ case VLC_ML_LIST_ENTRY_POINTS:
+ {
+ const bool banned = va_arg( args, int ) != 0;
+ const auto query = banned ? m_ml->bannedEntryPoints() : m_ml->entryPoints();
+ if ( query == nullptr )
+ return VLC_EGENERIC;
+ auto* res =
+ ml_convert_list<vlc_ml_folder_list_t, vlc_ml_folder_t>( query->all() );
+ *( va_arg( args, vlc_ml_folder_list_t** ) ) = res;
+ break;
+ }
+ case VLC_ML_COUNT_ENTRY_POINTS:
+ {
+ const bool banned = va_arg( args, int ) != 0;
+ const auto query = banned ? m_ml->bannedEntryPoints() : m_ml->entryPoints();
+ *( va_arg( args, size_t* ) ) = query ? query->count() : 0;
+ break;
+ }
}
return VLC_SUCCESS;
}
--
2.29.2
More information about the vlc-devel
mailing list