2
* Copyright 2013 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 2.1.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Author: Juhapekka Piiroinen <juhapekka.piiroinen@canonical.com>
19
#include "ubunturuncontrol.h"
21
using namespace Ubuntu;
22
using namespace Ubuntu::Internal;
25
UbuntuRunControl::UbuntuRunControl(ProjectExplorer::RunConfiguration *runConfiguration, ProjectExplorer::RunMode mode, bool debug)
26
: RunControl(runConfiguration, mode)
28
Utils::Environment env = Utils::Environment::systemEnvironment();
30
m_applicationLauncher.setEnvironment(env);
31
UbuntuProject* ubuntuProject = qobject_cast<UbuntuProject*>(runConfiguration->target()->project());
33
m_applicationLauncher.setWorkingDirectory(ubuntuProject->projectDir().absolutePath());
35
if (ubuntuProject->mainFile().compare(QString::fromLatin1("www/index.html"), Qt::CaseInsensitive) == 0) {
36
//TODO move into abstracted location
37
m_executable = QString::fromLatin1(Ubuntu::Constants::UBUNTUHTML_PROJECT_LAUNCHER_EXE);
38
m_commandLineArguments = QString(QLatin1String("--www=%0/www --inspector")).arg(ubuntuProject->projectDirectory());
41
m_executable = QtSupport::QtKitInformation::qtVersion(runConfiguration->target()->kit())->qmlsceneCommand();
42
m_commandLineArguments = QString(QLatin1String("%0.qml")).arg(ubuntuProject->displayName());
45
connect(&m_applicationLauncher, SIGNAL(appendMessage(QString,Utils::OutputFormat)),
46
this, SLOT(slotAppendMessage(QString,Utils::OutputFormat)));
47
connect(&m_applicationLauncher, SIGNAL(processExited(int)),
48
this, SLOT(processExited(int)));
49
connect(&m_applicationLauncher, SIGNAL(bringToForegroundRequested(qint64)),
50
this, SLOT(slotBringApplicationToForeground(qint64)));
53
UbuntuRunControl::~UbuntuRunControl() {
57
void UbuntuRunControl::start() {
58
qDebug() << __PRETTY_FUNCTION__;
59
m_applicationLauncher.start(ProjectExplorer::ApplicationLauncher::Gui, m_executable,
60
m_commandLineArguments);
61
setApplicationProcessHandle(ProjectExplorer::ProcessHandle(m_applicationLauncher.applicationPID()));
63
QString msg = tr("Starting %1 %2\n")
64
.arg(QDir::toNativeSeparators(m_executable), m_commandLineArguments);
65
appendMessage(msg, Utils::NormalMessageFormat);
68
ProjectExplorer::RunControl::StopResult UbuntuRunControl::stop() {
69
m_applicationLauncher.stop();
70
return StoppedSynchronously;
73
bool UbuntuRunControl::isRunning() const {
74
return m_applicationLauncher.isRunning();
77
QIcon UbuntuRunControl::icon() const {
78
return QIcon(QLatin1String(ProjectExplorer::Constants::ICON_RUN_SMALL));
81
void UbuntuRunControl::slotBringApplicationToForeground(qint64 pid) {
82
bringApplicationToForeground(pid);
85
void UbuntuRunControl::slotAppendMessage(const QString &line, Utils::OutputFormat format) {
86
appendMessage(line, format);
89
void UbuntuRunControl::processExited(int exitCode) {
90
QString msg = tr("%1 exited with code %2\n")
91
.arg(QDir::toNativeSeparators(m_executable)).arg(exitCode);
92
appendMessage(msg, exitCode ? Utils::ErrorMessageFormat : Utils::NormalMessageFormat);