OSDN Git Service

aeff84e654424838c77d6b830cc40c60032ac440
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qt-maemo / maemorunfactories.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the Qt Creator.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
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 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 ** $QT_END_LICENSE$
32 **
33 ****************************************************************************/
34
35 #include "maemorunfactories.h"
36
37 #include "maemoconstants.h"
38 #include "maemodebugsupport.h"
39 #include "maemoglobal.h"
40 #include "maemoremotemountsmodel.h"
41 #include "maemorunconfiguration.h"
42 #include "maemoruncontrol.h"
43 #include "maemotoolchain.h"
44 #include "qt4maemotarget.h"
45
46 #include <projectexplorer/projectexplorerconstants.h>
47 #include <debugger/debuggerconstants.h>
48 #include <qt4projectmanager/qt4project.h>
49 #include <qt4projectmanager/qt4projectmanagerconstants.h>
50
51 namespace Qt4ProjectManager {
52 namespace Internal {
53
54 using namespace ProjectExplorer;
55
56 namespace {
57
58 QString pathFromId(const QString &id)
59 {
60     if (!id.startsWith(MAEMO_RC_ID_PREFIX))
61         return QString();
62     return id.mid(QString(MAEMO_RC_ID_PREFIX).size());
63 }
64
65 } // namespace
66
67 MaemoRunConfigurationFactory::MaemoRunConfigurationFactory(QObject *parent)
68     : IRunConfigurationFactory(parent)
69 {
70 }
71
72 MaemoRunConfigurationFactory::~MaemoRunConfigurationFactory()
73 {
74 }
75
76 bool MaemoRunConfigurationFactory::canCreate(Target *parent,
77     const QString &id) const
78 {
79     AbstractQt4MaemoTarget *target = qobject_cast<AbstractQt4MaemoTarget *>(parent);
80     if (!target)
81         return false;
82     return target->qt4Project()->hasApplicationProFile(pathFromId(id));
83 }
84
85 bool MaemoRunConfigurationFactory::canRestore(Target *parent,
86     const QVariantMap &map) const
87 {
88     if (!qobject_cast<AbstractQt4MaemoTarget *>(parent))
89         return false;
90     return ProjectExplorer::idFromMap(map)
91         .startsWith(QLatin1String(MAEMO_RC_ID));
92 }
93
94 bool MaemoRunConfigurationFactory::canClone(Target *parent,
95     RunConfiguration *source) const
96 {
97     return canCreate(parent, source->id());
98 }
99
100 QStringList MaemoRunConfigurationFactory::availableCreationIds(Target *parent) const
101 {
102     if (AbstractQt4MaemoTarget *t = qobject_cast<AbstractQt4MaemoTarget *>(parent)) {
103         if (t) {
104             return t->qt4Project()->
105                 applicationProFilePathes(QLatin1String(MAEMO_RC_ID_PREFIX));
106         }
107     }
108     return QStringList();
109 }
110
111 QString MaemoRunConfigurationFactory::displayNameForId(const QString &id) const
112 {
113     return QFileInfo(pathFromId(id)).completeBaseName();
114 }
115
116 RunConfiguration *MaemoRunConfigurationFactory::create(Target *parent,
117     const QString &id)
118 {
119     if (!canCreate(parent, id))
120         return 0;
121     AbstractQt4MaemoTarget *pqt4parent = static_cast<AbstractQt4MaemoTarget *>(parent);
122     return new MaemoRunConfiguration(pqt4parent, pathFromId(id));
123
124 }
125
126 RunConfiguration *MaemoRunConfigurationFactory::restore(Target *parent,
127     const QVariantMap &map)
128 {
129     if (!canRestore(parent, map))
130         return 0;
131     AbstractQt4MaemoTarget *target = static_cast<AbstractQt4MaemoTarget *>(parent);
132     MaemoRunConfiguration *rc = new MaemoRunConfiguration(target, QString());
133     if (rc->fromMap(map))
134         return rc;
135
136     delete rc;
137     return 0;
138 }
139
140 RunConfiguration *MaemoRunConfigurationFactory::clone(Target *parent,
141     RunConfiguration *source)
142 {
143     if (!canClone(parent, source))
144         return 0;
145
146     MaemoRunConfiguration *old = static_cast<MaemoRunConfiguration *>(source);
147     return new MaemoRunConfiguration(static_cast<AbstractQt4MaemoTarget *>(parent), old);
148 }
149
150 // #pragma mark -- MaemoRunControlFactory
151
152 MaemoRunControlFactory::MaemoRunControlFactory(QObject *parent)
153     : IRunControlFactory(parent)
154 {
155 }
156
157 MaemoRunControlFactory::~MaemoRunControlFactory()
158 {
159 }
160
161 bool MaemoRunControlFactory::canRun(RunConfiguration *runConfiguration,
162     const QString &mode) const
163 {
164     const MaemoRunConfiguration * const maemoRunConfig
165         = qobject_cast<MaemoRunConfiguration *>(runConfiguration);
166     if (!maemoRunConfig
167         || !maemoRunConfig->deviceConfig() || !maemoRunConfig->toolchain()
168         || maemoRunConfig->remoteExecutableFilePath().isEmpty())
169         return false;
170     const int freePortCount = maemoRunConfig->freePorts().count();
171
172     const bool remoteMountsAllowed
173         = maemoRunConfig->maemoTarget()->allowsRemoteMounts();
174     if (remoteMountsAllowed && freePortCount == 0)
175         return false;
176     const int mountDirCount
177         = remoteMountsAllowed
178             ? maemoRunConfig->remoteMounts()->validMountSpecificationCount()
179             : 0;
180     if (mode == Debugger::Constants::DEBUGMODE)
181         return freePortCount >= mountDirCount + maemoRunConfig->portsUsedByDebuggers();
182     if (mode == ProjectExplorer::Constants::RUNMODE)
183         return freePortCount >= mountDirCount;
184     return false;
185 }
186
187 RunControl* MaemoRunControlFactory::create(RunConfiguration *runConfig,
188     const QString &mode)
189 {
190     Q_ASSERT(mode == ProjectExplorer::Constants::RUNMODE
191         || mode == Debugger::Constants::DEBUGMODE);
192     Q_ASSERT(canRun(runConfig, mode));
193     MaemoRunConfiguration *rc = qobject_cast<MaemoRunConfiguration *>(runConfig);
194     Q_ASSERT(rc);
195     if (mode == ProjectExplorer::Constants::RUNMODE)
196         return new MaemoRunControl(rc);
197     return MaemoDebugSupport::createDebugRunControl(rc);
198 }
199
200 QString MaemoRunControlFactory::displayName() const
201 {
202     return tr("Run on device");
203 }
204
205 RunConfigWidget *MaemoRunControlFactory::createConfigurationWidget(RunConfiguration *config)
206 {
207     Q_UNUSED(config)
208     return 0;
209 }
210
211     } // namespace Internal
212 } // namespace Qt4ProjectManager