mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-17 19:37:09 +02:00
Move JSON Qt4/5 wrapper into its own header
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
#include "utils/Closure.h"
|
#include "utils/Closure.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/NetworkAccessManager.h"
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
|
|
||||||
#include <QtPlugin>
|
#include <QtPlugin>
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
#include <network/Servent.h>
|
#include <network/Servent.h>
|
||||||
#include <sip/SipInfo.h>
|
#include <sip/SipInfo.h>
|
||||||
#include <sip/PeerInfo.h>
|
#include <sip/PeerInfo.h>
|
||||||
|
#include <utils/Json.h>
|
||||||
#include <utils/Logger.h>
|
#include <utils/Logger.h>
|
||||||
#include <SourceList.h>
|
#include <SourceList.h>
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@
|
|||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
#include "audio/AudioEngine.h"
|
#include "audio/AudioEngine.h"
|
||||||
#include "TomahawkSettings.h"
|
#include "TomahawkSettings.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/TomahawkCache.h"
|
#include "utils/TomahawkCache.h"
|
||||||
#include "utils/NetworkAccessManager.h"
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
#include "DiscogsPlugin.h"
|
#include "DiscogsPlugin.h"
|
||||||
|
|
||||||
|
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Closure.h"
|
#include "utils/Closure.h"
|
||||||
#include "utils/NetworkAccessManager.h"
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include "TomahawkSettings.h"
|
#include "TomahawkSettings.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "infosystem/InfoSystemWorker.h"
|
#include "infosystem/InfoSystemWorker.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/NetworkAccessManager.h"
|
#include "utils/NetworkAccessManager.h"
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
#include "audio/AudioEngine.h"
|
#include "audio/AudioEngine.h"
|
||||||
#include "TomahawkSettings.h"
|
#include "TomahawkSettings.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/TomahawkCache.h"
|
#include "utils/TomahawkCache.h"
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "RoviPlugin.h"
|
#include "RoviPlugin.h"
|
||||||
|
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/NetworkAccessManager.h"
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
#include "audio/AudioEngine.h"
|
#include "audio/AudioEngine.h"
|
||||||
#include "TomahawkSettings.h"
|
#include "TomahawkSettings.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/NetworkAccessManager.h"
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
#include "database/DatabaseCommand_AddClientAuth.h"
|
#include "database/DatabaseCommand_AddClientAuth.h"
|
||||||
#include "database/DatabaseCommand_ClientAuthValid.h"
|
#include "database/DatabaseCommand_ClientAuthValid.h"
|
||||||
#include "network/Servent.h"
|
#include "network/Servent.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
|
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include "audio/AudioEngine.h"
|
#include "audio/AudioEngine.h"
|
||||||
#include "resolvers/Resolver.h"
|
#include "resolvers/Resolver.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
// Assumptions: QxtWebRequestEvent instance is called event and result is true on success
|
// Assumptions: QxtWebRequestEvent instance is called event and result is true on success
|
||||||
|
@@ -345,7 +345,7 @@ list(APPEND libSources
|
|||||||
playlist/dynamic/database/DatabaseGenerator.cpp
|
playlist/dynamic/database/DatabaseGenerator.cpp
|
||||||
playlist/dynamic/database/DatabaseControl.cpp
|
playlist/dynamic/database/DatabaseControl.cpp
|
||||||
playlist/dynamic/DynamicControl.cpp
|
playlist/dynamic/DynamicControl.cpp
|
||||||
|
|
||||||
resolvers/ExternalResolver.cpp
|
resolvers/ExternalResolver.cpp
|
||||||
resolvers/Resolver.cpp
|
resolvers/Resolver.cpp
|
||||||
resolvers/ScriptCollection.cpp
|
resolvers/ScriptCollection.cpp
|
||||||
@@ -360,6 +360,7 @@ list(APPEND libSources
|
|||||||
sip/PeerInfo.cpp
|
sip/PeerInfo.cpp
|
||||||
sip/SipStatusMessage.cpp
|
sip/SipStatusMessage.cpp
|
||||||
|
|
||||||
|
utils/Json.cpp
|
||||||
utils/TomahawkUtils.cpp
|
utils/TomahawkUtils.cpp
|
||||||
utils/Logger.cpp
|
utils/Logger.cpp
|
||||||
utils/Qnr_IoDeviceStream.cpp
|
utils/Qnr_IoDeviceStream.cpp
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
#include "infosystem/InfoSystemCache.h"
|
#include "infosystem/InfoSystemCache.h"
|
||||||
#include "resolvers/ExternalResolver.h"
|
#include "resolvers/ExternalResolver.h"
|
||||||
#include "resolvers/ScriptCollection.h"
|
#include "resolvers/ScriptCollection.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include "infosystem/InfoSystemCache.h"
|
#include "infosystem/InfoSystemCache.h"
|
||||||
#include "playlist/PlaylistUpdaterInterface.h"
|
#include "playlist/PlaylistUpdaterInterface.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
|
|
||||||
#include "PlaylistEntry.h"
|
#include "PlaylistEntry.h"
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
#else
|
#else
|
||||||
#include <qt5keychain/keychain.h>
|
#include <qt5keychain/keychain.h>
|
||||||
#endif
|
#endif
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/Json.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#include "ConfigStorage.h"
|
#include "ConfigStorage.h"
|
||||||
#include "resolvers/ExternalResolver.h"
|
#include "resolvers/ExternalResolver.h"
|
||||||
#include "resolvers/ExternalResolverGui.h"
|
#include "resolvers/ExternalResolverGui.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include "Album.h"
|
#include "Album.h"
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "SpotifyAccount.h"
|
#include "SpotifyAccount.h"
|
||||||
#include "utils/Closure.h"
|
#include "utils/Closure.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/NetworkAccessManager.h"
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "Database.h"
|
#include "Database.h"
|
||||||
|
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include "DatabaseCommand.h"
|
#include "DatabaseCommand.h"
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include "playlist/dynamic/DynamicControl.h"
|
#include "playlist/dynamic/DynamicControl.h"
|
||||||
#include "playlist/dynamic/GeneratorInterface.h"
|
#include "playlist/dynamic/GeneratorInterface.h"
|
||||||
#include "network/Servent.h"
|
#include "network/Servent.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include "DatabaseImpl.h"
|
#include "DatabaseImpl.h"
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
#include "DatabaseCommand_CreatePlaylist.h"
|
#include "DatabaseCommand_CreatePlaylist.h"
|
||||||
|
|
||||||
#include "network/Servent.h"
|
#include "network/Servent.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include "DatabaseImpl.h"
|
#include "DatabaseImpl.h"
|
||||||
|
@@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include "DatabaseCommand_LoadAllPlaylists_p.h"
|
#include "DatabaseCommand_LoadAllPlaylists_p.h"
|
||||||
|
|
||||||
|
#include "utils/Json.h"
|
||||||
|
|
||||||
#include "DatabaseImpl.h"
|
#include "DatabaseImpl.h"
|
||||||
#include "Playlist.h"
|
#include "Playlist.h"
|
||||||
#include "PlaylistEntry.h"
|
#include "PlaylistEntry.h"
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
#include "playlist/dynamic/DynamicControl.h"
|
#include "playlist/dynamic/DynamicControl.h"
|
||||||
#include "playlist/dynamic/GeneratorInterface.h"
|
#include "playlist/dynamic/GeneratorInterface.h"
|
||||||
#include "playlist/dynamic/GeneratorFactory.h"
|
#include "playlist/dynamic/GeneratorFactory.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include "DatabaseImpl.h"
|
#include "DatabaseImpl.h"
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "DatabaseCommand_LoadPlaylistEntries.h"
|
#include "DatabaseCommand_LoadPlaylistEntries.h"
|
||||||
|
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include "DatabaseImpl.h"
|
#include "DatabaseImpl.h"
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include "playlist/dynamic/DynamicPlaylist.h"
|
#include "playlist/dynamic/DynamicPlaylist.h"
|
||||||
#include "playlist/dynamic/DynamicControl.h"
|
#include "playlist/dynamic/DynamicControl.h"
|
||||||
#include "network/Servent.h"
|
#include "network/Servent.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include "DatabaseImpl.h"
|
#include "DatabaseImpl.h"
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "collection/Collection.h"
|
#include "collection/Collection.h"
|
||||||
#include "network/Servent.h"
|
#include "network/Servent.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include "DatabaseImpl.h"
|
#include "DatabaseImpl.h"
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "DatabaseWorker.h"
|
#include "DatabaseWorker.h"
|
||||||
|
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include "Database.h"
|
#include "Database.h"
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
#include "network/Servent.h"
|
#include "network/Servent.h"
|
||||||
#include "network/Msg.h"
|
#include "network/Msg.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
|
|
||||||
#include "QTcpSocketExtra.h"
|
#include "QTcpSocketExtra.h"
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include "Msg_p.h"
|
#include "Msg_p.h"
|
||||||
|
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/Json.h"
|
||||||
|
|
||||||
#include <QtEndian>
|
#include <QtEndian>
|
||||||
|
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "network/Msg_p.h"
|
#include "network/Msg_p.h"
|
||||||
#include "network/Servent.h"
|
#include "network/Servent.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
|
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
#include "sip/PeerInfo.h"
|
#include "sip/PeerInfo.h"
|
||||||
#include "sip/SipPlugin.h"
|
#include "sip/SipPlugin.h"
|
||||||
#include "utils/Closure.h"
|
#include "utils/Closure.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/NetworkAccessManager.h"
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include "database/DatabaseCommand_SetDynamicPlaylistRevision.h"
|
#include "database/DatabaseCommand_SetDynamicPlaylistRevision.h"
|
||||||
#include "database/DatabaseCommand_LoadDynamicPlaylistEntries.h"
|
#include "database/DatabaseCommand_LoadDynamicPlaylistEntries.h"
|
||||||
#include "database/DatabaseCommand_DeleteDynamicPlaylist.h"
|
#include "database/DatabaseCommand_DeleteDynamicPlaylist.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include "GeneratorFactory.h"
|
#include "GeneratorFactory.h"
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "accounts/AccountConfigWidget.h"
|
#include "accounts/AccountConfigWidget.h"
|
||||||
#include "utils/TomahawkUtilsGui.h"
|
#include "utils/TomahawkUtilsGui.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/NetworkAccessManager.h"
|
#include "utils/NetworkAccessManager.h"
|
||||||
#include "utils/NetworkProxyFactory.h"
|
#include "utils/NetworkProxyFactory.h"
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
#include "SipInfo.h"
|
#include "SipInfo.h"
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/Json.h"
|
||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
|
@@ -37,6 +37,7 @@
|
|||||||
#include "jobview/JobStatusView.h"
|
#include "jobview/JobStatusView.h"
|
||||||
#include "jobview/JobStatusModel.h"
|
#include "jobview/JobStatusModel.h"
|
||||||
#include "jobview/ErrorStatusMessage.h"
|
#include "jobview/ErrorStatusMessage.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/NetworkReply.h"
|
#include "utils/NetworkReply.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
@@ -20,19 +20,21 @@
|
|||||||
|
|
||||||
#include "ItunesParser.h"
|
#include "ItunesParser.h"
|
||||||
|
|
||||||
#include <QtNetwork/QNetworkAccessManager>
|
|
||||||
#include <QRegExp>
|
|
||||||
|
|
||||||
#include "Query.h"
|
|
||||||
#include "SourceList.h"
|
|
||||||
#include "jobview/JobStatusView.h"
|
#include "jobview/JobStatusView.h"
|
||||||
#include "jobview/JobStatusModel.h"
|
#include "jobview/JobStatusModel.h"
|
||||||
#include "jobview/ErrorStatusMessage.h"
|
#include "jobview/ErrorStatusMessage.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/NetworkReply.h"
|
#include "utils/NetworkReply.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/NetworkAccessManager.h"
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
|
||||||
|
#include "Query.h"
|
||||||
|
#include "SourceList.h"
|
||||||
|
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QRegExp>
|
||||||
|
|
||||||
// Forward Declarations breaking QSharedPointer
|
// Forward Declarations breaking QSharedPointer
|
||||||
#if QT_VERSION < QT_VERSION_CHECK( 5, 0, 0 )
|
#if QT_VERSION < QT_VERSION_CHECK( 5, 0, 0 )
|
||||||
#include "Playlist.h"
|
#include "Playlist.h"
|
||||||
|
116
src/libtomahawk/utils/Json.cpp
Normal file
116
src/libtomahawk/utils/Json.cpp
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014, Uwe L. Korn <uwelk@xhochy.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Json.h"
|
||||||
|
|
||||||
|
// Qt version specific includes
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
||||||
|
#include <QUrlQuery>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QMetaProperty>
|
||||||
|
#else
|
||||||
|
#include <qjson/parser.h>
|
||||||
|
#include <qjson/qobjecthelper.h>
|
||||||
|
#include <qjson/serializer.h>
|
||||||
|
#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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
36
src/libtomahawk/utils/Json.h
Normal file
36
src/libtomahawk/utils/Json.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014, Uwe L. Korn <uwelk@xhochy.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#ifndef TOMAHAWKUTILS_JSON_H
|
||||||
|
#define TOMAHAWKUTILS_JSON_H
|
||||||
|
|
||||||
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
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
|
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "JspfLoader.h"
|
#include "JspfLoader.h"
|
||||||
|
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/NetworkReply.h"
|
#include "utils/NetworkReply.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include "ShortLinkHelper_p.h"
|
#include "ShortLinkHelper_p.h"
|
||||||
|
|
||||||
#include "utils/Closure.h"
|
#include "utils/Closure.h"
|
||||||
|
#include "utils/Json.h"
|
||||||
#include "utils/NetworkAccessManager.h"
|
#include "utils/NetworkAccessManager.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "Playlist.h"
|
#include "Playlist.h"
|
||||||
|
@@ -19,20 +19,22 @@
|
|||||||
|
|
||||||
#include "SpotifyParser.h"
|
#include "SpotifyParser.h"
|
||||||
|
|
||||||
#include <QtNetwork/QNetworkAccessManager>
|
#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 "Query.h"
|
||||||
#include "SourceList.h"
|
#include "SourceList.h"
|
||||||
#include "DropJob.h"
|
#include "DropJob.h"
|
||||||
#include "DropJobNotifier.h"
|
#include "DropJobNotifier.h"
|
||||||
#include "ViewManager.h"
|
#include "ViewManager.h"
|
||||||
#include "jobview/JobStatusView.h"
|
|
||||||
#include "jobview/JobStatusModel.h"
|
#include <QNetworkAccessManager>
|
||||||
#include "jobview/ErrorStatusMessage.h"
|
|
||||||
#include "utils/NetworkReply.h"
|
|
||||||
#include "utils/TomahawkUtils.h"
|
|
||||||
#include "utils/Logger.h"
|
|
||||||
#include "utils/NetworkAccessManager.h"
|
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
@@ -57,11 +57,6 @@
|
|||||||
// Qt version specific includes
|
// Qt version specific includes
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
#include <QJsonDocument>
|
|
||||||
#else
|
|
||||||
#include <qjson/parser.h>
|
|
||||||
#include <qjson/qobjecthelper.h>
|
|
||||||
#include <qjson/serializer.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#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
|
void
|
||||||
urlAddQueryItem( QUrl& url, const QString& key, const QString& value )
|
urlAddQueryItem( QUrl& url, const QString& key, const QString& value )
|
||||||
{
|
{
|
||||||
|
@@ -207,12 +207,6 @@ namespace TomahawkUtils
|
|||||||
* Qt4 / Qt5 compatibility layer
|
* 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 */
|
/* QUrl */
|
||||||
DLLEXPORT void urlAddQueryItem( QUrl& url, const QString& key, const QString& value );
|
DLLEXPORT void urlAddQueryItem( QUrl& url, const QString& key, const QString& value );
|
||||||
DLLEXPORT QString urlQueryItemValue( const QUrl& url, const QString& key );
|
DLLEXPORT QString urlQueryItemValue( const QUrl& url, const QString& key );
|
||||||
|
Reference in New Issue
Block a user