[vlc-devel] [PATCH 08/55] qt: add SortKey-Title map list for playlist

Fatih Uzunoglu fuzun54 at outlook.com
Thu Jan 7 21:36:21 UTC 2021


This patch enables getting a list of sorting keys with titles as a valid model so that there won't be redefinition on the QML side.
---
 .../gui/qt/playlist/playlist_controller.cpp   |  8 ++++++
 .../gui/qt/playlist/playlist_controller.hpp   |  6 +++++
 .../gui/qt/playlist/playlist_controller_p.hpp | 25 +++++++++++++++++++
 3 files changed, 39 insertions(+)

diff --git a/modules/gui/qt/playlist/playlist_controller.cpp b/modules/gui/qt/playlist/playlist_controller.cpp
index ab2a81d0d8..671d98df2e 100644
--- a/modules/gui/qt/playlist/playlist_controller.cpp
+++ b/modules/gui/qt/playlist/playlist_controller.cpp
@@ -286,6 +286,7 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
 PlaylistControllerModelPrivate::PlaylistControllerModelPrivate(PlaylistControllerModel* playlistController)
     : q_ptr(playlistController)
 {
+    fillSortKeyTitleList();
 }
 
 PlaylistControllerModelPrivate::~PlaylistControllerModelPrivate()
@@ -807,6 +808,13 @@ bool PlaylistControllerModel::hasPrev() const
     return d->m_hasPrev;
 }
 
+QVariantList PlaylistControllerModel::getSortKeyTitleList() const
+{
+    Q_D(const PlaylistControllerModel);
+
+    return d->sortKeyTitleList;
+}
+
 
   } // namespace playlist
 } // namespace vlc
diff --git a/modules/gui/qt/playlist/playlist_controller.hpp b/modules/gui/qt/playlist/playlist_controller.hpp
index d285eded3d..27e37c1082 100644
--- a/modules/gui/qt/playlist/playlist_controller.hpp
+++ b/modules/gui/qt/playlist/playlist_controller.hpp
@@ -25,6 +25,8 @@
 
 #include <QObject>
 #include <QVector>
+#include <QVariantList>
+
 #include "media.hpp"
 #include "playlist_common.hpp"
 #include "playlist_item.hpp"
@@ -71,6 +73,8 @@ public:
     };
     Q_ENUM(SortOrder)
 
+    Q_PROPERTY(QVariantList sortKeyTitleList READ getSortKeyTitleList CONSTANT)
+
     Q_PROPERTY(PlaylistPtr playlistPtr READ getPlaylistPtr WRITE setPlaylistPtr NOTIFY playlistPtrChanged)
 
     Q_PROPERTY(PlaylistItem currentItem READ getCurrentItem NOTIFY currentItemChanged)
@@ -122,6 +126,7 @@ public:
     PlaylistControllerModel(vlc_playlist_t *playlist, QObject *parent = nullptr);
     virtual ~PlaylistControllerModel();
 
+
 public slots:
     PlaylistItem getCurrentItem() const;
 
@@ -146,6 +151,7 @@ public slots:
     void setSortOrder(SortOrder sortOrder);
     void switchSortOrder();
 
+    QVariantList getSortKeyTitleList() const;
     PlaylistPtr getPlaylistPtr() const;
     void setPlaylistPtr(PlaylistPtr id);
     void setPlaylistPtr(vlc_playlist_t* newPlaylist);
diff --git a/modules/gui/qt/playlist/playlist_controller_p.hpp b/modules/gui/qt/playlist/playlist_controller_p.hpp
index 4fd22c974e..8ecc26a6ba 100644
--- a/modules/gui/qt/playlist/playlist_controller_p.hpp
+++ b/modules/gui/qt/playlist/playlist_controller_p.hpp
@@ -20,6 +20,8 @@
 
 #include "playlist_controller.hpp"
 
+#include "qt.hpp" // for qtr()
+
 namespace vlc {
 namespace playlist {
 
@@ -63,6 +65,29 @@ public:
     size_t m_count = 0;
     PlaylistControllerModel::SortKey m_sortKey = PlaylistControllerModel::SORT_KEY_NONE;
     PlaylistControllerModel::SortOrder m_sortOrder = PlaylistControllerModel::SORT_ORDER_ASC;
+
+    QVariantList sortKeyTitleList;
+
+private:
+    inline void fillSortKeyTitleList()
+    {
+        auto filler = [this](PlaylistControllerModel::SortKey key, const QString& title) {
+            QVariantMap map;
+            map.insert("key", key);
+            map.insert("title", title);
+            sortKeyTitleList.push_back(map);
+        };
+
+        filler(PlaylistControllerModel::SORT_KEY_DURATION, qtr("Duration"));
+        filler(PlaylistControllerModel::SORT_KEY_ARTIST, qtr("Artist"));
+        filler(PlaylistControllerModel::SORT_KEY_ALBUM, qtr("Album"));
+        filler(PlaylistControllerModel::SORT_KEY_ALBUM_ARTIST, qtr( "Album Artist"));
+        filler(PlaylistControllerModel::SORT_KEY_GENRE, qtr("Genre"));
+        filler(PlaylistControllerModel::SORT_KEY_TRACK_NUMBER, qtr( "Track Number"));
+        filler(PlaylistControllerModel::SORT_KEY_DISC_NUMBER, qtr( "Disc Number"));
+        filler(PlaylistControllerModel::SORT_KEY_URL, qtr("URL"));
+        filler(PlaylistControllerModel::SORT_KEY_RATING, qtr("Rating"));
+    }
 };
 
 } //namespace playlist
-- 
2.27.0



More information about the vlc-devel mailing list