2013-09-26 18:38:44 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-09-26 18:38:44 +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.
|
2013-09-26 18:38:44 +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.
|
2013-09-26 18:38:44 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "createandroidmanifestwizard.h"
|
|
|
|
|
|
2014-09-22 16:20:51 +03:00
|
|
|
#include <android/androidconfigurations.h>
|
2018-12-05 10:29:48 +01:00
|
|
|
#include <android/androidconstants.h>
|
2014-06-25 15:42:11 +02:00
|
|
|
#include <android/androidmanager.h>
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
|
2020-02-13 14:03:37 +01:00
|
|
|
#include <projectexplorer/buildsystem.h>
|
2018-12-05 10:29:48 +01:00
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
#include <projectexplorer/projectnodes.h>
|
2018-05-04 11:13:43 +02:00
|
|
|
#include <projectexplorer/runconfiguration.h>
|
2013-09-26 18:38:44 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2014-06-25 15:42:11 +02:00
|
|
|
|
|
|
|
|
#include <qtsupport/qtkitinformation.h>
|
|
|
|
|
|
2020-01-08 22:47:06 +01:00
|
|
|
#include <utils/infolabel.h>
|
2020-02-13 14:15:54 +01:00
|
|
|
#include <utils/pathchooser.h>
|
2016-08-03 17:55:54 +02:00
|
|
|
|
2014-09-22 16:20:51 +03:00
|
|
|
#include <QCheckBox>
|
2013-09-26 18:38:44 +02:00
|
|
|
#include <QComboBox>
|
2018-07-02 18:12:25 +02:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
2013-09-26 18:38:44 +02:00
|
|
|
#include <QFormLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
2018-07-02 18:12:25 +02:00
|
|
|
using namespace ProjectExplorer;
|
2014-09-22 16:20:51 +03:00
|
|
|
using namespace Utils;
|
2014-06-25 15:42:11 +02:00
|
|
|
|
2018-07-02 18:40:29 +02:00
|
|
|
namespace Android {
|
2020-02-13 14:15:54 +01:00
|
|
|
namespace Internal {
|
2018-07-02 18:40:29 +02:00
|
|
|
|
2013-09-26 18:38:44 +02:00
|
|
|
//
|
|
|
|
|
// NoApplicationProFilePage
|
|
|
|
|
//
|
2020-02-13 14:15:54 +01:00
|
|
|
|
|
|
|
|
class NoApplicationProFilePage : public QWizardPage
|
|
|
|
|
{
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(Android::NoApplicationProFilePage)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
NoApplicationProFilePage(CreateAndroidManifestWizard *wizard);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
NoApplicationProFilePage::NoApplicationProFilePage(CreateAndroidManifestWizard *)
|
2013-09-26 18:38:44 +02:00
|
|
|
{
|
2018-07-25 12:19:15 +02:00
|
|
|
auto layout = new QVBoxLayout(this);
|
2020-02-13 14:15:54 +01:00
|
|
|
auto label = new QLabel(this);
|
2013-09-26 18:38:44 +02:00
|
|
|
label->setWordWrap(true);
|
|
|
|
|
label->setText(tr("No application .pro file found in this project."));
|
|
|
|
|
layout->addWidget(label);
|
|
|
|
|
setTitle(tr("No Application .pro File"));
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-13 14:15:54 +01:00
|
|
|
|
2013-09-26 18:38:44 +02:00
|
|
|
//
|
|
|
|
|
// ChooseProFilePage
|
|
|
|
|
//
|
2020-02-13 14:15:54 +01:00
|
|
|
|
|
|
|
|
class ChooseProFilePage : public QWizardPage
|
|
|
|
|
{
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(Android::ChooseProfilePage)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit ChooseProFilePage(CreateAndroidManifestWizard *wizard);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void nodeSelected(int index);
|
|
|
|
|
|
|
|
|
|
CreateAndroidManifestWizard *m_wizard;
|
|
|
|
|
QComboBox *m_comboBox;
|
|
|
|
|
};
|
|
|
|
|
|
2018-07-02 18:12:25 +02:00
|
|
|
ChooseProFilePage::ChooseProFilePage(CreateAndroidManifestWizard *wizard)
|
|
|
|
|
: m_wizard(wizard)
|
2013-09-26 18:38:44 +02:00
|
|
|
{
|
2018-07-25 12:19:15 +02:00
|
|
|
auto fl = new QFormLayout(this);
|
2013-09-26 18:38:44 +02:00
|
|
|
QLabel *label = new QLabel(this);
|
|
|
|
|
label->setWordWrap(true);
|
2014-09-22 16:20:51 +03:00
|
|
|
label->setText(tr("Select the .pro file for which you want to create the Android template files."));
|
2013-09-26 18:38:44 +02:00
|
|
|
fl->addRow(label);
|
|
|
|
|
|
2020-02-13 14:03:37 +01:00
|
|
|
BuildSystem *buildSystem = wizard->buildSystem();
|
2018-07-02 18:12:25 +02:00
|
|
|
QString currentBuildTarget;
|
2020-02-13 14:03:37 +01:00
|
|
|
if (RunConfiguration *rc = buildSystem->target()->activeRunConfiguration())
|
2018-07-02 18:12:25 +02:00
|
|
|
currentBuildTarget = rc->buildKey();
|
|
|
|
|
|
2013-09-26 18:38:44 +02:00
|
|
|
m_comboBox = new QComboBox(this);
|
2020-02-13 14:03:37 +01:00
|
|
|
for (const BuildTargetInfo &bti : buildSystem->applicationTargets()) {
|
2018-07-02 18:12:25 +02:00
|
|
|
const QString displayName = bti.buildKey;
|
|
|
|
|
m_comboBox->addItem(displayName, QVariant(bti.buildKey)); // TODO something more?
|
|
|
|
|
if (bti.buildKey == currentBuildTarget)
|
2015-01-16 13:22:47 +01:00
|
|
|
m_comboBox->setCurrentIndex(m_comboBox->count() - 1);
|
|
|
|
|
}
|
2013-09-26 18:38:44 +02:00
|
|
|
|
2015-01-16 13:22:47 +01:00
|
|
|
nodeSelected(m_comboBox->currentIndex());
|
2019-02-26 09:40:49 +01:00
|
|
|
connect(m_comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
2016-06-26 22:52:59 +03:00
|
|
|
this, &ChooseProFilePage::nodeSelected);
|
2013-09-26 18:38:44 +02:00
|
|
|
|
|
|
|
|
fl->addRow(tr(".pro file:"), m_comboBox);
|
|
|
|
|
setTitle(tr("Select a .pro File"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ChooseProFilePage::nodeSelected(int index)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(index)
|
2018-07-02 18:12:25 +02:00
|
|
|
m_wizard->setBuildKey(m_comboBox->itemData(m_comboBox->currentIndex()).toString());
|
2013-09-26 18:38:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// ChooseDirectoryPage
|
|
|
|
|
//
|
2020-02-13 14:15:54 +01:00
|
|
|
|
|
|
|
|
class ChooseDirectoryPage : public QWizardPage
|
|
|
|
|
{
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(Android::ChooseDirectoryPage)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
ChooseDirectoryPage(CreateAndroidManifestWizard *wizard);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void initializePage();
|
|
|
|
|
bool isComplete() const;
|
|
|
|
|
void checkPackageSourceDir();
|
|
|
|
|
|
|
|
|
|
CreateAndroidManifestWizard *m_wizard;
|
|
|
|
|
PathChooser *m_androidPackageSourceDir = nullptr;
|
|
|
|
|
InfoLabel *m_sourceDirectoryWarning = nullptr;
|
|
|
|
|
QLabel *m_label;
|
|
|
|
|
QFormLayout *m_layout;
|
|
|
|
|
bool m_complete = true;
|
|
|
|
|
};
|
|
|
|
|
|
2013-09-26 18:38:44 +02:00
|
|
|
ChooseDirectoryPage::ChooseDirectoryPage(CreateAndroidManifestWizard *wizard)
|
2020-02-13 14:15:54 +01:00
|
|
|
: m_wizard(wizard)
|
2013-09-26 18:38:44 +02:00
|
|
|
{
|
2015-01-16 13:22:47 +01:00
|
|
|
m_layout = new QFormLayout(this);
|
|
|
|
|
m_label = new QLabel(this);
|
|
|
|
|
m_label->setWordWrap(true);
|
|
|
|
|
m_layout->addRow(m_label);
|
2013-09-26 18:38:44 +02:00
|
|
|
|
2015-01-16 13:22:47 +01:00
|
|
|
m_androidPackageSourceDir = new PathChooser(this);
|
|
|
|
|
m_androidPackageSourceDir->setExpectedKind(PathChooser::Directory);
|
|
|
|
|
m_layout->addRow(tr("Android package source directory:"), m_androidPackageSourceDir);
|
2013-09-26 18:38:44 +02:00
|
|
|
|
2020-01-08 22:47:06 +01:00
|
|
|
m_sourceDirectoryWarning =
|
2020-02-13 14:15:54 +01:00
|
|
|
new InfoLabel(tr("The Android package source directory cannot be the same as "
|
|
|
|
|
"the project directory."), InfoLabel::Error, this);
|
2014-03-12 15:20:39 +01:00
|
|
|
m_sourceDirectoryWarning->setVisible(false);
|
2020-01-08 22:47:06 +01:00
|
|
|
m_sourceDirectoryWarning->setElideMode(Qt::ElideNone);
|
2014-03-12 15:20:39 +01:00
|
|
|
m_sourceDirectoryWarning->setWordWrap(true);
|
2020-01-08 22:47:06 +01:00
|
|
|
m_layout->addRow(m_sourceDirectoryWarning);
|
2013-09-26 18:38:44 +02:00
|
|
|
|
2016-06-26 22:52:59 +03:00
|
|
|
connect(m_androidPackageSourceDir, &PathChooser::pathChanged,
|
|
|
|
|
m_wizard, &CreateAndroidManifestWizard::setDirectory);
|
2014-09-22 16:20:51 +03:00
|
|
|
|
|
|
|
|
if (wizard->copyGradle()) {
|
2018-07-25 12:19:15 +02:00
|
|
|
auto checkBox = new QCheckBox(this);
|
2014-09-22 16:20:51 +03:00
|
|
|
checkBox->setChecked(true);
|
|
|
|
|
connect(checkBox, &QCheckBox::toggled, wizard, &CreateAndroidManifestWizard::setCopyGradle);
|
|
|
|
|
checkBox->setText(tr("Copy the Gradle files to Android directory"));
|
2015-01-05 14:21:59 +01:00
|
|
|
checkBox->setToolTip(tr("It is highly recommended if you are planning to extend the Java part of your Qt application."));
|
2015-01-16 13:22:47 +01:00
|
|
|
m_layout->addRow(checkBox);
|
2014-09-22 16:20:51 +03:00
|
|
|
}
|
2013-09-26 18:38:44 +02:00
|
|
|
}
|
|
|
|
|
|
2014-03-12 15:20:39 +01:00
|
|
|
void ChooseDirectoryPage::checkPackageSourceDir()
|
|
|
|
|
{
|
2018-07-02 18:12:25 +02:00
|
|
|
const QString buildKey = m_wizard->buildKey();
|
2020-02-13 14:03:37 +01:00
|
|
|
const BuildTargetInfo bti = m_wizard->buildSystem()->buildTarget(buildKey);
|
2018-07-02 18:12:25 +02:00
|
|
|
const QString projectDir = bti.projectFilePath.toFileInfo().absolutePath();
|
|
|
|
|
|
|
|
|
|
const QString newDir = m_androidPackageSourceDir->path();
|
2014-03-12 15:20:39 +01:00
|
|
|
bool isComplete = QFileInfo(projectDir) != QFileInfo(newDir);
|
|
|
|
|
|
|
|
|
|
m_sourceDirectoryWarning->setVisible(!isComplete);
|
|
|
|
|
|
|
|
|
|
if (isComplete != m_complete) {
|
|
|
|
|
m_complete = isComplete;
|
|
|
|
|
emit completeChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ChooseDirectoryPage::isComplete() const
|
|
|
|
|
{
|
|
|
|
|
return m_complete;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-16 13:22:47 +01:00
|
|
|
void ChooseDirectoryPage::initializePage()
|
|
|
|
|
{
|
2020-02-13 14:03:37 +01:00
|
|
|
const Target *target = m_wizard->buildSystem()->target();
|
2018-07-02 18:12:25 +02:00
|
|
|
const QString buildKey = m_wizard->buildKey();
|
2019-02-18 18:24:10 +01:00
|
|
|
const BuildTargetInfo bti = target->buildTarget(buildKey);
|
2018-07-02 18:12:25 +02:00
|
|
|
const QString projectDir = bti.projectFilePath.toFileInfo().absolutePath();
|
|
|
|
|
|
2018-12-05 10:29:48 +01:00
|
|
|
QString androidPackageDir;
|
|
|
|
|
if (const ProjectNode *node = target->project()->findNodeForBuildKey(buildKey))
|
2018-12-18 17:52:19 +01:00
|
|
|
androidPackageDir = node->data(Android::Constants::AndroidPackageSourceDir).toString();
|
2018-07-02 18:12:25 +02:00
|
|
|
|
2015-01-16 13:22:47 +01:00
|
|
|
if (androidPackageDir.isEmpty()) {
|
|
|
|
|
m_label->setText(tr("Select the Android package source directory.\n\n"
|
|
|
|
|
"The files in the Android package source directory are copied to the build directory's "
|
|
|
|
|
"Android directory and the default files are overwritten."));
|
|
|
|
|
|
2018-07-02 18:12:25 +02:00
|
|
|
m_androidPackageSourceDir->setPath(projectDir + "/android");
|
2016-06-26 22:52:59 +03:00
|
|
|
connect(m_androidPackageSourceDir, &PathChooser::rawPathChanged,
|
|
|
|
|
this, &ChooseDirectoryPage::checkPackageSourceDir);
|
2015-01-16 13:22:47 +01:00
|
|
|
} else {
|
|
|
|
|
m_label->setText(tr("The Android template files will be created in the ANDROID_PACKAGE_SOURCE_DIR set in the .pro file."));
|
|
|
|
|
m_androidPackageSourceDir->setPath(androidPackageDir);
|
|
|
|
|
m_androidPackageSourceDir->setReadOnly(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_wizard->setDirectory(m_androidPackageSourceDir->path());
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-26 18:38:44 +02:00
|
|
|
//
|
|
|
|
|
// CreateAndroidManifestWizard
|
|
|
|
|
//
|
2020-02-13 14:03:37 +01:00
|
|
|
CreateAndroidManifestWizard::CreateAndroidManifestWizard(BuildSystem *buildSystem)
|
|
|
|
|
: m_buildSystem(buildSystem), m_copyState(Ask)
|
2013-09-26 18:38:44 +02:00
|
|
|
{
|
2014-09-22 16:20:51 +03:00
|
|
|
setWindowTitle(tr("Create Android Template Files Wizard"));
|
2013-09-26 18:38:44 +02:00
|
|
|
|
2020-02-13 14:03:37 +01:00
|
|
|
const QList<BuildTargetInfo> buildTargets = buildSystem->applicationTargets();
|
|
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitAspect::qtVersion(buildSystem->kit());
|
2014-09-22 16:20:51 +03:00
|
|
|
m_copyGradle = version && version->qtVersion() >= QtSupport::QtVersionNumber(5, 4, 0);
|
|
|
|
|
|
2019-05-03 17:26:49 +02:00
|
|
|
if (buildTargets.isEmpty()) {
|
2013-09-26 18:38:44 +02:00
|
|
|
// oh uhm can't create anything
|
|
|
|
|
addPage(new NoApplicationProFilePage(this));
|
2019-05-03 17:26:49 +02:00
|
|
|
} else if (buildTargets.size() == 1) {
|
|
|
|
|
setBuildKey(buildTargets.first().buildKey);
|
2013-09-26 18:38:44 +02:00
|
|
|
addPage(new ChooseDirectoryPage(this));
|
|
|
|
|
} else {
|
2018-07-02 18:12:25 +02:00
|
|
|
addPage(new ChooseProFilePage(this));
|
2013-09-26 18:38:44 +02:00
|
|
|
addPage(new ChooseDirectoryPage(this));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-02 18:12:25 +02:00
|
|
|
QString CreateAndroidManifestWizard::buildKey() const
|
2013-09-26 18:38:44 +02:00
|
|
|
{
|
2018-07-02 18:12:25 +02:00
|
|
|
return m_buildKey;
|
2013-09-26 18:38:44 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-02 18:12:25 +02:00
|
|
|
void CreateAndroidManifestWizard::setBuildKey(const QString &buildKey)
|
2013-09-26 18:38:44 +02:00
|
|
|
{
|
2018-07-02 18:12:25 +02:00
|
|
|
m_buildKey = buildKey;
|
2013-09-26 18:38:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CreateAndroidManifestWizard::setDirectory(const QString &directory)
|
|
|
|
|
{
|
|
|
|
|
m_directory = directory;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-22 16:20:51 +03:00
|
|
|
bool CreateAndroidManifestWizard::copyGradle()
|
2013-09-26 18:38:44 +02:00
|
|
|
{
|
2014-09-22 16:20:51 +03:00
|
|
|
return m_copyGradle;
|
2014-07-21 21:55:01 +02:00
|
|
|
}
|
|
|
|
|
|
2014-09-22 16:20:51 +03:00
|
|
|
void CreateAndroidManifestWizard::setCopyGradle(bool copy)
|
2014-07-21 21:55:01 +02:00
|
|
|
{
|
2014-09-22 16:20:51 +03:00
|
|
|
m_copyGradle = copy;
|
2013-09-26 18:38:44 +02:00
|
|
|
}
|
|
|
|
|
|
2014-09-22 16:20:51 +03:00
|
|
|
bool CreateAndroidManifestWizard::copy(const QFileInfo &src, const QFileInfo &dst, QStringList * addedFiles)
|
2013-09-26 18:38:44 +02:00
|
|
|
{
|
2014-09-22 16:20:51 +03:00
|
|
|
bool copyFile = true;
|
|
|
|
|
if (dst.exists()) {
|
|
|
|
|
switch (m_copyState) {
|
|
|
|
|
case Ask:
|
|
|
|
|
{
|
|
|
|
|
int res = QMessageBox::question(this,
|
|
|
|
|
tr("Overwrite %1 file").arg(dst.fileName()),
|
|
|
|
|
tr("Overwrite existing \"%1\"?")
|
|
|
|
|
.arg(QDir(m_directory).relativeFilePath(dst.absoluteFilePath())),
|
|
|
|
|
QMessageBox::Yes | QMessageBox::YesToAll |
|
|
|
|
|
QMessageBox::No | QMessageBox::NoToAll |
|
|
|
|
|
QMessageBox::Cancel);
|
|
|
|
|
switch (res) {
|
|
|
|
|
case QMessageBox::YesToAll:
|
|
|
|
|
m_copyState = OverwriteAll;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case QMessageBox::Yes:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case QMessageBox::NoToAll:
|
|
|
|
|
m_copyState = SkipAll;
|
|
|
|
|
copyFile = false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case QMessageBox::No:
|
|
|
|
|
copyFile = false;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-09-26 18:38:44 +02:00
|
|
|
}
|
2014-09-22 16:20:51 +03:00
|
|
|
break;
|
|
|
|
|
case SkipAll:
|
|
|
|
|
copyFile = false;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2013-09-26 18:38:44 +02:00
|
|
|
}
|
2014-09-22 16:20:51 +03:00
|
|
|
if (copyFile)
|
|
|
|
|
QFile::remove(dst.filePath());
|
2013-09-26 18:38:44 +02:00
|
|
|
}
|
|
|
|
|
|
2014-09-22 16:20:51 +03:00
|
|
|
if (!dst.absoluteDir().exists())
|
|
|
|
|
dst.absoluteDir().mkpath(dst.absolutePath());
|
2014-07-21 21:55:01 +02:00
|
|
|
|
2014-09-22 16:20:51 +03:00
|
|
|
if (copyFile && !QFile::copy(src.filePath(), dst.filePath())) {
|
2014-07-21 21:55:01 +02:00
|
|
|
QMessageBox::warning(this, tr("File Creation Error"),
|
2014-09-22 16:20:51 +03:00
|
|
|
tr("Could not copy file \"%1\" to \"%2\".")
|
|
|
|
|
.arg(src.filePath()).arg(dst.filePath()));
|
|
|
|
|
return false;
|
2014-07-21 21:55:01 +02:00
|
|
|
}
|
2014-09-22 16:20:51 +03:00
|
|
|
addedFiles->append(dst.absoluteFilePath());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-07-21 21:55:01 +02:00
|
|
|
|
2014-09-22 16:20:51 +03:00
|
|
|
void CreateAndroidManifestWizard::createAndroidTemplateFiles()
|
|
|
|
|
{
|
|
|
|
|
if (m_directory.isEmpty())
|
2013-09-26 18:38:44 +02:00
|
|
|
return;
|
2014-09-22 16:20:51 +03:00
|
|
|
|
|
|
|
|
QStringList addedFiles;
|
2020-02-13 14:03:37 +01:00
|
|
|
Target *target = m_buildSystem->target();
|
|
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtKitAspect::qtVersion(target->kit());
|
2014-11-18 18:26:08 +02:00
|
|
|
if (!version)
|
|
|
|
|
return;
|
|
|
|
|
if (version->qtVersion() < QtSupport::QtVersionNumber(5, 4, 0)) {
|
2019-09-30 14:34:31 +02:00
|
|
|
const QString src = version->prefix().toString() + "/src/android/java/AndroidManifest.xml";
|
2019-05-28 13:49:26 +02:00
|
|
|
FileUtils::copyRecursively(FilePath::fromString(src),
|
|
|
|
|
FilePath::fromString(m_directory + QLatin1String("/AndroidManifest.xml")),
|
2018-07-25 12:19:15 +02:00
|
|
|
nullptr, [this, &addedFiles](QFileInfo src, QFileInfo dst, QString *){return copy(src, dst, &addedFiles);});
|
2014-09-22 16:20:51 +03:00
|
|
|
} else {
|
2019-09-30 14:34:31 +02:00
|
|
|
const QString src = version->prefix().toString() + "/src/android/templates";
|
2014-09-22 16:20:51 +03:00
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
FileUtils::copyRecursively(FilePath::fromString(src),
|
|
|
|
|
FilePath::fromString(m_directory),
|
2018-07-25 12:19:15 +02:00
|
|
|
nullptr, [this, &addedFiles](QFileInfo src, QFileInfo dst, QString *){return copy(src, dst, &addedFiles);});
|
2014-09-22 16:20:51 +03:00
|
|
|
|
2017-03-01 19:16:18 +02:00
|
|
|
if (m_copyGradle) {
|
2019-09-30 14:34:31 +02:00
|
|
|
FilePath gradlePath = version->prefix().pathAppended("src/3rdparty/gradle");
|
2017-03-01 19:16:18 +02:00
|
|
|
if (!gradlePath.exists())
|
2019-05-16 14:49:56 +02:00
|
|
|
gradlePath = AndroidConfigurations::currentConfig().sdkLocation().pathAppended("/tools/templates/gradle/wrapper");
|
2019-05-28 13:49:26 +02:00
|
|
|
FileUtils::copyRecursively(gradlePath, FilePath::fromString(m_directory),
|
2018-07-25 12:19:15 +02:00
|
|
|
nullptr, [this, &addedFiles](QFileInfo src, QFileInfo dst, QString *){return copy(src, dst, &addedFiles);});
|
2017-03-01 19:16:18 +02:00
|
|
|
}
|
2014-09-22 16:20:51 +03:00
|
|
|
|
2020-02-13 14:03:37 +01:00
|
|
|
AndroidManager::updateGradleProperties(target, m_buildKey);
|
2013-09-26 18:38:44 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-02 18:12:25 +02:00
|
|
|
|
2018-12-05 10:29:48 +01:00
|
|
|
QString androidPackageDir;
|
2020-02-13 14:03:37 +01:00
|
|
|
ProjectNode *node = target->project()->findNodeForBuildKey(m_buildKey);
|
2018-12-05 10:29:48 +01:00
|
|
|
if (node) {
|
|
|
|
|
node->addFiles(addedFiles);
|
2018-12-18 17:52:19 +01:00
|
|
|
androidPackageDir = node->data(Android::Constants::AndroidPackageSourceDir).toString();
|
2018-07-02 18:12:25 +02:00
|
|
|
|
2020-02-24 11:08:55 +01:00
|
|
|
if (androidPackageDir.isEmpty()) {
|
|
|
|
|
// and now time for some magic
|
|
|
|
|
const BuildTargetInfo bti = target->buildTarget(m_buildKey);
|
|
|
|
|
const QString value = "$$PWD/"
|
|
|
|
|
+ bti.projectFilePath.toFileInfo().absoluteDir().relativeFilePath(
|
|
|
|
|
m_directory);
|
|
|
|
|
bool result = node->setData(Android::Constants::AndroidPackageSourceDir, value);
|
|
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
|
QMessageBox::warning(this,
|
|
|
|
|
tr("Project File not Updated"),
|
|
|
|
|
tr("Could not update the project file %1.")
|
|
|
|
|
.arg(bti.projectFilePath.toUserOutput()));
|
|
|
|
|
}
|
2013-09-26 18:38:44 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-09-22 16:20:51 +03:00
|
|
|
Core::EditorManager::openEditor(m_directory + QLatin1String("/AndroidManifest.xml"));
|
2013-09-26 18:38:44 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-13 14:03:37 +01:00
|
|
|
BuildSystem *CreateAndroidManifestWizard::buildSystem() const
|
2018-07-02 18:12:25 +02:00
|
|
|
{
|
2020-02-13 14:03:37 +01:00
|
|
|
return m_buildSystem;
|
2018-07-02 18:12:25 +02:00
|
|
|
}
|
|
|
|
|
|
2013-09-26 18:38:44 +02:00
|
|
|
void CreateAndroidManifestWizard::accept()
|
|
|
|
|
{
|
2014-09-22 16:20:51 +03:00
|
|
|
createAndroidTemplateFiles();
|
2015-02-03 23:50:37 +02:00
|
|
|
Wizard::accept();
|
2013-09-26 18:38:44 +02:00
|
|
|
}
|
2018-07-02 18:40:29 +02:00
|
|
|
|
2020-02-13 14:15:54 +01:00
|
|
|
} // namespace Internal
|
2018-07-02 18:40:29 +02:00
|
|
|
} // namespace Android
|