From 77a2aff0395b08857f5d05827fc8322cf7a7e8e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonah=20Br=C3=BCchert?= Date: Thu, 31 Oct 2019 22:06:53 +0100 Subject: [PATCH] Port from QScriptEngine to QJSonDocument --- OpenBoard.pro | 1 - src/core/UBApplicationController.cpp | 8 +++--- src/core/UBApplicationController.h | 2 -- src/web/UBOEmbedParser.cpp | 38 +++++++++++++--------------- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/OpenBoard.pro b/OpenBoard.pro index 11039a06..5e92a613 100644 --- a/OpenBoard.pro +++ b/OpenBoard.pro @@ -34,7 +34,6 @@ QT += webkit QT += svg QT += network QT += xml -QT += script QT += xmlpatterns QT += uitools QT += multimedia diff --git a/src/core/UBApplicationController.cpp b/src/core/UBApplicationController.cpp index 04f504af..7adaa7eb 100644 --- a/src/core/UBApplicationController.cpp +++ b/src/core/UBApplicationController.cpp @@ -543,19 +543,17 @@ void UBApplicationController::downloadJsonFinished(QString currentJson) } */ - QScriptValue scriptValue; - QScriptEngine scriptEngine; - scriptValue = scriptEngine.evaluate ("(" + currentJson + ")"); + QJsonObject jsonObject = QJsonDocument::fromJson(currentJson.toUtf8()).object(); UBVersion installedVersion (qApp->applicationVersion()); - UBVersion jsonVersion (scriptValue.property("version").toString()); + UBVersion jsonVersion (jsonObject.value("version").toString()); qDebug() << "json version: " << jsonVersion.toUInt(); qDebug() << "installed version: " << installedVersion.toUInt(); if (jsonVersion > installedVersion) { 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); } } diff --git a/src/core/UBApplicationController.h b/src/core/UBApplicationController.h index d36bae1f..d943f9c5 100644 --- a/src/core/UBApplicationController.h +++ b/src/core/UBApplicationController.h @@ -38,8 +38,6 @@ #include -#include -#include class UBBoardView; diff --git a/src/web/UBOEmbedParser.cpp b/src/web/UBOEmbedParser.cpp index 90ce95db..6b65b1fb 100644 --- a/src/web/UBOEmbedParser.cpp +++ b/src/web/UBOEmbedParser.cpp @@ -32,9 +32,9 @@ #include #include #include -#include -#include #include +#include +#include #include "UBOEmbedParser.h" @@ -119,23 +119,21 @@ sOEmbedContent UBOEmbedParser::getJSONInfos(const QString &json) { sOEmbedContent content; - QScriptValue scriptValue; - QScriptEngine scriptEngine; - scriptValue = scriptEngine.evaluate ("(" + json + ")"); - - QString providerUrl = scriptValue.property("provider_url").toString(); - QString title = scriptValue.property("title").toString(); - QString html = scriptValue.property("html").toString(); - QString authorName = scriptValue.property("author_name").toString(); - int height = scriptValue.property("height").toInteger(); - int thumbnailWidth = scriptValue.property("thumbnail_width").toInteger(); - int width = scriptValue.property("width").toInteger(); - float version = scriptValue.property("version").toString().toFloat(); - QString authorUrl = scriptValue.property("author_url").toString(); - QString providerName = scriptValue.property("provider_name").toString(); - QString thumbnailUrl = scriptValue.property("thumbnail_url").toString(); - QString type = scriptValue.property("type").toString(); - int thumbnailHeight = scriptValue.property("thumbnail_height").toInteger(); + QJsonObject jsonObject = QJsonDocument::fromJson(json.toUtf8()).object(); + + QString providerUrl = jsonObject.value("provider_url").toString(); + QString title = jsonObject.value("title").toString(); + QString html = jsonObject.value("html").toString(); + QString authorName = jsonObject.value("author_name").toString(); + int height = jsonObject.value("height").toInt(); + int thumbnailWidth = jsonObject.value("thumbnail_width").toInt(); + int width = jsonObject.value("width").toInt(); + float version = jsonObject.value("version").toString().toFloat(); + QString authorUrl = jsonObject.value("author_url").toString(); + QString providerName = jsonObject.value("provider_name").toString(); + QString thumbnailUrl = jsonObject.value("thumbnail_url").toString(); + QString type = jsonObject.value("type").toString(); + int thumbnailHeight = jsonObject.value("thumbnail_height").toInt(); content.providerUrl = providerUrl; content.title = title; @@ -152,7 +150,7 @@ sOEmbedContent UBOEmbedParser::getJSONInfos(const QString &json) content.thumbHeight = thumbnailHeight; if("photo" == content.type){ - content.url = scriptValue.property("url").toString(); + content.url = jsonObject.value("url").toString(); }else if("video" == content.type){ QStringList strl = content.html.split('\"'); for(int i=0; i