From e6edf54a9c3e815507ccfcd4ea1325f964004797 Mon Sep 17 00:00:00 2001
From: con <qtc-committer@nokia.com>
Date: Mon, 30 Nov 2009 17:55:08 +0100
Subject: [PATCH] Show Symbian deploy progress as real progress indicator.

Task-number: QTCREATORBUG-364
---
 .../qt-s60/s60devicerunconfiguration.cpp      | 43 ++++++++++++++++++-
 .../qt-s60/s60devicerunconfiguration.h        |  4 ++
 src/shared/trk/launcher.cpp                   |  6 ++-
 src/shared/trk/launcher.h                     |  1 +
 4 files changed, 51 insertions(+), 3 deletions(-)

diff --git a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp
index bcb257b11b9..cefe094fab0 100644
--- a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp
+++ b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp
@@ -41,6 +41,7 @@
 
 #include <coreplugin/icore.h>
 #include <coreplugin/messagemanager.h>
+#include <coreplugin/progressmanager/progressmanager.h>
 #include <utils/qtcassert.h>
 #include <utils/pathchooser.h>
 #include <projectexplorer/projectexplorerconstants.h>
@@ -60,6 +61,13 @@ using namespace Qt4ProjectManager::Internal;
 
 enum { debug = 0 };
 
