[vlc-commits] [Git][videolan/vlc][master] 8 commits: qt/mlvideo: Fix the 'isNew' property
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Sat Jul 9 22:21:43 UTC 2022
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
31e65c12 by Benjamin Arnaud at 2022-07-09T22:02:11+00:00
qt/mlvideo: Fix the 'isNew' property
The previous implementation simply did not work.
- - - - -
5f12cf60 by Benjamin Arnaud at 2022-07-09T22:02:11+00:00
qt/mlvideo: Add the 'setIsNew' function
- - - - -
badffa68 by Benjamin Arnaud at 2022-07-09T22:02:11+00:00
qt/mlvideomodel: Fix the 'onVlcMlEvent' conditions
- - - - -
cb565f71 by Benjamin Arnaud at 2022-07-09T22:02:11+00:00
qt/mlvideogroupsmodel: Fix the 'onVlcMlEvent' conditions
- - - - -
0385fc7e by Benjamin Arnaud at 2022-07-09T22:02:11+00:00
qt/mlartistmodel: Fix the 'onVlcMlEvent' conditions
- - - - -
f2bfb770 by Benjamin Arnaud at 2022-07-09T22:02:11+00:00
qt/medialibrary: Add the 'vlc_ml_media_set_played' function
- - - - -
fdc769f1 by Benjamin Arnaud at 2022-07-09T22:02:11+00:00
qt/mlvideomodel: Add the 'setItemPlayed' function
- - - - -
367f6eaf by Benjamin Arnaud at 2022-07-09T22:02:11+00:00
qml/MLContextMenu: Add the 'mark as seen / unseen' support
fix #26403
- - - - -
9 changed files:
- include/vlc_media_library.h
- modules/gui/qt/medialibrary/mlartistmodel.cpp
- modules/gui/qt/medialibrary/mlvideo.cpp
- modules/gui/qt/medialibrary/mlvideo.hpp
- modules/gui/qt/medialibrary/mlvideogroupsmodel.cpp
- 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
=====================================
@@ -579,6 +579,7 @@ enum vlc_ml_control
VLC_ML_MEDIA_GENERATE_THUMBNAIL, /**< arg1: media id; arg2: vlc_ml_thumbnail_size_t; arg3: width; arg4: height; arg5: position */
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_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 */
@@ -1080,6 +1081,12 @@ static inline int vlc_ml_media_set_type( vlc_medialibrary_t* p_ml, int64_t i_med
return vlc_ml_control( p_ml, VLC_ML_MEDIA_SET_TYPE, i_media_id, (int)i_type );
}
+static inline int vlc_ml_media_set_played( vlc_medialibrary_t* p_ml, int64_t i_media_id,
+ bool b_played )
+{
+ return vlc_ml_control( p_ml, VLC_ML_MEDIA_SET_PLAYED, i_media_id, (int) b_played );
+}
+
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/mlartistmodel.cpp
=====================================
@@ -93,7 +93,7 @@ void MLArtistModel::onVlcMlEvent(const MLEvent &event)
return;
case VLC_ML_EVENT_ARTIST_UPDATED:
{
- MLItemId itemId(event.deletion.i_entity_id, VLC_ML_PARENT_UNKNOWN);
+ MLItemId itemId(event.modification.i_entity_id, VLC_ML_PARENT_UNKNOWN);
updateItemInCache(itemId);
return;
}
=====================================
modules/gui/qt/medialibrary/mlvideo.cpp
=====================================
@@ -83,6 +83,8 @@ MLVideo::MLVideo(const vlc_ml_media_t* data)
{
assert( data->i_type == VLC_ML_MEDIA_TYPE_VIDEO || data->i_type == VLC_ML_MEDIA_TYPE_UNKNOWN );
+ m_isNew = (m_playCount == 0 && m_progress <= 0);
+
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 )
{
@@ -135,7 +137,12 @@ MLVideo::MLVideo(const vlc_ml_media_t* data)
bool MLVideo::isNew() const
{
- return (m_playCount == 1 && m_progress <= 0);
+ return m_isNew;
+}
+
+void MLVideo::setIsNew(bool isNew)
+{
+ m_isNew = isNew;
}
QString MLVideo::getFileName() const
=====================================
modules/gui/qt/medialibrary/mlvideo.hpp
=====================================
@@ -92,6 +92,7 @@ public:
MLVideo(const vlc_ml_media_t *data);
bool isNew() const;
+ void setIsNew(bool isNew);
QString getFileName() const;
QString getTitle() const;
QString getThumbnail(vlc_ml_thumbnail_status_t* status);
@@ -108,6 +109,7 @@ public:
QList<VideoDescription> getVideoDesc() const;
private:
+ bool m_isNew;
QString m_fileName;
QString m_title;
QString m_thumbnail;
=====================================
modules/gui/qt/medialibrary/mlvideogroupsmodel.cpp
=====================================
@@ -189,13 +189,9 @@ void MLVideoGroupsModel::onVlcMlEvent(const MLEvent & event) /* override */
}
case VLC_ML_EVENT_MEDIA_UPDATED:
{
- if (event.creation.media.i_type == VLC_ML_MEDIA_TYPE_VIDEO)
- {
- MLItemId itemId(event.modification.i_entity_id, VLC_ML_PARENT_UNKNOWN);
- updateItemInCache(itemId);
- return;
- }
- break;
+ MLItemId itemId(event.modification.i_entity_id, VLC_ML_PARENT_UNKNOWN);
+ updateItemInCache(itemId);
+ return;
}
case VLC_ML_EVENT_GROUP_DELETED:
{
@@ -205,11 +201,8 @@ void MLVideoGroupsModel::onVlcMlEvent(const MLEvent & event) /* override */
}
case VLC_ML_EVENT_MEDIA_DELETED:
{
- if (event.creation.media.i_type == VLC_ML_MEDIA_TYPE_VIDEO)
- {
- MLItemId itemId(event.deletion.i_entity_id, VLC_ML_PARENT_UNKNOWN);
- deleteItemInCache(itemId);
- }
+ MLItemId itemId(event.deletion.i_entity_id, VLC_ML_PARENT_UNKNOWN);
+ deleteItemInCache(itemId);
return;
}
default:
=====================================
modules/gui/qt/medialibrary/mlvideomodel.cpp
=====================================
@@ -42,6 +42,31 @@ MLVideoModel::MLVideoModel(QObject* parent)
{
}
+// Interface
+
+/* Q_INVOKABLE */ void MLVideoModel::setItemPlayed(const QModelIndex & index, bool played)
+{
+ MLVideo * video = static_cast<MLVideo *>(item(index.row()));
+
+ if (video == nullptr)
+ return;
+
+ assert(m_mediaLib);
+
+ const MLItemId & itemId = video->getId();
+
+ // ML thread
+ m_mediaLib->runOnMLThread(this, [itemId, played] (vlc_medialibrary_t * ml)
+ {
+ vlc_ml_media_set_played(ml, itemId.id, played);
+ });
+
+ // NOTE: We want the change to be visible right away.
+ video->setIsNew(played == false);
+
+ emit dataChanged(index, index, { VIDEO_IS_NEW });
+}
+
QVariant MLVideoModel::itemRoleData(MLItem *item, int role) const
{
const auto video = static_cast<MLVideo *>(item);
@@ -144,32 +169,38 @@ QByteArray MLVideoModel::criteriaToName(vlc_ml_sorting_criteria_t criteria) cons
void MLVideoModel::onVlcMlEvent(const MLEvent &event)
{
- if (event.creation.media.i_type != VLC_ML_MEDIA_TYPE_VIDEO)
- return MLBaseModel::onVlcMlEvent( event );
-
switch (event.i_type)
{
case VLC_ML_EVENT_MEDIA_ADDED:
{
- emit resetRequested();
+ if (event.creation.media.i_type == VLC_ML_MEDIA_TYPE_VIDEO)
+ {
+ emit resetRequested();
+
+ return;
+ }
+
break;
}
case VLC_ML_EVENT_MEDIA_UPDATED:
{
MLItemId itemId(event.modification.i_entity_id, VLC_ML_PARENT_UNKNOWN);
updateItemInCache(itemId);
+
return;
}
case VLC_ML_EVENT_MEDIA_DELETED:
{
MLItemId itemId(event.deletion.i_entity_id, VLC_ML_PARENT_UNKNOWN);
deleteItemInCache(itemId);
+
return;
}
default:
break;
}
- MLBaseModel::onVlcMlEvent( event );
+
+ MLBaseModel::onVlcMlEvent(event);
}
void MLVideoModel::thumbnailUpdated(const QModelIndex& idx, MLItem* mlitem, const QString& mrl, vlc_ml_thumbnail_status_t status)
=====================================
modules/gui/qt/medialibrary/mlvideomodel.hpp
=====================================
@@ -62,6 +62,10 @@ 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.
+ Q_INVOKABLE void setItemPlayed(const QModelIndex & index, bool played);
+
protected:
QVariant itemRoleData(MLItem *item, int role) const override;
=====================================
modules/gui/qt/util/qml/MLContextMenu.qml
=====================================
@@ -26,14 +26,20 @@ import "qrc:///util/Helpers.js" as Helpers
NativeMenu {
id: root
+ // Properties
+
/* required */ property var model: null
property string idDataRole: "id"
property bool showPlayAsAudioAction: false
+ // Signals
+
signal showMediaInformation(int index)
+ // Settings
+
actions: [{
"text": I18n.qtr("Play"),
"action": addAndPlay
@@ -47,22 +53,29 @@ NativeMenu {
}, {
"text": I18n.qtr("Add to a playlist"),
"action": addToAPlaylist
+ }, {
+ "text": I18n.qtr("Mark as seen"),
+ "action": markSeen,
+ "visible": _showSeen
+ }, {
+ "text": I18n.qtr("Mark as unseen"),
+ "action": markUnseen,
+ "visible": _showUnseen
}, {
"text": I18n.qtr("Information"),
"action": _signalShowInformation,
"visible": showInformationAvailable
}]
+ // Events
+
onRequestData: {
model.getData(indexes, function (data) {
setData(requestID, data)
})
}
- function showInformationAvailable(options, indexes) {
- return indexes.length === 1
- && Helpers.isInteger(Helpers.get(options, "information", null))
- }
+ // Functions
function addAndPlay(dataList, options, indexes) {
model.ml.addAndPlay(_mlIDList(dataList), _playerOptions(options))
@@ -80,6 +93,32 @@ NativeMenu {
DialogsProvider.playlistsDialog(_mlIDList(dataList))
}
+ function markSeen(dataList, options, indexes) {
+ model.setItemPlayed(indexes[0], true)
+ }
+
+ function markUnseen(dataList, options, indexes) {
+ model.setItemPlayed(indexes[0], false)
+ }
+
+ function showInformationAvailable(options, indexes) {
+ return indexes.length === 1
+ && Helpers.isInteger(Helpers.get(options, "information", null))
+ }
+
+ // Private
+
+ function _showSeen(options, indexes) {
+ if (indexes.length !== 1)
+ return false
+
+ return model.getDataAt(indexes[0]).isNew
+ }
+
+ function _showUnseen(options, indexes) {
+ return (_showSeen(options, indexes) === false)
+ }
+
function _signalShowInformation(dataList, options) {
var index = Helpers.get(options, "information", null)
console.assert(Helpers.isInteger(index))
=====================================
modules/misc/medialibrary/medialibrary.cpp
=====================================
@@ -622,6 +622,7 @@ int MediaLibrary::Control( int query, va_list args )
case VLC_ML_MEDIA_SET_THUMBNAIL:
case VLC_ML_MEDIA_ADD_EXTERNAL_MRL:
case VLC_ML_MEDIA_SET_TYPE:
+ case VLC_ML_MEDIA_SET_PLAYED:
case VLC_ML_MEDIA_ADD_BOOKMARK:
case VLC_ML_MEDIA_REMOVE_BOOKMARK:
case VLC_ML_MEDIA_REMOVE_ALL_BOOKMARKS:
@@ -1459,6 +1460,17 @@ int MediaLibrary::controlMedia( int query, va_list args )
return VLC_EGENERIC;
return VLC_SUCCESS;
}
+ case VLC_ML_MEDIA_SET_PLAYED:
+ {
+ if ( va_arg( args, int ) )
+ {
+ if ( m->markAsPlayed() == false )
+ return VLC_EGENERIC;
+ }
+ else if ( m->removeFromHistory() == 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/19fb0ec2273a9e585aa59cd2749ae33c73db4cd2...367f6eaf4d2c689bd031a0ad3d09730c4bb68386
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/19fb0ec2273a9e585aa59cd2749ae33c73db4cd2...367f6eaf4d2c689bd031a0ad3d09730c4bb68386
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