From 983bc5d2489e737dc94aa4bf7b9a5983bcfcd48b Mon Sep 17 00:00:00 2001
From: Christian Kandeler <christian.kandeler@nokia.com>
Date: Wed, 6 Oct 2010 15:32:39 +0200
Subject: [PATCH] Maemo: Only mention mounting stuff to user when it's actually
 done.

Otherwise, we clutter the output window with potentially confusing
messages.

Reviewed-by: kh1
---
 .../qt-maemo/maemoremotemounter.cpp           | 15 ++++--
 .../qt-maemo/maemoremotemounter.h             |  1 +
 .../qt-maemo/maemosshrunner.cpp               | 51 ++++++++++++++++---
 .../qt-maemo/maemosshrunner.h                 |  2 +
 4 files changed, 57 insertions(+), 12 deletions(-)

diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.cpp
index 11ad3ab24e6..84fdd1cb614 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.cpp
@@ -47,7 +47,7 @@ namespace Qt4ProjectManager {
 namespace Internal {
 
 MaemoRemoteMounter::MaemoRemoteMounter(QObject *parent)
-    : QObject(parent), m_utfsServerTimer(new QTimer(this)),
+    : QObject(parent), m_toolChain(0), m_utfsServerTimer(new QTimer(this)),
       m_uploadJobId(SftpInvalidJob), m_state(Inactive)
 {
     connect(m_utfsServerTimer, SIGNAL(timeout()), this,
@@ -69,9 +69,10 @@ void MaemoRemoteMounter::setConnection(const Core::SshConnection::Ptr &connectio
 bool MaemoRemoteMounter::addMountSpecification(const MaemoMountSpecification &mountSpec,
     bool mountAsRoot)
 {
+    Q_ASSERT(m_toolChain);
     ASSERT_STATE(Inactive);
 
-    if (mountSpec.isValid()) {
+    if (m_toolChain->allowsRemoteMounts() && mountSpec.isValid()) {
         if (!m_portList.hasMore())
             return false;
         else
@@ -80,14 +81,17 @@ bool MaemoRemoteMounter::addMountSpecification(const MaemoMountSpecification &mo
     return true;
 }
 
+bool MaemoRemoteMounter::hasValidMountSpecifications() const
+{
+    return !m_mountSpecs.isEmpty();
+}
+
 void MaemoRemoteMounter::mount()
 {
     ASSERT_STATE(Inactive);
     Q_ASSERT(m_utfsServers.isEmpty());
     Q_ASSERT(m_connection);
 
-    if (!m_toolChain->allowsRemoteMounts())
-        m_mountSpecs.clear();
     if (m_mountSpecs.isEmpty()) {
         setState(Inactive);
         emit reportProgress(tr("No directories to mount"));
@@ -114,7 +118,6 @@ void MaemoRemoteMounter::unmount()
                 m_mountSpecs.at(i).mountSpec.remoteMountPoint);
     }
 
-    emit reportProgress(tr("Unmounting remote mount points..."));
     m_umountStderr.clear();
     m_unmountProcess = m_connection->createRemoteProcess(remoteCall.toUtf8());
     connect(m_unmountProcess.data(), SIGNAL(closed(int)), this,
@@ -458,6 +461,8 @@ void MaemoRemoteMounter::setState(State newState)
     m_state = newState;
 }
 
+// TODO: Perhaps remove this one again, since it might interfere with
+// an unrelated application
 void MaemoRemoteMounter::killUtfsClients()
 {
     const SshRemoteProcess::Ptr utfsClientKiller
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.h b/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.h
index 9445d3d050d..8e297be80df 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.h
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemoremotemounter.h
@@ -63,6 +63,7 @@ public:
     void setPortList(const MaemoPortList &portList) { m_portList = portList; }
     bool addMountSpecification(const MaemoMountSpecification &mountSpec,
         bool mountAsRoot);
+    bool hasValidMountSpecifications() const;
     void resetMountSpecifications() { m_mountSpecs.clear(); }
     void mount();
     void unmount();
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.cpp
index 75d2bc716eb..bc7989abd3d 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.cpp
@@ -168,7 +168,7 @@ void MaemoSshRunner::handleCleanupFinished(int exitStatus)
         << StopRequested);
 
     if (m_state == StopRequested || m_state == PostRunCleaning) {
-        m_mounter->unmount();
+        unmount();
         return;
     }
 
@@ -177,7 +177,7 @@ void MaemoSshRunner::handleCleanupFinished(int exitStatus)
             .arg(m_cleaner->errorString()));
     } else {
         m_mounter->setConnection(m_connection);
-        m_mounter->unmount();
+        unmount();
     }
 }
 
@@ -211,12 +211,11 @@ void MaemoSshRunner::handleUnmounted()
                 return;
         }
         setState(PreMountUnmounting);
-        m_mounter->unmount();
+        unmount();
         break;
     }
     case PreMountUnmounting:
-        setState(Mounting);
-        m_mounter->mount();
+        mount();
         break;
     case PostRunCleaning:
     case StopRequested:
@@ -333,8 +332,46 @@ void MaemoSshRunner::setState(State newState)
 
 void MaemoSshRunner::emitError(const QString &errorMsg)
 {
-    emit error(errorMsg);
-    setState(Inactive);
+    if (m_state != Inactive) {
+        emit error(errorMsg);
+        setState(Inactive);
+    }
+}
+
+void MaemoSshRunner::mount()
+{
+    setState(Mounting);
+    if (m_mounter->hasValidMountSpecifications()) {
+        emit reportProgress(tr("Mounting host directories..."));
+        m_mounter->mount();
+    } else {
+        handleMounted();
+    }
+}
+
+void MaemoSshRunner::unmount()
+{
+    ASSERT_STATE(QList<State>() << PreRunCleaning << PreMountUnmounting
+        << PostRunCleaning << StopRequested);
+    if (m_mounter->hasValidMountSpecifications()) {
+        QString message;
+        switch (m_state) {
+        case PreRunCleaning:
+            message = tr("Unmounting left-over host directory mounts...");
+            break;
+        case PreMountUnmounting:
+            message = tr("Potentially unmounting left-over host directory mounts...");
+        case StopRequested: case PostRunCleaning:
+            message = tr("Unmounting host directories...");
+            break;
+        default:
+            break;
+        }
+        emit reportProgress(message);
+        m_mounter->unmount();
+    } else {
+        handleUnmounted();
+    }
 }
 
 
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.h b/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.h
index 74a36453a45..2c756a2382b 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.h
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.h
@@ -102,6 +102,8 @@ private:
     void cleanup();
     bool addMountSpecification(const MaemoMountSpecification &mountSpec);
     bool isConnectionUsable() const;
+    void mount();
+    void unmount();
 
     MaemoRunConfiguration * const m_runConfig; // TODO this pointer can be invalid
     MaemoRemoteMounter * const m_mounter;
-- 
GitLab