From 50539ab46bd32d7feb0b719b93cc0ae95c0bbf51 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Sat, 21 Nov 2015 11:09:59 +1100 Subject: [PATCH] Merge libmygpo-qt from HEAD (fd4e40a2a3c69d5b4ba94e483ddcbbf3541b5767) plus https://github.com/gpodder/libmygpo-qt/pull/8 to make it use HTTPS for API requests --- 3rdparty/libmygpo-qt/AddRemoveResult.cpp | 8 +- 3rdparty/libmygpo-qt/ApiRequest.cpp | 2 +- 3rdparty/libmygpo-qt/ApiRequest.h | 12 +- 3rdparty/libmygpo-qt/CMakeLists.txt | 3 +- 3rdparty/libmygpo-qt/Config.cpp | 2 +- 3rdparty/libmygpo-qt/DeviceList.cpp | 5 +- 3rdparty/libmygpo-qt/DeviceSyncResult.cpp | 7 +- 3rdparty/libmygpo-qt/DeviceUpdates.cpp | 5 +- 3rdparty/libmygpo-qt/Episode.cpp | 5 +- 3rdparty/libmygpo-qt/EpisodeAction.cpp | 5 +- 3rdparty/libmygpo-qt/EpisodeActionList.cpp | 5 +- 3rdparty/libmygpo-qt/EpisodeList.cpp | 5 +- 3rdparty/libmygpo-qt/JsonCreator.cpp | 20 ++-- 3rdparty/libmygpo-qt/Podcast.cpp | 7 +- 3rdparty/libmygpo-qt/PodcastList.cpp | 5 +- 3rdparty/libmygpo-qt/RequestHandler.cpp | 2 +- 3rdparty/libmygpo-qt/Settings.cpp | 6 +- 3rdparty/libmygpo-qt/TagList.cpp | 5 +- 3rdparty/libmygpo-qt/UrlBuilder.cpp | 3 +- 3rdparty/libmygpo-qt/qjsonwrapper/Json.cpp | 123 +++++++++++++++++++++ 3rdparty/libmygpo-qt/qjsonwrapper/Json.h | 36 ++++++ CMakeLists.txt | 2 +- 22 files changed, 207 insertions(+), 66 deletions(-) create mode 100644 3rdparty/libmygpo-qt/qjsonwrapper/Json.cpp create mode 100644 3rdparty/libmygpo-qt/qjsonwrapper/Json.h diff --git a/3rdparty/libmygpo-qt/AddRemoveResult.cpp b/3rdparty/libmygpo-qt/AddRemoveResult.cpp index 1127b0391..83c0c60db 100644 --- a/3rdparty/libmygpo-qt/AddRemoveResult.cpp +++ b/3rdparty/libmygpo-qt/AddRemoveResult.cpp @@ -20,11 +20,11 @@ * USA * ***************************************************************************/ -#include - #include "AddRemoveResult.h" #include "AddRemoveResult_p.h" +#include "qjsonwrapper/Json.h" + using namespace mygpo; AddRemoveResultPrivate::AddRemoveResultPrivate( AddRemoveResult* qq, QNetworkReply* reply ) : q( qq ), m_reply( reply ), m_error( QNetworkReply::NoError ) @@ -64,7 +64,6 @@ QList< QPair< QUrl, QUrl > > AddRemoveResultPrivate::updateUrlsList() const bool AddRemoveResultPrivate::parse( const QVariant& data ) { - QJson::Parser parser; if( !data.canConvert( QVariant::Map ) ) return false; QVariantMap resultMap = data.toMap(); @@ -78,9 +77,8 @@ bool AddRemoveResultPrivate::parse( const QVariant& data ) bool AddRemoveResultPrivate::parse( const QByteArray& data ) { - QJson::Parser parser; bool ok; - QVariant variant = parser.parse( data, &ok ); + QVariant variant = QJsonWrapper::parseJson( data, &ok ); if( ok ) { ok = ( parse( variant ) ); diff --git a/3rdparty/libmygpo-qt/ApiRequest.cpp b/3rdparty/libmygpo-qt/ApiRequest.cpp index b3c533f2a..469a7a1ff 100644 --- a/3rdparty/libmygpo-qt/ApiRequest.cpp +++ b/3rdparty/libmygpo-qt/ApiRequest.cpp @@ -1,6 +1,6 @@ /*************************************************************************** * This file is part of libmygpo-qt * -* Copyright (c) 2010 - 2013 Stefan Derkits * +* Copyright (c) 2010 - 2014 Stefan Derkits * * Copyright (c) 2010 - 2011 Christian Wagner * * Copyright (c) 2010 - 2011 Felix Winter * * * diff --git a/3rdparty/libmygpo-qt/ApiRequest.h b/3rdparty/libmygpo-qt/ApiRequest.h index 982db49ba..c61119295 100644 --- a/3rdparty/libmygpo-qt/ApiRequest.h +++ b/3rdparty/libmygpo-qt/ApiRequest.h @@ -1,6 +1,6 @@ /*************************************************************************** * This file is part of libmygpo-qt * -* Copyright (c) 2010 - 2013 Stefan Derkits * +* Copyright (c) 2010 - 2014 Stefan Derkits * * Copyright (c) 2010 - 2011 Christian Wagner * * Copyright (c) 2010 - 2011 Felix Winter * * * @@ -84,7 +84,7 @@ public: */ QNetworkReply* suggestionsOpml( uint count ); - QNetworkReply* downloadSubscriptionsOpml( const QString& username, const QString& device ); + QNetworkReply* downloadSubscriptionsOpml( const QString& username, const QString& device = QString() ); /** * Returns the TXT Result for the Simple API Call "Downloading Podcast Toplists" @@ -111,7 +111,7 @@ public: */ QNetworkReply* suggestionsTxt( uint count ); - QNetworkReply* downloadSubscriptionsTxt( const QString& username, const QString& device ); + QNetworkReply* downloadSubscriptionsTxt( const QString& username, const QString& device = QString() ); /** * Returns the TXT Result for the Simple API Call "Downloading Podcast Toplists" @@ -153,9 +153,9 @@ public: * */ PodcastListPtr suggestions( uint count ); - - QNetworkReply* downloadSubscriptionsJson( const QString& username, const QString& device ); - + + QNetworkReply* downloadSubscriptionsJson( const QString& username, const QString& device = QString() ); + //ADVANCED API /** diff --git a/3rdparty/libmygpo-qt/CMakeLists.txt b/3rdparty/libmygpo-qt/CMakeLists.txt index c09d91448..64bd33cf2 100644 --- a/3rdparty/libmygpo-qt/CMakeLists.txt +++ b/3rdparty/libmygpo-qt/CMakeLists.txt @@ -1,7 +1,7 @@ # Extra bits for Clementine. set( MYGPO_QT_VERSION_MAJOR "1" ) set( MYGPO_QT_VERSION_MINOR "0" ) -set( MYGPO_QT_VERSION_PATCH "7" ) +set( MYGPO_QT_VERSION_PATCH "9" ) configure_file( Version.h.in ${CMAKE_CURRENT_BINARY_DIR}/Version.h ) include_directories("${QJSON_INCLUDEDIR}/qjson") @@ -27,6 +27,7 @@ set ( LIBMYGPO_QT_SRC DeviceUpdates.cpp DeviceList.cpp Device.cpp + qjsonwrapper/Json.cpp ) set ( LIBMYGPO_QT_MOC_H diff --git a/3rdparty/libmygpo-qt/Config.cpp b/3rdparty/libmygpo-qt/Config.cpp index a9ab85978..231f33a61 100644 --- a/3rdparty/libmygpo-qt/Config.cpp +++ b/3rdparty/libmygpo-qt/Config.cpp @@ -29,7 +29,7 @@ using namespace mygpo; Config* Config::s_instance = 0; -ConfigPrivate::ConfigPrivate( Config* qq ) : q( qq ), m_mygpoBaseUrl( QUrl( QLatin1String( "http://gpodder.net" ) ) ), m_userAgentPrefix( QString() ) +ConfigPrivate::ConfigPrivate( Config* qq ) : q( qq ), m_mygpoBaseUrl( QUrl( QLatin1String( "https://gpodder.net" ) ) ), m_userAgentPrefix( QString() ) { } diff --git a/3rdparty/libmygpo-qt/DeviceList.cpp b/3rdparty/libmygpo-qt/DeviceList.cpp index 46defc258..e972318cc 100644 --- a/3rdparty/libmygpo-qt/DeviceList.cpp +++ b/3rdparty/libmygpo-qt/DeviceList.cpp @@ -22,7 +22,7 @@ #include "DeviceList_p.h" -#include +#include "qjsonwrapper/Json.h" using namespace mygpo; @@ -73,9 +73,8 @@ bool DeviceListPrivate::parse( const QVariant& data ) bool DeviceListPrivate::parse( const QByteArray& data ) { - QJson::Parser parser; bool ok; - QVariant variant = parser.parse( data, &ok ); + QVariant variant = QJsonWrapper::parseJson( data, &ok ); if( ok ) { ok = ( parse( variant ) ); diff --git a/3rdparty/libmygpo-qt/DeviceSyncResult.cpp b/3rdparty/libmygpo-qt/DeviceSyncResult.cpp index b71f05588..1ee70494e 100644 --- a/3rdparty/libmygpo-qt/DeviceSyncResult.cpp +++ b/3rdparty/libmygpo-qt/DeviceSyncResult.cpp @@ -20,7 +20,7 @@ #include "DeviceSyncResult_p.h" -#include +#include "qjsonwrapper/Json.h" using namespace mygpo; @@ -85,9 +85,8 @@ bool DeviceSyncResultPrivate::parse( const QVariant& data ) bool DeviceSyncResultPrivate::parse( const QByteArray& data ) { - QJson::Parser parser; bool ok; - QVariant variant = parser.parse( data, &ok ); + QVariant variant = QJsonWrapper::parseJson( data, &ok ); if( ok ) { ok = ( parse( variant ) ); @@ -108,7 +107,7 @@ void DeviceSyncResultPrivate::parseData() emit q->parseError(); } } - m_reply->deleteLater(); + m_reply->deleteLater(); } void DeviceSyncResultPrivate::error( QNetworkReply::NetworkError error ) diff --git a/3rdparty/libmygpo-qt/DeviceUpdates.cpp b/3rdparty/libmygpo-qt/DeviceUpdates.cpp index c74b52fcb..04653c569 100644 --- a/3rdparty/libmygpo-qt/DeviceUpdates.cpp +++ b/3rdparty/libmygpo-qt/DeviceUpdates.cpp @@ -22,7 +22,7 @@ #include "DeviceUpdates_p.h" -#include +#include "qjsonwrapper/Json.h" using namespace mygpo; @@ -102,9 +102,8 @@ bool DeviceUpdatesPrivate::parse( const QVariant& data ) bool DeviceUpdatesPrivate::parse( const QByteArray& data ) { - QJson::Parser parser; bool ok; - QVariant variant = parser.parse( data, &ok ); + QVariant variant = QJsonWrapper::parseJson( data, &ok ); if( ok ) { ok = ( parse( variant ) ); diff --git a/3rdparty/libmygpo-qt/Episode.cpp b/3rdparty/libmygpo-qt/Episode.cpp index 921b72f7d..196de323f 100644 --- a/3rdparty/libmygpo-qt/Episode.cpp +++ b/3rdparty/libmygpo-qt/Episode.cpp @@ -22,7 +22,7 @@ #include "Episode_p.h" -#include +#include "qjsonwrapper/Json.h" using namespace mygpo; @@ -115,9 +115,8 @@ bool EpisodePrivate::parse ( const QVariant& data ) bool EpisodePrivate::parse ( const QByteArray& data ) { - QJson::Parser parser; bool ok; - QVariant variant = parser.parse ( data, &ok ); + QVariant variant = QJsonWrapper::parseJson( data, &ok ); if ( ok ) { if ( !parse ( variant ) ) return false; diff --git a/3rdparty/libmygpo-qt/EpisodeAction.cpp b/3rdparty/libmygpo-qt/EpisodeAction.cpp index ad1f0e5e3..95536be02 100644 --- a/3rdparty/libmygpo-qt/EpisodeAction.cpp +++ b/3rdparty/libmygpo-qt/EpisodeAction.cpp @@ -22,7 +22,7 @@ #include "EpisodeAction_p.h" -#include +#include "qjsonwrapper/Json.h" using namespace mygpo; @@ -163,9 +163,8 @@ bool EpisodeActionPrivate::parseActionType( const QString& data ) bool EpisodeActionPrivate::parse( const QByteArray& data ) { - QJson::Parser parser; bool ok; - QVariant variant = parser.parse( data, &ok ); + QVariant variant = QJsonWrapper::parseJson( data, &ok ); if( ok ) { if( !parse( variant ) ) return false; diff --git a/3rdparty/libmygpo-qt/EpisodeActionList.cpp b/3rdparty/libmygpo-qt/EpisodeActionList.cpp index 426f0e895..4c221cc7a 100644 --- a/3rdparty/libmygpo-qt/EpisodeActionList.cpp +++ b/3rdparty/libmygpo-qt/EpisodeActionList.cpp @@ -22,7 +22,7 @@ #include "EpisodeActionList_p.h" -#include +#include "qjsonwrapper/Json.h" using namespace mygpo; @@ -88,9 +88,8 @@ bool EpisodeActionListPrivate::parse( const QVariant& data ) bool EpisodeActionListPrivate::parse( const QByteArray& data ) { - QJson::Parser parser; bool ok; - QVariant variant = parser.parse( data, &ok ); + QVariant variant = QJsonWrapper::parseJson( data, &ok ); if( ok ) { ok = ( parse( variant ) ); diff --git a/3rdparty/libmygpo-qt/EpisodeList.cpp b/3rdparty/libmygpo-qt/EpisodeList.cpp index e003f2333..6a9de5de3 100644 --- a/3rdparty/libmygpo-qt/EpisodeList.cpp +++ b/3rdparty/libmygpo-qt/EpisodeList.cpp @@ -22,7 +22,7 @@ #include "EpisodeList_p.h" -#include +#include "qjsonwrapper/Json.h" using namespace mygpo; @@ -71,9 +71,8 @@ bool EpisodeListPrivate::parse( const QVariant& data ) bool EpisodeListPrivate::parse( const QByteArray& data ) { - QJson::Parser parser; bool ok; - QVariant variant = parser.parse( data, &ok ); + QVariant variant = QJsonWrapper::parseJson( data, &ok ); if( ok ) { ok = ( parse( variant ) ); diff --git a/3rdparty/libmygpo-qt/JsonCreator.cpp b/3rdparty/libmygpo-qt/JsonCreator.cpp index fc148a0f6..9c4f0bcc4 100644 --- a/3rdparty/libmygpo-qt/JsonCreator.cpp +++ b/3rdparty/libmygpo-qt/JsonCreator.cpp @@ -20,47 +20,44 @@ * USA * ***************************************************************************/ -#include +//#include #include #include #include #include -#include - #include "JsonCreator.h" +#include "qjsonwrapper/Json.h" + using namespace mygpo; static qulonglong c_maxlonglong = (2^64)-1; QByteArray JsonCreator::addRemoveSubsToJSON( const QList< QUrl >& add, const QList< QUrl >& remove ) { - QJson::Serializer serializer; QVariantMap jsonData; QVariant addVar( urlListToQVariantList( add ) ); QVariant removeVar( urlListToQVariantList( remove ) ); jsonData.insert( QString( QLatin1String( "add" ) ), addVar ); jsonData.insert( QString( QLatin1String( "remove" ) ), removeVar ); - QByteArray jsonByteArray = serializer.serialize( QVariant( jsonData ) ); + QByteArray jsonByteArray = QJsonWrapper::toJson( QVariant( jsonData ) ); return jsonByteArray; } QByteArray JsonCreator::saveSettingsToJSON( const QMap< QString, QVariant >& set, const QList< QString >& remove ) { - QJson::Serializer serializer; QVariantMap jsonData; //QVariant setVar(stringMapToQVariantMap(set)); QVariant removeVar( stringListToQVariantList( remove ) ); jsonData.insert( QString( QLatin1String( "set" ) ), set ); jsonData.insert( QString( QLatin1String( "remove" ) ), removeVar ); - QByteArray jsonByteArray = serializer.serialize( QVariant( jsonData ) ); + QByteArray jsonByteArray = QJsonWrapper::toJson( QVariant( jsonData ) ); return jsonByteArray; } QByteArray JsonCreator::episodeActionListToJSON( const QList& episodeActions ) { - QJson::Serializer serializer; QVariantList jsonData; foreach( const EpisodeActionPtr episodeAction, episodeActions ) @@ -68,19 +65,18 @@ QByteArray JsonCreator::episodeActionListToJSON( const QList& jsonData.append( episodeActionToQVariantMap( episodeAction ) ); } - QByteArray jsonByteArray = serializer.serialize( QVariant( jsonData ) ); + QByteArray jsonByteArray = QJsonWrapper::toJson( QVariant( jsonData ) ); return jsonByteArray; } QByteArray JsonCreator::renameDeviceStringToJSON( const QString& caption, const QString& type ) { - QJson::Serializer serializer; QVariantMap jsonData; QVariant captionVar( caption ); QVariant typeVar( type ); jsonData.insert( QString( QLatin1String( "caption" ) ), captionVar ); jsonData.insert( QString( QLatin1String( "type" ) ), typeVar ); - QByteArray jsonByteArray = serializer.serialize( QVariant( jsonData ) ); + QByteArray jsonByteArray = QJsonWrapper::toJson( QVariant( jsonData ) ); return jsonByteArray; } @@ -130,7 +126,7 @@ QByteArray JsonCreator::deviceSynchronizationListsToJSON(const QList< QStringLis jsonStr.append(syncVar); jsonStr.append(QLatin1String(" ,\"stop-synchronize\" : ")); jsonStr.append(stopVar); - jsonStr.append(QLatin1String(" }\n")); + jsonStr.append(QLatin1String(" }")); return jsonStr.toLocal8Bit(); } diff --git a/3rdparty/libmygpo-qt/Podcast.cpp b/3rdparty/libmygpo-qt/Podcast.cpp index 589505452..bad7900dc 100644 --- a/3rdparty/libmygpo-qt/Podcast.cpp +++ b/3rdparty/libmygpo-qt/Podcast.cpp @@ -22,7 +22,7 @@ #include "Podcast_p.h" -#include +#include "qjsonwrapper/Json.h" using namespace mygpo; @@ -181,9 +181,8 @@ bool PodcastPrivate::parse( const QVariant& data ) bool PodcastPrivate::parse( const QByteArray& data ) { - QJson::Parser parser; bool ok; - QVariant variant = parser.parse( data, &ok ); + QVariant variant = QJsonWrapper::parseJson( data, &ok ); if ( ok ) { if ( !parse( variant ) ) return false; @@ -197,8 +196,6 @@ bool PodcastPrivate::parse( const QByteArray& data ) void PodcastPrivate::parseData() { - //parsen und signal senden - QJson::Parser parser; if ( parse( m_reply->readAll( ) ) ) { emit q->finished(); diff --git a/3rdparty/libmygpo-qt/PodcastList.cpp b/3rdparty/libmygpo-qt/PodcastList.cpp index 7e2d9c4a4..fbd398796 100644 --- a/3rdparty/libmygpo-qt/PodcastList.cpp +++ b/3rdparty/libmygpo-qt/PodcastList.cpp @@ -22,7 +22,7 @@ #include "PodcastList_p.h" -#include +#include "qjsonwrapper/Json.h" using namespace mygpo; @@ -71,9 +71,8 @@ bool PodcastListPrivate::parse( const QVariant& data ) bool PodcastListPrivate::parse( const QByteArray& data ) { - QJson::Parser parser; bool ok; - QVariant variant = parser.parse( data, &ok ); + QVariant variant = QJsonWrapper::parseJson( data, &ok ); if( ok ) { ok = ( parse( variant ) ); diff --git a/3rdparty/libmygpo-qt/RequestHandler.cpp b/3rdparty/libmygpo-qt/RequestHandler.cpp index dea1a62db..af504c5c5 100644 --- a/3rdparty/libmygpo-qt/RequestHandler.cpp +++ b/3rdparty/libmygpo-qt/RequestHandler.cpp @@ -77,5 +77,5 @@ void RequestHandler::addAuthData( QNetworkRequest& request ) void RequestHandler::addUserAgent( QNetworkRequest &request ) { - request.setRawHeader("User-Agent", Config::instance()->userAgent().toAscii() ); + request.setRawHeader("User-Agent", Config::instance()->userAgent().toLatin1() ); } diff --git a/3rdparty/libmygpo-qt/Settings.cpp b/3rdparty/libmygpo-qt/Settings.cpp index a9045d9a1..c27e01c87 100644 --- a/3rdparty/libmygpo-qt/Settings.cpp +++ b/3rdparty/libmygpo-qt/Settings.cpp @@ -22,7 +22,7 @@ #include "Settings_p.h" -#include +#include "qjsonwrapper/Json.h" using namespace mygpo; @@ -49,9 +49,8 @@ bool SettingsPrivate::parse( const QVariant& data ) bool SettingsPrivate::parse( const QByteArray& data ) { - QJson::Parser parser; bool ok; - QVariant variant = parser.parse( data, &ok ); + QVariant variant = QJsonWrapper::parseJson( data, &ok ); if( ok ) { ok = ( parse( variant ) ); @@ -63,7 +62,6 @@ void SettingsPrivate::parseData() { if( m_reply->error() == QNetworkReply::NoError ) { - QJson::Parser parser; if( parse( m_reply->readAll() ) ) { emit q->finished(); diff --git a/3rdparty/libmygpo-qt/TagList.cpp b/3rdparty/libmygpo-qt/TagList.cpp index d975a7273..4c19749cf 100644 --- a/3rdparty/libmygpo-qt/TagList.cpp +++ b/3rdparty/libmygpo-qt/TagList.cpp @@ -22,7 +22,7 @@ #include "TagList_p.h" -#include +#include "qjsonwrapper/Json.h" using namespace mygpo; @@ -70,9 +70,8 @@ bool TagListPrivate::parse( const QVariant& data ) bool TagListPrivate::parse( const QByteArray& data ) { - QJson::Parser parser; bool ok; - QVariant variant = parser.parse( data, &ok ); + QVariant variant = QJsonWrapper::parseJson( data, &ok ); if( ok ) { ok = ( parse( variant ) ); diff --git a/3rdparty/libmygpo-qt/UrlBuilder.cpp b/3rdparty/libmygpo-qt/UrlBuilder.cpp index e0ba7649a..eebcc3060 100644 --- a/3rdparty/libmygpo-qt/UrlBuilder.cpp +++ b/3rdparty/libmygpo-qt/UrlBuilder.cpp @@ -74,7 +74,8 @@ QString UrlBuilder::getPodcastSearchUrl( const QString& query, Format f ) QString UrlBuilder::getSubscriptionsUrl( const QString& username, const QString& device, UrlBuilder::Format f) { - return s_server % QLatin1String( "/subscriptions/" ) % username % QLatin1String( "/" ) % device % getFormatExtension( f ); + QString deviceString = device.isNull() ? QString(QLatin1String("")) : (QLatin1String( "/" ) % device); + return s_server % QLatin1String( "/subscriptions/" ) % username % deviceString % getFormatExtension( f ); } QString UrlBuilder::getTopTagsUrl( uint i ) diff --git a/3rdparty/libmygpo-qt/qjsonwrapper/Json.cpp b/3rdparty/libmygpo-qt/qjsonwrapper/Json.cpp new file mode 100644 index 000000000..4a8c2ac36 --- /dev/null +++ b/3rdparty/libmygpo-qt/qjsonwrapper/Json.cpp @@ -0,0 +1,123 @@ +/* Copyright 2014, Uwe L. Korn + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "Json.h" + +// Qt version specific includes +#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) + #include + #include +#else + #include + #include + #include +#endif + +namespace QJsonWrapper +{ + +QVariantMap +qobject2qvariant( const QObject* object ) +{ +#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) + QVariantMap map; + if ( object == NULL ) + { + return map; + } + + const QMetaObject* metaObject = object->metaObject(); + 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 = !doc.isNull(); + } + return doc.toJson( QJsonDocument::Compact ); +#else + QJson::Serializer serializer; + return serializer.serialize( variant, ok ); +#endif +} + +} diff --git a/3rdparty/libmygpo-qt/qjsonwrapper/Json.h b/3rdparty/libmygpo-qt/qjsonwrapper/Json.h new file mode 100644 index 000000000..36d53a0f9 --- /dev/null +++ b/3rdparty/libmygpo-qt/qjsonwrapper/Json.h @@ -0,0 +1,36 @@ +/* Copyright 2014, Uwe L. Korn + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once +#ifndef QJSONWRAPPER_JSON_H +#define QJSONWRAPPER_JSON_H + +#include + +namespace QJsonWrapper +{ + QVariantMap qobject2qvariant( const QObject* object ); + void qvariant2qobject( const QVariantMap& variant, QObject* object ); + QVariant parseJson( const QByteArray& jsonData, bool* ok = 0 ); + QByteArray toJson( const QVariant &variant, bool* ok = 0 ); +} + +#endif // QJSONWRAPPER_JSON_H diff --git a/CMakeLists.txt b/CMakeLists.txt index 9118e9c3b..7b349065e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,7 +69,7 @@ pkg_check_modules(GSTREAMER_BASE REQUIRED gstreamer-base-1.0) pkg_check_modules(GSTREAMER_TAG REQUIRED gstreamer-tag-1.0) pkg_check_modules(LIBGPOD libgpod-1.0>=0.7.92) pkg_check_modules(LIBMTP libmtp>=1.0) -pkg_check_modules(LIBMYGPO_QT libmygpo-qt>=1.0.7) +pkg_check_modules(LIBMYGPO_QT libmygpo-qt>=1.0.9) pkg_check_modules(LIBPULSE libpulse) pkg_check_modules(LIBXML libxml-2.0) pkg_check_modules(QJSON REQUIRED QJson)