OSDN Git Service

9910380c070189e02709f902b5d1845862f33be1
[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->devConfig()->osVersion(),
106             m_runner->remoteExecutable()))
107         .arg(MaemoGlobal::remoteEnvironment(m_runner->userEnvChanges()))
108         .arg(m_runner->remoteExecutable())
109         .arg(m_runner->arguments()).toUtf8());
110 }
111
112 void MaemoRunControl::handleRemoteProcessFinished(qint64 exitCode)
113 {
114     if (exitCode != MaemoSshRunner::InvalidExitCode) {
115         appendMessage(tr("Finished running remote process. Exit code was %1.")
116             .arg(exitCode), NormalMessageFormat);
117     }
118     setFinished();
119 }
120
121 void MaemoRunControl::handleRemoteOutput(const QByteArray &output)
122 {
123     appendMessage(QString::fromUtf8(output), StdOutFormatSameLine);
124 }
125
126 void MaemoRunControl::handleRemoteErrorOutput(const QByteArray &output)
127 {
128     appendMessage(QString::fromUtf8(output), StdErrFormatSameLine);
129 }
130
131 void MaemoRunControl::handleProgressReport(const QString &progressString)
132 {
133     appendMessage(progressString, NormalMessageFormat);
134 }
135
136 void MaemoRunControl::handleMountDebugOutput(const QString &output)
137 {
138     appendMessage(output, StdErrFormatSameLine);
139 }
140
141 bool MaemoRunControl::isRunning() const
142 {
143     return m_running;
144 }
145
146 void MaemoRunControl::handleError(const QString &errString)
147 {
148     stop();
149     appendMessage(errString, ErrorMessageFormat);
150     QMessageBox::critical(0, tr("Remote Execution Failure"), errString);
151 }
152
153 void MaemoRunControl::setFinished()
154 {
155     disconnect(m_runner, 0, this, 0);
156     m_running = false;
157     emit finished();
158 }
159
160 } // namespace Internal
161 } // namespace Qt4ProjectManager