]> git.sur5r.net Git - minitube/blob - src/ytuser.h
Imported Upstream version 2.2
[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
46     int getNotifyCount() const { return notifyCount; }
47     void setNotifyCount(int count) { notifyCount = count; }
48     void storeNotifyCount(int count);
49     bool updateNotifyCount();
50
51     QString getUserId() const { return userId; }
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     static QList<YTUser*> getCachedUsers() { return cache.values(); }
63
64 public slots:
65     void updateWatched();
66     void unsubscribe();
67
68 signals:
69     void infoLoaded();
70     void thumbnailLoaded();
71     void error(QString message);
72     void notifyCountChanged();
73
74 private slots:
75     void parseResponse(QByteArray bytes);
76     void requestError(QNetworkReply *reply);
77     void storeThumbnail(QByteArray bytes);
78
79 private:
80     YTUser(QString userId, QObject *parent = 0);
81     void maybeLoadfromAPI();
82     void storeInfo();
83
84     static QHash<QString, YTUser*> cache;
85
86     int id;
87     QString userId;
88     QString userName;
89     QString displayName;
90     QString description;
91     QString countryCode;
92
93     QString thumbnailUrl;
94     QPixmap thumbnail;
95     bool loadingThumbnail;
96
97     int notifyCount;
98     uint checked;
99     uint watched;
100     uint loaded;
101     bool loading;
102 };
103
104 // This is required in order to use QPointer<YTUser> as a QVariant
105 typedef QPointer<YTUser> YTUserPointer;
106 Q_DECLARE_METATYPE(YTUserPointer)
107
108 #endif // YTUSER_H