From ef003ba769925bed14b07e2a3e174a6c1addfac6 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Sun, 30 Jan 2022 11:37:39 +0200 Subject: [PATCH] Android: Simplify SDK setup process by minimizing number of dialogs SDK setup process currently downloads the SDK tools, then checks the mandatory packages, asks the user if they want to install them, then show a dialog with package details, then asks again whether the user wants to check the licenses. The following two steps are redundant because there's a dialog which guards the package installation and waits for user's input: * Asking the user if they want to install the mandatory packages * Asking the user if they want to verify the licenses Change-Id: If06c0adea9444107a149c3ec32be67061954d1bb Reviewed-by: Alessandro Portale --- .../android/androidsdkmanagerwidget.cpp | 34 +++++++------------ src/plugins/android/androidsdkmanagerwidget.h | 4 +-- src/plugins/android/androidsettingswidget.cpp | 11 ++---- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/src/plugins/android/androidsdkmanagerwidget.cpp b/src/plugins/android/androidsdkmanagerwidget.cpp index 6d330960f79..be93c03f609 100644 --- a/src/plugins/android/androidsdkmanagerwidget.cpp +++ b/src/plugins/android/androidsdkmanagerwidget.cpp @@ -137,7 +137,7 @@ AndroidSdkManagerWidget::AndroidSdkManagerWidget(AndroidConfig &config, }); connect(m_ui->applySelectionButton, &QPushButton::clicked, - this, &AndroidSdkManagerWidget::onApplyButton); + this, [this]() { onApplyButton(); }); connect(m_ui->cancelButton, &QPushButton::clicked, this, &AndroidSdkManagerWidget::onCancel); connect(m_ui->optionsButton, &QPushButton::clicked, @@ -204,7 +204,7 @@ AndroidSdkManagerWidget::~AndroidSdkManagerWidget() delete m_ui; } -void AndroidSdkManagerWidget::installEssentials() +void AndroidSdkManagerWidget::installEssentials(const QString &extraMessage) { m_sdkModel->selectMissingEssentials(); if (!m_sdkModel->missingEssentials().isEmpty()) { @@ -215,16 +215,19 @@ void AndroidSdkManagerWidget::installEssentials() .arg(Core::Constants::IDE_DISPLAY_NAME) .arg(m_sdkModel->missingEssentials().join("\", \""))); } - onApplyButton(); + onApplyButton(extraMessage); } void AndroidSdkManagerWidget::beginLicenseCheck() { m_formatter->appendMessage(tr("Checking pending licenses...\n"), Utils::NormalMessageFormat); + m_formatter->appendMessage(tr("The installation of Android SDK packages may fail if the " + "respective licenses are not accepted.\n"), + Utils::LogMessageFormat); addPackageFuture(m_sdkManager->checkPendingLicenses()); } -void AndroidSdkManagerWidget::onApplyButton() +void AndroidSdkManagerWidget::onApplyButton(const QString &extraMessage) { QTC_ASSERT(m_currentView == PackageListing, return); @@ -246,10 +249,11 @@ void AndroidSdkManagerWidget::onApplyButton() installPackages << str; } + QString message = tr("%n Android SDK packages shall be updated.", "", packagesToUpdate.count()); + if (!extraMessage.isEmpty()) + message.prepend(extraMessage + "\n\n"); QMessageBox messageDlg(QMessageBox::Information, tr("Android SDK Changes"), - tr("%n Android SDK packages shall be updated.", - "", packagesToUpdate.count()), - QMessageBox::Ok | QMessageBox::Cancel, this); + message, QMessageBox::Ok | QMessageBox::Cancel, this); QString details; if (!uninstallPackages.isEmpty()) @@ -317,20 +321,8 @@ void AndroidSdkManagerWidget::onLicenseCheckResult(const AndroidSdkManager::Oper // No assertion was found. Looks like all license are accepted. Go Ahead. runPendingCommand(); } else { - // Assertion was found. Provide user workflow to accept licenses. - QString warningMessage = tr("Review Android SDK package licenses that have not been " - "accepted?\nNote that the installation and use of " - "Android SDK packages may fail if respective licenses are not " - "accepted."); - int userSelection = QMessageBox::question(this, tr("Android SDK Licenses"), warningMessage, - QMessageBox::Yes | QMessageBox::No); - if (userSelection == QMessageBox::Yes) { - // Run license workflow. - beginLicenseWorkflow(); - } else { - // User decided to go ahead anyways. - runPendingCommand(); - } + // Run license workflow. + beginLicenseWorkflow(); } } diff --git a/src/plugins/android/androidsdkmanagerwidget.h b/src/plugins/android/androidsdkmanagerwidget.h index 58be2ce7af2..5266290b109 100644 --- a/src/plugins/android/androidsdkmanagerwidget.h +++ b/src/plugins/android/androidsdkmanagerwidget.h @@ -80,7 +80,7 @@ public: QWidget *parent = nullptr); ~AndroidSdkManagerWidget() override; - void installEssentials(); + void installEssentials(const QString &extraMessage = {}); signals: void updatingSdk(); @@ -88,7 +88,7 @@ signals: void licenseWorkflowStarted(); private: - void onApplyButton(); + void onApplyButton(const QString &extraMessage = {}); void onUpdatePackages(); void onCancel(); void onOperationResult(int index); diff --git a/src/plugins/android/androidsettingswidget.cpp b/src/plugins/android/androidsettingswidget.cpp index fda3366a95f..e928023937a 100644 --- a/src/plugins/android/androidsettingswidget.cpp +++ b/src/plugins/android/androidsettingswidget.cpp @@ -544,14 +544,9 @@ void AndroidSettingsWidget::validateSdk() AllEssentialsInstalledRow}); m_androidConfig.setSdkFullyConfigured(sdkToolsOk && componentsOk); if (sdkToolsOk && !componentsOk) { - // Ask user to install essential SDK components. Works only for sdk tools version >= 26.0.0 - QString message = tr("Android SDK installation is missing necessary packages. Do you " - "want to install the missing packages?"); - auto userInput = QMessageBox::information(this, tr("Missing Android SDK Packages"), - message, QMessageBox::Yes | QMessageBox::No); - if (userInput == QMessageBox::Yes) { - m_sdkManagerWidget->installEssentials(); - } + m_sdkManagerWidget->installEssentials( + "Android SDK installation is missing necessary packages. " + "Do you want to install the missing packages?"); } updateNdkList();