[SCM] kdeconnect packaging branch, master, updated. debian/0.9g-1-1183-g9d69498
Maximiliano Curia
maxy at moszumanska.debian.org
Fri Oct 14 14:27:55 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/kdeconnect.git;a=commitdiff;h=f20f489
The following commit has been merged in the master branch:
commit f20f48999903cc515a935c00a52a5bca1b9b254f
Author: Àlex Fiestas <afiestas at kde.org>
Date: Sat Sep 13 00:49:56 2014 +0200
Port to aelperay from QJson to native json support
Straight forward port from QJson to the native Json support.
As a note I have added 2 helper functions that make the code bit more
readable (object2qvariant and qvariatn2qobject).
---
CMakeLists.txt | 3 +--
core/CMakeLists.txt | 1 -
core/networkpackage.cpp | 60 +++++++++++++++++++++++++++++++++----------
core/networkpackage.h | 1 -
interfaces/CMakeLists.txt | 2 --
tests/CMakeLists.txt | 2 --
tests/networkpackagetests.cpp | 4 +--
7 files changed, 49 insertions(+), 24 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 426394f..0ed1037 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,7 +8,6 @@ set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_SOURCE_DI
find_package(Qt5 5.2 REQUIRED COMPONENTS Quick Test)
find_package(KF5 REQUIRED COMPONENTS I18n KIO Notifications ConfigWidgets DBusAddons KCMUtils KDELibs4Support)
find_package(QCA2 REQUIRED)
-find_package(QJSON REQUIRED)
include(KDEInstallDirs)
include(KDECompilerSettings)
@@ -19,7 +18,7 @@ include(ECMInstallIcons)
include(FeatureSummary)
include(GenerateExportHeader)
-include_directories(${CMAKE_CURRENT_BINARY_DIR} ${QJSON_INCLUDE_DIR})
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(core)
add_subdirectory(kcm)
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index ab2bc62..090d4fb 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -36,7 +36,6 @@ PUBLIC
KF5::KDELibs4Support
PRIVATE
${QCA2_LIBRARIES}
- ${QJSON_LIBRARIES}
KF5::KIOWidgets
KF5::KCMUtils
Qt5::Network
diff --git a/core/networkpackage.cpp b/core/networkpackage.cpp
index 330850c..25fc971 100644
--- a/core/networkpackage.cpp
+++ b/core/networkpackage.cpp
@@ -23,14 +23,15 @@
#include <KSharedConfig>
#include <KConfigGroup>
+#include <QMetaObject>
+#include <QMetaProperty>
#include <QByteArray>
#include <QDataStream>
#include <QHostInfo>
#include <QSslKey>
#include <QDateTime>
+#include <qjsondocument.h>
#include <QtCrypto>
-#include <qjson/serializer.h>
-#include <qjson/qobjecthelper.h>
#include "filetransferjob.h"
@@ -62,6 +63,18 @@ void NetworkPackage::createIdentityPackage(NetworkPackage* np)
//kDebug(kdeconnect_kded()) << "createIdentityPackage" << np->serialize();
}
+QVariantMap qobject2qvairant(const QObject* object)
+{
+ QVariantMap map;
+ auto metaObject = object->metaObject();
+ for(int i = metaObject->propertyOffset(); i < metaObject->propertyCount(); ++i) {
+ const char *name = metaObject->property(i).name();
+ map.insert(QString::fromLatin1(name), object->property(name));
+ }
+
+ return map;
+}
+
QByteArray NetworkPackage::serialize() const
{
//Object -> QVariant
@@ -69,7 +82,7 @@ QByteArray NetworkPackage::serialize() const
//variant["id"] = mId;
//variant["type"] = mType;
//variant["body"] = mBody;
- QVariantMap variant = QJson::QObjectHelper::qobject2qvariant(this);
+ QVariantMap variant = qobject2qvairant(this);
if (hasPayload()) {
//kDebug(kdeconnect_kded()) << "Serializing payloadTransferInfo";
@@ -79,10 +92,10 @@ QByteArray NetworkPackage::serialize() const
//QVariant -> json
bool ok;
- QJson::Serializer serializer;
- QByteArray json = serializer.serialize(variant,&ok);
- if (!ok) {
- kDebug(debugArea()) << "Serialization error:" << serializer.errorMessage();
+ auto jsonDocument = QJsonDocument::fromVariant(variant);
+ QByteArray json = jsonDocument.toJson(QJsonDocument::Compact);
+ if (json.isEmpty()) {
+ kDebug(debugArea()) << "Serialization error:";
} else {
if (!isEncrypted()) {
//kDebug(kDebugArea) << "Serialized package:" << json;
@@ -93,19 +106,38 @@ QByteArray NetworkPackage::serialize() const
return json;
}
+void qvariant2qobject(const QVariantMap& variant, QObject* object)
+{
+ for ( QVariantMap::const_iterator iter = variant.begin(); iter != variant.end(); ++iter )
+ {
+ QVariant property = object->property( iter.key().toLatin1() );
+ Q_ASSERT( property.isValid() );
+ if ( property.isValid() )
+ {
+ QVariant value = iter.value();
+ if ( value.canConvert( property.type() ) )
+ {
+ value.convert( property.type() );
+ object->setProperty( iter.key().toLatin1(), value );
+ } else if ( QString( QLatin1String("QVariant") ).compare( QLatin1String( property.typeName() ) ) == 0) {
+ object->setProperty( iter.key().toLatin1(), value );
+ }
+ }
+ }
+}
+
bool NetworkPackage::unserialize(const QByteArray& a, NetworkPackage* np)
{
//Json -> QVariant
- QJson::Parser parser;
- bool ok;
- QVariantMap variant = parser.parse(a, &ok).toMap();
- if (!ok) {
- kDebug(debugArea()) << "Unserialization error:" << a;
+ QJsonParseError parseError;
+ auto parser = QJsonDocument::fromJson(a, &parseError);
+ if (parser.isNull()) {
+ kDebug(debugArea()) << "Unserialization error:" << parseError.errorString();
return false;
}
- //QVariant -> Object
- QJson::QObjectHelper::qvariant2qobject(variant, np);
+ auto variant = parser.toVariant().toMap();
+ qvariant2qobject(variant, np);
if (!np->isEncrypted()) {
//kDebug(kDebugArea) << "Unserialized: " << a;
diff --git a/core/networkpackage.h b/core/networkpackage.h
index ed26676..33737d9 100644
--- a/core/networkpackage.h
+++ b/core/networkpackage.h
@@ -30,7 +30,6 @@
#include <QIODevice>
#include <QtCrypto>
#include <QSharedPointer>
-#include <qjson/parser.h>
#include <KUrl>
#include "kdeconnectcore_export.h"
diff --git a/interfaces/CMakeLists.txt b/interfaces/CMakeLists.txt
index db20a4b..ec59957 100644
--- a/interfaces/CMakeLists.txt
+++ b/interfaces/CMakeLists.txt
@@ -72,8 +72,6 @@ target_link_libraries(kdeconnectinterfaces
Qt5::Core
Qt5::DBus
KF5::KDELibs4Support
-
- ${QJSON_LIBRARIES}
)
configure_file(KDEConnectConfig.cmake.in ${CMAKE_BINARY_DIR}/interfaces/KDEConnectConfig.cmake @ONLY)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 70c1ce0..8a63153 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,5 +1,4 @@
include_directories(
- ${QJSON_INCLUDE_DIR}
${QCA2_INCLUDE_DIR}
${KDEConnectCore_BINARY_DIR}
${CMAKE_SOURCE_DIR}
@@ -8,7 +7,6 @@ include_directories(
set(kdeconnect_libraries
KF5::KIOWidgets
Qt5::Network
- ${QJSON_LIBRARIES}
${QCA2_LIBRARIES}
Qt5::Test
kdeconnectcore
diff --git a/tests/networkpackagetests.cpp b/tests/networkpackagetests.cpp
index 35e14bf..d213975 100644
--- a/tests/networkpackagetests.cpp
+++ b/tests/networkpackagetests.cpp
@@ -66,7 +66,7 @@ void NetworkPackageTests::networkPackageTest()
QCOMPARE( np.type(), np2.type() );
QCOMPARE( np.body(), np2.body() );
- QByteArray json("{ \"id\": \"123\", \"type\": \"test\", \"body\": { \"testing\": true } }");
+ QByteArray json("{\"id\":\"123\",\"type\":\"test\",\"body\":{\"testing\":true}}");
//qDebug() << json;
NetworkPackage::unserialize(json,&np2);
QCOMPARE( np2.id(), QString("123") );
@@ -129,7 +129,7 @@ void NetworkPackageTests::networkPackageEncryptionTest()
//Test for long package encryption that need multi-chunk encryption
- QByteArray json = "{ \"body\" : { \"nowPlaying\" : \"A really long song name - A really long artist name\", \"player\" : \"A really long player name\", \"the_meaning_of_life_the_universe_and_everything\" : \"42\" }, \"id\" : \"A really long package id\", \"type\" : \"kdeconnect.a_really_really_long_package_type\" }
";
+ QByteArray json = "{\"body\":{\"nowPlaying\":\"A really long song name - A really long artist name\",\"player\":\"A really long player name\",\"the_meaning_of_life_the_universe_and_everything\":\"42\"},\"id\":\"A really long package id\",\"type\":\"kdeconnect.a_really_really_long_package_type\"}
";
qDebug() << "EME_PKCS1_OAEP maximumEncryptSize" << publicKey.maximumEncryptSize(QCA::EME_PKCS1_OAEP);
qDebug() << "EME_PKCS1v15 maximumEncryptSize" << publicKey.maximumEncryptSize(QCA::EME_PKCS1v15);
QCOMPARE( json.size() > publicKey.maximumEncryptSize(NetworkPackage::EncryptionAlgorithm), true );
--
kdeconnect packaging
More information about the pkg-kde-commits
mailing list