cmakerunconfiguration.cpp 6.68 KB
Newer Older
1
/**************************************************************************
dt's avatar
dt committed
2 3 4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
dt's avatar
dt committed
6 7 8
**
** Contact:  Qt Software Information (qt-info@nokia.com)
**
9
** Commercial Usage
dt's avatar
dt committed
10
**
11 12 13 14
** 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.
dt's avatar
dt committed
15
**
16
** GNU Lesser General Public License Usage
dt's avatar
dt committed
17
**
18 19 20 21 22 23
** 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.
dt's avatar
dt committed
24
**
25 26
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
dt's avatar
dt committed
27
**
28
**************************************************************************/
dt's avatar
dt committed
29 30

#include "cmakerunconfiguration.h"
hjk's avatar
hjk committed
31

dt's avatar
dt committed
32
#include "cmakeproject.h"
hjk's avatar
hjk committed
33
#include "cmakeprojectconstants.h"
dt's avatar
dt committed
34 35

#include <projectexplorer/environment.h>
hjk's avatar
hjk committed
36
#include <utils/qtcassert.h>
37 38
#include <QtGui/QFormLayout>
#include <QtGui/QLineEdit>
dt's avatar
dt committed
39 40 41 42

using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;

dt's avatar
dt committed
43
CMakeRunConfiguration::CMakeRunConfiguration(CMakeProject *pro, const QString &target, const QString &workingDirectory, const QString &title)
44 45 46 47 48
    : ProjectExplorer::ApplicationRunConfiguration(pro)
    , m_runMode(Gui)
    , m_target(target)
    , m_workingDirectory(workingDirectory)
    , m_title(title)
dt's avatar
dt committed
49
{
dt's avatar
dt committed
50
    setName(title);
dt's avatar
dt committed
51
}
hjk's avatar
hjk committed
52

dt's avatar
dt committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
CMakeRunConfiguration::~CMakeRunConfiguration()
{
}

QString CMakeRunConfiguration::type() const
{
    return Constants::CMAKERUNCONFIGURATION;
}

QString CMakeRunConfiguration::executable() const
{
    return m_target;
}

ProjectExplorer::ApplicationRunConfiguration::RunMode CMakeRunConfiguration::runMode() const
{
69
    return m_runMode;
dt's avatar
dt committed
70 71 72 73 74 75 76 77 78
}

QString CMakeRunConfiguration::workingDirectory() const
{
    return m_workingDirectory;
}

QStringList CMakeRunConfiguration::commandLineArguments() const
{
79
    return ProjectExplorer::Environment::parseCombinedArgString(m_arguments);
dt's avatar
dt committed
80 81 82 83
}

ProjectExplorer::Environment CMakeRunConfiguration::environment() const
{
84
    // TODO have a way for the user to setup the environment
dt's avatar
dt committed
85 86 87
    return ProjectExplorer::Environment::systemEnvironment();
}

dt's avatar
dt committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
QString CMakeRunConfiguration::title() const
{
    return m_title;
}

void CMakeRunConfiguration::setExecutable(const QString &executable)
{
    m_target = executable;
}

void CMakeRunConfiguration::setWorkingDirectory(const QString &workingDirectory)
{
    m_workingDirectory = workingDirectory;
}

dt's avatar
dt committed
103 104 105
void CMakeRunConfiguration::save(ProjectExplorer::PersistentSettingsWriter &writer) const
{
    ProjectExplorer::ApplicationRunConfiguration::save(writer);
106 107
    writer.saveValue("CMakeRunConfiguration.Target", m_target);
    writer.saveValue("CMakeRunConfiguration.WorkingDirectory", m_workingDirectory);
108
    writer.saveValue("CMakeRunConfiguration.UseTerminal", m_runMode == Console);
dt's avatar
dt committed
109
    writer.saveValue("CMakeRunConfiguation.Title", m_title);
110
    writer.saveValue("CMakeRunConfiguration.Arguments", m_arguments);
dt's avatar
dt committed
111 112 113 114 115
}

