Port from QScriptEngine to QJSonDocument

preferencesAboutTextFull
Jonah Brüchert 5 years ago
parent 9adb8e6643
commit 77a2aff039
No known key found for this signature in database
GPG Key ID: A81E075ABEC80A7E
  1. 1
      OpenBoard.pro
  2. 8
      src/core/UBApplicationController.cpp
  3. 2
      src/core/UBApplicationController.h
  4. 38
      src/web/UBOEmbedParser.cpp

@ -34,7 +34,6 @@ QT += webkit
QT += svg QT += svg
QT += network QT += network
QT += xml QT += xml
QT += script
QT += xmlpatterns QT += xmlpatterns
QT += uitools QT += uitools
QT += multimedia QT += multimedia

@ -543,19 +543,17 @@ void UBApplicationController::downloadJsonFinished(QString currentJson)
} }
*/ */
QScriptValue scriptValue; QJsonObject jsonObject = QJsonDocument::fromJson(currentJson.toUtf8()).object();
QScriptEngine scriptEngine;
scriptValue = scriptEngine.evaluate ("(" + currentJson + ")");
UBVersion installedVersion (qApp->applicationVersion()); UBVersion installedVersion (qApp->applicationVersion());
UBVersion jsonVersion (scriptValue.property("version").toString()); UBVersion jsonVersion (jsonObject.value("version").toString());
qDebug() << "json version: " << jsonVersion.toUInt(); qDebug() << "json version: " << jsonVersion.toUInt();
qDebug() << "installed version: " << installedVersion.toUInt(); qDebug() << "installed version: " << installedVersion.toUInt();
if (jsonVersion > installedVersion) { if (jsonVersion > installedVersion) {
if (UBApplication::mainWindow->yesNoQuestion(tr("Update available"), tr ("New update available, would you go to the web page ?"))){ if (UBApplication::mainWindow->yesNoQuestion(tr("Update available"), tr ("New update available, would you go to the web page ?"))){
QUrl url(scriptValue.property("url").toString()); QUrl url(jsonObject.value("url").toString());
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
} }
} }

@ -38,8 +38,6 @@
#include <QtNetwork/QHttpPart> #include <QtNetwork/QHttpPart>
#include <QScriptValue>
#include <QScriptEngine>
class UBBoardView; class UBBoardView;

@ -32,9 +32,9 @@
#include <QDomDocument> #include <QDomDocument>
#include <QDomElement> #include <QDomElement>
#include <QDomNode> #include <QDomNode>
#include <QScriptValue>
#include <QScriptEngine>
#include <QDebug> #include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include "UBOEmbedParser.h" #include "UBOEmbedParser.h"
@ -119,23 +119,21 @@ sOEmbedContent UBOEmbedParser::getJSONInfos(const QString &json)
{ {
sOEmbedContent content; sOEmbedContent content;
QScriptValue scriptValue; QJsonObject jsonObject = QJsonDocument::fromJson(json.toUtf8()).object();
QScriptEngine scriptEngine;
scriptValue = scriptEngine.evaluate ("(" + json + ")"); QString providerUrl = jsonObject.value("provider_url").toString();
QString title = jsonObject.value("title").toString();
QString providerUrl = scriptValue.property("provider_url").toString(); QString html = jsonObject.value("html").toString();
QString title = scriptValue.property("title").toString(); QString authorName = jsonObject.value("author_name").toString();
QString html = scriptValue.property("html").toString(); int height = jsonObject.value("height").toInt();
QString authorName = scriptValue.property("author_name").toString(); int thumbnailWidth = jsonObject.value("thumbnail_width").toInt();
int height = scriptValue.property("height").toInteger(); int width = jsonObject.value("width").toInt();
int thumbnailWidth = scriptValue.property("thumbnail_width").toInteger(); float version = jsonObject.value("version").toString().toFloat();
int width = scriptValue.property("width").toInteger(); QString authorUrl = jsonObject.value("author_url").toString();
float version = scriptValue.property("version").toString().toFloat(); QString providerName = jsonObject.value("provider_name").toString();
QString authorUrl = scriptValue.property("author_url").toString(); QString thumbnailUrl = jsonObject.value("thumbnail_url").toString();
QString providerName = scriptValue.property("provider_name").toString(); QString type = jsonObject.value("type").toString();
QString thumbnailUrl = scriptValue.property("thumbnail_url").toString(); int thumbnailHeight = jsonObject.value("thumbnail_height").toInt();
QString type = scriptValue.property("type").toString();
int thumbnailHeight = scriptValue.property("thumbnail_height").toInteger();
content.providerUrl = providerUrl; content.providerUrl = providerUrl;
content.title = title; content.title = title;
@ -152,7 +150,7 @@ sOEmbedContent UBOEmbedParser::getJSONInfos(const QString &json)
content.thumbHeight = thumbnailHeight; content.thumbHeight = thumbnailHeight;
if("photo" == content.type){ if("photo" == content.type){
content.url = scriptValue.property("url").toString(); content.url = jsonObject.value("url").toString();
}else if("video" == content.type){ }else if("video" == content.type){
QStringList strl = content.html.split('\"'); QStringList strl = content.html.split('\"');
for(int i=0; i<strl.size(); i++){ for(int i=0; i<strl.size(); i++){

Loading…
Cancel
Save