From e060086f5a19d6f0a0ffd85004c4c64758aef4a0 Mon Sep 17 00:00:00 2001 From: Daniel Teske Date: Wed, 12 Mar 2014 15:20:39 +0100 Subject: [PATCH] Android: Don't let the user choose a stupid ANDROID_PACKAGE_SOURCE_DIR On creating a AndroidManifest.xml we ask the user where to put the file, which as a sideeffect also sets ANDROID_PACKAGE_DIR. Since we copy everthing from ANDROID_PACKAGE_SOURCE_DIR into the build directory, using the project's source directory is not desireable. We now show a big error if the user tries that. Task-number: QTCREATORBUG-11708 Change-Id: I7fade3efac0b7466cad8e83a92c2115d0a70c683 Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../android/createandroidmanifestwizard.cpp | 44 ++++++++++++++++++- .../android/createandroidmanifestwizard.h | 8 ++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/plugins/android/createandroidmanifestwizard.cpp b/src/plugins/android/createandroidmanifestwizard.cpp index 5176b78930..bd8e0fbc52 100644 --- a/src/plugins/android/createandroidmanifestwizard.cpp +++ b/src/plugins/android/createandroidmanifestwizard.cpp @@ -95,7 +95,7 @@ void ChooseProFilePage::nodeSelected(int index) // ChooseDirectoryPage // ChooseDirectoryPage::ChooseDirectoryPage(CreateAndroidManifestWizard *wizard) - : m_wizard(wizard), m_androidPackageSourceDir(0) + : m_wizard(wizard), m_androidPackageSourceDir(0), m_complete(true) { QString androidPackageDir = m_wizard->node()->singleVariableValue(QmakeProjectManager::AndroidPackageSourceDir); @@ -104,28 +104,68 @@ ChooseDirectoryPage::ChooseDirectoryPage(CreateAndroidManifestWizard *wizard) label->setWordWrap(true); fl->addRow(label); + m_sourceDirectoryWarning = new QLabel(this); + m_sourceDirectoryWarning->setVisible(false); + m_sourceDirectoryWarning->setText(tr("The Android package source directory can not be the same as the project directory.")); + m_sourceDirectoryWarning->setWordWrap(true); + m_warningIcon = new QLabel(this); + m_warningIcon->setVisible(false); + m_warningIcon->setPixmap(QPixmap(QLatin1String(":/projectexplorer/images/compile_error.png"))); + m_warningIcon->setWordWrap(true); + m_warningIcon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + QHBoxLayout *hbox = new QHBoxLayout; + hbox->addWidget(m_warningIcon); + hbox->addWidget(m_sourceDirectoryWarning); + hbox->setAlignment(m_warningIcon, Qt::AlignTop); + + fl->addRow(hbox); + m_androidPackageSourceDir = new Utils::PathChooser(this); m_androidPackageSourceDir->setExpectedKind(Utils::PathChooser::Directory); fl->addRow(tr("Android package source directory:"), m_androidPackageSourceDir); if (androidPackageDir.isEmpty()) { - label->setText(tr("Select the Android package source directory. " + 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.")); m_androidPackageSourceDir->setPath(QFileInfo(m_wizard->node()->path()).absolutePath().append(QLatin1String("/android"))); + connect(m_androidPackageSourceDir, SIGNAL(changed(QString)), + this, SLOT(checkPackageSourceDir())); } else { label->setText(tr("The Android manifest file 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()); connect(m_androidPackageSourceDir, SIGNAL(pathChanged(QString)), m_wizard, SLOT(setDirectory(QString))); } +void ChooseDirectoryPage::checkPackageSourceDir() +{ + QString projectDir = QFileInfo(m_wizard->node()->path()).absolutePath(); + QString newDir = m_androidPackageSourceDir->path(); + bool isComplete = QFileInfo(projectDir) != QFileInfo(newDir); + + m_sourceDirectoryWarning->setVisible(!isComplete); + m_warningIcon->setVisible(!isComplete); + + if (isComplete != m_complete) { + m_complete = isComplete; + emit completeChanged(); + } +} + +bool ChooseDirectoryPage::isComplete() const +{ + return m_complete; +} + // // CreateAndroidManifestWizard // diff --git a/src/plugins/android/createandroidmanifestwizard.h b/src/plugins/android/createandroidmanifestwizard.h index a92c610e6f..8cb8c95b7f 100644 --- a/src/plugins/android/createandroidmanifestwizard.h +++ b/src/plugins/android/createandroidmanifestwizard.h @@ -34,6 +34,7 @@ QT_BEGIN_NAMESPACE class QComboBox; +class QLabel; QT_END_NAMESPACE namespace ProjectExplorer { class Target; } @@ -70,9 +71,16 @@ class ChooseDirectoryPage : public QWizardPage Q_OBJECT public: ChooseDirectoryPage(CreateAndroidManifestWizard *wizard); +protected: + bool isComplete() const; +private slots: + void checkPackageSourceDir(); private: CreateAndroidManifestWizard *m_wizard; Utils::PathChooser *m_androidPackageSourceDir; + QLabel *m_sourceDirectoryWarning; + QLabel *m_warningIcon; + bool m_complete; }; class CreateAndroidManifestWizard : public Utils::Wizard -- GitLab