]> git.sur5r.net Git - minitube/blob - src/ytuser.h
d7131cdc9ca9b71c94bc3ef042e2fe8e2f29b1d3
[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 #include <QtNetwork>
26
27 class YTUser : public QObject {
28
29     Q_OBJECT
30
31 public:
32     static YTUser* forId(QString userId);
33     static void subscribe(QString userId);
34     static void unsubscribe(QString userId);
35     static bool isSubscribed(QString userId);
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     void updateWatched();
46
47     int getNotifyCount() const { return notifyCount; }
48     void setNotifyCount(int count) { notifyCount = count; }
49     void storeNotifyCount(int count);
50     bool updateNotifyCount();
51
52     QString getUserId() const { return userId; }
53     QString getUserName() const { return userName; }
54     QString getDisplayName() const { return displayName; }
55     QString getDescription() const { return description; }
56     QString getCountryCode() const { return countryCode; }
57
58     void loadThumbnail();
59     const QString & getThumbnailDir();
60     QString getThumbnailLocation();
61     const QPixmap & getThumbnail() { return thumbnail; }
62
63     static QList<YTUser*> getCachedUsers() { return cache.values(); }
64
65 signals:
66     void infoLoaded();
67     void thumbnailLoaded();
68     void error(QString message);
69
70 private slots:
71     void parseResponse(QByteArray bytes);
72     void requestError(QNetworkReply *reply);
73     void storeThumbnail(QByteArray bytes);
74
75 private:
76     YTUser(QString userId, QObject *parent = 0);
77     void maybeLoadfromAPI();
78     void storeInfo();
79
80     static QHash<QString, YTUser*> cache;
81
82     int id;
83     QString userId;
84     QString userName;
85     QString displayName;
86     QString description;
87     QString countryCode;
88
89     QString thumbnailUrl;
90     QPixmap thumbnail;
91     bool loadingThumbnail;
92
93     int notifyCount;
94     uint checked;
95     uint watched;
96     uint loaded;
97     bool loading;
98 };
99
100 // This is required in order to use QPointer<YTUser> as a QVariant
101 typedef QPointer<YTUser> YTUserPointer;
102 Q_DECLARE_METATYPE(YTUserPointer)
103
104 #endif // YTUSER_H