OSDN Git Service

It's 2011 now.
[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 <coreplugin/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 Core {
58 class SftpChannel;
59 class SshConnection;
60 class SshRemoteProcess;
61 }
62
63 namespace Qt4ProjectManager {
64 namespace Internal {
65 class MaemoRemoteMounter;
66 class MaemoDeviceConfigListModel;
67 class MaemoPackageCreationStep;
68 class MaemoToolChain;
69 class MaemoUsedPortsGatherer;
70
71 class MaemoDeployStep : public ProjectExplorer::BuildStep
72 {
73     Q_OBJECT
74     friend class MaemoDeployStepFactory;
75 public:
76     MaemoDeployStep(ProjectExplorer::BuildStepList *bc);
77
78     virtual ~MaemoDeployStep();
79     MaemoDeviceConfig deviceConfig() const;
80     MaemoDeviceConfigListModel *deviceConfigModel() const { return m_deviceConfigModel; }
81     bool currentlyNeedsDeployment(const QString &host,
82         const MaemoDeployable &deployable) const;
83     void setDeployed(const QString &host, const MaemoDeployable &deployable);
84     QSharedPointer<MaemoDeployables> deployables() const { return m_deployables; }
85     QSharedPointer<Core::SshConnection> sshConnection() const { return m_connection; }
86
87     bool isDeployToSysrootEnabled() const { return m_deployToSysroot; }
88     void setDeployToSysrootEnabled(bool deploy) { m_deployToSysroot = deploy; }
89
90     Q_INVOKABLE void stop();
91
92 signals:
93     void done();
94     void error();
95
96 private slots:
97     void start();
98     void handleConnected();
99     void handleConnectionFailure();
100     void handleMounted();
101     void handleUnmounted();
102     void handleMountError(const QString &errorMsg);
103     void handleMountDebugOutput(const QString &output);
104     void handleProgressReport(const QString &progressMsg);
105     void handleCopyProcessFinished(int exitStatus);
106     void handleSysrootInstallerFinished();
107     void handleSysrootInstallerOutput();
108     void handleSysrootInstallerErrorOutput();
109     void handleSftpChannelInitialized();
110     void handleSftpChannelInitializationFailed(const QString &error);
111     void handleSftpJobFinished(Core::SftpJobId job, const QString &error);
112     void handleSftpChannelClosed();
113     void handleInstallationFinished(int exitStatus);
114     void handleDeviceInstallerOutput(const QByteArray &output);
115     void handleDeviceInstallerErrorOutput(const QByteArray &output);
116     void handlePortsGathererError(const QString &errorMsg);
117     void handlePortListReady();
118
119 private:
120     enum State {
121         Inactive, StopRequested, InstallingToSysroot, Connecting,
122         UnmountingOldDirs, UnmountingCurrentDirs, GatheringPorts, Mounting,
123         InstallingToDevice, UnmountingCurrentMounts, CopyingFile,
124         InitializingSftp, Uploading
125     };
126
127     MaemoDeployStep(ProjectExplorer::BuildStepList *bc,
128         MaemoDeployStep *other);
129     virtual bool init();
130     virtual void run(QFutureInterface<bool> &fi);
131     virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
132     virtual bool immutable() const { return true; }
133     virtual QVariantMap toMap() const;
134     virtual bool fromMap(const QVariantMap &map);
135
136     void ctor();
137     void raiseError(const QString &error);
138     void writeOutput(const QString &text, OutputFormat = MessageOutput);
139     void addDeployTimesToMap(QVariantMap &map) const;
140     void getDeployTimesFromMap(const QVariantMap &map);
141     const MaemoPackageCreationStep *packagingStep() const;
142     QString deployMountPoint() const;
143     const MaemoToolChain *toolChain() const;
144     void copyNextFileToDevice();
145     void installToSysroot();
146     QString uploadDir() const;
147     void connectToDevice();
148     void unmountOldDirs();
149     void setupMount();
150     void prepareSftpConnection();
151     void runDpkg(const QString &packageFilePath);
152     void setState(State newState);
153     void unmount();
154
155     static const QLatin1String Id;
156
157     QSharedPointer<MaemoDeployables> m_deployables;
158     QSharedPointer<Core::SshConnection> m_connection;
159     QProcess *m_sysrootInstaller;
160     typedef QPair<MaemoDeployable, QSharedPointer<Core::SshRemoteProcess> > DeviceDeployAction;
161     QScopedPointer<DeviceDeployAction> m_currentDeviceDeployAction;
162     QList<MaemoDeployable> m_filesToCopy;
163     MaemoRemoteMounter *m_mounter;
164     bool m_deployToSysroot;
165     QSharedPointer<Core::SftpChannel> m_uploader;
166     QSharedPointer<Core::SshRemoteProcess> m_deviceInstaller;
167
168     bool m_needsInstall;
169     typedef QPair<MaemoDeployable, QString> DeployablePerHost;
170     QHash<DeployablePerHost, QDateTime> m_lastDeployed;
171     MaemoDeviceConfigListModel *m_deviceConfigModel;
172     MaemoUsedPortsGatherer *m_portsGatherer;
173     MaemoPortList m_freePorts;
174     State m_state;
175 };
176
177 class MaemoDeployEventHandler : public QObject
178 {
179     Q_OBJECT
180 public:
181     MaemoDeployEventHandler(MaemoDeployStep *deployStep,
182         QFutureInterface<bool> &future);
183
184 private slots:
185     void handleDeployingDone();
186     void handleDeployingFailed();
187     void checkForCanceled();
188
189 private:
190     MaemoDeployStep * const m_deployStep;
191     const QFutureInterface<bool> m_future;
192     QEventLoop * const m_eventLoop;
193     bool m_error;
194 };
195
196 } // namespace Internal
197 } // namespace Qt4ProjectManager
198
199 #endif // MAEMODEPLOYSTEP_H