diff --git a/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_authenticationdialog.cpp b/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_authenticationdialog.cpp index cf921472f8..2ce707863f 100644 --- a/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_authenticationdialog.cpp +++ b/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_authenticationdialog.cpp @@ -1,247 +1,247 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2011-02-19 * Description : a tool to export images to VKontakte web service * * Copyright (C) 2010 by Thomas McGuire * Copyright (C) 2011-2015 by Alexander Potashev * Copyright (C) 2011-2020 by Gilles Caulier * * This program 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 2, or (at your option) any later version. * * This program 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. * * ============================================================ */ #include "vkontakte_authenticationdialog.h" #include "digikam_config.h" // Qt includes #ifdef HAVE_QWEBENGINE # include # include # include # include #else # include #endif #include #include #include #include #include #include #include // KDE incudes #include // Local includes #include "digikam_debug.h" #include "vkontakte_util.h" namespace Vkontakte { class Q_DECL_HIDDEN AuthenticationDialog::Private { public: QString appId; Vkontakte::AppPermissions::Value permissions; QString displayMode; #ifdef HAVE_QWEBENGINE QWebEngineView* webView; #else QWebView* webView; #endif QProgressBar* progressBar; QString error; QString errorDescription; }; AuthenticationDialog::AuthenticationDialog(QWidget* const parent) : QDialog(parent), d(new Private) { d->displayMode = QLatin1String("page"); setWindowTitle(i18nc("@title:window", "Authenticate with VKontakte")); setAttribute(Qt::WA_DeleteOnClose, true); QWidget* const progressWidget = new QWidget(this); QHBoxLayout* const progressLayout = new QHBoxLayout(progressWidget); progressLayout->setContentsMargins(QMargins()); #ifdef HAVE_QWEBENGINE d->webView = new QWebEngineView(this); d->webView->page()->profile()->cookieStore()->deleteAllCookies(); #else d->webView = new QWebView(this); d->webView->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true); d->webView->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar()); #endif d->progressBar = new QProgressBar(this); d->progressBar->setRange(0, 100); QLabel* const progressLabel = new QLabel(i18n("Loading Page:"), this); progressLayout->addWidget(progressLabel); progressLayout->addWidget(d->progressBar); // Buttons QDialogButtonBox* const buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel, this); connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); // Layout QVBoxLayout* const layout = new QVBoxLayout(this); layout->addWidget(progressWidget); layout->addWidget(d->webView); layout->addWidget(buttonBox); setLayout(layout); connect(buttonBox, &QDialogButtonBox::rejected, this, &AuthenticationDialog::canceled); connect(d->webView, SIGNAL(urlChanged(QUrl)), this, SLOT(urlChanged(QUrl))); connect(d->webView, SIGNAL(loadStarted()), progressWidget, SLOT(show())); connect(d->webView, SIGNAL(loadFinished(bool)), progressWidget, SLOT(hide())); connect(d->webView, SIGNAL(loadProgress(int)), d->progressBar, SLOT(setValue(int))); connect(d->webView, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool))); } AuthenticationDialog::~AuthenticationDialog() { delete d; } void AuthenticationDialog::setAppId(const QString& appId) { d->appId = appId; } void Vkontakte::AuthenticationDialog::setPermissions(Vkontakte::AppPermissions::Value permissions) { d->permissions = permissions; } // display= {page, popup, touch, wap} void AuthenticationDialog::setDisplayMode(const QString& displayMode) { d->displayMode = displayMode; } void AuthenticationDialog::start() { Q_ASSERT(!d->appId.isEmpty()); const QString url = QString::fromUtf8( "http://oauth.vk.com/authorize?" "client_id=%1&" "scope=%2&" "redirect_uri=http://oauth.vk.com/blank.html&" "display=%3&" "response_type=token") .arg(d->appId) - .arg(appPermissionsToStringList(d->permissions).join(QStringLiteral(","))) + .arg(appPermissionsToStringList(d->permissions).join(QLatin1String(","))) .arg(d->displayMode); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Showing" << url; d->webView->setUrl(QUrl::fromUserInput(url)); show(); } void AuthenticationDialog::showErrorDialog() { hide(); const QString details = i18n("VKontakte Error Description: %1
" "VKontakte Error: %2
", d->errorDescription, d->error); QMessageBox::warning(this, i18n("Authentication with VKontakte was not successful."), details, i18nc("@title:window", "Authentication Problem")); emit canceled(); close(); } void AuthenticationDialog::urlChanged(const QUrl& url) { qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Navigating to" << url; if ((url.host() == QLatin1String("oauth.vk.com")) && (url.path() == QLatin1String("/blank.html"))) { const QUrlQuery query(url); d->error = query.queryItemValue(QLatin1String("error")); d->errorDescription = query.queryItemValue(QLatin1String("error_description")).replace(QLatin1Char('+'), QLatin1Char(' ')); if (!d->error.isEmpty() || !d->errorDescription.isEmpty()) { QTimer::singleShot(0, this, SLOT(showErrorDialog())); return; } // The URL comes in the form "bla#access_token=bla&expires_in=foo", we need to convert from // # to ? const QUrl fixedURL = QUrl::fromUserInput(url.toString().replace(QLatin1Char('#'), QLatin1Char('?'))); const QUrlQuery fixedQuery(fixedURL); const QString accessToken = fixedQuery.queryItemValue(QLatin1String("access_token")); const QString tokenExpiresIn = fixedQuery.queryItemValue(QLatin1String("expires_in")); // TODO: use this for something? if (!accessToken.isEmpty()) { emit authenticated(accessToken); QTimer::singleShot(0, this, SLOT(close())); } } } void AuthenticationDialog::loadFinished(bool ok) { if (!ok) { hide(); QMessageBox::critical(parentWidget(), i18n("There was a network error when trying to authenticate with VKontakte web service."), i18nc("@title:window", "Network Error")); emit canceled(); close(); } } } // namespace Vkontakte diff --git a/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_createalbumjob.cpp b/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_createalbumjob.cpp index 13208bae05..7d420ec5b9 100644 --- a/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_createalbumjob.cpp +++ b/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_createalbumjob.cpp @@ -1,83 +1,83 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2011-02-19 * Description : a tool to export images to VKontakte web service * * Copyright (C) 2011-2015 by Alexander Potashev * Copyright (C) 2011-2020 by Gilles Caulier * * This program 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 2, or (at your option) any later version. * * This program 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. * * ============================================================ */ #include "vkontakte_createalbumjob.h" namespace Vkontakte { class Q_DECL_HIDDEN CreateAlbumJob::Private { public: AlbumInfo album; }; CreateAlbumJob::CreateAlbumJob(const QString& accessToken, const QString& title, const QString& description, int privacy, int comment_privacy) - : VkontakteJob(accessToken, QStringLiteral("photos.createAlbum"), true), + : VkontakteJob(accessToken, QLatin1String("photos.createAlbum"), true), d(new Private) { - addQueryItem(QStringLiteral("title"), title); + addQueryItem(QLatin1String("title"), title); if (!description.isEmpty()) { addQueryItem(QLatin1String("description"), description); } if (privacy != AlbumInfo::PRIVACY_UNKNOWN) { addQueryItem(QLatin1String("privacy"), QString::number(privacy)); } if (comment_privacy != AlbumInfo::PRIVACY_UNKNOWN) { addQueryItem(QLatin1String("comment_privacy"), QString::number(comment_privacy)); } } CreateAlbumJob::~CreateAlbumJob() { delete d; } void CreateAlbumJob::handleData(const QJsonValue& data) { if (!data.isObject()) { // TODO: report error!!! return; } d->album = AlbumInfo(data.toObject()); } AlbumInfo CreateAlbumJob::album() const { return d->album; } } // namespace Vkontakte diff --git a/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_photoinfo.cpp b/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_photoinfo.cpp index f3b0ee1eba..c7f4a5a8dd 100644 --- a/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_photoinfo.cpp +++ b/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_photoinfo.cpp @@ -1,104 +1,104 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2011-02-19 * Description : a tool to export images to VKontakte web service * * Copyright (C) 2011-2015 by Alexander Potashev * Copyright (C) 2011-2020 by Gilles Caulier * * This program 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 2, or (at your option) any later version. * * This program 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. * * ============================================================ */ #include "vkontakte_photoinfo.h" // Local includes #include "vkontakte_util.h" namespace Vkontakte { class Q_DECL_HIDDEN PhotoInfo::Private : public QSharedData { public: QJsonObject jsonData; }; PhotoInfo::PhotoInfo() : d(new Private) { } PhotoInfo::PhotoInfo(const QJsonObject& jsonData) : d(new Private) { d->jsonData = jsonData; } PhotoInfo::PhotoInfo(const PhotoInfo& other) { d = other.d; } PhotoInfo::~PhotoInfo() { } PhotoInfo &PhotoInfo::operator=(const PhotoInfo& other) { if (this != &other) { d = other.d; } return *this; } int PhotoInfo::pid() const { - return d->jsonData.value(QStringLiteral("pid")).toInt(-1); + return d->jsonData.value(QLatin1String("pid")).toInt(-1); } QUrl PhotoInfo::urlMaxResolution() const { // Photo URLs in the order of decresing size QStringList srcKeys; - srcKeys.append(QStringLiteral("src_xxxbig")); - srcKeys.append(QStringLiteral("src_xxbig")); - srcKeys.append(QStringLiteral("src_xbig")); - srcKeys.append(QStringLiteral("src_big")); - srcKeys.append(QStringLiteral("src")); - srcKeys.append(QStringLiteral("src_small")); + srcKeys.append(QLatin1String("src_xxxbig")); + srcKeys.append(QLatin1String("src_xxbig")); + srcKeys.append(QLatin1String("src_xbig")); + srcKeys.append(QLatin1String("src_big")); + srcKeys.append(QLatin1String("src")); + srcKeys.append(QLatin1String("src_small")); foreach (const QString& key, srcKeys) { if (!d->jsonData.contains(key)) { continue; } QJsonValue value = d->jsonData.value(key); if (value.isString()) { return QUrl(value.toString()); } } return QUrl(); } } // namespace Vkontakte diff --git a/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_photolistjob.cpp b/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_photolistjob.cpp index 1ba95cb192..ac66f3c70c 100644 --- a/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_photolistjob.cpp +++ b/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_photolistjob.cpp @@ -1,93 +1,93 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2011-02-19 * Description : a tool to export images to VKontakte web service * * Copyright (C) 2011-2015 by Alexander Potashev * Copyright (C) 2011-2020 by Gilles Caulier * * This program 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 2, or (at your option) any later version. * * This program 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. * * ============================================================ */ #include "vkontakte_photolistjob.h" // Qt includes #include // Local includes #include "vkontakte_util.h" namespace Vkontakte { class Q_DECL_HIDDEN PhotoListJob::Private { public: QList list; }; // http://vk.com/dev/photos.get // // The API also allows to set "limit" and "offset", but that // does not seem to be useful. PhotoListJob::PhotoListJob(const QString& accessToken, int uid, int aid, const QList& pids) - : VkontakteJob(accessToken, QStringLiteral("photos.get")), + : VkontakteJob(accessToken, QLatin1String("photos.get")), d(new Private) { - addQueryItem(QStringLiteral("uid"), QString::number(uid)); - addQueryItem(QStringLiteral("aid"), QString::number(aid)); + addQueryItem(QLatin1String("uid"), QString::number(uid)); + addQueryItem(QLatin1String("aid"), QString::number(aid)); if (!pids.empty()) { - addQueryItem(QStringLiteral("pids"), joinIntegers(pids)); + addQueryItem(QLatin1String("pids"), joinIntegers(pids)); } } PhotoListJob::~PhotoListJob() { delete d; } void PhotoListJob::handleData(const QJsonValue& data) { if (!data.isArray()) { // TODO: report error!!! return; } foreach (const QJsonValue& item, data.toArray()) { if (!item.isObject()) { // TODO: report error!!! d->list.clear(); return; } d->list.append(PhotoInfo(item.toObject())); } } QList PhotoListJob::list() const { return d->list; } } // namespace Vkontakte diff --git a/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_photopostjob.cpp b/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_photopostjob.cpp index 1577d24b7e..f2e9a45010 100644 --- a/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_photopostjob.cpp +++ b/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_photopostjob.cpp @@ -1,255 +1,255 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2011-02-19 * Description : a tool to export images to VKontakte web service * * Copyright (C) 2011-2015 by Alexander Potashev * Copyright (C) 2011-2020 by Gilles Caulier * * This program 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 2, or (at your option) any later version. * * This program 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. * * ============================================================ */ #include "vkontakte_photopostjob.h" // Qt includes #include #include #include #include #include #include #include #include // KDE includes #include #include // Local includes #include "digikam_debug.h" namespace Vkontakte { PhotoPostJob::PhotoPostJob(Vkontakte::UploadPhotosJob::Dest dest, const QUrl& url, const QStringList& files) { m_url = url; m_files = files; m_dest = dest; setCapabilities(KJob::Killable); m_ok = true; if ((files.size() <= 0) || (files.size() > 5)) { m_ok = false; } } void PhotoPostJob::handleError(const QJsonValue& data) { int error_code = -1; QString error_msg; if (data.isUndefined()) { qCWarning(DIGIKAM_WEBSERVICES_LOG) << "Response from server has unexpected format"; } else { const QVariantMap errorMap = data.toVariant().toMap(); - error_code = errorMap[QStringLiteral("error_code")].toInt(); - error_msg = errorMap[QStringLiteral("error_msg")].toString(); + error_code = errorMap[QLatin1String("error_code")].toInt(); + error_msg = errorMap[QLatin1String("error_msg")].toString(); qCWarning(DIGIKAM_WEBSERVICES_LOG) << "An error of type" << error_code << "occurred:" << error_msg; } setError(KJob::UserDefinedError); if (data.isUndefined()) { setErrorText(i18n( "Response from the VKontakte server has unexpected format. " "Please report this problem against product libkvkontakte " "at the KDE bug tracker.", - QStringLiteral("http://bugs.kde.org/"))); + QLatin1String("http://bugs.kde.org/"))); } else { setErrorText(i18n( "The VKontakte server returned an error " "of type %1 in reply to uploading to URL %2: %3", error_code, m_url.toString(), error_msg)); } } bool PhotoPostJob::appendFile(QHttpMultiPart* multiPart, const QString& header, const QString& path) { QString mime = QMimeDatabase().mimeTypeForUrl(QUrl(path)).name(); if (mime.isEmpty()) { return false; } QFileInfo fileInfo(path); QHttpPart imagePart; imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, - QVariant(QStringLiteral("form-data; name=\"%1\"; filename=\"%2\"") + QVariant(QString::fromUtf8("form-data; name=\"%1\"; filename=\"%2\"") .arg(header).arg(fileInfo.fileName()))); imagePart.setHeader(QNetworkRequest::ContentLengthHeader, QVariant(fileInfo.size())); imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(mime)); QFile* const file = new QFile(path); if (!file->open(QIODevice::ReadOnly)) { delete file; return false; } imagePart.setBodyDevice(file); file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart multiPart->append(imagePart); return true; } void PhotoPostJob::start() { if (!m_ok) { setError(UserDefinedError); - setErrorText(QStringLiteral("Internal error")); + setErrorText(QLatin1String("Internal error")); emitResult(); } QHttpMultiPart* const multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); switch (m_dest) { case Vkontakte::UploadPhotosJob::DEST_ALBUM: { // "file1" .. "file5" for (int i = 0 ; i < m_files.size() ; i++) { - if (!appendFile(multiPart, QStringLiteral("file%1").arg(i + 1), m_files[i])) + if (!appendFile(multiPart, QString::fromLatin1("file%1").arg(i + 1), m_files[i])) { m_ok = false; break; } } break; } case Vkontakte::UploadPhotosJob::DEST_PROFILE: case Vkontakte::UploadPhotosJob::DEST_WALL: { // "photo" - if (!appendFile(multiPart, QStringLiteral("photo"), m_files[0])) + if (!appendFile(multiPart, QLatin1String("photo"), m_files[0])) { m_ok = false; } break; } default: { m_ok = false; break; } } if (!m_ok) { setError(UserDefinedError); - setErrorText(QStringLiteral("Could not attach file")); + setErrorText(QLatin1String("Could not attach file")); emitResult(); } QNetworkAccessManager* manager = new QNetworkAccessManager(this); connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(parseNetworkResponse(QNetworkReply*))); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Starting POST request" << m_url; QNetworkReply* const reply = manager->post(QNetworkRequest(m_url), multiPart); multiPart->setParent(reply); // delete the multiPart with the reply } void PhotoPostJob::parseNetworkResponse(QNetworkReply *reply) { if (reply->error() != QNetworkReply::NoError) { // A communication error has occurred setError(reply->error()); setErrorText(KIO::buildErrorString(error(), QString())); // qCWarning(DIGIKAM_WEBSERVICES_LOG) << "Network error: " << reply->errorString(); } else { QByteArray ba = reply->readAll(); qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Got data:" << ba; QJsonParseError parseError; QJsonDocument data = QJsonDocument::fromJson(ba, &parseError); if (parseError.error == QJsonParseError::NoError) { const QJsonObject object = data.object(); if (!data.isObject()) { // Something went wrong, but there is no valid object "error" handleError(QJsonValue::Undefined); } - else if (object.contains(QStringLiteral("error"))) + else if (object.contains(QLatin1String("error"))) { - handleError(object.value(QStringLiteral("error"))); + handleError(object.value(QLatin1String("error"))); } else { // Handle data m_response = object.toVariantMap(); } } else { qCWarning(DIGIKAM_WEBSERVICES_LOG) << "Unable to parse JSON data:" << ba; setError(KJob::UserDefinedError); setErrorText( i18n("Unable to parse data returned by the VKontakte server: %1", parseError.errorString())); } } emitResult(); } QVariantMap PhotoPostJob::response() const { return m_response; } } // namespace Vkontakte diff --git a/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_savephotojob.cpp b/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_savephotojob.cpp index e36cfc5eb5..07c4589e74 100644 --- a/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_savephotojob.cpp +++ b/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_savephotojob.cpp @@ -1,161 +1,161 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2011-02-19 * Description : a tool to export images to VKontakte web service * * Copyright (C) 2011-2015 by Alexander Potashev * Copyright (C) 2011-2020 by Gilles Caulier * * This program 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 2, or (at your option) any later version. * * This program 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. * * ============================================================ */ #include "vkontakte_savephotojob.h" // Qt includes #include namespace Vkontakte { SavePhotoJob::SavePhotoJob(const QString& accessToken, UploadPhotosJob::Dest dest, const QVariantMap& photoIdData, int gid) : VkontakteJob(accessToken, getMethod(dest), true) { m_dest = dest; switch (dest) { case Vkontakte::UploadPhotosJob::DEST_ALBUM: { - addQueryItem(QStringLiteral("aid"), photoIdData[QStringLiteral("aid")].toString()); - addQueryItem(QStringLiteral("server"), photoIdData[QStringLiteral("server")].toString()); - addQueryItem(QStringLiteral("photos_list"), photoIdData[QStringLiteral("photos_list")].toString()); - addQueryItem(QStringLiteral("hash"), photoIdData[QStringLiteral("hash")].toString()); + addQueryItem(QLatin1String("aid"), photoIdData[QLatin1String("aid")].toString()); + addQueryItem(QLatin1String("server"), photoIdData[QLatin1String("server")].toString()); + addQueryItem(QLatin1String("photos_list"), photoIdData[QLatin1String("photos_list")].toString()); + addQueryItem(QLatin1String("hash"), photoIdData[QLatin1String("hash")].toString()); // TODO: may be "gid" will also be in "photoIdData", so this argument is unnecessary? if (gid != -1) { - addQueryItem(QStringLiteral("gid"), QString::number(gid)); + addQueryItem(QLatin1String("gid"), QString::number(gid)); } break; } case Vkontakte::UploadPhotosJob::DEST_PROFILE: { - addQueryItem(QStringLiteral("server"), photoIdData[QStringLiteral("server")].toString()); - addQueryItem(QStringLiteral("photo"), photoIdData[QStringLiteral("photos")].toString()); - addQueryItem(QStringLiteral("hash"), photoIdData[QStringLiteral("hash")].toString()); + addQueryItem(QLatin1String("server"), photoIdData[QLatin1String("server")].toString()); + addQueryItem(QLatin1String("photo"), photoIdData[QLatin1String("photos")].toString()); + addQueryItem(QLatin1String("hash"), photoIdData[QLatin1String("hash")].toString()); break; } case Vkontakte::UploadPhotosJob::DEST_WALL: { // TODO: support optional parameters "uid" and "gid" (for posting to other users' and groups' walls) // TODO: for posting onto a wall, we must also call the "wall.post" VK method - addQueryItem(QStringLiteral("server"), photoIdData[QStringLiteral("server")].toString()); - addQueryItem(QStringLiteral("photo"), photoIdData[QStringLiteral("photo")].toString()); - addQueryItem(QStringLiteral("hash"), photoIdData[QStringLiteral("hash")].toString()); + addQueryItem(QLatin1String("server"), photoIdData[QLatin1String("server")].toString()); + addQueryItem(QLatin1String("photo"), photoIdData[QLatin1String("photo")].toString()); + addQueryItem(QLatin1String("hash"), photoIdData[QLatin1String("hash")].toString()); break; } default: { // TODO: handle unknown destination error break; } } } // static QString SavePhotoJob::getMethod(Vkontakte::UploadPhotosJob::Dest dest) { switch (dest) { case Vkontakte::UploadPhotosJob::DEST_ALBUM: { return QLatin1String("photos.save"); } case Vkontakte::UploadPhotosJob::DEST_PROFILE: { return QLatin1String("photos.saveProfilePhoto"); } case Vkontakte::UploadPhotosJob::DEST_WALL: { return QLatin1String("photos.saveWallPhoto"); } default: { return QLatin1String(""); } } } void SavePhotoJob::handleItem(const QJsonValue& item) { if (!item.isObject()) { // TODO: report error!!! m_list.clear(); return; } m_list.append(PhotoInfo(item.toObject())); } void SavePhotoJob::handleData(const QJsonValue& data) { switch (m_dest) { case Vkontakte::UploadPhotosJob::DEST_ALBUM: { if (!data.isArray()) { // TODO: report error!!! return; } foreach (const QJsonValue& item, data.toArray()) { handleItem(item); } break; } case Vkontakte::UploadPhotosJob::DEST_PROFILE: case Vkontakte::UploadPhotosJob::DEST_WALL: { handleItem(data); break; } default: { break; } } } QList SavePhotoJob::list() const { return m_list; } } // namespace Vkontakte diff --git a/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_userinfo.cpp b/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_userinfo.cpp index 25a2c69b8f..0c9e82175f 100644 --- a/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_userinfo.cpp +++ b/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_userinfo.cpp @@ -1,165 +1,165 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2011-02-19 * Description : a tool to export images to VKontakte web service * * Copyright (C) 2011-2015 by Alexander Potashev * Copyright (C) 2011-2020 by Gilles Caulier * * This program 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 2, or (at your option) any later version. * * This program 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. * * ============================================================ */ #include "vkontakte_userinfo.h" // Qt includes #include // Local includes #include "vkontakte_util.h" namespace Vkontakte { class Q_DECL_HIDDEN UserInfo::Private : public QSharedData { public: QJsonObject jsonData; }; UserInfo::UserInfo() : d(new Private) { } UserInfo::UserInfo(const QJsonObject& jsonData) : d(new Private) { d->jsonData = jsonData; } UserInfo::UserInfo(const UserInfo& other) { d = other.d; } UserInfo::~UserInfo() { } UserInfo &UserInfo::operator=(const UserInfo& other) { if (this != &other) { d = other.d; } return *this; } int UserInfo::userId() const { - return d->jsonData.value(QStringLiteral("uid")).toInt(-1); + return d->jsonData.value(QLatin1String("uid")).toInt(-1); } QString UserInfo::firstName() const { - return d->jsonData.value(QStringLiteral("first_name")).toString(); + return d->jsonData.value(QLatin1String("first_name")).toString(); } QString UserInfo::lastName() const { - return d->jsonData.value(QStringLiteral("last_name")).toString(); + return d->jsonData.value(QLatin1String("last_name")).toString(); } QString UserInfo::nickName() const { - return d->jsonData.value(QStringLiteral("nick_name")).toString(); + return d->jsonData.value(QLatin1String("nick_name")).toString(); } QString UserInfo::domain() const { - return d->jsonData.value(QStringLiteral("domain")).toString(); + return d->jsonData.value(QLatin1String("domain")).toString(); } int UserInfo::sex() const { - return d->jsonData.value(QStringLiteral("sex")).toInt(-1); + return d->jsonData.value(QLatin1String("sex")).toInt(-1); } bool UserInfo::online() const { - return d->jsonData.value(QStringLiteral("online")).toBool(false); + return d->jsonData.value(QLatin1String("online")).toBool(false); } // static QStringList UserInfo::allQueryFields() { QStringList fields; - fields << QStringLiteral("sex") - << QStringLiteral("bdate") - << QStringLiteral("city") - << QStringLiteral("country") - << QStringLiteral("photo_50") - << QStringLiteral("photo_100") - << QStringLiteral("photo_200_orig") - << QStringLiteral("photo_200") - << QStringLiteral("photo_400_orig") - << QStringLiteral("photo_max") - << QStringLiteral("photo_max_orig") - << QStringLiteral("photo_id") - << QStringLiteral("online") - << QStringLiteral("online_mobile") - << QStringLiteral("domain") - << QStringLiteral("has_mobile") - << QStringLiteral("contacts") - << QStringLiteral("connections") - << QStringLiteral("site") - << QStringLiteral("education") - << QStringLiteral("universities") - << QStringLiteral("schools") - << QStringLiteral("can_post") - << QStringLiteral("can_see_all_posts") - << QStringLiteral("can_see_audio") - << QStringLiteral("can_write_private_message") - << QStringLiteral("status") - << QStringLiteral("last_seen") - << QStringLiteral("common_count") - << QStringLiteral("relation") - << QStringLiteral("relatives") - << QStringLiteral("counters") - << QStringLiteral("screen_name") - << QStringLiteral("maiden_name") - << QStringLiteral("timezone") - << QStringLiteral("occupation") - << QStringLiteral("activities") - << QStringLiteral("interests") - << QStringLiteral("music") - << QStringLiteral("movies") - << QStringLiteral("tv") - << QStringLiteral("books") - << QStringLiteral("games") - << QStringLiteral("about") - << QStringLiteral("quotes") - << QStringLiteral("personal") - << QStringLiteral("friends_status"); + fields << QLatin1String("sex") + << QLatin1String("bdate") + << QLatin1String("city") + << QLatin1String("country") + << QLatin1String("photo_50") + << QLatin1String("photo_100") + << QLatin1String("photo_200_orig") + << QLatin1String("photo_200") + << QLatin1String("photo_400_orig") + << QLatin1String("photo_max") + << QLatin1String("photo_max_orig") + << QLatin1String("photo_id") + << QLatin1String("online") + << QLatin1String("online_mobile") + << QLatin1String("domain") + << QLatin1String("has_mobile") + << QLatin1String("contacts") + << QLatin1String("connections") + << QLatin1String("site") + << QLatin1String("education") + << QLatin1String("universities") + << QLatin1String("schools") + << QLatin1String("can_post") + << QLatin1String("can_see_all_posts") + << QLatin1String("can_see_audio") + << QLatin1String("can_write_private_message") + << QLatin1String("status") + << QLatin1String("last_seen") + << QLatin1String("common_count") + << QLatin1String("relation") + << QLatin1String("relatives") + << QLatin1String("counters") + << QLatin1String("screen_name") + << QLatin1String("maiden_name") + << QLatin1String("timezone") + << QLatin1String("occupation") + << QLatin1String("activities") + << QLatin1String("interests") + << QLatin1String("music") + << QLatin1String("movies") + << QLatin1String("tv") + << QLatin1String("books") + << QLatin1String("games") + << QLatin1String("about") + << QLatin1String("quotes") + << QLatin1String("personal") + << QLatin1String("friends_status"); return fields; } } // namespace Vkontakte diff --git a/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_userinfojob.cpp b/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_userinfojob.cpp index 7b02dd765f..05d0131622 100644 --- a/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_userinfojob.cpp +++ b/core/dplugins/generic/webservices/vkontakte/backend/vkontakte_userinfojob.cpp @@ -1,119 +1,119 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2011-02-19 * Description : a tool to export images to VKontakte web service * * Copyright (C) 2011-2015 by Alexander Potashev * Copyright (C) 2011-2020 by Gilles Caulier * * This program 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 2, or (at your option) any later version. * * This program 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. * * ============================================================ */ #include "vkontakte_userinfojob.h" // Qt includes #include // Local includes #include "vkontakte_util.h" namespace Vkontakte { class Q_DECL_HIDDEN UserInfoJob::Private { public: QList userInfo; QStringList fields; }; // http://vk.com/dev/users.get UserInfoJob::UserInfoJob(const QString& accessToken) - : VkontakteJob(accessToken, QStringLiteral("users.get")), + : VkontakteJob(accessToken, QLatin1String("users.get")), d(new Private) { // The complete list of fields setFields(UserInfo::allQueryFields()); // TODO: do not pull extra fields by default // TODO: support "counters" request (probably in another KJob) } UserInfoJob::UserInfoJob(const QString& accessToken, int uid) - : VkontakteJob(accessToken, QStringLiteral("users.get")), + : VkontakteJob(accessToken, QLatin1String("users.get")), d(new Private) { setFields(UserInfo::allQueryFields()); // TODO: do not pull extra fields by default - addQueryItem(QStringLiteral("user_ids"), QString::number(uid)); + addQueryItem(QLatin1String("user_ids"), QString::number(uid)); } UserInfoJob::UserInfoJob(const QString& accessToken, const QList& uids) - : VkontakteJob(accessToken, QStringLiteral("users.get")), + : VkontakteJob(accessToken, QLatin1String("users.get")), d(new Private) { setFields(UserInfo::allQueryFields()); // TODO: do not pull extra fields by default - addQueryItem(QStringLiteral("user_ids"), joinIntegers(uids)); + addQueryItem(QLatin1String("user_ids"), joinIntegers(uids)); // TODO: make this working for more than 1000 uids // ("users.get" allows requesting only 1000 users at once) } UserInfoJob::~UserInfoJob() { delete d; } QList UserInfoJob::userInfo() const { return d->userInfo; } void UserInfoJob::setFields(const QStringList& fields) { d->fields = fields; } void UserInfoJob::prepareQueryItems() { if (!d->fields.isEmpty()) { - addQueryItem(QStringLiteral("fields"), d->fields.join(QStringLiteral(","))); + addQueryItem(QLatin1String("fields"), d->fields.join(QLatin1String(","))); } } void UserInfoJob::handleData(const QJsonValue& data) { if (!data.isArray()) { // TODO: report error!!! return; } foreach (const QJsonValue& item, data.toArray()) { if (!item.isObject()) { // TODO: report error!!! d->userInfo.clear(); return; } d->userInfo.append(UserInfo(item.toObject())); } } } // namespace Vkontakte