void CMakeRunConfiguration::restore(const ProjectExplorer::PersistentSettingsReader &reader)
{
    ProjectExplorer::ApplicationRunConfiguration::restore(reader);
116 117
    m_target = reader.restoreValue("CMakeRunConfiguration.Target").toString();
    m_workingDirectory = reader.restoreValue("CMakeRunConfiguration.WorkingDirectory").toString();
118
    m_runMode = reader.restoreValue("CMakeRunConfiguration.UseTerminal").toBool() ? Console : Gui;
dt's avatar
dt committed
119
    m_title = reader.restoreValue("CMakeRunConfiguation.Title").toString();
120
    m_arguments = reader.restoreValue("CMakeRunConfiguration.Arguments").toString();
dt's avatar
dt committed
121 122 123 124
}

QWidget *CMakeRunConfiguration::configurationWidget()
{
125 126 127 128 129 130 131 132 133 134 135 136 137 138
    QWidget *widget = new QWidget();
    QFormLayout *fl = new QFormLayout();
    widget->setLayout(fl);
    QLineEdit *argumentsLineEdit = new QLineEdit(widget);
    argumentsLineEdit->setText(m_arguments);
    connect(argumentsLineEdit, SIGNAL(textChanged(QString)),
            this, SLOT(setArguments(QString)));
    fl->addRow(tr("Arguments:"), argumentsLineEdit);
    return widget;
}

void CMakeRunConfiguration::setArguments(const QString &newText)
{
    m_arguments = newText;
dt's avatar
dt committed
139 140
}

141 142
QString CMakeRunConfiguration::dumperLibrary() const
{
143
    return CMakeManager::findDumperLibrary(environment());
144 145
}

dt's avatar
dt committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
// Factory
CMakeRunConfigurationFactory::CMakeRunConfigurationFactory()
{

}

CMakeRunConfigurationFactory::~CMakeRunConfigurationFactory()
{

}

// used to recreate the runConfigurations when restoring settings
bool CMakeRunConfigurationFactory::canCreate(const QString &type) const
{
    if (type.startsWith(Constants::CMAKERUNCONFIGURATION))
        return true;
    return false;
}

// used to show the list of possible additons to a project, returns a list of types
QStringList CMakeRunConfigurationFactory::canCreate(ProjectExplorer::Project *project) const
{
    CMakeProject *pro = qobject_cast<CMakeProject *>(project);
    if (!pro)
        return QStringList();
171 172 173 174 175
    QStringList allTargets = pro->targets();
    for (int i=0; i<allTargets.size(); ++i) {
        allTargets[i] = Constants::CMAKERUNCONFIGURATION + allTargets[i];
    }
    return allTargets;
dt's avatar
dt committed
176 177 178 179 180
}

// used to translate the types to names to display to the user
QString CMakeRunConfigurationFactory::nameForType(const QString &type) const
{
dt's avatar
dt committed
181
    Q_ASSERT(type.startsWith(Constants::CMAKERUNCONFIGURATION));
dt's avatar
dt committed
182 183 184 185 186 187 188 189 190 191

    if (type == Constants::CMAKERUNCONFIGURATION)
        return "CMake"; // Doesn't happen
    else
        return type.mid(QString(Constants::CMAKERUNCONFIGURATION).length());
}

QSharedPointer<ProjectExplorer::RunConfiguration> CMakeRunConfigurationFactory::create(ProjectExplorer::Project *project, const QString &type)
{
    CMakeProject *pro = qobject_cast<CMakeProject *>(project);
dt's avatar
dt committed
192
    Q_ASSERT(pro);
dt's avatar
dt committed
193 194
    if (type == Constants::CMAKERUNCONFIGURATION) {
        // Restoring, filename will be added by restoreSettings
dt's avatar
dt committed
195
        QSharedPointer<ProjectExplorer::RunConfiguration> rc(new CMakeRunConfiguration(pro, QString::null, QString::null, QString::null));
dt's avatar
dt committed
196 197 198
        return rc;
    } else {
        // Adding new
199 200 201
        const QString title = type.mid(QString(Constants::CMAKERUNCONFIGURATION).length());
        const CMakeTarget &ct = pro->targetForTitle(title);
        QSharedPointer<ProjectExplorer::RunConfiguration> rc(new CMakeRunConfiguration(pro, ct.executable, ct.workingDirectory, ct.title));
dt's avatar
dt committed
202 203 204
        return rc;
    }
}