1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

[Json] Use built-in QJSonDocument class in Qt 5

This commit is contained in:
nowrep 2014-02-06 22:24:10 +01:00
parent 03186060aa
commit c9a556658a
4 changed files with 37 additions and 7 deletions

View File

@ -11,8 +11,8 @@ before_install:
install: install:
- sudo apt-get -qq update - sudo apt-get -qq update
- sudo apt-get -qq install libssl-dev pkg-config libhunspell-dev libqjson-dev - sudo apt-get -qq install libssl-dev pkg-config libhunspell-dev
- if [[ "$QT" == "qt4" ]]; then sudo apt-get -qq install libqt4-dev libqt4-webkit libqt4-sql-sqlite; fi - if [[ "$QT" == "qt4" ]]; then sudo apt-get -qq install libqt4-dev libqt4-webkit libqt4-sql-sqlite libqjson-dev; fi
- if [[ "$QT" == "qt5" ]]; then sudo apt-add-repository -y ppa:beineri/opt-qt511; sudo apt-get update -qq; sudo apt-get install -qq qt51base qt51webkit qt51tools qt51script libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev; fi - if [[ "$QT" == "qt5" ]]; then sudo apt-add-repository -y ppa:beineri/opt-qt511; sudo apt-get update -qq; sudo apt-get install -qq qt51base qt51webkit qt51tools qt51script libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev; fi
script: script:

View File

@ -1,7 +1,7 @@
QupZilla Web Browser QupZilla Web Browser
---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------
[![Build Status](https://travis-ci.org/QupZilla/qupzilla.png?branch=master)](https://travis-ci.org/QupZilla/qupzilla) [![Build Status](https://travis-ci.org/QupZilla/qupzilla.png?branch=bookmarks)](https://travis-ci.org/QupZilla/qupzilla)
Homepage: [http://www.qupzilla.com](http://www.qupzilla.com) Homepage: [http://www.qupzilla.com](http://www.qupzilla.com)
Blog: [http://blog.qupzilla.com](http://blog.qupzilla.com) Blog: [http://blog.qupzilla.com](http://blog.qupzilla.com)
IRC: `#qupzilla` at `irc.freenode.net` IRC: `#qupzilla` at `irc.freenode.net`

View File

@ -508,13 +508,17 @@ isEqual(QT_MAJOR_VERSION, 5) {
SOURCES += tools/qzregexp.cpp SOURCES += tools/qzregexp.cpp
} }
!isEqual(QT_MAJOR_VERSION, 5) {
LIBS += -lqjson
}
!mac:unix { !mac:unix {
target.path = $$library_folder target.path = $$library_folder
INSTALLS += target INSTALLS += target
!contains(DEFINES, NO_X11):LIBS += -lX11 !contains(DEFINES, NO_X11):LIBS += -lX11
LIBS += -lcrypto -lqjson LIBS += -lcrypto
RESOURCES -= data/certs.qrc RESOURCES -= data/certs.qrc
} }
@ -523,11 +527,11 @@ win32 {
HEADERS += other/registerqappassociation.h HEADERS += other/registerqappassociation.h
SOURCES += other/registerqappassociation.cpp SOURCES += other/registerqappassociation.cpp
LIBS += -llibeay32 -lqjson LIBS += -llibeay32
} }
os2 { os2 {
LIBS += -lcrypto -lqjson LIBS += -lcrypto
} }
mac { mac {
@ -537,7 +541,7 @@ mac {
webview/macwebviewscroller.cpp webview/macwebviewscroller.cpp
RESOURCES -= data/certs.qrc RESOURCES -= data/certs.qrc
LIBS += -lcrypto -lqjson -framework CoreServices LIBS += -lcrypto -framework CoreServices
} }
message(===========================================) message(===========================================)

View File

@ -16,18 +16,44 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */ * ============================================================ */
#include "json.h" #include "json.h"
#if QT_VERSION < 0x050000
#include <qjson/parser.h> #include <qjson/parser.h>
#include <qjson/serializer.h> #include <qjson/serializer.h>
#else
#include <QJsonDocument>
#endif
QVariant Json::parse(const QByteArray &data, bool *ok) QVariant Json::parse(const QByteArray &data, bool *ok)
{ {
#if QT_VERSION < 0x050000
QJson::Parser parser; QJson::Parser parser;
return parser.parse(data, ok); return parser.parse(data, ok);
#else
QJsonParseError error;
QJsonDocument doc = QJsonDocument::fromJson(data, &error);
if (ok) {
*ok = error.error == QJsonParseError::NoError;
}
return doc.toVariant();
#endif
} }
QByteArray Json::serialize(const QVariant &variant, bool *ok) QByteArray Json::serialize(const QVariant &variant, bool *ok)
{ {
#if QT_VERSION < 0x050000
QJson::Serializer serializer; QJson::Serializer serializer;
serializer.setIndentMode(QJson::IndentFull); serializer.setIndentMode(QJson::IndentFull);
return serializer.serialize(variant, ok); return serializer.serialize(variant, ok);
#else
QJsonDocument doc = QJsonDocument::fromVariant(variant);
if (ok) {
*ok = !doc.isNull();
}
return doc.toJson(QJsonDocument::Indented);
#endif
} }