]> git.sur5r.net Git - minitube/blob - src/ytchannel.h
Optimized aggregator
[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 <QtGui>
25 #if QT_VERSION >= 0x050000
26 #include <QtWidgets>
27 #endif
28 #include <QtNetwork>
29
30 class YTChannel : public QObject {
31
32     Q_OBJECT
33
34 public:
35     static YTChannel* forId(const QString &channelId);
36     static void subscribe(const QString &channelId);
37     static void unsubscribe(const QString &channelId);
38     static bool isSubscribed(const QString &channelId);
39
40     int getId() { return id; }
41     void setId(int id) { this->id = id; }
42
43     uint getChecked() { return checked; }
44     void updateChecked();
45
46     uint getWatched() const { return watched; }
47     void setWatched(uint watched) { this->watched = watched; }
48
49     int getNotifyCount() const { return notifyCount; }
50     void setNotifyCount(int count) { notifyCount = count; }
51     void storeNotifyCount(int count);
52     bool updateNotifyCount();
53
54     QString getChannelId() const { return channelId; }
55     QString getUserName() const { return userName; }
56     QString getDisplayName() const { return displayName; }
57     QString getDescription() const { return description; }
58     QString getCountryCode() const { return countryCode; }
59
60     void loadThumbnail();
61     const QString & getThumbnailDir();
62     QString getThumbnailLocation();
63     const QPixmap & getThumbnail() { return thumbnail; }
64
65     QString latestVideoId();
66
67     static QList<YTChannel*> getCachedChannels() { return cache.values(); }
68
69 public slots:
70     void updateWatched();
71     void unsubscribe();
72
73 signals:
74     void infoLoaded();
75     void thumbnailLoaded();
76     void error(QString message);
77     void notifyCountChanged();
78
79 private slots:
80     void parseResponse(const QByteArray &bytes);
81     void requestError(QNetworkReply *reply);
82     void storeThumbnail(const QByteArray &bytes);
83
84 private:
85     YTChannel(const QString &channelId, QObject *parent = 0);
86     void maybeLoadfromAPI();
87     void storeInfo();
88
89     static QHash<QString, YTChannel*> cache;
90
91     int id;
92     QString channelId;
93     QString userName;
94     QString displayName;
95     QString description;
96     QString countryCode;
97
98     QString thumbnailUrl;
99     QPixmap thumbnail;
100     bool loadingThumbnail;
101
102     int notifyCount;
103     uint checked;
104     uint watched;
105     uint loaded;
106     bool loading;
107 };
108
109 // This is required in order to use QPointer<YTUser> as a QVariant
110 typedef QPointer<YTChannel> YTChannelPointer;
111 Q_DECLARE_METATYPE(YTChannelPointer)
112
113 #endif // YTCHANNEL_H