void SmugTalker::parseResponseListAlbumTmpl(const QByteArray& data) { int errCode = -1; QString errMsg; QDomDocument doc("albumtemplates.get"); if (!doc.setContent(data)) return; kDebug() << "Parse AlbumTemplates response:" << endl << data; QList<SmugAlbumTmpl> albumTList; QDomElement e = doc.documentElement(); for (QDomNode node = e.firstChild(); !node.isNull(); node = node.nextSibling()) { if (!node.isElement()) continue; e = node.toElement(); if (e.tagName() == "AlbumTemplates") { for (QDomNode nodeT = e.firstChild(); !nodeT.isNull(); nodeT = nodeT.nextSibling()) { if (!nodeT.isElement()) continue; QDomElement e = nodeT.toElement(); if (e.tagName() == "AlbumTemplate") { SmugAlbumTmpl tmpl; tmpl.id = e.attribute("id").toInt(); tmpl.name = htmlToText(e.attribute("AlbumTemplateName")); tmpl.isPublic = e.attribute("Public") == "1"; tmpl.password = htmlToText(e.attribute("Password")); tmpl.passwordHint = htmlToText(e.attribute("PasswordHint")); albumTList.append(tmpl); } } errCode = 0; } else if (e.tagName() == "err") { errCode = e.attribute("code").toInt(); errMsg = e.attribute("msg"); kDebug() << "Error:" << errCode << errMsg; } } if (errCode == 15) // 15: empty list errCode = 0; emit signalBusy(false); emit signalListAlbumTmplDone(errCode, errorToText(errCode, errMsg), albumTList); }
void SmugTalker::parseResponseListSubCategories(const QByteArray& data) { int errCode = -1; QString errMsg; QDomDocument doc("subcategories.get"); if (!doc.setContent(data)) return; kDebug() << "Parse SubCategories response:" << endl << data; QList <SmugCategory> categoriesList; QDomElement e = doc.documentElement(); for (QDomNode node = e.firstChild(); !node.isNull(); node = node.nextSibling()) { if (!node.isElement()) continue; e = node.toElement(); if (e.tagName() == "SubCategories") { for (QDomNode nodeC = e.firstChild(); !nodeC.isNull(); nodeC = nodeC.nextSibling()) { if (!nodeC.isElement()) continue; e = nodeC.toElement(); if (e.tagName() == "SubCategory") { SmugCategory category; category.id = e.attribute("id").toInt(); category.name = htmlToText(e.attribute("Title")); // Name in 1.2.1 categoriesList.append(category); } } errCode = 0; } else if (e.tagName() == "err") { errCode = e.attribute("code").toInt(); errMsg = e.attribute("msg"); kDebug() << "Error:" << errCode << errMsg; } } if (errCode == 15) // 15: empty list errCode = 0; emit signalBusy(false); emit signalListSubCategoriesDone(errCode, errorToText(errCode, errMsg), categoriesList); }
void SmugTalker::parseResponseListPhotos(const QByteArray& data) { int errCode = -1; QString errMsg; QDomDocument doc(QString::fromLatin1("images.get")); if (!doc.setContent(data)) return; qCDebug(KIPIPLUGINS_LOG) << "Parse Photos response:" << endl << data; QList <SmugPhoto> photosList; 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("Album")) { node = e.firstChild(); if (!node.isElement()) continue; e = node.toElement(); } if (e.tagName() == QString::fromLatin1("Images")) { for (QDomNode nodeP = e.firstChild(); !nodeP.isNull(); nodeP = nodeP.nextSibling()) { if (!nodeP.isElement()) continue; e = nodeP.toElement(); if (e.tagName() == QString::fromLatin1("Image")) { SmugPhoto photo; photo.id = e.attribute(QString::fromLatin1("id")).toLongLong(); photo.key = e.attribute(QString::fromLatin1("Key")); photo.caption = htmlToText(e.attribute(QString::fromLatin1("Caption"))); photo.keywords = htmlToText(e.attribute(QString::fromLatin1("Keywords"))); photo.thumbURL = e.attribute(QString::fromLatin1("ThumbURL")); // try to get largest size available if (e.hasAttribute(QString::fromLatin1("Video1280URL"))) photo.originalURL = e.attribute(QString::fromLatin1("Video1280URL")); else if (e.hasAttribute(QString::fromLatin1("Video960URL"))) photo.originalURL = e.attribute(QString::fromLatin1("Video960URL")); else if (e.hasAttribute(QString::fromLatin1("Video640URL"))) photo.originalURL = e.attribute(QString::fromLatin1("Video640URL")); else if (e.hasAttribute(QString::fromLatin1("Video320URL"))) photo.originalURL = e.attribute(QString::fromLatin1("Video320URL")); else if (e.hasAttribute(QString::fromLatin1("OriginalURL"))) photo.originalURL = e.attribute(QString::fromLatin1("OriginalURL")); else if (e.hasAttribute(QString::fromLatin1("X3LargeURL"))) photo.originalURL = e.attribute(QString::fromLatin1("X3LargeURL")); else if (e.hasAttribute(QString::fromLatin1("X2LargeURL"))) photo.originalURL = e.attribute(QString::fromLatin1("X2LargeURL")); else if (e.hasAttribute(QString::fromLatin1("XLargeURL"))) photo.originalURL = e.attribute(QString::fromLatin1("XLargeURL")); else if (e.hasAttribute(QString::fromLatin1("LargeURL"))) photo.originalURL = e.attribute(QString::fromLatin1("LargeURL")); else if (e.hasAttribute(QString::fromLatin1("MediumURL"))) photo.originalURL = e.attribute(QString::fromLatin1("MediumURL")); else if (e.hasAttribute(QString::fromLatin1("SmallURL"))) photo.originalURL = e.attribute(QString::fromLatin1("SmallURL")); photosList.append(photo); } } 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; emit signalBusy(false); emit signalListPhotosDone(errCode, errorToText(errCode, errMsg), photosList); }
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); }