maemorunfactories.cpp 7.79 KB
Newer Older
hjk's avatar
hjk committed
1
/**************************************************************************
2
**
hjk's avatar
hjk committed
3
** This file is part of Qt Creator
4
**
hjk's avatar
hjk committed
5
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
6
**
Eike Ziller's avatar
Eike Ziller committed
7
** Contact: http://www.qt-project.org/
8 9
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
10 11 12 13 14 15 16
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 18
**
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
19
** rights. These rights are described in the Nokia Qt LGPL Exception
20 21
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
22 23 24 25 26
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
27
**
hjk's avatar
hjk committed
28
**************************************************************************/
29 30
#include "maemorunfactories.h"

31
#include "maemoapplicationrunnerhelperactions.h"
32
#include "maemoconstants.h"
33
#include "maemoglobal.h"
34
#include "maemoremotemountsmodel.h"
35
#include "maemorunconfiguration.h"
36

37
#include <debugger/debuggerconstants.h>
38
#include <debugger/debuggerstartparameters.h>
39 40 41
#include <debugger/debuggerplugin.h>
#include <debugger/debuggerrunner.h>
#include <projectexplorer/projectexplorerconstants.h>
Tobias Hunger's avatar
Tobias Hunger committed
42
#include <projectexplorer/kitinformation.h>
Tobias Hunger's avatar
Tobias Hunger committed
43 44
#include <projectexplorer/target.h>
#include <qt4projectmanager/qt4nodes.h>
45
#include <qt4projectmanager/qt4project.h>
Tobias Hunger's avatar
Tobias Hunger committed
46
#include <qtsupport/customexecutablerunconfiguration.h>
47 48
#include <remotelinux/remotelinuxdebugsupport.h>
#include <remotelinux/remotelinuxruncontrol.h>
49

50
using namespace Debugger;
51
using namespace ProjectExplorer;
52
using namespace Qt4ProjectManager;
53
using namespace RemoteLinux;
54

