[vlc-commits] [Git][videolan/vlc][master] 2 commits: qt: add method to get url of parent directory
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Thu Jul 6 16:08:58 UTC 2023
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
9ad44c6f by Mohit Marathe at 2023-07-06T15:40:50+00:00
qt: add method to get url of parent directory
Signed-off-by: Mohit Marathe <mohitmarathe23 at gmail.com>
- - - - -
4c88bf0e by Mohit Marathe at 2023-07-06T15:40:50+00:00
qt: add option to open parent folder in MLContextMenu
Signed-off-by: Mohit Marathe <mohitmarathe23 at gmail.com>
- - - - -
6 changed files:
- modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp
- modules/gui/qt/medialibrary/mlalbumtrackmodel.hpp
- modules/gui/qt/medialibrary/mlhelper.hpp
- modules/gui/qt/medialibrary/mlvideomodel.cpp
- modules/gui/qt/medialibrary/mlvideomodel.hpp
- modules/gui/qt/util/qml/MLContextMenu.qml
Changes:
=====================================
modules/gui/qt/medialibrary/mlalbumtrackmodel.cpp
=====================================
@@ -18,6 +18,7 @@
#include "mlalbumtrackmodel.hpp"
#include "util/vlctick.hpp"
+#include "mlhelper.hpp"
QHash<QByteArray, vlc_ml_sorting_criteria_t> MLAlbumTrackModel::M_names_to_criteria = {
{"id", VLC_ML_SORTING_DEFAULT},
@@ -44,14 +45,19 @@ QVariant MLAlbumTrackModel::itemRoleData(MLItem *item, const int role) const
// Tracks
case TRACK_ID:
return QVariant::fromValue( ml_track->getId() );
- case TRACK_TITLE :
+ case TRACK_TITLE:
return QVariant::fromValue( ml_track->getTitle() );
- case TRACK_COVER :
+ case TRACK_COVER:
return QVariant::fromValue( ml_track->getCover() );
- case TRACK_NUMBER :
+ case TRACK_NUMBER:
return QVariant::fromValue( ml_track->getTrackNumber() );
case TRACK_DISC_NUMBER:
return QVariant::fromValue( ml_track->getDiscNumber() );
+ case TRACK_IS_LOCAL:
+ {
+ QUrl trackUrl(ml_track->getMRL());
+ return QVariant::fromValue( trackUrl.isLocalFile() );
+ }
case TRACK_DURATION :
return QVariant::fromValue( ml_track->getDuration() );
case TRACK_ALBUM:
@@ -77,6 +83,7 @@ QHash<int, QByteArray> MLAlbumTrackModel::roleNames() const
{ TRACK_COVER, "cover" },
{ TRACK_NUMBER, "track_number" },
{ TRACK_DISC_NUMBER, "disc_number" },
+ { TRACK_IS_LOCAL, "isLocal" },
{ TRACK_DURATION, "duration" },
{ TRACK_ALBUM, "album_title"},
{ TRACK_ARTIST, "main_artist"},
@@ -196,3 +203,8 @@ MLAlbumTrackModel::Loader::loadItemById(vlc_medialibrary_t* ml, MLItemId itemId)
return std::make_unique<MLAlbumTrack>(ml, media.get());
}
+/* Q_INVOKABLE */ QUrl MLAlbumTrackModel::getParentURL(const QModelIndex &index)
+{
+ MLAlbumTrack *ml_track = static_cast<MLAlbumTrack *>(item(index.row()));
+ return getParentURLFromMLItem(ml_track);
+}
=====================================
modules/gui/qt/medialibrary/mlalbumtrackmodel.hpp
=====================================
@@ -37,6 +37,7 @@ public:
TRACK_COVER,
TRACK_NUMBER,
TRACK_DISC_NUMBER,
+ TRACK_IS_LOCAL,
TRACK_DURATION,
TRACK_ALBUM,
TRACK_ARTIST,
@@ -53,6 +54,8 @@ public:
QHash<int, QByteArray> roleNames() const override;
+ Q_INVOKABLE QUrl getParentURL(const QModelIndex &index);
+
protected:
QVariant itemRoleData(MLItem *item, int role) const override;
=====================================
modules/gui/qt/medialibrary/mlhelper.hpp
=====================================
@@ -27,9 +27,11 @@
#include <vlc_media_library.h>
#include <QString>
+#include <QUrl>
// Forward declarations
class MLBaseModel;
+class MLItem;
class MLItemId;
class CoverGenerator;
class QUrl;
@@ -101,4 +103,17 @@ void thumbnailCopy(const MLListRange<T> &list, O dst, const int max)
QString urlToDisplayString(const QUrl &url);
+template<typename T>
+QUrl getParentURLFromMLItem(T *mlItem)
+{
+ if (mlItem == nullptr)
+ return QUrl();
+
+ QString mrl = mlItem->getMRL();
+ QUrl fileUrl(mrl);
+ QUrl parentDirUrl = fileUrl.adjusted(QUrl::RemoveFilename);
+
+ return parentDirUrl;
+}
+
#endif // MLHELPER_HPP
=====================================
modules/gui/qt/medialibrary/mlvideomodel.cpp
=====================================
@@ -120,6 +120,11 @@ QVariant MLVideoModel::itemRoleData(MLItem *item, int role) const
}
return QVariant::fromValue( thumbnail );
}
+ case VIDEO_IS_LOCAL:
+ {
+ QUrl videoUrl(video->getMRL());
+ return QVariant::fromValue( videoUrl.isLocalFile() );
+ }
case VIDEO_DURATION:
return QVariant::fromValue( video->getDuration() );
case VIDEO_PROGRESS:
@@ -155,6 +160,7 @@ QHash<int, QByteArray> MLVideoModel::roleNames() const
{ VIDEO_FILENAME, "fileName" },
{ VIDEO_TITLE, "title" },
{ VIDEO_THUMBNAIL, "thumbnail" },
+ { VIDEO_IS_LOCAL, "isLocal"},
{ VIDEO_DURATION, "duration" },
{ VIDEO_PROGRESS, "progress" },
{ VIDEO_PLAYCOUNT, "playcount" },
@@ -302,3 +308,8 @@ MLVideoModel::Loader::loadItemById(vlc_medialibrary_t* ml, MLItemId itemId) cons
return std::make_unique<MLVideo>(media.get());
}
+/* Q_INVOKABLE */ QUrl MLVideoModel::getParentURL(const QModelIndex &index)
+{
+ MLVideo *video = static_cast<MLVideo *>(item(index.row()));
+ return getParentURLFromMLItem(video);
+}
=====================================
modules/gui/qt/medialibrary/mlvideomodel.hpp
=====================================
@@ -43,6 +43,7 @@ public:
VIDEO_FILENAME,
VIDEO_TITLE,
VIDEO_THUMBNAIL,
+ VIDEO_IS_LOCAL,
VIDEO_DURATION,
VIDEO_PROGRESS,
VIDEO_PLAYCOUNT,
@@ -59,10 +60,13 @@ public:
public:
explicit MLVideoModel(QObject* parent = nullptr);
+
virtual ~MLVideoModel() = default;
QHash<int, QByteArray> roleNames() const override;
+ Q_INVOKABLE QUrl getParentURL(const QModelIndex & index);
+
public: // Interface
// NOTE: These functions are useful when we want to apply a change before the database event.
@@ -99,3 +103,4 @@ private:
};
#endif // MCVIDEOMODEL_H
+
=====================================
modules/gui/qt/util/qml/MLContextMenu.qml
=====================================
@@ -69,6 +69,10 @@ NativeMenu {
"text": I18n.qtr("Mark as unseen"),
"action": markUnseen,
"visible": _showUnseen
+ }, {
+ "text": I18n.qtr("Open Containing Folder"),
+ "action": openContainingFolder,
+ "visible": _openContainingFolder
}, {
"text": I18n.qtr("Information"),
"action": _signalShowInformation,
@@ -126,6 +130,13 @@ NativeMenu {
model.setItemPlayed(indexes[0], false)
}
+ function openContainingFolder(dataList, options, indexes) {
+ const parentDir = model.getParentURL(indexes[0]);
+
+ Qt.openUrlExternally(parentDir)
+ }
+
+
function showInformationAvailable(options, indexes) {
return indexes.length === 1
&& Helpers.isInteger(Helpers.get(options, "information", null))
@@ -173,6 +184,16 @@ NativeMenu {
return (isNew === false)
}
+ function _openContainingFolder(options, indexes) {
+ if (indexes.length !== 1)
+ return false
+
+ const isLocal = model.getDataAt(indexes[0]).isLocal
+
+ // NOTE: Strictly comparing 'isLocal' given it might be undefined.
+ return (isLocal === true)
+ }
+
function _signalShowInformation(dataList, options) {
const index = Helpers.get(options, "information", null)
console.assert(Helpers.isInteger(index))
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0ff86bf8a28a080340f600cb8561815fc43e3b4a...4c88bf0e7e531fb001cab26673940dadf472b334
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0ff86bf8a28a080340f600cb8561815fc43e3b4a...4c88bf0e7e531fb001cab26673940dadf472b334
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