2018-02-27 18:06:05 +01:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
|
|
|
* This file was part of Clementine.
|
|
|
|
* Copyright 2010, David Sansome <me@davidsansome.com>
|
2021-03-20 21:14:47 +01:00
|
|
|
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
|
2018-02-27 18:06:05 +01:00
|
|
|
*
|
|
|
|
* Strawberry is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Strawberry is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-09 18:39:44 +02:00
|
|
|
*
|
2018-02-27 18:06:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2020-02-08 15:03:11 +01:00
|
|
|
#include <memory>
|
2018-10-19 20:18:46 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QObject>
|
|
|
|
#include <QIODevice>
|
|
|
|
#include <QDataStream>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QBuffer>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QList>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QStringBuilder>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QMimeData>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QAbstractProxyModel>
|
|
|
|
|
2018-10-21 15:13:48 +02:00
|
|
|
#include "core/utilities.h"
|
2020-02-08 15:03:11 +01:00
|
|
|
#include "core/song.h"
|
2018-10-21 15:13:48 +02:00
|
|
|
#include "playlist/playlist.h"
|
2020-02-08 15:03:11 +01:00
|
|
|
#include "playlist/playlistitem.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "queue.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
const char *Queue::kRowsMimetype = "application/x-strawberry-queue-rows";
|
|
|
|
|
2021-06-20 19:04:08 +02:00
|
|
|
Queue::Queue(Playlist *playlist, QObject *parent) : QAbstractProxyModel(parent), playlist_(playlist), total_length_ns_(0) {
|
2018-10-21 15:13:48 +02:00
|
|
|
|
2021-01-26 16:48:04 +01:00
|
|
|
signal_item_count_changed_ = QObject::connect(this, &Queue::ItemCountChanged, this, &Queue::UpdateTotalLength);
|
|
|
|
QObject::connect(this, &Queue::TotalLengthChanged, this, &Queue::UpdateSummaryText);
|
2018-10-21 15:13:48 +02:00
|
|
|
|
|
|
|
UpdateSummaryText();
|
|
|
|
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
QModelIndex Queue::mapFromSource(const QModelIndex &source_index) const {
|
|
|
|
|
|
|
|
if (!source_index.isValid()) return QModelIndex();
|
|
|
|
|
|
|
|
const int source_row = source_index.row();
|
|
|
|
for (int i = 0; i < source_indexes_.count(); ++i) {
|
2021-08-23 21:21:08 +02:00
|
|
|
if (source_indexes_[i].row() == source_row) {
|
2018-02-27 18:06:05 +01:00
|
|
|
return index(i, source_index.column());
|
2021-08-23 21:21:08 +02:00
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
return QModelIndex();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-06-20 19:04:08 +02:00
|
|
|
bool Queue::ContainsSourceRow(const int source_row) const {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < source_indexes_.count(); ++i) {
|
|
|
|
if (source_indexes_[i].row() == source_row) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex Queue::mapToSource(const QModelIndex &proxy_index) const {
|
|
|
|
|
|
|
|
if (!proxy_index.isValid()) return QModelIndex();
|
|
|
|
|
|
|
|
return source_indexes_[proxy_index.row()];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Queue::setSourceModel(QAbstractItemModel *source_model) {
|
|
|
|
|
|
|
|
if (sourceModel()) {
|
2021-01-26 16:48:04 +01:00
|
|
|
QObject::disconnect(sourceModel(), &QAbstractItemModel::dataChanged, this, &Queue::SourceDataChanged);
|
|
|
|
QObject::disconnect(sourceModel(), &QAbstractItemModel::rowsRemoved, this, &Queue::SourceLayoutChanged);
|
|
|
|
QObject::disconnect(sourceModel(), &QAbstractItemModel::layoutChanged, this, &Queue::SourceLayoutChanged);
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QAbstractProxyModel::setSourceModel(source_model);
|
|
|
|
|
2021-01-26 16:48:04 +01:00
|
|
|
QObject::connect(sourceModel(), &QAbstractItemModel::dataChanged, this, &Queue::SourceDataChanged);
|
|
|
|
QObject::connect(sourceModel(), &QAbstractItemModel::rowsRemoved, this, &Queue::SourceLayoutChanged);
|
|
|
|
QObject::connect(sourceModel(), &QAbstractItemModel::layoutChanged, this, &Queue::SourceLayoutChanged);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Queue::SourceDataChanged(const QModelIndex &top_left, const QModelIndex &bottom_right) {
|
|
|
|
|
|
|
|
for (int row = top_left.row(); row <= bottom_right.row(); ++row) {
|
|
|
|
QModelIndex proxy_index = mapFromSource(sourceModel()->index(row, 0));
|
|
|
|
if (!proxy_index.isValid()) continue;
|
|
|
|
|
|
|
|
emit dataChanged(proxy_index, proxy_index);
|
|
|
|
}
|
2021-09-13 20:49:33 +02:00
|
|
|
emit ItemCountChanged(ItemCount());
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Queue::SourceLayoutChanged() {
|
|
|
|
|
2021-01-26 16:48:04 +01:00
|
|
|
QObject::disconnect(signal_item_count_changed_);
|
2020-09-03 16:59:18 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
for (int i = 0; i < source_indexes_.count(); ++i) {
|
|
|
|
if (!source_indexes_[i].isValid()) {
|
|
|
|
beginRemoveRows(QModelIndex(), i, i);
|
|
|
|
source_indexes_.removeAt(i);
|
|
|
|
endRemoveRows();
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
2020-09-03 16:59:18 +02:00
|
|
|
|
2021-01-26 16:48:04 +01:00
|
|
|
signal_item_count_changed_ = QObject::connect(this, &Queue::ItemCountChanged, this, &Queue::UpdateTotalLength);
|
2020-09-03 16:59:18 +02:00
|
|
|
|
2021-09-13 20:49:33 +02:00
|
|
|
emit ItemCountChanged(ItemCount());
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex Queue::index(int row, int column, const QModelIndex &parent) const {
|
2019-09-15 20:27:32 +02:00
|
|
|
Q_UNUSED(parent);
|
2018-02-27 18:06:05 +01:00
|
|
|
return createIndex(row, column);
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex Queue::parent(const QModelIndex &child) const {
|
2019-09-15 20:27:32 +02:00
|
|
|
Q_UNUSED(child);
|
2018-02-27 18:06:05 +01:00
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
int Queue::rowCount(const QModelIndex &parent) const {
|
|
|
|
if (parent.isValid()) return 0;
|
|
|
|
return source_indexes_.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
int Queue::columnCount(const QModelIndex&) const { return 1; }
|
|
|
|
|
|
|
|
QVariant Queue::data(const QModelIndex &proxy_index, int role) const {
|
|
|
|
|
|
|
|
QModelIndex source_index = source_indexes_[proxy_index.row()];
|
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
case Playlist::Role_QueuePosition:
|
|
|
|
return proxy_index.row();
|
|
|
|
|
|
|
|
case Qt::DisplayRole: {
|
|
|
|
const QString artist = source_index.sibling(source_index.row(), Playlist::Column_Artist).data().toString();
|
|
|
|
const QString title = source_index.sibling(source_index.row(), Playlist::Column_Title).data().toString();
|
|
|
|
|
|
|
|
if (artist.isEmpty()) return title;
|
|
|
|
return QString(artist + " - " + title);
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Queue::ToggleTracks(const QModelIndexList &source_indexes) {
|
|
|
|
|
|
|
|
for (const QModelIndex &source_index : source_indexes) {
|
|
|
|
QModelIndex proxy_index = mapFromSource(source_index);
|
|
|
|
if (proxy_index.isValid()) {
|
|
|
|
// Dequeue the track
|
|
|
|
const int row = proxy_index.row();
|
|
|
|
beginRemoveRows(QModelIndex(), row, row);
|
|
|
|
source_indexes_.removeAt(row);
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Enqueue the track
|
|
|
|
const int row = source_indexes_.count();
|
|
|
|
beginInsertRows(QModelIndex(), row, row);
|
|
|
|
source_indexes_ << QPersistentModelIndex(source_index);
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-10-21 15:13:48 +02:00
|
|
|
void Queue::InsertFirst(const QModelIndexList &source_indexes) {
|
|
|
|
|
|
|
|
for (const QModelIndex &source_index : source_indexes) {
|
|
|
|
QModelIndex proxy_index = mapFromSource(source_index);
|
|
|
|
if (proxy_index.isValid()) {
|
|
|
|
// Already in the queue, so remove it to be reinserted later
|
|
|
|
const int row = proxy_index.row();
|
|
|
|
beginRemoveRows(QModelIndex(), row, row);
|
|
|
|
source_indexes_.removeAt(row);
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const int rows = source_indexes.count();
|
|
|
|
// Enqueue the tracks at the beginning
|
|
|
|
beginInsertRows(QModelIndex(), 0, rows - 1);
|
|
|
|
int offset = 0;
|
2021-06-12 20:53:23 +02:00
|
|
|
for (const QModelIndex &source_index : source_indexes) {
|
2018-10-21 15:13:48 +02:00
|
|
|
source_indexes_.insert(offset, QPersistentModelIndex(source_index));
|
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
endInsertRows();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
int Queue::PositionOf(const QModelIndex &source_index) const {
|
|
|
|
return mapFromSource(source_index).row();
|
|
|
|
}
|
|
|
|
|
2018-10-21 15:13:48 +02:00
|
|
|
bool Queue::is_empty() const { return source_indexes_.isEmpty(); }
|
|
|
|
|
|
|
|
int Queue::ItemCount() const { return source_indexes_.length(); }
|
|
|
|
|
|
|
|
quint64 Queue::GetTotalLength() const { return total_length_ns_; }
|
|
|
|
|
|
|
|
void Queue::UpdateTotalLength() {
|
|
|
|
|
|
|
|
quint64 total = 0;
|
|
|
|
|
2019-04-08 18:46:11 +02:00
|
|
|
for (const QPersistentModelIndex &row : source_indexes_) {
|
2018-10-21 15:13:48 +02:00
|
|
|
int id = row.row();
|
|
|
|
|
|
|
|
Q_ASSERT(playlist_->has_item_at(id));
|
|
|
|
|
|
|
|
quint64 length = playlist_->item_at(id)->Metadata().length_nanosec();
|
|
|
|
if (length > 0) total += length;
|
|
|
|
}
|
|
|
|
|
|
|
|
total_length_ns_ = total;
|
|
|
|
|
|
|
|
emit TotalLengthChanged(total);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Queue::UpdateSummaryText() {
|
|
|
|
|
|
|
|
QString summary;
|
2021-09-13 20:49:33 +02:00
|
|
|
int tracks = ItemCount();
|
|
|
|
quint64 nanoseconds = GetTotalLength();
|
2018-10-21 15:13:48 +02:00
|
|
|
|
|
|
|
summary += tracks == 1 ? tr("1 track") : tr("%1 tracks").arg(tracks);
|
|
|
|
|
2021-06-22 13:54:58 +02:00
|
|
|
if (nanoseconds > 0) {
|
2018-10-21 15:13:48 +02:00
|
|
|
summary += " - [ " + Utilities::WordyTimeNanosec(nanoseconds) + " ]";
|
2021-06-20 19:04:08 +02:00
|
|
|
}
|
2018-10-21 15:13:48 +02:00
|
|
|
|
|
|
|
emit SummaryTextChanged(summary);
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Queue::Clear() {
|
2018-10-21 15:13:48 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
if (source_indexes_.isEmpty()) return;
|
|
|
|
|
2021-03-21 18:53:02 +01:00
|
|
|
beginRemoveRows(QModelIndex(), 0, static_cast<int>(source_indexes_.count() - 1));
|
2018-02-27 18:06:05 +01:00
|
|
|
source_indexes_.clear();
|
|
|
|
endRemoveRows();
|
2018-10-21 15:13:48 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Queue::Move(const QList<int> &proxy_rows, int pos) {
|
|
|
|
|
2021-03-21 04:47:11 +01:00
|
|
|
emit layoutAboutToBeChanged();
|
2018-02-27 18:06:05 +01:00
|
|
|
QList<QPersistentModelIndex> moved_items;
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// Take the items out of the list first, keeping track of whether the insertion point changes
|
2018-02-27 18:06:05 +01:00
|
|
|
int offset = 0;
|
2021-06-20 19:04:08 +02:00
|
|
|
moved_items.reserve(proxy_rows.count());
|
|
|
|
for (const int row : proxy_rows) {
|
2018-02-27 18:06:05 +01:00
|
|
|
moved_items << source_indexes_.takeAt(row - offset);
|
2021-06-20 19:04:08 +02:00
|
|
|
if (pos != -1 && pos >= row) --pos;
|
|
|
|
++offset;
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Put the items back in
|
2021-03-21 18:53:02 +01:00
|
|
|
const int start = pos == -1 ? static_cast<int>(source_indexes_.count()) : pos;
|
2018-02-27 18:06:05 +01:00
|
|
|
for (int i = start; i < start + moved_items.count(); ++i) {
|
|
|
|
source_indexes_.insert(i, moved_items[i - start]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update persistent indexes
|
|
|
|
for (const QModelIndex &pidx : persistentIndexList()) {
|
|
|
|
const int dest_offset = proxy_rows.indexOf(pidx.row());
|
|
|
|
if (dest_offset != -1) {
|
|
|
|
// This index was moved
|
|
|
|
changePersistentIndex(pidx, index(start + dest_offset, pidx.column(), QModelIndex()));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int d = 0;
|
|
|
|
for (int row : proxy_rows) {
|
|
|
|
if (pidx.row() > row) d--;
|
|
|
|
}
|
|
|
|
if (pidx.row() + d >= start) d += proxy_rows.count();
|
|
|
|
|
|
|
|
changePersistentIndex(pidx, index(pidx.row() + d, pidx.column(), QModelIndex()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-21 04:47:11 +01:00
|
|
|
emit layoutChanged();
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Queue::MoveUp(int row) {
|
|
|
|
Move(QList<int>() << row, row - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Queue::MoveDown(int row) {
|
|
|
|
Move(QList<int>() << row, row + 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList Queue::mimeTypes() const {
|
|
|
|
return QStringList() << kRowsMimetype << Playlist::kRowsMimetype;
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::DropActions Queue::supportedDropActions() const {
|
|
|
|
return Qt::MoveAction | Qt::CopyAction | Qt::LinkAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMimeData *Queue::mimeData(const QModelIndexList &indexes) const {
|
|
|
|
|
|
|
|
QMimeData *data = new QMimeData;
|
|
|
|
|
|
|
|
QList<int> rows;
|
2021-01-26 16:48:04 +01:00
|
|
|
for (const QModelIndex &idx : indexes) {
|
|
|
|
if (idx.column() != 0) continue;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2021-01-26 16:48:04 +01:00
|
|
|
rows << idx.row();
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QBuffer buf;
|
2021-07-14 20:52:57 +02:00
|
|
|
if (buf.open(QIODevice::WriteOnly)) {
|
|
|
|
QDataStream stream(&buf);
|
|
|
|
stream << rows;
|
|
|
|
buf.close();
|
|
|
|
data->setData(kRowsMimetype, buf.data());
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
return data;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Queue::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int, const QModelIndex&) {
|
|
|
|
|
|
|
|
if (action == Qt::IgnoreAction)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (data->hasFormat(kRowsMimetype)) {
|
|
|
|
// Dragged from the queue
|
|
|
|
|
|
|
|
QList<int> proxy_rows;
|
|
|
|
QDataStream stream(data->data(kRowsMimetype));
|
|
|
|
stream >> proxy_rows;
|
2018-10-19 20:18:46 +02:00
|
|
|
|
|
|
|
// Make sure we take them in order
|
|
|
|
std::stable_sort(proxy_rows.begin(), proxy_rows.end());
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
Move(proxy_rows, row);
|
|
|
|
}
|
|
|
|
else if (data->hasFormat(Playlist::kRowsMimetype)) {
|
|
|
|
// Dragged from the playlist
|
|
|
|
|
|
|
|
Playlist *playlist = nullptr;
|
|
|
|
QList<int> source_rows;
|
|
|
|
QDataStream stream(data->data(Playlist::kRowsMimetype));
|
2021-06-20 19:04:08 +02:00
|
|
|
stream.readRawData(reinterpret_cast<char*>(&playlist), sizeof(Playlist));
|
2018-02-27 18:06:05 +01:00
|
|
|
stream >> source_rows;
|
|
|
|
|
|
|
|
QModelIndexList source_indexes;
|
|
|
|
for (int source_row : source_rows) {
|
|
|
|
const QModelIndex source_index = sourceModel()->index(source_row, 0);
|
|
|
|
const QModelIndex proxy_index = mapFromSource(source_index);
|
|
|
|
if (proxy_index.isValid()) {
|
|
|
|
// This row was already in the queue, so no need to add it again
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
source_indexes << source_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!source_indexes.isEmpty()) {
|
2021-03-21 18:53:02 +01:00
|
|
|
const int insert_point = row == -1 ? static_cast<int>(source_indexes_.count()) : row;
|
|
|
|
beginInsertRows(QModelIndex(), insert_point, insert_point + static_cast<int>(source_indexes.count() - 1));
|
2021-08-23 21:21:08 +02:00
|
|
|
for (int i = 0; i < source_indexes.count(); ++i) {
|
2018-02-27 18:06:05 +01:00
|
|
|
source_indexes_.insert(insert_point + i, source_indexes[i]);
|
|
|
|
}
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-26 16:48:04 +01:00
|
|
|
Qt::ItemFlags Queue::flags(const QModelIndex &idx) const {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
|
|
|
|
2021-08-23 21:21:08 +02:00
|
|
|
if (idx.isValid()) {
|
2018-02-27 18:06:05 +01:00
|
|
|
flags |= Qt::ItemIsDragEnabled;
|
2021-08-23 21:21:08 +02:00
|
|
|
}
|
|
|
|
else {
|
2018-02-27 18:06:05 +01:00
|
|
|
flags |= Qt::ItemIsDropEnabled;
|
2021-08-23 21:21:08 +02:00
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
return flags;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int Queue::PeekNext() const {
|
2021-06-20 19:04:08 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
if (source_indexes_.isEmpty()) return -1;
|
|
|
|
return source_indexes_.first().row();
|
2021-06-20 19:04:08 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int Queue::TakeNext() {
|
|
|
|
|
|
|
|
if (source_indexes_.isEmpty()) return -1;
|
|
|
|
|
|
|
|
beginRemoveRows(QModelIndex(), 0, 0);
|
|
|
|
int ret = source_indexes_.takeFirst().row();
|
|
|
|
endRemoveRows();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant Queue::headerData(int section, Qt::Orientation orientation, int role) const {
|
2019-09-15 20:27:32 +02:00
|
|
|
Q_UNUSED(section);
|
|
|
|
Q_UNUSED(orientation);
|
|
|
|
Q_UNUSED(role);
|
2018-02-27 18:06:05 +01:00
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Queue::Remove(QList<int> &proxy_rows) {
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// Order the rows
|
2018-10-19 20:18:46 +02:00
|
|
|
std::stable_sort(proxy_rows.begin(), proxy_rows.end());
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// Reflects immediately changes in the playlist
|
2021-03-21 04:47:11 +01:00
|
|
|
emit layoutAboutToBeChanged();
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
int removed_rows = 0;
|
|
|
|
for (int row : proxy_rows) {
|
2018-05-01 00:41:33 +02:00
|
|
|
// After the first row, the row number needs to be updated
|
2018-02-27 18:06:05 +01:00
|
|
|
const int real_row = row - removed_rows;
|
|
|
|
beginRemoveRows(QModelIndex(), real_row, real_row);
|
|
|
|
source_indexes_.removeAt(real_row);
|
|
|
|
endRemoveRows();
|
|
|
|
removed_rows++;
|
|
|
|
}
|
|
|
|
|
2021-03-21 04:47:11 +01:00
|
|
|
emit layoutChanged();
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
}
|