androidbuildapkwidget.cpp 8.61 KB
Newer Older
1
/****************************************************************************
2
**
3
4
5
** Copyright (C) 2016 BogDan Vatra <bog_dan_ro@yahoo.com>
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
6
7
8
9
10
11
12
**
** 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
13
14
15
** 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.
16
**
17
18
19
20
21
22
23
** 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.
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
**
****************************************************************************/

#include "androidbuildapkstep.h"
#include "androidbuildapkwidget.h"
#include "androidconfigurations.h"
#include "androidcreatekeystorecertificate.h"
#include "androidmanager.h"
#include "ui_androidbuildapkwidget.h"

#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/project.h>
#include <projectexplorer/target.h>
#include <qtsupport/qtkitinformation.h>

#include <utils/fancylineedit.h>
#include <utils/pathchooser.h>
Ulf Hermann's avatar
Ulf Hermann committed
41
#include <utils/utilsicons.h>
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

#include <QFileDialog>

#include <algorithm>

using namespace Android;
using namespace Internal;

AndroidBuildApkWidget::AndroidBuildApkWidget(AndroidBuildApkStep *step)
    : ProjectExplorer::BuildStepConfigWidget(),
      m_ui(new Ui::AndroidBuildApkWidget),
      m_step(step)
{
    m_ui->setupUi(this);

    // Target sdk combobox
    int minApiLevel = 9;
59
60
    const AndroidConfig &config = AndroidConfigurations::currentConfig();
    QStringList targets = AndroidConfig::apiLevelNamesFor(config.sdkTargets(minApiLevel));
Daniel Teske's avatar
Daniel Teske committed
61
    targets.removeDuplicates();
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
    m_ui->targetSDKComboBox->addItems(targets);
    m_ui->targetSDKComboBox->setCurrentIndex(targets.indexOf(AndroidManager::buildTargetSDK(step->target())));

    // deployment option
    switch (m_step->deployAction()) {
    case AndroidBuildApkStep::MinistroDeployment:
        m_ui->ministroOption->setChecked(true);
        break;
    case AndroidBuildApkStep::BundleLibrariesDeployment:
        m_ui->bundleQtOption->setChecked(true);
        break;
    default:
        // can't happen
        break;
    }

    // signing
    m_ui->signPackageCheckBox->setChecked(m_step->signPackage());
    m_ui->KeystoreLocationPathChooser->setExpectedKind(Utils::PathChooser::File);
    m_ui->KeystoreLocationPathChooser->lineEdit()->setReadOnly(true);
    m_ui->KeystoreLocationPathChooser->setPath(m_step->keystorePath().toUserOutput());
    m_ui->KeystoreLocationPathChooser->setInitialBrowsePathBackup(QDir::homePath());
    m_ui->KeystoreLocationPathChooser->setPromptDialogFilter(tr("Keystore files (*.keystore *.jks)"));
    m_ui->KeystoreLocationPathChooser->setPromptDialogTitle(tr("Select Keystore File"));
Ulf Hermann's avatar
Ulf Hermann committed
86
    m_ui->signingDebugWarningIcon->setPixmap(Utils::Icons::WARNING.pixmap());
87
88
89
90
91
92
    m_ui->signingDebugWarningIcon->hide();
    m_ui->signingDebugWarningLabel->hide();
    signPackageCheckBoxToggled(m_step->signPackage());

    m_ui->verboseOutputCheckBox->setChecked(m_step->verboseOutput());
    m_ui->openPackageLocationCheckBox->setChecked(m_step->openPackageLocation());
BogDan Vatra's avatar
BogDan Vatra committed
93
    m_ui->addDebuggerCheckBox->setChecked(m_step->addDebugger());
94
95

    // target sdk
Orgad Shaneh's avatar
Orgad Shaneh committed
96
97
98
    connect(m_ui->targetSDKComboBox,
            static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
            this, &AndroidBuildApkWidget::setTargetSdk);
99
100

    // deployment options
Orgad Shaneh's avatar
Orgad Shaneh committed
101
102
103
104
105
106
107
108
109
    connect(m_ui->ministroOption, &QAbstractButton::clicked,
            this, &AndroidBuildApkWidget::setMinistro);
    connect(m_ui->bundleQtOption, &QAbstractButton::clicked,
            this, &AndroidBuildApkWidget::setBundleQtLibs);

    connect(m_ui->openPackageLocationCheckBox, &QAbstractButton::toggled,
            this, &AndroidBuildApkWidget::openPackageLocationCheckBoxToggled);
    connect(m_ui->verboseOutputCheckBox, &QAbstractButton::toggled,
            this, &AndroidBuildApkWidget::verboseOutputCheckBoxToggled);
BogDan Vatra's avatar
BogDan Vatra committed
110
111
    connect(m_ui->addDebuggerCheckBox, &QAbstractButton::toggled,
            m_step, &AndroidBuildApkStep::setAddDebugger);
112
113

    //signing
Orgad Shaneh's avatar
Orgad Shaneh committed
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    connect(m_ui->signPackageCheckBox, &QAbstractButton::toggled,
            this, &AndroidBuildApkWidget::signPackageCheckBoxToggled);
    connect(m_ui->KeystoreCreatePushButton, &QAbstractButton::clicked,
            this, &AndroidBuildApkWidget::createKeyStore);
    connect(m_ui->KeystoreLocationPathChooser, &Utils::PathChooser::pathChanged,
            this, &AndroidBuildApkWidget::updateKeyStorePath);
    connect(m_ui->certificatesAliasComboBox,
            static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
            this, &AndroidBuildApkWidget::certificatesAliasComboBoxActivated);
    connect(m_ui->certificatesAliasComboBox,
            static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
            this, &AndroidBuildApkWidget::certificatesAliasComboBoxCurrentIndexChanged);

    connect(m_step->buildConfiguration(), &ProjectExplorer::BuildConfiguration::buildTypeChanged,
            this, &AndroidBuildApkWidget::updateSigningWarning);
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166

    updateSigningWarning();
}

