OSDN Git Service

ae5b402800d5308441d038bb90ece154a7273a46
[qt-creator-jp/qt-creator-jp.git] / src / plugins / genericprojectmanager / generictarget.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "generictarget.h"
35
36 #include "genericbuildconfiguration.h"
37 #include "genericproject.h"
38 #include "genericmakestep.h"
39
40 #include <projectexplorer/buildsteplist.h>
41 #include <projectexplorer/customexecutablerunconfiguration.h>
42 #include <projectexplorer/deployconfiguration.h>
43 #include <projectexplorer/projectexplorerconstants.h>
44
45 #include <QtGui/QApplication>
46 #include <QtGui/QStyle>
47
48 namespace {
49 const char * const GENERIC_DESKTOP_TARGET_DISPLAY_NAME("Desktop");
50 }
51
52 using namespace GenericProjectManager;
53 using namespace GenericProjectManager::Internal;
54
55 ////////////////////////////////////////////////////////////////////////////////////
56 // GenericTarget
57 ////////////////////////////////////////////////////////////////////////////////////
58
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))
63 {
64     setDefaultDisplayName(QApplication::translate("GenericProjectManager::GenericTarget",
65                                                   GENERIC_DESKTOP_TARGET_DISPLAY_NAME));
66     setIcon(qApp->style()->standardIcon(QStyle::SP_ComputerIcon));
67 }
68
69 GenericTarget::~GenericTarget()
70 {
71 }
72
73 ProjectExplorer::BuildConfigWidget *GenericTarget::createConfigWidget()
74 {
75     return new GenericBuildSettingsWidget(this);
76 }
77
78 GenericProject *GenericTarget::genericProject() const
79 {
80     return static_cast<GenericProject *>(project());
81 }
82
83 GenericBuildConfigurationFactory *GenericTarget::buildConfigurationFactory() const
84 {
85     return m_buildConfigurationFactory;
86 }
87
88 ProjectExplorer::DeployConfigurationFactory *GenericTarget::deployConfigurationFactory() const
89 {
90     return m_deployConfigurationFactory;
91 }
92
93 GenericBuildConfiguration *GenericTarget::activeBuildConfiguration() const
94 {
95     return static_cast<GenericBuildConfiguration *>(Target::activeBuildConfiguration());
96 }
97
98 bool GenericTarget::fromMap(const QVariantMap &map)
99 {
100     if (!Target::fromMap(map))
101         return false;
102
103     return true;
104 }
105
106 ////////////////////////////////////////////////////////////////////////////////////
107 // GenericTargetFactory
108 ////////////////////////////////////////////////////////////////////////////////////
109
110 GenericTargetFactory::GenericTargetFactory(QObject *parent) :
111     ITargetFactory(parent)
112 {
113 }
114
115 GenericTargetFactory::~GenericTargetFactory()
116 {
117 }
118
119 bool GenericTargetFactory::supportsTargetId(const QString &id) const
120 {
121     return id == QLatin1String(GENERIC_DESKTOP_TARGET_ID);
122 }
123
124 QStringList GenericTargetFactory::supportedTargetIds(ProjectExplorer::Project *parent) const
125 {
126     if (!qobject_cast<GenericProject *>(parent))
127         return QStringList();
128     return QStringList() << QLatin1String(GENERIC_DESKTOP_TARGET_ID);
129 }
130
131 QString GenericTargetFactory::displayNameForId(const QString &id) const
132 {
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");
137     return QString();
138 }
139
140 bool GenericTargetFactory::canCreate(ProjectExplorer::Project *parent, const QString &id) const
141 {
142     if (!qobject_cast<GenericProject *>(parent))
143         return false;
144     return id == QLatin1String(GENERIC_DESKTOP_TARGET_ID);
145 }
146
147 GenericTarget *GenericTargetFactory::create(ProjectExplorer::Project *parent, const QString &id)
148 {
149     if (!canCreate(parent, id))
150         return 0;
151     GenericProject *genericproject = static_cast<GenericProject *>(parent);
152     GenericTarget *t = new GenericTarget(genericproject);
153
154     // Set up BuildConfiguration:
155     GenericBuildConfiguration *bc = new GenericBuildConfiguration(t);
156     bc->setDisplayName("all");
157
158     ProjectExplorer::BuildStepList *buildSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
159     GenericMakeStep *makeStep = new GenericMakeStep(buildSteps);
160     buildSteps->insertStep(0, makeStep);
161
162     makeStep->setBuildTarget("all", /* on = */ true);
163
164     bc->setBuildDirectory(genericproject->projectDirectory());
165
166     t->addBuildConfiguration(bc);
167
168     t->addDeployConfiguration(t->deployConfigurationFactory()->create(t, ProjectExplorer::Constants::DEFAULT_DEPLOYCONFIGURATION_ID));
169
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));
173
174     return t;
175 }
176
177 bool GenericTargetFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
178 {
179     return canCreate(parent, ProjectExplorer::idFromMap(map));
180 }
181
182 GenericTarget *GenericTargetFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
183 {
184     if (!canRestore(parent, map))
185         return 0;
186     GenericProject *genericproject = static_cast<GenericProject *>(parent);
187     GenericTarget *target = new GenericTarget(genericproject);
188     if (target->fromMap(map))
189         return target;
190     delete target;
191     return 0;
192 }