]> git.sur5r.net Git - minitube/blob - src/ytchannel.h
New upstream version 3.8
[minitube] / src / ytchannel.h
1 /* $BEGIN_LICENSE
2
3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
5
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Minitube is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
18
19 $END_LICENSE */
20
21 #ifndef YTCHANNEL_H
22 #define YTCHANNEL_H
23
24 #include <QtWidgets>
25 #include <QtNetwork>
26
27 class YTChannel : public QObject {
28
29     Q_OBJECT
30
31 public:
32     static YTChannel* forId(const QString &channelId);
33     static bool subscribe(const QString &channelId);
34     static void unsubscribe(const QString &channelId);
35     static bool isSubscribed(const QString &channelId);
36
37     int getId() { return id; }
38     void setId(int id) { this->id = id; }
39
40     uint getChecked() { return checked; }
41     void updateChecked();
42
43     uint getWatched() const { return watched; }
44     void setWatched(uint watched) { this->watched = watched; }
45
46     int getNotifyCount() const { return notifyCount; }
47     void setNotifyCount(int count) { notifyCount = count; }
48     void storeNotifyCount(int count);
49     bool updateNotifyCount();
50
51     QString getChannelId() const { return channelId; }
52     QString getUserName() const { return userName; }
53     QString getDisplayName() const { return displayName; }
54     QString getDescription() const { return description; }
55     QString getCountryCode() const { return countryCode; }
56
57     void loadThumbnail();
58     const QString & getThumbnailDir();
59     QString getThumbnailLocation();
60     const QPixmap & getThumbnail() { return thumbnail; }
61
62     QString latestVideoId();
63
64     static const QHash<QString, YTChannel*> &getCachedChannels() { return cache; }
65
66 public slots:
67     void updateWatched();
68     void unsubscribe();
69
70 signals:
71     void infoLoaded();
72     void thumbnailLoaded();
73     void error(QString message);
74     void notifyCountChanged();
75
76 private slots:
77     void parseResponse(const QByteArray &bytes);
78     void requestError(const QString &message);
79     void storeThumbnail(const QByteArray &bytes);
80
81 private:
82     YTChannel(const QString &channelId, QObject *parent = 0);
83     void maybeLoadfromAPI();
84     void storeInfo();
85
86     static QHash<QString, YTChannel*> cache;
87
88     int id;
89     QString channelId;
90     QString userName;
91     QString displayName;
92     QString description;
93     QString countryCode;
94
95     QString thumbnailUrl;
96     QPixmap thumbnail;
97     bool loadingThumbnail;
98
99     int notifyCount;
100     uint checked;
101     uint watched;
102     uint loaded;
103     bool loading;
104 };
105
106 // This is required in order to use QPointer<YTUser> as a QVariant
107 typedef QPointer<YTChannel> YTChannelPointer;
108 Q_DECLARE_METATYPE(YTChannelPointer)
109
110 #endif // YTCHANNEL_H