diff options
Diffstat (limited to 'transferengine-plugins/mastodontransferplugin')
7 files changed, 40 insertions, 37 deletions
diff --git a/transferengine-plugins/mastodontransferplugin/mastodonapi.cpp b/transferengine-plugins/mastodontransferplugin/mastodonapi.cpp index baf9dd8..fa973d0 100644 --- a/transferengine-plugins/mastodontransferplugin/mastodonapi.cpp +++ b/transferengine-plugins/mastodontransferplugin/mastodonapi.cpp @@ -1,8 +1,11 @@ /* - * Copyright (C) 2013-2026 Jolla Ltd. + * SPDX-FileCopyrightText: 2013 - 2026 Jolla Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause */ #include "mastodonapi.h" +#include "mastodonauthutils.h" #include <QtCore/QFile> #include <QtCore/QFileInfo> @@ -18,6 +21,7 @@ MastodonApi::MastodonApi(QNetworkAccessManager *qnam, QObject *parent) : QObject(parent) + , m_cancelRequested(false) , m_qnam(qnam) { } @@ -26,33 +30,6 @@ MastodonApi::~MastodonApi() { } -QString MastodonApi::normalizeApiHost(const QString &rawHost) -{ - QString host = rawHost.trimmed(); - if (host.isEmpty()) { - host = QStringLiteral("https://mastodon.social"); - } - - if (!host.startsWith(QLatin1String("https://")) - && !host.startsWith(QLatin1String("http://"))) { - host.prepend(QStringLiteral("https://")); - } - - QUrl url(host); - if (!url.isValid() || url.host().isEmpty()) { - return QStringLiteral("https://mastodon.social"); - } - - QString normalized = QString::fromLatin1(url.toEncoded(QUrl::RemovePath - | QUrl::RemoveQuery - | QUrl::RemoveFragment)); - if (normalized.endsWith(QLatin1Char('/'))) { - normalized.chop(1); - } - - return normalized; -} - bool MastodonApi::uploadImage(const QString &filePath, const QString &statusText, const QString &mimeType, @@ -65,7 +42,8 @@ bool MastodonApi::uploadImage(const QString &filePath, return false; } - m_apiHost = normalizeApiHost(apiHost); + m_cancelRequested = false; + m_apiHost = MastodonAuthUtils::normalizeApiHost(apiHost); m_accessToken = accessToken; m_statusText = statusText; @@ -116,7 +94,8 @@ bool MastodonApi::postStatus(const QString &statusText, const QString &apiHost, const QString &accessToken) { - m_apiHost = normalizeApiHost(apiHost); + m_cancelRequested = false; + m_apiHost = MastodonAuthUtils::normalizeApiHost(apiHost); m_accessToken = accessToken; m_statusText = statusText; @@ -172,11 +151,11 @@ void MastodonApi::cancelUpload() return; } + m_cancelRequested = true; const QList<QNetworkReply*> replies = m_replies.keys(); Q_FOREACH (QNetworkReply *reply, replies) { reply->abort(); } - m_replies.clear(); } void MastodonApi::replyError(QNetworkReply::NetworkError error) @@ -205,6 +184,14 @@ void MastodonApi::finished() reply->deleteLater(); + if (m_cancelRequested && error == QNetworkReply::OperationCanceledError) { + if (m_replies.isEmpty()) { + m_cancelRequested = false; + emit transferCanceled(); + } + return; + } + if (apiCall == UPLOAD_MEDIA) { if (error != QNetworkReply::NoError || httpCode < 200 || httpCode >= 300) { finishTransfer(error == QNetworkReply::NoError ? QNetworkReply::UnknownNetworkError : error, @@ -241,6 +228,8 @@ void MastodonApi::finished() void MastodonApi::finishTransfer(QNetworkReply::NetworkError error, int httpCode, const QByteArray &data) { + m_cancelRequested = false; + if (httpCode == 401) { emit credentialsExpired(); } diff --git a/transferengine-plugins/mastodontransferplugin/mastodonapi.h b/transferengine-plugins/mastodontransferplugin/mastodonapi.h index 4ac3d80..df4c87a 100644 --- a/transferengine-plugins/mastodontransferplugin/mastodonapi.h +++ b/transferengine-plugins/mastodontransferplugin/mastodonapi.h @@ -1,5 +1,7 @@ /* - * Copyright (C) 2013-2026 Jolla Ltd. + * SPDX-FileCopyrightText: 2013 - 2026 Jolla Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause */ #ifndef MASTODONAPI_H @@ -49,11 +51,11 @@ private Q_SLOTS: void uploadProgress(qint64 received, qint64 total); private: - static QString normalizeApiHost(const QString &rawHost); bool postStatusInternal(const QString &mediaId); void finishTransfer(QNetworkReply::NetworkError error, int httpCode, const QByteArray &data); QMap<QNetworkReply*, API_CALL> m_replies; + bool m_cancelRequested; QNetworkAccessManager *m_qnam; QString m_accessToken; QString m_apiHost; diff --git a/transferengine-plugins/mastodontransferplugin/mastodontransferplugin.cpp b/transferengine-plugins/mastodontransferplugin/mastodontransferplugin.cpp index 064388c..a843df2 100644 --- a/transferengine-plugins/mastodontransferplugin/mastodontransferplugin.cpp +++ b/transferengine-plugins/mastodontransferplugin/mastodontransferplugin.cpp @@ -1,5 +1,7 @@ /* - * Copyright (C) 2013-2026 Jolla Ltd. + * SPDX-FileCopyrightText: 2013 - 2026 Jolla Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause */ #include "mastodontransferplugin.h" diff --git a/transferengine-plugins/mastodontransferplugin/mastodontransferplugin.h b/transferengine-plugins/mastodontransferplugin/mastodontransferplugin.h index 865faff..4d3baaf 100644 --- a/transferengine-plugins/mastodontransferplugin/mastodontransferplugin.h +++ b/transferengine-plugins/mastodontransferplugin/mastodontransferplugin.h @@ -1,5 +1,7 @@ /* - * Copyright (C) 2013-2026 Jolla Ltd. + * SPDX-FileCopyrightText: 2013 - 2026 Jolla Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause */ #ifndef MASTODONTRANSFERPLUGIN_H diff --git a/transferengine-plugins/mastodontransferplugin/mastodontransferplugin.pro b/transferengine-plugins/mastodontransferplugin/mastodontransferplugin.pro index 8782156..422a889 100644 --- a/transferengine-plugins/mastodontransferplugin/mastodontransferplugin.pro +++ b/transferengine-plugins/mastodontransferplugin/mastodontransferplugin.pro @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2013 - 2026 Jolla Ltd. +# +# SPDX-License-Identifier: BSD-3-Clause + TEMPLATE = lib TARGET = $$qtLibraryTarget(mastodontransferplugin) CONFIG += plugin diff --git a/transferengine-plugins/mastodontransferplugin/mastodonuploader.cpp b/transferengine-plugins/mastodontransferplugin/mastodonuploader.cpp index 6e0a6ea..7b87823 100644 --- a/transferengine-plugins/mastodontransferplugin/mastodonuploader.cpp +++ b/transferengine-plugins/mastodontransferplugin/mastodonuploader.cpp @@ -1,5 +1,7 @@ /* - * Copyright (C) 2013-2026 Jolla Ltd. + * SPDX-FileCopyrightText: 2013 - 2026 Jolla Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause */ #include "mastodonuploader.h" diff --git a/transferengine-plugins/mastodontransferplugin/mastodonuploader.h b/transferengine-plugins/mastodontransferplugin/mastodonuploader.h index f773c23..72d9689 100644 --- a/transferengine-plugins/mastodontransferplugin/mastodonuploader.h +++ b/transferengine-plugins/mastodontransferplugin/mastodonuploader.h @@ -1,5 +1,7 @@ /* - * Copyright (C) 2013-2026 Jolla Ltd. + * SPDX-FileCopyrightText: 2013 - 2026 Jolla Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause */ #ifndef MASTODONUPLOADER_H |
