Skip to content
Snippets Groups Projects
applicationrunconfiguration.cpp 5.05 KiB
Newer Older
/**************************************************************************
con's avatar
con committed
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
**
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
**
** Commercial Usage
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
**
**************************************************************************/
hjk's avatar
hjk committed

con's avatar
con committed
#include "applicationrunconfiguration.h"
con's avatar
con committed
#include "environment.h"
hjk's avatar
hjk committed

con's avatar
con committed
#include <projectexplorer/projectexplorerconstants.h>
hjk's avatar
hjk committed
#include <utils/qtcassert.h>
con's avatar
con committed

con's avatar
con committed
#include <QtGui/QLabel>

using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;

/// LocalApplicationRunConfiguration
con's avatar
con committed

Tobias Hunger's avatar
Tobias Hunger committed
LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, const QString &id) :
    RunConfiguration(target, id)
con's avatar
con committed
{
}

Tobias Hunger's avatar
Tobias Hunger committed
LocalApplicationRunConfiguration::LocalApplicationRunConfiguration(Target *target, LocalApplicationRunConfiguration *rc) :
    RunConfiguration(target, rc)
con's avatar
con committed
{
}

LocalApplicationRunConfiguration::~LocalApplicationRunConfiguration()
con's avatar
con committed
{
}

/// LocalApplicationRunControlFactory
con's avatar
con committed

LocalApplicationRunControlFactory::LocalApplicationRunControlFactory()
con's avatar
con committed
{
}

LocalApplicationRunControlFactory::~LocalApplicationRunControlFactory()
con's avatar
con committed
{
}

bool LocalApplicationRunControlFactory::canRun(ProjectExplorer::RunConfiguration *runConfiguration, const QString &mode) const
con's avatar
con committed
{
    return (mode == ProjectExplorer::Constants::RUNMODE)
            && (qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration) != 0);
con's avatar
con committed
}

QString LocalApplicationRunControlFactory::displayName() const
con's avatar
con committed
{
    return tr("Run");
con's avatar
con committed
}

RunControl *LocalApplicationRunControlFactory::create(ProjectExplorer::RunConfiguration *runConfiguration, const QString &mode)
con's avatar
con committed
{
    QTC_ASSERT(canRun(runConfiguration, mode), return 0);
    return new LocalApplicationRunControl(qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration));
con's avatar
con committed
}

QWidget *LocalApplicationRunControlFactory::createConfigurationWidget(RunConfiguration *runConfiguration)
con's avatar
con committed
{
    Q_UNUSED(runConfiguration)
con's avatar
con committed
    return new QLabel("TODO add Configuration widget");
}

// ApplicationRunControl

LocalApplicationRunControl::LocalApplicationRunControl(LocalApplicationRunConfiguration *runConfiguration)
    : RunControl(runConfiguration)
con's avatar
con committed
{
    m_applicationLauncher.setEnvironment(runConfiguration->environment().toStringList());
    m_applicationLauncher.setWorkingDirectory(runConfiguration->workingDirectory());

    m_executable = runConfiguration->executable();
    m_runMode = static_cast<ApplicationLauncher::Mode>(runConfiguration->runMode());
    m_commandLineArguments = runConfiguration->commandLineArguments();

    connect(&m_applicationLauncher, SIGNAL(appendMessage(QString,bool)),
            this, SLOT(slotAppendMessage(QString,bool)));
    connect(&m_applicationLauncher, SIGNAL(appendOutput(QString, bool)),
            this, SLOT(slotAddToOutputWindow(QString, bool)));
con's avatar
con committed
    connect(&m_applicationLauncher, SIGNAL(processExited(int)),
            this, SLOT(processExited(int)));
    connect(&m_applicationLauncher, SIGNAL(bringToForegroundRequested(qint64)),
            this, SLOT(bringApplicationToForeground(qint64)));
}

LocalApplicationRunControl::~LocalApplicationRunControl()
con's avatar
con committed
{
}

void LocalApplicationRunControl::start()
con's avatar
con committed
{
    m_applicationLauncher.start(m_runMode, m_executable, m_commandLineArguments);
con's avatar
con committed
    emit started();

    emit appendMessage(this, tr("Starting %1...").arg(QDir::toNativeSeparators(m_executable)), false);
con's avatar
con committed
}

void LocalApplicationRunControl::stop()
con's avatar
con committed
{
    m_applicationLauncher.stop();
}

bool LocalApplicationRunControl::isRunning() const
con's avatar
con committed
{
    return m_applicationLauncher.isRunning();
}

void LocalApplicationRunControl::slotAppendMessage(const QString &err,
                                                   bool isError)
con's avatar
con committed
{
    emit appendMessage(this, err, isError);
con's avatar
con committed
    emit finished();
}

void LocalApplicationRunControl::slotAddToOutputWindow(const QString &line,
                                                       bool isError)
con's avatar
con committed
{
    emit addToOutputWindowInline(this, line, isError);
con's avatar
con committed
}

void LocalApplicationRunControl::processExited(int exitCode)
con's avatar
con committed
{
    emit appendMessage(this, tr("%1 exited with code %2").arg(QDir::toNativeSeparators(m_executable)).arg(exitCode), false);
con's avatar
con committed
    emit finished();
}