[vlc-commits] qt: add 'duration' property to playlist model to get total duration
Fatih Uzunoglu
git at videolan.org
Fri Jul 3 14:58:57 CEST 2020
vlc | branch: master | Fatih Uzunoglu <fuzun54 at outlook.com> | Sat Jun 20 00:17:48 2020 +0300| [1bcd922bd497da7dd0b3b86fec244b86ac26aff1] | committer: Pierre Lamot
qt: add 'duration' property to playlist model to get total duration
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1bcd922bd497da7dd0b3b86fec244b86ac26aff1
---
modules/gui/qt/playlist/playlist_model.cpp | 27 +++++++++++++++++++++++++++
modules/gui/qt/playlist/playlist_model.hpp | 3 +++
modules/gui/qt/playlist/playlist_model_p.hpp | 2 ++
3 files changed, 32 insertions(+)
diff --git a/modules/gui/qt/playlist/playlist_model.cpp b/modules/gui/qt/playlist/playlist_model.cpp
index 1b571ae2ae..7bb5960fc2 100644
--- a/modules/gui/qt/playlist/playlist_model.cpp
+++ b/modules/gui/qt/playlist/playlist_model.cpp
@@ -179,6 +179,15 @@ void PlaylistListModelPrivate::onItemsReset(const QVector<PlaylistItem>& newCont
m_items = newContent;
q->endResetModel();
+ m_duration = VLC_TICK_FROM_SEC(0);
+ if (m_items.size())
+ {
+ for(const auto& i : m_items)
+ {
+ m_duration += i.getDuration();
+ }
+ }
+
emit q->countChanged(m_items.size());
emit q->selectedCountChanged();
}
@@ -192,6 +201,11 @@ void PlaylistListModelPrivate::onItemsAdded(const QVector<PlaylistItem>& added,
std::move(added.cbegin(), added.cend(), m_items.begin() + index);
q->endInsertRows();
+ for(const auto& i : added)
+ {
+ m_duration += i.getDuration();
+ }
+
emit q->countChanged(m_items.size());
}
@@ -220,6 +234,12 @@ void PlaylistListModelPrivate::onItemsMoved(size_t index, size_t count, size_t t
void PlaylistListModelPrivate::onItemsRemoved(size_t index, size_t count)
{
Q_Q(PlaylistListModel);
+
+ for(size_t i = index; i < count; ++i)
+ {
+ m_duration -= m_items.at(i).getDuration();
+ }
+
q->beginRemoveRows({}, index, index + count - 1);
m_items.remove(index, count);
q->endRemoveRows();
@@ -298,6 +318,13 @@ PlaylistListModel::rowCount(const QModelIndex &parent) const
return d->m_items.size();
}
+VLCTick
+PlaylistListModel::getDuration() const
+{
+ Q_D(const PlaylistListModel);
+ return VLCTick(d->m_duration);
+}
+
const PlaylistItem &
PlaylistListModel::itemAt(int index) const
{
diff --git a/modules/gui/qt/playlist/playlist_model.hpp b/modules/gui/qt/playlist/playlist_model.hpp
index c0b775d0f2..9ff02651cc 100644
--- a/modules/gui/qt/playlist/playlist_model.hpp
+++ b/modules/gui/qt/playlist/playlist_model.hpp
@@ -28,6 +28,7 @@
#include "playlist_common.hpp"
#include "playlist_item.hpp"
#include "util/selectable_list_model.hpp"
+#include "util/vlctick.hpp"
namespace vlc {
namespace playlist {
@@ -39,6 +40,7 @@ class PlaylistListModel : public SelectableListModel
Q_PROPERTY(PlaylistPtr playlistId READ getPlaylistId WRITE setPlaylistId NOTIFY playlistIdChanged)
Q_PROPERTY(int currentIndex READ getCurrentIndex NOTIFY currentIndexChanged)
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
+ Q_PROPERTY(VLCTick duration READ getDuration NOTIFY countChanged)
public:
enum Roles
@@ -58,6 +60,7 @@ public:
QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent = {}) const override;
+ VLCTick getDuration() const;
QVariant data(const QModelIndex &index,
int role = Qt::DisplayRole) const override;
diff --git a/modules/gui/qt/playlist/playlist_model_p.hpp b/modules/gui/qt/playlist/playlist_model_p.hpp
index 315dc1bdde..8164efff4c 100644
--- a/modules/gui/qt/playlist/playlist_model_p.hpp
+++ b/modules/gui/qt/playlist/playlist_model_p.hpp
@@ -63,6 +63,8 @@ public:
/* access only from the UI thread */
QVector<PlaylistItem> m_items;
ssize_t m_current = -1;
+
+ vlc_tick_t m_duration = 0;
};
} //namespace playlist
More information about the vlc-commits
mailing list