[vlc-commits] [Git][videolan/vlc][master] 4 commits: core/medialibrary: Add the favorite media setter
Steve Lhomme (@robUx4)
gitlab at videolan.org
Sat Jan 14 08:56:16 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
e07e728d by Benjamin Arnaud at 2023-01-14T08:43:40+00:00
core/medialibrary: Add the favorite media setter
- - - - -
fff9bcf6 by Benjamin Arnaud at 2023-01-14T08:43:40+00:00
qt/mlvideo: Add the 'isFavorite' property
- - - - -
1043c0df by Benjamin Arnaud at 2023-01-14T08:43:40+00:00
qt/mlvideomodel: Add the 'favorite' support
- - - - -
64ddf617 by Benjamin Arnaud at 2023-01-14T08:43:40+00:00
qml/MLContextMenu: Add the 'favorite' entries
- - - - -
7 changed files:
- include/vlc_media_library.h
- modules/gui/qt/medialibrary/mlvideo.cpp
- modules/gui/qt/medialibrary/mlvideo.hpp
- modules/gui/qt/medialibrary/mlvideomodel.cpp
- modules/gui/qt/medialibrary/mlvideomodel.hpp
- modules/gui/qt/util/qml/MLContextMenu.qml
- modules/misc/medialibrary/medialibrary.cpp
Changes:
=====================================
include/vlc_media_library.h
=====================================
@@ -581,6 +581,7 @@ enum vlc_ml_control
VLC_ML_MEDIA_ADD_EXTERNAL_MRL, /**< arg1: media id; arg2: const char*; arg3: type(vlc_ml_file_type_t) */
VLC_ML_MEDIA_SET_TYPE, /**< arg1: media id; arg2: vlc_ml_media_type_t */
VLC_ML_MEDIA_SET_PLAYED, /**< arg1: media id; arg2: bool */
+ VLC_ML_MEDIA_SET_FAVORITE, /**< arg1: media id; arg2: bool */
VLC_ML_MEDIA_ADD_BOOKMARK, /**< arg1: media id; arg2: int64_t */
VLC_ML_MEDIA_REMOVE_BOOKMARK, /**< arg1: media id; arg2: int64_t */
VLC_ML_MEDIA_REMOVE_ALL_BOOKMARKS, /**< arg1: media id */
@@ -1088,6 +1089,12 @@ static inline int vlc_ml_media_set_played( vlc_medialibrary_t* p_ml, int64_t i_m
return vlc_ml_control( p_ml, VLC_ML_MEDIA_SET_PLAYED, i_media_id, (int) b_played );
}
+static inline int vlc_ml_media_set_favorite( vlc_medialibrary_t* p_ml, int64_t i_media_id,
+ bool b_favorite )
+{
+ return vlc_ml_control( p_ml, VLC_ML_MEDIA_SET_FAVORITE, i_media_id, (int) b_favorite );
+}
+
static inline vlc_ml_bookmark_list_t*
vlc_ml_list_media_bookmarks( vlc_medialibrary_t* p_ml, const vlc_ml_query_params_t* params,
int64_t i_media_id )
=====================================
modules/gui/qt/medialibrary/mlvideo.cpp
=====================================
@@ -86,6 +86,8 @@ MLVideo::MLVideo(const vlc_ml_media_t* data)
m_isNew = (m_playCount == 0 && m_progress <= 0);
+ m_isFavorite = data->b_is_favorite;
+
for( const vlc_ml_file_t& file: ml_range_iterate<vlc_ml_file_t>( data->p_files ) )
if( file.i_type == VLC_ML_FILE_TYPE_MAIN )
{
@@ -146,6 +148,16 @@ void MLVideo::setIsNew(bool isNew)
m_isNew = isNew;
}
+bool MLVideo::isFavorite() const
+{
+ return m_isFavorite;
+}
+
+void MLVideo::setIsFavorite(bool isFavorite)
+{
+ m_isFavorite = isFavorite;
+}
+
QString MLVideo::getFileName() const
{
return m_fileName;
=====================================
modules/gui/qt/medialibrary/mlvideo.hpp
=====================================
@@ -93,6 +93,8 @@ public:
bool isNew() const;
void setIsNew(bool isNew);
+ bool isFavorite() const;
+ void setIsFavorite(bool isFavorite);
QString getFileName() const;
QString getTitle() const;
QString getThumbnail(vlc_ml_thumbnail_status_t* status);
@@ -110,6 +112,7 @@ public:
private:
bool m_isNew;
+ bool m_isFavorite;
QString m_fileName;
QString m_title;
QString m_thumbnail;
=====================================
modules/gui/qt/medialibrary/mlvideomodel.cpp
=====================================
@@ -54,12 +54,12 @@ MLVideoModel::MLVideoModel(QObject* parent)
assert(m_mediaLib);
- const MLItemId & itemId = video->getId();
+ int64_t id = video->getId().id;
// ML thread
- m_mediaLib->runOnMLThread(this, [itemId, played] (vlc_medialibrary_t * ml)
+ m_mediaLib->runOnMLThread(this, [id, played] (vlc_medialibrary_t * ml)
{
- vlc_ml_media_set_played(ml, itemId.id, played);
+ vlc_ml_media_set_played(ml, id, played);
});
// NOTE: We want the change to be visible right away.
@@ -68,6 +68,29 @@ MLVideoModel::MLVideoModel(QObject* parent)
emit dataChanged(index, index, { VIDEO_IS_NEW });
}
+/* Q_INVOKABLE */ void MLVideoModel::setItemFavorite(const QModelIndex & index, bool favorite)
+{
+ MLVideo * video = static_cast<MLVideo *>(item(index.row()));
+
+ if (video == nullptr)
+ return;
+
+ assert(m_mediaLib);
+
+ int64_t id = video->getId().id;
+
+ // ML thread
+ m_mediaLib->runOnMLThread(this, [id, favorite] (vlc_medialibrary_t * ml)
+ {
+ vlc_ml_media_set_favorite(ml, id, favorite);
+ });
+
+ // NOTE: We want the change to be visible right away.
+ video->setIsFavorite(favorite);
+
+ emit dataChanged(index, index, { VIDEO_IS_FAVORITE });
+}
+
QVariant MLVideoModel::itemRoleData(MLItem *item, int role) const
{
const auto video = static_cast<MLVideo *>(item);
@@ -80,6 +103,8 @@ QVariant MLVideoModel::itemRoleData(MLItem *item, int role) const
return QVariant::fromValue( video->getId() );
case VIDEO_IS_NEW:
return QVariant::fromValue( video->isNew() );
+ case VIDEO_IS_FAVORITE:
+ return QVariant::fromValue( video->isFavorite() );
case VIDEO_FILENAME:
return QVariant::fromValue( video->getFileName() );
case VIDEO_TITLE:
@@ -125,6 +150,7 @@ QHash<int, QByteArray> MLVideoModel::roleNames() const
return {
{ VIDEO_ID, "id" },
{ VIDEO_IS_NEW, "isNew" },
+ { VIDEO_IS_FAVORITE, "isFavorite" },
{ VIDEO_FILENAME, "fileName" },
{ VIDEO_TITLE, "title" },
{ VIDEO_THUMBNAIL, "thumbnail" },
=====================================
modules/gui/qt/medialibrary/mlvideomodel.hpp
=====================================
@@ -39,6 +39,7 @@ public:
enum Role {
VIDEO_ID = Qt::UserRole + 1,
VIDEO_IS_NEW,
+ VIDEO_IS_FAVORITE,
VIDEO_FILENAME,
VIDEO_TITLE,
VIDEO_THUMBNAIL,
@@ -63,9 +64,12 @@ public:
QHash<int, QByteArray> roleNames() const override;
public: // Interface
- // NOTE: This function is useful when we want to apply the change before the database event.
+ // NOTE: These functions are useful when we want to apply a change before the database event.
+
Q_INVOKABLE void setItemPlayed(const QModelIndex & index, bool played);
+ Q_INVOKABLE void setItemFavorite(const QModelIndex & index, bool played);
+
protected:
QVariant itemRoleData(MLItem *item, int role) const override;
=====================================
modules/gui/qt/util/qml/MLContextMenu.qml
=====================================
@@ -50,6 +50,14 @@ NativeMenu {
}, {
"text": I18n.qtr("Enqueue"),
"action": enqueue
+ }, {
+ "text": I18n.qtr("Add to favorites"),
+ "action": addFavorite,
+ "visible": _showAddFavorite
+ }, {
+ "text": I18n.qtr("Remove from favorites"),
+ "action": removeFavorite,
+ "visible": _showRemoveFavorite
}, {
"text": I18n.qtr("Add to a playlist"),
"action": addToAPlaylist
@@ -93,6 +101,14 @@ NativeMenu {
DialogsProvider.playlistsDialog(_mlIDList(dataList))
}
+ function addFavorite(dataList, options, indexes) {
+ model.setItemFavorite(indexes[0], true)
+ }
+
+ function removeFavorite(dataList, options, indexes) {
+ model.setItemFavorite(indexes[0], false)
+ }
+
function markSeen(dataList, options, indexes) {
model.setItemPlayed(indexes[0], true)
}
@@ -108,6 +124,26 @@ NativeMenu {
// Private
+ function _showAddFavorite(options, indexes) {
+ if (indexes.length !== 1)
+ return false
+
+ var isFavorite = model.getDataAt(indexes[0]).isFavorite
+
+ // NOTE: Strictly comparing 'isFavorite' given it might be undefined.
+ return (isFavorite === false)
+ }
+
+ function _showRemoveFavorite(options, indexes) {
+ if (indexes.length !== 1)
+ return false
+
+ var isFavorite = model.getDataAt(indexes[0]).isFavorite
+
+ // NOTE: Strictly comparing 'isFavorite' given it might be undefined.
+ return (isFavorite === true)
+ }
+
function _showSeen(options, indexes) {
if (indexes.length !== 1)
return false
=====================================
modules/misc/medialibrary/medialibrary.cpp
=====================================
@@ -626,6 +626,7 @@ int MediaLibrary::Control( int query, va_list args )
case VLC_ML_MEDIA_ADD_EXTERNAL_MRL:
case VLC_ML_MEDIA_SET_TYPE:
case VLC_ML_MEDIA_SET_PLAYED:
+ case VLC_ML_MEDIA_SET_FAVORITE:
case VLC_ML_MEDIA_ADD_BOOKMARK:
case VLC_ML_MEDIA_REMOVE_BOOKMARK:
case VLC_ML_MEDIA_REMOVE_ALL_BOOKMARKS:
@@ -1474,6 +1475,13 @@ int MediaLibrary::controlMedia( int query, va_list args )
return VLC_EGENERIC;
return VLC_SUCCESS;
}
+ case VLC_ML_MEDIA_SET_FAVORITE:
+ {
+ bool favorite = va_arg( args, int );
+ if ( m->setFavorite( favorite ) == false )
+ return VLC_EGENERIC;
+ return VLC_SUCCESS;
+ }
case VLC_ML_MEDIA_ADD_BOOKMARK:
{
auto time = va_arg( args, int64_t );
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/c619786bc21bbf2dbdc2be707953b2a33d161a0e...64ddf617a707a68a707c34f55bbe9db665a72860
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/c619786bc21bbf2dbdc2be707953b2a33d161a0e...64ddf617a707a68a707c34f55bbe9db665a72860
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