From ffb04781f8bddccfc987906672e40fe659a7d695 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Fri, 18 Apr 2014 14:11:24 +0100 Subject: [PATCH] Move JSON Qt4/5 wrapper into its own header --- .../hatchet/account/HatchetAccount.cpp | 1 + src/accounts/hatchet/sip/HatchetSip.cpp | 1 + .../generic/charts/ChartsPlugin.cpp | 2 +- .../generic/discogs/DiscogsPlugin.cpp | 2 +- src/infoplugins/generic/hypem/HypemPlugin.cpp | 1 + .../generic/newreleases/NewReleasesPlugin.cpp | 1 + src/infoplugins/generic/rovi/RoviPlugin.cpp | 1 + .../generic/spotify/SpotifyPlugin.cpp | 1 + src/libtomahawk-playdarapi/Api_v1.cpp | 1 + src/libtomahawk-playdarapi/Api_v1_5.cpp | 1 + src/libtomahawk/CMakeLists.txt | 3 +- src/libtomahawk/SourceList.cpp | 2 +- src/libtomahawk/TomahawkSettings.cpp | 1 + .../accounts/CredentialsManager.cpp | 2 +- src/libtomahawk/accounts/ResolverAccount.cpp | 1 + .../accounts/spotify/SpotifyInfoPlugin.cpp | 1 + src/libtomahawk/database/Database.cpp | 1 + .../DatabaseCommand_CreateDynamicPlaylist.cpp | 1 + .../DatabaseCommand_CreatePlaylist.cpp | 1 + .../DatabaseCommand_LoadAllPlaylists.cpp | 2 + ...baseCommand_LoadDynamicPlaylistEntries.cpp | 1 + .../DatabaseCommand_LoadPlaylistEntries.cpp | 1 + ...baseCommand_SetDynamicPlaylistRevision.cpp | 1 + .../DatabaseCommand_SetPlaylistRevision.cpp | 1 + src/libtomahawk/database/DatabaseWorker.cpp | 1 + src/libtomahawk/network/Connection.cpp | 1 + src/libtomahawk/network/Msg.cpp | 2 +- src/libtomahawk/network/MsgProcessor.cpp | 1 + src/libtomahawk/network/Servent.cpp | 1 + .../playlist/dynamic/DynamicPlaylist.cpp | 1 + src/libtomahawk/resolvers/ScriptResolver.cpp | 1 + src/libtomahawk/sip/SipInfo.cpp | 2 +- src/libtomahawk/utils/GroovesharkParser.cpp | 1 + src/libtomahawk/utils/ItunesParser.cpp | 12 +- src/libtomahawk/utils/Json.cpp | 116 ++++++++++++++++++ src/libtomahawk/utils/Json.h | 36 ++++++ src/libtomahawk/utils/JspfLoader.cpp | 1 + src/libtomahawk/utils/ShortLinkHelper.cpp | 1 + src/libtomahawk/utils/SpotifyParser.cpp | 18 +-- src/libtomahawk/utils/TomahawkUtils.cpp | 87 ------------- src/libtomahawk/utils/TomahawkUtils.h | 6 - 41 files changed, 206 insertions(+), 113 deletions(-) create mode 100644 src/libtomahawk/utils/Json.cpp create mode 100644 src/libtomahawk/utils/Json.h diff --git a/src/accounts/hatchet/account/HatchetAccount.cpp b/src/accounts/hatchet/account/HatchetAccount.cpp index 74558c0ee..2d2198d0b 100644 --- a/src/accounts/hatchet/account/HatchetAccount.cpp +++ b/src/accounts/hatchet/account/HatchetAccount.cpp @@ -24,6 +24,7 @@ #include "utils/Closure.h" #include "utils/Logger.h" #include "utils/NetworkAccessManager.h" +#include "utils/Json.h" #include "utils/TomahawkUtils.h" #include diff --git a/src/accounts/hatchet/sip/HatchetSip.cpp b/src/accounts/hatchet/sip/HatchetSip.cpp index 7c4c947e4..b92cf6fb9 100644 --- a/src/accounts/hatchet/sip/HatchetSip.cpp +++ b/src/accounts/hatchet/sip/HatchetSip.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include diff --git a/src/infoplugins/generic/charts/ChartsPlugin.cpp b/src/infoplugins/generic/charts/ChartsPlugin.cpp index d687fbdf7..d03df7144 100644 --- a/src/infoplugins/generic/charts/ChartsPlugin.cpp +++ b/src/infoplugins/generic/charts/ChartsPlugin.cpp @@ -26,7 +26,7 @@ #include "Typedefs.h" #include "audio/AudioEngine.h" #include "TomahawkSettings.h" -#include "utils/TomahawkUtils.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "utils/TomahawkCache.h" #include "utils/NetworkAccessManager.h" diff --git a/src/infoplugins/generic/discogs/DiscogsPlugin.cpp b/src/infoplugins/generic/discogs/DiscogsPlugin.cpp index 0401f7766..deacab244 100644 --- a/src/infoplugins/generic/discogs/DiscogsPlugin.cpp +++ b/src/infoplugins/generic/discogs/DiscogsPlugin.cpp @@ -19,7 +19,7 @@ #include "DiscogsPlugin.h" -#include "utils/TomahawkUtils.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "utils/Closure.h" #include "utils/NetworkAccessManager.h" diff --git a/src/infoplugins/generic/hypem/HypemPlugin.cpp b/src/infoplugins/generic/hypem/HypemPlugin.cpp index 33481eada..a0538cebe 100644 --- a/src/infoplugins/generic/hypem/HypemPlugin.cpp +++ b/src/infoplugins/generic/hypem/HypemPlugin.cpp @@ -30,6 +30,7 @@ #include "TomahawkSettings.h" #include "utils/TomahawkUtils.h" #include "infosystem/InfoSystemWorker.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "utils/NetworkAccessManager.h" #include "Source.h" diff --git a/src/infoplugins/generic/newreleases/NewReleasesPlugin.cpp b/src/infoplugins/generic/newreleases/NewReleasesPlugin.cpp index ae383f0f9..47b15f568 100644 --- a/src/infoplugins/generic/newreleases/NewReleasesPlugin.cpp +++ b/src/infoplugins/generic/newreleases/NewReleasesPlugin.cpp @@ -26,6 +26,7 @@ #include "Typedefs.h" #include "audio/AudioEngine.h" #include "TomahawkSettings.h" +#include "utils/Json.h" #include "utils/TomahawkUtils.h" #include "utils/Logger.h" #include "utils/TomahawkCache.h" diff --git a/src/infoplugins/generic/rovi/RoviPlugin.cpp b/src/infoplugins/generic/rovi/RoviPlugin.cpp index df131058d..87f91bcda 100644 --- a/src/infoplugins/generic/rovi/RoviPlugin.cpp +++ b/src/infoplugins/generic/rovi/RoviPlugin.cpp @@ -19,6 +19,7 @@ #include "RoviPlugin.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "utils/NetworkAccessManager.h" diff --git a/src/infoplugins/generic/spotify/SpotifyPlugin.cpp b/src/infoplugins/generic/spotify/SpotifyPlugin.cpp index 16efcd5a4..3cc0aa879 100644 --- a/src/infoplugins/generic/spotify/SpotifyPlugin.cpp +++ b/src/infoplugins/generic/spotify/SpotifyPlugin.cpp @@ -29,6 +29,7 @@ #include "Typedefs.h" #include "audio/AudioEngine.h" #include "TomahawkSettings.h" +#include "utils/Json.h" #include "utils/TomahawkUtils.h" #include "utils/Logger.h" #include "utils/NetworkAccessManager.h" diff --git a/src/libtomahawk-playdarapi/Api_v1.cpp b/src/libtomahawk-playdarapi/Api_v1.cpp index 8ae81691b..a9f598625 100644 --- a/src/libtomahawk-playdarapi/Api_v1.cpp +++ b/src/libtomahawk-playdarapi/Api_v1.cpp @@ -25,6 +25,7 @@ #include "database/DatabaseCommand_AddClientAuth.h" #include "database/DatabaseCommand_ClientAuthValid.h" #include "network/Servent.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "utils/TomahawkUtils.h" diff --git a/src/libtomahawk-playdarapi/Api_v1_5.cpp b/src/libtomahawk-playdarapi/Api_v1_5.cpp index e73ad4813..ec55661b2 100644 --- a/src/libtomahawk-playdarapi/Api_v1_5.cpp +++ b/src/libtomahawk-playdarapi/Api_v1_5.cpp @@ -24,6 +24,7 @@ #include "audio/AudioEngine.h" #include "resolvers/Resolver.h" +#include "utils/Json.h" #include "utils/Logger.h" // Assumptions: QxtWebRequestEvent instance is called event and result is true on success diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index f0b90fbae..1dd3a31fb 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -345,7 +345,7 @@ list(APPEND libSources playlist/dynamic/database/DatabaseGenerator.cpp playlist/dynamic/database/DatabaseControl.cpp playlist/dynamic/DynamicControl.cpp - + resolvers/ExternalResolver.cpp resolvers/Resolver.cpp resolvers/ScriptCollection.cpp @@ -360,6 +360,7 @@ list(APPEND libSources sip/PeerInfo.cpp sip/SipStatusMessage.cpp + utils/Json.cpp utils/TomahawkUtils.cpp utils/Logger.cpp utils/Qnr_IoDeviceStream.cpp diff --git a/src/libtomahawk/SourceList.cpp b/src/libtomahawk/SourceList.cpp index 1eecf1895..19109df8e 100644 --- a/src/libtomahawk/SourceList.cpp +++ b/src/libtomahawk/SourceList.cpp @@ -27,7 +27,7 @@ #include "infosystem/InfoSystemCache.h" #include "resolvers/ExternalResolver.h" #include "resolvers/ScriptCollection.h" - +#include "utils/Json.h" #include "utils/Logger.h" using namespace Tomahawk; diff --git a/src/libtomahawk/TomahawkSettings.cpp b/src/libtomahawk/TomahawkSettings.cpp index b3b0a7a6d..e4b653c77 100644 --- a/src/libtomahawk/TomahawkSettings.cpp +++ b/src/libtomahawk/TomahawkSettings.cpp @@ -26,6 +26,7 @@ #include "infosystem/InfoSystemCache.h" #include "playlist/PlaylistUpdaterInterface.h" #include "utils/Logger.h" +#include "utils/Json.h" #include "utils/TomahawkUtils.h" #include "PlaylistEntry.h" diff --git a/src/libtomahawk/accounts/CredentialsManager.cpp b/src/libtomahawk/accounts/CredentialsManager.cpp index 57b7c20ff..af6f02878 100644 --- a/src/libtomahawk/accounts/CredentialsManager.cpp +++ b/src/libtomahawk/accounts/CredentialsManager.cpp @@ -28,7 +28,7 @@ #else #include #endif - #include "utils/TomahawkUtils.h" + #include "utils/Json.h" #endif #include diff --git a/src/libtomahawk/accounts/ResolverAccount.cpp b/src/libtomahawk/accounts/ResolverAccount.cpp index 5e0e2bf5c..b7a614158 100644 --- a/src/libtomahawk/accounts/ResolverAccount.cpp +++ b/src/libtomahawk/accounts/ResolverAccount.cpp @@ -27,6 +27,7 @@ #include "ConfigStorage.h" #include "resolvers/ExternalResolver.h" #include "resolvers/ExternalResolverGui.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "Album.h" diff --git a/src/libtomahawk/accounts/spotify/SpotifyInfoPlugin.cpp b/src/libtomahawk/accounts/spotify/SpotifyInfoPlugin.cpp index f16972140..47dcf013f 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyInfoPlugin.cpp +++ b/src/libtomahawk/accounts/spotify/SpotifyInfoPlugin.cpp @@ -20,6 +20,7 @@ #include "SpotifyAccount.h" #include "utils/Closure.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "utils/NetworkAccessManager.h" diff --git a/src/libtomahawk/database/Database.cpp b/src/libtomahawk/database/Database.cpp index 41b824029..e792ee86c 100644 --- a/src/libtomahawk/database/Database.cpp +++ b/src/libtomahawk/database/Database.cpp @@ -19,6 +19,7 @@ #include "Database.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "DatabaseCommand.h" diff --git a/src/libtomahawk/database/DatabaseCommand_CreateDynamicPlaylist.cpp b/src/libtomahawk/database/DatabaseCommand_CreateDynamicPlaylist.cpp index b2d3f659b..ac374e4be 100644 --- a/src/libtomahawk/database/DatabaseCommand_CreateDynamicPlaylist.cpp +++ b/src/libtomahawk/database/DatabaseCommand_CreateDynamicPlaylist.cpp @@ -22,6 +22,7 @@ #include "playlist/dynamic/DynamicControl.h" #include "playlist/dynamic/GeneratorInterface.h" #include "network/Servent.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "DatabaseImpl.h" diff --git a/src/libtomahawk/database/DatabaseCommand_CreatePlaylist.cpp b/src/libtomahawk/database/DatabaseCommand_CreatePlaylist.cpp index ddcacc366..b17faed22 100644 --- a/src/libtomahawk/database/DatabaseCommand_CreatePlaylist.cpp +++ b/src/libtomahawk/database/DatabaseCommand_CreatePlaylist.cpp @@ -19,6 +19,7 @@ #include "DatabaseCommand_CreatePlaylist.h" #include "network/Servent.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "DatabaseImpl.h" diff --git a/src/libtomahawk/database/DatabaseCommand_LoadAllPlaylists.cpp b/src/libtomahawk/database/DatabaseCommand_LoadAllPlaylists.cpp index 5a980fa16..95838de66 100644 --- a/src/libtomahawk/database/DatabaseCommand_LoadAllPlaylists.cpp +++ b/src/libtomahawk/database/DatabaseCommand_LoadAllPlaylists.cpp @@ -19,6 +19,8 @@ #include "DatabaseCommand_LoadAllPlaylists_p.h" +#include "utils/Json.h" + #include "DatabaseImpl.h" #include "Playlist.h" #include "PlaylistEntry.h" diff --git a/src/libtomahawk/database/DatabaseCommand_LoadDynamicPlaylistEntries.cpp b/src/libtomahawk/database/DatabaseCommand_LoadDynamicPlaylistEntries.cpp index 48b03e121..e5862f7d9 100644 --- a/src/libtomahawk/database/DatabaseCommand_LoadDynamicPlaylistEntries.cpp +++ b/src/libtomahawk/database/DatabaseCommand_LoadDynamicPlaylistEntries.cpp @@ -21,6 +21,7 @@ #include "playlist/dynamic/DynamicControl.h" #include "playlist/dynamic/GeneratorInterface.h" #include "playlist/dynamic/GeneratorFactory.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "DatabaseImpl.h" diff --git a/src/libtomahawk/database/DatabaseCommand_LoadPlaylistEntries.cpp b/src/libtomahawk/database/DatabaseCommand_LoadPlaylistEntries.cpp index 8acfa727f..01606b7af 100644 --- a/src/libtomahawk/database/DatabaseCommand_LoadPlaylistEntries.cpp +++ b/src/libtomahawk/database/DatabaseCommand_LoadPlaylistEntries.cpp @@ -18,6 +18,7 @@ #include "DatabaseCommand_LoadPlaylistEntries.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "DatabaseImpl.h" diff --git a/src/libtomahawk/database/DatabaseCommand_SetDynamicPlaylistRevision.cpp b/src/libtomahawk/database/DatabaseCommand_SetDynamicPlaylistRevision.cpp index 2ba4f2307..30700da35 100644 --- a/src/libtomahawk/database/DatabaseCommand_SetDynamicPlaylistRevision.cpp +++ b/src/libtomahawk/database/DatabaseCommand_SetDynamicPlaylistRevision.cpp @@ -22,6 +22,7 @@ #include "playlist/dynamic/DynamicPlaylist.h" #include "playlist/dynamic/DynamicControl.h" #include "network/Servent.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "DatabaseImpl.h" diff --git a/src/libtomahawk/database/DatabaseCommand_SetPlaylistRevision.cpp b/src/libtomahawk/database/DatabaseCommand_SetPlaylistRevision.cpp index 8926d86c6..055118ae2 100644 --- a/src/libtomahawk/database/DatabaseCommand_SetPlaylistRevision.cpp +++ b/src/libtomahawk/database/DatabaseCommand_SetPlaylistRevision.cpp @@ -20,6 +20,7 @@ #include "collection/Collection.h" #include "network/Servent.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "DatabaseImpl.h" diff --git a/src/libtomahawk/database/DatabaseWorker.cpp b/src/libtomahawk/database/DatabaseWorker.cpp index c025b48e9..78538cacc 100644 --- a/src/libtomahawk/database/DatabaseWorker.cpp +++ b/src/libtomahawk/database/DatabaseWorker.cpp @@ -19,6 +19,7 @@ #include "DatabaseWorker.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "Database.h" diff --git a/src/libtomahawk/network/Connection.cpp b/src/libtomahawk/network/Connection.cpp index 4da79518d..c234b490d 100644 --- a/src/libtomahawk/network/Connection.cpp +++ b/src/libtomahawk/network/Connection.cpp @@ -25,6 +25,7 @@ #include "network/Servent.h" #include "network/Msg.h" #include "utils/Logger.h" +#include "utils/Json.h" #include "utils/TomahawkUtils.h" #include "QTcpSocketExtra.h" diff --git a/src/libtomahawk/network/Msg.cpp b/src/libtomahawk/network/Msg.cpp index 593267455..bd3b413d4 100644 --- a/src/libtomahawk/network/Msg.cpp +++ b/src/libtomahawk/network/Msg.cpp @@ -19,7 +19,7 @@ #include "Msg_p.h" -#include "utils/TomahawkUtils.h" +#include "utils/Json.h" #include diff --git a/src/libtomahawk/network/MsgProcessor.cpp b/src/libtomahawk/network/MsgProcessor.cpp index ab568a494..d0244c4bd 100644 --- a/src/libtomahawk/network/MsgProcessor.cpp +++ b/src/libtomahawk/network/MsgProcessor.cpp @@ -20,6 +20,7 @@ #include "network/Msg_p.h" #include "network/Servent.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "utils/TomahawkUtils.h" diff --git a/src/libtomahawk/network/Servent.cpp b/src/libtomahawk/network/Servent.cpp index 55617d646..754c2a6c5 100644 --- a/src/libtomahawk/network/Servent.cpp +++ b/src/libtomahawk/network/Servent.cpp @@ -32,6 +32,7 @@ #include "sip/PeerInfo.h" #include "sip/SipPlugin.h" #include "utils/Closure.h" +#include "utils/Json.h" #include "utils/TomahawkUtils.h" #include "utils/Logger.h" #include "utils/NetworkAccessManager.h" diff --git a/src/libtomahawk/playlist/dynamic/DynamicPlaylist.cpp b/src/libtomahawk/playlist/dynamic/DynamicPlaylist.cpp index d40c6c3c5..03a6a0c02 100644 --- a/src/libtomahawk/playlist/dynamic/DynamicPlaylist.cpp +++ b/src/libtomahawk/playlist/dynamic/DynamicPlaylist.cpp @@ -26,6 +26,7 @@ #include "database/DatabaseCommand_SetDynamicPlaylistRevision.h" #include "database/DatabaseCommand_LoadDynamicPlaylistEntries.h" #include "database/DatabaseCommand_DeleteDynamicPlaylist.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "GeneratorFactory.h" diff --git a/src/libtomahawk/resolvers/ScriptResolver.cpp b/src/libtomahawk/resolvers/ScriptResolver.cpp index 8e1875f61..572348d93 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.cpp +++ b/src/libtomahawk/resolvers/ScriptResolver.cpp @@ -22,6 +22,7 @@ #include "accounts/AccountConfigWidget.h" #include "utils/TomahawkUtilsGui.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "utils/NetworkAccessManager.h" #include "utils/NetworkProxyFactory.h" diff --git a/src/libtomahawk/sip/SipInfo.cpp b/src/libtomahawk/sip/SipInfo.cpp index b32fa013f..894c69a19 100644 --- a/src/libtomahawk/sip/SipInfo.cpp +++ b/src/libtomahawk/sip/SipInfo.cpp @@ -20,7 +20,7 @@ #include "SipInfo.h" #include "utils/Logger.h" -#include "utils/TomahawkUtils.h" +#include "utils/Json.h" #include diff --git a/src/libtomahawk/utils/GroovesharkParser.cpp b/src/libtomahawk/utils/GroovesharkParser.cpp index 666f8a378..6a44ae9c3 100644 --- a/src/libtomahawk/utils/GroovesharkParser.cpp +++ b/src/libtomahawk/utils/GroovesharkParser.cpp @@ -37,6 +37,7 @@ #include "jobview/JobStatusView.h" #include "jobview/JobStatusModel.h" #include "jobview/ErrorStatusMessage.h" +#include "utils/Json.h" #include "utils/NetworkReply.h" #include "utils/TomahawkUtils.h" #include "utils/Logger.h" diff --git a/src/libtomahawk/utils/ItunesParser.cpp b/src/libtomahawk/utils/ItunesParser.cpp index 117d6d3c8..3bfb33d84 100644 --- a/src/libtomahawk/utils/ItunesParser.cpp +++ b/src/libtomahawk/utils/ItunesParser.cpp @@ -20,19 +20,21 @@ #include "ItunesParser.h" -#include -#include - -#include "Query.h" -#include "SourceList.h" #include "jobview/JobStatusView.h" #include "jobview/JobStatusModel.h" #include "jobview/ErrorStatusMessage.h" +#include "utils/Json.h" #include "utils/NetworkReply.h" #include "utils/TomahawkUtils.h" #include "utils/Logger.h" #include "utils/NetworkAccessManager.h" +#include "Query.h" +#include "SourceList.h" + +#include +#include + // Forward Declarations breaking QSharedPointer #if QT_VERSION < QT_VERSION_CHECK( 5, 0, 0 ) #include "Playlist.h" diff --git a/src/libtomahawk/utils/Json.cpp b/src/libtomahawk/utils/Json.cpp new file mode 100644 index 000000000..34d81e304 --- /dev/null +++ b/src/libtomahawk/utils/Json.cpp @@ -0,0 +1,116 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2014, Uwe L. Korn + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "Json.h" + +// Qt version specific includes +#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) + #include + #include + #include +#else + #include + #include + #include +#endif + +namespace TomahawkUtils +{ + +QVariantMap +qobject2qvariant( const QObject* object ) +{ +#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) + const QMetaObject* metaObject = object->metaObject(); + QVariantMap map; + for ( int i = 0; i < metaObject->propertyCount(); ++i ) + { + QMetaProperty metaproperty = metaObject->property( i ); + if ( metaproperty.isReadable() ) + { + map[ QLatin1String( metaproperty.name() ) ] = object->property( metaproperty.name() ); + } + } + return map; +#else + return QJson::QObjectHelper::qobject2qvariant( object ); +#endif +} + + +void +qvariant2qobject( const QVariantMap& variant, QObject* object ) +{ +#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) + 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 ); + } + } + } +#else + QJson::QObjectHelper::qvariant2qobject( variant, object ); +#endif +} + + +QVariant +parseJson( const QByteArray& jsonData, bool* ok ) +{ +#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) + QJsonParseError error; + QJsonDocument doc = QJsonDocument::fromJson( jsonData, &error ); + if ( ok != NULL ) + { + *ok = ( error.error == QJsonParseError::NoError ); + } + return doc.toVariant(); +#else + QJson::Parser p; + return p.parse( jsonData, ok ); +#endif +} + + +QByteArray +toJson( const QVariant &variant, bool* ok ) +{ +#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) + QJsonDocument doc = QJsonDocument::fromVariant( variant ); + if ( ok != NULL ) + { + *ok = true; + } + return doc.toJson(); +#else + QJson::Serializer serializer; + return serializer.serialize( variant, ok ); +#endif +} + +} diff --git a/src/libtomahawk/utils/Json.h b/src/libtomahawk/utils/Json.h new file mode 100644 index 000000000..6aa8bfd13 --- /dev/null +++ b/src/libtomahawk/utils/Json.h @@ -0,0 +1,36 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2014, Uwe L. Korn + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#pragma once +#ifndef TOMAHAWKUTILS_JSON_H +#define TOMAHAWKUTILS_JSON_H + +#include "DllMacro.h" + +#include + +namespace TomahawkUtils +{ + /* QJson */ + DLLEXPORT QVariantMap qobject2qvariant( const QObject* object ); + DLLEXPORT void qvariant2qobject( const QVariantMap& variant, QObject* object ); + DLLEXPORT QVariant parseJson( const QByteArray& jsonData, bool* ok = 0 ); + DLLEXPORT QByteArray toJson( const QVariant &variant, bool* ok = 0 ); +} + +#endif // TOMAHAWKUTILS_JSON_H diff --git a/src/libtomahawk/utils/JspfLoader.cpp b/src/libtomahawk/utils/JspfLoader.cpp index 648b58178..1ccc1c13b 100644 --- a/src/libtomahawk/utils/JspfLoader.cpp +++ b/src/libtomahawk/utils/JspfLoader.cpp @@ -19,6 +19,7 @@ #include "JspfLoader.h" +#include "utils/Json.h" #include "utils/Logger.h" #include "utils/NetworkReply.h" #include "utils/TomahawkUtils.h" diff --git a/src/libtomahawk/utils/ShortLinkHelper.cpp b/src/libtomahawk/utils/ShortLinkHelper.cpp index fc1958fc3..19e72b479 100644 --- a/src/libtomahawk/utils/ShortLinkHelper.cpp +++ b/src/libtomahawk/utils/ShortLinkHelper.cpp @@ -22,6 +22,7 @@ #include "ShortLinkHelper_p.h" #include "utils/Closure.h" +#include "utils/Json.h" #include "utils/NetworkAccessManager.h" #include "utils/TomahawkUtils.h" #include "Playlist.h" diff --git a/src/libtomahawk/utils/SpotifyParser.cpp b/src/libtomahawk/utils/SpotifyParser.cpp index 703a95dc9..95fec4f0f 100644 --- a/src/libtomahawk/utils/SpotifyParser.cpp +++ b/src/libtomahawk/utils/SpotifyParser.cpp @@ -19,20 +19,22 @@ #include "SpotifyParser.h" -#include +#include "jobview/JobStatusView.h" +#include "jobview/JobStatusModel.h" +#include "jobview/ErrorStatusMessage.h" +#include "utils/Json.h" +#include "utils/NetworkReply.h" +#include "utils/TomahawkUtils.h" +#include "utils/Logger.h" +#include "utils/NetworkAccessManager.h" #include "Query.h" #include "SourceList.h" #include "DropJob.h" #include "DropJobNotifier.h" #include "ViewManager.h" -#include "jobview/JobStatusView.h" -#include "jobview/JobStatusModel.h" -#include "jobview/ErrorStatusMessage.h" -#include "utils/NetworkReply.h" -#include "utils/TomahawkUtils.h" -#include "utils/Logger.h" -#include "utils/NetworkAccessManager.h" + +#include using namespace Tomahawk; diff --git a/src/libtomahawk/utils/TomahawkUtils.cpp b/src/libtomahawk/utils/TomahawkUtils.cpp index 4bf619f06..69cbd0c5e 100644 --- a/src/libtomahawk/utils/TomahawkUtils.cpp +++ b/src/libtomahawk/utils/TomahawkUtils.cpp @@ -57,11 +57,6 @@ // Qt version specific includes #if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) #include - #include -#else - #include - #include - #include #endif #ifdef Q_OS_WIN @@ -848,88 +843,6 @@ compareVersionStrings( const QString& first, const QString& second ) } -QVariantMap -qobject2qvariant( const QObject* object ) -{ -#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) - const QMetaObject* metaObject = object->metaObject(); - QVariantMap map; - for ( int i = 0; i < metaObject->propertyCount(); ++i ) - { - QMetaProperty metaproperty = metaObject->property( i ); - if ( metaproperty.isReadable() ) - { - map[ QLatin1String( metaproperty.name() ) ] = object->property( metaproperty.name() ); - } - } - return map; -#else - return QJson::QObjectHelper::qobject2qvariant( object ); -#endif -} - - -void -qvariant2qobject( const QVariantMap& variant, QObject* object ) -{ -#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) - for ( QVariantMap::const_iterator iter = variant.begin(); iter != variant.end(); ++iter ) - { - QVariant property = object->property( iter.key().toLatin1() ); - QVariant value = iter.value(); - Q_ASSERT( property.isValid() ); - if ( property.isValid() ) - { - 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 ); - } - } - } -#else - QJson::QObjectHelper::qvariant2qobject( variant, object ); -#endif -} - - -QVariant -parseJson( const QByteArray& jsonData, bool* ok ) -{ -#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) - QJsonParseError error; - QJsonDocument doc = QJsonDocument::fromJson( jsonData, &error ); - if ( ok != NULL ) - { - *ok = ( error.error == QJsonParseError::NoError ); - } - return doc.toVariant(); -#else - QJson::Parser p; - return p.parse( jsonData, ok ); -#endif -} - - -QByteArray -toJson( const QVariant &variant, bool* ok ) -{ -#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) - QJsonDocument doc = QJsonDocument::fromVariant( variant ); - if ( ok != NULL ) - { - *ok = true; - } - return doc.toJson(); -#else - QJson::Serializer serializer; - return serializer.serialize( variant, ok ); -#endif -} - - void urlAddQueryItem( QUrl& url, const QString& key, const QString& value ) { diff --git a/src/libtomahawk/utils/TomahawkUtils.h b/src/libtomahawk/utils/TomahawkUtils.h index 3f33f7804..03cdfed68 100644 --- a/src/libtomahawk/utils/TomahawkUtils.h +++ b/src/libtomahawk/utils/TomahawkUtils.h @@ -207,12 +207,6 @@ namespace TomahawkUtils * Qt4 / Qt5 compatibility layer */ - /* QJson */ - DLLEXPORT QVariantMap qobject2qvariant( const QObject* object ); - DLLEXPORT void qvariant2qobject( const QVariantMap& variant, QObject* object ); - DLLEXPORT QVariant parseJson( const QByteArray& jsonData, bool* ok = 0 ); - DLLEXPORT QByteArray toJson( const QVariant &variant, bool* ok = 0 ); - /* QUrl */ DLLEXPORT void urlAddQueryItem( QUrl& url, const QString& key, const QString& value ); DLLEXPORT QString urlQueryItemValue( const QUrl& url, const QString& key );