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 "generictarget.h"
36 #include "genericbuildconfiguration.h"
37 #include "genericproject.h"
38 #include "genericmakestep.h"
40 #include <projectexplorer/buildsteplist.h>
41 #include <projectexplorer/customexecutablerunconfiguration.h>
42 #include <projectexplorer/deployconfiguration.h>
43 #include <projectexplorer/projectexplorerconstants.h>
45 #include <QtGui/QApplication>
46 #include <QtGui/QStyle>
49 const char * const GENERIC_DESKTOP_TARGET_DISPLAY_NAME("Desktop");
52 using namespace GenericProjectManager;
53 using namespace GenericProjectManager::Internal;
55 ////////////////////////////////////////////////////////////////////////////////////
57 ////////////////////////////////////////////////////////////////////////////////////
59 GenericTarget::GenericTarget(GenericProject *parent) :
60 ProjectExplorer::Target(parent, QLatin1String(GENERIC_DESKTOP_TARGET_ID)),
61 m_buildConfigurationFactory(new GenericBuildConfigurationFactory(this)),
62 m_deployConfigurationFactory(new ProjectExplorer::DeployConfigurationFactory(this))
64 setDefaultDisplayName(QApplication::translate("GenericProjectManager::GenericTarget",
65 GENERIC_DESKTOP_TARGET_DISPLAY_NAME));
66 setIcon(qApp->style()->standardIcon(QStyle::SP_ComputerIcon));
69 GenericTarget::~GenericTarget()
73 ProjectExplorer::BuildConfigWidget *GenericTarget::createConfigWidget()
75 return new GenericBuildSettingsWidget(this);
78 GenericProject *GenericTarget::genericProject() const
80 return static_cast<GenericProject *>(project());
83 GenericBuildConfigurationFactory *GenericTarget::buildConfigurationFactory() const
85 return m_buildConfigurationFactory;
88 ProjectExplorer::DeployConfigurationFactory *GenericTarget::deployConfigurationFactory() const
90 return m_deployConfigurationFactory;
93 GenericBuildConfiguration *GenericTarget::activeBuildConfiguration() const
95 return static_cast<GenericBuildConfiguration *>(Target::activeBuildConfiguration());
98 bool GenericTarget::fromMap(const QVariantMap &map)
100 if (!Target::fromMap(map))
106 ////////////////////////////////////////////////////////////////////////////////////
107 // GenericTargetFactory
108 ////////////////////////////////////////////////////////////////////////////////////
110 GenericTargetFactory::GenericTargetFactory(QObject *parent) :
111 ITargetFactory(parent)
115 GenericTargetFactory::~GenericTargetFactory()
119 bool GenericTargetFactory::supportsTargetId(const QString &id) const
121 return id == QLatin1String(GENERIC_DESKTOP_TARGET_ID);
124 QStringList GenericTargetFactory::supportedTargetIds(ProjectExplorer::Project *parent) const
126 if (!qobject_cast<GenericProject *>(parent))
127 return QStringList();
128 return QStringList() << QLatin1String(GENERIC_DESKTOP_TARGET_ID);
131 QString GenericTargetFactory::displayNameForId(const QString &id) const
133 if (id == QLatin1String(GENERIC_DESKTOP_TARGET_ID))
134 return QCoreApplication::translate("GenericProjectManager::GenericTarget",
135 GENERIC_DESKTOP_TARGET_DISPLAY_NAME,
136 "Generic desktop target display name");
140 bool GenericTargetFactory::canCreate(ProjectExplorer::Project *parent, const QString &id) const
142 if (!qobject_cast<GenericProject *>(parent))
144 return id == QLatin1String(GENERIC_DESKTOP_TARGET_ID);
147 GenericTarget *GenericTargetFactory::create(ProjectExplorer::Project *parent, const QString &id)
149 if (!canCreate(parent, id))
151 GenericProject *genericproject = static_cast<GenericProject *>(parent);
152 GenericTarget *t = new GenericTarget(genericproject);
154 // Set up BuildConfiguration:
155 GenericBuildConfiguration *bc = new GenericBuildConfiguration(t);
156 bc->setDisplayName("all");
158 ProjectExplorer::BuildStepList *buildSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
159 GenericMakeStep *makeStep = new GenericMakeStep(buildSteps);
160 buildSteps->insertStep(0, makeStep);
162 makeStep->setBuildTarget("all", /* on = */ true);
164 bc->setBuildDirectory(genericproject->projectDirectory());
166 t->addBuildConfiguration(bc);
168 t->addDeployConfiguration(t->deployConfigurationFactory()->create(t, ProjectExplorer::Constants::DEFAULT_DEPLOYCONFIGURATION_ID));
170 // Add a runconfiguration. The CustomExecutableRC one will query the user
171 // for its settings, so it is a good choice here.
172 t->addRunConfiguration(new ProjectExplorer::CustomExecutableRunConfiguration(t));
177 bool GenericTargetFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
179 return canCreate(parent, ProjectExplorer::idFromMap(map));
182 GenericTarget *GenericTargetFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
184 if (!canRestore(parent, map))
186 GenericProject *genericproject = static_cast<GenericProject *>(parent);
187 GenericTarget *target = new GenericTarget(genericproject);
188 if (target->fromMap(map))