strawberry-audio-player-win.../src/queue/queue.h

101 lines
3.4 KiB
C
Raw Normal View History

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
*/
#ifndef QUEUE_H
#define QUEUE_H
#include "config.h"
#include <QObject>
#include <QAbstractItemModel>
2018-02-27 18:06:05 +01:00
#include <QAbstractProxyModel>
#include <QList>
#include <QVariant>
#include <QString>
#include <QStringList>
2018-02-27 18:06:05 +01:00
2020-02-08 15:03:11 +01:00
class QMimeData;
class Playlist;
2018-10-21 15:13:48 +02:00
2018-02-27 18:06:05 +01:00
class Queue : public QAbstractProxyModel {
Q_OBJECT
public:
explicit Queue(Playlist *playlist, QObject *parent = nullptr);
2018-02-27 18:06:05 +01:00
// Query the queue
bool is_empty() const;
int PositionOf(const QModelIndex &source_index) const;
2021-06-20 19:04:08 +02:00
bool ContainsSourceRow(const int source_row) const;
2018-02-27 18:06:05 +01:00
int PeekNext() const;
2018-10-21 15:13:48 +02:00
int ItemCount() const;
quint64 GetTotalLength() const;
2018-02-27 18:06:05 +01:00
// Modify the queue
int TakeNext();
void ToggleTracks(const QModelIndexList &source_indexes);
2018-10-21 15:13:48 +02:00
void InsertFirst(const QModelIndexList &source_indexes);
2018-02-27 18:06:05 +01:00
void Clear();
void Move(const QList<int> &proxy_rows, int pos);
2021-06-20 19:04:08 +02:00
void MoveUp(const int row);
void MoveDown(const int row);
2018-02-27 18:06:05 +01:00
void Remove(QList<int> &proxy_rows);
// QAbstractProxyModel
2020-06-15 21:55:05 +02:00
void setSourceModel(QAbstractItemModel *source_model) override;
QModelIndex mapFromSource(const QModelIndex &source_index) const override;
QModelIndex mapToSource(const QModelIndex &proxy_index) const override;
2018-02-27 18:06:05 +01:00
// QAbstractItemModel
2020-06-15 21:55:05 +02:00
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &child) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &proxy_index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
QStringList mimeTypes() const override;
Qt::DropActions supportedDropActions() const override;
QMimeData *mimeData(const QModelIndexList &indexes) const override;
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
2021-01-26 16:48:04 +01:00
Qt::ItemFlags flags(const QModelIndex &idx) const override;
2018-02-27 18:06:05 +01:00
2018-10-21 15:13:48 +02:00
public slots:
void UpdateSummaryText();
signals:
void TotalLengthChanged(const quint64 length);
void ItemCountChanged(const int count);
void SummaryTextChanged(const QString &message);
2018-10-21 15:13:48 +02:00
private slots:
2018-02-27 18:06:05 +01:00
void SourceDataChanged(const QModelIndex &top_left, const QModelIndex &bottom_right);
void SourceLayoutChanged();
2018-10-21 15:13:48 +02:00
void UpdateTotalLength();
2018-02-27 18:06:05 +01:00
2018-10-21 15:13:48 +02:00
private:
2018-02-27 18:06:05 +01:00
QList<QPersistentModelIndex> source_indexes_;
2018-10-21 15:13:48 +02:00
const Playlist *playlist_;
quint64 total_length_ns_;
QMetaObject::Connection signal_item_count_changed_;
2018-02-27 18:06:05 +01:00
};
#endif // QUEUE_H