[vlc-commits] [Git][videolan/vlc][master] 4 commits: medialibrary: add VLC_ML_REMOVE_STREAM

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sun Jul 9 11:04:42 UTC 2023



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
8ba9acdc by Mohit Marathe at 2023-07-09T08:59:27+00:00
medialibrary: add VLC_ML_REMOVE_STREAM

Signed-off-by: Mohit Marathe <mohitmarathe23 at gmail.com>

- - - - -
007153c3 by Mohit Marathe at 2023-07-09T08:59:27+00:00
qt: create function to delete a stream item

Signed-off-by: Mohit Marathe <mohitmarathe23 at gmail.com>

- - - - -
2f4f7bf7 by Mohit Marathe at 2023-07-09T08:59:27+00:00
qt: add isDeletable as role of the mlurlmodel

Signed-off-by: Mohit Marathe <mohitmarathe23 at gmail.com>

- - - - -
301cef1b by Mohit Marathe at 2023-07-09T08:59:27+00:00
qt: add option to delete stream/URL item in MLContextMenu

Signed-off-by: Mohit Marathe <mohitmarathe23 at gmail.com>

- - - - -


5 changed files:

- include/vlc_media_library.h
- modules/gui/qt/medialibrary/mlurlmodel.cpp
- modules/gui/qt/medialibrary/mlurlmodel.hpp
- modules/gui/qt/util/qml/MLContextMenu.qml
- modules/misc/medialibrary/medialibrary.cpp


Changes:

=====================================
include/vlc_media_library.h
=====================================
@@ -576,6 +576,8 @@ enum vlc_ml_control
     VLC_ML_NEW_EXTERNAL_MEDIA,      /**< arg1: const char*; arg2(out): vlc_ml_media_t** */
     VLC_ML_NEW_STREAM,              /**< arg1: const char*; arg2(out): vlc_ml_media_t** */
 
+    VLC_ML_REMOVE_STREAM,
+
     /* Media management */
     VLC_ML_MEDIA_UPDATE_PROGRESS,           /**< arg1: media id; arg2: playback position; can fail */
     VLC_ML_MEDIA_GET_MEDIA_PLAYBACK_STATE,  /**< arg1: media id; arg2: vlc_ml_playback_state; arg3: char**; */
@@ -1026,6 +1028,11 @@ static inline vlc_ml_media_t* vlc_ml_new_stream( vlc_medialibrary_t* p_ml, const
     return res;
 }
 
+static inline int vlc_ml_remove_stream( vlc_medialibrary_t* p_ml, int64_t i_media_id )
+{
+    return vlc_ml_control(p_ml, VLC_ML_REMOVE_STREAM, i_media_id);
+}
+
 static inline int vlc_ml_media_update_progress( vlc_medialibrary_t* p_ml, int64_t i_media_id,
                                                 double progress )
 {


=====================================
modules/gui/qt/medialibrary/mlurlmodel.cpp
=====================================
@@ -39,6 +39,8 @@ QVariant MLUrlModel::itemRoleData(MLItem *item, int role) const
         return QVariant::fromValue( ml_url->getUrl() );
     case URL_LAST_PLAYED_DATE :
         return QVariant::fromValue( ml_url->getLastPlayedDate() );
+    case URL_IS_DELETABLE:
+        return QVariant::fromValue( true );
     default :
         return QVariant();
     }
@@ -49,7 +51,8 @@ QHash<int, QByteArray> MLUrlModel::roleNames() const
     return {
         { URL_ID, "id" },
         { URL_URL, "url" },
-        { URL_LAST_PLAYED_DATE, "last_played_date" }
+        { URL_LAST_PLAYED_DATE, "last_played_date" },
+        { URL_IS_DELETABLE, "isDeletable" },
     };
 }
 
@@ -81,6 +84,27 @@ void MLUrlModel::addAndPlay( const QString &url )
     });
 }
 
