summaryrefslogtreecommitdiffstats
path: root/tests/manual/examples/twittertimeline/twittertimelinemodel.h
blob: 7dbbae11b31fbc798f2a421c41541810ac294144 (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
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#ifndef TWITTERTIMELINEMODEL_H
#define TWITTERTIMELINEMODEL_H

#include "twitter.h"

#include <QtCore>
#include <QtNetwork>

class TwitterTimelineModel : public QAbstractTableModel
{
    Q_OBJECT

public:
    TwitterTimelineModel(QObject *parent = nullptr);

    int rowCount(const QModelIndex &parent) const override;
    QVariant data(const QModelIndex &index, int role) const override;
    int columnCount(const QModelIndex &parent) const override;
    QVariant headerData(int section, Qt::Orientation orientation, int role) const override;

    void authenticate(const std::pair<QString, QString> &clientCredentials);
    QAbstractOAuth::Status status() const;

public slots:
    void updateTimeline();

signals:
    void authenticated();

private:
    Q_DISABLE_COPY(TwitterTimelineModel)

    void parseJson();

    struct Tweet {
        quint64 id;
        QDateTime createdAt;
        QString user;
        QString text;
    };

    QList<Tweet> tweets;
    Twitter twitter;
};

#endif // TWITTERTIMELINEMODEL_H