1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "s60emulatorrunconfiguration.h"
36 #include "qt4project.h"
37 #include "qt4target.h"
38 #include "s60manager.h"
39 #include "qt4projectmanagerconstants.h"
40 #include "qtoutputformatter.h"
42 #include <utils/qtcassert.h>
43 #include <utils/detailswidget.h>
45 #include <QtGui/QLabel>
46 #include <QtGui/QVBoxLayout>
47 #include <QtGui/QFormLayout>
49 using namespace ProjectExplorer;
50 using namespace Qt4ProjectManager;
51 using namespace Qt4ProjectManager::Internal;
54 const char * const S60_EMULATOR_RC_ID("Qt4ProjectManager.S60EmulatorRunConfiguration");
55 const char * const S60_EMULATOR_RC_PREFIX("Qt4ProjectManager.S60EmulatorRunConfiguration.");
57 const char * const PRO_FILE_KEY("Qt4ProjectManager.S60EmulatorRunConfiguration.ProFile");
59 QString pathFromId(const QString &id)
61 if (!id.startsWith(QLatin1String(S60_EMULATOR_RC_PREFIX)))
63 return id.mid(QString::fromLatin1(S60_EMULATOR_RC_PREFIX).size());
66 QString pathToId(const QString &path)
68 return QString::fromLatin1(S60_EMULATOR_RC_PREFIX) + path;
73 // ======== S60EmulatorRunConfiguration
75 S60EmulatorRunConfiguration::S60EmulatorRunConfiguration(Qt4Target *parent, const QString &proFilePath) :
76 RunConfiguration(parent, QLatin1String(S60_EMULATOR_RC_ID)),
77 m_proFilePath(proFilePath),
78 m_validParse(parent->qt4Project()->validParse(proFilePath))
83 S60EmulatorRunConfiguration::S60EmulatorRunConfiguration(Qt4Target *parent, S60EmulatorRunConfiguration *source) :
84 RunConfiguration(parent, source),
85 m_proFilePath(source->m_proFilePath),
86 m_validParse(source->m_validParse)
91 void S60EmulatorRunConfiguration::ctor()
93 if (!m_proFilePath.isEmpty())
94 //: S60 emulator run configuration default display name, %1 is base pro-File name
95 setDefaultDisplayName(tr("%1 in Symbian Emulator").arg(QFileInfo(m_proFilePath).completeBaseName()));
97 //: S60 emulator run configuration default display name (no pro-file name)
98 setDefaultDisplayName(tr("Run on Symbian Emulator"));
99 Qt4Project *pro = qt4Target()->qt4Project();
100 connect(pro, SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*,bool)),
101 this, SLOT(proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFileNode*,bool)));
102 connect(pro, SIGNAL(proFileInvalidated(Qt4ProjectManager::Internal::Qt4ProFileNode *)),
103 this, SLOT(proFileInvalidated(Qt4ProjectManager::Internal::Qt4ProFileNode *)));
107 S60EmulatorRunConfiguration::~S60EmulatorRunConfiguration()
111 void S60EmulatorRunConfiguration::handleParserState(bool success)
113 bool enabled = isEnabled();
114 m_validParse = success;
115 if (enabled != isEnabled()) {
116 emit isEnabledChanged(!enabled);
120 void S60EmulatorRunConfiguration::proFileInvalidated(Qt4ProjectManager::Internal::Qt4ProFileNode *pro)
122 if (m_proFilePath != pro->path())
124 handleParserState(false);
127 void S60EmulatorRunConfiguration::proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFileNode *pro, bool success)
129 if (m_proFilePath != pro->path())
131 handleParserState(success);
132 emit targetInformationChanged();
135 Qt4Target *S60EmulatorRunConfiguration::qt4Target() const
137 return static_cast<Qt4Target *>(target());
140 bool S60EmulatorRunConfiguration::isEnabled(ProjectExplorer::BuildConfiguration *configuration) const
144 Qt4BuildConfiguration *qt4bc = qobject_cast<Qt4BuildConfiguration *>(configuration);
145 QTC_ASSERT(qt4bc, return false);
146 const ProjectExplorer::ToolChainType type = qt4bc->toolChainType();
147 return type == ProjectExplorer::ToolChain_WINSCW;
150 QWidget *S60EmulatorRunConfiguration::createConfigurationWidget()
152 return new S60EmulatorRunConfigurationWidget(this);
155 ProjectExplorer::OutputFormatter *S60EmulatorRunConfiguration::createOutputFormatter() const
157 return new QtOutputFormatter(qt4Target()->qt4Project());
160 QVariantMap S60EmulatorRunConfiguration::toMap() const
162 QVariantMap map(ProjectExplorer::RunConfiguration::toMap());
163 const QDir projectDir = QDir(target()->project()->projectDirectory());
164 map.insert(QLatin1String(PRO_FILE_KEY), projectDir.relativeFilePath(m_proFilePath));
168 bool S60EmulatorRunConfiguration::fromMap(const QVariantMap &map)
170 const QDir projectDir = QDir(target()->project()->projectDirectory());
171 m_proFilePath = projectDir.filePath(map.value(QLatin1String(PRO_FILE_KEY)).toString());
173 if (m_proFilePath.isEmpty())
176 m_validParse = qt4Target()->qt4Project()->validParse(m_proFilePath);
178 //: S60 emulator run configuration default display name, %1 is base pro-File name
179 setDefaultDisplayName(tr("%1 in Symbian Emulator").arg(QFileInfo(m_proFilePath).completeBaseName()));
181 return RunConfiguration::fromMap(map);
184 QString S60EmulatorRunConfiguration::executable() const
186 Qt4BuildConfiguration *qt4bc = qt4Target()->activeBuildConfiguration();
187 QtVersion *qtVersion = qt4bc->qtVersion();
188 QString baseDir = S60Manager::instance()->deviceForQtVersion(qtVersion).epocRoot;
189 QString qmakeBuildConfig = "urel";
190 if (qt4bc->qmakeBuildConfiguration() & QtVersion::DebugBuild)
191 qmakeBuildConfig = "udeb";
192 baseDir += "/epoc32/release/winscw/" + qmakeBuildConfig;
194 TargetInformation ti = qt4Target()->qt4Project()->rootProjectNode()->targetInformation(m_proFilePath);
197 QString executable = QDir::toNativeSeparators(QDir::cleanPath(baseDir + QLatin1Char('/') + ti.target));
198 executable += QLatin1String(".exe");
203 // ======== S60EmulatorRunConfigurationWidget
205 S60EmulatorRunConfigurationWidget::S60EmulatorRunConfigurationWidget(S60EmulatorRunConfiguration *runConfiguration,
208 m_runConfiguration(runConfiguration),
209 m_detailsWidget(new Utils::DetailsWidget),
210 m_executableLabel(new QLabel(m_runConfiguration->executable()))
212 m_detailsWidget->setState(Utils::DetailsWidget::NoSummary);
213 QVBoxLayout *mainBoxLayout = new QVBoxLayout();
214 mainBoxLayout->setMargin(0);
215 setLayout(mainBoxLayout);
216 mainBoxLayout->addWidget(m_detailsWidget);
217 QWidget *detailsContainer = new QWidget;
218 m_detailsWidget->setWidget(detailsContainer);
220 QFormLayout *detailsFormLayout = new QFormLayout();
221 detailsFormLayout->setMargin(0);
222 detailsContainer->setLayout(detailsFormLayout);
224 detailsFormLayout->addRow(tr("Executable:"), m_executableLabel);
226 connect(m_runConfiguration, SIGNAL(targetInformationChanged()),
227 this, SLOT(updateTargetInformation()));
229 connect(m_runConfiguration, SIGNAL(isEnabledChanged(bool)),
230 this, SLOT(runConfigurationEnabledChange(bool)));
232 setEnabled(m_runConfiguration->isEnabled());
235 void S60EmulatorRunConfigurationWidget::updateTargetInformation()
237 m_executableLabel->setText(m_runConfiguration->executable());
240 void S60EmulatorRunConfigurationWidget::runConfigurationEnabledChange(bool enabled)
245 // ======== S60EmulatorRunConfigurationFactory
247 S60EmulatorRunConfigurationFactory::S60EmulatorRunConfigurationFactory(QObject *parent)
248 : IRunConfigurationFactory(parent)
252 S60EmulatorRunConfigurationFactory::~S60EmulatorRunConfigurationFactory()
256 bool S60EmulatorRunConfigurationFactory::canCreate(Target *parent, const QString &id) const
258 Qt4Target * t(qobject_cast<Qt4Target *>(parent));
260 t->id() != QLatin1String(Constants::S60_EMULATOR_TARGET_ID))
262 return t->qt4Project()->hasApplicationProFile(pathFromId(id));
265 RunConfiguration *S60EmulatorRunConfigurationFactory::create(Target *parent, const QString &id)
267 if (!canCreate(parent, id))
269 Qt4Target *t(static_cast<Qt4Target *>(parent));
270 return new S60EmulatorRunConfiguration(t, pathFromId(id));
273 bool S60EmulatorRunConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const
275 Qt4Target * t(qobject_cast<Qt4Target *>(parent));
277 t->id() != QLatin1String(Constants::S60_EMULATOR_TARGET_ID))
279 QString id(ProjectExplorer::idFromMap(map));
280 return id == QLatin1String(S60_EMULATOR_RC_ID);
283 RunConfiguration *S60EmulatorRunConfigurationFactory::restore(Target *parent, const QVariantMap &map)
285 if (!canRestore(parent, map))
287 Qt4Target *t(static_cast<Qt4Target *>(parent));
288 S60EmulatorRunConfiguration *rc(new S60EmulatorRunConfiguration(t, QString()));
289 if (rc->fromMap(map))
295 bool S60EmulatorRunConfigurationFactory::canClone(Target *parent, RunConfiguration *source) const
297 return canCreate(parent, source->id());
300 RunConfiguration *S60EmulatorRunConfigurationFactory::clone(Target *parent, RunConfiguration *source)
302 if (!canClone(parent, source))
304 Qt4Target *t(static_cast<Qt4Target *>(parent));
305 return new S60EmulatorRunConfiguration(t, QString());
308 QStringList S60EmulatorRunConfigurationFactory::availableCreationIds(Target *parent) const
310 Qt4Target * t(qobject_cast<Qt4Target *>(parent));
312 t->id() != QLatin1String(Constants::S60_EMULATOR_TARGET_ID))
313 return QStringList();
315 return t->qt4Project()->applicationProFilePathes(QLatin1String(S60_EMULATOR_RC_PREFIX));
318 QString S60EmulatorRunConfigurationFactory::displayNameForId(const QString &id) const
320 if (!pathFromId(id).isEmpty())
321 return tr("%1 in Symbian Emulator").arg(QFileInfo(pathFromId(id)).completeBaseName());
325 // ======== S60EmulatorRunControl
327 S60EmulatorRunControl::S60EmulatorRunControl(S60EmulatorRunConfiguration *runConfiguration, QString mode)
328 : RunControl(runConfiguration, mode)
330 // stuff like the EPOCROOT and EPOCDEVICE env variable
331 Utils::Environment env = Utils::Environment::systemEnvironment();
332 runConfiguration->qt4Target()->activeBuildConfiguration()->toolChain()->addToEnvironment(env);
333 m_applicationLauncher.setEnvironment(env);
335 m_executable = runConfiguration->executable();
336 connect(&m_applicationLauncher, SIGNAL(applicationError(QString)),
337 this, SLOT(slotError(QString)));
338 connect(&m_applicationLauncher, SIGNAL(appendMessage(QString, ProjectExplorer::OutputFormat)),
339 this, SLOT(slotAppendMessage(QString, ProjectExplorer::OutputFormat)));
340 connect(&m_applicationLauncher, SIGNAL(processExited(int)),
341 this, SLOT(processExited(int)));
342 connect(&m_applicationLauncher, SIGNAL(bringToForegroundRequested(qint64)),
343 this, SLOT(bringApplicationToForeground(qint64)));
346 void S60EmulatorRunControl::start()
348 m_applicationLauncher.start(ApplicationLauncher::Gui, m_executable, QString());
351 QString msg = tr("Starting %1...").arg(QDir::toNativeSeparators(m_executable));
352 appendMessage(msg, NormalMessageFormat);
355 RunControl::StopResult S60EmulatorRunControl::stop()
357 m_applicationLauncher.stop();
358 return StoppedSynchronously;
361 bool S60EmulatorRunControl::isRunning() const
363 return m_applicationLauncher.isRunning();
366 void S60EmulatorRunControl::slotError(const QString & err)
368 appendMessage(err, ErrorMessageFormat);
372 void S60EmulatorRunControl::slotAppendMessage(const QString &line, OutputFormat format)
374 static QString prefix = tr("[Qt Message]");
375 static int prefixLength = prefix.length();
376 int index = line.indexOf(prefix);
378 appendMessage(line.mid(index + prefixLength + 1), format);
381 void S60EmulatorRunControl::processExited(int exitCode)
383 QString msg = tr("%1 exited with code %2");
384 appendMessage(msg, exitCode ? ErrorMessageFormat : NormalMessageFormat);