OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qt-s60 / s60runcontrolbase.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 qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "s60runcontrolbase.h"
34
35 #include "s60deployconfiguration.h"
36 #include "s60devicerunconfiguration.h"
37
38 #include "qt4buildconfiguration.h"
39 #include "qt4symbiantarget.h"
40 #include "qt4target.h"
41 #include "qtoutputformatter.h"
42
43 #include <utils/qtcassert.h>
44
45 #include <coreplugin/icore.h>
46 #include <coreplugin/progressmanager/progressmanager.h>
47
48 #include <QtCore/QDateTime>
49 #include <QtCore/QDir>
50 #include <QtCore/QFileInfo>
51
52 using namespace ProjectExplorer;
53 using namespace Qt4ProjectManager;
54 using namespace Qt4ProjectManager::Internal;
55
56 const int PROGRESS_MIN = 0;
57 const int PROGRESS_MAX = 200;
58
59 enum { debug = 0 };
60
61 // Format information about a file
62 QString S60RunControlBase::msgListFile(const QString &file)
63 {
64     QString rc;
65     const QFileInfo fi(file);
66     QTextStream str(&rc);
67     if (fi.exists())
68         str << fi.size() << ' ' << fi.lastModified().toString(Qt::ISODate) << ' ' << QDir::toNativeSeparators(fi.absoluteFilePath());
69     else
70         str << "<non-existent> " << QDir::toNativeSeparators(fi.absoluteFilePath());
71     return rc;
72 }
73
74 S60RunControlBase::S60RunControlBase(RunConfiguration *runConfiguration, const QString &mode) :
75     RunControl(runConfiguration, mode),
76     m_launchProgress(0)
77 {
78     connect(this, SIGNAL(finished()), this, SLOT(reportLaunchFinished()));
79     connect(this, SIGNAL(finished()), this, SLOT(handleFinished()));
80
81     const S60DeviceRunConfiguration *s60runConfig = qobject_cast<S60DeviceRunConfiguration *>(runConfiguration);
82     QTC_ASSERT(s60runConfig, return);
83     const Qt4BuildConfiguration *activeBuildConf = s60runConfig->qt4Target()->activeBuildConfiguration();
84     QTC_ASSERT(activeBuildConf, return);
85     const S60DeployConfiguration *activeDeployConf = qobject_cast<S60DeployConfiguration *>(s60runConfig->qt4Target()->activeDeployConfiguration());
86     QTC_ASSERT(activeDeployConf, return);
87
88     m_executableUid = s60runConfig->executableUid();
89     m_targetName = s60runConfig->targetName();
90     m_commandLineArguments = s60runConfig->commandLineArguments();
91     m_qtDir = activeBuildConf->qtVersion()->versionInfo().value("QT_INSTALL_DATA");
92     m_installationDrive = activeDeployConf->installationDrive();
93     if (const QtVersion *qtv = activeDeployConf->qtVersion())
94         m_qtBinPath = qtv->versionInfo().value(QLatin1String("QT_INSTALL_BINS"));
95     QTC_ASSERT(!m_qtBinPath.isEmpty(), return);
96     m_executableFileName = s60runConfig->localExecutableFileName();
97     m_runSmartInstaller = activeDeployConf->runSmartInstaller();
98
99     if (debug)
100         qDebug() << "S60RunControlBase::CT" << m_targetName;
101 }
102
103 void S60RunControlBase::start()
104 {
105     QTC_ASSERT(!m_launchProgress, return);
106
107     m_launchProgress = new QFutureInterface<void>;
108     Core::ICore::instance()->progressManager()->addTask(m_launchProgress->future(),
109                                                         tr("Launching"),
110                                                         QLatin1String("Symbian.Launch"));
111     m_launchProgress->setProgressRange(PROGRESS_MIN, PROGRESS_MAX);
112     m_launchProgress->setProgressValue(PROGRESS_MIN);
113     m_launchProgress->reportStarted();
114
115     if (m_runSmartInstaller) { //Smart Installer does the running by itself
116         cancelProgress();
117         appendMessage(tr("Please finalise the installation on your device."), NormalMessageFormat);
118         emit finished();
119         return;
120     }
121
122     if (!doStart()) {
123         emit finished();
124         return;
125     }
126     emit started();
127     startLaunching();
128 }
129
130 S60RunControlBase::~S60RunControlBase()
131 {
132     if (m_launchProgress) {
133         m_launchProgress->reportFinished();
134         delete m_launchProgress;
135         m_launchProgress = 0;
136     }
137 }
138
139 RunControl::StopResult S60RunControlBase::stop()
140 {
141     doStop();
142     return AsynchronousStop;
143 }
144
145 bool S60RunControlBase::promptToStop(bool *optionalPrompt) const
146 {
147     Q_UNUSED(optionalPrompt)
148     // We override the settings prompt
149     QTC_ASSERT(isRunning(), return true;)
150
151     const QString question = tr("<html><head/><body><center><i>%1</i> is still running on the device.</center>"
152                                         "<center>Terminating it can leave the target in an inconsistent state.</center>"
153                                         "<center>Would you still like to terminate it?</center></body></html>").arg(displayName());
154     return showPromptToStopDialog(tr("Application Still Running"), question,
155                                   tr("Force Quit"), tr("Keep Running"));
156 }
157
158 void S60RunControlBase::startLaunching()
159 {
160     if (setupLauncher())
161         setProgress(maxProgress()*0.30);
162     else {
163         stop();
164         emit finished();
165     }
166 }
167
168 void S60RunControlBase::handleFinished()
169 {
170     appendMessage(tr("Finished."), NormalMessageFormat);
171 }
172
173 void S60RunControlBase::setProgress(int value)
174 {
175     if (m_launchProgress) {
176         if (value < PROGRESS_MAX) {
177             if (value < PROGRESS_MIN)
178                 m_launchProgress->setProgressValue(PROGRESS_MIN);
179             else
180                 m_launchProgress->setProgressValue(value);
181         } else {
182             m_launchProgress->setProgressValue(PROGRESS_MAX);
183             m_launchProgress->reportFinished();
184             delete m_launchProgress;
185             m_launchProgress = 0;
186         }
187     }
188 }
189
190 void S60RunControlBase::cancelProgress()
191 {
192     if (m_launchProgress) {
193         m_launchProgress->reportCanceled();
194         m_launchProgress->reportFinished();
195     }
196     delete m_launchProgress;
197     m_launchProgress = 0;
198 }
199
200 int S60RunControlBase::maxProgress() const
201 {
202     return PROGRESS_MAX;
203 }
204
205 void S60RunControlBase::reportLaunchFinished()
206 {
207     setProgress(maxProgress());
208 }
209
210 quint32 S60RunControlBase::executableUid() const
211 {
212     return m_executableUid;
213 }
214
215 QString S60RunControlBase::executableName() const
216 {
217     return QString::fromLatin1("%1.exe").arg(targetName());
218 }
219
220 const QString &S60RunControlBase::targetName() const
221 {
222     return m_targetName;
223 }
224
225 const QString &S60RunControlBase::commandLineArguments() const
226 {
227     return m_commandLineArguments;
228 }
229
230 const QString &S60RunControlBase::executableFileName() const
231 {
232     return m_executableFileName;
233 }
234
235 const QString &S60RunControlBase::qtDir() const
236 {
237     return m_qtDir;
238 }
239
240 const QString &S60RunControlBase::qtBinPath() const
241 {
242     return m_qtBinPath;
243 }
244
245 bool S60RunControlBase::runSmartInstaller() const
246 {
247     return m_runSmartInstaller;
248 }
249
250 char S60RunControlBase::installationDrive() const
251 {
252     return m_installationDrive;
253 }