OSDN Git Service

Maemo: Fix device environment reader's error reporting.
authorChristian Kandeler <christian.kandeler@nokia.com>
Wed, 13 Oct 2010 09:04:24 +0000 (11:04 +0200)
committerChristian Kandeler <christian.kandeler@nokia.com>
Wed, 13 Oct 2010 09:06:17 +0000 (11:06 +0200)
The error() signal was not connected anywhere.
Also, there was no way to interrupt a failing operation.

Reviewed-by: kh1
src/plugins/qt4projectmanager/qt-maemo/maemodeviceenvreader.cpp
src/plugins/qt4projectmanager/qt-maemo/maemodeviceenvreader.h
src/plugins/qt4projectmanager/qt-maemo/maemorunconfigurationwidget.cpp
src/plugins/qt4projectmanager/qt-maemo/maemorunconfigurationwidget.h

index eab38d7..9275ec8 100644 (file)
@@ -84,8 +84,9 @@ void MaemoDeviceEnvReader::start()
 void MaemoDeviceEnvReader::stop()
 {
     m_stop = true;
-    disconnect(m_connection.data(), 0, this, 0);
 
+    if (m_connection)
+        disconnect(m_connection.data(), 0, this, 0);
     if (m_remoteProcess) {
         disconnect(m_remoteProcess.data());
         m_remoteProcess->closeChannel();
@@ -109,6 +110,7 @@ void MaemoDeviceEnvReader::executeRemoteCall()
         SLOT(remoteErrorOutput(QByteArray)));
 
     m_remoteOutput.clear();
+    m_remoteErrorOutput.clear();
     m_remoteProcess->start();
 }
 
@@ -116,7 +118,7 @@ void MaemoDeviceEnvReader::handleConnectionFailure()
 {
     emit error(tr("Could not connect to host: %1")
         .arg(m_connection->errorString()));
-    emit finished();
+    setFinished();
 }
 
 void MaemoDeviceEnvReader::handleCurrentDeviceConfigChanged()
@@ -124,7 +126,7 @@ void MaemoDeviceEnvReader::handleCurrentDeviceConfigChanged()
     m_devConfig = m_runConfig->deviceConfig();
 
     m_env.clear();
-    emit finished();
+    setFinished();
 }
 
 void MaemoDeviceEnvReader::remoteProcessFinished(int exitCode)
@@ -143,10 +145,15 @@ void MaemoDeviceEnvReader::remoteProcessFinished(int exitCode)
                 QString::SkipEmptyParts));
         }
     } else {
-        emit error(tr("Error running remote process: %1")
-            .arg(m_remoteProcess->errorString()));
+        QString errorMsg = tr("Error running remote process: %1")
+            .arg(m_remoteProcess->errorString());
+        if (!m_remoteErrorOutput.isEmpty()) {
+            errorMsg += tr("\nRemote stderr was: '%1'")
+                .arg(QString::fromUtf8(m_remoteErrorOutput));
+        }
+        emit error(errorMsg);
     }
-    emit finished();
+    setFinished();
 }
 
 void MaemoDeviceEnvReader::remoteOutput(const QByteArray &data)
@@ -156,8 +163,14 @@ void MaemoDeviceEnvReader::remoteOutput(const QByteArray &data)
 
 void MaemoDeviceEnvReader::remoteErrorOutput(const QByteArray &data)
 {
-    emit error(data);
+    m_remoteErrorOutput += data;
+}
+
+void MaemoDeviceEnvReader::setFinished()
+{
+    stop();
+    emit finished();
 }
 
-    }   // Internal
+}   // Internal
 }   // Qt4ProjectManager
index e5ad89e..d31c6b0 100644 (file)
@@ -77,8 +77,11 @@ private slots:
     void remoteErrorOutput(const QByteArray &data);
 
 private:
+    void setFinished();
+
     bool m_stop;
     QString m_remoteOutput;
+    QByteArray m_remoteErrorOutput;
     Utils::Environment m_env;
     MaemoDeviceConfig m_devConfig;
     MaemoRunConfiguration *m_runConfig;
index ddc20d8..7abb2e4 100644 (file)
@@ -51,6 +51,7 @@
 #include <qt4projectmanager/qt4target.h>
 #include <utils/detailswidget.h>
 
+#include <QtCore/QCoreApplication>
 #include <QtGui/QComboBox>
 #include <QtGui/QFileDialog>
 #include <QtGui/QFormLayout>
