summaryrefslogtreecommitdiffstats
path: root/src/ifmedia/qifplayqueue.h
blob: 0fc4a4da332b387830bab5c097e024d483e935d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (C) 2021 The Qt Company Ltd.
// Copyright (C) 2019 Luxoft Sweden AB
// Copyright (C) 2018 Pelagicore AG
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QIFPLAYQUEUE_H
#define QIFPLAYQUEUE_H

#include <QtCore/QAbstractListModel>
#include <QtQml/QQmlEngine>
#include <QtIfMedia/qtifmediaglobal.h>

QT_BEGIN_NAMESPACE

class QIfMediaPlayer;
class QIfPlayQueuePrivate;

class Q_QTIFMEDIA_EXPORT QIfPlayQueue : public QAbstractListModel
{
    Q_OBJECT
    QML_NAMED_ELEMENT(PlayQueue)
    QML_ANONYMOUS

    Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL)
    Q_PROPERTY(int chunkSize READ chunkSize WRITE setChunkSize NOTIFY chunkSizeChanged FINAL)
    Q_PROPERTY(int fetchMoreThreshold READ fetchMoreThreshold WRITE setFetchMoreThreshold NOTIFY fetchMoreThresholdChanged FINAL)
    Q_PROPERTY(int count READ rowCount NOTIFY countChanged FINAL)

    //TODO fix naming
    Q_PROPERTY(QIfPlayQueue::LoadingType loadingType READ loadingType WRITE setLoadingType NOTIFY loadingTypeChanged FINAL)
public:
    ~QIfPlayQueue() override;

    enum Roles {
        NameRole = Qt::DisplayRole,
        TypeRole = Qt::UserRole,
        ItemRole
    };

    //TODO fix naming
    enum LoadingType {
        FetchMore,
        DataChanged
    };
    Q_ENUM(LoadingType)

    int currentIndex() const;
    void setCurrentIndex(int currentIndex);

    int chunkSize() const;
    void setChunkSize(int chunkSize);

    int fetchMoreThreshold() const;
    void setFetchMoreThreshold(int fetchMoreThreshold);

    QIfPlayQueue::LoadingType loadingType() const;
    void setLoadingType(QIfPlayQueue::LoadingType loadingType);

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role) const override;

    bool canFetchMore(const QModelIndex &parent) const override;
    void fetchMore(const QModelIndex &parent) override;

    QHash<int, QByteArray> roleNames() const override;

    Q_INVOKABLE QVariant get(int index) const;

    template <typename T> T at(int i) const {
        return data(index(i,0), ItemRole).value<T>();
    }

    Q_INVOKABLE void insert(int index, const QVariant &variant);
    Q_INVOKABLE void remove(int index);
    Q_INVOKABLE void move(int cur_index, int new_index);

Q_SIGNALS:
    void chunkSizeChanged(int chunkSize);
    void countChanged();
    void fetchMoreThresholdChanged(int fetchMoreThreshold);
    void fetchMoreThresholdReached() const;
    void loadingTypeChanged(QIfPlayQueue::LoadingType loadingType);

    void currentIndexChanged(int currentIndex);

protected:
    explicit QIfPlayQueue(QIfMediaPlayer *parent = nullptr);

private:
    Q_DECLARE_PRIVATE(QIfPlayQueue)
    Q_PRIVATE_SLOT(d_func(), void onCurrentIndexChanged(int currentIndex))
    Q_PRIVATE_SLOT(d_func(), void onCanReportCountChanged(bool canReportCount))
    Q_PRIVATE_SLOT(d_func(), void onDataFetched(const QUuid &identifier, const QList<QVariant> &items, int start, bool moreAvailable))
    Q_PRIVATE_SLOT(d_func(), void onCountChanged(int new_length))
    Q_PRIVATE_SLOT(d_func(), void onDataChanged(const QList<QVariant> &data, int start, int count))
    Q_PRIVATE_SLOT(d_func(), void onFetchMoreThresholdReached())

    friend class QIfMediaPlayer;
    friend class QIfMediaPlayerPrivate;
};

QT_END_NAMESPACE

#endif // QIFPLAYQUEUE_H