void RoviPlugin::albumLookupFinished() { QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() ); Q_ASSERT( reply ); if ( reply->error() != QNetworkReply::NoError ) return; Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(); QJson::Parser p; bool ok; QVariantMap response = p.parse( reply, &ok ).toMap(); if ( !ok || response.isEmpty() || !response.contains( "searchResponse" ) ) { tLog() << "Error parsing JSON from Rovi!" << p.errorString() << response; emit info( requestData, QVariant() ); return; } QVariantList resultList = response[ "searchResponse" ].toMap().value( "results" ).toList(); if ( resultList.size() == 0 ) { emit info( requestData, QVariant() ); return; } QVariantMap results = resultList.first().toMap(); QVariantList tracks = results[ "album" ].toMap()[ "tracks" ].toList(); if ( tracks.isEmpty() ) { tLog() << "Error parsing JSON from Rovi!" << p.errorString() << response; emit info( requestData, QVariant() ); } QStringList trackNameList; foreach ( const QVariant& track, tracks ) { const QVariantMap trackData = track.toMap(); if ( trackData.contains( "title" ) ) trackNameList << trackData[ "title" ].toString(); } QVariantMap returnedData; returnedData["tracks"] = trackNameList; emit info( requestData, returnedData ); Tomahawk::InfoSystem::InfoStringHash criteria; criteria["artist"] = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash>()["artist"]; criteria["album"] = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash>()["album"]; emit updateCache( criteria, 0, requestData.type, returnedData ); }
QVariant ContentItemInterfacePrivate::parseReplyDataVariant(const QByteArray &replyData, bool *ok) { QVariant parsed; #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) QJson::Parser jsonParser; parsed = jsonParser.parse(replyData, ok); if (!*ok) { qWarning() << Q_FUNC_INFO << "Error parsing JSON file:" << jsonParser.errorString() << "at" << jsonParser.errorLine(); } #else QJsonParseError jsonError; QJsonDocument jsonDocument = QJsonDocument::fromJson(replyData, &jsonError); *ok = !jsonDocument.isEmpty(); if (!*ok) { qWarning() << Q_FUNC_INFO << "Error parsing JSON file:" << jsonError.errorString() << "at" << jsonError.offset; } parsed = jsonDocument.toVariant(); #endif if (!*ok) { parsed.clear(); } return parsed; }
virtual void OnObserve(const char* aTopic, const PRUnichar* aData) { // LOGT("aTopic: %s, data: %s", aTopic, NS_ConvertUTF16toUTF8(aData).get()); QString data((QChar*)aData); if (!data.startsWith('{') && !data.startsWith('[') && !data.startsWith('"')) { QVariant vdata = QVariant::fromValue(data); Q_EMIT q->recvObserve(aTopic, vdata); return; } bool ok = true; #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) QJson::Parser parser; QVariant vdata = parser.parse(data.toUtf8(), &ok); #else QJsonParseError error; QJsonDocument doc = QJsonDocument::fromJson(data.toUtf8(), &error); ok = error.error == QJsonParseError::NoError; QVariant vdata = doc.toVariant(); #endif if (ok) { // LOGT("mesg:%s, data:%s", aTopic, data.toUtf8().data()); Q_EMIT q->recvObserve(aTopic, vdata); } else { #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) LOGT("parse: s:'%s', err:%s, errLine:%i", data.toUtf8().data(), parser.errorString().toUtf8().data(), parser.errorLine()); #else LOGT("parse: s:'%s', err:%s, errLine:%i", data.toUtf8().data(), error.errorString().toUtf8().data(), error.offset); #endif } }
QVariant Parse(const QByteArray &data, bool *ok) { QJson::Parser parser; QVariant result = parser.parse(data, ok); if (ok != 0 && *ok == false) LogError(QString("TundraJson::Parse: Error on line %1: %2") .arg(parser.errorLine()).arg(parser.errorString())); return result; }
void RdioParser::rdioReturned() { QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() ); Q_ASSERT( r ); m_reqQueries.remove( r ); m_count++; r->deleteLater(); if ( r->error() == QNetworkReply::NoError ) { QJson::Parser p; bool ok; QVariantMap res = p.parse( r, &ok ).toMap(); QVariantMap result = res.value( "result" ).toMap(); if ( !ok || result.isEmpty() ) { tLog() << "Failed to parse json from Rdio browse item :" << p.errorString() << "On line" << p.errorLine() << "With data:" << res; return; } QVariantList tracks = result.value( "tracks" ).toList(); if ( tracks.isEmpty() ) { tLog() << "Got no tracks in result, ignoring!" << result; return; } // Playlists will have these m_title = result[ "name" ].toString(); m_creator = result[ "owner" ].toString(); foreach( QVariant track, tracks ) { QVariantMap rdioResult = track.toMap(); QString title, artist, album; title = rdioResult.value( "name", QString() ).toString(); artist = rdioResult.value( "artist", QString() ).toString(); album = rdioResult.value( "album", QString() ).toString(); if ( title.isEmpty() && artist.isEmpty() ) // don't have enough... { tLog() << "Didn't get an artist and track name from Rdio, not enough to build a query on. Aborting" << title << artist << album; return; } Tomahawk::query_ptr q = Tomahawk::Query::get( artist, title, album, uuid(), !m_createPlaylist ); m_tracks << q; }
QVariant Cache::load(QString name, QString *error) { error->clear(); // If the name is in the cache, if (recent().contains(name)) { QVariantMap result; recent().removeOne(name); recent().prepend(name); // If the data is not loaded, if (!data().contains(name)) { // Load the data QByteArray array = read_file(directory() + '/' + name.replace('/', '-'), error); if (!error->isEmpty()) return QVariant(); bool ok; QJson::Parser parser; result = parser.parse(array, &ok).toMap(); if (!ok) { *error = INVALID_JSON + parser.errorString(); return QVariant(); } this->data()[name] = result; } else { result = this->data()[name].toMap(); } //qDebug() << "Saved:" << result["time"].toDateTime(); //qDebug() << "Now:" << QDateTime::currentDateTime(); //qDebug() << "Data exists in cache:" << name; // If the data is current, if (maxTime() == 0 || result["time"].toDateTime().msecsTo(QDateTime::currentDateTime()) < maxTime()) { // Return the data return result["data"]; } else { // Otherwise, // Return no data, with error "Outdated data" *error = OUTDATED_DATA; return result["data"]; } } else { // Otherwise, //qDebug() << "Data not in cache:" << name; // Return no data, with error "No data in cache" *error = NO_DATA; return QVariant(); } }
void DeclarationValidator::visit(Declaration* declaration) { bool testDataOk; QJson::Parser parser; QVariantMap testData = parser.parse(preprocess(declaration->comment()), &testDataOk).toMap(); if (!testDataOk) { d->testsPassed = false; qDebug() << "Error parsing test data for declaration on line" << declaration->range().start.line + 1; qDebug() << "Parser error on comment line" << parser.errorLine() << "was" << parser.errorString(); return; } if (!KDevelop::runTests(testData, declaration)) d->testsPassed = false; }
virtual void RecvAsyncMessage(const PRUnichar* aMessage, const PRUnichar* aData) { NS_ConvertUTF16toUTF8 message(aMessage); NS_ConvertUTF16toUTF8 data(aData); bool ok = false; #if (QT_VERSION <= QT_VERSION_CHECK(5, 0, 0)) QJson::Parser parser; QVariant vdata = parser.parse(QByteArray(data.get()), &ok); #else QJsonParseError error; QJsonDocument doc = QJsonDocument::fromJson(QByteArray(data.get()), &error); ok = error.error == QJsonParseError::NoError; QVariant vdata = doc.toVariant(); #endif if (!strncmp(message.get(), "embed:", 6) || !strncmp(message.get(), "chrome:", 7)) { if (ok) { if (!strcmp(message.get(), "embed:alert")) { Q_EMIT q->alert(vdata); return; } else if (!strcmp(message.get(), "embed:confirm")) { Q_EMIT q->confirm(vdata); return; } else if (!strcmp(message.get(), "embed:prompt")) { Q_EMIT q->prompt(vdata); return; } else if (!strcmp(message.get(), "embed:auth")) { Q_EMIT q->authRequired(vdata); return; } else if (!strcmp(message.get(), "chrome:title")) { QMap<QString, QVariant> map = vdata.toMap(); mTitle = map["title"].toString(); Q_EMIT q->titleChanged(); return; } } else { #if (QT_VERSION <= QT_VERSION_CHECK(5, 0, 0)) LOGT("parse: err:%s, errLine:%i", parser.errorString().toUtf8().data(), parser.errorLine()); #else LOGT("parse: err:%s, errLine:%i", error.errorString().toUtf8().data(), error.offset); #endif } } LOGT("mesg:%s, data:%s", message.get(), data.get()); Q_EMIT q->recvAsyncMessage(message.get(), vdata); }
void polarList::requestFinished(QByteArray res) { QJson::Parser parser; bool ok; QList<QVariant> result = parser.parse (res, &ok).toList(); if (!ok) { qWarning() << "Error parsing json data " << res; qWarning() << "Error: " << parser.errorString() << " (line: " << parser.errorLine() << ")"; } qWarning() << "Polar list: " ; foreach (QVariant polar, result) { qWarning() << "\t-" << polar.toString(); } }
QVariant QGitHubReleaseAPIPrivate::parseJSon(const QByteArray &ba, QString &err) const { #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) || defined(QJSON_FOUND) #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) QJson::Parser parser; bool ok = false; #else QJsonParseError ok; #endif err = QString::null; #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) QVariant v(QJsonDocument::fromJson(ba, &ok).toVariant()); if(ok.error == QJsonParseError::NoError) { return v; } else { err = ok.errorString(); } #else QVariant v(parser.parse(m_jsonData, &ok)); if(ok) { return v; } else { err = parser.errorString(); } #endif #else err = tr("No JSon parser found"); #endif return QVariant(); }
QVariant ParseFile(const QString &filePath, bool removeCommentLines, bool *ok) { QFile file(filePath); if (!file.open(QFile::ReadOnly)) return QVariant(); QByteArray data = file.readAll(); file.close(); if (removeCommentLines) { // If we are removing lines, we have to parse here to report correct error line! // If this wont be reported right, startup and rendering config errors in console // are going to be very confusing to people as the line numbers won't match the file content. uint removedLines = 0; data = RemoveLines(data, QStringList() << "//" << "#", &removedLines); QJson::Parser parser; QVariant result = parser.parse(data, ok); if (ok != 0 && *ok == false) LogError(QString("TundraJson::Parse: Error on line %1: %2") .arg(parser.errorLine()+removedLines).arg(parser.errorString())); return result; } return Parse(data, ok); }
QDateTime Cache::lastUpdated(QString name, QString *error) { // If the name is in the cache, if (recent().contains(name)) { QVariantMap result; // If the data is not loaded, if (!data().contains(name)) { // Load the data QByteArray array = read_file(directory() + '/' + name.replace('/', '-'), error); if (!error->isEmpty()) return QDateTime::currentDateTime(); bool ok; QJson::Parser parser; result = parser.parse(array, &ok).toMap(); if (!ok) { *error = INVALID_JSON + parser.errorString(); return QDateTime::currentDateTime(); } this->data()[name] = result; } else { result = this->data()[name].toMap(); } //qDebug() << "Saved:" << result["time"].toDateTime(); //qDebug() << "Now:" << QDateTime::currentDateTime(); return result["time"].toDateTime(); } else { // Otherwise, // Return no data, with error "No data in cache" *error = NO_DATA; return QDateTime::currentDateTime(); } }
bool FEMemoryMetaData::parseMetaData(QString json) { QJson::Parser parser; QVariant top = parser.parse(json.toStdString().c_str()); if (!top.isValid()) { QString errormsg = QString("Error parsing JSON from config file on line number: ") + QString::number(parser.errorLine()) + " error text: " + parser.errorString(); //QMessageBox::information(0,"Error",errormsg); qDebug() << "Error parsing JSON"; qDebug() << "Line number:" << parser.errorLine() << "error text:" << parser.errorString(); qDebug() << "Start Json"; qDebug() << "Json:" << json; qDebug() << "End Json"; return false; } QVariantMap topmap = top.toMap(); QVariantMap errormap = topmap["errormap"].toMap(); QVariantMap::iterator i = errormap.begin(); while (i != errormap.end()) { bool ok = false; m_errorMap[i.value().toString().mid(2).toInt(&ok,16)] = i.key(); i++; } QVariantMap ramvars = topmap["ramvars"].toMap(); i = ramvars.begin(); while (i != ramvars.end()) { bool ok = false; unsigned short locid = i.key().mid(2).toInt(&ok,16); m_readOnlyMetaDataMap[locid] = ReadOnlyRamBlock(); QVariantMap locidlist = i.value().toMap(); QString title = locidlist["title"].toString(); m_readOnlyMetaDataMap[locid].title = title; QVariantList locidmap = locidlist["vars"].toList(); int offset = 0; for (int j=0;j<locidmap.size();j++) { QVariantMap newlocidmap = locidmap[j].toMap(); ReadOnlyRamData rdata; rdata.dataTitle = newlocidmap["name"].toString(); rdata.dataDescription = newlocidmap["title"].toString(); rdata.locationId = locid; rdata.offset = offset; rdata.size = newlocidmap["size"].toInt(); offset += rdata.size; m_readOnlyMetaDataMap[locid].m_ramData.append(rdata); m_readOnlyMetaData.append(rdata); //m_readOnlyMetaDataMap[locid].append(rdata); } /*QVariantMap::iterator j = locidmap.begin(); while (j != locidmap.end()) { if (j.key() == "title") { QString title = j.value().toString(); qDebug() << "Location title:" << title; } else { qDebug() << j.key(); QVariantMap valuemap = j.value().toMap(); if (valuemap.contains("type")) { ConfigData cdata; cdata.configDescription = valuemap["title"].toString(); cdata.configTitle = j.key(); cdata.elementSize = valuemap["size"].toInt(); cdata.locationId = locid; cdata.offset = valuemap["offset"].toInt(); cdata.type = valuemap["type"].toString(); QVariantMap calcmap = valuemap["calc"].toMap(); QList<QPair<QString,double> > calclist; QVariantMap::iterator k = calcmap.begin(); while (k != calcmap.end()) { calclist.append(QPair<QString,double>(k.key(),k.value().toDouble())); k++; } cdata.elementCalc = calclist; if (valuemap["type"] == "value") { } else if (valuemap["type"] == "array") { cdata.arraySize = valuemap["arraysize"].toInt(); } m_configMetaData.append(cdata); } } j++; }*/ i++; } /*"lookuptables" : { "0x8000" : { "title": "IAT Transfer Table", "size" : "1024", "editable" : "false" }, "0x8001" : { "title" : "CHT Transfer Table", "size" : "1024", "editable" : "false" } }*/ QVariantMap lookups = topmap["lookuptables"].toMap(); i = lookups.begin(); while (i != lookups.end()) { QVariantMap lookupmap = i.value().toMap(); QString keystr = i.key(); bool ok = false; unsigned short keyint = keystr.mid(2).toInt(&ok,16); LookupMetaData meta; meta.locationid = keyint; meta.title = lookupmap["title"].toString(); if (lookupmap["editable"].toString().toLower() == "true") { meta.editable = true; } else { meta.editable = false; } m_lookupMetaData[keyint] = meta; i++; } qDebug() << m_readOnlyMetaData.size() << "Ram entries found"; QVariantMap tables = topmap["tables"].toMap(); i = tables.begin(); while (i != tables.end()) { QVariantMap tabledata = i.value().toMap(); if (tabledata["type"] == "3D") { Table3DMetaData meta; QString id = tabledata["locationid"].toString(); QString xtitle = tabledata["xtitle"].toString(); QVariantList xcalc = tabledata["xcalc"].toList(); QString xdp = tabledata["xdp"].toString(); unsigned int size = tabledata["size"].toInt(); QString ytitle = tabledata["ytitle"].toString(); QVariantList ycalc = tabledata["ycalc"].toList(); QString ydp = tabledata["ydp"].toString(); QString ztitle = tabledata["ztitle"].toString(); QVariantList zcalc = tabledata["zcalc"].toList(); QString zdp = tabledata["zdp"].toString(); QString xhighlight = tabledata["xhighlight"].toString(); QString yhighlight = tabledata["yhighlight"].toString(); //QVariantMap::iterator calci = xcalc.begin(); QList<QPair<QString,double> > xcalclist; QList<QPair<QString,double> > ycalclist; QList<QPair<QString,double> > zcalclist; for (int j=0;j<xcalc.size();j++) { qDebug() << "XCalc:" << xcalc[j].toMap()["type"].toString() << xcalc[j].toMap()["value"].toDouble(); xcalclist.append(QPair<QString,double>(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble())); } for (int j=0;j<ycalc.size();j++) { ycalclist.append(QPair<QString,double>(ycalc[j].toMap()["type"].toString(),ycalc[j].toMap()["value"].toDouble())); } for (int j=0;j<zcalc.size();j++) { zcalclist.append(QPair<QString,double>(zcalc[j].toMap()["type"].toString(),zcalc[j].toMap()["value"].toDouble())); } bool ok = false; meta.locationId = id.mid(2).toInt(&ok,16); meta.tableTitle = i.key(); meta.xAxisCalc = xcalclist; meta.xAxisTitle = xtitle; meta.xDp = xdp.toInt(); meta.yAxisCalc = ycalclist; meta.yAxisTitle = ytitle; meta.yDp = ydp.toInt(); meta.zAxisCalc = zcalclist; meta.zAxisTitle = ztitle; meta.zDp = zdp.toInt(); meta.size = size; meta.valid = true; meta.xHighlight = xhighlight; meta.yHighlight = yhighlight; m_table3DMetaData.append(meta); } else if (tabledata["type"] == "2D") { Table2DMetaData meta; QString id = tabledata["locationid"].toString(); QString xtitle = tabledata["xtitle"].toString(); QVariantList xcalc = tabledata["xcalc"].toList(); QString xdp = tabledata["xdp"].toString(); QString ytitle = tabledata["ytitle"].toString(); QVariantList ycalc = tabledata["ycalc"].toList(); QString ydp = tabledata["ydp"].toString(); unsigned int size = tabledata["size"].toInt(); QString xhighlight = tabledata["xhighlight"].toString(); QList<QPair<QString,double> > xcalclist; QList<QPair<QString,double> > ycalclist; for (int j=0;j<xcalc.size();j++) { qDebug() << "XCalc:" << xcalc[j].toMap()["type"].toString() << xcalc[j].toMap()["value"].toDouble(); xcalclist.append(QPair<QString,double>(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble())); } for (int j=0;j<ycalc.size();j++) { ycalclist.append(QPair<QString,double>(ycalc[j].toMap()["type"].toString(),ycalc[j].toMap()["value"].toDouble())); } bool ok = false; meta.locationId = id.mid(2).toInt(&ok,16); meta.tableTitle = i.key(); meta.xAxisCalc = xcalclist; meta.xAxisTitle = xtitle; meta.xDp = xdp.toInt(); meta.yAxisCalc = ycalclist; meta.yAxisTitle = ytitle; meta.yDp = ydp.toInt(); meta.size = size; meta.valid = true; meta.xHighlight = xhighlight; m_table2DMetaData.append(meta); } i++; } return true; }
void BdLogic::replyFinished() { QByteArray replyData(m_reply->readAll()); if(m_replyGotError) { return; } qDebug() << BoxNames[m_dlState] << " reply body:\n" << replyData; // TODO: if state is login, check if it worked .... if(m_dlState != DLSTATE_LOGIN) { QJson::Parser parser; bool parsedOk = true; if(m_dlState == DLSTATE_INACTIVEPROJECTS) { m_boxMapRawJson[BoxNames[m_dlState]] += replyData; m_boxMapRawJson[BoxNames[m_dlState]] += "\n"; m_inactiveProjectListParsedJson.push_back(parser.parse(replyData, &parsedOk)); m_currentInactiveProjectDlIx++; } else { m_boxMapRawJson[BoxNames[m_dlState]] = replyData; m_boxMapParsedJson[BoxNames[m_dlState]] = parser.parse(replyData, &parsedOk); if(m_dlState == DLSTATE_RESOURCES) { buildInactiveProjectList(); } } if(!parsedOk) { m_statusString = QString("Error parsing JSON from URL: "); if(m_dlState == DLSTATE_RESOURCES) { m_statusString += DOIT_RESOURCES_DATA_URL; } else { m_statusString += DOIT_BASE_DATA_URL; m_statusString += BoxNames[m_dlState]; } // User doesn't really need to know line number of error, // but print during development: qDebug() << m_statusString << ": " << parser.errorString() << ", on line: " << parser.errorLine(); m_statusCode = BDLOGIC_STATUS_JSON_PARSE_ERROR; emit downloadStatusUpdated(m_statusCode, m_statusString); m_reply->deleteLater(); return; } } // After this, I can re-use my QNetworkReply pointer m_reply->deleteLater(); if(m_dlState != DLSTATE_INACTIVEPROJECTS) { m_dlState++; } // Catch no inactive projects, as soon as state is entered if(m_dlState == DLSTATE_INACTIVEPROJECTS) { if(m_currentInactiveProjectDlIx >= m_inactiveProjectUUIDList.length()) { m_dlState++; } } if(m_dlState != DLSTATE_FINISHED) { QNetworkRequest request; QString boxUrl; if(m_dlState == DLSTATE_RESOURCES) { boxUrl = DOIT_RESOURCES_DATA_URL; } else if(m_dlState == DLSTATE_INACTIVEPROJECTS) { boxUrl = DOIT_BASE_DATA_URL "project/"; boxUrl += QUrl::toPercentEncoding(m_inactiveProjectUUIDList[m_currentInactiveProjectDlIx]); } else { boxUrl = DOIT_BASE_DATA_URL; boxUrl += BoxNames[m_dlState]; } request.setUrl(boxUrl); m_reply = m_netManager->get(request); connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished())); connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(replyError(QNetworkReply::NetworkError))); connect(m_reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(replySSLError(QList<QSslError>))); m_statusString = QString("Downloading data for box: "); m_statusString += BoxNames[m_dlState]; emit downloadStatusUpdated(m_statusCode, m_statusString); } else { m_statusCode = BDLOGIC_STATUS_DOWNLOAD_FINISHED; m_statusString = QString("Downloading finished"); addInactiveProjectTasksToBoxes(); SetDataModelOrdering(0); emit downloadStatusUpdated(m_statusCode, m_statusString); qDebug() << m_statusString; } }
bool ImgurTalker::parseResponseImageUpload(const QByteArray& data) { bool ok = false; if (data.isEmpty()) return false; QJson::Parser* p = new QJson::Parser(); QVariant r = p->parse(data, &ok); if (ok) { QMap<QString, QVariant> m = r.toMap(); QString responseType = m.begin().key(); if (responseType == "error") { ImgurError error; QMap<QString,QVariant> errData = m.begin().value().toMap(); for (QMap<QString,QVariant>::iterator it = errData.begin(); it != errData.end(); ++it) { QString v = it.value().toString(); if (it.key() == "message") { error.message = v; } if (it.key() == "request") { error.request = v; } if (it.key() == "method") { if ( v == "get") { error.method = ImgurError::GET; } if ( v == "post") { error.method = ImgurError::POST; } } if (it.key() == "format") { if ( v == "json") { error.format = ImgurError::JSON; } if ( v == "xml") { error.format = ImgurError::XML; } } if (it.key() == "parameters") { error.parameters = v; } } emit signalError(error); // p->errorString() return false; } if (responseType == "upload" ) { ImgurSuccess success; QMap<QString, QVariant> successData = m.begin().value().toMap(); for (QMap<QString,QVariant>::iterator it = successData.begin(); it != successData.end(); ++it) { if (it.key() == "image") { QMap<QString, QVariant> v = it.value().toMap(); for (QMap<QString,QVariant>::iterator it = v.begin(); it != v.end(); ++it) { QString value = it.value().toString(); if (it.key() == "name") { success.image.name = value; } if (it.key() == "title") { success.image.title = value; } if (it.key() == "caption") { success.image.caption = value; } if (it.key() == "hash") { success.image.hash = value; } if (it.key() == "deleteHash") { success.image.deletehash = value; } if (it.key() == "dateTime") { //success.image.datetime = QDateTime(value); } if (it.key() == "type") { success.image.type = value; } if (it.key() == "animated") { success.image.animated = (value == "true"); } if (it.key() == "width") { success.image.width = value.toInt(); } if (it.key() == "height") { success.image.height = value.toInt(); } if (it.key() == "size") { success.image.size = value.toInt(); } if (it.key() == "views") { success.image.views = value.toInt(); } if (it.key() == "bandwidth") { success.image.bandwidth = value.toLongLong(); } } } if (it.key() == "links") { QMap<QString, QVariant> v = it.value().toMap(); for (QMap<QString,QVariant>::iterator it = v.begin(); it != v.end(); ++it) { QString value = it.value().toString(); if (it.key() == "original") { success.links.original = value; } if (it.key() == "imgur_page") { success.links.imgur_page = value; } if (it.key() == "delete_page") { success.links.delete_page = value; } if (it.key() == "small_square") { success.links.small_square = value; } if (it.key() == "largeThumbnail") { success.links.large_thumbnail = value; } } } } emit signalSuccess(success); // kDebug() << "Link:" << success.links.imgur_page; // kDebug() << "Delete:" << success.links.delete_page; } } else { ImgurError error; error.message = "Parse error"; emit signalError (error); // p->errorString() kDebug() << "Parser error :" << p->errorString(); return false; } return true; }
void QgsAmsLegendFetcher::handleFinished() { // Parse result QJson::Parser parser; bool ok = false; QVariantMap queryResults = parser.parse( mQueryReply, &ok ).toMap(); if ( !ok ) { emit error( QString( "Parsing error at line %1: %2" ).arg( parser.errorLine() ).arg( parser.errorString() ) ); } QgsDataSourceURI dataSource( mProvider->dataSourceUri() ); QList< QPair<QString, QImage> > legendEntries; foreach ( const QVariant& result, queryResults["layers"].toList() ) { QVariantMap queryResultMap = result.toMap(); QString layerId = queryResultMap["layerId"].toString(); if ( layerId != dataSource.param( "layer" ) && !mProvider->subLayers().contains( layerId ) ) { continue; } QVariantList legendSymbols = queryResultMap["legend"].toList(); foreach ( const QVariant& legendEntry, legendSymbols ) { QVariantMap legendEntryMap = legendEntry.toMap(); QString label = legendEntryMap["label"].toString(); if ( label.isEmpty() && legendSymbols.size() == 1 ) label = queryResultMap["layerName"].toString(); QByteArray imageData = QByteArray::fromBase64( legendEntryMap["imageData"].toByteArray() ); legendEntries.append( qMakePair( label, QImage::fromData( imageData ) ) ); } }
bool FEMemoryMetaData::parseMetaData(QString json) { QJson::Parser parser; QVariant top = parser.parse(json.toStdString().c_str()); if (!top.isValid()) { QString errormsg = QString("Error parsing JSON from config file on line number: ") + QString::number(parser.errorLine()) + " error text: " + parser.errorString(); qDebug() << "Error parsing JSON"; qDebug() << "Line number:" << parser.errorLine() << "error text:" << parser.errorString(); qDebug() << "Start Json"; qDebug() << "Json:" << json; qDebug() << "End Json"; return false; } QVariantMap topmap = top.toMap(); QVariantMap errormap = topmap["errormap"].toMap(); QVariantMap::iterator i = errormap.begin(); while (i != errormap.end()) { bool ok = false; m_errorMap[i.value().toString().mid(2).toInt(&ok,16)] = i.key(); i++; } QVariantMap ramvars = topmap["ramvars"].toMap(); i = ramvars.begin(); while (i != ramvars.end()) { bool ok = false; unsigned short locid = i.key().mid(2).toInt(&ok,16); m_readOnlyMetaDataMap[locid] = ReadOnlyRamBlock(); QVariantMap locidlist = i.value().toMap(); QString title = locidlist["title"].toString(); m_readOnlyMetaDataMap[locid].title = title; QVariantList locidmap = locidlist["vars"].toList(); int offset = 0; for (int j=0;j<locidmap.size();j++) { QVariantMap newlocidmap = locidmap[j].toMap(); ReadOnlyRamData rdata; rdata.dataTitle = newlocidmap["name"].toString(); rdata.dataDescription = newlocidmap["title"].toString(); rdata.locationId = locid; rdata.offset = offset; rdata.size = newlocidmap["size"].toInt(); offset += rdata.size; m_readOnlyMetaDataMap[locid].m_ramData.append(rdata); m_readOnlyMetaData.append(rdata); } i++; } QVariantMap lookups = topmap["lookuptables"].toMap(); i = lookups.begin(); while (i != lookups.end()) { QVariantMap lookupmap = i.value().toMap(); QString keystr = i.key(); bool ok = false; unsigned short keyint = keystr.mid(2).toInt(&ok,16); LookupMetaData meta; meta.locationid = keyint; meta.title = lookupmap["title"].toString(); if (lookupmap["editable"].toString().toLower() == "true") { meta.editable = true; } else { meta.editable = false; } m_lookupMetaData[keyint] = meta; i++; } qDebug() << m_readOnlyMetaData.size() << "Ram entries found"; QVariantMap tables = topmap["tables"].toMap(); i = tables.begin(); while (i != tables.end()) { QVariantMap tabledata = i.value().toMap(); if (tabledata["type"] == "3D") { Table3DMetaData meta; QString id = tabledata["locationid"].toString(); QString xtitle = tabledata["xtitle"].toString(); QVariantList xcalc = tabledata["xcalc"].toList(); QString xdp = tabledata["xdp"].toString(); unsigned int size = tabledata["size"].toInt(); QString ytitle = tabledata["ytitle"].toString(); QVariantList ycalc = tabledata["ycalc"].toList(); QString ydp = tabledata["ydp"].toString(); QString ztitle = tabledata["ztitle"].toString(); QVariantList zcalc = tabledata["zcalc"].toList(); QString zdp = tabledata["zdp"].toString(); QString xhighlight = tabledata["xhighlight"].toString(); QString yhighlight = tabledata["yhighlight"].toString(); QList<QPair<QString,double> > xcalclist; QList<QPair<QString,double> > ycalclist; QList<QPair<QString,double> > zcalclist; for (int j=0;j<xcalc.size();j++) { qDebug() << "XCalc:" << xcalc[j].toMap()["type"].toString() << xcalc[j].toMap()["value"].toDouble(); xcalclist.append(QPair<QString,double>(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble())); } for (int j=0;j<ycalc.size();j++) { ycalclist.append(QPair<QString,double>(ycalc[j].toMap()["type"].toString(),ycalc[j].toMap()["value"].toDouble())); } for (int j=0;j<zcalc.size();j++) { zcalclist.append(QPair<QString,double>(zcalc[j].toMap()["type"].toString(),zcalc[j].toMap()["value"].toDouble())); } bool ok = false; meta.locationId = id.mid(2).toInt(&ok,16); meta.tableTitle = i.key(); meta.xAxisCalc = xcalclist; meta.xAxisTitle = xtitle; meta.xDp = xdp.toInt(); meta.yAxisCalc = ycalclist; meta.yAxisTitle = ytitle; meta.yDp = ydp.toInt(); meta.zAxisCalc = zcalclist; meta.zAxisTitle = ztitle; meta.zDp = zdp.toInt(); meta.size = size; meta.valid = true; meta.xHighlight = xhighlight; meta.yHighlight = yhighlight; for (int i=0;i<m_table3DMetaData.size();i++) { if (m_table3DMetaData[i].locationId == meta.locationId) { //Error, already exists; qDebug() << "Error: Location ID 0x" + QString::number(meta.locationId,16).toUpper() + " is defined twice in the metadata file"; return false; } } m_table3DMetaData.append(meta); } else if (tabledata["type"] == "2D") { Table2DMetaData meta; QString id = tabledata["locationid"].toString(); QString xtitle = tabledata["xtitle"].toString(); QVariantList xcalc = tabledata["xcalc"].toList(); QString xdp = tabledata["xdp"].toString(); QString ytitle = tabledata["ytitle"].toString(); QVariantList ycalc = tabledata["ycalc"].toList(); QString ydp = tabledata["ydp"].toString(); unsigned int size = tabledata["size"].toInt(); QString xhighlight = tabledata["xhighlight"].toString(); QList<QPair<QString,double> > xcalclist; QList<QPair<QString,double> > ycalclist; for (int j=0;j<xcalc.size();j++) { qDebug() << "XCalc:" << xcalc[j].toMap()["type"].toString() << xcalc[j].toMap()["value"].toDouble(); xcalclist.append(QPair<QString,double>(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble())); } for (int j=0;j<ycalc.size();j++) { ycalclist.append(QPair<QString,double>(ycalc[j].toMap()["type"].toString(),ycalc[j].toMap()["value"].toDouble())); } bool ok = false; meta.locationId = id.mid(2).toInt(&ok,16); meta.tableTitle = i.key(); meta.xAxisCalc = xcalclist; meta.xAxisTitle = xtitle; meta.xDp = xdp.toInt(); meta.yAxisCalc = ycalclist; meta.yAxisTitle = ytitle; meta.yDp = ydp.toInt(); meta.size = size; meta.valid = true; meta.xHighlight = xhighlight; for (int i=0;i<m_table2DMetaData.size();i++) { if (m_table2DMetaData[i].locationId == meta.locationId) { //Error, already exists; qDebug() << "Error: Location ID 0x" + QString::number(meta.locationId,16).toUpper() + " is defined twice in the metadata file"; return false; } } m_table2DMetaData.append(meta); } i++; } return true; }
void JSPFLoader::gotBody() { QJson::Parser p; bool retOk; QVariantMap wrapper = p.parse( m_body, &retOk ).toMap(); if ( !retOk ) { tLog() << "Failed to parse jspf json:" << p.errorString() << "on line" << p.errorLine(); return; } if ( !wrapper.contains( "playlist" ) ) { tLog() << "No playlist element in JSPF!"; return; } QVariantMap pl = wrapper.value( "playlist" ).toMap(); QString origTitle = pl.value( "title" ).toString(); m_info = pl.value( "info" ).toString(); m_creator = pl.value( "creator" ).toString(); m_title = origTitle; if ( m_title.isEmpty() ) m_title = tr( "New Playlist" ); if ( !m_overrideTitle.isEmpty() ) m_title = m_overrideTitle; if ( pl.contains( "track" ) ) { QVariantList tracks = pl.value( "track" ).toList(); bool shownError = false; foreach ( const QVariant& currentTrack, tracks ) { QVariantMap tM = currentTrack.toMap(); QString artist, album, track, duration, annotation, url; artist = tM.value( "creator" ).toString(); album = tM.value( "album" ).toString(); track = tM.value( "title" ).toString(); duration = tM.value( "duration" ).toString(); annotation = tM.value( "annotation" ).toString(); if ( tM.value( "location" ).toList().size() > 0 ) url = tM.value( "location" ).toList().first().toString(); if ( artist.isEmpty() || track.isEmpty() ) { if ( !shownError ) { QMessageBox::warning( 0, tr( "Failed to save tracks" ), tr( "Some tracks in the playlist do not contain an artist and a title. They will be ignored." ), QMessageBox::Ok ); shownError = true; } continue; } track_ptr t = Tomahawk::Track::get( artist, track, album, duration.toInt() / 1000 ); query_ptr q = Tomahawk::Query::get( t ); if ( !q ) continue; if ( !url.isEmpty() ) { q->setResultHint( url ); q->setSaveHTTPResultHint( true ); } m_entries << q; }
void MemoryMetaData::loadMetaDataFromFile(QString filestr) { qDebug() << "Loading config file from:" << filestr; QFile file(filestr); file.open(QIODevice::ReadOnly); QByteArray filebytes = file.readAll(); file.close(); QJson::Parser parser; QVariant top = parser.parse(filebytes); if (!top.isValid()) { QString errormsg = QString("Error parsing JSON from config file on line number: ") + QString::number(parser.errorLine()) + " error text: " + parser.errorString(); //QMessageBox::information(0,"Error",errormsg); qDebug() << "Error parsing JSON"; qDebug() << "Line number:" << parser.errorLine() << "error text:" << parser.errorString(); return; } QVariantMap topmap = top.toMap(); QVariantMap errormap = topmap["errormap"].toMap(); QVariantMap::iterator i = errormap.begin(); while (i != errormap.end()) { bool ok = false; m_errorMap[i.value().toString().mid(2).toInt(&ok,16)] = i.key(); i++; } QVariantMap ramvars = topmap["ramvars"].toMap(); i = ramvars.begin(); while (i != ramvars.end()) { bool ok = false; unsigned short locid = i.key().mid(2).toInt(&ok,16); m_readOnlyMetaDataMap[locid] = ReadOnlyRamBlock(); QVariantMap locidlist = i.value().toMap(); QString title = locidlist["title"].toString(); m_readOnlyMetaDataMap[locid].title = title; QVariantList locidmap = locidlist["vars"].toList(); int offset = 0; for (int j=0;j<locidmap.size();j++) { QVariantMap newlocidmap = locidmap[j].toMap(); ReadOnlyRamData rdata; rdata.dataTitle = newlocidmap["name"].toString(); rdata.dataDescription = newlocidmap["title"].toString(); rdata.locationId = locid; rdata.offset = offset; rdata.size = newlocidmap["size"].toInt(); offset += rdata.size; m_readOnlyMetaDataMap[locid].m_ramData.append(rdata); m_readOnlyMetaData.append(rdata); //m_readOnlyMetaDataMap[locid].append(rdata); } /*QVariantMap::iterator j = locidmap.begin(); while (j != locidmap.end()) { if (j.key() == "title") { QString title = j.value().toString(); qDebug() << "Location title:" << title; } else { qDebug() << j.key(); QVariantMap valuemap = j.value().toMap(); if (valuemap.contains("type")) { ConfigData cdata; cdata.configDescription = valuemap["title"].toString(); cdata.configTitle = j.key(); cdata.elementSize = valuemap["size"].toInt(); cdata.locationId = locid; cdata.offset = valuemap["offset"].toInt(); cdata.type = valuemap["type"].toString(); QVariantMap calcmap = valuemap["calc"].toMap(); QList<QPair<QString,double> > calclist; QVariantMap::iterator k = calcmap.begin(); while (k != calcmap.end()) { calclist.append(QPair<QString,double>(k.key(),k.value().toDouble())); k++; } cdata.elementCalc = calclist; if (valuemap["type"] == "value") { } else if (valuemap["type"] == "array") { cdata.arraySize = valuemap["arraysize"].toInt(); } m_configMetaData.append(cdata); } } j++; }*/ i++; } qDebug() << m_readOnlyMetaData.size() << "Ram entries found"; QVariantMap tables = topmap["tables"].toMap(); i = tables.begin(); while (i != tables.end()) { QVariantMap tabledata = i.value().toMap(); if (tabledata["type"] == "3D") { Table3DMetaData meta; QString id = tabledata["locationid"].toString(); QString xtitle = tabledata["xtitle"].toString(); QVariantList xcalc = tabledata["xcalc"].toList(); QString xdp = tabledata["xdp"].toString(); unsigned int size = tabledata["size"].toInt(); QString ytitle = tabledata["ytitle"].toString(); QVariantList ycalc = tabledata["ycalc"].toList(); QString ydp = tabledata["ydp"].toString(); QString ztitle = tabledata["ztitle"].toString(); QVariantList zcalc = tabledata["zcalc"].toList(); QString zdp = tabledata["zdp"].toString(); //QVariantMap::iterator calci = xcalc.begin(); QList<QPair<QString,double> > xcalclist; QList<QPair<QString,double> > ycalclist; QList<QPair<QString,double> > zcalclist; for (int j=0;j<xcalc.size();j++) { qDebug() << "XCalc:" << xcalc[j].toMap()["type"].toString() << xcalc[j].toMap()["value"].toDouble(); xcalclist.append(QPair<QString,double>(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble())); } for (int j=0;j<ycalc.size();j++) { ycalclist.append(QPair<QString,double>(ycalc[j].toMap()["type"].toString(),ycalc[j].toMap()["value"].toDouble())); } for (int j=0;j<zcalc.size();j++) { zcalclist.append(QPair<QString,double>(zcalc[j].toMap()["type"].toString(),zcalc[j].toMap()["value"].toDouble())); } bool ok = false; meta.locationId = id.mid(2).toInt(&ok,16); meta.tableTitle = i.key(); meta.xAxisCalc = xcalclist; meta.xAxisTitle = xtitle; meta.xDp = xdp.toInt(); meta.yAxisCalc = ycalclist; meta.yAxisTitle = ytitle; meta.yDp = ydp.toInt(); meta.zAxisCalc = zcalclist; meta.zAxisTitle = ztitle; meta.zDp = zdp.toInt(); meta.size = size; meta.valid = true; m_table3DMetaData.append(meta); } else if (tabledata["type"] == "2D") { Table2DMetaData meta; QString id = tabledata["locationid"].toString(); QString xtitle = tabledata["xtitle"].toString(); QVariantList xcalc = tabledata["xcalc"].toList(); QString xdp = tabledata["xdp"].toString(); QString ytitle = tabledata["ytitle"].toString(); QVariantList ycalc = tabledata["ycalc"].toList(); QString ydp = tabledata["ydp"].toString(); unsigned int size = tabledata["size"].toInt(); QList<QPair<QString,double> > xcalclist; QList<QPair<QString,double> > ycalclist; for (int j=0;j<xcalc.size();j++) { qDebug() << "XCalc:" << xcalc[j].toMap()["type"].toString() << xcalc[j].toMap()["value"].toDouble(); xcalclist.append(QPair<QString,double>(xcalc[j].toMap()["type"].toString(),xcalc[j].toMap()["value"].toDouble())); } for (int j=0;j<ycalc.size();j++) { ycalclist.append(QPair<QString,double>(ycalc[j].toMap()["type"].toString(),ycalc[j].toMap()["value"].toDouble())); } bool ok = false; meta.locationId = id.mid(2).toInt(&ok,16); meta.tableTitle = i.key(); meta.xAxisCalc = xcalclist; meta.xAxisTitle = xtitle; meta.xDp = xdp.toInt(); meta.yAxisCalc = ycalclist; meta.yAxisTitle = ytitle; meta.yDp = ydp.toInt(); meta.size = size; meta.valid = true; m_table2DMetaData.append(meta); } i++; } }