From 69628390815254297bbd8c95436f6780fa846fae Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 10 Feb 2026 23:16:37 +0100 Subject: Translations fixed and other stuff --- .../mastodonshareplugin/mastodonshareplugin.pro | 1 + .../mastodonshareservicestatus.cpp | 101 +-------------------- .../mastodonshareservicestatus.h | 1 - .../mastodontransferplugin.pro | 1 + 4 files changed, 7 insertions(+), 97 deletions(-) (limited to 'transferengine-plugins') diff --git a/transferengine-plugins/mastodonshareplugin/mastodonshareplugin.pro b/transferengine-plugins/mastodonshareplugin/mastodonshareplugin.pro index 6de949e..1ab7c6c 100644 --- a/transferengine-plugins/mastodonshareplugin/mastodonshareplugin.pro +++ b/transferengine-plugins/mastodonshareplugin/mastodonshareplugin.pro @@ -3,6 +3,7 @@ TARGET = $$qtLibraryTarget(mastodonshareplugin) CONFIG += plugin DEPENDPATH += . INCLUDEPATH += .. +INCLUDEPATH += ../../common CONFIG += link_pkgconfig PKGCONFIG += nemotransferengine-qt5 accounts-qt5 sailfishaccounts libsignon-qt5 diff --git a/transferengine-plugins/mastodonshareservicestatus.cpp b/transferengine-plugins/mastodonshareservicestatus.cpp index 8c70e12..6ff4cb8 100644 --- a/transferengine-plugins/mastodonshareservicestatus.cpp +++ b/transferengine-plugins/mastodonshareservicestatus.cpp @@ -1,4 +1,5 @@ #include "mastodonshareservicestatus.h" +#include "mastodonauthutils.h" #include #include @@ -22,33 +23,6 @@ MastodonShareServiceStatus::MastodonShareServiceStatus(QObject *parent) { } -QString MastodonShareServiceStatus::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; -} - void MastodonShareServiceStatus::signIn(int accountId) { Accounts::Account *account = Accounts::Account::fromId(m_accountManager, accountId, this); @@ -93,66 +67,7 @@ void MastodonShareServiceStatus::signIn(int accountId) QVariantMap signonSessionData = accountService.authData().parameters(); - QString configuredHost = account->value(QStringLiteral("auth/oauth2/web_server/Host")).toString().trimmed(); - if (configuredHost.isEmpty()) { - configuredHost = normalizeApiHost(account->value(QStringLiteral("api/Host")).toString()); - } - - if (configuredHost.startsWith(QLatin1String("https://"))) { - configuredHost.remove(0, 8); - } else if (configuredHost.startsWith(QLatin1String("http://"))) { - configuredHost.remove(0, 7); - } - - const int separator = configuredHost.indexOf(QLatin1Char('/')); - if (separator > -1) { - configuredHost.truncate(separator); - } - while (configuredHost.endsWith(QLatin1Char('/'))) { - configuredHost.chop(1); - } - - if (configuredHost.isEmpty()) { - configuredHost = QStringLiteral("mastodon.social"); - } - signonSessionData.insert(QStringLiteral("Host"), configuredHost); - - const QString authPath = account->value(QStringLiteral("auth/oauth2/web_server/AuthPath")).toString().trimmed(); - if (!authPath.isEmpty()) { - signonSessionData.insert(QStringLiteral("AuthPath"), authPath); - } - - const QString tokenPath = account->value(QStringLiteral("auth/oauth2/web_server/TokenPath")).toString().trimmed(); - if (!tokenPath.isEmpty()) { - signonSessionData.insert(QStringLiteral("TokenPath"), tokenPath); - } - - const QString responseType = account->value(QStringLiteral("auth/oauth2/web_server/ResponseType")).toString().trimmed(); - if (!responseType.isEmpty()) { - signonSessionData.insert(QStringLiteral("ResponseType"), responseType); - } - - const QString redirectUri = account->value(QStringLiteral("auth/oauth2/web_server/RedirectUri")).toString().trimmed(); - if (!redirectUri.isEmpty()) { - signonSessionData.insert(QStringLiteral("RedirectUri"), redirectUri); - } - - const QVariant scopeValue = account->value(QStringLiteral("auth/oauth2/web_server/Scope")); - if (scopeValue.isValid()) { - signonSessionData.insert(QStringLiteral("Scope"), scopeValue); - } - - const QString clientId = account->value(QStringLiteral("auth/oauth2/web_server/ClientId")).toString().trimmed(); - if (!clientId.isEmpty()) { - signonSessionData.insert(QStringLiteral("ClientId"), clientId); - } - - const QString clientSecret = account->value(QStringLiteral("auth/oauth2/web_server/ClientSecret")).toString().trimmed(); - if (!clientSecret.isEmpty()) { - signonSessionData.insert(QStringLiteral("ClientSecret"), clientSecret); - } - - signonSessionData.insert(QStringLiteral("UiPolicy"), SignOn::NoUserInteractionPolicy); + MastodonAuthUtils::addSignOnSessionParameters(account, &signonSessionData); connect(session, SIGNAL(response(SignOn::SessionData)), this, SLOT(signOnResponse(SignOn::SessionData)), @@ -168,20 +83,14 @@ void MastodonShareServiceStatus::signIn(int accountId) void MastodonShareServiceStatus::signOnResponse(const SignOn::SessionData &responseData) { - QVariantMap data; - Q_FOREACH (const QString &key, responseData.propertyNames()) { - data.insert(key, responseData.getProperty(key)); - } + const QVariantMap data = MastodonAuthUtils::responseDataToMap(responseData); SignOn::AuthSession *session = qobject_cast(sender()); Accounts::Account *account = session->property("account").value(); SignOn::Identity *identity = session->property("identity").value(); const int accountId = account ? account->id() : 0; - QString accessToken = data.value(QLatin1String("AccessToken")).toString().trimmed(); - if (accessToken.isEmpty()) { - accessToken = data.value(QLatin1String("access_token")).toString().trimmed(); - } + QString accessToken = MastodonAuthUtils::accessToken(data); if (accountId > 0 && m_accountIdToDetailsIdx.contains(accountId)) { AccountDetails &accountDetails(m_accountDetails[m_accountIdToDetailsIdx[accountId]]); @@ -308,7 +217,7 @@ void MastodonShareServiceStatus::queryStatus(QueryStatusMode mode) if (!m_accountIdToDetailsIdx.contains(id)) { AccountDetails details; details.accountId = id; - details.apiHost = normalizeApiHost(acc->value(QStringLiteral("api/Host")).toString()); + details.apiHost = MastodonAuthUtils::normalizeApiHost(acc->value(QStringLiteral("api/Host")).toString()); QUrl apiUrl(details.apiHost); details.providerName = apiUrl.host(); diff --git a/transferengine-plugins/mastodonshareservicestatus.h b/transferengine-plugins/mastodonshareservicestatus.h index 571efd5..d7968f5 100644 --- a/transferengine-plugins/mastodonshareservicestatus.h +++ b/transferengine-plugins/mastodonshareservicestatus.h @@ -60,7 +60,6 @@ private: Error }; - static QString normalizeApiHost(const QString &rawHost); void setAccountDetailsState(int accountId, AccountDetailsState state); void signIn(int accountId); diff --git a/transferengine-plugins/mastodontransferplugin/mastodontransferplugin.pro b/transferengine-plugins/mastodontransferplugin/mastodontransferplugin.pro index b37bf17..8782156 100644 --- a/transferengine-plugins/mastodontransferplugin/mastodontransferplugin.pro +++ b/transferengine-plugins/mastodontransferplugin/mastodontransferplugin.pro @@ -3,6 +3,7 @@ TARGET = $$qtLibraryTarget(mastodontransferplugin) CONFIG += plugin DEPENDPATH += . INCLUDEPATH += .. +INCLUDEPATH += ../../common QT += network -- cgit v1.2.3