diff --git a/src/libs/utils/utilsicons.cpp b/src/libs/utils/utilsicons.cpp index 3ba5a7514fb..704ffd9e3cf 100644 --- a/src/libs/utils/utilsicons.cpp +++ b/src/libs/utils/utilsicons.cpp @@ -42,6 +42,8 @@ const Icon LOCKED({ {QLatin1String(":/utils/images/locked.png"), Theme::PanelTextColorDark}}, Icon::Tint); const Icon UNLOCKED_TOOLBAR({ {QLatin1String(":/utils/images/unlocked.png"), Theme::IconsBaseColor}}); +const Icon UNLOCKED({ + {QLatin1String(":/utils/images/unlocked.png"), Theme::PanelTextColorDark}}, Icon::Tint); const Icon PINNED({ {QLatin1String(":/utils/images/pinned.png"), Theme::PanelTextColorDark}}, Icon::Tint); const Icon NEXT({ diff --git a/src/libs/utils/utilsicons.h b/src/libs/utils/utilsicons.h index 04a7566a28b..0bd317fbbb6 100644 --- a/src/libs/utils/utilsicons.h +++ b/src/libs/utils/utilsicons.h @@ -38,6 +38,7 @@ QTCREATOR_UTILS_EXPORT extern const Icon EDIT_CLEAR_TOOLBAR; QTCREATOR_UTILS_EXPORT extern const Icon LOCKED_TOOLBAR; QTCREATOR_UTILS_EXPORT extern const Icon LOCKED; QTCREATOR_UTILS_EXPORT extern const Icon UNLOCKED_TOOLBAR; +QTCREATOR_UTILS_EXPORT extern const Icon UNLOCKED; QTCREATOR_UTILS_EXPORT extern const Icon PINNED; QTCREATOR_UTILS_EXPORT extern const Icon NEXT; QTCREATOR_UTILS_EXPORT extern const Icon NEXT_TOOLBAR; diff --git a/src/plugins/android/androidsettingswidget.cpp b/src/plugins/android/androidsettingswidget.cpp index 30875271c10..62ba4c23087 100644 --- a/src/plugins/android/androidsettingswidget.cpp +++ b/src/plugins/android/androidsettingswidget.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -360,25 +361,44 @@ void AndroidSettingsWidget::showEvent(QShowEvent *event) void AndroidSettingsWidget::updateNdkList() { - m_ui->ndkListComboBox->clear(); - for (const Ndk *ndk : m_sdkManager->installedNdkPackages()) - m_ui->ndkListComboBox->addItem(ndk->installedLocation().toString()); + m_ui->ndkListWidget->clear(); + for (const Ndk *ndk : m_sdkManager->installedNdkPackages()) { + m_ui->ndkListWidget->addItem(new QListWidgetItem(Utils::Icons::LOCKED.icon(), + ndk->installedLocation().toString())); + } for (const QString &ndk : m_androidConfig.getCustomNdkList()) { - if (m_androidConfig.isValidNdk(ndk)) - m_ui->ndkListComboBox->addItem(ndk); - else + if (m_androidConfig.isValidNdk(ndk)) { + m_ui->ndkListWidget->addItem( + new QListWidgetItem(Utils::Icons::UNLOCKED.icon(), ndk)); + } else { m_androidConfig.removeCustomNdk(ndk); + } } + + m_ui->ndkListWidget->setCurrentRow(0); } void AndroidSettingsWidget::addCustomNdkItem() { - const QString ndkPath = QDir::toNativeSeparators(m_ui->customNdkPathChooser->rawPath()); - m_androidConfig.addCustomNdk(ndkPath); - if (m_ui->ndkListComboBox->findData(ndkPath) == -1) - m_ui->ndkListComboBox->addItem(ndkPath); - m_ui->ndkListComboBox->setCurrentText(ndkPath); + const QString homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first(); + const QString ndkPath = QFileDialog::getExistingDirectory(this, tr("Select an NDK"), homePath); + + if (m_androidConfig.isValidNdk(ndkPath)) { + m_androidConfig.addCustomNdk(ndkPath); + if (m_ui->ndkListWidget->findItems(ndkPath, Qt::MatchExactly).size() == 0) { + m_ui->ndkListWidget->addItem( + new QListWidgetItem(Utils::Icons::UNLOCKED.icon(), ndkPath)); + } + } else if (!ndkPath.isEmpty()) { + QMessageBox::warning( + this, + tr("Add Custom NDK"), + tr("The selected path has an invalid NDK. This might mean that the path contains space " + "characters, or that it does not have a \"toolchains\" sub-directory, or that the " + "NDK version could not be retrieved because of a missing \"source.properties\" or " + "\"RELEASE.TXT\" file")); + } } AndroidSettingsWidget::AndroidSettingsWidget() @@ -481,25 +501,18 @@ AndroidSettingsWidget::AndroidSettingsWidget() connect(m_ui->SDKLocationPathChooser, &Utils::PathChooser::rawPathChanged, this, &AndroidSettingsWidget::onSdkPathChanged); - connect(m_ui->ndkListComboBox, - QOverload::of(&QComboBox::currentIndexChanged), - [this](const QString &ndk) { - validateNdk(); - m_ui->removeCustomNdkButton->setEnabled(m_androidConfig.getCustomNdkList().contains(ndk)); - }); - connect(m_ui->customNdkPathChooser, &Utils::PathChooser::rawPathChanged, this, [this]() { - const QString ndkPath = m_ui->customNdkPathChooser->rawPath(); - m_ui->addCustomNdkButton->setEnabled(m_androidConfig.isValidNdk(ndkPath)); + + connect(m_ui->ndkListWidget, &QListWidget::currentTextChanged, [this](const QString &ndk) { + validateNdk(); + m_ui->removeCustomNdkButton->setEnabled(m_androidConfig.getCustomNdkList().contains(ndk)); }); connect(m_ui->addCustomNdkButton, &QPushButton::clicked, this, &AndroidSettingsWidget::addCustomNdkItem); connect(m_ui->removeCustomNdkButton, &QPushButton::clicked, this, [this]() { - m_androidConfig.removeCustomNdk(m_ui->ndkListComboBox->currentText()); - m_ui->ndkListComboBox->removeItem(m_ui->ndkListComboBox->currentIndex()); + m_androidConfig.removeCustomNdk(m_ui->ndkListWidget->currentItem()->text()); + m_ui->ndkListWidget->takeItem(m_ui->ndkListWidget->currentRow()); }); - connect(m_ui->ndkListComboBox, QOverload::of(&QComboBox::currentIndexChanged), - [this](const QString) { validateNdk(); }); connect(m_ui->openSslPathChooser, &Utils::PathChooser::rawPathChanged, this, &AndroidSettingsWidget::validateOpenSsl); connect(&m_virtualDevicesWatcher, &QFutureWatcherBase::finished, @@ -664,7 +677,8 @@ Utils::FilePath AndroidSettingsWidget::findJdkInCommonPaths() void AndroidSettingsWidget::validateNdk() { - auto ndkPath = Utils::FilePath::fromUserInput(m_ui->ndkListComboBox->currentText()); + const QListWidgetItem *currentItem = m_ui->ndkListWidget->currentItem(); + Utils::FilePath ndkPath = Utils::FilePath::fromString(currentItem ? currentItem->text() : ""); auto summaryWidget = static_cast(m_ui->androidDetailsWidget->widget()); summaryWidget->setPointValid(NdkPathExistsRow, ndkPath.exists()); @@ -889,7 +903,8 @@ void AndroidSettingsWidget::updateUI() m_ui->sdkManagerTab->setEnabled(sdkToolsOk); m_sdkManagerWidget->setSdkManagerControlsEnabled(!m_androidConfig.useNativeUiTools()); - Utils::FilePath currentNdk = Utils::FilePath::fromString(m_ui->ndkListComboBox->currentText()); + const QListWidgetItem *currentItem = m_ui->ndkListWidget->currentItem(); + Utils::FilePath currentNdk = Utils::FilePath::fromString(currentItem ? currentItem->text() : ""); auto infoText = tr("(SDK Version: %1, NDK Bundle Version: %2)") .arg(m_androidConfig.sdkToolsVersion().toString()) .arg(currentNdk.isEmpty() ? "" : m_androidConfig.ndkVersion(currentNdk).toString()); diff --git a/src/plugins/android/androidsettingswidget.ui b/src/plugins/android/androidsettingswidget.ui index 2a25b93386c..12d54c07856 100644 --- a/src/plugins/android/androidsettingswidget.ui +++ b/src/plugins/android/androidsettingswidget.ui @@ -106,23 +106,6 @@ - - - - Add custom NDK: - - - - - - - - - - - - - @@ -133,7 +116,27 @@ - + + + + Download Android SDK + + + + + + + + + + + + + + + + + @@ -143,63 +146,76 @@ - - - - Download Android SDK + + + + QAbstractScrollArea::AdjustToContents - - - - - - - 20 - 0 - + + QListView::Adjust - - - - - + + 0 + + false - - - 0 - 0 - - - - Add the selected custom NDK. The toolchains and debuggers will be created automatically. - - - Add - - - - - - - - false - - - - 0 - 0 - - - - Remove the selected custom NDK. - - - Remove - - + + + + + + true + + + + 0 + 0 + + + + Add the selected custom NDK. The toolchains and debuggers will be created automatically. + + + Add... + + + + + + + false + + + + 0 + 0 + + + + Remove the selected NDK if it has been added manually. + + + Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + +