OSDN Git Service

RemoteLinux: Introduce abstract packaging step.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / remotelinux / abstractremotelinuxdeploystep.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at info@qt.nokia.com.
30 **
31 **************************************************************************/
32 #include "abstractremotelinuxdeploystep.h"
33
34 #include "abstractremotelinuxdeployservice.h"
35 #include "maemodeploystepwidget.h"
36 #include "remotelinuxdeployconfiguration.h"
37
38 #include <projectexplorer/projectexplorerconstants.h>
39 #include <qt4projectmanager/qt4buildconfiguration.h>
40
41 using namespace ProjectExplorer;
42
43 namespace RemoteLinux {
44 namespace Internal {
45
46 class AbstractRemoteLinuxDeployStepPrivate
47 {
48 public:
49     bool hasError;
50     QFutureInterface<bool> future;
51 };
52
53 } // namespace Internal
54
55 AbstractRemoteLinuxDeployStep::AbstractRemoteLinuxDeployStep(BuildStepList *bsl, const QString &id)
56     : BuildStep(bsl, id), m_d(new Internal::AbstractRemoteLinuxDeployStepPrivate)
57 {
58 }
59
60 AbstractRemoteLinuxDeployStep::AbstractRemoteLinuxDeployStep(BuildStepList *bsl,
61         AbstractRemoteLinuxDeployStep *other)
62     : BuildStep(bsl, other), m_d(new Internal::AbstractRemoteLinuxDeployStepPrivate)
63 {
64 }
65
66 bool AbstractRemoteLinuxDeployStep::fromMap(const QVariantMap &map)
67 {
68     if (!BuildStep::fromMap(map))
69         return false;
70     deployService()->importDeployTimes(map);
71     return true;
72 }
73
74 QVariantMap AbstractRemoteLinuxDeployStep::toMap() const
75 {
76     return BuildStep::toMap().unite(deployService()->exportDeployTimes());
77 }
78
79 bool AbstractRemoteLinuxDeployStep::init()
80 {
81     return isDeploymentPossible();
82 }
83
84 bool AbstractRemoteLinuxDeployStep::isDeploymentPossible(QString *whyNot) const
85 {
86     deployService()->setDeviceConfiguration(deployConfiguration()->deviceConfiguration());
87     deployService()->setBuildConfiguration(qobject_cast<Qt4ProjectManager::Qt4BuildConfiguration *>(buildConfiguration()));
88     return deployService()->isDeploymentPossible(whyNot);
89 }
90
91 void AbstractRemoteLinuxDeployStep::run(QFutureInterface<bool> &fi)
92 {
93     connect(deployService(), SIGNAL(errorMessage(QString)), SLOT(handleErrorMessage(QString)));
94     connect(deployService(), SIGNAL(progressMessage(QString)), SLOT(handleProgressMessage(QString)));
95     connect(deployService(), SIGNAL(stdOutData(QString)), SLOT(handleStdOutData(QString)));
96     connect(deployService(), SIGNAL(stdErrData(QString)), SLOT(handleStdErrData(QString)));
97     connect(deployService(), SIGNAL(finished()), SLOT(handleFinished()));
98
99     m_d->hasError = false;
100     m_d->future = fi;
101     deployService()->start();
102 }
103
104 void AbstractRemoteLinuxDeployStep::cancel()
105 {
106     if (m_d->hasError)
107         return;
108
109     emit addOutput(tr("User requests deployment to stop; cleaning up."), MessageOutput);
110     m_d->hasError = true;
111     deployService()->stop();
112 }
113
114 BuildStepConfigWidget *AbstractRemoteLinuxDeployStep::createConfigWidget()
115 {
116     return new Internal::MaemoDeployStepBaseWidget(this);
117 }
118
119 RemoteLinuxDeployConfiguration *AbstractRemoteLinuxDeployStep::deployConfiguration() const
120 {
121     return qobject_cast<RemoteLinuxDeployConfiguration *>(BuildStep::deployConfiguration());
122 }
123
124 void AbstractRemoteLinuxDeployStep::handleProgressMessage(const QString &message)
125 {
126     emit addOutput(message, MessageOutput);
127 }
128
129 void AbstractRemoteLinuxDeployStep::handleErrorMessage(const QString &message)
130 {
131     emit addTask(Task(Task::Error, message, QString(), -1,
132         ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
133     m_d->hasError = true;
134 }
135
136 void AbstractRemoteLinuxDeployStep::handleFinished()
137 {
138     if (m_d->hasError)
139         emit addOutput(tr("Deployment failed."), ErrorMessageOutput);
140     else
141         emit addOutput(tr("Deployment finished."), MessageOutput);
142     disconnect(deployService(), 0, this, 0);
143     m_d->future.reportResult(!m_d->hasError);
144     emit finished();
145 }
146
147 void AbstractRemoteLinuxDeployStep::handleStdOutData(const QString &data)
148 {
149     emit addOutput(data, NormalOutput, DontAppendNewline);
150 }
151
152 void AbstractRemoteLinuxDeployStep::handleStdErrData(const QString &data)
153 {
154     emit addOutput(data, ErrorOutput, DontAppendNewline);
155 }
156
157 } // namespace RemoteLinux