maemoruncontrol.cpp 4.92 KB
Newer Older
1 2
/****************************************************************************
**
con's avatar
con committed
3
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Creator.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "maemoruncontrol.h"
36

37
#include "maemoglobal.h"
38
#include "maemorunconfiguration.h"
39
#include "maemosshrunner.h"
40

41
#include <projectexplorer/projectexplorerconstants.h>
42 43
#include <utils/qtcassert.h>

ck's avatar
ck committed
44 45
#include <QtGui/QMessageBox>

46
using namespace ProjectExplorer;
ck's avatar
ck committed
47

48 49 50
namespace Qt4ProjectManager {
namespace Internal {

51
using ProjectExplorer::RunConfiguration;
ck's avatar
ck committed
52

ck's avatar
ck committed
53 54
MaemoRunControl::MaemoRunControl(RunConfiguration *rc)
    : RunControl(rc, ProjectExplorer::Constants::RUNMODE)
55
    , m_runner(new MaemoSshRunner(this, qobject_cast<MaemoRunConfiguration *>(rc), false))
56
    , m_running(false)
57 58 59
{
}

ck's avatar
ck committed
60
MaemoRunControl::~MaemoRunControl()
61
{
ck's avatar
ck committed
62
    stop();
63 64
}

ck's avatar
ck committed
65
void MaemoRunControl::start()
66
{
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
    m_running = true;
    emit started();
    disconnect(m_runner, 0, this, 0);
    connect(m_runner, SIGNAL(error(QString)), SLOT(handleSshError(QString)));
    connect(m_runner, SIGNAL(readyForExecution()), SLOT(startExecution()));
    connect(m_runner, SIGNAL(remoteErrorOutput(QByteArray)),
        SLOT(handleRemoteErrorOutput(QByteArray)));
    connect(m_runner, SIGNAL(remoteOutput(QByteArray)),
        SLOT(handleRemoteOutput(QByteArray)));
    connect(m_runner, SIGNAL(remoteProcessStarted()),
        SLOT(handleRemoteProcessStarted()));
    connect(m_runner, SIGNAL(remoteProcessFinished(qint64)),
        SLOT(handleRemoteProcessFinished(qint64)));
    connect(m_runner, SIGNAL(reportProgress(QString)),
        SLOT(handleProgressReport(QString)));
    connect(m_runner, SIGNAL(mountDebugOutput(QString)),
        SLOT(handleMountDebugOutput(QString)));
    m_runner->start();
85 86
}

87
RunControl::StopResult MaemoRunControl::stop()
88
{
89
    m_runner->stop();
90
    return StoppedSynchronously;
91 92
}

ck's avatar
ck committed
93
void MaemoRunControl::handleSshError(const QString &error)
94
{
95 96
    handleError(error);
    setFinished();
97 98
}

ck's avatar
ck committed
99
void MaemoRunControl::startExecution()
100
{
101
    appendMessage(tr("Starting remote process ..."), NormalMessageFormat);
102
    m_runner->startExecution(QString::fromLocal8Bit("%1 %2 %3 %4")
103 104 105
        .arg(MaemoGlobal::remoteCommandPrefix(m_runner->remoteExecutable()))
        .arg(MaemoGlobal::remoteEnvironment(m_runner->userEnvChanges()))
        .arg(m_runner->remoteExecutable())
106
        .arg(m_runner->arguments()).toUtf8());
ck's avatar
ck committed
107 108
}

109
void MaemoRunControl::handleRemoteProcessFinished(qint64 exitCode)
ck's avatar
ck committed
110
{
111
    if (exitCode != MaemoSshRunner::InvalidExitCode) {
112
        appendMessage(tr("Finished running remote process. Exit code was %1.")
113
            .arg(exitCode), NormalMessageFormat);
114
    }
115
    setFinished();
ck's avatar
ck committed
116 117
}

ck's avatar
ck committed
118
void MaemoRunControl::handleRemoteOutput(const QByteArray &output)
ck's avatar
ck committed
119
{
120
    appendMessage(QString::fromUtf8(output), StdOutFormatSameLine);
ck's avatar
ck committed
121 122
}

ck's avatar
ck committed
123
void MaemoRunControl::handleRemoteErrorOutput(const QByteArray &output)
ck's avatar
ck committed
124
{
125
    appendMessage(QString::fromUtf8(output), StdErrFormatSameLine);
126 127
}

128 129
void MaemoRunControl::handleProgressReport(const QString &progressString)
{
130
    appendMessage(progressString, NormalMessageFormat);
131 132
}

133 134
void MaemoRunControl::handleMountDebugOutput(const QString &output)
{
135
    appendMessage(output, StdErrFormatSameLine);
136 137
}

ck's avatar
ck committed
138
bool MaemoRunControl::isRunning() const
139
{
140
    return m_running;
141 142
}

143 144 145 146 147
QIcon MaemoRunControl::icon() const
{
    return QIcon(ProjectExplorer::Constants::ICON_RUN_SMALL);
}

ck's avatar
ck committed
148
void MaemoRunControl::handleError(const QString &errString)
ck's avatar
ck committed
149
{
ck's avatar
ck committed
150
    stop();
151
    appendMessage(errString, ErrorMessageFormat);
152
    QMessageBox::critical(0, tr("Remote Execution Failure"), errString);
ck's avatar
ck committed
153 154
}

ck's avatar
ck committed
155
void MaemoRunControl::setFinished()
ck's avatar
ck committed
156
{
157
    disconnect(m_runner, 0, this, 0);
158 159
    m_running = false;
    emit finished();
ck's avatar
ck committed
160 161
}

162
} // namespace Internal
163
} // namespace Qt4ProjectManager