From dd6966b2f03c87ce566f3e6fb85c525514c0e01a Mon Sep 17 00:00:00 2001
From: ck <qt-info@nokia.com>
Date: Mon, 2 Aug 2010 12:49:25 +0200
Subject: [PATCH] Maemo: Do the bind() for remote mounts on the device.

This makes us more independent of the developer PC's firewall setting.

Reviewed-by: kh1
---
 .../qt-maemo/maemoconstants.h                 |  1 -
 .../qt-maemo/maemodebugsupport.cpp            |  2 +-
 .../qt-maemo/maemodeviceconfigurations.cpp    | 10 +--
 .../qt-maemo/maemodeviceconfigurations.h      |  4 +-
 .../qt-maemo/maemoremotemountsmodel.cpp       | 16 ++---
 .../qt-maemo/maemoremotemountsmodel.h         |  2 +-
 .../qt-maemo/maemorunconfiguration.cpp        |  7 +-
 .../qt-maemo/maemorunconfiguration.h          |  3 -
 .../qt-maemo/maemorunconfigurationwidget.cpp  | 22 ------
 .../qt-maemo/maemorunconfigurationwidget.h    |  3 -
 .../qt-maemo/maemosettingswidget.cpp          |  6 +-
 .../qt-maemo/maemosettingswidget.ui           |  4 +-
 .../qt-maemo/maemosshrunner.cpp               | 70 ++++++++++++-------
 .../qt-maemo/maemosshrunner.h                 |  6 +-
 14 files changed, 70 insertions(+), 86 deletions(-)

diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoconstants.h b/src/plugins/qt4projectmanager/qt-maemo/maemoconstants.h
index 41ac1cb5074..2f27e408377 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemoconstants.h
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemoconstants.h
@@ -72,7 +72,6 @@ static const QLatin1String MountPortsKey(PREFIX ".MountPorts");
 static const QLatin1String BaseEnvironmentBaseKey(PREFIX ".BaseEnvironmentBase");
 static const QLatin1String UserEnvironmentChangesKey(PREFIX ".UserEnvironmentChanges");
 static const QLatin1String UseRemoteGdbKey(PREFIX ".UseRemoteGdb");
