From 250d2a87c9bc9813ec36b34a515b77967eadc857 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 7 Jan 2026 02:47:16 +0200 Subject: [PATCH 1/3] use qt auth for device code flow Signed-off-by: Trial97 --- launcher/minecraft/auth/AuthFlow.h | 2 +- .../auth/steps/MSADeviceCodeStep.cpp | 258 ++++-------------- .../minecraft/auth/steps/MSADeviceCodeStep.h | 23 +- launcher/minecraft/auth/steps/MSAStep.cpp | 8 +- launcher/minecraft/auth/steps/MSAStep.h | 3 +- launcher/ui/dialogs/MSALoginDialog.cpp | 9 +- launcher/ui/dialogs/MSALoginDialog.h | 2 +- 7 files changed, 70 insertions(+), 235 deletions(-) diff --git a/launcher/minecraft/auth/AuthFlow.h b/launcher/minecraft/auth/AuthFlow.h index d881a7691..b8a6db5ea 100644 --- a/launcher/minecraft/auth/AuthFlow.h +++ b/launcher/minecraft/auth/AuthFlow.h @@ -27,7 +27,7 @@ class AuthFlow : public Task { signals: void authorizeWithBrowser(const QUrl& url); - void authorizeWithBrowserWithExtra(QString url, QString code, int expiresIn); + void authorizeWithBrowserWithExtra(const QUrl& verificationUrl, const QString& code, const QUrl& completeVerificationUrl); protected: void succeed(); diff --git a/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp b/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp index 3feb6852c..13c26c1a0 100644 --- a/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp +++ b/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp @@ -39,15 +39,55 @@ #include #include "Application.h" -#include "Json.h" -#include "net/RawHeaderProxy.h" -// https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-device-code MSADeviceCodeStep::MSADeviceCodeStep(AccountData* data) : AuthStep(data) { m_clientId = APPLICATION->getMSAClientID(); - connect(&m_expiration_timer, &QTimer::timeout, this, &MSADeviceCodeStep::abort); - connect(&m_pool_timer, &QTimer::timeout, this, &MSADeviceCodeStep::authenticateUser); + m_oauth2.setAuthorizationUrl(QUrl("https://login.microsoftonline.com/consumers/oauth2/v2.0/devicecode")); + m_oauth2.setTokenUrl(QUrl("https://login.microsoftonline.com/consumers/oauth2/v2.0/token")); + m_oauth2.setRequestedScopeTokens({ "XboxLive.SignIn", "XboxLive.offline_access" }); + m_oauth2.setClientIdentifier(m_clientId); + m_oauth2.setNetworkAccessManager(APPLICATION->network()); + + connect(&m_oauth2, &QOAuth2DeviceAuthorizationFlow::granted, this, [this] { + m_data->msaClientID = m_oauth2.clientIdentifier(); + m_data->msaToken.issueInstant = QDateTime::currentDateTimeUtc(); + m_data->msaToken.notAfter = m_oauth2.expirationAt(); + m_data->msaToken.extra = m_oauth2.extraTokens(); + m_data->msaToken.refresh_token = m_oauth2.refreshToken(); + m_data->msaToken.token = m_oauth2.token(); + emit finished(AccountTaskState::STATE_WORKING, tr("Got ")); + }); + connect(&m_oauth2, &QOAuth2DeviceAuthorizationFlow::authorizeWithUserCode, this, &MSADeviceCodeStep::authorizeWithBrowser); + connect(&m_oauth2, &QOAuth2DeviceAuthorizationFlow::requestFailed, this, [this](const QAbstractOAuth2::Error err) { + auto state = AccountTaskState::STATE_FAILED_HARD; + if (m_oauth2.status() == QAbstractOAuth::Status::Granted) { + if (err == QAbstractOAuth2::Error::NetworkError) { + state = AccountTaskState::STATE_OFFLINE; + } else { + state = AccountTaskState::STATE_FAILED_SOFT; + } + } + auto message = tr("Microsoft user authentication failed."); + qWarning() << message; + emit finished(state, message); + }); + connect(&m_oauth2, &QOAuth2DeviceAuthorizationFlow::serverReportedErrorOccurred, this, + [this](const QString& error, const QString& errorDescription, const QUrl& uri) { + qWarning() << "Failed to login because" << error << errorDescription; + emit finished(AccountTaskState::STATE_FAILED_HARD, errorDescription); + }); + + connect(&m_oauth2, &QOAuth2DeviceAuthorizationFlow::extraTokensChanged, this, + [this](const QVariantMap& tokens) { m_data->msaToken.extra = tokens; }); + + connect(&m_oauth2, &QOAuth2DeviceAuthorizationFlow::clientIdentifierChanged, this, + [this](const QString& clientIdentifier) { m_data->msaClientID = clientIdentifier; }); + connect(&m_oauth2, &QOAuth2DeviceAuthorizationFlow::userCodeExpirationAtChanged, this, [](const QDateTime& expiration) { + qDebug() << "============="; + qDebug() << expiration; + qDebug() << "============="; + }); } QString MSADeviceCodeStep::describe() @@ -57,27 +97,9 @@ QString MSADeviceCodeStep::describe() void MSADeviceCodeStep::perform() { - QUrlQuery data; - data.addQueryItem("client_id", m_clientId); - data.addQueryItem("scope", "XboxLive.SignIn XboxLive.offline_access"); - auto payload = data.query(QUrl::FullyEncoded).toUtf8(); - QUrl url("https://login.microsoftonline.com/consumers/oauth2/v2.0/devicecode"); - auto headers = QList{ - { "Content-Type", "application/x-www-form-urlencoded" }, - { "Accept", "application/json" }, - }; - auto [request, response] = Net::Upload::makeByteArray(url, payload); - m_request = request; - m_request->addHeaderProxy(std::make_unique(headers)); - m_request->enableAutoRetry(true); - - m_task.reset(new NetJob("MSADeviceCodeStep", APPLICATION->network())); - m_task->setAskRetry(false); - m_task->addNetAction(m_request); - - connect(m_task.get(), &Task::finished, this, [this, response] { deviceAuthorizationFinished(response); }); - - m_task->start(); + *m_data = AccountData(); + m_data->msaClientID = m_clientId; + m_oauth2.grant(); } struct DeviceAuthorizationResponse { @@ -91,188 +113,10 @@ struct DeviceAuthorizationResponse { QString error_description; }; -DeviceAuthorizationResponse parseDeviceAuthorizationResponse(const QByteArray& data) -{ - QJsonParseError err; - QJsonDocument doc = QJsonDocument::fromJson(data, &err); - if (err.error != QJsonParseError::NoError) { - qWarning() << "Failed to parse device authorization response due to err:" << err.errorString(); - return {}; - } - - if (!doc.isObject()) { - qWarning() << "Device authorization response is not an object"; - return {}; - } - auto obj = doc.object(); - return { - obj["device_code"].toString(), obj["user_code"].toString(), obj["verification_uri"].toString(), obj["expires_in"].toInt(), - obj["interval"].toInt(), obj["error"].toString(), obj["error_description"].toString(), - }; -} - -void MSADeviceCodeStep::deviceAuthorizationFinished(QByteArray* response) -{ - auto rsp = parseDeviceAuthorizationResponse(*response); - if (!rsp.error.isEmpty() || !rsp.error_description.isEmpty()) { - qWarning() << "Device authorization failed:" << rsp.error; - emit finished(AccountTaskState::STATE_FAILED_HARD, - tr("Device authorization failed: %1").arg(rsp.error_description.isEmpty() ? rsp.error : rsp.error_description)); - return; - } - if (!m_request->wasSuccessful() || m_request->error() != QNetworkReply::NoError) { - qWarning() << "Device authorization failed:" << *response; - emit finished(AccountTaskState::STATE_FAILED_HARD, tr("Failed to retrieve device authorization")); - return; - } - - if (rsp.device_code.isEmpty() || rsp.user_code.isEmpty() || rsp.verification_uri.isEmpty() || rsp.expires_in == 0) { - qWarning() << "Device authorization failed: required fields missing"; - emit finished(AccountTaskState::STATE_FAILED_HARD, tr("Device authorization failed: required fields missing")); - return; - } - if (rsp.interval != 0) { - interval = rsp.interval; - } - m_device_code = rsp.device_code; - emit authorizeWithBrowser(rsp.verification_uri, rsp.user_code, rsp.expires_in); - m_expiration_timer.setTimerType(Qt::VeryCoarseTimer); - m_expiration_timer.setInterval(rsp.expires_in * 1000); - m_expiration_timer.setSingleShot(true); - m_expiration_timer.start(); - m_pool_timer.setTimerType(Qt::VeryCoarseTimer); - m_pool_timer.setSingleShot(true); - startPoolTimer(); -} - void MSADeviceCodeStep::abort() { - m_expiration_timer.stop(); - m_pool_timer.stop(); - if (m_request) { - m_request->abort(); - } - m_is_aborted = true; + if (m_oauth2.isPolling()) + m_oauth2.stopTokenPolling(); + emit finished(AccountTaskState::STATE_FAILED_HARD, tr("Task aborted")); } - -void MSADeviceCodeStep::startPoolTimer() -{ - if (m_is_aborted) { - return; - } - if (m_expiration_timer.remainingTime() < interval * 1000) { - perform(); - return; - } - - m_pool_timer.setInterval(interval * 1000); - m_pool_timer.start(); -} - -void MSADeviceCodeStep::authenticateUser() -{ - QUrlQuery data; - data.addQueryItem("client_id", m_clientId); - data.addQueryItem("grant_type", "urn:ietf:params:oauth:grant-type:device_code"); - data.addQueryItem("device_code", m_device_code); - auto payload = data.query(QUrl::FullyEncoded).toUtf8(); - QUrl url("https://login.microsoftonline.com/consumers/oauth2/v2.0/token"); - auto headers = QList{ - { "Content-Type", "application/x-www-form-urlencoded" }, - { "Accept", "application/json" }, - }; - auto [request, response] = Net::Upload::makeByteArray(url, payload); - m_request = request; - m_request->addHeaderProxy(std::make_unique(headers)); - - connect(m_request.get(), &Task::finished, this, [this, response] { authenticationFinished(response); }); - - m_request->setNetwork(APPLICATION->network()); - m_request->start(); -} - -struct AuthenticationResponse { - QString access_token; - QString token_type; - QString refresh_token; - int expires_in; - - QString error; - QString error_description; - - QVariantMap extra; -}; - -AuthenticationResponse parseAuthenticationResponse(const QByteArray& data) -{ - QJsonParseError err; - QJsonDocument doc = QJsonDocument::fromJson(data, &err); - if (err.error != QJsonParseError::NoError) { - qWarning() << "Failed to parse device authorization response due to err:" << err.errorString(); - return {}; - } - - if (!doc.isObject()) { - qWarning() << "Device authorization response is not an object"; - return {}; - } - auto obj = doc.object(); - return { obj["access_token"].toString(), - obj["token_type"].toString(), - obj["refresh_token"].toString(), - obj["expires_in"].toInt(), - obj["error"].toString(), - obj["error_description"].toString(), - obj.toVariantMap() }; -} - -void MSADeviceCodeStep::authenticationFinished(QByteArray* response) -{ - if (m_request->error() == QNetworkReply::TimeoutError) { - // rfc8628#section-3.5 - // "On encountering a connection timeout, clients MUST unilaterally - // reduce their polling frequency before retrying. The use of an - // exponential backoff algorithm to achieve this, such as doubling the - // polling interval on each such connection timeout, is RECOMMENDED." - interval *= 2; - startPoolTimer(); - return; - } - auto rsp = parseAuthenticationResponse(*response); - if (rsp.error == "slow_down") { - // rfc8628#section-3.5 - // "A variant of 'authorization_pending', the authorization request is - // still pending and polling should continue, but the interval MUST - // be increased by 5 seconds for this and all subsequent requests." - interval += 5; - startPoolTimer(); - return; - } - if (rsp.error == "authorization_pending") { - // keep trying - rfc8628#section-3.5 - // "The authorization request is still pending as the end user hasn't - // yet completed the user-interaction steps (Section 3.3)." - startPoolTimer(); - return; - } - if (!rsp.error.isEmpty() || !rsp.error_description.isEmpty()) { - qWarning() << "Device Access failed:" << rsp.error; - emit finished(AccountTaskState::STATE_FAILED_HARD, - tr("Device Access failed: %1").arg(rsp.error_description.isEmpty() ? rsp.error : rsp.error_description)); - return; - } - if (!m_request->wasSuccessful() || m_request->error() != QNetworkReply::NoError) { - startPoolTimer(); // it failed so just try again without increasing the interval - return; - } - - m_expiration_timer.stop(); - m_data->msaClientID = m_clientId; - m_data->msaToken.issueInstant = QDateTime::currentDateTimeUtc(); - m_data->msaToken.notAfter = QDateTime::currentDateTime().addSecs(rsp.expires_in); - m_data->msaToken.extra = rsp.extra; - m_data->msaToken.refresh_token = rsp.refresh_token; - m_data->msaToken.token = rsp.access_token; - emit finished(AccountTaskState::STATE_WORKING, tr("Got MSA token")); -} diff --git a/launcher/minecraft/auth/steps/MSADeviceCodeStep.h b/launcher/minecraft/auth/steps/MSADeviceCodeStep.h index cfb8270d4..fe9cff189 100644 --- a/launcher/minecraft/auth/steps/MSADeviceCodeStep.h +++ b/launcher/minecraft/auth/steps/MSADeviceCodeStep.h @@ -35,11 +35,10 @@ #pragma once #include -#include #include "minecraft/auth/AuthStep.h" -#include "net/NetJob.h" -#include "net/Upload.h" + +#include class MSADeviceCodeStep : public AuthStep { Q_OBJECT @@ -55,23 +54,9 @@ class MSADeviceCodeStep : public AuthStep { void abort() override; signals: - void authorizeWithBrowser(QString url, QString code, int expiresIn); - - private slots: - void deviceAuthorizationFinished(QByteArray* response); - void startPoolTimer(); - void authenticateUser(); - void authenticationFinished(QByteArray* response); + void authorizeWithBrowser(const QUrl& verificationUrl, const QString& code, const QUrl& completeVerificationUrl); private: QString m_clientId; - QString m_device_code; - bool m_is_aborted = false; - int interval = 5; - - QTimer m_pool_timer; - QTimer m_expiration_timer; - - Net::Upload::Ptr m_request; - NetJob::Ptr m_task; + QOAuth2DeviceAuthorizationFlow m_oauth2; }; diff --git a/launcher/minecraft/auth/steps/MSAStep.cpp b/launcher/minecraft/auth/steps/MSAStep.cpp index 51a5e5ce0..93137f66f 100644 --- a/launcher/minecraft/auth/steps/MSAStep.cpp +++ b/launcher/minecraft/auth/steps/MSAStep.cpp @@ -133,8 +133,8 @@ MSAStep::MSAStep(AccountData* data, bool silent) : AuthStep(data), m_silent(sile m_oauth2.setReplyHandler(new CustomOAuthOobReplyHandler(this)); } m_oauth2.setAuthorizationUrl(QUrl("https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize")); - m_oauth2.setAccessTokenUrl(QUrl("https://login.microsoftonline.com/consumers/oauth2/v2.0/token")); - m_oauth2.setScope("XboxLive.SignIn XboxLive.offline_access"); + m_oauth2.setTokenUrl(QUrl("https://login.microsoftonline.com/consumers/oauth2/v2.0/token")); + m_oauth2.setRequestedScopeTokens({ "XboxLive.SignIn", "XboxLive.offline_access" }); m_oauth2.setClientIdentifier(m_clientId); m_oauth2.setNetworkAccessManager(APPLICATION->network()); @@ -164,7 +164,7 @@ MSAStep::MSAStep(AccountData* data, bool silent) : AuthStep(data), m_silent(sile qWarning() << message; emit finished(state, message); }); - connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::error, this, + connect(&m_oauth2, &QOAuth2AuthorizationCodeFlow::serverReportedErrorOccurred, this, [this](const QString& error, const QString& errorDescription, const QUrl& uri) { qWarning() << "Failed to login because" << error << errorDescription; emit finished(AccountTaskState::STATE_FAILED_HARD, errorDescription); @@ -195,7 +195,7 @@ void MSAStep::perform() return; } m_oauth2.setRefreshToken(m_data->msaToken.refresh_token); - m_oauth2.refreshAccessToken(); + m_oauth2.refreshTokens(); } else { m_oauth2.setModifyParametersFunction( [](QAbstractOAuth::Stage stage, QMultiMap* map) { map->insert("prompt", "select_account"); }); diff --git a/launcher/minecraft/auth/steps/MSAStep.h b/launcher/minecraft/auth/steps/MSAStep.h index 2f4e7812b..baab1895a 100644 --- a/launcher/minecraft/auth/steps/MSAStep.h +++ b/launcher/minecraft/auth/steps/MSAStep.h @@ -38,7 +38,8 @@ #include "minecraft/auth/AuthStep.h" -#include +#include + class MSAStep : public AuthStep { Q_OBJECT public: diff --git a/launcher/ui/dialogs/MSALoginDialog.cpp b/launcher/ui/dialogs/MSALoginDialog.cpp index e238a54eb..c269f0126 100644 --- a/launcher/ui/dialogs/MSALoginDialog.cpp +++ b/launcher/ui/dialogs/MSALoginDialog.cpp @@ -179,15 +179,20 @@ void paintQR(QPainter& painter, const QSize canvasSize, const QString& data, QCo } } -void MSALoginDialog::authorizeWithBrowserWithExtra(QString url, QString code, [[maybe_unused]] int expiresIn) +void MSALoginDialog::authorizeWithBrowserWithExtra(const QUrl& verificationUrl, const QString& code, const QUrl& completeVerificationUrl) { ui->stackedWidget->setCurrentIndex(1); ui->stackedWidget->adjustSize(); ui->stackedWidget->updateGeometry(); this->adjustSize(); + auto url = verificationUrl.toString(); + if (completeVerificationUrl.isValid()) { + url = completeVerificationUrl.toString(); + } + const auto linkString = QString("%2").arg(url, url); - if (url == "https://www.microsoft.com/link" && !code.isEmpty()) { + if (!completeVerificationUrl.isValid() && url == "https://www.microsoft.com/link" && !code.isEmpty()) { url += QString("?otc=%1").arg(code); } ui->code->setText(code); diff --git a/launcher/ui/dialogs/MSALoginDialog.h b/launcher/ui/dialogs/MSALoginDialog.h index f19abbe6d..86a1b94ee 100644 --- a/launcher/ui/dialogs/MSALoginDialog.h +++ b/launcher/ui/dialogs/MSALoginDialog.h @@ -42,7 +42,7 @@ class MSALoginDialog : public QDialog { void onDeviceFlowStatus(QString status); void onAuthFlowStatus(QString status); void authorizeWithBrowser(const QUrl& url); - void authorizeWithBrowserWithExtra(QString url, QString code, int expiresIn); + void authorizeWithBrowserWithExtra(const QUrl& verificationUrl, const QString& code, const QUrl& completeVerificationUrl); private: Ui::MSALoginDialog* ui; From 170d59de2a60bd3a2ec06e56f4fbe08b665a588a Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 7 Jan 2026 03:04:19 +0200 Subject: [PATCH 2/3] deprecate any qt version older than qt 6.9.3 Signed-off-by: Trial97 --- .github/workflows/codeql.yml | 2 +- CMakeLists.txt | 4 +- launcher/MTPixmapCache.h | 9 ++++- launcher/VersionProxyModel.cpp | 10 ++++- launcher/meta/Version.cpp | 2 +- .../auth/steps/MSADeviceCodeStep.cpp | 5 --- launcher/minecraft/skins/SkinModel.cpp | 2 +- .../modplatform/legacy_ftb/PackFetchTask.cpp | 9 ++--- launcher/news/NewsChecker.cpp | 14 +++---- launcher/ui/dialogs/ExportToModListDialog.cpp | 8 ++-- launcher/ui/dialogs/ExportToModListDialog.h | 2 +- .../ui/dialogs/skins/SkinManageDialog.cpp | 4 +- launcher/ui/dialogs/skins/draw/Scene.cpp | 8 ++-- launcher/ui/java/InstallJavaDialog.cpp | 2 +- launcher/ui/pages/modplatform/CustomPage.cpp | 10 ++--- launcher/ui/widgets/JavaSettingsWidget.cpp | 5 +-- launcher/ui/widgets/JavaWizardWidget.cpp | 4 +- .../ui/widgets/LanguageSelectionWidget.cpp | 4 +- .../ui/widgets/MinecraftSettingsWidget.cpp | 2 +- launcher/ui/widgets/ModFilterWidget.cpp | 38 +++++++++---------- 20 files changed, 76 insertions(+), 68 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f9705bf53..436ae07ee 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -37,7 +37,7 @@ jobs: uses: ./.github/actions/setup-dependencies with: build-type: Debug - qt-version: 6.4.3 + qt-version: 6.9.3 - name: Configure and Build run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 12afdefcc..23faf920f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,8 +36,8 @@ set(CMAKE_C_STANDARD 11) include(GenerateExportHeader) add_compile_definitions($<$>:QT_NO_DEBUG>) -add_compile_definitions(QT_WARN_DEPRECATED_UP_TO=0x060400) -add_compile_definitions(QT_DISABLE_DEPRECATED_UP_TO=0x060400) +add_compile_definitions(QT_WARN_DEPRECATED_UP_TO=0x060D00) +add_compile_definitions(QT_DISABLE_DEPRECATED_UP_TO=0x060903) if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") add_compile_options( diff --git a/launcher/MTPixmapCache.h b/launcher/MTPixmapCache.h index 0ba9c5ac8..e7f6dfbe3 100644 --- a/launcher/MTPixmapCache.h +++ b/launcher/MTPixmapCache.h @@ -88,7 +88,14 @@ class PixmapCache final : public QObject { QPixmapCache::remove(key); return true; } - bool _replace(const QPixmapCache::Key& key, const QPixmap& pixmap) { return QPixmapCache::replace(key, pixmap); } + bool _replace(const QPixmapCache::Key& key, const QPixmap& pixmap) + { + if (!key.isValid()) + return false; + remove(key); + const_cast(key) = insert(pixmap); + return key.isValid(); + } bool _setCacheLimit(int n) { QPixmapCache::setCacheLimit(n); diff --git a/launcher/VersionProxyModel.cpp b/launcher/VersionProxyModel.cpp index aaab7e8e0..f38c56f95 100644 --- a/launcher/VersionProxyModel.cpp +++ b/launcher/VersionProxyModel.cpp @@ -70,7 +70,15 @@ class VersionFilterModel : public QSortFilterProxyModel { return true; } - void filterChanged() { invalidateFilter(); } + void filterChanged() + { +#if QT_VERSION < QT_VERSION_CHECK(6, 10, 0) + invalidateFilter(); +#else + beginFilterChange(); + endFilterChange(); +#endif + } private: VersionProxyModel* m_parent; diff --git a/launcher/meta/Version.cpp b/launcher/meta/Version.cpp index ce9a9cc8a..156dfc65a 100644 --- a/launcher/meta/Version.cpp +++ b/launcher/meta/Version.cpp @@ -38,7 +38,7 @@ QString Meta::Version::typeString() const QDateTime Meta::Version::time() const { - return QDateTime::fromMSecsSinceEpoch(m_time * 1000, Qt::UTC); + return QDateTime::fromMSecsSinceEpoch(m_time * 1000, QTimeZone::UTC); } void Meta::Version::parse(const QJsonObject& obj) diff --git a/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp b/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp index 13c26c1a0..f2cdf8ed6 100644 --- a/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp +++ b/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp @@ -83,11 +83,6 @@ MSADeviceCodeStep::MSADeviceCodeStep(AccountData* data) : AuthStep(data) connect(&m_oauth2, &QOAuth2DeviceAuthorizationFlow::clientIdentifierChanged, this, [this](const QString& clientIdentifier) { m_data->msaClientID = clientIdentifier; }); - connect(&m_oauth2, &QOAuth2DeviceAuthorizationFlow::userCodeExpirationAtChanged, this, [](const QDateTime& expiration) { - qDebug() << "============="; - qDebug() << expiration; - qDebug() << "============="; - }); } QString MSADeviceCodeStep::describe() diff --git a/launcher/minecraft/skins/SkinModel.cpp b/launcher/minecraft/skins/SkinModel.cpp index e2c41f17b..8904b15a0 100644 --- a/launcher/minecraft/skins/SkinModel.cpp +++ b/launcher/minecraft/skins/SkinModel.cpp @@ -71,7 +71,7 @@ static QImage improveSkin(QImage skin) auto copyRect = [&p, &newSkin](int startX, int startY, int offsetX, int offsetY, int sizeX, int sizeY) { QImage region = newSkin.copy(startX, startY, sizeX, sizeY); - region = region.mirrored(true, false); + region = region.flipped(Qt::Horizontal); p.drawImage(startX + offsetX, startY + offsetY, region); }; diff --git a/launcher/modplatform/legacy_ftb/PackFetchTask.cpp b/launcher/modplatform/legacy_ftb/PackFetchTask.cpp index 7d1807ab3..cc8246835 100644 --- a/launcher/modplatform/legacy_ftb/PackFetchTask.cpp +++ b/launcher/modplatform/legacy_ftb/PackFetchTask.cpp @@ -134,12 +134,11 @@ bool PackFetchTask::parseAndAddPacks(QByteArray& data, PackType packType, Modpac { QDomDocument doc; - QString errorMsg = "Unknown error."; - int errorLine = -1; - int errorCol = -1; + auto result = doc.setContent(data); - if (!doc.setContent(data, false, &errorMsg, &errorLine, &errorCol)) { - auto fullErrMsg = QString("Failed to fetch modpack data: %1 %2:%3!").arg(errorMsg).arg(errorLine).arg(errorCol); + if (!result) { + auto fullErrMsg = + QString("Failed to fetch modpack data: %1 %2:%3!").arg(result.errorMessage).arg(result.errorLine).arg(result.errorColumn); qWarning() << fullErrMsg; return false; } diff --git a/launcher/news/NewsChecker.cpp b/launcher/news/NewsChecker.cpp index 35173dd7b..c6dbb4e07 100644 --- a/launcher/news/NewsChecker.cpp +++ b/launcher/news/NewsChecker.cpp @@ -76,18 +76,18 @@ void NewsChecker::rssDownloadFinished() m_newsNetJob.reset(); QDomDocument doc; { - // Stuff to store error info in. - QString errorMsg = "Unknown error."; - int errorLine = -1; - int errorCol = -1; - QFile feed(m_entry->getFullPath()); if (feed.open(QFile::ReadOnly | QFile::Text)) { QTextStream in(&feed); // Parse the XML. - if (!doc.setContent(in.readAll(), false, &errorMsg, &errorLine, &errorCol)) { - fail(QString("Error parsing RSS feed XML. %1 at %2:%3.").arg(errorMsg).arg(errorLine).arg(errorCol)); + auto result = doc.setContent(in.readAll()); + if (!result) { + QString fullErrorMsg = QString("Error parsing RSS feed XML. %1 at %2:%3.") + .arg(result.errorMessage) + .arg(result.errorLine) + .arg(result.errorColumn); + fail(fullErrorMsg); return; } } diff --git a/launcher/ui/dialogs/ExportToModListDialog.cpp b/launcher/ui/dialogs/ExportToModListDialog.cpp index e8873f9b4..95d44f1c0 100644 --- a/launcher/ui/dialogs/ExportToModListDialog.cpp +++ b/launcher/ui/dialogs/ExportToModListDialog.cpp @@ -47,10 +47,10 @@ ExportToModListDialog::ExportToModListDialog(QString name, QList mods, QWi enableCustom(false); connect(ui->formatComboBox, &QComboBox::currentIndexChanged, this, &ExportToModListDialog::formatChanged); - connect(ui->authorsCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger); - connect(ui->versionCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger); - connect(ui->urlCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger); - connect(ui->filenameCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger); + connect(ui->authorsCheckBox, &QCheckBox::checkStateChanged, this, &ExportToModListDialog::trigger); + connect(ui->versionCheckBox, &QCheckBox::checkStateChanged, this, &ExportToModListDialog::trigger); + connect(ui->urlCheckBox, &QCheckBox::checkStateChanged, this, &ExportToModListDialog::trigger); + connect(ui->filenameCheckBox, &QCheckBox::checkStateChanged, this, &ExportToModListDialog::trigger); connect(ui->authorsButton, &QPushButton::clicked, this, [this](bool) { addExtra(ExportToModList::Authors); }); connect(ui->versionButton, &QPushButton::clicked, this, [this](bool) { addExtra(ExportToModList::Version); }); connect(ui->urlButton, &QPushButton::clicked, this, [this](bool) { addExtra(ExportToModList::Url); }); diff --git a/launcher/ui/dialogs/ExportToModListDialog.h b/launcher/ui/dialogs/ExportToModListDialog.h index 4ebe203f7..2120e3308 100644 --- a/launcher/ui/dialogs/ExportToModListDialog.h +++ b/launcher/ui/dialogs/ExportToModListDialog.h @@ -39,7 +39,7 @@ class ExportToModListDialog : public QDialog { protected slots: void formatChanged(int index); void triggerImp(); - void trigger(int) { triggerImp(); }; + void trigger(Qt::CheckState) { triggerImp(); }; void addExtra(ExportToModList::OptionalData option); private: diff --git a/launcher/ui/dialogs/skins/SkinManageDialog.cpp b/launcher/ui/dialogs/skins/SkinManageDialog.cpp index 4dfeeaa34..a3f288c3a 100644 --- a/launcher/ui/dialogs/skins/SkinManageDialog.cpp +++ b/launcher/ui/dialogs/skins/SkinManageDialog.cpp @@ -98,7 +98,7 @@ SkinManageDialog::SkinManageDialog(QWidget* parent, MinecraftAccountPtr acct) connect(contentsWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &SkinManageDialog::selectionChanged); connect(m_ui->listView, &QListView::customContextMenuRequested, this, &SkinManageDialog::show_context_menu); - connect(m_ui->elytraCB, &QCheckBox::stateChanged, this, [this]() { + connect(m_ui->elytraCB, &QCheckBox::checkStateChanged, this, [this]() { if (m_skinPreview) { m_skinPreview->setElytraVisible(m_ui->elytraCB->isChecked()); } @@ -186,7 +186,7 @@ QPixmap previewCape(QImage capeImage, bool elytra = false) { if (elytra) { auto wing = capeImage.copy(34, 2, 12, 20); - QImage mirrored = wing.mirrored(true, false); + QImage mirrored = wing.flipped(Qt::Horizontal); QImage combined(wing.width() * 2 + 1, wing.height() + 14, capeImage.format()); combined.fill(Qt::transparent); diff --git a/launcher/ui/dialogs/skins/draw/Scene.cpp b/launcher/ui/dialogs/skins/draw/Scene.cpp index 1d06c694f..47c390ac1 100644 --- a/launcher/ui/dialogs/skins/draw/Scene.cpp +++ b/launcher/ui/dialogs/skins/draw/Scene.cpp @@ -96,11 +96,11 @@ Scene::Scene(const QImage& skin, bool slim, const QImage& cape) : QOpenGLFunctio m_elytra << leftWing << rightWing; // texture init - m_skinTexture = new QOpenGLTexture(skin.mirrored()); + m_skinTexture = new QOpenGLTexture(skin.flipped()); m_skinTexture->setMinificationFilter(QOpenGLTexture::Nearest); m_skinTexture->setMagnificationFilter(QOpenGLTexture::Nearest); - m_capeTexture = new QOpenGLTexture(cape.mirrored()); + m_capeTexture = new QOpenGLTexture(cape.flipped()); m_capeTexture->setMinificationFilter(QOpenGLTexture::Nearest); m_capeTexture->setMagnificationFilter(QOpenGLTexture::Nearest); } @@ -162,7 +162,7 @@ void updateTexture(QOpenGLTexture* texture, const QImage& img) void Scene::setSkin(const QImage& skin) { - updateTexture(m_skinTexture, skin.mirrored()); + updateTexture(m_skinTexture, skin.flipped()); } void Scene::setMode(bool slim) @@ -171,7 +171,7 @@ void Scene::setMode(bool slim) } void Scene::setCape(const QImage& cape) { - updateTexture(m_capeTexture, cape.mirrored()); + updateTexture(m_capeTexture, cape.flipped()); } void Scene::setCapeVisible(bool visible) { diff --git a/launcher/ui/java/InstallJavaDialog.cpp b/launcher/ui/java/InstallJavaDialog.cpp index fd8e43398..dddfb8789 100644 --- a/launcher/ui/java/InstallJavaDialog.cpp +++ b/launcher/ui/java/InstallJavaDialog.cpp @@ -207,7 +207,7 @@ InstallDialog::InstallDialog(const QString& uid, BaseInstance* instance, QWidget auto recommendedCheckBox = new QCheckBox("Recommended", this); recommendedCheckBox->setCheckState(Qt::CheckState::Checked); - connect(recommendedCheckBox, &QCheckBox::stateChanged, this, [this](int state) { + connect(recommendedCheckBox, &QCheckBox::checkStateChanged, this, [this](Qt::CheckState state) { for (BasePage* page : container->getPages()) { pageCast(page)->setRecommend(state == Qt::Checked); } diff --git a/launcher/ui/pages/modplatform/CustomPage.cpp b/launcher/ui/pages/modplatform/CustomPage.cpp index f24abf9fb..3ebc09406 100644 --- a/launcher/ui/pages/modplatform/CustomPage.cpp +++ b/launcher/ui/pages/modplatform/CustomPage.cpp @@ -51,11 +51,11 @@ CustomPage::CustomPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(par ui->setupUi(this); connect(ui->versionList, &VersionSelectWidget::selectedVersionChanged, this, &CustomPage::setSelectedVersion); filterChanged(); - connect(ui->alphaFilter, &QCheckBox::stateChanged, this, &CustomPage::filterChanged); - connect(ui->betaFilter, &QCheckBox::stateChanged, this, &CustomPage::filterChanged); - connect(ui->snapshotFilter, &QCheckBox::stateChanged, this, &CustomPage::filterChanged); - connect(ui->releaseFilter, &QCheckBox::stateChanged, this, &CustomPage::filterChanged); - connect(ui->experimentsFilter, &QCheckBox::stateChanged, this, &CustomPage::filterChanged); + connect(ui->alphaFilter, &QCheckBox::checkStateChanged, this, &CustomPage::filterChanged); + connect(ui->betaFilter, &QCheckBox::checkStateChanged, this, &CustomPage::filterChanged); + connect(ui->snapshotFilter, &QCheckBox::checkStateChanged, this, &CustomPage::filterChanged); + connect(ui->releaseFilter, &QCheckBox::checkStateChanged, this, &CustomPage::filterChanged); + connect(ui->experimentsFilter, &QCheckBox::checkStateChanged, this, &CustomPage::filterChanged); connect(ui->refreshBtn, &QPushButton::clicked, this, &CustomPage::refresh); connect(ui->loaderVersionList, &VersionSelectWidget::selectedVersionChanged, this, &CustomPage::setSelectedLoaderVersion); diff --git a/launcher/ui/widgets/JavaSettingsWidget.cpp b/launcher/ui/widgets/JavaSettingsWidget.cpp index e13c847d0..9c96fd432 100644 --- a/launcher/ui/widgets/JavaSettingsWidget.cpp +++ b/launcher/ui/widgets/JavaSettingsWidget.cpp @@ -62,9 +62,9 @@ JavaSettingsWidget::JavaSettingsWidget(BaseInstance* instance, QWidget* parent) if (m_instance == nullptr) { m_ui->javaDownloadBtn->hide(); if (BuildConfig.JAVA_DOWNLOADER_ENABLED) { - connect(m_ui->autodetectJavaCheckBox, &QCheckBox::stateChanged, this, [this](bool state) { + connect(m_ui->autodetectJavaCheckBox, &QCheckBox::checkStateChanged, this, [this](Qt::CheckState state) { m_ui->autodownloadJavaCheckBox->setEnabled(state); - if (!state) + if (state != Qt::Checked) m_ui->autodownloadJavaCheckBox->setChecked(false); }); } else { @@ -135,7 +135,6 @@ void JavaSettingsWidget::loadSettings() if (m_instance == nullptr) { m_ui->skipWizardCheckBox->setChecked(settings->get("IgnoreJavaWizard").toBool()); m_ui->autodetectJavaCheckBox->setChecked(settings->get("AutomaticJavaSwitch").toBool()); - m_ui->autodetectJavaCheckBox->stateChanged(m_ui->autodetectJavaCheckBox->isChecked()); m_ui->autodownloadJavaCheckBox->setChecked(settings->get("AutomaticJavaDownload").toBool()); } diff --git a/launcher/ui/widgets/JavaWizardWidget.cpp b/launcher/ui/widgets/JavaWizardWidget.cpp index bcf498b6d..8b97c2239 100644 --- a/launcher/ui/widgets/JavaWizardWidget.cpp +++ b/launcher/ui/widgets/JavaWizardWidget.cpp @@ -152,13 +152,13 @@ void JavaWizardWidget::setupUi() m_autodownloadCheckBox->setObjectName("autodownloadCheckBox"); m_autodownloadCheckBox->setEnabled(m_autodetectJavaCheckBox->isChecked()); m_veriticalJavaLayout->addWidget(m_autodownloadCheckBox); - connect(m_autodetectJavaCheckBox, &QCheckBox::stateChanged, this, [this] { + connect(m_autodetectJavaCheckBox, &QCheckBox::checkStateChanged, this, [this] { m_autodownloadCheckBox->setEnabled(m_autodetectJavaCheckBox->isChecked()); if (!m_autodetectJavaCheckBox->isChecked()) m_autodownloadCheckBox->setChecked(false); }); - connect(m_autodownloadCheckBox, &QCheckBox::stateChanged, this, [this] { + connect(m_autodownloadCheckBox, &QCheckBox::checkStateChanged, this, [this] { auto isChecked = m_autodownloadCheckBox->isChecked(); m_versionWidget->setVisible(!isChecked); m_javaStatusBtn->setVisible(!isChecked); diff --git a/launcher/ui/widgets/LanguageSelectionWidget.cpp b/launcher/ui/widgets/LanguageSelectionWidget.cpp index 3f35df7b0..bd6d82226 100644 --- a/launcher/ui/widgets/LanguageSelectionWidget.cpp +++ b/launcher/ui/widgets/LanguageSelectionWidget.cpp @@ -35,8 +35,8 @@ LanguageSelectionWidget::LanguageSelectionWidget(QWidget* parent) : QWidget(pare formatCheckbox = new QCheckBox(this); formatCheckbox->setObjectName(QStringLiteral("formatCheckbox")); formatCheckbox->setCheckState(APPLICATION->settings()->get("UseSystemLocale").toBool() ? Qt::Checked : Qt::Unchecked); - connect(formatCheckbox, &QCheckBox::stateChanged, - [this]() { APPLICATION->translations()->setUseSystemLocale(formatCheckbox->isChecked()); }); + connect(formatCheckbox, &QCheckBox::checkStateChanged, + [this] { APPLICATION->translations()->setUseSystemLocale(formatCheckbox->isChecked()); }); verticalLayout->addWidget(formatCheckbox); auto translations = APPLICATION->translations(); diff --git a/launcher/ui/widgets/MinecraftSettingsWidget.cpp b/launcher/ui/widgets/MinecraftSettingsWidget.cpp index 460068bd3..b68f37d9a 100644 --- a/launcher/ui/widgets/MinecraftSettingsWidget.cpp +++ b/launcher/ui/widgets/MinecraftSettingsWidget.cpp @@ -118,7 +118,7 @@ MinecraftSettingsWidget::MinecraftSettingsWidget(MinecraftInstance* instance, QW for (auto c : { m_ui->neoForge, m_ui->forge, m_ui->fabric, m_ui->quilt, m_ui->liteLoader, m_ui->babric, m_ui->btaBabric, m_ui->legacyFabric, m_ui->ornithe, m_ui->rift }) { - connect(c, &QCheckBox::stateChanged, this, &MinecraftSettingsWidget::saveSelectedLoaders); + connect(c, &QCheckBox::checkStateChanged, this, &MinecraftSettingsWidget::saveSelectedLoaders); } } diff --git a/launcher/ui/widgets/ModFilterWidget.cpp b/launcher/ui/widgets/ModFilterWidget.cpp index 6fab2b2a5..437cf3a4b 100644 --- a/launcher/ui/widgets/ModFilterWidget.cpp +++ b/launcher/ui/widgets/ModFilterWidget.cpp @@ -140,21 +140,21 @@ ModFilterWidget::ModFilterWidget(MinecraftInstance* instance, bool extended) ui->versions->setStyleSheet("combobox-popup: 0;"); ui->version->setStyleSheet("combobox-popup: 0;"); - connect(ui->showAllVersions, &QCheckBox::stateChanged, this, &ModFilterWidget::onShowAllVersionsChanged); + connect(ui->showAllVersions, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onShowAllVersionsChanged); connect(ui->versions, &QComboBox::currentIndexChanged, this, &ModFilterWidget::onVersionFilterChanged); connect(ui->versions, &CheckComboBox::checkedItemsChanged, this, [this] { onVersionFilterChanged(0); }); connect(ui->version, &QComboBox::currentTextChanged, this, &ModFilterWidget::onVersionFilterTextChanged); - connect(ui->neoForge, &QCheckBox::stateChanged, this, &ModFilterWidget::onLoadersFilterChanged); - connect(ui->forge, &QCheckBox::stateChanged, this, &ModFilterWidget::onLoadersFilterChanged); - connect(ui->fabric, &QCheckBox::stateChanged, this, &ModFilterWidget::onLoadersFilterChanged); - connect(ui->quilt, &QCheckBox::stateChanged, this, &ModFilterWidget::onLoadersFilterChanged); - connect(ui->liteLoader, &QCheckBox::stateChanged, this, &ModFilterWidget::onLoadersFilterChanged); - connect(ui->babric, &QCheckBox::stateChanged, this, &ModFilterWidget::onLoadersFilterChanged); - connect(ui->btaBabric, &QCheckBox::stateChanged, this, &ModFilterWidget::onLoadersFilterChanged); - connect(ui->legacyFabric, &QCheckBox::stateChanged, this, &ModFilterWidget::onLoadersFilterChanged); - connect(ui->ornithe, &QCheckBox::stateChanged, this, &ModFilterWidget::onLoadersFilterChanged); - connect(ui->rift, &QCheckBox::stateChanged, this, &ModFilterWidget::onLoadersFilterChanged); + connect(ui->neoForge, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onLoadersFilterChanged); + connect(ui->forge, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onLoadersFilterChanged); + connect(ui->fabric, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onLoadersFilterChanged); + connect(ui->quilt, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onLoadersFilterChanged); + connect(ui->liteLoader, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onLoadersFilterChanged); + connect(ui->babric, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onLoadersFilterChanged); + connect(ui->btaBabric, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onLoadersFilterChanged); + connect(ui->legacyFabric, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onLoadersFilterChanged); + connect(ui->ornithe, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onLoadersFilterChanged); + connect(ui->rift, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onLoadersFilterChanged); connect(ui->showMoreButton, &QPushButton::clicked, this, &ModFilterWidget::onShowMoreClicked); @@ -164,17 +164,17 @@ ModFilterWidget::ModFilterWidget(MinecraftInstance* instance, bool extended) } if (extended) { - connect(ui->clientSide, &QCheckBox::stateChanged, this, &ModFilterWidget::onSideFilterChanged); - connect(ui->serverSide, &QCheckBox::stateChanged, this, &ModFilterWidget::onSideFilterChanged); + connect(ui->clientSide, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onSideFilterChanged); + connect(ui->serverSide, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onSideFilterChanged); } - connect(ui->hideInstalled, &QCheckBox::stateChanged, this, &ModFilterWidget::onHideInstalledFilterChanged); - connect(ui->openSource, &QCheckBox::stateChanged, this, &ModFilterWidget::onOpenSourceFilterChanged); + connect(ui->hideInstalled, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onHideInstalledFilterChanged); + connect(ui->openSource, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onOpenSourceFilterChanged); - connect(ui->releaseCb, &QCheckBox::stateChanged, this, &ModFilterWidget::onReleaseFilterChanged); - connect(ui->betaCb, &QCheckBox::stateChanged, this, &ModFilterWidget::onReleaseFilterChanged); - connect(ui->alphaCb, &QCheckBox::stateChanged, this, &ModFilterWidget::onReleaseFilterChanged); - connect(ui->unknownCb, &QCheckBox::stateChanged, this, &ModFilterWidget::onReleaseFilterChanged); + connect(ui->releaseCb, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onReleaseFilterChanged); + connect(ui->betaCb, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onReleaseFilterChanged); + connect(ui->alphaCb, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onReleaseFilterChanged); + connect(ui->unknownCb, &QCheckBox::checkStateChanged, this, &ModFilterWidget::onReleaseFilterChanged); setHidden(true); loadVersionList(); From 1af838db2e33dce26c0ce98db3b38c11d6438d4e Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sun, 10 May 2026 23:16:46 +0300 Subject: [PATCH 3/3] chore(clang-tidy): modernize the code Signed-off-by: Trial97 --- launcher/MTPixmapCache.h | 47 +-- launcher/VersionProxyModel.cpp | 140 ++++---- launcher/VersionProxyModel.h | 34 +- launcher/meta/Version.cpp | 7 +- launcher/meta/Version.h | 4 +- launcher/minecraft/auth/AuthFlow.cpp | 11 +- launcher/minecraft/auth/AuthFlow.h | 6 +- .../auth/steps/MSADeviceCodeStep.cpp | 16 +- .../minecraft/auth/steps/MSADeviceCodeStep.h | 2 +- launcher/minecraft/auth/steps/MSAStep.cpp | 11 +- launcher/minecraft/auth/steps/MSAStep.h | 2 +- .../minecraft/mod/ResourceFolderModel.cpp | 4 +- launcher/minecraft/skins/SkinModel.cpp | 64 ++-- launcher/minecraft/skins/SkinModel.h | 15 +- .../modplatform/legacy_ftb/PackFetchTask.cpp | 38 ++- .../modplatform/legacy_ftb/PackFetchTask.h | 20 +- launcher/news/NewsChecker.cpp | 8 +- launcher/news/NewsChecker.h | 4 +- launcher/ui/dialogs/ExportToModListDialog.cpp | 130 ++++---- launcher/ui/dialogs/ExportToModListDialog.h | 10 +- launcher/ui/dialogs/MSALoginDialog.cpp | 134 ++++---- launcher/ui/dialogs/MSALoginDialog.h | 16 +- .../ui/dialogs/skins/SkinManageDialog.cpp | 102 +++--- launcher/ui/dialogs/skins/SkinManageDialog.h | 8 +- launcher/ui/dialogs/skins/draw/Scene.cpp | 37 ++- launcher/ui/java/InstallJavaDialog.cpp | 224 +++++++------ launcher/ui/java/InstallJavaDialog.h | 4 +- launcher/ui/pages/modplatform/CustomPage.cpp | 141 ++++---- launcher/ui/pages/modplatform/CustomPage.h | 21 +- launcher/ui/widgets/JavaSettingsWidget.cpp | 41 ++- launcher/ui/widgets/JavaWizardWidget.cpp | 130 ++++---- launcher/ui/widgets/JavaWizardWidget.h | 39 ++- .../ui/widgets/LanguageSelectionWidget.cpp | 89 ++--- launcher/ui/widgets/LanguageSelectionWidget.h | 14 +- .../ui/widgets/MinecraftSettingsWidget.cpp | 142 ++++---- launcher/ui/widgets/MinecraftSettingsWidget.h | 2 +- launcher/ui/widgets/ModFilterWidget.cpp | 303 ++++++++++-------- launcher/ui/widgets/ModFilterWidget.h | 24 +- 38 files changed, 1088 insertions(+), 956 deletions(-) diff --git a/launcher/MTPixmapCache.h b/launcher/MTPixmapCache.h index e7f6dfbe3..87522ef95 100644 --- a/launcher/MTPixmapCache.h +++ b/launcher/MTPixmapCache.h @@ -46,7 +46,7 @@ class PixmapCache final : public QObject { Q_OBJECT public: - PixmapCache(QObject* parent) : QObject(parent) {} + explicit PixmapCache(QObject* parent) : QObject(parent) {} ~PixmapCache() override = default; static PixmapCache& instance() { return *s_instance; } @@ -90,8 +90,9 @@ class PixmapCache final : public QObject { } bool _replace(const QPixmapCache::Key& key, const QPixmap& pixmap) { - if (!key.isValid()) + if (!key.isValid()) { return false; + } remove(key); const_cast(key) = insert(pixmap); return key.isValid(); @@ -108,33 +109,33 @@ class PixmapCache final : public QObject { */ bool _markCacheMissByEviciton() { - static constexpr uint maxCache = static_cast(std::numeric_limits::max()) / 4; - static constexpr uint step = 10240; - static constexpr int oneSecond = 1000; + static constexpr uint s_maxCache = static_cast(std::numeric_limits::max()) / 4; + static constexpr uint s_step = 10240; + static constexpr int s_oneSecond = 1000; auto now = QTime::currentTime(); - if (!m_last_cache_miss_by_eviciton.isNull()) { - auto diff = m_last_cache_miss_by_eviciton.msecsTo(now); - if (diff < oneSecond) { // less than a second ago - ++m_consecutive_fast_evicitons; + if (!m_lastCacheMissByEviciton.isNull()) { + auto diff = m_lastCacheMissByEviciton.msecsTo(now); + if (diff < s_oneSecond) { // less than a second ago + ++m_consecutiveFastEvicitons; } else { - m_consecutive_fast_evicitons = 0; + m_consecutiveFastEvicitons = 0; } } - m_last_cache_miss_by_eviciton = now; - if (m_consecutive_fast_evicitons >= m_consecutive_fast_evicitons_threshold) { + m_lastCacheMissByEviciton = now; + if (m_consecutiveFastEvicitons >= m_consecutiveFastEvicitonsThreshold) { // increase the cache size - uint newSize = _cacheLimit() + step; - if (newSize >= maxCache) { // increase it until you overflow :D - newSize = maxCache; - qDebug() << m_consecutive_fast_evicitons + uint newSize = _cacheLimit() + s_step; + if (newSize >= s_maxCache) { // increase it until you overflow :D + newSize = s_maxCache; + qDebug() << m_consecutiveFastEvicitons << tr("pixmap cache misses by eviction happened too fast, doing nothing as the cache size reached it's limit"); } else { - qDebug() << m_consecutive_fast_evicitons - << tr("pixmap cache misses by eviction happened too fast, increasing cache size to") << static_cast(newSize); + qDebug() << m_consecutiveFastEvicitons << tr("pixmap cache misses by eviction happened too fast, increasing cache size to") + << static_cast(newSize); } _setCacheLimit(static_cast(newSize)); - m_consecutive_fast_evicitons = 0; + m_consecutiveFastEvicitons = 0; return true; } return false; @@ -142,13 +143,13 @@ class PixmapCache final : public QObject { bool _setFastEvictionThreshold(int threshold) { - m_consecutive_fast_evicitons_threshold = threshold; + m_consecutiveFastEvicitonsThreshold = threshold; return true; } private: static PixmapCache* s_instance; - QTime m_last_cache_miss_by_eviciton; - int m_consecutive_fast_evicitons = 0; - int m_consecutive_fast_evicitons_threshold = 15; + QTime m_lastCacheMissByEviciton; + int m_consecutiveFastEvicitons = 0; + int m_consecutiveFastEvicitonsThreshold = 15; }; diff --git a/launcher/VersionProxyModel.cpp b/launcher/VersionProxyModel.cpp index f38c56f95..d11e7a099 100644 --- a/launcher/VersionProxyModel.cpp +++ b/launcher/VersionProxyModel.cpp @@ -44,21 +44,21 @@ class VersionFilterModel : public QSortFilterProxyModel { Q_OBJECT public: - VersionFilterModel(VersionProxyModel* parent) : QSortFilterProxyModel(parent) + explicit VersionFilterModel(VersionProxyModel* parent) : QSortFilterProxyModel(parent), m_parent(parent) { - m_parent = parent; setSortRole(BaseVersionList::SortRole); sort(0, Qt::DescendingOrder); } - bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const + bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override { const auto& filters = m_parent->filters(); const QString& search = m_parent->search(); - const QModelIndex idx = sourceModel()->index(source_row, 0, source_parent); + const QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent); - if (!search.isEmpty() && !sourceModel()->data(idx, BaseVersionList::VersionRole).toString().contains(search, Qt::CaseInsensitive)) + if (!search.isEmpty() && !sourceModel()->data(idx, BaseVersionList::VersionRole).toString().contains(search, Qt::CaseInsensitive)) { return false; + } for (auto it = filters.begin(); it != filters.end(); ++it) { auto data = sourceModel()->data(idx, it.key()); @@ -84,14 +84,13 @@ class VersionFilterModel : public QSortFilterProxyModel { VersionProxyModel* m_parent; }; -VersionProxyModel::VersionProxyModel(QObject* parent) : QAbstractProxyModel(parent) +VersionProxyModel::VersionProxyModel(QObject* parent) : QAbstractProxyModel(parent), m_filterModel(new VersionFilterModel(this)) { - filterModel = new VersionFilterModel(this); - connect(filterModel, &QAbstractItemModel::dataChanged, this, &VersionProxyModel::sourceDataChanged); - connect(filterModel, &QAbstractItemModel::rowsAboutToBeInserted, this, &VersionProxyModel::sourceRowsAboutToBeInserted); - connect(filterModel, &QAbstractItemModel::rowsInserted, this, &VersionProxyModel::sourceRowsInserted); - connect(filterModel, &QAbstractItemModel::rowsAboutToBeRemoved, this, &VersionProxyModel::sourceRowsAboutToBeRemoved); - connect(filterModel, &QAbstractItemModel::rowsRemoved, this, &VersionProxyModel::sourceRowsRemoved); + connect(m_filterModel, &QAbstractItemModel::dataChanged, this, &VersionProxyModel::sourceDataChanged); + connect(m_filterModel, &QAbstractItemModel::rowsAboutToBeInserted, this, &VersionProxyModel::sourceRowsAboutToBeInserted); + connect(m_filterModel, &QAbstractItemModel::rowsInserted, this, &VersionProxyModel::sourceRowsInserted); + connect(m_filterModel, &QAbstractItemModel::rowsAboutToBeRemoved, this, &VersionProxyModel::sourceRowsAboutToBeRemoved); + connect(m_filterModel, &QAbstractItemModel::rowsRemoved, this, &VersionProxyModel::sourceRowsRemoved); // FIXME: implement when needed /* connect(replacing, &QAbstractItemModel::rowsAboutToBeMoved, this, &VersionProxyModel::sourceRowsAboutToBeMoved); @@ -99,18 +98,20 @@ VersionProxyModel::VersionProxyModel(QObject* parent) : QAbstractProxyModel(pare connect(replacing, &QAbstractItemModel::layoutAboutToBeChanged, this, &VersionProxyModel::sourceLayoutAboutToBeChanged); connect(replacing, &QAbstractItemModel::layoutChanged, this, &VersionProxyModel::sourceLayoutChanged); */ - connect(filterModel, &QAbstractItemModel::modelAboutToBeReset, this, &VersionProxyModel::sourceAboutToBeReset); - connect(filterModel, &QAbstractItemModel::modelReset, this, &VersionProxyModel::sourceReset); + connect(m_filterModel, &QAbstractItemModel::modelAboutToBeReset, this, &VersionProxyModel::sourceAboutToBeReset); + connect(m_filterModel, &QAbstractItemModel::modelReset, this, &VersionProxyModel::sourceReset); - QAbstractProxyModel::setSourceModel(filterModel); + QAbstractProxyModel::setSourceModel(m_filterModel); } QVariant VersionProxyModel::headerData(int section, Qt::Orientation orientation, int role) const { - if (section < 0 || section >= m_columns.size()) - return QVariant(); - if (orientation != Qt::Horizontal) - return QVariant(); + if (section < 0 || section >= m_columns.size()) { + return {}; + } + if (orientation != Qt::Horizontal) { + return {}; + } auto column = m_columns[section]; if (role == Qt::DisplayRole) { switch (column) { @@ -161,7 +162,7 @@ QVariant VersionProxyModel::headerData(int section, Qt::Orientation orientation, QVariant VersionProxyModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) { - return QVariant(); + return {}; } auto column = m_columns[index.column()]; auto parentIndex = mapToSource(index); @@ -196,11 +197,12 @@ QVariant VersionProxyModel::data(const QModelIndex& index, int role) const } } case Qt::ToolTipRole: { - if (column == Name && hasRecommended) { + if (column == Name && m_hasRecommended) { auto value = sourceModel()->data(parentIndex, BaseVersionList::RecommendedRole); if (value.toBool()) { return tr("Recommended"); - } else if (hasLatest) { + } + if (m_hasLatest) { auto latest = sourceModel()->data(parentIndex, BaseVersionList::LatestRole); if (latest.toBool()) { return tr("Latest"); @@ -210,11 +212,12 @@ QVariant VersionProxyModel::data(const QModelIndex& index, int role) const return sourceModel()->data(parentIndex, BaseVersionList::VersionIdRole); } case Qt::DecorationRole: { - if (column == Name && hasRecommended) { + if (column == Name && m_hasRecommended) { auto recommenced = sourceModel()->data(parentIndex, BaseVersionList::RecommendedRole); if (recommenced.toBool()) { return QIcon::fromTheme("star"); - } else if (hasLatest) { + } + if (m_hasLatest) { auto latest = sourceModel()->data(parentIndex, BaseVersionList::LatestRole); if (latest.toBool()) { return QIcon::fromTheme("bug"); @@ -233,7 +236,7 @@ QVariant VersionProxyModel::data(const QModelIndex& index, int role) const return QVariant(); } default: { - if (roles.contains((BaseVersionList::ModelRoles)role)) { + if (m_roles.contains((BaseVersionList::ModelRoles)role)) { return sourceModel()->data(parentIndex, role); } return QVariant(); @@ -266,18 +269,20 @@ QModelIndex VersionProxyModel::index(int row, int column, const QModelIndex& par { // no trees here... shoo if (parent.isValid()) { - return QModelIndex(); + return {}; + } + if (row < 0 || row >= sourceModel()->rowCount()) { + return {}; + } + if (column < 0 || column >= columnCount()) { + return {}; } - if (row < 0 || row >= sourceModel()->rowCount()) - return QModelIndex(); - if (column < 0 || column >= columnCount()) - return QModelIndex(); return QAbstractItemModel::createIndex(row, column); } int VersionProxyModel::columnCount(const QModelIndex& parent) const { - return parent.isValid() ? 0 : m_columns.size(); + return parent.isValid() ? 0 : static_cast(m_columns.size()); } int VersionProxyModel::rowCount(const QModelIndex& parent) const @@ -288,30 +293,31 @@ int VersionProxyModel::rowCount(const QModelIndex& parent) const return 0; } -void VersionProxyModel::sourceDataChanged(const QModelIndex& source_top_left, const QModelIndex& source_bottom_right) +void VersionProxyModel::sourceDataChanged(const QModelIndex& sourceTopLeft, const QModelIndex& sourceBottomRight) { - if (source_top_left.parent() != source_bottom_right.parent()) - return; - - // whole row is getting changed - auto topLeft = createIndex(source_top_left.row(), 0); - auto bottomRight = createIndex(source_bottom_right.row(), columnCount() - 1); - emit dataChanged(topLeft, bottomRight); -} - -void VersionProxyModel::setSourceModel(QAbstractItemModel* replacingRaw) -{ - auto replacing = dynamic_cast(replacingRaw); - - m_columns.clear(); - if (!replacing) { - roles.clear(); - filterModel->setSourceModel(replacing); + if (sourceTopLeft.parent() != sourceBottomRight.parent()) { return; } - roles = replacing->providesRoles(); - if (roles.contains(BaseVersionList::VersionRole)) { + // whole row is getting changed + auto topLeft = createIndex(sourceTopLeft.row(), 0); + auto bottomRight = createIndex(sourceBottomRight.row(), columnCount() - 1); + emit dataChanged(topLeft, bottomRight); +} + +void VersionProxyModel::setSourceModel(QAbstractItemModel* sourceModel) +{ + auto* replacing = dynamic_cast(sourceModel); + + m_columns.clear(); + if (!replacing) { + m_roles.clear(); + m_filterModel->setSourceModel(replacing); + return; + } + + m_roles = replacing->providesRoles(); + if (m_roles.contains(BaseVersionList::VersionRole)) { m_columns.push_back(Name); } /* @@ -320,39 +326,39 @@ void VersionProxyModel::setSourceModel(QAbstractItemModel* replacingRaw) m_columns.push_back(ParentVersion); } */ - if (roles.contains(BaseVersionList::CPUArchitectureRole)) { + if (m_roles.contains(BaseVersionList::CPUArchitectureRole)) { m_columns.push_back(CPUArchitecture); } - if (roles.contains(BaseVersionList::PathRole)) { + if (m_roles.contains(BaseVersionList::PathRole)) { m_columns.push_back(Path); } - if (roles.contains(BaseVersionList::JavaNameRole)) { + if (m_roles.contains(BaseVersionList::JavaNameRole)) { m_columns.push_back(JavaName); } - if (roles.contains(BaseVersionList::JavaMajorRole)) { + if (m_roles.contains(BaseVersionList::JavaMajorRole)) { m_columns.push_back(JavaMajor); } - if (roles.contains(Meta::VersionList::TimeRole)) { + if (m_roles.contains(Meta::VersionList::TimeRole)) { m_columns.push_back(Time); } - if (roles.contains(BaseVersionList::BranchRole)) { + if (m_roles.contains(BaseVersionList::BranchRole)) { m_columns.push_back(Branch); } - if (roles.contains(BaseVersionList::TypeRole)) { + if (m_roles.contains(BaseVersionList::TypeRole)) { m_columns.push_back(Type); } - if (roles.contains(BaseVersionList::RecommendedRole)) { - hasRecommended = true; + if (m_roles.contains(BaseVersionList::RecommendedRole)) { + m_hasRecommended = true; } - if (roles.contains(BaseVersionList::LatestRole)) { - hasLatest = true; + if (m_roles.contains(BaseVersionList::LatestRole)) { + m_hasLatest = true; } - filterModel->setSourceModel(replacing); + m_filterModel->setSourceModel(replacing); } QModelIndex VersionProxyModel::getRecommended() const { - if (!roles.contains(BaseVersionList::RecommendedRole)) { + if (!m_roles.contains(BaseVersionList::RecommendedRole)) { return index(0, 0); } int recommended = 0; @@ -384,19 +390,19 @@ void VersionProxyModel::clearFilters() { m_filters.clear(); m_search.clear(); - filterModel->filterChanged(); + m_filterModel->filterChanged(); } void VersionProxyModel::setFilter(const BaseVersionList::ModelRoles column, Filter f) { m_filters[column] = std::move(f); - filterModel->filterChanged(); + m_filterModel->filterChanged(); } void VersionProxyModel::setSearch(const QString& search) { m_search = search; - filterModel->filterChanged(); + m_filterModel->filterChanged(); } const VersionProxyModel::FilterMap& VersionProxyModel::filters() const diff --git a/launcher/VersionProxyModel.h b/launcher/VersionProxyModel.h index ddd5d2458..8be51d592 100644 --- a/launcher/VersionProxyModel.h +++ b/launcher/VersionProxyModel.h @@ -9,22 +9,22 @@ class VersionFilterModel; class VersionProxyModel : public QAbstractProxyModel { Q_OBJECT public: - enum Column { Name, ParentVersion, Branch, Type, CPUArchitecture, Path, Time, JavaName, JavaMajor }; + enum Column : std::uint8_t { Name, ParentVersion, Branch, Type, CPUArchitecture, Path, Time, JavaName, JavaMajor }; using FilterMap = QHash; public: - VersionProxyModel(QObject* parent = 0); - virtual ~VersionProxyModel() {}; + explicit VersionProxyModel(QObject* parent = nullptr); + ~VersionProxyModel() override = default; - virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override; - virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override; - virtual QModelIndex mapFromSource(const QModelIndex& sourceIndex) const override; - virtual QModelIndex mapToSource(const QModelIndex& proxyIndex) const override; - virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; - virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; - virtual QModelIndex parent(const QModelIndex& child) const override; - virtual void setSourceModel(QAbstractItemModel* sourceModel) override; + int columnCount(const QModelIndex& parent = QModelIndex()) const override; + int rowCount(const QModelIndex& parent = QModelIndex()) const override; + QModelIndex mapFromSource(const QModelIndex& sourceIndex) const override; + QModelIndex mapToSource(const QModelIndex& proxyIndex) const override; + QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + QModelIndex parent(const QModelIndex& child) const override; + void setSourceModel(QAbstractItemModel* sourceModel) override; const FilterMap& filters() const; const QString& search() const; @@ -36,7 +36,7 @@ class VersionProxyModel : public QAbstractProxyModel { void setCurrentVersion(const QString& version); private slots: - void sourceDataChanged(const QModelIndex& source_top_left, const QModelIndex& source_bottom_right); + void sourceDataChanged(const QModelIndex& sourceTopLeft, const QModelIndex& sourceBottomRight); void sourceAboutToBeReset(); void sourceReset(); @@ -51,9 +51,9 @@ class VersionProxyModel : public QAbstractProxyModel { QList m_columns; FilterMap m_filters; QString m_search; - BaseVersionList::RoleList roles; - VersionFilterModel* filterModel; - bool hasRecommended = false; - bool hasLatest = false; + BaseVersionList::RoleList m_roles; + VersionFilterModel* m_filterModel; + bool m_hasRecommended = false; + bool m_hasLatest = false; QString m_currentVersion; }; diff --git a/launcher/meta/Version.cpp b/launcher/meta/Version.cpp index 156dfc65a..c1782bba5 100644 --- a/launcher/meta/Version.cpp +++ b/launcher/meta/Version.cpp @@ -27,8 +27,9 @@ QString Meta::Version::descriptor() const } QString Meta::Version::name() const { - if (m_data) + if (m_data) { return m_data->name; + } return m_uid; } QString Meta::Version::typeString() const @@ -110,9 +111,9 @@ void Meta::Version::setRequires(const Meta::RequireSet& reqs, const Meta::Requir emit requiresChanged(); } -void Meta::Version::setVolatile(bool volatile_) +void Meta::Version::setVolatile(bool volatileVar) { - m_volatile = volatile_; + m_volatile = volatileVar; } void Meta::Version::setData(const VersionFilePtr& data) diff --git a/launcher/meta/Version.h b/launcher/meta/Version.h index a2bbc6176..55534f38b 100644 --- a/launcher/meta/Version.h +++ b/launcher/meta/Version.h @@ -38,7 +38,7 @@ class Version : public QObject, public BaseVersion, public BaseEntity { using Ptr = std::shared_ptr; explicit Version(const QString& uid, const QString& version); - virtual ~Version() = default; + ~Version() override = default; QString descriptor() const override; QString name() const override; @@ -66,7 +66,7 @@ class Version : public QObject, public BaseVersion, public BaseEntity { void setType(const QString& type); void setTime(qint64 time); void setRequires(const Meta::RequireSet& reqs, const Meta::RequireSet& conflicts); - void setVolatile(bool volatile_); + void setVolatile(bool volatileVar); void setRecommended(bool recommended); void setProvidesRecommendations(); void setData(const VersionFilePtr& data); diff --git a/launcher/minecraft/auth/AuthFlow.cpp b/launcher/minecraft/auth/AuthFlow.cpp index 5b8f98122..553d1587b 100644 --- a/launcher/minecraft/auth/AuthFlow.cpp +++ b/launcher/minecraft/auth/AuthFlow.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "minecraft/auth/AccountData.h" #include "minecraft/auth/steps/EntitlementsStep.h" @@ -17,7 +18,7 @@ #include -AuthFlow::AuthFlow(AccountData* data, Action action) : Task(), m_data(data) +AuthFlow::AuthFlow(AccountData* data, Action action) : m_data(data) { if (data->type == AccountType::MSA) { if (action == Action::DeviceCode) { @@ -75,11 +76,12 @@ void AuthFlow::nextStep() void AuthFlow::stepFinished(AccountTaskState resultingState, QString message) { - if (changeState(resultingState, message)) + if (changeState(resultingState, std::move(message))) { nextStep(); + } } -bool AuthFlow::changeState(AccountTaskState newState, QString reason) +bool AuthFlow::changeState(AccountTaskState newState, const QString& reason) { m_taskState = newState; setDetails(reason); @@ -148,8 +150,9 @@ bool AuthFlow::changeState(AccountTaskState newState, QString reason) } bool AuthFlow::abort() { - if (m_currentStep) + if (m_currentStep) { m_currentStep->abort(); + } emitAborted(); return true; } diff --git a/launcher/minecraft/auth/AuthFlow.h b/launcher/minecraft/auth/AuthFlow.h index b8a6db5ea..c1628a62b 100644 --- a/launcher/minecraft/auth/AuthFlow.h +++ b/launcher/minecraft/auth/AuthFlow.h @@ -13,10 +13,10 @@ class AuthFlow : public Task { Q_OBJECT public: - enum class Action { Refresh, Login, DeviceCode }; + enum class Action : std::uint8_t { Refresh, Login, DeviceCode }; explicit AuthFlow(AccountData* data, Action action = Action::Refresh); - virtual ~AuthFlow() = default; + ~AuthFlow() override = default; void executeTask() override; @@ -35,7 +35,7 @@ class AuthFlow : public Task { private slots: // NOTE: true -> non-terminal state, false -> terminal state - bool changeState(AccountTaskState newState, QString reason = QString()); + bool changeState(AccountTaskState newState, const QString& reason = {}); void stepFinished(AccountTaskState resultingState, QString message); private: diff --git a/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp b/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp index f2cdf8ed6..141d620a4 100644 --- a/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp +++ b/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp @@ -73,7 +73,7 @@ MSADeviceCodeStep::MSADeviceCodeStep(AccountData* data) : AuthStep(data) emit finished(state, message); }); connect(&m_oauth2, &QOAuth2DeviceAuthorizationFlow::serverReportedErrorOccurred, this, - [this](const QString& error, const QString& errorDescription, const QUrl& uri) { + [this](const QString& error, const QString& errorDescription, const QUrl& /*uri*/) { qWarning() << "Failed to login because" << error << errorDescription; emit finished(AccountTaskState::STATE_FAILED_HARD, errorDescription); }); @@ -97,21 +97,11 @@ void MSADeviceCodeStep::perform() m_oauth2.grant(); } -struct DeviceAuthorizationResponse { - QString device_code; - QString user_code; - QString verification_uri; - int expires_in; - int interval; - - QString error; - QString error_description; -}; - void MSADeviceCodeStep::abort() { - if (m_oauth2.isPolling()) + if (m_oauth2.isPolling()) { m_oauth2.stopTokenPolling(); + } emit finished(AccountTaskState::STATE_FAILED_HARD, tr("Task aborted")); } diff --git a/launcher/minecraft/auth/steps/MSADeviceCodeStep.h b/launcher/minecraft/auth/steps/MSADeviceCodeStep.h index fe9cff189..ca228d11d 100644 --- a/launcher/minecraft/auth/steps/MSADeviceCodeStep.h +++ b/launcher/minecraft/auth/steps/MSADeviceCodeStep.h @@ -44,7 +44,7 @@ class MSADeviceCodeStep : public AuthStep { Q_OBJECT public: explicit MSADeviceCodeStep(AccountData* data); - virtual ~MSADeviceCodeStep() noexcept = default; + ~MSADeviceCodeStep() noexcept override = default; void perform() override; diff --git a/launcher/minecraft/auth/steps/MSAStep.cpp b/launcher/minecraft/auth/steps/MSAStep.cpp index 93137f66f..c78077f17 100644 --- a/launcher/minecraft/auth/steps/MSAStep.cpp +++ b/launcher/minecraft/auth/steps/MSAStep.cpp @@ -36,19 +36,19 @@ #include "MSAStep.h" #include -#include #include +#include #include #include #include "Application.h" #include "BuildConfig.h" -#include "FileSystem.h" #include #include #include +namespace { bool isSchemeHandlerRegistered() { #ifdef Q_OS_LINUX @@ -110,6 +110,7 @@ class LoggingOAuthHttpServerReplyHandler final : public QOAuthHttpServerReplyHan QOAuthHttpServerReplyHandler::networkReplyFinished(reply); } }; +} // namespace MSAStep::MSAStep(AccountData* data, bool silent) : AuthStep(data), m_silent(silent) { @@ -117,7 +118,7 @@ MSAStep::MSAStep(AccountData* data, bool silent) : AuthStep(data), m_silent(sile if (QCoreApplication::applicationFilePath().startsWith("/tmp/.mount_") || APPLICATION->isPortable() || !isSchemeHandlerRegistered()) { - auto replyHandler = new LoggingOAuthHttpServerReplyHandler(this); + auto* replyHandler = new LoggingOAuthHttpServerReplyHandler(this); replyHandler->setCallbackText(QString(R"XXX(