OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qt-maemo / maemoruncontrol.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the Qt Creator.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 ** $QT_END_LICENSE$
32 **
33 ****************************************************************************/
34
35 #include "maemoruncontrol.h"
36
37 #include "maemodeploystep.h"
38 #include "maemoglobal.h"
39 #include "maemorunconfiguration.h"
40 #include "maemosshrunner.h"
41
42 #include <projectexplorer/projectexplorerconstants.h>
43 #include <utils/qtcassert.h>
44
45 #include <QtGui/QMessageBox>
46
47 using namespace Core;
48 using namespace ProjectExplorer;
49
50 namespace Qt4ProjectManager {
51 namespace Internal {
52
53 using ProjectExplorer::RunConfiguration;
54
55 MaemoRunControl::MaemoRunControl(RunConfiguration *rc)
56     : RunControl(rc, ProjectExplorer::Constants::RUNMODE)
57     , m_runner(new MaemoSshRunner(this, qobject_cast<MaemoRunConfiguration *>(rc), false))
58     , m_running(false)
59 {
60 }
61
62 MaemoRunControl::~MaemoRunControl()
63 {
64     stop();
65 }
66
67 void MaemoRunControl::start()
68 {
69     m_running = true;
70     emit started();
71     disconnect(m_runner, 0, this, 0);
72     connect(m_runner, SIGNAL(error(QString)), SLOT(handleSshError(QString)));
73     connect(m_runner, SIGNAL(readyForExecution()), SLOT(startExecution()));
74     connect(m_runner, SIGNAL(remoteErrorOutput(QByteArray)),
75         SLOT(handleRemoteErrorOutput(QByteArray)));
76     connect(m_runner, SIGNAL(remoteOutput(QByteArray)),
77         SLOT(handleRemoteOutput(QByteArray)));
78     connect(m_runner, SIGNAL(remoteProcessStarted()),
79         SLOT(handleRemoteProcessStarted()));
80     connect(m_runner, SIGNAL(remoteProcessFinished(qint64)),
81         SLOT(handleRemoteProcessFinished(qint64)));
82     connect(m_runner, SIGNAL(reportProgress(QString)),
83         SLOT(handleProgressReport(QString)));
84     connect(m_runner, SIGNAL(mountDebugOutput(QString)),
85         SLOT(handleMountDebugOutput(QString)));
86     m_runner->start();
87 }
88
89 RunControl::StopResult MaemoRunControl::stop()
90 {
91     m_runner->stop();
92     return StoppedSynchronously;
93 }
94
95 void MaemoRunControl::handleSshError(const QString &error)
96 {
97     handleError(error);
98     setFinished();
99 }
100
101 void MaemoRunControl::startExecution()
102 {
103     appendMessage(tr("Starting remote process ..."), NormalMessageFormat);
104     m_runner->startExecution(QString::fromLocal8Bit("%1 %2 %3 %4")
105         .arg(MaemoGlobal::remoteCommandPrefix(m_runner->remoteExecutable()))
106         .arg(MaemoGlobal::remoteEnvironment(m_runner->userEnvChanges()))
107         .arg(m_runner->remoteExecutable())
108         .arg(m_runner->arguments()).toUtf8());
109 }
110
111 void MaemoRunControl::handleRemoteProcessFinished(qint64 exitCode)
112 {
113     if (exitCode != MaemoSshRunner::InvalidExitCode) {
114         appendMessage(tr("Finished running remote process. Exit code was %1.")
115             .arg(exitCode), NormalMessageFormat);
116     }
117     setFinished();
118 }
119
120 void MaemoRunControl::handleRemoteOutput(const QByteArray &output)
121 {
122     appendMessage(QString::fromUtf8(output), StdOutFormatSameLine);
123 }
124
125 void MaemoRunControl::handleRemoteErrorOutput(const QByteArray &output)
126 {
127     appendMessage(QString::fromUtf8(output), StdErrFormatSameLine);
128 }
129
130 void MaemoRunControl::handleProgressReport(const QString &progressString)
131 {
132     appendMessage(progressString, NormalMessageFormat);
133 }
134
135 void MaemoRunControl::handleMountDebugOutput(const QString &output)
136 {
137     appendMessage(output, StdErrFormatSameLine);
138 }
139
140 bool MaemoRunControl::isRunning() const
141 {
142     return m_running;
143 }
144
145 void MaemoRunControl::handleError(const QString &errString)
146 {
147     stop();
148     appendMessage(errString, ErrorMessageFormat);
149     QMessageBox::critical(0, tr("Remote Execution Failure"), errString);
150 }
151
152 void MaemoRunControl::setFinished()
153 {
154     disconnect(m_runner, 0, this, 0);
155     m_running = false;
156     emit finished();
157 }
158
159 } // namespace Internal
160 } // namespace Qt4ProjectManager