AndroidBuildApkWidget::~AndroidBuildApkWidget()
{
    delete m_ui;
}

QString AndroidBuildApkWidget::displayName() const
{
    return tr("<b>Build Android APK</b>");
}

QString AndroidBuildApkWidget::summaryText() const
{
    return displayName();
}

void AndroidBuildApkWidget::setTargetSdk(const QString &sdk)
{
    m_step->setBuildTargetSdk(sdk);
}

void AndroidBuildApkWidget::setMinistro()
{
    m_step->setDeployAction(AndroidBuildApkStep::MinistroDeployment);
}

void AndroidBuildApkWidget::setBundleQtLibs()
{
    m_step->setDeployAction(AndroidBuildApkStep::BundleLibrariesDeployment);
}

void AndroidBuildApkWidget::signPackageCheckBoxToggled(bool checked)
{
    m_ui->certificatesAliasComboBox->setEnabled(checked);
    m_step->setSignPackage(checked);
BogDan Vatra's avatar
BogDan Vatra committed
167
    m_ui->addDebuggerCheckBox->setChecked(!checked);
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
    updateSigningWarning();
    if (!checked)
        return;
    if (!m_step->keystorePath().isEmpty())
        setCertificates();
}

void AndroidBuildApkWidget::createKeyStore()
{
    AndroidCreateKeystoreCertificate d;
    if (d.exec() != QDialog::Accepted)
        return;
    m_ui->KeystoreLocationPathChooser->setPath(d.keystoreFilePath().toUserOutput());
    m_step->setKeystorePath(d.keystoreFilePath());
    m_step->setKeystorePassword(d.keystorePassword());
    m_step->setCertificateAlias(d.certificateAlias());
    m_step->setCertificatePassword(d.certificatePassword());
    setCertificates();
}

void AndroidBuildApkWidget::setCertificates()
{
    QAbstractItemModel *certificates = m_step->keystoreCertificates();
191
192
193
194
    if (certificates) {
        m_ui->signPackageCheckBox->setChecked(certificates);
        m_ui->certificatesAliasComboBox->setModel(certificates);
    }
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
}

void AndroidBuildApkWidget::updateKeyStorePath(const QString &path)
{
    Utils::FileName file = Utils::FileName::fromString(path);
    m_step->setKeystorePath(file);
    m_ui->signPackageCheckBox->setChecked(!file.isEmpty());
    if (!file.isEmpty())
        setCertificates();
}

void AndroidBuildApkWidget::certificatesAliasComboBoxActivated(const QString &alias)
{
    if (alias.length())
        m_step->setCertificateAlias(alias);
}

void AndroidBuildApkWidget::certificatesAliasComboBoxCurrentIndexChanged(const QString &alias)
{
    if (alias.length())
        m_step->setCertificateAlias(alias);
}

void AndroidBuildApkWidget::openPackageLocationCheckBoxToggled(bool checked)
{
    m_step->setOpenPackageLocation(checked);
}

void AndroidBuildApkWidget::verboseOutputCheckBoxToggled(bool checked)
{
    m_step->setVerboseOutput(checked);
}

void AndroidBuildApkWidget::updateSigningWarning()
{
Ulf Hermann's avatar
Ulf Hermann committed
230
231
232
    bool nonRelease = m_step->buildConfiguration()->buildType()
            != ProjectExplorer::BuildConfiguration::Release;
    if (m_step->signPackage() && nonRelease) {
233
234
235
236
237
238
239
        m_ui->signingDebugWarningIcon->setVisible(true);
        m_ui->signingDebugWarningLabel->setVisible(true);
    } else {
        m_ui->signingDebugWarningIcon->setVisible(false);
        m_ui->signingDebugWarningLabel->setVisible(false);
    }
}