+static const int    PROGRESS_PACKAGECREATED = 100;
+static const int    PROGRESS_PACKAGESIGNED = 200;
+static const int    PROGRESS_DEPLOYBASE = 200;
+static const int    PROGRESS_PACKAGEDEPLOYED = 300;
+static const int    PROGRESS_PACKAGEINSTALLED = 400;
+static const int    PROGRESS_MAX = 400;
+
 // Format information about a file
 static QString lsFile(const QString &f)
 {
@@ -414,7 +422,10 @@ S60DeviceRunControlBase::S60DeviceRunControlBase(RunConfiguration *runConfigurat
     m_makesis(new QProcess(this)),
     m_signsis(0),
     m_launcher(0)
-{    
+{
+    // connect for automatically reporting the "finished deploy" state to the progress manager
+    connect(this, SIGNAL(finished()), this, SLOT(reportDeployFinished()));
+
     connect(m_makesis, SIGNAL(readyReadStandardError()),
             this, SLOT(readStandardError()));
     connect(m_makesis, SIGNAL(readyReadStandardOutput()),
@@ -490,6 +501,13 @@ S60DeviceRunControlBase::~S60DeviceRunControlBase()
 
 void S60DeviceRunControlBase::start()
 {
+    m_deployProgress = new QFutureInterface<void>;
+    Core::ICore::instance()->progressManager()->addTask(m_deployProgress->future(),
+                                                        tr("Deploying"),
+                                                        QLatin1String("Symbian.Deploy"));
+    m_deployProgress->setProgressRange(0, PROGRESS_MAX);
+    m_deployProgress->setProgressValue(0);
+    m_deployProgress->reportStarted();
     emit started();
     if (m_serialPortName.isEmpty()) {
         error(this, tr("There is no device plugged in."));
@@ -609,6 +627,7 @@ void S60DeviceRunControlBase::makesisProcessFinished()
         emit finished();
         return;
     }
+    m_deployProgress->setProgressValue(PROGRESS_PACKAGECREATED);
     switch (m_toolChain) {
     case ProjectExplorer::ToolChain::GCCE_GNUPOC:
     case ProjectExplorer::ToolChain::RVCT_ARMV6_GNUPOC:
@@ -650,6 +669,7 @@ void S60DeviceRunControlBase::signsisProcessFinished()
         stop();
         emit finished();
     } else {
+        m_deployProgress->setProgressValue(PROGRESS_PACKAGESIGNED);
         startDeployment();
     }
 }
@@ -665,6 +685,7 @@ void S60DeviceRunControlBase::startDeployment()
     connect(m_launcher, SIGNAL(canNotCloseFile(QString,QString)), this, SLOT(printCloseFileFailed(QString,QString)));
     connect(m_launcher, SIGNAL(installingStarted()), this, SLOT(printInstallingNotice()));
     connect(m_launcher, SIGNAL(canNotInstall(QString,QString)), this, SLOT(printInstallFailed(QString,QString)));
+    connect(m_launcher, SIGNAL(installingFinished()), this, SLOT(printInstallingFinished()));
     connect(m_launcher, SIGNAL(copyProgress(int)), this, SLOT(printCopyProgress(int)));
     connect(m_launcher, SIGNAL(stateChanged(int)), this, SLOT(slotLauncherStateChanged(int)));
 
@@ -733,14 +754,23 @@ void S60DeviceRunControlBase::printCopyingNotice()
 
 void S60DeviceRunControlBase::printCopyProgress(int progress)
 {
-    emit addToOutputWindow(this, tr("%1% copied.").arg(progress));
+    m_deployProgress->setProgressValue(PROGRESS_DEPLOYBASE + progress);
 }
 
 void S60DeviceRunControlBase::printInstallingNotice()
 {
+    m_deployProgress->setProgressValue(PROGRESS_PACKAGEDEPLOYED);
     emit addToOutputWindow(this, tr("Installing application..."));
 }
 
+void S60DeviceRunControlBase::printInstallingFinished()
+{
+    m_deployProgress->setProgressValue(PROGRESS_PACKAGEINSTALLED);
+    m_deployProgress->reportFinished();
+    delete m_deployProgress;
+    m_deployProgress = 0;
+}
+
 void S60DeviceRunControlBase::printInstallFailed(const QString &filename, const QString &errorMessage)
 {
     emit addToOutputWindow(this, tr("Could not install from package %1 on device: %2").arg(filename, errorMessage));
@@ -753,6 +783,15 @@ void S60DeviceRunControlBase::launcherFinished()
     handleLauncherFinished();
 }
 
+void S60DeviceRunControlBase::reportDeployFinished()
+{
+    if (m_deployProgress) {
+        m_deployProgress->reportFinished();
+        delete m_deployProgress;
+        m_deployProgress = 0;
+    }
+}
+
 QMessageBox *S60DeviceRunControlBase::createTrkWaitingMessageBox(const QString &port, QWidget *parent)
 {
     const QString title  = QCoreApplication::translate("Qt4ProjectManager::Internal::S60DeviceRunControlBase",
diff --git a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h
index c68dff066fc..8eac205640f 100644
--- a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h
+++ b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.h
@@ -36,6 +36,7 @@
 #include <projectexplorer/toolchain.h>
 
 #include <QtCore/QProcess>
+#include <QtCore/QFutureInterface>
 
 QT_BEGIN_NAMESPACE
 class QMessageBox;
@@ -176,9 +177,11 @@ private slots:
     void printCopyProgress(int progress);
     void printInstallingNotice();
     void printInstallFailed(const QString &filename, const QString &errorMessage);
+    void printInstallingFinished();
     void launcherFinished();
     void slotLauncherStateChanged(int);
     void slotWaitingForTrkClosed();
+    void reportDeployFinished();
 
 private:        
     bool createPackageFileFromTemplate(QString *errorMessage);
@@ -207,6 +210,7 @@ private:
     QString m_makesisTool;
     QString m_packageFile;
 
+    QFutureInterface<void> *m_deployProgress;
     trk::Launcher *m_launcher;
 };
 
diff --git a/src/shared/trk/launcher.cpp b/src/shared/trk/launcher.cpp
index b9b5f04a159..62f015cd1ed 100644
--- a/src/shared/trk/launcher.cpp
+++ b/src/shared/trk/launcher.cpp
@@ -640,7 +640,11 @@ void Launcher::handleInstallPackageFinished(const TrkResult &result)
     if (result.errorCode()) {
         emit canNotInstall(d->m_installFileName, result.errorString());
         disconnectTrk();
-    } else if (d->m_startupActions & ActionRun) {
+        return;
+    } else {
+        emit installingFinished();
+    }
+    if (d->m_startupActions & ActionRun) {
         startInferiorIfNeeded();
     } else {
         disconnectTrk();
diff --git a/src/shared/trk/launcher.h b/src/shared/trk/launcher.h
index 538d367e742..93a28217168 100644
--- a/src/shared/trk/launcher.h
+++ b/src/shared/trk/launcher.h
@@ -103,6 +103,7 @@ signals:
     void canNotCloseFile(const QString &filename, const QString &errorMessage);
     void installingStarted();
     void canNotInstall(const QString &packageFilename, const QString &errorMessage);
+    void installingFinished();
     void startingApplication();
     void applicationRunning(uint pid);
     void canNotRun(const QString &errorMessage);
-- 
GitLab