[vlc-commits] qt: make playlist sort attributes playlist properties

Fatih Uzunoglu git at videolan.org
Thu Oct 15 10:32:38 CEST 2020


vlc | branch: master | Fatih Uzunoglu <fuzun54 at outlook.com> | Fri Oct  9 19:56:29 2020 +0300| [35b5d03b282aee00480ddc5be819ab1e5d377779] | committer: Pierre Lamot

qt: make playlist sort attributes playlist properties

+ add SORT_KEY_NONE to SortKey enum

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=35b5d03b282aee00480ddc5be819ab1e5d377779
---

 modules/gui/qt/playlist/playlist_controller.cpp   | 79 ++++++++++++++++++++++-
 modules/gui/qt/playlist/playlist_controller.hpp   | 19 +++++-
 modules/gui/qt/playlist/playlist_controller_p.hpp |  2 +
 3 files changed, 97 insertions(+), 3 deletions(-)

diff --git a/modules/gui/qt/playlist/playlist_controller.cpp b/modules/gui/qt/playlist/playlist_controller.cpp
index 4215e774e6..6d9932e49d 100644
--- a/modules/gui/qt/playlist/playlist_controller.cpp
+++ b/modules/gui/qt/playlist/playlist_controller.cpp
@@ -303,6 +303,9 @@ PlaylistControllerModel::PlaylistControllerModel(QObject *parent)
     : QObject(parent)
     , d_ptr( new PlaylistControllerModelPrivate(this) )
 {
+    connect(this, &PlaylistControllerModel::itemsMoved, this, &PlaylistControllerModel::resetSortKey);
+    connect(this, &PlaylistControllerModel::itemsAdded, this, &PlaylistControllerModel::resetSortKey);
+    connect(this, &PlaylistControllerModel::isEmptyChanged, [this](bool isEmpty) {if (isEmpty) emit resetSortKey();});
 }
 
 PlaylistControllerModel::PlaylistControllerModel(vlc_playlist_t *playlist, QObject *parent)
