| 
									
										
										
										
											2022-08-19 15:59:36 +02:00
										 |  |  | // Copyright (C) 2016 The Qt Company Ltd.
 | 
					
						
							| 
									
										
										
										
											2022-12-21 10:12:09 +01:00
										 |  |  | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
 | 
					
						
							| 
									
										
										
										
											2013-09-26 18:38:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  | #include "androidtr.h"
 | 
					
						
							| 
									
										
										
										
											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>
 | 
					
						
							| 
									
										
										
										
											2022-11-10 12:24:15 +01:00
										 |  |  | #include <utils/qtcassert.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 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 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); | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |     label->setText(Tr::tr("No application .pro file found in this project.")); | 
					
						
							| 
									
										
										
										
											2013-09-26 18:38:44 +02:00
										 |  |  |     layout->addWidget(label); | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |     setTitle(Tr::tr("No Application .pro File")); | 
					
						
							| 
									
										
										
										
											2013-09-26 18:38:44 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 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); | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |     label->setText(Tr::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(); | 
					
						
							| 
									
										
										
										
											2020-03-31 20:25:54 +02:00
										 |  |  |     QString currentBuildKey = buildSystem->target()->activeBuildKey(); | 
					
						
							| 
									
										
										
										
											2018-07-02 18:12:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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()) { | 
					
						
							| 
									
										
										
										
											2021-11-30 17:25:50 +01:00
										 |  |  |         const QString displayName = QDir::toNativeSeparators(bti.buildKey); | 
					
						
							| 
									
										
										
										
											2018-07-02 18:12:25 +02:00
										 |  |  |         m_comboBox->addItem(displayName, QVariant(bti.buildKey)); // TODO something more?
 | 
					
						
							| 
									
										
										
										
											2020-03-31 20:25:54 +02:00
										 |  |  |         if (bti.buildKey == currentBuildKey) | 
					
						
							| 
									
										
										
										
											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()); | 
					
						
							| 
									
										
										
										
											2022-07-19 22:51:32 +02:00
										 |  |  |     connect(m_comboBox, &QComboBox::currentIndexChanged, this, &ChooseProFilePage::nodeSelected); | 
					
						
							| 
									
										
										
										
											2013-09-26 18:38:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |     fl->addRow(Tr::tr(".pro file:"), m_comboBox); | 
					
						
							|  |  |  |     setTitle(Tr::tr("Select a .pro File")); | 
					
						
							| 
									
										
										
										
											2013-09-26 18:38:44 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     ChooseDirectoryPage(CreateAndroidManifestWizard *wizard); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2020-11-18 15:26:38 +01:00
										 |  |  |     void initializePage() final; | 
					
						
							|  |  |  |     bool isComplete() const final; | 
					
						
							| 
									
										
										
										
											2020-02-13 14:15:54 +01:00
										 |  |  |     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); | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |     m_layout->addRow(Tr::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 = | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |             new InfoLabel(Tr::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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-02 11:49:36 +02:00
										 |  |  |     connect(m_androidPackageSourceDir, &PathChooser::textChanged, m_wizard, [this] { | 
					
						
							|  |  |  |         m_wizard->setDirectory(m_androidPackageSourceDir->rawFilePath()); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											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
										 |  |  |         connect(checkBox, &QCheckBox::toggled, wizard, &CreateAndroidManifestWizard::setCopyGradle); | 
					
						
							| 
									
										
										
										
											2020-11-23 19:07:38 +02:00
										 |  |  |         checkBox->setChecked(false); | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |         checkBox->setText(Tr::tr("Copy the Gradle files to Android directory")); | 
					
						
							|  |  |  |         checkBox->setToolTip(Tr::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); | 
					
						
							| 
									
										
										
										
											2022-09-27 08:41:53 +02:00
										 |  |  |     const FilePath projectDir = bti.projectFilePath.absolutePath(); | 
					
						
							| 
									
										
										
										
											2018-07-02 18:12:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-27 08:41:53 +02:00
										 |  |  |     const FilePath newDir = m_androidPackageSourceDir->filePath(); | 
					
						
							|  |  |  |     bool isComplete = projectDir.canonicalPath() != newDir.canonicalPath(); | 
					
						
							| 
									
										
										
										
											2014-03-12 15:20:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 17:16:43 +02:00
										 |  |  |     FilePath androidPackageDir; | 
					
						
							| 
									
										
										
										
											2018-12-05 10:29:48 +01:00
										 |  |  |     if (const ProjectNode *node = target->project()->findNodeForBuildKey(buildKey)) | 
					
						
							| 
									
										
										
										
											2021-09-08 17:16:43 +02:00
										 |  |  |         androidPackageDir = FilePath::fromVariant(node->data(Android::Constants::AndroidPackageSourceDir)); | 
					
						
							| 
									
										
										
										
											2018-07-02 18:12:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-16 13:22:47 +01:00
										 |  |  |     if (androidPackageDir.isEmpty()) { | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |         m_label->setText(Tr::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.")); | 
					
						
							| 
									
										
										
										
											2015-01-16 13:22:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-14 17:25:44 -08:00
										 |  |  |         const FilePath projectPath = bti.projectFilePath.isFile() | 
					
						
							|  |  |  |                 ? bti.projectFilePath.parentDir() : bti.projectFilePath; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_androidPackageSourceDir->setFilePath(projectPath / "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 { | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |         m_label->setText(Tr::tr("The Android template files will be created in the %1 set in the .pro " | 
					
						
							|  |  |  |                                 "file.").arg(QLatin1String(Constants::ANDROID_PACKAGE_SOURCE_DIR))); | 
					
						
							| 
									
										
										
										
											2021-09-08 17:16:43 +02:00
										 |  |  |         m_androidPackageSourceDir->setFilePath(androidPackageDir); | 
					
						
							| 
									
										
										
										
											2015-01-16 13:22:47 +01:00
										 |  |  |         m_androidPackageSourceDir->setReadOnly(true); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-10 19:16:26 +02:00
										 |  |  |     m_wizard->setDirectory(m_androidPackageSourceDir->filePath()); | 
					
						
							| 
									
										
										
										
											2015-01-16 13:22:47 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-26 18:38:44 +02:00
										 |  |  | //
 | 
					
						
							|  |  |  | // CreateAndroidManifestWizard
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2020-02-13 14:03:37 +01:00
										 |  |  | CreateAndroidManifestWizard::CreateAndroidManifestWizard(BuildSystem *buildSystem) | 
					
						
							| 
									
										
										
										
											2020-06-11 16:24:42 +02:00
										 |  |  |     : m_buildSystem(buildSystem) | 
					
						
							| 
									
										
										
										
											2013-09-26 18:38:44 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |     setWindowTitle(Tr::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(); | 
					
						
							| 
									
										
										
										
											2022-01-21 16:06:36 +01:00
										 |  |  |     QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(buildSystem->kit()); | 
					
						
							| 
									
										
										
										
											2022-07-04 18:36:40 +02:00
										 |  |  |     m_copyGradle = version && version->qtVersion() >= QVersionNumber(5, 4, 0); | 
					
						
							| 
									
										
										
										
											2014-09-22 16:20:51 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-10 19:16:26 +02:00
										 |  |  | void CreateAndroidManifestWizard::setDirectory(const FilePath &directory) | 
					
						
							| 
									
										
										
										
											2013-09-26 18:38:44 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     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
										 |  |  | void CreateAndroidManifestWizard::createAndroidTemplateFiles() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_directory.isEmpty()) | 
					
						
							| 
									
										
										
										
											2013-09-26 18:38:44 +02:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2014-09-22 16:20:51 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-11 16:24:42 +02:00
										 |  |  |     FileUtils::CopyAskingForOverwrite copy(this); | 
					
						
							| 
									
										
										
										
											2020-02-13 14:03:37 +01:00
										 |  |  |     Target *target = m_buildSystem->target(); | 
					
						
							| 
									
										
										
										
											2022-01-21 16:06:36 +01:00
										 |  |  |     QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(target->kit()); | 
					
						
							| 
									
										
										
										
											2014-11-18 18:26:08 +02:00
										 |  |  |     if (!version) | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2022-07-04 18:36:40 +02:00
										 |  |  |     if (version->qtVersion() < QVersionNumber(5, 4, 0)) { | 
					
						
							| 
									
										
										
										
											2021-08-10 19:16:26 +02:00
										 |  |  |         FileUtils::copyRecursively(version->prefix() / "src/android/java/AndroidManifest.xml", | 
					
						
							|  |  |  |                                    m_directory / "AndroidManifest.xml", | 
					
						
							| 
									
										
										
										
											2020-06-11 16:24:42 +02:00
										 |  |  |                                    nullptr, | 
					
						
							|  |  |  |                                    copy); | 
					
						
							| 
									
										
										
										
											2014-09-22 16:20:51 +03:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2021-08-10 19:16:26 +02:00
										 |  |  |         FileUtils::copyRecursively(version->prefix() / "src/android/templates", | 
					
						
							|  |  |  |                                    m_directory, | 
					
						
							| 
									
										
										
										
											2020-06-11 16:24:42 +02:00
										 |  |  |                                    nullptr, | 
					
						
							|  |  |  |                                    copy); | 
					
						
							| 
									
										
										
										
											2014-09-22 16:20:51 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-01 19:16:18 +02:00
										 |  |  |         if (m_copyGradle) { | 
					
						
							| 
									
										
										
										
											2021-08-10 19:16:26 +02:00
										 |  |  |             FilePath gradlePath = version->prefix() / "src/3rdparty/gradle"; | 
					
						
							| 
									
										
										
										
											2022-11-10 12:24:15 +01:00
										 |  |  |             QTC_ASSERT(gradlePath.exists(), return); | 
					
						
							| 
									
										
										
										
											2021-08-10 19:16:26 +02:00
										 |  |  |             FileUtils::copyRecursively(gradlePath, m_directory, nullptr, copy); | 
					
						
							| 
									
										
										
										
											2017-03-01 19:16:18 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2013-09-26 18:38:44 +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) { | 
					
						
							| 
									
										
										
										
											2020-06-11 16:24:42 +02:00
										 |  |  |         node->addFiles(copy.files()); | 
					
						
							| 
									
										
										
										
											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( | 
					
						
							| 
									
										
										
										
											2021-08-10 19:16:26 +02:00
										 |  |  |                                       m_directory.toString()); | 
					
						
							| 
									
										
										
										
											2020-02-24 11:08:55 +01:00
										 |  |  |             bool result = node->setData(Android::Constants::AndroidPackageSourceDir, value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (!result) { | 
					
						
							|  |  |  |                 QMessageBox::warning(this, | 
					
						
							| 
									
										
										
										
											2022-10-06 17:53:35 +02:00
										 |  |  |                                      Tr::tr("Project File not Updated"), | 
					
						
							|  |  |  |                                      Tr::tr("Could not update the project file %1.") | 
					
						
							|  |  |  |                                      .arg(bti.projectFilePath.toUserOutput())); | 
					
						
							| 
									
										
										
										
											2020-02-24 11:08:55 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2013-09-26 18:38:44 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-08-10 19:16:26 +02:00
										 |  |  |     Core::EditorManager::openEditor(m_directory / "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
 |