forked from qt-creator/qt-creator
Android: move non UI functions from settingsWidget class
Change-Id: I2d6c6806fc8b219b65d241a0243ee1edab5125a1 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -73,6 +73,7 @@
|
||||
#include <QProcess>
|
||||
#include <QRegularExpression>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
#include <QStringList>
|
||||
#include <QTcpSocket>
|
||||
#include <QThread>
|
||||
@@ -964,6 +965,27 @@ QStringList AndroidConfig::allEssentials() const
|
||||
return allPackages;
|
||||
}
|
||||
|
||||
bool AndroidConfig::allEssentialsInstalled()
|
||||
{
|
||||
QStringList essentialPkgs(allEssentials());
|
||||
for (const AndroidSdkPackage *pkg :
|
||||
AndroidConfigurations::sdkManager()->installedSdkPackages()) {
|
||||
if (essentialPkgs.contains(pkg->sdkStylePath()))
|
||||
essentialPkgs.removeOne(pkg->sdkStylePath());
|
||||
if (essentialPkgs.isEmpty())
|
||||
break;
|
||||
}
|
||||
return essentialPkgs.isEmpty() ? true : false;
|
||||
}
|
||||
|
||||
bool AndroidConfig::sdkToolsOk() const
|
||||
{
|
||||
bool exists = sdkLocation().exists();
|
||||
bool writable = sdkLocation().isWritablePath();
|
||||
bool sdkToolsExist = !sdkToolsVersion().isNull();
|
||||
return exists && writable && sdkToolsExist;
|
||||
}
|
||||
|
||||
QStringList AndroidConfig::essentialsFromQtVersion(const BaseQtVersion &version) const
|
||||
{
|
||||
QtVersionNumber qtVersion = version.qtVersion();
|
||||
@@ -1070,6 +1092,28 @@ void AndroidConfig::setAutomaticKitCreation(bool b)
|
||||
m_automaticKitCreation = b;
|
||||
}
|
||||
|
||||
FilePath AndroidConfig::defaultSdkPath()
|
||||
{
|
||||
QString sdkFromEnvVar = QString::fromLocal8Bit(getenv("ANDROID_SDK_ROOT"));
|
||||
if (!sdkFromEnvVar.isEmpty())
|
||||
return Utils::FilePath::fromString(sdkFromEnvVar);
|
||||
|
||||
// Set default path of SDK as used by Android Studio
|
||||
if (Utils::HostOsInfo::isMacHost()) {
|
||||
return Utils::FilePath::fromString(
|
||||
QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
|
||||
+ "/../Android/sdk");
|
||||
}
|
||||
|
||||
if (Utils::HostOsInfo::isWindowsHost()) {
|
||||
return Utils::FilePath::fromString(
|
||||
QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/Android/sdk");
|
||||
}
|
||||
|
||||
return Utils::FilePath::fromString(
|
||||
QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/Android/Sdk");
|
||||
}
|
||||
|
||||
///////////////////////////////////
|
||||
// AndroidConfigurations
|
||||
///////////////////////////////////
|
||||
|
@@ -134,6 +134,8 @@ public:
|
||||
QStringList defaultEssentials() const;
|
||||
QStringList essentialsFromQtVersion(const QtSupport::BaseQtVersion &version) const;
|
||||
QStringList allEssentials() const;
|
||||
bool allEssentialsInstalled();
|
||||
bool sdkToolsOk() const;
|
||||
|
||||
Utils::FilePath openJDKLocation() const;
|
||||
void setOpenJDKLocation(const Utils::FilePath &openJDKLocation);
|
||||
@@ -150,6 +152,7 @@ public:
|
||||
bool automaticKitCreation() const;
|
||||
void setAutomaticKitCreation(bool b);
|
||||
|
||||
static Utils::FilePath defaultSdkPath();
|
||||
Utils::FilePath adbToolPath() const;
|
||||
Utils::FilePath androidToolPath() const;
|
||||
Utils::FilePath emulatorToolPath() const;
|
||||
|
@@ -102,6 +102,8 @@ public:
|
||||
private:
|
||||
void apply() final { AndroidConfigurations::setConfig(m_androidConfig); }
|
||||
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
void validateJdk();
|
||||
void validateNdk();
|
||||
void updateNdkList();
|
||||
@@ -127,10 +129,6 @@ private:
|
||||
void disableAvdControls();
|
||||
|
||||
void downloadSdk();
|
||||
bool allEssentialsInstalled();
|
||||
bool sdkToolsOk() const;
|
||||
FilePath getDefaultSdkPath() const;
|
||||
void showEvent(QShowEvent *event) final;
|
||||
void addCustomNdkItem();
|
||||
void validateOpenSsl();
|
||||
|
||||
@@ -293,28 +291,6 @@ AvdModel::AvdModel()
|
||||
setHeader({tr("AVD Name"), tr("API"), tr("CPU/ABI"), tr("Device type"), tr("Target"), tr("SD-card size")});
|
||||
}
|
||||
|
||||
FilePath AndroidSettingsWidget::getDefaultSdkPath() const
|
||||
{
|
||||
QString sdkFromEnvVar = QString::fromLocal8Bit(getenv("ANDROID_SDK_ROOT"));
|
||||
if (!sdkFromEnvVar.isEmpty())
|
||||
return FilePath::fromString(sdkFromEnvVar);
|
||||
|
||||
// Set default path of SDK as used by Android Studio
|
||||
if (HostOsInfo::isMacHost()) {
|
||||
return FilePath::fromString(
|
||||
QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
|
||||
+ "/../Android/sdk");
|
||||
}
|
||||
|
||||
if (HostOsInfo::isWindowsHost()) {
|
||||
return FilePath::fromString(
|
||||
QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/Android/sdk");
|
||||
}
|
||||
|
||||
return FilePath::fromString(
|
||||
QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/Android/Sdk");
|
||||
}
|
||||
|
||||
void AndroidSettingsWidget::showEvent(QShowEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
@@ -437,7 +413,7 @@ AndroidSettingsWidget::AndroidSettingsWidget()
|
||||
|
||||
FilePath currentSDKPath = m_androidConfig.sdkLocation();
|
||||
if (currentSDKPath.isEmpty())
|
||||
currentSDKPath = getDefaultSdkPath();
|
||||
currentSDKPath = AndroidConfig::defaultSdkPath();
|
||||
|
||||
m_ui.SDKLocationPathChooser->setFilePath(currentSDKPath);
|
||||
m_ui.SDKLocationPathChooser->setPromptDialogTitle(tr("Select Android SDK folder"));
|
||||
@@ -651,9 +627,7 @@ void AndroidSettingsWidget::validateSdk()
|
||||
// after AndroidSdkManager::packageReloadFinished.
|
||||
m_androidSummary->setPointValid(PlatformSdkInstalledRow,
|
||||
!m_sdkManager.installedSdkPlatforms().isEmpty());
|
||||
|
||||
m_androidSummary->setPointValid(AllEssentialsInstalledRow, allEssentialsInstalled());
|
||||
|
||||
m_androidSummary->setPointValid(AllEssentialsInstalledRow, m_androidConfig.allEssentialsInstalled());
|
||||
updateUI();
|
||||
|
||||
const bool sdkToolsOk = m_androidSummary->rowsOk({SdkPathExistsRow,
|
||||
@@ -868,7 +842,7 @@ void AndroidSettingsWidget::updateUI()
|
||||
|
||||
void AndroidSettingsWidget::downloadSdk()
|
||||
{
|
||||
if (sdkToolsOk()) {
|
||||
if (m_androidConfig.sdkToolsOk()) {
|
||||
QMessageBox::warning(this, AndroidSdkDownloader::dialogTitle(),
|
||||
tr("The selected path already has a valid SDK Tools package."));
|
||||
validateSdk();
|
||||
@@ -888,25 +862,6 @@ void AndroidSettingsWidget::downloadSdk()
|
||||
}
|
||||
}
|
||||
|
||||
bool AndroidSettingsWidget::allEssentialsInstalled()
|
||||
{
|
||||
QStringList essentialPkgs = m_androidConfig.allEssentials();
|
||||
for (const AndroidSdkPackage *pkg : m_sdkManager.installedSdkPackages()) {
|
||||
essentialPkgs.removeOne(pkg->sdkStylePath());
|
||||
if (essentialPkgs.isEmpty())
|
||||
break;
|
||||
}
|
||||
return essentialPkgs.isEmpty() ? true : false;
|
||||
}
|
||||
|
||||
bool AndroidSettingsWidget::sdkToolsOk() const
|
||||
{
|
||||
bool exists = m_androidConfig.sdkLocation().exists();
|
||||
bool writable = m_androidConfig.sdkLocation().isWritablePath();
|
||||
bool sdkToolsExist = !m_androidConfig.sdkToolsVersion().isNull();
|
||||
return exists && writable && sdkToolsExist;
|
||||
}
|
||||
|
||||
// AndroidSettingsPage
|
||||
|
||||
AndroidSettingsPage::AndroidSettingsPage()
|
||||
|
Reference in New Issue
Block a user