55
namespace Madde {
56
namespace Internal {
57 58 59

namespace {

60
QString pathFromId(Core::Id id)
61
{
Tobias Hunger's avatar
Tobias Hunger committed
62
    QString idStr = id.toString();
63 64
    const QString prefix = QLatin1String(MAEMO_RC_ID_PREFIX);
    if (!idStr.startsWith(prefix))
65
        return QString();
66
    return idStr.mid(prefix.size());
67 68
}

69 70 71
template<class Receiver> void setHelperActions(Receiver *receiver, MaemoRunConfiguration *runConfig,
        RunControl *runControl)
{
Tobias Hunger's avatar
Tobias Hunger committed
72
    const Kit * const k = runConfig->target()->kit();
73
    MaemoPreRunAction * const preRunAction = new MaemoPreRunAction(
Tobias Hunger's avatar
Tobias Hunger committed
74
            DeviceKitInformation::device(k), MaemoGlobal::maddeRoot(k),
75 76 77 78 79 80 81
            runConfig->remoteMounts()->mountSpecs(), runControl);
    MaemoPostRunAction * const postRunAction
            = new MaemoPostRunAction(preRunAction->mounter(), runControl);
    receiver->setApplicationRunnerPreRunAction(preRunAction);
    receiver->setApplicationRunnerPostRunAction(postRunAction);
}

82 83 84
} // namespace

MaemoRunConfigurationFactory::MaemoRunConfigurationFactory(QObject *parent)
Tobias Hunger's avatar
Tobias Hunger committed
85 86
    : QmakeRunConfigurationFactory(parent)
{ setObjectName(QLatin1String("MaemoRunConfigurationFactory")); }
87 88 89 90 91

MaemoRunConfigurationFactory::~MaemoRunConfigurationFactory()
{
}

Tobias Hunger's avatar
Tobias Hunger committed
92
bool MaemoRunConfigurationFactory::canCreate(Target *parent, const Core::Id id) const
93
{
Tobias Hunger's avatar
Tobias Hunger committed
94 95 96
    if (!canHandle(parent))
        return false;
    return static_cast<Qt4Project *>(parent->project())->hasApplicationProFile(pathFromId(id));
97 98 99 100 101
}

bool MaemoRunConfigurationFactory::canRestore(Target *parent,
    const QVariantMap &map) const
{
Tobias Hunger's avatar
Tobias Hunger committed
102 103
    return canHandle(parent)
        && ProjectExplorer::idFromMap(map).toString().startsWith(QLatin1String(MAEMO_RC_ID_PREFIX));
104 105 106 107 108
}

bool MaemoRunConfigurationFactory::canClone(Target *parent,
    RunConfiguration *source) const
{
Tobias Hunger's avatar
Tobias Hunger committed
109 110
    if (!canHandle(parent))
        return false;
111 112
    const RemoteLinuxRunConfiguration * const rlrc
            = qobject_cast<RemoteLinuxRunConfiguration *>(source);
113
    QString idStr = QString::fromLatin1(source->id().name()) + QLatin1Char('.') + rlrc->proFilePath();
Tobias Hunger's avatar
Tobias Hunger committed
114
    return rlrc && canCreate(parent, Core::Id(idStr));
115 116
}

117
QList<Core::Id> MaemoRunConfigurationFactory::availableCreationIds(Target *parent) const
118
{
119
    QList<Core::Id> result;
Tobias Hunger's avatar
Tobias Hunger committed
120 121 122 123 124
    if (!canHandle(parent))
        return result;
    QStringList proFiles = static_cast<Qt4Project *>(parent->project())->applicationProFilePathes(QLatin1String(MAEMO_RC_ID_PREFIX));
    foreach (const QString &pf, proFiles)
        result << Core::Id(pf);
125
    return result;
126 127
}

Tobias Hunger's avatar
Tobias Hunger committed
128
QString MaemoRunConfigurationFactory::displayNameForId(const Core::Id id) const
129
{
Christian Kandeler's avatar
Christian Kandeler committed
130
    return QFileInfo(pathFromId(id)).completeBaseName()
131
        + QLatin1String(" (on remote Maemo device)");
132 133
}

Tobias Hunger's avatar
Tobias Hunger committed
134
RunConfiguration *MaemoRunConfigurationFactory::create(Target *parent, const Core::Id id)
135 136 137
{
    if (!canCreate(parent, id))
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
138
    return new MaemoRunConfiguration(parent, id, pathFromId(id));
139 140 141 142 143 144 145
}

RunConfiguration *MaemoRunConfigurationFactory::restore(Target *parent,
    const QVariantMap &map)
{
    if (!canRestore(parent, map))
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
146 147

    Core::Id id = ProjectExplorer::idFromMap(map);
148
    MaemoRunConfiguration *rc
Tobias Hunger's avatar
Tobias Hunger committed
149
        = new MaemoRunConfiguration(parent, id, pathFromId(id));
150 151 152 153 154
    if (rc->fromMap(map))
        return rc;

    delete rc;
    return 0;
155 156
}

157
RunConfiguration *MaemoRunConfigurationFactory::clone(Target *parent, RunConfiguration *source)
158 159 160 161
{
    if (!canClone(parent, source))
        return 0;

162
    MaemoRunConfiguration *old = static_cast<MaemoRunConfiguration *>(source);
Tobias Hunger's avatar
Tobias Hunger committed
163 164 165 166 167
    return new MaemoRunConfiguration(parent, old);
}

bool MaemoRunConfigurationFactory::canHandle(Target *t) const
{
Tobias Hunger's avatar
Tobias Hunger committed
168
    if (!t->project()->supportsKit(t->kit()))
Tobias Hunger's avatar
Tobias Hunger committed
169 170 171
        return false;
    if (!qobject_cast<Qt4Project *>(t->project()))
        return false;
Tobias Hunger's avatar
Tobias Hunger committed
172
    Core::Id devType = DeviceTypeKitInformation::deviceTypeId(t->kit());
173
    return devType == Maemo5OsType || devType == HarmattanOsType;
Tobias Hunger's avatar
Tobias Hunger committed
174 175 176 177 178 179 180 181 182 183
}

QList<RunConfiguration *> MaemoRunConfigurationFactory::runConfigurationsForNode(Target *t, Node *n)
{
    QList<ProjectExplorer::RunConfiguration *> result;
    foreach (ProjectExplorer::RunConfiguration *rc, t->runConfigurations())
        if (MaemoRunConfiguration *mrc = qobject_cast<MaemoRunConfiguration *>(rc))
            if (mrc->proFilePath() == n->path())
                result << rc;
    return result;
184 185 186 187 188 189 190 191 192 193 194 195
}


MaemoRunControlFactory::MaemoRunControlFactory(QObject *parent)
    : IRunControlFactory(parent)
{
}

MaemoRunControlFactory::~MaemoRunControlFactory()
{
}

196
bool MaemoRunControlFactory::canRun(RunConfiguration *runConfiguration, RunMode mode) const
197
{
198 199
    const MaemoRunConfiguration * const maemoRunConfig
        = qobject_cast<MaemoRunConfiguration *>(runConfiguration);
200
    if (!maemoRunConfig || !maemoRunConfig->isEnabled())
201
        return false;
202
    return maemoRunConfig->hasEnoughFreePorts(mode);
203 204
}

205
RunControl* MaemoRunControlFactory::create(RunConfiguration *runConfig, RunMode mode, QString *errorMessage)
206
{
207
    Q_ASSERT(canRun(runConfig, mode));
208 209

    MaemoRunConfiguration *rc = qobject_cast<MaemoRunConfiguration *>(runConfig);
210
    Q_ASSERT(rc);
211

212 213 214 215 216
    if (mode == NormalRunMode) {
        RemoteLinuxRunControl * const runControl = new RemoteLinuxRunControl(rc);
        setHelperActions(runControl, rc, runControl);
        return runControl;
    }
217

218
    const DebuggerStartParameters params = LinuxDeviceDebugSupport::startParameters(rc);
219
    DebuggerRunControl * const runControl = DebuggerPlugin::createDebugger(params, rc, errorMessage);
220 221
    if (!runControl)
        return 0;
222 223
    LinuxDeviceDebugSupport * const debugSupport
            = new LinuxDeviceDebugSupport(rc, runControl->engine());
224
    setHelperActions(debugSupport, rc, runControl);
225 226
    connect(runControl, SIGNAL(finished()), debugSupport, SLOT(handleDebuggingFinished()));
    return runControl;
227 228 229 230 231 232 233 234
}

QString MaemoRunControlFactory::displayName() const
{
    return tr("Run on device");
}

    } // namespace Internal
235
} // namespace Madde