-static const QLatin1String GdbMountPortKey(PREFIX ".GdbMountPort");
 
 } // namespace Internal
 } // namespace Qt4ProjectManager
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemodebugsupport.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemodebugsupport.cpp
index 037246199bf..4a759e4d544 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemodebugsupport.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemodebugsupport.cpp
@@ -292,7 +292,7 @@ QString MaemoDebugSupport::gdbServerPort(const MaemoRunConfiguration *rc,
     // something in the config dialog, but we will make sure we use
     // the right port from the information file.
     return devConf.type == MaemoDeviceConfig::Physical
-        ? QString::number(devConf.gdbServerPort)
+        ? QString::number(devConf.debuggingPort)
         : rc->runtimeGdbServerPort();
 }
 
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.cpp
index 1403ff040e0..ed104d6db37 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.cpp
@@ -56,7 +56,7 @@ namespace {
     const QLatin1String TypeKey("Type");
     const QLatin1String HostKey("Host");
     const QLatin1String SshPortKey("SshPort");
-    const QLatin1String GdbServerPortKey("GdbServerPort");
+    const QLatin1String DebuggingPortKey("GdbServerPort");
     const QLatin1String UserNameKey("Uname");
     const QLatin1String AuthKey("Authentication");
     const QLatin1String KeyFileKey("KeyFile");
@@ -94,7 +94,7 @@ private:
 MaemoDeviceConfig::MaemoDeviceConfig(const QString &name, MaemoDeviceConfig::DeviceType devType)
     : name(name),
       type(devType),
-      gdbServerPort(defaultGdbServerPort(type)),
+      debuggingPort(defaultDebuggingPort(type)),
       internalId(MaemoDeviceConfigurations::instance().m_nextId++)
 {
     server.host = defaultHost(type);
@@ -109,7 +109,7 @@ MaemoDeviceConfig::MaemoDeviceConfig(const QSettings &settings,
                                      quint64 &nextId)
     : name(settings.value(NameKey).toString()),
       type(static_cast<DeviceType>(settings.value(TypeKey, DefaultDeviceType).toInt())),
-      gdbServerPort(settings.value(GdbServerPortKey, defaultGdbServerPort(type)).toInt()),
+      debuggingPort(settings.value(DebuggingPortKey, defaultDebuggingPort(type)).toInt()),
       internalId(settings.value(InternalIdKey, nextId).toULongLong())
 {
     if (internalId == nextId)
@@ -136,7 +136,7 @@ int MaemoDeviceConfig::defaultSshPort(DeviceType type) const
     return type == Physical ? DefaultSshPortHW : DefaultSshPortSim;
 }
 
-int MaemoDeviceConfig::defaultGdbServerPort(DeviceType type) const
+int MaemoDeviceConfig::defaultDebuggingPort(DeviceType type) const
 {
     return type == Physical ? DefaultGdbServerPortHW : DefaultGdbServerPortSim;
 }
@@ -157,7 +157,7 @@ void MaemoDeviceConfig::save(QSettings &settings) const
     settings.setValue(TypeKey, type);
     settings.setValue(HostKey, server.host);
     settings.setValue(SshPortKey, server.port);
-    settings.setValue(GdbServerPortKey, gdbServerPort);
+    settings.setValue(DebuggingPortKey, debuggingPort);
     settings.setValue(UserNameKey, server.uname);
     settings.setValue(AuthKey, server.authType);
     settings.setValue(PasswordKey, server.pwd);
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.h b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.h
index 68d5e9a78f0..6c55433edc9 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.h
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.h
@@ -63,12 +63,12 @@ public:
     Core::SshConnectionParameters server;
     QString name;
     DeviceType type;
-    int gdbServerPort;
+    int debuggingPort;
     quint64 internalId;
 
 private:
     int defaultSshPort(DeviceType type) const;
-    int defaultGdbServerPort(DeviceType type) const;
+    int defaultDebuggingPort(DeviceType type) const;
     QString defaultHost(DeviceType type) const;
 
 };
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoremotemountsmodel.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemoremotemountsmodel.cpp
index 0fa6ce9f03e..4016ed0abdd 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemoremotemountsmodel.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemoremotemountsmodel.cpp
@@ -39,7 +39,7 @@ const QLatin1String InvalidMountPoint("/");
 } // anonymous namespace
 
 MaemoRemoteMountsModel::MountSpecification::MountSpecification(const QString &l,
-    const QString &r, int p) : localDir(l), remoteMountPoint(r), port(p) {}
+    const QString &r, int p) : localDir(l), remoteMountPoint(r), remotePort(p) {}
 
 bool MaemoRemoteMountsModel::MountSpecification::isValid() const
 {
@@ -54,10 +54,10 @@ MaemoRemoteMountsModel::MaemoRemoteMountsModel(QObject *parent) :
 
 void MaemoRemoteMountsModel::addMountSpecification(const QString &localDir)
 {
-    int port = 10000;
+    int port = 10100;
     int i = 0;
     while (i < rowCount()) {
-        if (mountSpecificationAt(i).port == port) {
+        if (mountSpecificationAt(i).remotePort == port) {
             ++port;
             i = 0;
         } else {
@@ -114,7 +114,7 @@ QVariantMap MaemoRemoteMountsModel::toMap() const
     foreach (const MountSpecification &mountSpec, m_mountSpecs) {
         localDirsList << mountSpec.localDir;
         remoteMountPointsList << mountSpec.remoteMountPoint;
-        mountPortsList << mountSpec.port;
+        mountPortsList << mountSpec.remotePort;
     }
     map.insert(ExportedLocalDirsKey, localDirsList);
     map.insert(RemoteMountPointsKey, remoteMountPointsList);
@@ -157,7 +157,7 @@ QVariant MaemoRemoteMountsModel::headerData(int section,
     switch (section) {
     case LocalDirRow: return tr("Local directory");
     case RemoteMountPointRow: return tr("Remote mount point");
-    case PortRow: return tr("Local port");
+    case PortRow: return tr("Remote port");
     default: return QVariant();
     }
 }
@@ -179,7 +179,7 @@ QVariant MaemoRemoteMountsModel::data(const QModelIndex &index, int role) const
         break;
     case PortRow:
         if (role == Qt::DisplayRole || role == Qt::EditRole)
-            return mountSpec.port;
+            return mountSpec.remotePort;
         break;
     }
     return QVariant();
@@ -208,10 +208,10 @@ bool MaemoRemoteMountsModel::setData(const QModelIndex &index,
     case PortRow: {
         const int newPort = value.toInt();
         for (int i = 0; i < m_mountSpecs.count(); ++i) {
-            if (i != index.row() && m_mountSpecs.at(i).port == newPort)
+            if (i != index.row() && m_mountSpecs.at(i).remotePort == newPort)
                 return false;
         }
-        m_mountSpecs[index.row()].port = newPort;
+        m_mountSpecs[index.row()].remotePort = newPort;
         set = true;
         break;
     }
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoremotemountsmodel.h b/src/plugins/qt4projectmanager/qt-maemo/maemoremotemountsmodel.h
index 05fe1b9a857..eb64227e152 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemoremotemountsmodel.h
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemoremotemountsmodel.h
@@ -48,7 +48,7 @@ public:
 
         QString localDir;
         QString remoteMountPoint;
-        int port;
+        int remotePort;
     };
 
     explicit MaemoRemoteMountsModel(QObject *parent = 0);
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.cpp
index ddcafa3c9af..47779f618fd 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.cpp
@@ -56,8 +56,7 @@ namespace Qt4ProjectManager {
 namespace Internal {
 
 namespace {
-const bool DefaultUseRemoteGdbValue = false;  // TODO: Make true once utfs-server works on Windows.
-const int DefaultGdbMountPort = 10100;
+const bool DefaultUseRemoteGdbValue = false;  // TODO: Make true once it works reliably on Windows
 } // anonymous namespace
 
 using namespace ProjectExplorer;
@@ -67,7 +66,6 @@ MaemoRunConfiguration::MaemoRunConfiguration(Qt4Target *parent,
     : RunConfiguration(parent, QLatin1String(MAEMO_RC_ID))
     , m_proFilePath(proFilePath)
     , m_useRemoteGdb(DefaultUseRemoteGdbValue)
-    , m_gdbMountPort(DefaultGdbMountPort)
     , m_baseEnvironmentBase(SystemEnvironmentBase)
 {
     init();
@@ -80,7 +78,6 @@ MaemoRunConfiguration::MaemoRunConfiguration(Qt4Target *parent,
     , m_gdbPath(source->m_gdbPath)
     , m_arguments(source->m_arguments)
     , m_useRemoteGdb(source->useRemoteGdb())
-    , m_gdbMountPort(source->gdbMountPort())
     , m_baseEnvironmentBase(source->m_baseEnvironmentBase)
     , m_systemEnvironment(source->m_systemEnvironment)
     , m_userEnvironmentChanges(source->m_userEnvironmentChanges)
@@ -150,7 +147,6 @@ QVariantMap MaemoRunConfiguration::toMap() const
     const QDir dir = QDir(target()->project()->projectDirectory());
     map.insert(ProFileKey, dir.relativeFilePath(m_proFilePath));
     map.insert(UseRemoteGdbKey, useRemoteGdb());
-    map.insert(GdbMountPortKey, gdbMountPort());
     map.insert(BaseEnvironmentBaseKey, m_baseEnvironmentBase);
     map.insert(UserEnvironmentChangesKey,
         ProjectExplorer::EnvironmentItem::toStringList(m_userEnvironmentChanges));
@@ -168,7 +164,6 @@ bool MaemoRunConfiguration::fromMap(const QVariantMap &map)
     const QDir dir = QDir(target()->project()->projectDirectory());
     m_proFilePath = dir.filePath(map.value(ProFileKey).toString());
     m_useRemoteGdb = map.value(UseRemoteGdbKey, DefaultUseRemoteGdbValue).toBool();
-    m_gdbMountPort = map.value(GdbMountPortKey, DefaultGdbMountPort).toInt();
     m_userEnvironmentChanges =
         ProjectExplorer::EnvironmentItem::fromStringList(map.value(UserEnvironmentChangesKey)
         .toStringList());
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.h b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.h
index c5c54bf4153..138965e7475 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.h
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.h
@@ -96,8 +96,6 @@ public:
     QString runtimeGdbServerPort() const;
     bool useRemoteGdb() const { return m_useRemoteGdb; }
     void setUseRemoteGdb(bool useRemoteGdb) { m_useRemoteGdb = useRemoteGdb; }
-    int gdbMountPort() const { return m_gdbMountPort; }
-    void setGdbMountPort(int port) { m_gdbMountPort = port; }
 
     const QString gdbCmd() const;
     const QString dumperLib() const;
@@ -144,7 +142,6 @@ private:
     MaemoRemoteMountsModel *m_remoteMounts;
     QStringList m_arguments;
     bool m_useRemoteGdb;
-    int m_gdbMountPort;
 
     BaseEnvironmentBase m_baseEnvironmentBase;
     ProjectExplorer::Environment m_systemEnvironment;
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfigurationwidget.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfigurationwidget.cpp
index 7de590eae1c..2a632bfc417 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfigurationwidget.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfigurationwidget.cpp
@@ -56,7 +56,6 @@
 #include <QtGui/QLineEdit>
 #include <QtGui/QPushButton>
 #include <QtGui/QRadioButton>
-#include <QtGui/QSpinBox>
 #include <QtGui/QTableView>
 #include <QtGui/QToolButton>
 
@@ -132,9 +131,7 @@ void MaemoRunConfigurationWidget::addDebuggingWidgets(QVBoxLayout *mainLayout)
     m_debugDetailsContainer = new Utils::DetailsWidget(this);
     QWidget *debugWidget = new QWidget;
     m_debugDetailsContainer->setWidget(debugWidget);
-#ifndef Q_OS_WIN
     mainLayout->addWidget(m_debugDetailsContainer);
-#endif
     QFormLayout *debugLayout = new QFormLayout(debugWidget);
     QHBoxLayout *debugRadioButtonsLayout = new QHBoxLayout;
     debugLayout->addRow(debugRadioButtonsLayout);
@@ -147,17 +144,6 @@ void MaemoRunConfigurationWidget::addDebuggingWidgets(QVBoxLayout *mainLayout)
     gdbServerButton->setChecked(!gdbButton->isChecked());
     connect(gdbButton, SIGNAL(toggled(bool)), this,
         SLOT(handleDebuggingTypeChanged(bool)));
-    QHBoxLayout *spinBoxLayout = new QHBoxLayout;
-    m_gdbMountPortSpinBox = new QSpinBox;
-    m_gdbMountPortSpinBox->setMinimum(1024);
-    m_gdbMountPortSpinBox->setMaximum((1 << 16) - 1);
-    spinBoxLayout->addWidget(m_gdbMountPortSpinBox);
-    spinBoxLayout->addStretch(1);
-    debugLayout->addRow(tr("Local port for mounting the project directory:"),
-        spinBoxLayout);
-    m_gdbMountPortSpinBox->setValue(m_runConfiguration->gdbMountPort());
-    connect(m_gdbMountPortSpinBox, SIGNAL(valueChanged(int)), this,
-        SLOT(handleGdbMountPortChanged(int)));
     handleDebuggingTypeChanged(gdbButton->isChecked());
 }
 
@@ -167,9 +153,7 @@ void MaemoRunConfigurationWidget::addMountWidgets(QVBoxLayout *mainLayout)
     m_mountDetailsContainer = new Utils::DetailsWidget(this);
     QWidget *mountViewWidget = new QWidget;
     m_mountDetailsContainer->setWidget(mountViewWidget);
-#ifndef Q_OS_WIN
     mainLayout->addWidget(m_mountDetailsContainer);
-#endif
     QVBoxLayout *mountViewLayout = new QVBoxLayout(mountViewWidget);
     QHBoxLayout *tableLayout = new QHBoxLayout;
     mountViewLayout->addLayout(tableLayout);
@@ -339,12 +323,6 @@ void MaemoRunConfigurationWidget::handleDebuggingTypeChanged(bool useGdb)
     const QString detailsText = useGdb ? tr("Use gdb") : tr("Use gdbserver");
     m_debugDetailsContainer->setSummaryText(tr("<b>Debugging details:</b> ")
         + detailsText);
-    m_gdbMountPortSpinBox->setEnabled(useGdb);
-}
-
-void MaemoRunConfigurationWidget::handleGdbMountPortChanged(int port)
-{
-    m_runConfiguration->setGdbMountPort(port);
 }
 
 void MaemoRunConfigurationWidget::fetchEnvironment()
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfigurationwidget.h b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfigurationwidget.h
index 0c48cbfae28..8026cb2084e 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfigurationwidget.h
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfigurationwidget.h
@@ -43,7 +43,6 @@ class QLabel;
 class QLineEdit;
 class QModelIndex;
 class QPushButton;
-class QSpinBox;
 class QTableView;
 class QToolButton;
 class QVBoxLayout;
@@ -81,7 +80,6 @@ private slots:
     void changeLocalMountDir(const QModelIndex &index);
     void enableOrDisableRemoveMountSpecButton();
     void handleDebuggingTypeChanged(bool useGdb);
-    void handleGdbMountPortChanged(int port);
     void fetchEnvironment();
     void fetchEnvironmentFinished();
     void userChangesEdited();
@@ -101,7 +99,6 @@ private:
     QLineEdit *m_argsLineEdit;
     QLabel *m_executableLabel;
     QComboBox *m_devConfBox;
-    QSpinBox *m_gdbMountPortSpinBox;
     QTableView *m_mountView;
     QToolButton *m_removeMountButton;
     Utils::DetailsWidget *m_mountDetailsContainer;
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.cpp
index 2a6bc7de465..5e7c403996c 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.cpp
@@ -114,7 +114,7 @@ QString MaemoSettingsWidget::searchKeywords() const
 {
     QString rc;
     QTextStream(&rc) << m_ui->configurationLabel->text()
-        << ' ' << m_ui->gdbServerLabel->text()
+        << ' ' << m_ui->debuggingPortLabel->text()
         << ' ' << m_ui->sshPortLabel->text()
         << ' ' << m_ui->keyButton->text()
         << ' ' << m_ui->passwordButton->text()
@@ -213,7 +213,7 @@ void MaemoSettingsWidget::fillInValues()
     m_ui->nameLineEdit->setText(currentConfig().name);
     m_ui->hostLineEdit->setText(currentConfig().server.host);
     m_ui->sshPortSpinBox->setValue(currentConfig().server.port);
-    m_ui->gdbServerPortSpinBox->setValue(currentConfig().gdbServerPort);
+    m_ui->gdbServerPortSpinBox->setValue(currentConfig().debuggingPort);
     m_ui->timeoutSpinBox->setValue(currentConfig().server.timeout);
     m_ui->userLineEdit->setText(currentConfig().server.uname);
     m_ui->pwdLineEdit->setText(currentConfig().server.pwd);
@@ -295,7 +295,7 @@ void MaemoSettingsWidget::sshPortEditingFinished()
 
 void MaemoSettingsWidget::gdbServerPortEditingFinished()
 {
-    currentConfig().gdbServerPort = m_ui->gdbServerPortSpinBox->value();
+    currentConfig().debuggingPort = m_ui->gdbServerPortSpinBox->value();
 }
 
 void MaemoSettingsWidget::timeoutEditingFinished()
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.ui b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.ui
index cf1969f9f91..3b6ab984da1 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.ui
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.ui
@@ -184,7 +184,7 @@
               </widget>
              </item>
              <item>
-              <widget class="QLabel" name="gdbServerLabel">
+              <widget class="QLabel" name="debuggingPortLabel">
                <property name="sizePolicy">
                 <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
                  <horstretch>0</horstretch>
@@ -192,7 +192,7 @@
                 </sizepolicy>
                </property>
                <property name="text">
-                <string>Gdb server:</string>
+                <string>Debugging:</string>
                </property>
               </widget>
              </item>
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.cpp
index 4b8117480ff..935ff4595c0 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.cpp
@@ -87,7 +87,7 @@ void MaemoSshRunner::start()
         m_mountSpecs << MaemoRemoteMountsModel::MountSpecification(
             m_runConfig->localDirToMountForRemoteGdb(),
             MaemoGlobal::remoteProjectSourcesMountPoint(),
-            m_runConfig->gdbMountPort());
+            m_devConfig.debuggingPort);
     }
 
     m_stop = false;
@@ -252,10 +252,10 @@ void MaemoSshRunner::handleUploadFinished(Core::SftpJobId jobId,
         return;
     }
 
-    mount();
+    startUtfsClients();
 }
 
-void MaemoSshRunner::mount()
+void MaemoSshRunner::startUtfsClients()
 {
     const QString chmodFuse
         = MaemoGlobal::remoteSudo() + QLatin1String(" chmod a+r+w /dev/fuse");
@@ -266,43 +266,34 @@ void MaemoSshRunner::mount()
     for (int i = 0; i < m_mountSpecs.count(); ++i) {
         const MaemoRemoteMountsModel::MountSpecification &mountSpec
             = m_mountSpecs.at(i);
-        QProcess * const utfsServerProc = new QProcess(this);
-        connect(utfsServerProc, SIGNAL(readyReadStandardError()), this,
-            SLOT(handleUtfsServerErrorOutput()));
-        const QString port = QString::number(mountSpec.port);
-        const QString localSecretOpt = QLatin1String("-l");
-        const QString remoteSecretOpt = QLatin1String("-r");
-        const QStringList utfsServerArgs = QStringList() << localSecretOpt
-            << port << remoteSecretOpt << port << QLatin1String("-b") << port
-            << mountSpec.localDir;
-        utfsServerProc->start(utfsServer(), utfsServerArgs);
-        if (!utfsServerProc->waitForStarted()) {
-            delete utfsServerProc;
-            emit error(tr("Could not start UTFS server: %1")
-                .arg(utfsServerProc->errorString()));
-            return;
-        }
-        m_utfsServers << utfsServerProc;
+        const QString port = QString::number(mountSpec.remotePort);
         const QString mkdir = QString::fromLocal8Bit("%1 mkdir -p %2")
             .arg(MaemoGlobal::remoteSudo(), mountSpec.remoteMountPoint);
         const QString chmod = QString::fromLocal8Bit("%1 chmod a+r+w+x %2")
             .arg(MaemoGlobal::remoteSudo(), mountSpec.remoteMountPoint);
         const QString utfsClient
-            = QString::fromLocal8Bit("%1 -l %2 -r %2 -c `echo $SSH_CLIENT|cut -d ' ' -f 1`:%2 %4")
+            = QString::fromLocal8Bit("%1 -l %2 -r %2 -b %2 %4")
                   .arg(utfsClientOnDevice()).arg(port)
                   .arg(mountSpec.remoteMountPoint);
         remoteCall += andOp + mkdir + andOp + chmod + andOp + utfsClient;
     }
 
     m_mountProcess = m_connection->createRemoteProcess(remoteCall.toUtf8());
+    connect(m_mountProcess.data(), SIGNAL(started()), this,
+        SLOT(handleUtfsClientsStarted()));
     connect(m_mountProcess.data(), SIGNAL(closed(int)), this,
-        SLOT(handleMountProcessFinished(int)));
+        SLOT(handleUtfsClientsFinished(int)));
     connect(m_mountProcess.data(), SIGNAL(errorOutputAvailable(QByteArray)),
         this, SIGNAL(remoteErrorOutput(QByteArray)));
     m_mountProcess->start();
 }
 
-void MaemoSshRunner::handleMountProcessFinished(int exitStatus)
+void MaemoSshRunner::handleUtfsClientsStarted()
+{
+    startUtfsServers();
+}
+
+void MaemoSshRunner::handleUtfsClientsFinished(int exitStatus)
 {
     if (m_stop)
         return;
@@ -316,11 +307,8 @@ void MaemoSshRunner::handleMountProcessFinished(int exitStatus)
             .arg(m_mountProcess->errorString()));
         break;
     case SshRemoteProcess::ExitedNormally:
-        if (m_mountProcess->exitCode() == 0) {
-            emit readyForExecution();
-        } else {
+        if (m_mountProcess->exitCode() != 0)
             emit error(tr("Could not execute mount request."));
-        }
         break;
     default:
         Q_ASSERT_X(false, Q_FUNC_INFO,
@@ -328,6 +316,34 @@ void MaemoSshRunner::handleMountProcessFinished(int exitStatus)
     }
 }
 
+void MaemoSshRunner::startUtfsServers()
+{
+    for (int i = 0; i < m_mountSpecs.count(); ++i) {
+        const MaemoRemoteMountsModel::MountSpecification &mountSpec
+            = m_mountSpecs.at(i);
+        QProcess * const utfsServerProc = new QProcess(this);
+        connect(utfsServerProc, SIGNAL(readyReadStandardError()), this,
+            SLOT(handleUtfsServerErrorOutput()));
+        const QString port = QString::number(mountSpec.remotePort);
+        const QString localSecretOpt = QLatin1String("-l");
+        const QString remoteSecretOpt = QLatin1String("-r");
+        const QStringList utfsServerArgs = QStringList() << localSecretOpt
+            << port << remoteSecretOpt << port << QLatin1String("-c")
+            << (m_devConfig.server.host + QLatin1Char(':') + port)
+            << mountSpec.localDir;
+        utfsServerProc->start(utfsServer(), utfsServerArgs);
+        if (!utfsServerProc->waitForStarted()) {
+            delete utfsServerProc;
+            emit error(tr("Could not start UTFS server: %1")
+                .arg(utfsServerProc->errorString()));
+            return;
+        }
+        m_utfsServers << utfsServerProc;
+    }
+
+    emit readyForExecution();
+}
+
 void MaemoSshRunner::startExecution(const QByteArray &remoteCall)
 {
     if (m_runConfig->remoteExecutableFilePath().isEmpty()) {
diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.h b/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.h
index 4fd7a6295d6..29c520979d7 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.h
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemosshrunner.h
@@ -90,13 +90,15 @@ private slots:
     void handleUploaderInitialized();
     void handleUploaderInitializationFailed(const QString &reason);
     void handleUploadFinished(Core::SftpJobId jobId, const QString &error);
-    void handleMountProcessFinished(int exitStatus);
+    void handleUtfsClientsStarted();
+    void handleUtfsClientsFinished(int exitStatus);
     void handleUtfsServerErrorOutput();
 
 private:
     void cleanup(bool initialCleanup);
     void deployUtfsClient();
-    void mount();
+    void startUtfsClients();
+    void startUtfsServers();
     QString utfsClientOnDevice() const;
     QString utfsServer() const;
 
-- 
GitLab