-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();
- }
-}
-