void GDTalker::parseResponseListFolders(const QByteArray& data) { qCDebug(KIPIPLUGINS_LOG) << data; QJsonParseError err; QJsonDocument doc = QJsonDocument::fromJson(data, &err); if (err.error != QJsonParseError::NoError) { emit signalBusy(false); emit signalListAlbumsDone(0,i18n("Failed to list folders"),QList<GSFolder>()); return; } QJsonObject jsonObject = doc.object(); QJsonArray jsonArray = jsonObject[QString::fromLatin1("items")].toArray(); QList<GSFolder> albumList; GSFolder fps; fps.id = m_rootid; fps.title = m_rootfoldername; albumList.append(fps); foreach (const QJsonValue& value, jsonArray) { QJsonObject obj = value.toObject(); fps.id = obj[QString::fromLatin1("id")].toString(); fps.title = obj[QString::fromLatin1("title")].toString(); albumList.append(fps); }
void SmugTalker::parseResponseListAlbums(const QByteArray& data) { int errCode = -1; QString errMsg; QDomDocument doc(QString::fromLatin1("albums.get")); if (!doc.setContent(data)) return; qCDebug(KIPIPLUGINS_LOG) << "Parse Albums response:" << endl << data; QList <SmugAlbum> albumsList; QDomElement e = doc.documentElement(); for (QDomNode node = e.firstChild(); !node.isNull(); node = node.nextSibling()) { if (!node.isElement()) continue; e = node.toElement(); if (e.tagName() == QString::fromLatin1("Albums")) { for (QDomNode nodeA = e.firstChild(); !nodeA.isNull(); nodeA = nodeA.nextSibling()) { if (!nodeA.isElement()) continue; e = nodeA.toElement(); if (e.tagName() == QString::fromLatin1("Album")) { SmugAlbum album; album.id = e.attribute(QString::fromLatin1("id")).toLongLong(); album.key = e.attribute(QString::fromLatin1("Key")); album.title = htmlToText(e.attribute(QString::fromLatin1("Title"))); album.description = htmlToText(e.attribute(QString::fromLatin1("Description"))); album.keywords = htmlToText(e.attribute(QString::fromLatin1("Keywords"))); album.isPublic = e.attribute(QString::fromLatin1("Public")) == QString::fromLatin1("1"); album.password = htmlToText(e.attribute(QString::fromLatin1("Password"))); album.passwordHint = htmlToText(e.attribute(QString::fromLatin1("PasswordHint"))); album.imageCount = e.attribute(QString::fromLatin1("ImageCount")).toInt(); for (QDomNode nodeC = e.firstChild(); !nodeC.isNull(); nodeC = node.nextSibling()) { if (!nodeC.isElement()) continue; e = nodeC.toElement(); if (e.tagName() == QString::fromLatin1("Category")) { album.categoryID = e.attribute(QString::fromLatin1("id")).toLongLong(); album.category = htmlToText(e.attribute(QString::fromLatin1("Name"))); } else if (e.tagName() == QString::fromLatin1("SubCategory")) { album.subCategoryID = e.attribute(QString::fromLatin1("id")).toLongLong(); album.subCategory = htmlToText(e.attribute(QString::fromLatin1("Name"))); } } albumsList.append(album); } } errCode = 0; } else if (e.tagName() == QString::fromLatin1("err")) { errCode = e.attribute(QString::fromLatin1("code")).toInt(); errMsg = e.attribute(QString::fromLatin1("msg")); qCDebug(KIPIPLUGINS_LOG) << "Error:" << errCode << errMsg; } } if (errCode == 15) // 15: empty list errCode = 0; qSort(albumsList.begin(), albumsList.end(), SmugAlbum::lessThan); emit signalBusy(false); emit signalListAlbumsDone(errCode, errorToText(errCode, errMsg), albumsList); }
void FbTalker::parseResponseListAlbums(const QByteArray& data) { int errCode = -1; QString errMsg; QDomDocument doc("getAlbums"); if (!doc.setContent(data)) return; kDebug() << "Parse Albums response:" << endl << data; QDomElement docElem = doc.documentElement(); QList <FbAlbum> albumsList; if (docElem.tagName() == "photos_getAlbums_response") { for (QDomNode node = docElem.firstChild(); !node.isNull(); node = node.nextSibling()) { if (!node.isElement()) continue; if (node.nodeName() == "album") { FbAlbum album; for (QDomNode nodeA = node.toElement().firstChild(); !nodeA.isNull(); nodeA = nodeA.nextSibling()) { if (!nodeA.isElement()) continue; if (nodeA.nodeName() == "aid") album.id = nodeA.toElement().text().trimmed(); else if (nodeA.nodeName() == "name") album.title = nodeA.toElement().text(); else if (nodeA.nodeName() == "description") album.description = nodeA.toElement().text(); else if (nodeA.nodeName() == "location") album.location = nodeA.toElement().text(); else if (nodeA.nodeName() == "link") album.url = nodeA.toElement().text(); else if (nodeA.nodeName() == "visible") { if (nodeA.toElement().text() == "friends") album.privacy = FB_FRIENDS; else if (nodeA.toElement().text() == "friends-of-friends") album.privacy = FB_FRIENDS_OF_FRIENDS; else if (nodeA.toElement().text() == "networks") album.privacy = FB_NETWORKS; else if (nodeA.toElement().text() == "everyone") album.privacy = FB_EVERYONE; } } kDebug() << "AID: " << album.id; albumsList.append(album); } } errCode = 0; } else if (docElem.tagName() == "error_response") { errCode = parseErrorResponse(docElem, errMsg); } qSort(albumsList.begin(), albumsList.end()); emit signalBusy(false); emit signalListAlbumsDone(errCode, errorToText(errCode, errMsg), albumsList); }