From fc2d8deae3d2eb3386e29a9f27951f864517910e Mon Sep 17 00:00:00 2001
From: Kai Koehne <kai.koehne@nokia.com>
Date: Fri, 13 Jan 2012 15:00:04 +0100
Subject: [PATCH] QmlEngine: Move setup logic from setupInferior to setupEngine

This is more in line with e.g. the gdb engine, which also emits
requestRemoteSetup in setupEngine().

Change-Id: I1c2a4c56d6f190a3043ea8a18d2bb28c9d340826
Reviewed-by: Aurindam Jana <aurindam.jana@nokia.com>
---
 src/plugins/debugger/qml/qmlengine.cpp | 41 +++++++++++++-------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/src/plugins/debugger/qml/qmlengine.cpp b/src/plugins/debugger/qml/qmlengine.cpp
index 2f2d05efbe5..f66847f8bc4 100644
--- a/src/plugins/debugger/qml/qmlengine.cpp
+++ b/src/plugins/debugger/qml/qmlengine.cpp
@@ -197,19 +197,7 @@ void QmlEngine::setupInferior()
 {
     QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
 
-    if (startParameters().startMode == AttachToRemoteServer) {
-        emit requestRemoteSetup();
-        if (startParameters().qmlServerPort != quint16(-1))
-            notifyInferiorSetupOk();
-    } if (startParameters().startMode == AttachToQmlPort) {
-            notifyInferiorSetupOk();
-
-    } else {
-        d->m_applicationLauncher.setEnvironment(startParameters().environment);
-        d->m_applicationLauncher.setWorkingDirectory(startParameters().workingDirectory);
-
-        notifyInferiorSetupOk();
-    }
+    notifyInferiorSetupOk();
 }
 
 void QmlEngine::appendMessage(const QString &msg, Utils::OutputFormat /* format */)
@@ -422,14 +410,15 @@ void QmlEngine::handleRemoteSetupDone(int gdbServerPort, int qmlPort)
     Q_UNUSED(gdbServerPort);
     if (qmlPort != -1)
         startParameters().qmlServerPort = qmlPort;
-    notifyInferiorSetupOk();
+    notifyEngineSetupOk();
 }
 
 void QmlEngine::handleRemoteSetupFailed(const QString &message)
 {
-    QMessageBox::critical(0,tr("Failed to start application"),
-        tr("Application startup failed: %1").arg(message));
-    notifyInferiorSetupFailed();
+    if (isMasterEngine())
+        QMessageBox::critical(0,tr("Failed to start application"),
+            tr("Application startup failed: %1").arg(message));
+    notifyEngineSetupFailed();
 }
 
 void QmlEngine::shutdownInferior()
@@ -461,11 +450,21 @@ void QmlEngine::shutdownEngine()
 
 void QmlEngine::setupEngine()
 {
-    connect(&d->m_applicationLauncher, SIGNAL(bringToForegroundRequested(qint64)),
-            runControl(), SLOT(bringApplicationToForeground(qint64)),
-            Qt::UniqueConnection);
+    if (startParameters().startMode == AttachToQmlPort
+             || startParameters().startMode == AttachToRemoteServer) {
+        // we need to get the port first
+        emit requestRemoteSetup();
+    } else {
+        d->m_applicationLauncher.setEnvironment(startParameters().environment);
+        d->m_applicationLauncher.setWorkingDirectory(startParameters().workingDirectory);
 
-    notifyEngineSetupOk();
+        // We can't do this in the constructore because runControl() isn't yet defined
+        connect(&d->m_applicationLauncher, SIGNAL(bringToForegroundRequested(qint64)),
+                runControl(), SLOT(bringApplicationToForeground(qint64)),
+                Qt::UniqueConnection);
+
+        notifyEngineSetupOk();
+    }
 }
 
 void QmlEngine::continueInferior()
-- 
GitLab