From 583cd11371b457d8a04e52474efa025f624822f7 Mon Sep 17 00:00:00 2001
From: Daniel Teske <daniel.teske@digia.com>
Date: Thu, 13 Jun 2013 16:38:03 +0200
Subject: [PATCH] Android: Hide bundle qt option for Qt4

Task-number: QTCREATORBUG-9408

Change-Id: Ie86deea4b453d3ab3ebcf359c3e0b321a2cba33e
Reviewed-by: BogDan Vatra <bogdan@kde.org>
---
 src/plugins/android/androiddeploystep.cpp     | 42 +++++++++++++++++--
 src/plugins/android/androiddeploystep.h       |  4 ++
 .../android/androiddeploystepwidget.cpp       | 22 +++++++---
 src/plugins/android/androiddeploystepwidget.h |  1 +
 4 files changed, 60 insertions(+), 9 deletions(-)

diff --git a/src/plugins/android/androiddeploystep.cpp b/src/plugins/android/androiddeploystep.cpp
index c11ced5f1e4..04eeb91f023 100644
--- a/src/plugins/android/androiddeploystep.cpp
+++ b/src/plugins/android/androiddeploystep.cpp
@@ -83,9 +83,14 @@ void AndroidDeployStep::ctor()
     setDefaultDisplayName(tr("Deploy to Android device"));
     m_deployAction = NoDeploy;
 
-    if (QtSupport::BaseQtVersion *qt = QtSupport::QtKitInformation::qtVersion(target()->kit()))
-        if (qt->qtVersion() >= QtSupport::QtVersionNumber(5, 0, 0))
-            m_deployAction = BundleLibraries;
+    QtSupport::BaseQtVersion *qt = QtSupport::QtKitInformation::qtVersion(target()->kit());
+    m_bundleQtAvailable = qt && qt->qtVersion() >= QtSupport::QtVersionNumber(5, 0, 0);
+    if (m_bundleQtAvailable)
+        m_deployAction = BundleLibraries;
+
+
+    connect(ProjectExplorer::KitManager::instance(), SIGNAL(kitUpdated(ProjectExplorer::Kit*)),
+            this, SLOT(kitUpdated(ProjectExplorer::Kit *)));
 }
 
 bool AndroidDeployStep::init()
@@ -157,6 +162,14 @@ bool AndroidDeployStep::fromMap(const QVariantMap &map)
 
     if (m_deployAction == InstallQASI)
         m_deployAction = NoDeploy;
+    QtSupport::BaseQtVersion *qtVersion
+            = QtSupport::QtKitInformation::qtVersion(target()->kit());
+    if (m_deployAction == BundleLibraries)
+        if (!qtVersion || qtVersion->qtVersion() < QtSupport::QtVersionNumber(5, 0, 0))
+            m_deployAction = NoDeploy; // the kit changed to a non qt5 kit
+
+    m_bundleQtAvailable = qtVersion && qtVersion->qtVersion() >= QtSupport::QtVersionNumber(5, 0, 0);
+
     return ProjectExplorer::BuildStep::fromMap(map);
 }
 
@@ -201,6 +214,24 @@ void AndroidDeployStep::processFinished()
     process->deleteLater();
 }
 
+void AndroidDeployStep::kitUpdated(Kit *kit)
+{
+    if (kit != target()->kit())
+        return;
+    QtSupport::BaseQtVersion *qtVersion
+            = QtSupport::QtKitInformation::qtVersion(target()->kit());
+
+    bool newBundleQtAvailable = qtVersion && qtVersion->qtVersion() >= QtSupport::QtVersionNumber(5, 0, 0);
+    if (m_bundleQtAvailable != newBundleQtAvailable) {
+        m_bundleQtAvailable = newBundleQtAvailable;
+
+        if (!m_bundleQtAvailable && m_deployAction == BundleLibraries)
+            m_deployAction = NoDeploy; // the kit changed to a non qt5 kit
+
+        emit deployOptionsChanged();
+    }
+}
+
 void AndroidDeployStep::installQASIPackage(const QString &packagePath)
 {
     const QString targetArch = AndroidManager::targetArch(target());
@@ -226,6 +257,11 @@ void AndroidDeployStep::installQASIPackage(const QString &packagePath)
         delete process;
 }
 
