]> git.sur5r.net Git - minitube/blob - src/ytuser.h
Imported Upstream version 2.3.1
[minitube] / src / ytuser.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 YTUSER_H
22 #define YTUSER_H
23
24 #include <QtGui>
25 #if QT_VERSION >= 0x050000
26 #include <QtWidgets>
27 #endif
28 #include <QtNetwork>
29
30 class YTUser : public QObject {
31
32     Q_OBJECT
33
34 public:
35     static YTUser* forId(QString userId);
36     static void subscribe(QString userId);
37     static void unsubscribe(QString userId);
38     static bool isSubscribed(QString userId);
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 getUserId() const { return userId; }
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     static QList<YTUser*> getCachedUsers() { return cache.values(); }
66
67 public slots:
68     void updateWatched();
69     void unsubscribe();
70
71 signals:
72     void infoLoaded();
73     void thumbnailLoaded();
74     void error(QString message);
75     void notifyCountChanged();
76
77 private slots:
78     void parseResponse(QByteArray bytes);
79     void requestError(QNetworkReply *reply);
80     void storeThumbnail(QByteArray bytes);
81
82 private:
83     YTUser(QString userId, QObject *parent = 0);
84     void maybeLoadfromAPI();
85     void storeInfo();
86
87     static QHash<QString, YTUser*> cache;
88
89     int id;
90     QString userId;
91     QString userName;
92     QString displayName;
93     QString description;
94     QString countryCode;
95
96     QString thumbnailUrl;
97     QPixmap thumbnail;
98     bool loadingThumbnail;
99
100     int notifyCount;
101     uint checked;
102     uint watched;
103     uint loaded;
104     bool loading;
105 };
106
107 // This is required in order to use QPointer<YTUser> as a QVariant
108 typedef QPointer<YTUser> YTUserPointer;
109 Q_DECLARE_METATYPE(YTUserPointer)
110
111 #endif // YTUSER_H