@@ -59,6 +60,7 @@
 #include <QtGui/QHeaderView>
 #include <QtGui/QLabel>
 #include <QtGui/QLineEdit>
+#include <QtGui/QMessageBox>
 #include <QtGui/QPushButton>
 #include <QtGui/QRadioButton>
 #include <QtGui/QTableView>
 
 namespace Qt4ProjectManager {
 namespace Internal {
+namespace {
+const QString FetchEnvButtonText
+    = QCoreApplication::translate("Qt4ProjectManager::Internal::MaemoRunConfigurationWidget",
+          "Fetch Device Environment");
+} // anonymous namespace
 
 MaemoRunConfigurationWidget::MaemoRunConfigurationWidget(
         MaemoRunConfiguration *runConfiguration, QWidget *parent)
@@ -246,7 +253,7 @@ void MaemoRunConfigurationWidget::addEnvironmentWidgets(QVBoxLayout *mainLayout)
     m_baseEnvironmentComboBox->setCurrentIndex(m_runConfiguration->baseEnvironmentBase());
     baseEnvironmentLayout->addWidget(m_baseEnvironmentComboBox);
 
-    m_fetchEnv = new QPushButton(tr("Fetch Device Environment"));
+    m_fetchEnv = new QPushButton(FetchEnvButtonText);
     baseEnvironmentLayout->addWidget(m_fetchEnv);
     baseEnvironmentLayout->addStretch(10);
 
@@ -267,8 +274,10 @@ void MaemoRunConfigurationWidget::addEnvironmentWidgets(QVBoxLayout *mainLayout)
     connect(m_runConfiguration,
         SIGNAL(userEnvironmentChangesChanged(QList<Utils::EnvironmentItem>)),
         this, SLOT(userEnvironmentChangesChanged(QList<Utils::EnvironmentItem>)));
-    connect(m_fetchEnv, SIGNAL(pressed()), this, SLOT(fetchEnvironment()));
+    connect(m_fetchEnv, SIGNAL(clicked()), this, SLOT(fetchEnvironment()));
     connect(m_deviceEnvReader, SIGNAL(finished()), this, SLOT(fetchEnvironmentFinished()));
+    connect(m_deviceEnvReader, SIGNAL(error(QString)), this,
+        SLOT(fetchEnvironmentError(QString)));
 }
 
 void MaemoRunConfigurationWidget::argumentsEdited(const QString &text)
@@ -387,16 +396,33 @@ void MaemoRunConfigurationWidget::handleDebuggingTypeChanged(bool useGdb)
 
 void MaemoRunConfigurationWidget::fetchEnvironment()
 {
+    disconnect(m_fetchEnv, SIGNAL(clicked()), this, SLOT(fetchEnvironment()));
+    connect(m_fetchEnv, SIGNAL(clicked()), this, SLOT(stopFetchEnvironment()));
+    m_fetchEnv->setText(tr("Cancel Fetch Operation"));
     m_deviceEnvReader->start();
-    m_fetchEnv->setEnabled(false);
+}
+
+void MaemoRunConfigurationWidget::stopFetchEnvironment()
+{
+    m_deviceEnvReader->stop();
+    fetchEnvironmentFinished();
 }
 
 void MaemoRunConfigurationWidget::fetchEnvironmentFinished()
 {
-    m_fetchEnv->setEnabled(true);
+    disconnect(m_fetchEnv, SIGNAL(clicked()), this,
+        SLOT(stopFetchEnvironment()));
+    connect(m_fetchEnv, SIGNAL(clicked()), this, SLOT(fetchEnvironment()));
+    m_fetchEnv->setText(FetchEnvButtonText);
     m_runConfiguration->setSystemEnvironment(m_deviceEnvReader->deviceEnvironment());
 }
 
+void MaemoRunConfigurationWidget::fetchEnvironmentError(const QString &error)
+{
+    QMessageBox::warning(this, tr("Device error"),
+        tr("Fetching environment failed: %1").arg(error));
+}
+
 void MaemoRunConfigurationWidget::userChangesEdited()
 {
     m_ignoreChange = true;
index be686ac..e97c107 100644 (file)
@@ -85,6 +85,8 @@ private slots:
     void handleDebuggingTypeChanged(bool useGdb);
     void fetchEnvironment();
     void fetchEnvironmentFinished();
+    void fetchEnvironmentError(const QString &error);
+    void stopFetchEnvironment();
     void userChangesEdited();
     void baseEnvironmentSelected(int index);
     void baseEnvironmentChanged();