+bool AndroidDeployStep::bundleQtOptionAvailable()
+{
+    return m_bundleQtAvailable;
+}
+
 void AndroidDeployStep::setDeployAction(AndroidDeployStep::AndroidDeployAction deploy)
 {
     m_deployAction = deploy;
diff --git a/src/plugins/android/androiddeploystep.h b/src/plugins/android/androiddeploystep.h
index ad922c46e1d..6725020a853 100644
--- a/src/plugins/android/androiddeploystep.h
+++ b/src/plugins/android/androiddeploystep.h
@@ -96,6 +96,7 @@ public:
 
     void cleanLibsOnDevice();
     void installQASIPackage(const QString &packagePath);
+    bool bundleQtOptionAvailable();
 
 public slots:
     void setDeployAction(AndroidDeployAction deploy);
@@ -103,12 +104,14 @@ public slots:
 signals:
     void done();
     void error();
+    void deployOptionsChanged();
 
 private slots:
     bool deployPackage();
     void handleBuildOutput();
     void handleBuildError();
     void processFinished();
+    void kitUpdated(ProjectExplorer::Kit *kit);
 
 private:
     AndroidDeployStep(ProjectExplorer::BuildStepList *bc,
@@ -151,6 +154,7 @@ private:
     AndroidDeployAction m_runDeployAction;
     QString m_ndkToolChainVersion;
     QString m_libgnustl;
+    bool m_bundleQtAvailable;
     static const Core::Id Id;
 };
 
diff --git a/src/plugins/android/androiddeploystepwidget.cpp b/src/plugins/android/androiddeploystepwidget.cpp
index 482051342cd..93140abf3c2 100644
--- a/src/plugins/android/androiddeploystepwidget.cpp
+++ b/src/plugins/android/androiddeploystepwidget.cpp
@@ -47,6 +47,21 @@ AndroidDeployStepWidget::AndroidDeployStepWidget(AndroidDeployStep *step) :
 {
     ui->setupUi(this);
 
+    deployOptionsChanged();
+
+    connect(ui->ministroOption, SIGNAL(clicked()), SLOT(setMinistro()));
+    connect(ui->temporaryQtOption, SIGNAL(clicked()), SLOT(setDeployLocalQtLibs()));
+    connect(ui->bundleQtOption, SIGNAL(clicked()), SLOT(setBundleQtLibs()));
+
+    connect(ui->chooseButton, SIGNAL(clicked()), SLOT(setQASIPackagePath()));
+    connect(ui->cleanLibsPushButton, SIGNAL(clicked()), SLOT(cleanLibsOnDevice()));
+
+    connect(m_step, SIGNAL(deployOptionsChanged()),
+            this, SLOT(deployOptionsChanged()));
+}
+
+void AndroidDeployStepWidget::deployOptionsChanged()
+{
     switch (m_step->deployAction()) {
     case AndroidDeployStep::NoDeploy:
         ui->ministroOption->setChecked(true);
@@ -62,12 +77,7 @@ AndroidDeployStepWidget::AndroidDeployStepWidget(AndroidDeployStep *step) :
         break;
     }
 
-    connect(ui->ministroOption, SIGNAL(clicked()), SLOT(setMinistro()));
-    connect(ui->temporaryQtOption, SIGNAL(clicked()), SLOT(setDeployLocalQtLibs()));
-    connect(ui->bundleQtOption, SIGNAL(clicked()), SLOT(setBundleQtLibs()));
-
-    connect(ui->chooseButton, SIGNAL(clicked()), SLOT(setQASIPackagePath()));
-    connect(ui->cleanLibsPushButton, SIGNAL(clicked()), SLOT(cleanLibsOnDevice()));
+    ui->bundleQtOption->setVisible(m_step->bundleQtOptionAvailable());
 }
 
 AndroidDeployStepWidget::~AndroidDeployStepWidget()
diff --git a/src/plugins/android/androiddeploystepwidget.h b/src/plugins/android/androiddeploystepwidget.h
index 8c05d0aa629..94bea1c6dee 100644
--- a/src/plugins/android/androiddeploystepwidget.h
+++ b/src/plugins/android/androiddeploystepwidget.h
@@ -56,6 +56,7 @@ private slots:
     void setQASIPackagePath();
     void cleanLibsOnDevice();
 
+    void deployOptionsChanged();
 private:
     virtual QString summaryText() const;
     virtual QString displayName() const;
-- 
GitLab