@@ -455,9 +458,23 @@ PlaylistControllerModel::sort(const QVector<vlc_playlist_sort_criterion> &criter
 
 void PlaylistControllerModel::sort(PlaylistControllerModel::SortKey key, PlaylistControllerModel::SortOrder order)
 {
+    if(key != SortKey::SORT_KEY_NONE)
+        setSortKey(key);
+    setSortOrder(order);
+
+    sort();
+}
+
+void PlaylistControllerModel::sort(void)
+{
+    Q_D(PlaylistControllerModel);
+
+    if (d->m_sortKey == SortKey::SORT_KEY_NONE)
+        return;
+
     vlc_playlist_sort_criterion crit = {
-        static_cast<vlc_playlist_sort_key>(key) ,
-        static_cast<vlc_playlist_sort_order>(order)
+        static_cast<vlc_playlist_sort_key>(d->m_sortKey),
+        static_cast<vlc_playlist_sort_order>(d->m_sortOrder)
     };
     QVector<vlc_playlist_sort_criterion> criteria { crit };
     sort( criteria );
@@ -657,6 +674,13 @@ void PlaylistControllerModel::setPlaylistPtr(vlc_playlist_t* newPlaylist)
     emit playlistPtrChanged( PlaylistPtr(newPlaylist) );
 }
 
+void PlaylistControllerModel::resetSortKey()
+{
+    Q_D(PlaylistControllerModel);
+    d->m_sortKey = SortKey::SORT_KEY_NONE;
+    emit sortKeyChanged();
+}
+
 void PlaylistControllerModel::setPlaylistPtr(PlaylistPtr ptr)
 {
     setPlaylistPtr(ptr.m_playlist);
@@ -702,6 +726,57 @@ size_t PlaylistControllerModel::count() const
     return d->m_count;
 }
 
+void PlaylistControllerModel::setSortKey(SortKey sortKey)
+{
+    Q_D(PlaylistControllerModel);
+
+    if (sortKey == d->m_sortKey)
+        return;
+
+    d->m_sortKey = sortKey;
+    emit sortKeyChanged();
+}
+
+void PlaylistControllerModel::setSortOrder(SortOrder sortOrder)
+{
+    Q_D(PlaylistControllerModel);
+
+    SortOrder order = d->m_sortOrder;
+    if(sortOrder == order)
+        return;
+
+    d->m_sortOrder = sortOrder;
+    emit sortOrderChanged();
+}
+
+void PlaylistControllerModel::switchSortOrder()
+{
+    Q_D(PlaylistControllerModel);
+
+    SortOrder order = d->m_sortOrder;
+    if (order == SortOrder::SORT_ORDER_ASC)
+        order = SortOrder::SORT_ORDER_DESC;
+    else if (order == SortOrder::SORT_ORDER_DESC)
+        order = SortOrder::SORT_ORDER_ASC;
+    else
+        return;
+
+    d->m_sortOrder = order;
+    emit sortOrderChanged();
+}
+
+PlaylistControllerModel::SortKey PlaylistControllerModel::getSortKey() const
+{
+    Q_D(const PlaylistControllerModel);
+    return d->m_sortKey;
+}
+
+PlaylistControllerModel::SortOrder PlaylistControllerModel::getSortOrder() const
+{
+    Q_D(const PlaylistControllerModel);
+    return d->m_sortOrder;
+}
+
 bool PlaylistControllerModel::hasNext() const
 {
     Q_D(const PlaylistControllerModel);
diff --git a/modules/gui/qt/playlist/playlist_controller.hpp b/modules/gui/qt/playlist/playlist_controller.hpp
index e411fcd747..e4424fbc8c 100644
--- a/modules/gui/qt/playlist/playlist_controller.hpp
+++ b/modules/gui/qt/playlist/playlist_controller.hpp
@@ -59,7 +59,8 @@ public:
         SORT_KEY_TRACK_NUMBER = VLC_PLAYLIST_SORT_KEY_TRACK_NUMBER,
         SORT_KEY_DISC_NUMBER = VLC_PLAYLIST_SORT_KEY_DISC_NUMBER,
         SORT_KEY_URL = VLC_PLAYLIST_SORT_KEY_URL,
-        SORT_KEY_RATIN = VLC_PLAYLIST_SORT_KEY_RATING
+        SORT_KEY_RATIN = VLC_PLAYLIST_SORT_KEY_RATING,
+        SORT_KEY_NONE
     };
     Q_ENUM(SortKey)
 
@@ -81,6 +82,8 @@ public:
     Q_PROPERTY(bool playAndExit READ isPlayAndExit WRITE setPlayAndExit NOTIFY playAndExitChanged)
     Q_PROPERTY(bool empty READ isEmpty NOTIFY isEmptyChanged)
     Q_PROPERTY(size_t count READ count NOTIFY countChanged)
+    Q_PROPERTY(SortKey sortKey READ getSortKey WRITE setSortKey NOTIFY sortKeyChanged)
+    Q_PROPERTY(SortOrder sortOrder READ getSortOrder WRITE setSortOrder NOTIFY sortOrderChanged)
 
 public:
     Q_INVOKABLE void play();
@@ -107,7 +110,10 @@ public:
 
     Q_INVOKABLE void shuffle();
     void sort(const QVector<vlc_playlist_sort_criterion> &);
+
     Q_INVOKABLE void sort(SortKey key, SortOrder order);
+    Q_INVOKABLE void sort(void);
+
     Q_INVOKABLE void explore(const PlaylistItem& pItem);
 
 public:
@@ -133,10 +139,18 @@ public slots:
     bool isEmpty() const;
     size_t count() const;
 
+    SortKey getSortKey() const;
+    void setSortKey(SortKey sortKey);
+    SortOrder getSortOrder() const;
+    void setSortOrder(SortOrder sortOrder);
+    void switchSortOrder();
+
     PlaylistPtr getPlaylistPtr() const;
     void setPlaylistPtr(PlaylistPtr id);
     void setPlaylistPtr(vlc_playlist_t* newPlaylist);
 
+    void resetSortKey();
+
 signals:
     void playlistPtrChanged( PlaylistPtr );
 
@@ -150,6 +164,9 @@ signals:
     void isEmptyChanged( bool empty );
     void countChanged(size_t );
 
+    void sortKeyChanged();
+    void sortOrderChanged();
+
     void currentIndexChanged(ssize_t index);
     void itemsReset(QVector<PlaylistItem>);
     void itemsAdded(size_t index, QVector<PlaylistItem>);
diff --git a/modules/gui/qt/playlist/playlist_controller_p.hpp b/modules/gui/qt/playlist/playlist_controller_p.hpp
index 388dbac7dd..f49ec5b636 100644
--- a/modules/gui/qt/playlist/playlist_controller_p.hpp
+++ b/modules/gui/qt/playlist/playlist_controller_p.hpp
@@ -61,6 +61,8 @@ public:
     bool m_isPlayAndExit;
     bool m_empty = true;
     size_t m_count = 0;
+    PlaylistControllerModel::SortKey m_sortKey = PlaylistControllerModel::SORT_KEY_NONE;
+    PlaylistControllerModel::SortOrder m_sortOrder = PlaylistControllerModel::SORT_ORDER_ASC;
 };
 
 } //namespace playlist



More information about the vlc-commits mailing list