1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the Qt Creator.
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
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
33 ****************************************************************************/
35 #include "maemorunfactories.h"
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"
46 #include <projectexplorer/projectexplorerconstants.h>
47 #include <debugger/debuggerconstants.h>
48 #include <qt4projectmanager/qt4project.h>
49 #include <qt4projectmanager/qt4projectmanagerconstants.h>
51 namespace Qt4ProjectManager {
54 using namespace ProjectExplorer;
58 QString pathFromId(const QString &id)
60 if (!id.startsWith(MAEMO_RC_ID_PREFIX))
62 return id.mid(QString(MAEMO_RC_ID_PREFIX).size());
67 MaemoRunConfigurationFactory::MaemoRunConfigurationFactory(QObject *parent)
68 : IRunConfigurationFactory(parent)
72 MaemoRunConfigurationFactory::~MaemoRunConfigurationFactory()
76 bool MaemoRunConfigurationFactory::canCreate(Target *parent,
77 const QString &id) const
79 AbstractQt4MaemoTarget *target = qobject_cast<AbstractQt4MaemoTarget *>(parent);
82 return target->qt4Project()->hasApplicationProFile(pathFromId(id));
85 bool MaemoRunConfigurationFactory::canRestore(Target *parent,
86 const QVariantMap &map) const
88 if (!qobject_cast<AbstractQt4MaemoTarget *>(parent))
90 return ProjectExplorer::idFromMap(map)
91 .startsWith(QLatin1String(MAEMO_RC_ID));
94 bool MaemoRunConfigurationFactory::canClone(Target *parent,
95 RunConfiguration *source) const
97 return canCreate(parent, source->id());
100 QStringList MaemoRunConfigurationFactory::availableCreationIds(Target *parent) const
102 if (AbstractQt4MaemoTarget *t = qobject_cast<AbstractQt4MaemoTarget *>(parent)) {
104 return t->qt4Project()->
105 applicationProFilePathes(QLatin1String(MAEMO_RC_ID_PREFIX));
108 return QStringList();
111 QString MaemoRunConfigurationFactory::displayNameForId(const QString &id) const
113 return QFileInfo(pathFromId(id)).completeBaseName();
116 RunConfiguration *MaemoRunConfigurationFactory::create(Target *parent,
119 if (!canCreate(parent, id))
121 AbstractQt4MaemoTarget *pqt4parent = static_cast<AbstractQt4MaemoTarget *>(parent);
122 return new MaemoRunConfiguration(pqt4parent, pathFromId(id));
126 RunConfiguration *MaemoRunConfigurationFactory::restore(Target *parent,
127 const QVariantMap &map)
129 if (!canRestore(parent, map))
131 AbstractQt4MaemoTarget *target = static_cast<AbstractQt4MaemoTarget *>(parent);
132 MaemoRunConfiguration *rc = new MaemoRunConfiguration(target, QString());
133 if (rc->fromMap(map))
140 RunConfiguration *MaemoRunConfigurationFactory::clone(Target *parent,
141 RunConfiguration *source)
143 if (!canClone(parent, source))
146 MaemoRunConfiguration *old = static_cast<MaemoRunConfiguration *>(source);
147 return new MaemoRunConfiguration(static_cast<AbstractQt4MaemoTarget *>(parent), old);
150 // #pragma mark -- MaemoRunControlFactory
152 MaemoRunControlFactory::MaemoRunControlFactory(QObject *parent)
153 : IRunControlFactory(parent)
157 MaemoRunControlFactory::~MaemoRunControlFactory()
161 bool MaemoRunControlFactory::canRun(RunConfiguration *runConfiguration,
162 const QString &mode) const
164 const MaemoRunConfiguration * const maemoRunConfig
165 = qobject_cast<MaemoRunConfiguration *>(runConfiguration);
167 || !maemoRunConfig->deviceConfig() || !maemoRunConfig->toolchain()
168 || maemoRunConfig->remoteExecutableFilePath().isEmpty())
170 const int freePortCount = maemoRunConfig->freePorts().count();
172 const bool remoteMountsAllowed
173 = maemoRunConfig->maemoTarget()->allowsRemoteMounts();
174 if (remoteMountsAllowed && freePortCount == 0)
176 const int mountDirCount
177 = remoteMountsAllowed
178 ? maemoRunConfig->remoteMounts()->validMountSpecificationCount()
180 if (mode == Debugger::Constants::DEBUGMODE)
181 return freePortCount >= mountDirCount + maemoRunConfig->portsUsedByDebuggers();
182 if (mode == ProjectExplorer::Constants::RUNMODE)
183 return freePortCount >= mountDirCount;
187 RunControl* MaemoRunControlFactory::create(RunConfiguration *runConfig,
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);
195 if (mode == ProjectExplorer::Constants::RUNMODE)
196 return new MaemoRunControl(rc);
197 return MaemoDebugSupport::createDebugRunControl(rc);
200 QString MaemoRunControlFactory::displayName() const
202 return tr("Run on device");
205 RunConfigWidget *MaemoRunControlFactory::createConfigurationWidget(RunConfiguration *config)
211 } // namespace Internal
212 } // namespace Qt4ProjectManager