2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2014-06-25 15:42:11 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 BogDan Vatra <bog_dan_ro@yahoo.com>
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-06-25 15:42:11 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2014-06-25 15:42:11 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2014-06-25 15:42:11 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "androidbuildapkstep.h"
|
|
|
|
|
#include "androidbuildapkwidget.h"
|
|
|
|
|
#include "androidconfigurations.h"
|
|
|
|
|
#include "androidconstants.h"
|
|
|
|
|
#include "androidmanager.h"
|
2017-08-18 08:22:34 +02:00
|
|
|
#include "androidsdkmanager.h"
|
2014-06-25 15:42:11 +02:00
|
|
|
#include "androidqtsupport.h"
|
|
|
|
|
#include "certificatesmodel.h"
|
|
|
|
|
|
|
|
|
|
#include "javaparser.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/fileutils.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
|
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
|
|
|
|
|
#include <qtsupport/qtkitinformation.h>
|
|
|
|
|
|
2016-04-29 16:52:58 +02:00
|
|
|
#include <utils/synchronousprocess.h>
|
2016-12-22 17:55:17 +01:00
|
|
|
#include <utils/utilsicons.h>
|
2014-06-25 15:42:11 +02:00
|
|
|
|
2016-12-22 17:55:17 +01:00
|
|
|
#include <QDialogButtonBox>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QLineEdit>
|
2014-06-25 15:42:11 +02:00
|
|
|
#include <QMessageBox>
|
2016-04-29 16:52:58 +02:00
|
|
|
#include <QProcess>
|
2016-12-22 17:55:17 +01:00
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
2014-06-25 15:42:11 +02:00
|
|
|
|
|
|
|
|
namespace Android {
|
|
|
|
|
using namespace Internal;
|
|
|
|
|
|
2017-04-12 14:08:17 +02:00
|
|
|
const QVersionNumber gradleScriptRevokedSdkVersion(25, 3, 0);
|
2017-06-12 14:23:06 +02:00
|
|
|
const char KeystoreLocationKey[] = "KeystoreLocation";
|
|
|
|
|
const char BuildTargetSdkKey[] = "BuildTargetSdk";
|
|
|
|
|
const char VerboseOutputKey[] = "VerboseOutput";
|
2017-09-27 18:24:04 -07:00
|
|
|
const char UseMinistroKey[] = "UseMinistro";
|
2016-12-22 17:55:17 +01:00
|
|
|
|
2017-10-23 13:42:07 +02:00
|
|
|
class PasswordInputDialog : public QDialog
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
2016-12-22 17:55:17 +01:00
|
|
|
public:
|
|
|
|
|
enum Context{
|
|
|
|
|
KeystorePassword = 1,
|
|
|
|
|
CertificatePassword
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PasswordInputDialog(Context context, std::function<bool (const QString &)> callback,
|
|
|
|
|
const QString &extraContextStr, QWidget *parent = nullptr);
|
|
|
|
|
|
|
|
|
|
static QString getPassword(Context context, std::function<bool (const QString &)> callback,
|
|
|
|
|
const QString &extraContextStr, bool *ok = nullptr,
|
|
|
|
|
QWidget *parent = nullptr);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::function<bool (const QString &)> verifyCallback = [](const QString &) { return true; };
|
|
|
|
|
QLabel *inputContextlabel = new QLabel(this);
|
|
|
|
|
QLineEdit *inputEdit = new QLineEdit(this);
|
|
|
|
|
QLabel *warningIcon = new QLabel(this);
|
|
|
|
|
QLabel *warningLabel = new QLabel(this);
|
|
|
|
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
|
|
|
|
|
this);
|
|
|
|
|
};
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
AndroidBuildApkStep::AndroidBuildApkStep(ProjectExplorer::BuildStepList *parent, const Core::Id id)
|
|
|
|
|
: ProjectExplorer::AbstractProcessStep(parent, id),
|
2017-08-18 08:22:34 +02:00
|
|
|
m_buildTargetSdk(AndroidConfig::apiLevelNameFor(AndroidConfigurations::
|
|
|
|
|
sdkManager()->latestAndroidSdkPlatform()))
|
2014-06-25 15:42:11 +02:00
|
|
|
{
|
|
|
|
|
//: AndroidBuildApkStep default display name
|
|
|
|
|
setDefaultDisplayName(tr("Build Android APK"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AndroidBuildApkStep::AndroidBuildApkStep(ProjectExplorer::BuildStepList *parent,
|
|
|
|
|
AndroidBuildApkStep *other)
|
|
|
|
|
: ProjectExplorer::AbstractProcessStep(parent, other),
|
|
|
|
|
m_signPackage(other->signPackage()),
|
|
|
|
|
m_verbose(other->m_verbose),
|
2017-09-27 18:24:04 -07:00
|
|
|
m_useMinistro(other->useMinistro()),
|
2014-06-25 15:42:11 +02:00
|
|
|
m_openPackageLocation(other->m_openPackageLocation),
|
2016-12-05 14:02:27 +01:00
|
|
|
// leave m_openPackageLocationForRun at false
|
2014-06-25 15:42:11 +02:00
|
|
|
m_buildTargetSdk(other->m_buildTargetSdk)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-13 12:19:35 +01:00
|
|
|
bool AndroidBuildApkStep::init(QList<const BuildStep *> &earlierSteps)
|
2014-06-25 15:42:11 +02:00
|
|
|
{
|
|
|
|
|
ProjectExplorer::BuildConfiguration *bc = buildConfiguration();
|
|
|
|
|
|
|
|
|
|
if (m_signPackage) {
|
|
|
|
|
// check keystore and certificate passwords
|
2016-12-22 17:55:17 +01:00
|
|
|
if (!verifyKeystorePassword() || !verifyCertificatePassword())
|
|
|
|
|
return false;
|
2014-06-25 15:42:11 +02:00
|
|
|
|
2015-02-20 15:10:56 +01:00
|
|
|
if (bc->buildType() != ProjectExplorer::BuildConfiguration::Release)
|
|
|
|
|
emit addOutput(tr("Warning: Signing a debug or profile package."),
|
2017-01-12 10:59:12 +01:00
|
|
|
OutputFormat::ErrorMessage);
|
2014-06-25 15:42:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(target()->kit());
|
|
|
|
|
if (!version)
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-07-31 13:36:18 +02:00
|
|
|
const QVersionNumber sdkToolsVersion = AndroidConfigurations::currentConfig().sdkToolsVersion();
|
2017-09-08 23:36:13 +02:00
|
|
|
if (sdkToolsVersion >= gradleScriptRevokedSdkVersion) {
|
|
|
|
|
if (!version->sourcePath().appendPath("src/3rdparty/gradle").exists()) {
|
|
|
|
|
emit addOutput(tr("The installed SDK tools version (%1) does not include Gradle "
|
|
|
|
|
"scripts. The minimum Qt version required for Gradle build to work "
|
|
|
|
|
"is %2").arg(sdkToolsVersion.toString()).arg("5.9.0/5.6.3"),
|
|
|
|
|
OutputFormat::Stderr);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else if (version->qtVersion() < QtSupport::QtVersionNumber(5, 4, 0)) {
|
|
|
|
|
emit addOutput(tr("The minimum Qt version required for Gradle build to work is %2. "
|
|
|
|
|
"It is recommended to install the latest Qt version.")
|
|
|
|
|
.arg("5.4.0"), OutputFormat::Stderr);
|
2017-04-12 14:08:17 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-17 18:46:12 +02:00
|
|
|
int minSDKForKit = AndroidManager::minimumSDK(target()->kit());
|
|
|
|
|
if (AndroidManager::minimumSDK(target()) < minSDKForKit) {
|
|
|
|
|
emit addOutput(tr("The API level set for the APK is less than the minimum required by the kit."
|
2017-01-12 10:59:12 +01:00
|
|
|
"\nThe minimum API level required by the kit is %1.").arg(minSDKForKit), OutputFormat::Stderr);
|
2016-08-17 18:46:12 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
JavaParser *parser = new JavaParser;
|
|
|
|
|
parser->setProjectFileList(target()->project()->files(ProjectExplorer::Project::AllFiles));
|
|
|
|
|
parser->setSourceDirectory(androidPackageSourceDir());
|
2017-06-12 14:23:06 +02:00
|
|
|
parser->setBuildDirectory(Utils::FileName::fromString(bc->buildDirectory().appendPath(Constants::ANDROID_BUILDDIRECTORY).toString()));
|
2014-06-25 15:42:11 +02:00
|
|
|
setOutputParser(parser);
|
|
|
|
|
|
|
|
|
|
m_openPackageLocationForRun = m_openPackageLocation;
|
2014-09-22 16:20:51 +03:00
|
|
|
m_apkPath = AndroidManager::androidQtSupport(target())->apkPath(target()).toString();
|
2014-06-25 15:42:11 +02:00
|
|
|
|
2015-11-13 12:19:35 +01:00
|
|
|
bool result = AbstractProcessStep::init(earlierSteps);
|
2014-06-25 15:42:11 +02:00
|
|
|
if (!result)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::showInGraphicalShell()
|
|
|
|
|
{
|
|
|
|
|
Core::FileUtils::showInGraphicalShell(Core::ICore::instance()->mainWindow(), m_apkPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::BuildStepConfigWidget *AndroidBuildApkStep::createConfigWidget()
|
|
|
|
|
{
|
|
|
|
|
return new AndroidBuildApkWidget(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::processFinished(int exitCode, QProcess::ExitStatus status)
|
|
|
|
|
{
|
|
|
|
|
AbstractProcessStep::processFinished(exitCode, status);
|
|
|
|
|
if (m_openPackageLocationForRun && status == QProcess::NormalExit && exitCode == 0)
|
|
|
|
|
QMetaObject::invokeMethod(this, "showInGraphicalShell", Qt::QueuedConnection);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-22 17:55:17 +01:00
|
|
|
bool AndroidBuildApkStep::verifyKeystorePassword()
|
|
|
|
|
{
|
2017-01-10 16:33:56 +01:00
|
|
|
if (!m_keystorePath.exists()) {
|
2017-09-08 14:20:43 +02:00
|
|
|
addOutput(tr("Cannot sign the package. Invalid keystore path (%1).")
|
2017-01-20 10:08:43 +02:00
|
|
|
.arg(m_keystorePath.toString()), OutputFormat::ErrorMessage);
|
2017-01-10 16:33:56 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-22 17:55:17 +01:00
|
|
|
if (AndroidManager::checkKeystorePassword(m_keystorePath.toString(), m_keystorePasswd))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
bool success = false;
|
|
|
|
|
auto verifyCallback = std::bind(&AndroidManager::checkKeystorePassword,
|
|
|
|
|
m_keystorePath.toString(), std::placeholders::_1);
|
|
|
|
|
m_keystorePasswd = PasswordInputDialog::getPassword(PasswordInputDialog::KeystorePassword,
|
|
|
|
|
verifyCallback, "", &success);
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidBuildApkStep::verifyCertificatePassword()
|
|
|
|
|
{
|
2017-01-10 16:33:56 +01:00
|
|
|
if (!AndroidManager::checkCertificateExists(m_keystorePath.toString(), m_keystorePasswd,
|
|
|
|
|
m_certificateAlias)) {
|
|
|
|
|
addOutput(tr("Cannot sign the package. Certificate alias %1 does not exist.")
|
2017-01-20 10:08:43 +02:00
|
|
|
.arg(m_certificateAlias), OutputFormat::ErrorMessage);
|
2017-01-10 16:33:56 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-22 17:55:17 +01:00
|
|
|
if (AndroidManager::checkCertificatePassword(m_keystorePath.toString(), m_keystorePasswd,
|
|
|
|
|
m_certificateAlias, m_certificatePasswd)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool success = false;
|
|
|
|
|
auto verifyCallback = std::bind(&AndroidManager::checkCertificatePassword,
|
|
|
|
|
m_keystorePath.toString(), m_keystorePasswd,
|
|
|
|
|
m_certificateAlias, std::placeholders::_1);
|
|
|
|
|
|
|
|
|
|
m_certificatePasswd = PasswordInputDialog::getPassword(PasswordInputDialog::CertificatePassword,
|
|
|
|
|
verifyCallback, m_certificateAlias,
|
|
|
|
|
&success);
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
bool AndroidBuildApkStep::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
m_keystorePath = Utils::FileName::fromString(map.value(KeystoreLocationKey).toString());
|
|
|
|
|
m_signPackage = false; // don't restore this
|
|
|
|
|
m_buildTargetSdk = map.value(BuildTargetSdkKey).toString();
|
2017-08-18 08:22:34 +02:00
|
|
|
if (m_buildTargetSdk.isEmpty()) {
|
|
|
|
|
m_buildTargetSdk = AndroidConfig::apiLevelNameFor(AndroidConfigurations::
|
|
|
|
|
sdkManager()->latestAndroidSdkPlatform());
|
|
|
|
|
}
|
2014-06-25 15:42:11 +02:00
|
|
|
m_verbose = map.value(VerboseOutputKey).toBool();
|
2017-09-27 18:24:04 -07:00
|
|
|
m_useMinistro = map.value(UseMinistroKey).toBool();
|
2014-06-25 15:42:11 +02:00
|
|
|
return ProjectExplorer::BuildStep::fromMap(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap AndroidBuildApkStep::toMap() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap map = ProjectExplorer::AbstractProcessStep::toMap();
|
|
|
|
|
map.insert(KeystoreLocationKey, m_keystorePath.toString());
|
|
|
|
|
map.insert(BuildTargetSdkKey, m_buildTargetSdk);
|
|
|
|
|
map.insert(VerboseOutputKey, m_verbose);
|
2017-09-27 18:24:04 -07:00
|
|
|
map.insert(UseMinistroKey, m_useMinistro);
|
2014-06-25 15:42:11 +02:00
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utils::FileName AndroidBuildApkStep::keystorePath()
|
|
|
|
|
{
|
|
|
|
|
return m_keystorePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AndroidBuildApkStep::buildTargetSdk() const
|
|
|
|
|
{
|
|
|
|
|
return m_buildTargetSdk;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setBuildTargetSdk(const QString &sdk)
|
|
|
|
|
{
|
|
|
|
|
m_buildTargetSdk = sdk;
|
2017-09-08 23:36:13 +02:00
|
|
|
AndroidManager::updateGradleProperties(target());
|
2014-06-25 15:42:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setKeystorePath(const Utils::FileName &path)
|
|
|
|
|
{
|
|
|
|
|
m_keystorePath = path;
|
|
|
|
|
m_certificatePasswd.clear();
|
|
|
|
|
m_keystorePasswd.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setKeystorePassword(const QString &pwd)
|
|
|
|
|
{
|
|
|
|
|
m_keystorePasswd = pwd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setCertificateAlias(const QString &alias)
|
|
|
|
|
{
|
|
|
|
|
m_certificateAlias = alias;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setCertificatePassword(const QString &pwd)
|
|
|
|
|
{
|
|
|
|
|
m_certificatePasswd = pwd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidBuildApkStep::signPackage() const
|
|
|
|
|
{
|
|
|
|
|
return m_signPackage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setSignPackage(bool b)
|
|
|
|
|
{
|
|
|
|
|
m_signPackage = b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidBuildApkStep::openPackageLocation() const
|
|
|
|
|
{
|
|
|
|
|
return m_openPackageLocation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setOpenPackageLocation(bool open)
|
|
|
|
|
{
|
|
|
|
|
m_openPackageLocation = open;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setVerboseOutput(bool verbose)
|
|
|
|
|
{
|
|
|
|
|
m_verbose = verbose;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 18:24:04 -07:00
|
|
|
bool AndroidBuildApkStep::useMinistro() const
|
|
|
|
|
{
|
|
|
|
|
return m_useMinistro;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setUseMinistro(bool useMinistro)
|
|
|
|
|
{
|
|
|
|
|
m_useMinistro = useMinistro;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-28 14:03:20 +02:00
|
|
|
bool AndroidBuildApkStep::addDebugger() const
|
|
|
|
|
{
|
|
|
|
|
return m_addDebugger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidBuildApkStep::setAddDebugger(bool debug)
|
|
|
|
|
{
|
|
|
|
|
m_addDebugger = debug;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
bool AndroidBuildApkStep::verboseOutput() const
|
|
|
|
|
{
|
|
|
|
|
return m_verbose;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAbstractItemModel *AndroidBuildApkStep::keystoreCertificates()
|
|
|
|
|
{
|
2016-12-22 17:55:17 +01:00
|
|
|
// check keystore passwords
|
|
|
|
|
if (!verifyKeystorePassword())
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
CertificatesModel *model = nullptr;
|
2017-06-12 18:23:05 +02:00
|
|
|
const QStringList params = {"-list", "-v", "-keystore", m_keystorePath.toUserOutput(),
|
|
|
|
|
"-storepass", m_keystorePasswd, "-J-Duser.language=en"};
|
2016-12-22 17:55:17 +01:00
|
|
|
|
|
|
|
|
Utils::SynchronousProcess keytoolProc;
|
|
|
|
|
keytoolProc.setTimeoutS(30);
|
|
|
|
|
const Utils::SynchronousProcessResponse response
|
|
|
|
|
= keytoolProc.run(AndroidConfigurations::currentConfig().keytoolPath().toString(), params);
|
2017-01-11 09:29:37 +01:00
|
|
|
if (response.result > Utils::SynchronousProcessResponse::FinishedError)
|
2016-12-22 17:55:17 +01:00
|
|
|
QMessageBox::critical(0, tr("Error"), tr("Failed to run keytool."));
|
|
|
|
|
else
|
|
|
|
|
model = new CertificatesModel(response.stdOut(), this);
|
|
|
|
|
|
|
|
|
|
return model;
|
2014-06-25 15:42:11 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-22 17:55:17 +01:00
|
|
|
PasswordInputDialog::PasswordInputDialog(PasswordInputDialog::Context context,
|
|
|
|
|
std::function<bool (const QString &)> callback,
|
|
|
|
|
const QString &extraContextStr,
|
|
|
|
|
QWidget *parent) :
|
|
|
|
|
QDialog(parent, Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint),
|
|
|
|
|
verifyCallback(callback)
|
|
|
|
|
|
2014-06-25 15:42:11 +02:00
|
|
|
{
|
2016-12-22 17:55:17 +01:00
|
|
|
inputEdit->setEchoMode(QLineEdit::Password);
|
|
|
|
|
|
|
|
|
|
warningIcon->setPixmap(Utils::Icons::WARNING.pixmap());
|
|
|
|
|
warningIcon->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum));
|
|
|
|
|
warningIcon->hide();
|
|
|
|
|
|
|
|
|
|
warningLabel->hide();
|
|
|
|
|
|
|
|
|
|
auto warningLayout = new QHBoxLayout;
|
|
|
|
|
warningLayout->addWidget(warningIcon);
|
|
|
|
|
warningLayout->addWidget(warningLabel);
|
|
|
|
|
|
|
|
|
|
auto mainLayout = new QVBoxLayout(this);
|
|
|
|
|
mainLayout->addWidget(inputContextlabel);
|
|
|
|
|
mainLayout->addWidget(inputEdit);
|
|
|
|
|
mainLayout->addLayout(warningLayout);
|
|
|
|
|
mainLayout->addWidget(buttonBox);
|
|
|
|
|
|
|
|
|
|
connect(inputEdit, &QLineEdit::textChanged,[this](const QString &text) {
|
|
|
|
|
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(buttonBox, &QDialogButtonBox::accepted, [this]() {
|
|
|
|
|
if (verifyCallback(inputEdit->text())) {
|
|
|
|
|
accept(); // Dialog accepted.
|
|
|
|
|
} else {
|
|
|
|
|
warningIcon->show();
|
|
|
|
|
warningLabel->show();
|
|
|
|
|
warningLabel->setText(tr("Incorrect password."));
|
|
|
|
|
inputEdit->clear();
|
|
|
|
|
adjustSize();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
|
|
|
|
|
|
|
|
|
setWindowTitle(context == KeystorePassword ? tr("Keystore") : tr("Certificate"));
|
|
|
|
|
|
|
|
|
|
QString contextStr;
|
|
|
|
|
if (context == KeystorePassword)
|
|
|
|
|
contextStr = tr("Enter keystore password");
|
|
|
|
|
else
|
|
|
|
|
contextStr = tr("Enter certificate password");
|
|
|
|
|
|
|
|
|
|
contextStr += extraContextStr.isEmpty() ? QStringLiteral(":") :
|
|
|
|
|
QStringLiteral(" (%1):").arg(extraContextStr);
|
|
|
|
|
inputContextlabel->setText(contextStr);
|
2014-06-25 15:42:11 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-22 17:55:17 +01:00
|
|
|
QString PasswordInputDialog::getPassword(Context context, std::function<bool (const QString &)> callback,
|
|
|
|
|
const QString &extraContextStr, bool *ok, QWidget *parent)
|
2014-06-25 15:42:11 +02:00
|
|
|
{
|
2016-12-22 17:55:17 +01:00
|
|
|
std::unique_ptr<PasswordInputDialog> dlg(new PasswordInputDialog(context, callback,
|
|
|
|
|
extraContextStr, parent));
|
|
|
|
|
bool isAccepted = dlg->exec() == QDialog::Accepted;
|
|
|
|
|
if (ok)
|
|
|
|
|
*ok = isAccepted;
|
|
|
|
|
return isAccepted ? dlg->inputEdit->text() : "";
|
2014-06-25 15:42:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Android
|
2017-10-23 13:42:07 +02:00
|
|
|
|
|
|
|
|
#include "androidbuildapkstep.moc"
|