OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / projectexplorer / deployconfiguration.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 (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "deployconfiguration.h"
34
35 #include "buildmanager.h"
36 #include "buildsteplist.h"
37 #include "buildstepspage.h"
38 #include "projectexplorer.h"
39 #include "projectexplorerconstants.h"
40 #include "target.h"
41
42 #include <QtCore/QStringList>
43
44 using namespace ProjectExplorer;
45
46 namespace {
47
48 const char * const BUILD_STEP_LIST_COUNT("ProjectExplorer.BuildConfiguration.BuildStepListCount");
49 const char * const BUILD_STEP_LIST_PREFIX("ProjectExplorer.BuildConfiguration.BuildStepList.");
50
51 } // namespace
52
53 DeployConfiguration::DeployConfiguration(Target *target, const QString &id) :
54     ProjectConfiguration(target, id),
55     m_stepList(0)
56 {
57     Q_ASSERT(target);
58     m_stepList = new BuildStepList(this, QLatin1String(Constants::BUILDSTEPS_DEPLOY));
59     //: Display name of the deploy build step list. Used as part of the labels in the project window.
60     m_stepList->setDefaultDisplayName(tr("Deploy"));
61     //: Default DeployConfiguration display name
62     setDefaultDisplayName(tr("No deployment"));
63 }
64
65 DeployConfiguration::DeployConfiguration(Target *target, DeployConfiguration *source) :
66     ProjectConfiguration(target, source)
67 {
68     Q_ASSERT(target);
69     // Do not clone stepLists here, do that in the derived constructor instead
70     // otherwise BuildStepFactories might reject to set up a BuildStep for us
71     // since we are not yet the derived class!
72 }
73
74 DeployConfiguration::~DeployConfiguration()
75 {
76     delete m_stepList;
77 }
78
79 BuildStepList *DeployConfiguration::stepList() const
80 {
81     return m_stepList;
82 }
83
84 QVariantMap DeployConfiguration::toMap() const
85 {
86     QVariantMap map(ProjectConfiguration::toMap());
87     map.insert(QLatin1String(BUILD_STEP_LIST_COUNT), 1);
88     map.insert(QLatin1String(BUILD_STEP_LIST_PREFIX) + QLatin1String("0"), m_stepList->toMap());
89     return map;
90 }
91
92 DeployConfigurationWidget *DeployConfiguration::configurationWidget() const
93 {
94     return 0;
95 }
96
97 bool DeployConfiguration::fromMap(const QVariantMap &map)
98 {
99     if (!ProjectConfiguration::fromMap(map))
100         return false;
101
102     int maxI = map.value(QLatin1String(BUILD_STEP_LIST_COUNT), 0).toInt();
103     if (maxI != 1)
104         return false;
105     QVariantMap data = map.value(QLatin1String(BUILD_STEP_LIST_PREFIX) + QLatin1String("0")).toMap();
106     if (!data.isEmpty()) {
107         m_stepList = new BuildStepList(this, data);
108         if (m_stepList->isNull()) {
109             qWarning() << "Failed to restore deploy step list";
110             delete m_stepList;
111             m_stepList = 0;
112             return false;
113         }
114         m_stepList->setDefaultDisplayName(tr("Deploy"));
115     } else {
116         qWarning() << "No data for deploy step list found!";
117         return false;
118     }
119
120     // TODO: We assume that we hold the deploy list
121     Q_ASSERT(m_stepList && m_stepList->id() == QLatin1String(ProjectExplorer::Constants::BUILDSTEPS_DEPLOY));
122
123     return true;
124 }
125
126 Target *DeployConfiguration::target() const
127 {
128     return static_cast<Target *>(parent());
129 }
130
131 void DeployConfiguration::cloneSteps(DeployConfiguration *source)
132 {
133     if (source == this)
134         return;
135     delete m_stepList;
136     m_stepList = new BuildStepList(this, source->stepList());
137     m_stepList->cloneSteps(source->stepList());
138 }
139
140 ///
141 // DeployConfigurationFactory
142 ///
143
144 DeployConfigurationFactory::DeployConfigurationFactory(QObject *parent) :
145     QObject(parent)
146 { }
147
148 DeployConfigurationFactory::~DeployConfigurationFactory()
149 { }
150
151 QStringList DeployConfigurationFactory::availableCreationIds(Target *parent) const
152 {
153     Q_UNUSED(parent);
154     return QStringList() << QLatin1String(Constants::DEFAULT_DEPLOYCONFIGURATION_ID);
155 }
156
157 QString DeployConfigurationFactory::displayNameForId(const QString &id) const
158 {
159     if (id == QLatin1String(Constants::DEFAULT_DEPLOYCONFIGURATION_ID))
160         //: Display name of the default deploy configuration
161         return tr("Deploy Configuration");
162     return QString();
163 }
164
165 bool DeployConfigurationFactory::canCreate(Target *parent, const QString &id) const
166 {
167     Q_UNUSED(parent);
168     return id == QLatin1String(Constants::DEFAULT_DEPLOYCONFIGURATION_ID);
169 }
170
171 DeployConfiguration *DeployConfigurationFactory::create(Target *parent, const QString &id)
172 {
173     if (!canCreate(parent, id))
174         return 0;
175     return new DeployConfiguration(parent, id);
176 }
177
178 bool DeployConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const
179 {
180     return canCreate(parent, idFromMap(map));
181 }
182
183 DeployConfiguration *DeployConfigurationFactory::restore(Target *parent, const QVariantMap &map)
184 {
185     if (!canRestore(parent, map))
186         return 0;
187     DeployConfiguration *dc = new DeployConfiguration(parent, idFromMap(map));
188     if (!dc->fromMap(map)) {
189         delete dc;
190         return 0;
191     }
192     return dc;
193 }
194
195 bool DeployConfigurationFactory::canClone(Target *parent, DeployConfiguration *product) const
196 {
197     return canCreate(parent, product->id());
198 }
199
200 DeployConfiguration *DeployConfigurationFactory::clone(Target *parent, DeployConfiguration *product)
201 {
202     if (!canClone(parent, product))
203         return 0;
204     return new DeployConfiguration(parent, product);
205 }
206
207 ///
208 // DeployConfigurationWidget
209 ///
210
211 DeployConfigurationWidget::DeployConfigurationWidget(QWidget *parent) : NamedWidget(parent)
212 { }