+void MLUrlModel::deleteStream( const MLItemId itemId )
+{
+    struct Ctx{
+        bool succeed = false;
+    };
+    m_mediaLib->runOnMLThread<Ctx>(this,
+        //ML thread
+        [itemId](vlc_medialibrary_t* ml, Ctx& ctx){
+            int64_t id = itemId.id;
+            vlc_ml_remove_stream(ml, id);
+            ctx.succeed = true;
+        },
+        //UI Thread
+        [this](quint64, Ctx& ctx){
+            if (!ctx.succeed)
+                return;
+
+            emit resetRequested();
+        });
+}
+
 vlc_ml_sorting_criteria_t MLUrlModel::roleToCriteria(int role) const
 {
     switch (role) {


=====================================
modules/gui/qt/medialibrary/mlurlmodel.hpp
=====================================
@@ -50,7 +50,8 @@ public:
     enum Roles {
         URL_ID = Qt::UserRole + 1,
         URL_URL,
-        URL_LAST_PLAYED_DATE
+        URL_LAST_PLAYED_DATE,
+        URL_IS_DELETABLE
     };
     Q_ENUM(Roles)
 
@@ -62,6 +63,8 @@ public:
 
     Q_INVOKABLE void addAndPlay( const QString& url );
 
+    Q_INVOKABLE void deleteStream( const MLItemId itemId );
+
 protected:
     QVariant itemRoleData(MLItem *item, int role) const override;
 


=====================================
modules/gui/qt/util/qml/MLContextMenu.qml
=====================================
@@ -73,6 +73,10 @@ NativeMenu {
             "text": I18n.qtr("Open Containing Folder"),
             "action": openContainingFolder,
             "visible": _openContainingFolder
+        }, {
+            "text": I18n.qtr("Delete"),
+            "action": deleteStream,
+            "visible": _deleteStream
         }, {
             "text": I18n.qtr("Information"),
             "action": _signalShowInformation,
@@ -136,6 +140,9 @@ NativeMenu {
         Qt.openUrlExternally(parentDir)
     }
 
+    function deleteStream(dataList, options, indexes) {
+        model.deleteStream(dataList[0][idDataRole])
+    }
 
     function showInformationAvailable(options, indexes) {
         return indexes.length === 1
@@ -194,6 +201,16 @@ NativeMenu {
         return (isLocal === true)
     }
 
+    function _deleteStream(options, indexes) {
+        if (indexes.length !== 1)
+            return false
+
+        const isDeletable = model.getDataAt(indexes[0]).isDeletable
+
+        // NOTE: Strictly comparing 'isDeletable' given it might be undefined.
+        return (isDeletable === true)
+    }
+
     function _signalShowInformation(dataList, options) {
         const index = Helpers.get(options, "information", null)
         console.assert(Helpers.isInteger(index))


=====================================
modules/misc/medialibrary/medialibrary.cpp
=====================================
@@ -522,6 +522,7 @@ int MediaLibrary::Control( int query, va_list args )
         case VLC_ML_RESUME_BACKGROUND:
         case VLC_ML_NEW_EXTERNAL_MEDIA:
         case VLC_ML_NEW_STREAM:
+        case VLC_ML_REMOVE_STREAM:
         case VLC_ML_MEDIA_GENERATE_THUMBNAIL:
         {
             /* These operations require the media library to be started
@@ -608,6 +609,17 @@ int MediaLibrary::Control( int query, va_list args )
             *va_arg( args, vlc_ml_media_t**) = CreateAndConvert<vlc_ml_media_t>( media.get() );
             return VLC_SUCCESS;
         }
+        case VLC_ML_REMOVE_STREAM:
+        {
+            auto priorityAccess = m_ml->acquirePriorityAccess();
+
+            auto id = va_arg( args, int64_t );
+            auto media = m_ml->media( id );
+            if ( media == nullptr )
+                return VLC_EGENERIC;
+            m_ml->removeExternalMedia( media );
+            return VLC_SUCCESS;
+        }
         case VLC_ML_MEDIA_GENERATE_THUMBNAIL:
         {
             auto priorityAccess = m_ml->acquirePriorityAccess();



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/a4f29f92d165116843b3c82d415ce5e4b136dbea...301cef1b6c315c74eda2d0f46af753ad13404f71

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/a4f29f92d165116843b3c82d415ce5e4b136dbea...301cef1b6c315c74eda2d0f46af753ad13404f71
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