Initial import of the code.
[grr] / src / googlereader.h
1 #ifndef _QTMAIN_H
2 #define _QTMAIN_H
3
4 #include <QObject>
5 #include <QNetworkReply>
6 #include <QNetworkRequest>
7 #include <QDomDocument>
8 #include <QBuffer>
9 #include <QDateTime>
10
11 class GoogleReader;
12 class Entry;
13
14 class Feed : public QObject {
15         Q_OBJECT
16
17         public:
18                 bool subscription_updated;
19                 
20                 QString id;
21                 QString title;
22                 QString sortid;
23                 QString firstitemmsec;
24                 QString cat_id;
25                 QString cat_label;
26         
27                 int unread;
28                 uint newestitem;
29                 
30                 QString continuation;
31
32                 QDateTime lastUpdated;
33
34                 GoogleReader *reader;
35
36                 bool special;
37
38                 void updateSubscription(Feed *feed);
39
40                 Feed(GoogleReader *gr = NULL) : QObject() {
41                         unread = 0;
42                         reader = gr;
43                         special = false;
44                 }
45
46                 void fetch(bool);
47                 void addEntry(Entry *);
48                 void delEntry(Entry *);
49                 void signalUpdated(); // TODO: Clean this up...
50                 QList<Entry *> getEntries();
51                 int getEntriesSize() { return entries.size(); }
52                 void markRead();
53                 void updateUnread(int);
54
55         signals:
56                 void updateFeedComplete();
57                 void allReadChanged();
58
59         private:
60                 QHash<QString, Entry *> entries;
61                 QBuffer buffer;
62 };
63     
64 Q_DECLARE_METATYPE(Feed *)
65
66 #define ENTRY_FLAG_READ         0x00000001
67 #define ENTRY_FLAG_STARRED      0x00000002
68 #define ENTRY_FLAG_LOCKED       0x00000004
69
70 class Entry : public QObject {
71         Q_OBJECT
72
73         public:
74                 QString id;
75                 QString title;
76                 QString author;
77                 QDateTime published;
78                 qulonglong crawled;
79                 QUrl link;
80                 QString source;
81                 QString content;
82                 unsigned int flags;
83                 Feed *feed;
84
85                 Entry(Feed *f = NULL) : QObject() {
86                         feed = f;
87                         flags = 0;
88                 }
89         
90                 Entry(Entry &e) : QObject() {
91                         id = e.id;
92                         title = e.title;
93                         author = e.author;
94                         published = e.published;
95                         link = e.link;
96                         source = e.source;
97                         content = e.content;
98                         flags = e.flags;
99                         feed = e.feed;
100                 }
101
102                 void markRead(bool);
103                 void markStar(bool);
104
105         private:
106                 QBuffer postread;
107                 QBuffer poststar;
108 };
109
110 Q_DECLARE_METATYPE(Entry *)
111
112 class GoogleReader: public QObject {
113         Q_OBJECT
114
115         public:
116                 GoogleReader();
117                 void updateSubscriptions();
118                 void updateUnread();
119                 QList<Feed *> getFeeds();
120                 QNetworkAccessManager *getManager() {
121                         return &manager;
122                 }
123                 void getToken();
124                 
125                 QUrl edittag_url;
126                 QUrl markallread_url;
127                 QByteArray token;
128                 QNetworkAccessManager manager;
129                 QDateTime lastUpdated;
130                 QHash<QString, Feed *> feeds;
131
132                 void setLogin(QString l) { login = l; }
133                 void setPasswd(QString p) { passwd = p; }
134                 void logOut() { 
135                         SID = NULL; 
136                         token = NULL;
137                         updateSubscriptionsPending = false;
138                         updateUnreadPending = false;
139                         SIDPending = false;
140                 }
141
142         private slots:
143                 void downloadFinished(QNetworkReply *reply);
144
145         private:
146                 char *SID;
147                 QBuffer buffer;
148                 bool updateSubscriptionsPending;
149                 bool updateUnreadPending;
150                 bool SIDPending;
151
152                 void getSID();
153                 void parseSubscriptions(QDomDocument dom);
154                 void parseUnread(QDomDocument dom);
155                 void parseFeed(QDomDocument dom);
156
157                 QUrl login_url;
158                 QUrl subscriptions_url;
159                 QUrl unread_url;
160                 QUrl token_url;
161
162                 QString login;
163                 QString passwd;
164
165         signals:
166                 void updateSubscriptionsComplete();
167                 void updateUnreadComplete();
168                 void allReadChanged();
169                 void loginFailed(QString);
170 };
171
172 #endif
173