[vlc-commits] [Git][videolan/vlc][master] 3 commits: medialib: allow to list audio or video only playlists
Steve Lhomme (@robUx4)
gitlab at videolan.org
Fri May 5 17:50:16 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
793acb3a by Pierre Lamot at 2023-05-05T17:35:39+00:00
medialib: allow to list audio or video only playlists
- - - - -
0af016b1 by Pierre Lamot at 2023-05-05T17:35:39+00:00
qt: allow filtering on video/audio only in MLPlaylistListModel
- - - - -
d060da25 by Pierre Lamot at 2023-05-05T17:35:39+00:00
qml: show video/audio playlists only in Video/Music > Playlists
- - - - -
5 changed files:
- include/vlc_media_library.h
- modules/gui/qt/medialibrary/mlplaylistlistmodel.cpp
- modules/gui/qt/medialibrary/mlplaylistlistmodel.hpp
- modules/gui/qt/medialibrary/qml/PlaylistMediaList.qml
- modules/misc/medialibrary/medialibrary.cpp
Changes:
=====================================
include/vlc_media_library.h
=====================================
@@ -89,6 +89,13 @@ typedef enum vlc_ml_history_type_t
VLC_ML_HISTORY_TYPE_NETWORK,
} vlc_ml_history_type_t;
+typedef enum vlc_ml_playlist_type_t
+{
+ VLC_ML_PLAYLIST_TYPE_ALL,
+ VLC_ML_PLAYLIST_TYPE_AUDIO,
+ VLC_ML_PLAYLIST_TYPE_VIDEO,
+} vlc_ml_playlist_type_t;
+
typedef struct vlc_ml_thumbnail_t
{
char* psz_mrl;
@@ -1738,20 +1745,20 @@ static inline size_t vlc_ml_count_group_media( vlc_medialibrary_t* p_ml, const v
//-------------------------------------------------------------------------------------------------
-static inline vlc_ml_playlist_list_t* vlc_ml_list_playlists( vlc_medialibrary_t* p_ml, const vlc_ml_query_params_t* params )
+static inline vlc_ml_playlist_list_t* vlc_ml_list_playlists( vlc_medialibrary_t* p_ml, const vlc_ml_query_params_t* params, vlc_ml_playlist_type_t playlist_type )
{
vlc_assert( p_ml != NULL );
vlc_ml_playlist_list_t* res;
- if ( vlc_ml_list( p_ml, VLC_ML_LIST_PLAYLISTS, params, &res ) != VLC_SUCCESS )
+ if ( vlc_ml_list( p_ml, VLC_ML_LIST_PLAYLISTS, params, (int) playlist_type, &res ) != VLC_SUCCESS )
return NULL;
return res;
}
-static inline size_t vlc_ml_count_playlists( vlc_medialibrary_t* p_ml, const vlc_ml_query_params_t* params )
+static inline size_t vlc_ml_count_playlists( vlc_medialibrary_t* p_ml, const vlc_ml_query_params_t* params, vlc_ml_playlist_type_t playlist_type)
{
vlc_assert( p_ml != NULL );
size_t count;
- if ( vlc_ml_list( p_ml, VLC_ML_COUNT_PLAYLISTS, params, &count ) != VLC_SUCCESS )
+ if ( vlc_ml_list( p_ml, VLC_ML_COUNT_PLAYLISTS, params, (int) playlist_type, &count ) != VLC_SUCCESS )
return 0;
return count;
}
=====================================
modules/gui/qt/medialibrary/mlplaylistlistmodel.cpp
=====================================
@@ -284,7 +284,7 @@ vlc_ml_sorting_criteria_t MLPlaylistListModel::roleToCriteria(int role) const /*
std::unique_ptr<MLBaseModel::BaseLoader> MLPlaylistListModel::createLoader() const /* override */
{
- return std::make_unique<Loader>(*this);
+ return std::make_unique<Loader>(*this, m_playlistType);
}
//-------------------------------------------------------------------------------------------------
@@ -400,18 +400,48 @@ void MLPlaylistListModel::setCoverPrefix(const QString & prefix)
emit coverPrefixChanged();
}
+MLPlaylistListModel::PlaylistType MLPlaylistListModel::playlistType() const
+{
+ return m_playlistType;
+}
+
+void MLPlaylistListModel::setPlaylistType(PlaylistType playlistType)
+{
+ if (m_playlistType == playlistType)
+ return;
+ m_playlistType = playlistType;
+ resetCache();
+ emit playlistTypeChanged();
+}
+
//=================================================================================================
// Loader
//=================================================================================================
-MLPlaylistListModel::Loader::Loader(const MLPlaylistListModel & model)
- : MLBaseModel::BaseLoader(model) {}
+static inline vlc_ml_playlist_type_t qmlToMLPlaylistType(MLPlaylistListModel::PlaylistType type)
+{
+ switch(type) {
+ case MLPlaylistListModel::PlaylistType::PLAYLIST_TYPE_ALL:
+ return VLC_ML_PLAYLIST_TYPE_ALL;
+ case MLPlaylistListModel::PlaylistType::PLAYLIST_TYPE_AUDIO:
+ return VLC_ML_PLAYLIST_TYPE_AUDIO;
+ case MLPlaylistListModel::PlaylistType::PLAYLIST_TYPE_VIDEO:
+ return VLC_ML_PLAYLIST_TYPE_VIDEO;
+ default:
+ vlc_assert_unreachable();
+ }
+}
+
+MLPlaylistListModel::Loader::Loader(const MLPlaylistListModel & model, PlaylistType playlistType)
+ : MLBaseModel::BaseLoader(model)
+ , m_playlistType(playlistType)
+{}
size_t MLPlaylistListModel::Loader::count(vlc_medialibrary_t* ml) const /* override */
{
vlc_ml_query_params_t params = getParams().toCQueryParams();
-
- return vlc_ml_count_playlists(ml, ¶ms);
+ vlc_ml_playlist_type_t mlPlaylistType = qmlToMLPlaylistType(m_playlistType);
+ return vlc_ml_count_playlists(ml, ¶ms, mlPlaylistType);
}
std::vector<std::unique_ptr<MLItem>>
@@ -419,7 +449,9 @@ MLPlaylistListModel::Loader::load(vlc_medialibrary_t* ml, size_t index, size_t c
{
vlc_ml_query_params_t params = getParams(index, count).toCQueryParams();
- ml_unique_ptr<vlc_ml_playlist_list_t> list(vlc_ml_list_playlists(ml, ¶ms));
+ vlc_ml_playlist_type_t mlPlaylistType = qmlToMLPlaylistType(m_playlistType);
+
+ ml_unique_ptr<vlc_ml_playlist_list_t> list(vlc_ml_list_playlists(ml, ¶ms, mlPlaylistType));
if (list == nullptr)
return {};
=====================================
modules/gui/qt/medialibrary/mlplaylistlistmodel.hpp
=====================================
@@ -30,13 +30,6 @@ class MLPlaylistListModel : public MLBaseModel
{
Q_OBJECT
- Q_PROPERTY(QSize coverSize READ coverSize WRITE setCoverSize NOTIFY coverSizeChanged FINAL)
-
- Q_PROPERTY(QString coverDefault READ coverDefault WRITE setCoverDefault
- NOTIFY coverDefaultChanged FINAL)
-
- Q_PROPERTY(QString coverPrefix READ coverPrefix WRITE setCoverPrefix NOTIFY coverPrefixChanged FINAL)
-
public:
enum Roles
{
@@ -47,6 +40,24 @@ public:
PLAYLIST_COUNT
};
+ enum PlaylistType {
+ PLAYLIST_TYPE_ALL,
+ PLAYLIST_TYPE_AUDIO,
+ PLAYLIST_TYPE_VIDEO,
+ };
+ Q_ENUM(PlaylistType)
+
+public:
+
+ Q_PROPERTY(QSize coverSize READ coverSize WRITE setCoverSize NOTIFY coverSizeChanged FINAL)
+
+ Q_PROPERTY(QString coverDefault READ coverDefault WRITE setCoverDefault
+ NOTIFY coverDefaultChanged FINAL)
+
+ Q_PROPERTY(QString coverPrefix READ coverPrefix WRITE setCoverPrefix NOTIFY coverPrefixChanged FINAL)
+
+ Q_PROPERTY(PlaylistType playlistType READ playlistType WRITE setPlaylistType NOTIFY playlistTypeChanged FINAL)
+
public:
explicit MLPlaylistListModel(QObject * parent = nullptr);
@@ -85,6 +96,7 @@ signals:
void coverSizeChanged ();
void coverDefaultChanged();
void coverPrefixChanged ();
+ void playlistTypeChanged();
public: // Properties
QSize coverSize() const;
@@ -96,10 +108,14 @@ public: // Properties
QString coverPrefix() const;
void setCoverPrefix(const QString & prefix);
+ PlaylistType playlistType() const;
+ void setPlaylistType(PlaylistType type);
+
private: // Variables
QSize m_coverSize;
QString m_coverDefault;
QString m_coverPrefix;
+ PlaylistType m_playlistType = PLAYLIST_TYPE_ALL;
bool m_transactionPending = false;
bool m_resetAfterTransaction = false;
@@ -107,13 +123,15 @@ private: // Variables
private:
struct Loader : public MLBaseModel::BaseLoader
{
- Loader(const MLPlaylistListModel & model);
+ Loader(const MLPlaylistListModel & model, PlaylistType playlistType);
size_t count(vlc_medialibrary_t* ml) const override;
std::vector<std::unique_ptr<MLItem>> load(vlc_medialibrary_t* ml, size_t index, size_t count) const override;
std::unique_ptr<MLItem> loadItemById(vlc_medialibrary_t* ml, MLItemId itemId) const override;
+
+ PlaylistType m_playlistType;
};
};
=====================================
modules/gui/qt/medialibrary/qml/PlaylistMediaList.qml
=====================================
@@ -95,6 +95,9 @@ MainInterface.MainViewLoader {
model: MLPlaylistListModel {
ml: MediaLib
+ playlistType: isMusic ? MLPlaylistListModel.PLAYLIST_TYPE_AUDIO
+ : MLPlaylistListModel.PLAYLIST_TYPE_VIDEO
+
coverSize: (isMusic) ? Qt.size(512, 512)
: Qt.size(1024, 640)
=====================================
modules/misc/medialibrary/medialibrary.cpp
=====================================
@@ -1990,11 +1990,28 @@ int MediaLibrary::listPlaylist( int listQuery, const medialibrary::QueryParamete
case VLC_ML_LIST_PLAYLISTS:
case VLC_ML_COUNT_PLAYLISTS:
{
+ auto vlcPlaylistType = static_cast<vlc_ml_playlist_type_t>(va_arg( args, int ));
+ medialibrary::PlaylistType mlPlaylistType;
+ switch (vlcPlaylistType)
+ {
+ case VLC_ML_PLAYLIST_TYPE_ALL:
+ mlPlaylistType = medialibrary::PlaylistType::All;
+ break;
+ case VLC_ML_PLAYLIST_TYPE_VIDEO:
+ mlPlaylistType = medialibrary::PlaylistType::VideoOnly;
+ break;
+ case VLC_ML_PLAYLIST_TYPE_AUDIO:
+ mlPlaylistType = medialibrary::PlaylistType::AudioOnly;
+ break;
+ default:
+ vlc_assert_unreachable();
+ }
+
medialibrary::Query<medialibrary::IPlaylist> query;
if ( pattern != nullptr )
query = m_ml->searchPlaylists( pattern, paramsPtr );
else
- query = m_ml->playlists( medialibrary::PlaylistType::All, paramsPtr );
+ query = m_ml->playlists( mlPlaylistType, paramsPtr );
if ( query == nullptr )
return VLC_EGENERIC;
switch ( listQuery )
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/d109df247cc401225f305307041123df09b45b52...d060da25a89311b9eba3fe25af705a875364e490
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/d109df247cc401225f305307041123df09b45b52...d060da25a89311b9eba3fe25af705a875364e490
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list