From 42aafd247a3a96f7a6c07d31b3a0881691a8daf2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 15 Apr 2015 18:26:09 +0200 Subject: [PATCH] Update optional components to qt5 --- CMakeLists.txt | 51 ++++++------ src/CMakeLists.txt | 7 +- src/dbus/org.freedesktop.Avahi.EntryGroup.xml | 4 +- src/dbus/org.freedesktop.Avahi.Server.xml | 2 +- .../org.freedesktop.MediaPlayer.player.xml | 8 +- src/dbus/org.freedesktop.MediaPlayer.root.xml | 2 +- .../org.freedesktop.MediaPlayer.tracklist.xml | 2 +- src/dbus/org.freedesktop.Notifications.xml | 2 +- src/dbus/org.freedesktop.UDisks.Device.xml | 8 +- src/dbus/org.freedesktop.UDisks.xml | 2 +- src/dbus/org.mpris.MediaPlayer2.Player.xml | 2 +- src/dbus/org.mpris.MediaPlayer2.Playlists.xml | 8 +- src/dbus/org.mpris.MediaPlayer2.TrackList.xml | 6 +- src/devices/mtpconnection.cpp | 14 ++-- src/internet/box/boxservice.cpp | 73 +++++++++--------- src/internet/box/boxservice.h | 2 +- src/internet/dropbox/dropboxauthenticator.cpp | 20 ++--- src/internet/dropbox/dropboxservice.cpp | 50 ++++++------ .../googledrive/googledriveclient.cpp | 60 ++++++++------- .../googledrive/googledriveservice.cpp | 7 +- src/internet/lastfm/lastfmcompat.h | 28 +++---- src/internet/lastfm/lastfmservice.cpp | 2 +- src/internet/seafile/seafileservice.cpp | 77 ++++++++++--------- src/internet/skydrive/skydriveservice.cpp | 38 ++++----- src/internet/vk/vkconnection.cpp | 60 +++++++++------ src/internet/vk/vkmusiccache.cpp | 2 +- src/moodbar/moodbarpipeline.cpp | 2 +- src/ui/ripcd.cpp | 6 +- src/widgets/osd_x11.cpp | 2 +- src/wiimotedev/wiimotesettingspage.cpp | 2 +- tests/CMakeLists.txt | 8 +- 31 files changed, 298 insertions(+), 259 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fccae8aa..c108b2974 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,9 +87,9 @@ if (WIN32) find_library(QTSPARKLE_LIBRARIES qtsparkle) endif (WIN32) -find_library(LASTFM_LIBRARIES lastfm) -find_path(LASTFM_INCLUDE_DIRS lastfm/ws.h) -find_path(LASTFM1_INCLUDE_DIRS lastfm/Track.h) +find_library(LASTFM5_LIBRARIES lastfm5) +find_path(LASTFM5_INCLUDE_DIRS lastfm5/ws.h) +find_path(LASTFM51_INCLUDE_DIRS lastfm5/Track.h) find_path(SPARSEHASH_INCLUDE_DIRS google/sparsetable) @@ -115,7 +115,7 @@ else() set(CMAKE_REQUIRED_LIBRARIES) endif() -if(LASTFM_INCLUDE_DIRS AND LASTFM1_INCLUDE_DIRS) +if(LASTFM5_INCLUDE_DIRS AND LASTFM51_INCLUDE_DIRS) set(HAVE_LIBLASTFM1 ON) endif() @@ -192,85 +192,85 @@ endif(WIN32) optional_component(BREAKPAD OFF "Crash reporting") -optional_component(GOOGLE_DRIVE OFF "Google Drive support" +optional_component(GOOGLE_DRIVE ON "Google Drive support" DEPENDS "Google sparsehash" SPARSEHASH_INCLUDE_DIRS DEPENDS "Taglib 1.8" "TAGLIB_VERSION VERSION_GREATER 1.7.999" ) -optional_component(DROPBOX OFF "Dropbox support" +optional_component(DROPBOX ON "Dropbox support" DEPENDS "Google sparsehash" SPARSEHASH_INCLUDE_DIRS DEPENDS "Taglib 1.8" "TAGLIB_VERSION VERSION_GREATER 1.7.999" ) -optional_component(SKYDRIVE OFF "Skydrive support" +optional_component(SKYDRIVE ON "Skydrive support" DEPENDS "Google sparsehash" SPARSEHASH_INCLUDE_DIRS DEPENDS "Taglib 1.8" "TAGLIB_VERSION VERSION_GREATER 1.7.999" ) -optional_component(BOX OFF "Box support" +optional_component(BOX ON "Box support" DEPENDS "Google sparsehash" SPARSEHASH_INCLUDE_DIRS DEPENDS "Taglib 1.8" "TAGLIB_VERSION VERSION_GREATER 1.7.999" ) -optional_component(VK OFF "Vk.com support") +optional_component(VK ON "Vk.com support") -optional_component(SEAFILE OFF "Seafile support" +optional_component(SEAFILE ON "Seafile support" DEPENDS "Google sparsehash" SPARSEHASH_INCLUDE_DIRS DEPENDS "Taglib 1.8" "TAGLIB_VERSION VERSION_GREATER 1.7.999" ) -optional_component(AUDIOCD OFF "Devices: Audio CD support" +optional_component(AUDIOCD ON "Devices: Audio CD support" DEPENDS "libcdio" CDIO_FOUND ) -optional_component(LIBGPOD OFF "Devices: iPod classic support" +optional_component(LIBGPOD ON "Devices: iPod classic support" DEPENDS "libgpod" LIBGPOD_FOUND ) -optional_component(GIO OFF "Devices: GIO device backend" +optional_component(GIO ON "Devices: GIO device backend" DEPENDS "libgio" GIO_FOUND DEPENDS "Linux or Windows" "NOT APPLE" ) -optional_component(LIBMTP OFF "Devices: MTP support" +optional_component(LIBMTP ON "Devices: MTP support" DEPENDS "libmtp" LIBMTP_FOUND ) -optional_component(LIBLASTFM OFF "Last.fm support" - DEPENDS "liblastfm" LASTFM_LIBRARIES LASTFM_INCLUDE_DIRS +optional_component(LIBLASTFM ON "Last.fm support" + DEPENDS "liblastfm" LASTFM5_LIBRARIES LASTFM5_INCLUDE_DIRS ) -optional_component(DBUS OFF "D-Bus support" +optional_component(DBUS ON "D-Bus support" DEPENDS "Linux" LINUX ) -optional_component(WIIMOTEDEV OFF "Wiimote support" +optional_component(WIIMOTEDEV ON "Wiimote support" DEPENDS "D-Bus support" HAVE_DBUS ) -optional_component(DEVICEKIT OFF "Devices: DeviceKit backend" +optional_component(DEVICEKIT ON "Devices: DeviceKit backend" DEPENDS "D-Bus support" HAVE_DBUS ) -optional_component(SPOTIFY_BLOB OFF "Spotify support: non-GPL binary helper" +optional_component(SPOTIFY_BLOB ON "Spotify support: non-GPL binary helper" DEPENDS "protobuf" PROTOBUF_FOUND PROTOBUF_PROTOC_EXECUTABLE DEPENDS "libspotify" SPOTIFY_FOUND ) -optional_component(MOODBAR OFF "Moodbar support" +optional_component(MOODBAR ON "Moodbar support" DEPENDS "fftw3" FFTW3_FOUND ) -optional_component(SPARKLE OFF "Sparkle integration" +optional_component(SPARKLE ON "Sparkle integration" DEPENDS "Mac OS X" APPLE DEPENDS "Sparkle" SPARKLE ) -optional_component(LIBPULSE OFF "Pulse audio integration" +optional_component(LIBPULSE ON "Pulse audio integration" DEPENDS "libpulse" LIBPULSE_FOUND ) -optional_component(VISUALISATIONS OFF "Visualisations") +optional_component(VISUALISATIONS ON "Visualisations") if(NOT HAVE_SPOTIFY_BLOB AND NOT QCA_QT5_FOUND) message(FATAL_ERROR "Either QCA-qt5 must be available or the non-GPL Spotify " @@ -282,6 +282,7 @@ endif() # Find DBus if it's enabled if (HAVE_DBUS) find_package(Qt5 COMPONENTS DBus) + get_target_property(QT_DBUSXML2CPP_EXECUTABLE Qt5::qdbusxml2cpp LOCATION) endif () if (HAVE_VK) @@ -291,7 +292,7 @@ if (HAVE_VK) endif(HAVE_VK) # We can include the Qt definitions now -set(QT_LIBRARIES Qt5::Core Qt5::OpenGL Qt5::Sql Qt5::Network Qt5::Xml Qt5::Widgets Qt5::Concurrent Qt5::X11Extras) +set(QT_LIBRARIES Qt5::Core Qt5::OpenGL Qt5::Sql Qt5::Network Qt5::Xml Qt5::Widgets Qt5::Concurrent Qt5::X11Extras Qt5::DBus) # Remove GLU and GL from the link line - they're not really required # and don't exist on my mingw toolchain diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b9cc0d438..9d193c850 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,7 +44,7 @@ find_package(OpenGL) include_directories(${OPENGL_INCLUDE_DIR}) if(HAVE_LIBLASTFM) - include_directories(${LASTFM_INCLUDE_DIRS}) + include_directories(${LASTFM5_INCLUDE_DIRS}) endif(HAVE_LIBLASTFM) if(HAVE_BREAKPAD) @@ -1223,9 +1223,6 @@ add_library(clementine_lib STATIC ${OTHER_UIC_SOURCES} ) -add_dependencies(clementine_lib pot) - - target_link_libraries(clementine_lib clementine-spotifyblob-messages libclementine-common @@ -1261,7 +1258,7 @@ if(ENABLE_VISUALISATIONS) endif(ENABLE_VISUALISATIONS) if(HAVE_LIBLASTFM) - target_link_libraries(clementine_lib ${LASTFM_LIBRARIES}) + target_link_libraries(clementine_lib ${LASTFM5_LIBRARIES}) endif(HAVE_LIBLASTFM) if(HAVE_LIBGPOD) diff --git a/src/dbus/org.freedesktop.Avahi.EntryGroup.xml b/src/dbus/org.freedesktop.Avahi.EntryGroup.xml index 2930d7eeb..ec7f13742 100644 --- a/src/dbus/org.freedesktop.Avahi.EntryGroup.xml +++ b/src/dbus/org.freedesktop.Avahi.EntryGroup.xml @@ -51,7 +51,7 @@ - @@ -73,7 +73,7 @@ - diff --git a/src/dbus/org.freedesktop.Avahi.Server.xml b/src/dbus/org.freedesktop.Avahi.Server.xml index f336f207c..49493b3e0 100644 --- a/src/dbus/org.freedesktop.Avahi.Server.xml +++ b/src/dbus/org.freedesktop.Avahi.Server.xml @@ -132,7 +132,7 @@ - diff --git a/src/dbus/org.freedesktop.MediaPlayer.player.xml b/src/dbus/org.freedesktop.MediaPlayer.player.xml index fc81b98a7..1523ec00d 100644 --- a/src/dbus/org.freedesktop.MediaPlayer.player.xml +++ b/src/dbus/org.freedesktop.MediaPlayer.player.xml @@ -26,7 +26,7 @@ - + @@ -47,7 +47,7 @@ - + @@ -56,12 +56,12 @@ - + - + diff --git a/src/dbus/org.freedesktop.MediaPlayer.root.xml b/src/dbus/org.freedesktop.MediaPlayer.root.xml index 593e99177..6b8976ed0 100644 --- a/src/dbus/org.freedesktop.MediaPlayer.root.xml +++ b/src/dbus/org.freedesktop.MediaPlayer.root.xml @@ -13,7 +13,7 @@ - + diff --git a/src/dbus/org.freedesktop.MediaPlayer.tracklist.xml b/src/dbus/org.freedesktop.MediaPlayer.tracklist.xml index db8aabdae..d2db72f32 100644 --- a/src/dbus/org.freedesktop.MediaPlayer.tracklist.xml +++ b/src/dbus/org.freedesktop.MediaPlayer.tracklist.xml @@ -7,7 +7,7 @@ - + diff --git a/src/dbus/org.freedesktop.Notifications.xml b/src/dbus/org.freedesktop.Notifications.xml index 41f733009..00e85ea53 100644 --- a/src/dbus/org.freedesktop.Notifications.xml +++ b/src/dbus/org.freedesktop.Notifications.xml @@ -22,7 +22,7 @@ - + diff --git a/src/dbus/org.freedesktop.UDisks.Device.xml b/src/dbus/org.freedesktop.UDisks.Device.xml index 816dd6ffc..99d1c459f 100644 --- a/src/dbus/org.freedesktop.UDisks.Device.xml +++ b/src/dbus/org.freedesktop.UDisks.Device.xml @@ -636,7 +636,7 @@ - + An array of triples (pid, uid, command line for the process @@ -1355,9 +1355,9 @@ - - - + + + diff --git a/src/dbus/org.freedesktop.UDisks.xml b/src/dbus/org.freedesktop.UDisks.xml index 07daea04d..f046d64bf 100644 --- a/src/dbus/org.freedesktop.UDisks.xml +++ b/src/dbus/org.freedesktop.UDisks.xml @@ -1051,7 +1051,7 @@ - + An array of file systems known to the daemon and what features are supported. Each element in the array contains the following members: diff --git a/src/dbus/org.mpris.MediaPlayer2.Player.xml b/src/dbus/org.mpris.MediaPlayer2.Player.xml index 3c11567fa..711a74e47 100644 --- a/src/dbus/org.mpris.MediaPlayer2.Player.xml +++ b/src/dbus/org.mpris.MediaPlayer2.Player.xml @@ -27,7 +27,7 @@ - + diff --git a/src/dbus/org.mpris.MediaPlayer2.Playlists.xml b/src/dbus/org.mpris.MediaPlayer2.Playlists.xml index f94b31f2f..ef4c28a3c 100644 --- a/src/dbus/org.mpris.MediaPlayer2.Playlists.xml +++ b/src/dbus/org.mpris.MediaPlayer2.Playlists.xml @@ -6,7 +6,7 @@ - + @@ -17,12 +17,12 @@ - + - + - + diff --git a/src/dbus/org.mpris.MediaPlayer2.TrackList.xml b/src/dbus/org.mpris.MediaPlayer2.TrackList.xml index 5b609c7b3..a08888cb8 100644 --- a/src/dbus/org.mpris.MediaPlayer2.TrackList.xml +++ b/src/dbus/org.mpris.MediaPlayer2.TrackList.xml @@ -6,7 +6,7 @@ - + @@ -26,7 +26,7 @@ - + @@ -34,7 +34,7 @@ - + diff --git a/src/devices/mtpconnection.cpp b/src/devices/mtpconnection.cpp index 009aad5eb..0c55d2778 100644 --- a/src/devices/mtpconnection.cpp +++ b/src/devices/mtpconnection.cpp @@ -20,6 +20,7 @@ #include #include +#include MtpConnection::MtpConnection(const QUrl& url) : device_(nullptr) { QString hostname = url.host(); @@ -34,19 +35,20 @@ MtpConnection::MtpConnection(const QUrl& url) : device_(nullptr) { const unsigned int bus_location = host_re.cap(1).toInt(); const unsigned int device_num = host_re.cap(2).toInt(); - if (url.hasQueryItem("vendor")) { + QUrlQuery url_query(url); + if (url_query.hasQueryItem("vendor")) { LIBMTP_raw_device_t* raw_device = (LIBMTP_raw_device_t*)malloc(sizeof(LIBMTP_raw_device_t)); raw_device->device_entry.vendor = - url.queryItemValue("vendor").toAscii().data(); + url_query.queryItemValue("vendor").toLatin1().data(); raw_device->device_entry.product = - url.queryItemValue("product").toAscii().data(); + url_query.queryItemValue("product").toLatin1().data(); raw_device->device_entry.vendor_id = - url.queryItemValue("vendor_id").toUShort(); + url_query.queryItemValue("vendor_id").toUShort(); raw_device->device_entry.product_id = - url.queryItemValue("product_id").toUShort(); + url_query.queryItemValue("product_id").toUShort(); raw_device->device_entry.device_flags = - url.queryItemValue("quirks").toUInt(); + url_query.queryItemValue("quirks").toUInt(); raw_device->bus_location = bus_location; raw_device->devnum = device_num; diff --git a/src/internet/box/boxservice.cpp b/src/internet/box/boxservice.cpp index 3a39caaad..46fdec844 100644 --- a/src/internet/box/boxservice.cpp +++ b/src/internet/box/boxservice.cpp @@ -18,7 +18,10 @@ #include "boxservice.h" -#include +#include +#include +#include +#include #include "core/application.h" #include "core/player.h" @@ -122,10 +125,9 @@ void BoxService::AddAuthorizationHeader(QNetworkRequest* request) const { void BoxService::FetchUserInfoFinished(QNetworkReply* reply) { reply->deleteLater(); - QJson::Parser parser; - QVariantMap response = parser.parse(reply).toMap(); + QJsonObject json_response = QJsonDocument::fromJson(reply->readAll()).object(); - QString name = response["name"].toString(); + QString name = json_response["name"].toString(); if (!name.isEmpty()) { QSettings s; s.beginGroup(kSettingsGroup); @@ -160,7 +162,9 @@ void BoxService::UpdateFiles() { void BoxService::InitialiseEventsCursor() { QUrl url(kEvents); - url.addQueryItem("stream_position", "now"); + QUrlQuery url_query; + url_query.addQueryItem("stream_position", "now"); + url.setQuery(url_query); QNetworkRequest request(url); AddAuthorizationHeader(&request); QNetworkReply* reply = network_->get(request); @@ -170,12 +174,11 @@ void BoxService::InitialiseEventsCursor() { void BoxService::InitialiseEventsFinished(QNetworkReply* reply) { reply->deleteLater(); - QJson::Parser parser; - QVariantMap response = parser.parse(reply).toMap(); - if (response.contains("next_stream_position")) { + QJsonObject json_response = QJsonDocument::fromJson(reply->readAll()).object(); + if (json_response.contains("next_stream_position")) { QSettings s; s.beginGroup(kSettingsGroup); - s.setValue("cursor", response["next_stream_position"]); + s.setValue("cursor", json_response["next_stream_position"].toString()); } } @@ -189,9 +192,11 @@ void BoxService::FetchRecursiveFolderItems(const int folder_id, << "modified_at" << "name"; QString fields_list = fields.join(","); - url.addQueryItem("fields", fields_list); - url.addQueryItem("limit", "1000"); // Maximum according to API docs. - url.addQueryItem("offset", QString::number(offset)); + QUrlQuery url_query (url); + url_query.addQueryItem("fields", fields_list); + url_query.addQueryItem("limit", "1000"); // Maximum according to API docs. + url_query.addQueryItem("offset", QString::number(offset)); + url.setQuery(url_query); QNetworkRequest request(url); AddAuthorizationHeader(&request); QNetworkReply* reply = network_->get(request); @@ -204,21 +209,18 @@ void BoxService::FetchFolderItemsFinished(QNetworkReply* reply, const int folder_id) { reply->deleteLater(); - QByteArray data = reply->readAll(); + QJsonObject json_response = QJsonDocument::fromJson(reply->readAll()).object(); - QJson::Parser parser; - QVariantMap response = parser.parse(data).toMap(); - - QVariantList entries = response["entries"].toList(); - const int total_entries = response["total_count"].toInt(); - const int offset = response["offset"].toInt(); + QJsonArray entries = json_response["entries"].toArray(); + const int total_entries = json_response["total_count"].toInt(); + const int offset = json_response["offset"].toInt(); if (entries.size() + offset < total_entries) { // Fetch the next page if necessary. FetchRecursiveFolderItems(folder_id, offset + entries.size()); } - for (const QVariant& e : entries) { - QVariantMap entry = e.toMap(); + for (const QJsonValue& e : entries) { + QJsonObject entry = e.toObject(); if (entry["type"].toString() == "folder") { FetchRecursiveFolderItems(entry["id"].toInt()); } else { @@ -227,16 +229,16 @@ void BoxService::FetchFolderItemsFinished(QNetworkReply* reply, } } -void BoxService::MaybeAddFileEntry(const QVariantMap& entry) { +void BoxService::MaybeAddFileEntry(const QJsonObject &entry) { QString mime_type = GuessMimeTypeForFile(entry["name"].toString()); QUrl url; url.setScheme("box"); - url.setPath(entry["id"].toString()); + url.setPath("/" + entry["id"].toString()); Song song; song.set_url(url); - song.set_ctime(entry["created_at"].toDateTime().toTime_t()); - song.set_mtime(entry["modified_at"].toDateTime().toTime_t()); + song.set_ctime(QDateTime::fromString(entry["created_at"].toString()).toTime_t()); + song.set_mtime(QDateTime::fromString(entry["modified_at"].toString()).toTime_t()); song.set_filesize(entry["size"].toInt()); song.set_title(entry["name"].toString()); @@ -271,8 +273,10 @@ void BoxService::RedirectFollowed(QNetworkReply* reply, const Song& song, void BoxService::UpdateFilesFromCursor(const QString& cursor) { QUrl url(kEvents); - url.addQueryItem("stream_position", cursor); - url.addQueryItem("limit", "5000"); + QUrlQuery url_query; + url_query.addQueryItem("stream_position", cursor); + url_query.addQueryItem("limit", "5000"); + url.setQuery(url_query); QNetworkRequest request(url); AddAuthorizationHeader(&request); QNetworkReply* reply = network_->get(request); @@ -283,18 +287,17 @@ void BoxService::UpdateFilesFromCursor(const QString& cursor) { void BoxService::FetchEventsFinished(QNetworkReply* reply) { // TODO(John Maguire): Page through events. reply->deleteLater(); - QJson::Parser parser; - QVariantMap response = parser.parse(reply).toMap(); + QJsonObject json_response = QJsonDocument::fromJson(reply->readAll()).object(); QSettings s; s.beginGroup(kSettingsGroup); - s.setValue("cursor", response["next_stream_position"]); + s.setValue("cursor", json_response["next_stream_position"].toString()); - QVariantList entries = response["entries"].toList(); - for (const QVariant& e : entries) { - QVariantMap event = e.toMap(); + QJsonArray entries = json_response["entries"].toArray(); + for (const QJsonValue& e : entries) { + QJsonObject event = e.toObject(); QString type = event["event_type"].toString(); - QVariantMap source = event["source"].toMap(); + QJsonObject source = event["source"].toObject(); if (source["type"] == "file") { if (type == "ITEM_UPLOAD") { // Add file. @@ -303,7 +306,7 @@ void BoxService::FetchEventsFinished(QNetworkReply* reply) { // Delete file. QUrl url; url.setScheme("box"); - url.setPath(source["id"].toString()); + url.setPath("/" + source["id"].toString()); Song song = library_backend_->GetSongByUrl(url); if (song.is_valid()) { library_backend_->DeleteSongs(SongList() << song); diff --git a/src/internet/box/boxservice.h b/src/internet/box/boxservice.h index 9748f680e..a7fd990aa 100644 --- a/src/internet/box/boxservice.h +++ b/src/internet/box/boxservice.h @@ -64,7 +64,7 @@ class BoxService : public CloudFileService { void UpdateFilesFromCursor(const QString& cursor); QNetworkReply* FetchContentUrlForFile(const QString& file_id); void InitialiseEventsCursor(); - void MaybeAddFileEntry(const QVariantMap& entry); + void MaybeAddFileEntry(const QJsonObject& entry); void EnsureConnected(); QString access_token_; diff --git a/src/internet/dropbox/dropboxauthenticator.cpp b/src/internet/dropbox/dropboxauthenticator.cpp index 22284ff32..3bc67db77 100644 --- a/src/internet/dropbox/dropboxauthenticator.cpp +++ b/src/internet/dropbox/dropboxauthenticator.cpp @@ -20,11 +20,12 @@ #include -#include - #include #include #include +#include +#include +#include #include "core/closure.h" #include "core/logging.h" @@ -98,8 +99,10 @@ void DropboxAuthenticator::Authorise() { SLOT(RedirectArrived(LocalRedirectServer*)), server); QUrl url(kAuthoriseEndpoint); - url.addQueryItem("oauth_token", token_); - url.addQueryItem("oauth_callback", server->url().toString()); + QUrlQuery url_query; + url_query.addQueryItem("oauth_token", token_); + url_query.addQueryItem("oauth_callback", server->url().toString()); + url.setQuery(url_query); QDesktopServices::openUrl(url); } @@ -108,7 +111,7 @@ void DropboxAuthenticator::RedirectArrived(LocalRedirectServer* server) { server->deleteLater(); QUrl request_url = server->request_url(); qLog(Debug) << Q_FUNC_INFO << request_url; - uid_ = request_url.queryItemValue("uid"); + uid_ = QUrlQuery(request_url).queryItemValue("uid"); RequestAccessToken(); } @@ -126,7 +129,7 @@ void DropboxAuthenticator::RequestAccessToken() { void DropboxAuthenticator::RequestAccessTokenFinished(QNetworkReply* reply) { reply->deleteLater(); - QString result = QString::fromAscii(reply->readAll()); + QString result = QString::fromLatin1(reply->readAll()); qLog(Debug) << result; QMap params = ParseParamList(result); access_token_ = params["oauth_token"]; @@ -174,8 +177,7 @@ void DropboxAuthenticator::RequestAccountInformation() { void DropboxAuthenticator::RequestAccountInformationFinished( QNetworkReply* reply) { reply->deleteLater(); - QJson::Parser parser; - QVariantMap response = parser.parse(reply).toMap(); - name_ = response["display_name"].toString(); + QJsonDocument document = QJsonDocument::fromBinaryData(reply->readAll()); + name_ = document.object()["display_name"].toString(); emit Finished(); } diff --git a/src/internet/dropbox/dropboxservice.cpp b/src/internet/dropbox/dropboxservice.cpp index 666dbc6e7..8bbd4f611 100644 --- a/src/internet/dropbox/dropboxservice.cpp +++ b/src/internet/dropbox/dropboxservice.cpp @@ -21,8 +21,10 @@ #include #include - -#include +#include +#include +#include +#include #include "core/application.h" #include "core/logging.h" @@ -103,9 +105,11 @@ void DropboxService::RequestFileList() { s.beginGroup(kSettingsGroup); QUrl url = QUrl(QString(kDeltaEndpoint)); + QUrlQuery url_query; if (s.contains("cursor")) { - url.addQueryItem("cursor", s.value("cursor").toString()); + url_query.addQueryItem("cursor", s.value("cursor").toString()); } + url.setQuery(url_query); QNetworkRequest request(url); request.setRawHeader("Authorization", GenerateAuthorisationHeader()); @@ -117,21 +121,22 @@ void DropboxService::RequestFileList() { void DropboxService::RequestFileListFinished(QNetworkReply* reply) { reply->deleteLater(); - QJson::Parser parser; - QVariantMap response = parser.parse(reply).toMap(); - if (response.contains("reset") && response["reset"].toBool()) { + QJsonDocument document = QJsonDocument::fromBinaryData(reply->readAll()); + QJsonObject json_response = document.object(); + + if (json_response.contains("reset") && json_response["reset"].toBool()) { qLog(Debug) << "Resetting Dropbox DB"; library_backend_->DeleteAll(); } QSettings settings; settings.beginGroup(kSettingsGroup); - settings.setValue("cursor", response["cursor"].toString()); + settings.setValue("cursor", json_response["cursor"].toString()); - QVariantList contents = response["entries"].toList(); + QJsonArray contents = json_response["entries"].toArray(); qLog(Debug) << "Delta found:" << contents.size(); - for (const QVariant& c : contents) { - QVariantList item = c.toList(); + for (const QJsonValue& c : contents) { + QJsonArray item = c.toArray(); QString path = item[0].toString(); QUrl url; @@ -148,7 +153,7 @@ void DropboxService::RequestFileListFinished(QNetworkReply* reply) { continue; } - QVariantMap metadata = item[1].toMap(); + QJsonObject metadata = item[1].toObject(); if (metadata["is_dir"].toBool()) { continue; } @@ -168,7 +173,7 @@ void DropboxService::RequestFileListFinished(QNetworkReply* reply) { } } - if (response.contains("has_more") && response["has_more"].toBool()) { + if (json_response.contains("has_more") && json_response["has_more"].toBool()) { RequestFileList(); } else { // Long-poll wait for changes. @@ -181,9 +186,11 @@ void DropboxService::LongPollDelta() { s.beginGroup(kSettingsGroup); QUrl request_url = QUrl(QString(kLongPollEndpoint)); + QUrlQuery url_query; if (s.contains("cursor")) { - request_url.addQueryItem("cursor", s.value("cursor").toString()); + url_query.addQueryItem("cursor", s.value("cursor").toString()); } + request_url.setQuery(url_query); QNetworkRequest request(request_url); request.setRawHeader("Authorization", GenerateAuthorisationHeader()); QNetworkReply* reply = network_->get(request); @@ -193,15 +200,14 @@ void DropboxService::LongPollDelta() { void DropboxService::LongPollFinished(QNetworkReply* reply) { reply->deleteLater(); - QJson::Parser parser; - QVariantMap response = parser.parse(reply).toMap(); - if (response["changes"].toBool()) { + QJsonObject json_response = QJsonDocument::fromBinaryData(reply->readAll()).object(); + if (json_response["changes"].toBool()) { // New changes, we should request deltas again. qLog(Debug) << "Detected new dropbox changes; fetching..."; RequestFileList(); } else { bool ok = false; - int backoff_secs = response["backoff"].toInt(&ok); + int backoff_secs = json_response["backoff"].toString().toInt(&ok); backoff_secs = ok ? backoff_secs : 0; QTimer::singleShot(backoff_secs * 1000, this, SLOT(LongPollDelta())); @@ -219,8 +225,7 @@ QNetworkReply* DropboxService::FetchContentUrl(const QUrl& url) { void DropboxService::FetchContentUrlFinished(QNetworkReply* reply, const QVariantMap& data) { reply->deleteLater(); - QJson::Parser parser; - QVariantMap response = parser.parse(reply).toMap(); + QJsonObject json_response = QJsonDocument::fromBinaryData(reply->readAll()).object(); QFileInfo info(data["path"].toString()); QUrl url; @@ -236,7 +241,7 @@ void DropboxService::FetchContentUrlFinished(QNetworkReply* reply, song.set_ctime(0); MaybeAddFileToDatabase(song, data["mime_type"].toString(), - QUrl::fromEncoded(response["url"].toByteArray()), + QUrl::fromEncoded(json_response["url"].toString().toLatin1()), QString::null); } @@ -244,7 +249,6 @@ QUrl DropboxService::GetStreamingUrlFromSongId(const QUrl& url) { QNetworkReply* reply = FetchContentUrl(url); WaitForSignal(reply, SIGNAL(finished())); - QJson::Parser parser; - QVariantMap response = parser.parse(reply).toMap(); - return QUrl::fromEncoded(response["url"].toByteArray()); + QJsonObject json_response = QJsonDocument::fromJson(reply->readAll()).object(); + return QUrl::fromEncoded(json_response["url"].toString().toLatin1()); } diff --git a/src/internet/googledrive/googledriveclient.cpp b/src/internet/googledrive/googledriveclient.cpp index e93cae44f..66e9a3eba 100644 --- a/src/internet/googledrive/googledriveclient.cpp +++ b/src/internet/googledrive/googledriveclient.cpp @@ -19,7 +19,12 @@ #include "googledriveclient.h" -#include +#include +#include +#include +#include +#include +#include #include "internet/core/oauthenticator.h" #include "core/closure.h" @@ -114,16 +119,15 @@ void Client::FetchUserInfoFinished(ConnectResponse* response, if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) != 200) { qLog(Warning) << "Failed to get user info" << reply->readAll(); } else { - QJson::Parser parser; - bool ok = false; - QVariantMap result = parser.parse(reply, &ok).toMap(); - if (!ok) { + QJsonParseError error; + QJsonDocument document = QJsonDocument::fromJson(reply->readAll(), &error); + if (error.error != QJsonParseError::NoError) { qLog(Error) << "Failed to parse user info reply"; return; } - qLog(Debug) << result; - response->user_email_ = result["email"].toString(); + qLog(Debug) << document; + response->user_email_ = document.object()["email"].toString(); qLog(Debug) << response->user_email_; } emit response->Finished(); @@ -157,16 +161,15 @@ GetFileResponse* Client::GetFile(const QString& file_id) { void Client::GetFileFinished(GetFileResponse* response, QNetworkReply* reply) { reply->deleteLater(); - QJson::Parser parser; - bool ok = false; - QVariantMap result = parser.parse(reply, &ok).toMap(); - if (!ok) { + QJsonParseError error; + QJsonDocument document = QJsonDocument::fromJson(reply->readAll(), &error); + if (error.error != QJsonParseError::NoError) { qLog(Error) << "Failed to fetch file with ID" << response->file_id_; emit response->Finished(); return; } - response->file_ = File(result); + response->file_ = File(document.object().toVariantMap()); emit response->Finished(); } @@ -179,13 +182,16 @@ ListChangesResponse* Client::ListChanges(const QString& cursor) { void Client::MakeListChangesRequest(ListChangesResponse* response, const QString& page_token) { QUrl url(kGoogleDriveChanges); + QUrlQuery url_query; if (!response->cursor().isEmpty()) { - url.addQueryItem("startChangeId", response->cursor()); + url_query.addQueryItem("startChangeId", response->cursor()); } if (!page_token.isEmpty()) { - url.addQueryItem("pageToken", page_token); + url_query.addQueryItem("pageToken", page_token); } + url.setQuery(url_query); + qLog(Debug) << "Requesting changes at:" << response->cursor() << page_token; QNetworkRequest request(url); @@ -201,33 +207,33 @@ void Client::ListChangesFinished(ListChangesResponse* response, QNetworkReply* reply) { reply->deleteLater(); - QJson::Parser parser; - bool ok = false; + QJsonParseError error; + QJsonDocument document = QJsonDocument::fromJson(reply->readAll(), &error); // TODO(John Maguire): Put this on a separate thread as the response could be large. - QVariantMap result = parser.parse(reply, &ok).toMap(); - if (!ok) { + if (error.error != QJsonParseError::NoError) { qLog(Error) << "Failed to fetch changes" << response->cursor(); emit response->Finished(); return; } - if (result.contains("largestChangeId")) { - response->next_cursor_ = result["largestChangeId"].toString(); + QJsonObject json_result = document.object(); + if (json_result.contains("largestChangeId")) { + response->next_cursor_ = json_result["largestChangeId"].toString(); } // Emit the FilesFound signal for the files in the response. FileList files; QList files_deleted; - for (const QVariant& v : result["items"].toList()) { - QVariantMap change = v.toMap(); + for (const QJsonValue & v : json_result["items"].toArray()) { + QJsonObject change = v.toObject(); if (change["deleted"].toBool() || - change["file"].toMap()["labels"].toMap()["trashed"].toBool()) { + change["file"].toObject()["labels"].toObject()["trashed"].toBool()) { QUrl url; url.setScheme("googledrive"); - url.setPath(change["fileId"].toString()); + url.setPath("/" + change["fileId"].toString()); files_deleted << url; } else { - files << File(change["file"].toMap()); + files << File(change["file"].toObject().toVariantMap()); } } @@ -235,8 +241,8 @@ void Client::ListChangesFinished(ListChangesResponse* response, emit response->FilesDeleted(files_deleted); // Get the next page of results if there is one. - if (result.contains("nextPageToken")) { - MakeListChangesRequest(response, result["nextPageToken"].toString()); + if (json_result.contains("nextPageToken")) { + MakeListChangesRequest(response, json_result["nextPageToken"].toString()); } else { emit response->Finished(); } diff --git a/src/internet/googledrive/googledriveservice.cpp b/src/internet/googledrive/googledriveservice.cpp index d7b106677..cc1797b25 100644 --- a/src/internet/googledrive/googledriveservice.cpp +++ b/src/internet/googledrive/googledriveservice.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "core/application.h" #include "core/closure.h" @@ -163,7 +164,7 @@ void GoogleDriveService::FilesFound(const QList& files) { QUrl url; url.setScheme("googledrive"); - url.setPath(file.id()); + url.setPath("/" + file.id()); Song song; // Add some extra tags from the Google Drive metadata. @@ -204,7 +205,9 @@ QUrl GoogleDriveService::GetStreamingUrlFromSongId(const QString& id) { loop.exec(); QUrl url(response->file().download_url()); - url.addQueryItem("access_token", client_->access_token()); + QUrlQuery url_query(url); + url_query.addQueryItem("access_token", client_->access_token()); + url.setQuery(url_query); return url; } diff --git a/src/internet/lastfm/lastfmcompat.h b/src/internet/lastfm/lastfmcompat.h index 7ca9acf5d..c0681869f 100644 --- a/src/internet/lastfm/lastfmcompat.h +++ b/src/internet/lastfm/lastfmcompat.h @@ -24,21 +24,21 @@ #include "fixlastfm.h" #ifdef HAVE_LIBLASTFM1 -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #else -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #endif namespace lastfm { diff --git a/src/internet/lastfm/lastfmservice.cpp b/src/internet/lastfm/lastfmservice.cpp index 243e5858d..11d20c905 100644 --- a/src/internet/lastfm/lastfmservice.cpp +++ b/src/internet/lastfm/lastfmservice.cpp @@ -213,7 +213,7 @@ void LastFMService::UpdateSubscriberStatusFinished(QNetworkReply* reply) { QUrl LastFMService::FixupUrl(const QUrl& url) { QUrl ret; - ret.setEncodedUrl(url.toEncoded().replace( + ret.setUrl(url.toEncoded().replace( "USERNAME", QUrl::toPercentEncoding(lastfm::ws::Username))); return ret; } diff --git a/src/internet/seafile/seafileservice.cpp b/src/internet/seafile/seafileservice.cpp index 27a5b4bed..4ce2b802e 100644 --- a/src/internet/seafile/seafileservice.cpp +++ b/src/internet/seafile/seafileservice.cpp @@ -22,8 +22,11 @@ #include -#include #include +#include +#include +#include +#include #include "core/application.h" #include "core/player.h" @@ -80,7 +83,7 @@ bool SeafileService::has_credentials() const { void SeafileService::AddAuthorizationHeader(QNetworkRequest* request) const { request->setRawHeader("Authorization", - QString("Token %1").arg(access_token_).toAscii()); + QString("Token %1").arg(access_token_).toLatin1()); } void SeafileService::ForgetCredentials() { @@ -98,13 +101,15 @@ void SeafileService::ForgetCredentials() { bool SeafileService::GetToken(const QString& mail, const QString& password, const QString& server) { QUrl url(server + kAuthTokenUrl); + QUrlQuery url_query; + + url_query.addQueryItem("username", mail); + url_query.addQueryItem("password", password); + QNetworkRequest request(url); AddAuthorizationHeader(&request); - url.addQueryItem("username", mail); - url.addQueryItem("password", password); - - QNetworkReply* reply = network_->post(request, url.encodedQuery()); + QNetworkReply* reply = network_->post(request, url_query.toString().toLatin1()); WaitForSignal(reply, SIGNAL(finished())); if (!CheckReply(&reply)) { @@ -114,11 +119,10 @@ bool SeafileService::GetToken(const QString& mail, const QString& password, reply->deleteLater(); - QJson::Parser parser; - QVariantMap response = parser.parse(reply->readAll()).toMap(); + QJsonObject json_response = QJsonDocument::fromJson(reply->readAll()).object(); // Because the server responds "token" - access_token_ = response["token"].toString().replace("\"", ""); + access_token_ = json_response["token"].toString().replace("\"", ""); if (access_token_.isEmpty()) { return false; @@ -156,11 +160,11 @@ void SeafileService::GetLibrariesFinished(QNetworkReply* reply) { // key : id, value : name QMap libraries; QByteArray data = reply->readAll(); - QJson::Parser parser; - QList repos = parser.parse(data).toList(); - for (int i = 0; i < repos.size(); ++i) { - QVariantMap repo = repos.at(i).toMap(); + QJsonArray json_repos = QJsonDocument::fromJson(data).array(); + + for (const QJsonValue & json_repo: json_repos) { + QJsonObject repo = json_repo.toObject(); QString repo_name = repo["name"].toString(), repo_id = repo["id"].toString(); @@ -246,7 +250,9 @@ void SeafileService::UpdateLibrariesInProgress( QNetworkReply* SeafileService::PrepareFetchFolderItems(const QString& library, const QString& path) { QUrl url(server_ + QString(kFolderItemsUrl).arg(library)); - url.addQueryItem("p", path); + QUrlQuery url_query; + url_query.addQueryItem("p", path); + url.setQuery(url_query); QNetworkRequest request(url); AddAuthorizationHeader(&request); @@ -277,12 +283,11 @@ void SeafileService::FetchAndCheckFolderItemsFinished( QByteArray data = reply->readAll(); - QJson::Parser parser; - QList variant_entries = parser.parse(data).toList(); + QJsonArray json_entries = QJsonDocument::fromJson(data).array(); SeafileTree::Entries entries; - for (const QVariant& e : variant_entries) { - QVariantMap entry = e.toMap(); + for (const QJsonValue& e : json_entries) { + QJsonObject entry = e.toObject(); SeafileTree::Entry::Type entry_type = SeafileTree::Entry::StringToType(entry["type"].toString()); QString entry_name = entry["name"].toString(); @@ -322,14 +327,13 @@ void SeafileService::AddRecursivelyFolderItemsFinished(QNetworkReply* reply, reply->deleteLater(); QByteArray data = reply->readAll(); - QJson::Parser parser; - QList entries = parser.parse(data).toList(); + QJsonArray json_entries = QJsonDocument::fromJson(data).array(); - for (const QVariant& e : entries) { - QVariantMap entry_map = e.toMap(); + for (const QJsonValue& e : json_entries) { + QJsonObject json_entry = e.toObject(); SeafileTree::Entry::Type entry_type = - SeafileTree::Entry::StringToType(entry_map["type"].toString()); - QString entry_name = entry_map["name"].toString(); + SeafileTree::Entry::StringToType(json_entry["type"].toString()); + QString entry_name = json_entry["name"].toString(); // We just want libraries/directories and files which could be songs. if (entry_type == SeafileTree::Entry::NONE) { @@ -339,7 +343,7 @@ void SeafileService::AddRecursivelyFolderItemsFinished(QNetworkReply* reply, continue; } - SeafileTree::Entry entry(entry_name, entry_map["id"].toString(), + SeafileTree::Entry entry(entry_name, json_entry["id"].toString(), entry_type); // If AddEntry was not successful we stop @@ -360,7 +364,9 @@ void SeafileService::AddRecursivelyFolderItemsFinished(QNetworkReply* reply, QNetworkReply* SeafileService::PrepareFetchContentForFile( const QString& library, const QString& filepath) { QUrl content_url(server_ + QString(kFileContentUrl).arg(library)); - content_url.addQueryItem("p", filepath); + QUrlQuery content_url_query; + content_url_query.addQueryItem("p", filepath); + content_url.setQuery(content_url_query); QNetworkRequest request(content_url); AddAuthorizationHeader(&request); @@ -397,23 +403,22 @@ void SeafileService::MaybeAddFileEntryInProgress(QNetworkReply* reply, QByteArray data = reply->readAll(); - QJson::Parser parser; - QVariantMap entry_detail_map = parser.parse(data).toMap(); + QJsonObject json_entry_detail = QJsonDocument::fromJson(data).object(); QUrl url; url.setScheme("seafile"); - url.setPath("/" + library + path + entry_detail_map["name"].toString()); + url.setPath("/" + library + path + json_entry_detail["name"].toString()); Song song; song.set_url(url); song.set_ctime(0); - song.set_mtime(entry_detail_map["mtime"].toInt()); - song.set_filesize(entry_detail_map["size"].toInt()); - song.set_title(entry_detail_map["name"].toString()); + song.set_mtime(json_entry_detail["mtime"].toInt()); + song.set_filesize(json_entry_detail["size"].toInt()); + song.set_title(json_entry_detail["name"].toString()); // Get the download url of the entry reply = PrepareFetchContentUrlForFile( - library, path + entry_detail_map["name"].toString()); + library, path + json_entry_detail["name"].toString()); NewClosure( reply, SIGNAL(finished()), this, SLOT(FetchContentUrlForFileFinished(QNetworkReply*, Song, QString)), @@ -423,7 +428,9 @@ void SeafileService::MaybeAddFileEntryInProgress(QNetworkReply* reply, QNetworkReply* SeafileService::PrepareFetchContentUrlForFile( const QString& library, const QString& filepath) { QUrl content_url(server_ + QString(kFileUrl).arg(library)); - content_url.addQueryItem("p", filepath); + QUrlQuery content_url_query; + content_url_query.addQueryItem("p", filepath); + content_url.setQuery(content_url_query); QNetworkRequest request(content_url); AddAuthorizationHeader(&request); @@ -589,7 +596,7 @@ bool SeafileService::CheckReply(QNetworkReply** reply, int tries) { // Unknown, 404 ... (*reply)->deleteLater(); - qLog(Warning) << "Error for reply : " << status_code_variant.toInt(); + qLog(Warning) << "Error with the reply : " << status_code_variant.toInt(); return false; } diff --git a/src/internet/skydrive/skydriveservice.cpp b/src/internet/skydrive/skydriveservice.cpp index 91bfce90c..c8f001429 100644 --- a/src/internet/skydrive/skydriveservice.cpp +++ b/src/internet/skydrive/skydriveservice.cpp @@ -19,9 +19,12 @@ #include "skydriveservice.h" -#include +#include +#include +#include +#include -#include +#include #include "core/application.h" #include "core/player.h" @@ -107,10 +110,9 @@ void SkydriveService::AddAuthorizationHeader(QNetworkRequest* request) { void SkydriveService::FetchUserInfoFinished(QNetworkReply* reply) { reply->deleteLater(); - QJson::Parser parser; - QVariantMap response = parser.parse(reply).toMap(); + QJsonObject json_response = QJsonDocument::fromBinaryData(reply->readAll()).object(); - QString name = response["name"].toString(); + QString name = json_response["name"].toString(); if (!name.isEmpty()) { QSettings s; s.beginGroup(kSettingsGroup); @@ -124,7 +126,9 @@ void SkydriveService::FetchUserInfoFinished(QNetworkReply* reply) { void SkydriveService::ListFiles(const QString& folder) { QUrl url(QString(kSkydriveBase) + folder + "/files"); - url.addQueryItem("filter", "audio,folders"); + QUrlQuery url_query; + url_query.addQueryItem("filter", "audio,folders"); + url.setQuery(url_query); QNetworkRequest request(url); AddAuthorizationHeader(&request); @@ -135,27 +139,26 @@ void SkydriveService::ListFiles(const QString& folder) { void SkydriveService::ListFilesFinished(QNetworkReply* reply) { reply->deleteLater(); - QJson::Parser parser; - QVariantMap response = parser.parse(reply).toMap(); + QJsonObject json_response = QJsonDocument::fromBinaryData(reply->readAll()).object(); - QVariantList files = response["data"].toList(); - for (const QVariant& f : files) { - QVariantMap file = f.toMap(); + QJsonArray files = json_response["data"].toArray(); + for (const QJsonValue& f : files) { + QJsonObject file = f.toObject(); if (file["type"].toString() == "audio") { QString mime_type = GuessMimeTypeForFile(file["name"].toString()); QUrl url; url.setScheme("skydrive"); - url.setPath(file["id"].toString()); + url.setPath("/" + file["id"].toString()); Song song; song.set_url(url); - song.set_ctime(file["created_time"].toDateTime().toTime_t()); - song.set_mtime(file["updated_time"].toDateTime().toTime_t()); + song.set_ctime(QDateTime::fromString(file["created_time"].toString()).toTime_t()); + song.set_mtime(QDateTime::fromString(file["updated_time"].toString()).toTime_t()); song.set_comment(file["description"].toString()); song.set_filesize(file["size"].toInt()); song.set_title(file["name"].toString()); - QUrl download_url = file["source"].toUrl(); + QUrl download_url(file["source"].toString()); // HTTPS appears to be broken somehow between Qt & Skydrive downloads. // Fortunately, just changing the scheme to HTTP works. download_url.setScheme("http"); @@ -175,9 +178,8 @@ QUrl SkydriveService::GetStreamingUrlFromSongId(const QString& file_id) { std::unique_ptr reply(network_->get(request)); WaitForSignal(reply.get(), SIGNAL(finished())); - QJson::Parser parser; - QVariantMap response = parser.parse(reply.get()).toMap(); - return response["source"].toUrl(); + QJsonObject json_response = QJsonDocument::fromBinaryData(reply.get()->readAll()).object(); + return QUrl(json_response["source"].toString()); } void SkydriveService::EnsureConnected() { diff --git a/src/internet/vk/vkconnection.cpp b/src/internet/vk/vkconnection.cpp index d44a65e65..3fd8353ea 100644 --- a/src/internet/vk/vkconnection.cpp +++ b/src/internet/vk/vkconnection.cpp @@ -21,8 +21,10 @@ #include #include - -#include +#include +#include +#include +#include #include "core/closure.h" #include "core/logging.h" @@ -95,18 +97,22 @@ bool VkConnection::hasAccount() { QNetworkRequest VkConnection::makeRequest(const QString& method, const QVariantMap& args) { QUrl url = kApiUrl; - url.setPath(url.path() % QLatin1Literal("/") % method); + url.setPath(url.path() + "/" + method); + QUrlQuery url_query; for (auto it = args.constBegin(); it != args.constEnd(); ++it) { - url.addEncodedQueryItem(QUrl::toPercentEncoding(it.key()), + url_query.addQueryItem(QUrl::toPercentEncoding(it.key()), QUrl::toPercentEncoding(it.value().toString())); } - url.addEncodedQueryItem("access_token", access_token_); + url_query.addQueryItem("access_token", access_token_); + url.setQuery(url_query); return QNetworkRequest(url); } void VkConnection::decorateRequest(QNetworkRequest& request) { QUrl url = request.url(); - url.addEncodedQueryItem("access_token", access_token_); + QUrlQuery url_query(url); + url_query.addQueryItem("access_token", access_token_); + url.setQuery(url_query); request.setUrl(url); } @@ -115,11 +121,13 @@ void VkConnection::requestAccessToken() { server->Listen(); QUrl url = kVkOAuthEndpoint; - url.addQueryItem("client_id", kAppID); - url.addQueryItem("scope", + QUrlQuery url_query; + url_query.addQueryItem("client_id", kAppID); + url_query.addQueryItem("scope", Vreen::flagsToStrList(kScopes, kScopeNames).join(",")); - url.addQueryItem("redirect_uri", server->url().toString()); - url.addQueryItem("response_type", "code"); + url_query.addQueryItem("redirect_uri", server->url().toString()); + url_query.addQueryItem("response_type", "code"); + url.setQuery(url_query); qLog(Debug) << "Try to login to Vk.com" << url; @@ -130,13 +138,16 @@ void VkConnection::requestAccessToken() { } void VkConnection::codeRecived(LocalRedirectServer* server, QUrl redirect_uri) { - if (server->request_url().hasQueryItem("code")) { - code_ = server->request_url().queryItemValue("code").toUtf8(); + QUrlQuery url_query_server(server->request_url()); + if (url_query_server.hasQueryItem("code")) { + code_ = url_query_server.queryItemValue("code").toUtf8(); QUrl url = kVkOAuthTokenEndpoint; - url.addQueryItem("client_id", kAppID); - url.addQueryItem("client_secret", kAppSecret); - url.addQueryItem("code", QString::fromUtf8(code_)); - url.addQueryItem("redirect_uri", redirect_uri.toString()); + QUrlQuery url_query; + url_query.addQueryItem("client_id", kAppID); + url_query.addQueryItem("client_secret", kAppSecret); + url_query.addQueryItem("code", QString::fromUtf8(code_)); + url_query.addQueryItem("redirect_uri", redirect_uri.toString()); + url.setQuery(url_query); qLog(Debug) << "Getting access token" << url; QNetworkRequest request(url); @@ -159,21 +170,22 @@ void VkConnection::accessTokenRecived(QNetworkReply* reply) { return; } - QJson::Parser parser; - bool ok = false; QByteArray reply_data = reply->readAll(); - QVariantMap result = parser.parse(reply_data, &ok).toMap(); - if (!ok) { + QJsonParseError error; + QJsonDocument document = QJsonDocument::fromJson(reply_data, &error); + if (error.error != QJsonParseError::NoError) { qLog(Error) << "Failed to parse oauth reply" << reply_data; emit setConnectionState(Vreen::Client::StateOffline); clear(); return; } - qLog(Debug) << result; - access_token_ = result["access_token"].toByteArray(); - expires_in_ = result["expires_in"].toUInt(); - uid_ = result["user_id"].toInt(); + QJsonObject json_result = document.object(); + qLog(Debug) << json_result; + + access_token_ = json_result["access_token"].toString().toLatin1(); + expires_in_ = json_result["expires_in"].toString().toUInt(); + uid_ = json_result["user_id"].toInt(); if (expires_in_) { expires_in_ += QDateTime::currentDateTime().toTime_t(); diff --git a/src/internet/vk/vkmusiccache.cpp b/src/internet/vk/vkmusiccache.cpp index 62033948c..c802818e3 100644 --- a/src/internet/vk/vkmusiccache.cpp +++ b/src/internet/vk/vkmusiccache.cpp @@ -130,7 +130,7 @@ void VkMusicCache::DownloadNext() { void VkMusicCache::DownloadProgress(qint64 bytesReceived, qint64 bytesTotal) { if (bytesTotal) { - int progress = qRound(100 * bytesReceived / bytesTotal); + int progress = qRound(100. * bytesReceived / bytesTotal); app_->task_manager()->SetTaskProgress(task_id, progress, 100); } } diff --git a/src/moodbar/moodbarpipeline.cpp b/src/moodbar/moodbarpipeline.cpp index 7163efda1..d5409211d 100644 --- a/src/moodbar/moodbarpipeline.cpp +++ b/src/moodbar/moodbarpipeline.cpp @@ -57,7 +57,7 @@ bool MoodbarPipeline::IsAvailable() { GstElement* MoodbarPipeline::CreateElement(const QString& factory_name) { GstElement* ret = - gst_element_factory_make(factory_name.toAscii().constData(), nullptr); + gst_element_factory_make(factory_name.toLatin1().constData(), nullptr); if (ret) { gst_bin_add(GST_BIN(pipeline_), ret); diff --git a/src/ui/ripcd.cpp b/src/ui/ripcd.cpp index bf8a329a8..cbcd62670 100644 --- a/src/ui/ripcd.cpp +++ b/src/ui/ripcd.cpp @@ -75,11 +75,11 @@ RipCD::RipCD(QWidget* parent) ui_->setupUi(this); // Set column widths in the QTableWidget. - ui_->tableWidget->horizontalHeader()->setResizeMode( + ui_->tableWidget->horizontalHeader()->setSectionResizeMode( kCheckboxColumn, QHeaderView::ResizeToContents); - ui_->tableWidget->horizontalHeader()->setResizeMode( + ui_->tableWidget->horizontalHeader()->setSectionResizeMode( kTrackNumberColumn, QHeaderView::ResizeToContents); - ui_->tableWidget->horizontalHeader()->setResizeMode(kTrackTitleColumn, + ui_->tableWidget->horizontalHeader()->setSectionResizeMode(kTrackTitleColumn, QHeaderView::Stretch); // Add a rip button diff --git a/src/widgets/osd_x11.cpp b/src/widgets/osd_x11.cpp index a79bc841c..d5e10436b 100644 --- a/src/widgets/osd_x11.cpp +++ b/src/widgets/osd_x11.cpp @@ -66,7 +66,7 @@ QDBusArgument& operator<<(QDBusArgument& arg, const QImage& image) { int channels = i.isGrayscale() ? 1 : (i.hasAlphaChannel() ? 4 : 3); arg << i.depth() / channels; arg << channels; - arg << QByteArray(reinterpret_cast(i.bits()), i.numBytes()); + arg << QByteArray(reinterpret_cast(i.bits()), i.byteCount()); arg.endStructure(); return arg; } diff --git a/src/wiimotedev/wiimotesettingspage.cpp b/src/wiimotedev/wiimotesettingspage.cpp index 3c9adfcf3..77f780aab 100644 --- a/src/wiimotedev/wiimotesettingspage.cpp +++ b/src/wiimotedev/wiimotesettingspage.cpp @@ -26,7 +26,7 @@ WiimoteSettingsPage::WiimoteSettingsPage(SettingsDialog* dialog) : SettingsPage(dialog), ui_(new Ui_WiimoteSettingsPage) { ui_->setupUi(this); - ui_->list->header()->setResizeMode(QHeaderView::ResizeToContents); + ui_->list->header()->setSectionResizeMode(QHeaderView::ResizeToContents); setWindowIcon(QIcon(":/icons/32x32/wiimotedev.png")); text_buttons_.insert(WIIMOTE_BTN_1, "Wiiremote 1"); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7c46c02d2..95c954d00 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -74,14 +74,14 @@ qt5_wrap_cpp(TESTUTILS-SOURCES-MOC ${TESTUTILS-MOC-HEADERS}) add_library(test_utils STATIC EXCLUDE_FROM_ALL ${TESTUTILS-SOURCES} ${TESTUTILS-SOURCES-MOC}) target_link_libraries(test_utils ${GMOCK_LIBRARIES} ${QT_LIBRARIES} ${QT_QTTEST_LIBRARY}) -add_custom_target(test - echo "Running tests" +add_custom_target(clementine_test + echo "Running Clementine tests" WORKING_DIRECTORY ${CURRENT_BINARY_DIR} ) add_custom_target(build_tests WORKING_DIRECTORY ${CURRENT_BINARY_DIR} ) -add_dependencies(test build_tests) +add_dependencies(clementine_test build_tests) qt5_add_resources(TEST-RESOURCE-SOURCES data/testdata.qrc) @@ -112,7 +112,7 @@ macro(add_test_file test_source gui_required) set_target_properties(${TEST_NAME} PROPERTIES COMPILE_FLAGS "-Wno-bool-conversions") endif (SUPPORTS_NOBOOL) - add_custom_command(TARGET test POST_BUILD + add_custom_command(TARGET clementine_test POST_BUILD COMMAND ./${TEST_NAME}${CMAKE_EXECUTABLE_SUFFIX}) add_dependencies(build_tests ${TEST_NAME}) endmacro (add_test_file)