Android: use QListWidget to show defined NDKs

Use QListWidget to show all installed NDKs (from SDK manager), and NDKs
Added manually by the user. Each item has an icon to indicate if it's
removable when added by the user, or non-removable if installed from the
SDK manager.

Change-Id: I26ae5909ce930d5cc8af561b6b4e9cc5415d12f1
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Assam Boudjelthia
2020-03-11 18:49:02 +02:00
parent 3faa91945a
commit 7fd0f30776
4 changed files with 129 additions and 95 deletions

View File

@@ -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({

View File

@@ -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;

View File

@@ -54,6 +54,7 @@
#include <QAbstractTableModel>
#include <QDesktopServices>
#include <QDir>
#include <QFileDialog>
#include <QFutureWatcher>
#include <QList>
#include <QMessageBox>
@@ -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<const QString &>::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<const QString &>::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<SummaryWidget *>(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());

View File

@@ -106,23 +106,6 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="customNdkLabel">
<property name="text">
<string>Add custom NDK:</string>
</property>
</widget>
</item>
<item row="1" column="6">
<widget class="QToolButton" name="downloadNDKToolButton">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="1" colspan="4">
<widget class="Utils::PathChooser" name="SDKLocationPathChooser" native="true"/>
</item>
<item row="0" column="5">
<widget class="QToolButton" name="sdkToolsAutoDownloadButton">
<property name="toolTip">
@@ -133,7 +116,27 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="7">
<item row="0" column="6">
<widget class="QToolButton" name="downloadSDKToolButton">
<property name="toolTip">
<string>Download Android SDK</string>
</property>
</widget>
</item>
<item row="2" column="6">
<widget class="QToolButton" name="downloadNDKToolButton">
<property name="toolTip">
<string/>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="1" colspan="4">
<widget class="Utils::PathChooser" name="SDKLocationPathChooser" native="true"/>
</item>
<item row="5" column="0" colspan="7">
<widget class="Utils::DetailsWidget" name="androidDetailsWidget" native="true"/>
</item>
<item row="2" column="0">
@@ -143,63 +146,76 @@
</property>
</widget>
</item>
<item row="0" column="6">
<widget class="QToolButton" name="downloadSDKToolButton">
<property name="toolTip">
<string>Download Android SDK</string>
<item row="2" column="1" rowspan="3">
<widget class="QListWidget" name="ndkListWidget">
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
</widget>
</item>
<item row="1" column="1" colspan="3">
<widget class="Utils::PathChooser" name="customNdkPathChooser" native="true">
<property name="minimumSize">
<size>
<width>20</width>
<height>0</height>
</size>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QPushButton" name="addCustomNdkButton">
<property name="enabled">
<property name="modelColumn">
<number>0</number>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Add the selected custom NDK. The toolchains and debuggers will be created automatically.</string>
</property>
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="3">
<widget class="QComboBox" name="ndkListComboBox"/>
</item>
<item row="2" column="4">
<widget class="QPushButton" name="removeCustomNdkButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Remove the selected custom NDK.</string>
</property>
<property name="text">
<string>Remove</string>
</property>
</widget>
<item row="2" column="2" rowspan="3" colspan="3">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QPushButton" name="addCustomNdkButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Add the selected custom NDK. The toolchains and debuggers will be created automatically.</string>
</property>
<property name="text">
<string>Add...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeCustomNdkButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Remove the selected NDK if it has been added manually.</string>
</property>
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>