url.addEncodedQueryItem("c", continuation.toUtf8());
request.setUrl(url);
- reader->getManager()->get(request);
+ reply = reader->getManager()->get(request);
+ connect(reply, SIGNAL(finished()), SLOT(fetchFinished()));
+}
+
+void Feed::fetchFinished() {
+ if (reply->error()) {
+ qDebug() << "Download of" << reply->url() << "failed:" << qPrintable(reply->errorString());
+ return;
+ }
+
+ QJson::Parser parser;
+ bool ok;
+ QVariantMap result = parser.parse(reply->readAll(), &ok).toMap();
+ QString continuation;
+
+ continuation = result["continuation"].toString();
+
+ foreach(QVariant l, result["items"].toList()) {
+ QVariantMap e = l.toMap();
+ Entry *entry = new Entry();;
+ QString content, summary;
+
+ entry->id = e["id"].toString();
+ entry->published = QDateTime::fromTime_t(e["published"].toUInt());
+ entry->author = e["author"].toString();
+ entry->source = (e["origin"].toMap())["streamId"].toString();
+ entry->link = (e["alternate"].toMap())["href"].toString();
+
+ content = (e["content"].toMap())["content"].toString();
+ summary = (e["summary"].toMap())["content"].toString();
+ if(content != "") entry->content = content; else entry->content = summary;
+
+ if(e["isReadStateLocked"].toBool())
+ entry->flags |= ENTRY_FLAG_LOCKED | ENTRY_FLAG_READ;
+
+ QWebPage p;
+ p.mainFrame()->setHtml(e["title"].toString());
+ entry->title = p.mainFrame()->toPlainText();
+
+ foreach(QVariant c, e["categories"].toList()) {
+ QString cat = c.toString();
+ if(cat.endsWith("/state/com.google/read"))
+ entry->flags |= ENTRY_FLAG_READ;
+ else if(cat.endsWith("/state/com.google/starred"))
+ entry->flags |= ENTRY_FLAG_STARRED;
+ else if(cat.endsWith("/state/com.google/broadcast"))
+ entry->flags |= ENTRY_FLAG_SHARED;
+ }
+
+ entry->feed = this;
+ addEntry(entry);
+ }
+
+ lastUpdated = QDateTime::currentDateTime();
+
+ emit updateFeedComplete();
+
+ reply->deleteLater();
}
GoogleReader::GoogleReader() {
QByteArray data = reply->readAll();
//qDebug() << "Result:" << data;
}
- else {
- parseFeed(reply->readAll());
- }
reply->deleteLater();
}
-void GoogleReader::parseFeed(QByteArray data) {
- QJson::Parser parser;
- bool ok;
- QVariantMap result = parser.parse(data, &ok).toMap();
- QString continuation, feedsource, id;
- Feed *feed = NULL;
-
- id = result["id"].toString();
- continuation = result["continuation"].toString();
-
- /* TODO: This hack should not be needed.. Figure out a cleaner way */
- if(id.endsWith("/state/com.google/starred"))
- feedsource = "user/-/state/com.google/starred";
- else if(id.endsWith("/state/com.google/broadcast"))
- feedsource = "user/-/state/com.google/broadcast";
-
- foreach(QVariant l, result["items"].toList()) {
- QVariantMap e = l.toMap();
- Entry entry;
- QString content, summary;
-
- entry.id = e["id"].toString();
- entry.published = QDateTime::fromTime_t(e["published"].toUInt());
- entry.author = e["author"].toString();
- entry.source = (e["origin"].toMap())["streamId"].toString();
- entry.link = (e["alternate"].toMap())["href"].toString();
-
- content = (e["content"].toMap())["content"].toString();
- summary = (e["summary"].toMap())["content"].toString();
- if(content != "") entry.content = content; else entry.content = summary;
-
- if(e["isReadStateLocked"].toBool())
- entry.flags |= ENTRY_FLAG_LOCKED | ENTRY_FLAG_READ;
-
- QWebPage p;
- p.mainFrame()->setHtml(e["title"].toString());
- entry.title = p.mainFrame()->toPlainText();
-
- foreach(QVariant c, e["categories"].toList()) {
- QString cat = c.toString();
- if(cat.endsWith("/state/com.google/read"))
- entry.flags |= ENTRY_FLAG_READ;
- else if(cat.endsWith("/state/com.google/starred"))
- entry.flags |= ENTRY_FLAG_STARRED;
- else if(cat.endsWith("/state/com.google/broadcast"))
- entry.flags |= ENTRY_FLAG_SHARED;
- }
-
- if(!feed)
- feed = feeds.value(feedsource == "" ? entry.source : feedsource);
-
- if(feed) {
- entry.feed = feed;
- feed->addEntry(new Entry(entry));
- }
- }
-
- if(feed) {
- feed->lastUpdated = QDateTime::currentDateTime();
- feed->continuation = continuation;
- feed->signalUpdated();
- }
-}
-
void GoogleReader::parseSubscriptions(QByteArray data) {
QJson::Parser parser;
bool ok;
entries.remove(entry->id);
}
-void Feed::signalUpdated() {
- // TODO: Clean this up
- emit updateFeedComplete();
-}
-
void Feed::updateUnread(int i) {
bool allRead = (unread == 0);