OSDN Git Service

0861cc2cfbac6b28ee83f15f37d32be78b31b7ca
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qt-maemo / maemodeploystep.h
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 (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef MAEMODEPLOYSTEP_H
35 #define MAEMODEPLOYSTEP_H
36
37 #include "maemodeployable.h"
38 #include "maemodeployables.h"
39 #include "maemodeviceconfigurations.h"
40 #include "maemomountspecification.h"
41
42 #include <utils/ssh/sftpdefs.h>
43 #include <projectexplorer/buildstep.h>
44
45 #include <QtCore/QHash>
46 #include <QtCore/QList>
47 #include <QtCore/QMap>
48 #include <QtCore/QPair>
49 #include <QtCore/QSharedPointer>
50
51 QT_BEGIN_NAMESPACE
52 class QEventLoop;
53 class QProcess;
54 class QTimer;
55 QT_END_NAMESPACE
56
57 namespace Utils {
58 class SftpChannel;
59 class SshConnection;
60 class SshRemoteProcess;
61 }
62
63 namespace Qt4ProjectManager {
64 class Qt4BuildConfiguration;
65 namespace Internal {
66 class MaemoRemoteMounter;
67 class MaemoDeviceConfig;
68 class MaemoPackageCreationStep;
69 class MaemoToolChain;
70 class MaemoUsedPortsGatherer;
71
72 class MaemoDeployStep : public ProjectExplorer::BuildStep
73 {
74     Q_OBJECT
75     friend class MaemoDeployStepFactory;
76 public:
77     MaemoDeployStep(ProjectExplorer::BuildStepList *bc);
78
79     virtual ~MaemoDeployStep();
80     QSharedPointer<const MaemoDeviceConfig> deviceConfig() const { return m_deviceConfig; }
81     const AbstractQt4MaemoTarget *maemotarget() const;
82     void setDeviceConfig(int i);
83     bool currentlyNeedsDeployment(const QString &host,
84         const MaemoDeployable &deployable) const;
85     void setDeployed(const QString &host, const MaemoDeployable &deployable);
86     QSharedPointer<MaemoDeployables> deployables() const { return m_deployables; }
87     QSharedPointer<Utils::SshConnection> sshConnection() const { return m_connection; }
88     MaemoPortList freePorts() const;
89
90     bool isDeployToSysrootEnabled() const { return m_deployToSysroot; }
91     void setDeployToSysrootEnabled(bool deploy) { m_deployToSysroot = deploy; }
92
93     Q_INVOKABLE void stop();
94
95 signals:
96     void done();
97     void error();
98     void deviceConfigChanged();
99
100 private slots:
101     void start();
102     void handleConnected();
103     void handleConnectionFailure();
104     void handleMounted();
105     void handleUnmounted();
106     void handleMountError(const QString &errorMsg);
107     void handleMountDebugOutput(const QString &output);
108     void handleProgressReport(const QString &progressMsg);
109     void handleCopyProcessFinished(int exitStatus);
110     void handleSysrootInstallerFinished();
111     void handleSysrootInstallerOutput();
112     void handleSysrootInstallerErrorOutput();
113     void handleSftpChannelInitialized();
114     void handleSftpChannelInitializationFailed(const QString &error);
115     void handleSftpJobFinished(Utils::SftpJobId job, const QString &error);
116     void handleSftpChannelClosed();
117     void handleInstallationFinished(int exitStatus);
118     void handleDeviceInstallerOutput(const QByteArray &output);
119     void handleDeviceInstallerErrorOutput(const QByteArray &output);
120     void handlePortsGathererError(const QString &errorMsg);
121     void handlePortListReady();
122     void handleDeviceConfigurationsUpdated();
123
124 private:
125     enum State {
126         Inactive, StopRequested, InstallingToSysroot, Connecting,
127         UnmountingOldDirs, UnmountingCurrentDirs, GatheringPorts, Mounting,
128         InstallingToDevice, UnmountingCurrentMounts, CopyingFile,
129         InitializingSftp, Uploading
130     };
131
132     MaemoDeployStep(ProjectExplorer::BuildStepList *bc,
133         MaemoDeployStep *other);
134     virtual bool init();
135     virtual void run(QFutureInterface<bool> &fi);
136     virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
137     virtual bool immutable() const { return true; }
138     virtual QVariantMap toMap() const;
139     virtual bool fromMap(const QVariantMap &map);
140
141     void ctor();
142     void raiseError(const QString &error);
143     void writeOutput(const QString &text, OutputFormat = MessageOutput);
144     void addDeployTimesToMap(QVariantMap &map) const;
145     void getDeployTimesFromMap(const QVariantMap &map);
146     const MaemoPackageCreationStep *packagingStep() const;
147     QString deployMountPoint() const;
148     const MaemoToolChain *toolChain() const;
149     void copyNextFileToDevice();
150     void installToSysroot();
151     QString uploadDir() const;
152     void connectToDevice();
153     void unmountOldDirs();
154     void setupMount();
155     void prepareSftpConnection();
156     void runPackageInstaller(const QString &packageFilePath);
157     void setState(State newState);
158     void unmount();
159     void setDeviceConfig(MaemoDeviceConfig::Id internalId);
160     const Qt4BuildConfiguration *qt4BuildConfiguration() const;
161
162     static const QLatin1String Id;
163
164     QSharedPointer<MaemoDeployables> m_deployables;
165     QSharedPointer<Utils::SshConnection> m_connection;
166     QProcess *m_sysrootInstaller;
167     typedef QPair<MaemoDeployable, QSharedPointer<Utils::SshRemoteProcess> > DeviceDeployAction;
168     QScopedPointer<DeviceDeployAction> m_currentDeviceDeployAction;
169     QList<MaemoDeployable> m_filesToCopy;
170     MaemoRemoteMounter *m_mounter;
171     bool m_deployToSysroot;
172     QSharedPointer<Utils::SftpChannel> m_uploader;
173     QSharedPointer<Utils::SshRemoteProcess> m_deviceInstaller;
174
175     bool m_needsInstall;
176     typedef QPair<MaemoDeployable, QString> DeployablePerHost;
177     QHash<DeployablePerHost, QDateTime> m_lastDeployed;
178     QSharedPointer<const MaemoDeviceConfig> m_deviceConfig;
179     QSharedPointer<const MaemoDeviceConfig> m_cachedDeviceConfig;
180     MaemoUsedPortsGatherer *m_portsGatherer;
181     MaemoPortList m_freePorts;
182     QByteArray m_installerStderr;
183     State m_state;
184     bool m_hasError;
185 };
186
187 class MaemoDeployEventHandler : public QObject
188 {
189     Q_OBJECT
190 public:
191     MaemoDeployEventHandler(MaemoDeployStep *deployStep,
192         QFutureInterface<bool> &future);
193
194 private slots:
195     void handleDeployingDone();
196     void handleDeployingFailed();
197     void checkForCanceled();
198
199 private:
200     MaemoDeployStep * const m_deployStep;
201     const QFutureInterface<bool> m_future;
202     QEventLoop * const m_eventLoop;
203     bool m_error;
204 };
205
206 } // namespace Internal
207 } // namespace Qt4ProjectManager
208
209 #endif // MAEMODEPLOYSTEP_H