[vlc-commits] [Git][videolan/vlc][master] 3 commits: qt: DialogsProvider: Implement Message box

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Fri May 30 09:09:24 UTC 2025



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
f738a095 by djain at 2025-05-30T08:53:41+00:00
qt: DialogsProvider: Implement Message box

This commit implements a method which returns promise. When the
promise is resolved it generates a Message Box.

- - - - -
f195a01b by djain at 2025-05-30T08:53:41+00:00
qml: MLContextMenu: Add "Delete File" option for Media Files.

With "Delete File" option, media files will be deleted from the source
directory.

- - - - -
166a07af by djain at 2025-05-30T08:53:41+00:00
qt: MLMediaModel: Implemented business logic for deleteFileFromSource method.

This method will check for the write permission of file selected and its parent folder. Then delete the file.

- - - - -


5 changed files:

- modules/gui/qt/dialogs/dialogs_provider.cpp
- modules/gui/qt/dialogs/dialogs_provider.hpp
- modules/gui/qt/medialibrary/mlmediamodel.cpp
- modules/gui/qt/medialibrary/mlmediamodel.hpp
- modules/gui/qt/util/qml/MLContextMenu.qml


Changes:

=====================================
modules/gui/qt/dialogs/dialogs_provider.cpp
=====================================
@@ -67,6 +67,7 @@
 #include <QUrl>
 #include <QInputDialog>
 #include <QPointer>
+#include <QMessageBox>
 
 #define I_OP_DIR_WINTITLE I_DIR_OR_FOLDER( N_("Open Directory"), \
                                            N_("Open Folder") )
@@ -401,6 +402,16 @@ void DialogsProvider::mediaInfoDialog( const MLItemId& itemId )
     }
 }
 
+bool DialogsProvider::getMessageDialog(const QString& message) const
+{
+    QMessageBox messageBox;
+    messageBox.setText(message);
+    messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
+
+    int result = messageBox.exec();
+    return result == QMessageBox::Ok;
+}
+
 void DialogsProvider::mediaCodecDialog()
 {
     ensureDialog(m_mediaInfoDialog);


=====================================
modules/gui/qt/dialogs/dialogs_provider.hpp
=====================================
@@ -177,6 +177,7 @@ public slots:
     void mediaInfoDialog( const PlaylistItem& pItem );
     void mediaInfoDialog( const MLItemId& itemId );
     void mediaCodecDialog();
+    bool getMessageDialog(const QString& message) const;
     void prefsDialog();
     void firstRunDialog();
     void extendedDialog();


=====================================
modules/gui/qt/medialibrary/mlmediamodel.cpp
=====================================
@@ -21,6 +21,7 @@
 
 #include "mlmediamodel.hpp"
 #include "mlhelper.hpp"
+#include <QFile>
 
 MLMediaModel::MLMediaModel(QObject *par)
     : MLBaseModel(par)
@@ -45,14 +46,66 @@ void MLMediaModel::setMediaIsFavorite(const QModelIndex &index, bool isFavorite)
     emit dataChanged(index, index, { MEDIA_IS_FAVORITE });
 }
 
-QUrl MLMediaModel::getParentURL(const QModelIndex &index)
-{
+QUrl MLMediaModel::getParentURL(const QModelIndex &index) {
     const auto media = static_cast<MLMedia *>(item(index.row()));
     assert(media != nullptr);
+    return getParentURL(media);
+}
 
+QUrl MLMediaModel::getParentURL(const MLMedia *media) const{
+    assert(media != nullptr);
     return getParentURLFromURL(media->mrl());
 }
 
+bool MLMediaModel::getPermissions(const MLMedia* media) const
+{
+    QString mrl = media->mrl();
+
+    QUrl fileUrl(mrl);
+    QString localPath = fileUrl.toLocalFile();
+
+    if (localPath.isEmpty())
+        return false;
+
+    QFileDevice::Permissions filePermissions = QFile::permissions(localPath);
+
+    if (!(filePermissions & QFileDevice::WriteUser))
+        return false;
+
+    QUrl parentUrl = getParentURL(media);
+    QString parentPath = parentUrl.toLocalFile();
+
+    if (parentPath.isEmpty())
+        return false;
+
+    QFileDevice::Permissions folderPermissions = QFile::permissions(parentPath);
+
+    return folderPermissions & QFileDevice::WriteUser;
+}
+
+void MLMediaModel::deleteFileFromSource(const QModelIndex &index)
+{
+    const auto media = static_cast<MLMedia *>(item(index.row()));
+    QString mrl = media->mrl();
+
+    QUrl fileUrl(mrl);
+    QString localPath = fileUrl.toLocalFile();
+
+    QFile file(localPath);
+    bool removed = file.remove();
+    if (!removed)
+        return;
+
+    QUrl parentUrl = getParentURL(index);
+    QString parentUrlString = parentUrl.toString();
+
+    m_mediaLib->runOnMLThread(this,
+                              [parentUrlString](vlc_medialibrary_t *ml)
+                              {
+                                  vlc_ml_reload_folder(ml, qtu(parentUrlString));
+                              });
+}
+
 vlc_ml_sorting_criteria_t MLMediaModel::nameToCriteria(QByteArray name) const
 {
     return QHash<QByteArray, vlc_ml_sorting_criteria_t> {
@@ -78,6 +131,7 @@ QHash<int, QByteArray> MLMediaModel::roleNames() const
         {MEDIA_PROGRESS, "progress"},
         {MEDIA_PLAYCOUNT, "playcount"},
         {MEDIA_LAST_PLAYED_DATE, "last_played_date"},
+        {MEDIA_IS_DELETABLE_FILE, "isDeletableFile"},
     };
 }
 
@@ -128,6 +182,8 @@ QVariant MLMediaModel::itemRoleData(const MLItem *item, int role) const
         return QVariant::fromValue(media->playCount());
     case MEDIA_LAST_PLAYED_DATE:
         return QVariant::fromValue( media->lastPlayedDate().toString( QLocale::system().dateFormat( QLocale::ShortFormat ) ) );
+    case MEDIA_IS_DELETABLE_FILE:
+        return QVariant::fromValue(getPermissions(media));
     }
     return {};
 }


=====================================
modules/gui/qt/medialibrary/mlmediamodel.hpp
=====================================
@@ -47,6 +47,7 @@ public:
         MEDIA_PROGRESS,
         MEDIA_PLAYCOUNT,
         MEDIA_LAST_PLAYED_DATE,
+        MEDIA_IS_DELETABLE_FILE,
         MEDIA_ROLES_COUNT,
     };
 
@@ -55,6 +56,9 @@ public:
 
     Q_INVOKABLE void setMediaIsFavorite(const QModelIndex &index, bool isFavorite);
     Q_INVOKABLE QUrl getParentURL(const QModelIndex &index);
+    Q_INVOKABLE QUrl getParentURL(const MLMedia *media) const;
+    Q_INVOKABLE bool getPermissions(const MLMedia* media) const;
+    Q_INVOKABLE void deleteFileFromSource(const QModelIndex &index);
 
 protected:
     QHash<int, QByteArray> roleNames() const override;


=====================================
modules/gui/qt/util/qml/MLContextMenu.qml
=====================================
@@ -89,7 +89,11 @@ NativeMenu {
             "text": qsTr("Information"),
             "action": _signalShowInformation,
             "visible": showInformationAvailable
-        }, {
+        },{
+            "text": qsTr("Delete File From System"),
+            "action": deleteFileFromSource,
+            "visible": _deleteFileFromSource
+        },{
             "text": qsTr("Media Information"),
             "action": function(dataList, options, indexes) {
                 DialogsProvider.mediaInfoDialog(dataList[0][idDataRole])
@@ -160,6 +164,15 @@ NativeMenu {
         model.deleteStream(dataList[0][idDataRole])
     }
 
+    function deleteFileFromSource(dataList, options, indexes) {
+        let confirm = DialogsProvider.getMessageDialog("Are you sure you want to delete this file?");
+        
+        if (confirm) {
+            model.deleteFileFromSource(indexes[0]);
+            console.log("File Deleted !!");
+        }
+    }
+
     function showInformationAvailable(dataList, options, indexes) {
         return indexes.length === 1
                 && Helpers.isInteger(options?.["information"] ?? null)
@@ -201,6 +214,10 @@ NativeMenu {
         return _checkRole(dataList, "isDeletable", true)
     }
 
+    function _deleteFileFromSource(dataList, options, indexes) {
+        return  _checkRole(dataList, "isDeletableFile", true)
+    }
+
     function _signalShowInformation(dataList, options) {
         const index = options?.["information"] ?? null
         console.assert(Helpers.isInteger(index))



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/2a8ab2b23d5c979ba94d3b912eea8f674d880efd...166a07af151a732baa4b36e8a20fffe648b3444d

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/2a8ab2b23d5c979ba94d3b912eea8f674d880efd...166a07af151a732baa4b36e8a20fffe648b3444d
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