maemorunfactories.cpp 7.46 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 43 44
#include <projectexplorer/profileinformation.h>
#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
}

} // namespace

MaemoRunConfigurationFactory::MaemoRunConfigurationFactory(QObject *parent)
Tobias Hunger's avatar
Tobias Hunger committed
72 73
    : QmakeRunConfigurationFactory(parent)
{ setObjectName(QLatin1String("MaemoRunConfigurationFactory")); }
74 75 76 77 78

MaemoRunConfigurationFactory::~MaemoRunConfigurationFactory()
{
}

Tobias Hunger's avatar
Tobias Hunger committed
79
bool MaemoRunConfigurationFactory::canCreate(Target *parent, const Core::Id id) const
80
{
Tobias Hunger's avatar
Tobias Hunger committed
81 82 83
    if (!canHandle(parent))
        return false;
    return static_cast<Qt4Project *>(parent->project())->hasApplicationProFile(pathFromId(id));
84 85 86 87 88
}

bool MaemoRunConfigurationFactory::canRestore(Target *parent,
    const QVariantMap &map) const
{
Tobias Hunger's avatar
Tobias Hunger committed
89 90
    return canHandle(parent)
        && ProjectExplorer::idFromMap(map).toString().startsWith(QLatin1String(MAEMO_RC_ID_PREFIX));
91 92 93 94 95
}

bool MaemoRunConfigurationFactory::canClone(Target *parent,
    RunConfiguration *source) const
{
Tobias Hunger's avatar
Tobias Hunger committed
96 97
    if (!canHandle(parent))
        return false;
98 99
    const RemoteLinuxRunConfiguration * const rlrc
            = qobject_cast<RemoteLinuxRunConfiguration *>(source);
100
    QString idStr = QString::fromLatin1(source->id().name()) + QLatin1Char('.') + rlrc->proFilePath();
Tobias Hunger's avatar
Tobias Hunger committed
101
    return rlrc && canCreate(parent, Core::Id(idStr));
102 103
}

104
QList<Core::Id> MaemoRunConfigurationFactory::availableCreationIds(Target *parent) const
105
{
106
    QList<Core::Id> result;
Tobias Hunger's avatar
Tobias Hunger committed
107 108 109 110 111
    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);
112
    return result;
113 114
}

Tobias Hunger's avatar
Tobias Hunger committed
115
QString MaemoRunConfigurationFactory::displayNameForId(const Core::Id id) const
116
{
Christian Kandeler's avatar
Christian Kandeler committed
117
    return QFileInfo(pathFromId(id)).completeBaseName()
118
        + QLatin1String(" (on remote Maemo device)");
119 120
}

Tobias Hunger's avatar
Tobias Hunger committed
121
RunConfiguration *MaemoRunConfigurationFactory::create(Target *parent, const Core::Id id)
122 123 124
{
    if (!canCreate(parent, id))
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
125
    return new MaemoRunConfiguration(parent, id, pathFromId(id));
126 127 128 129 130 131 132
}

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

    Core::Id id = ProjectExplorer::idFromMap(map);
135
    MaemoRunConfiguration *rc
Tobias Hunger's avatar
Tobias Hunger committed
136
        = new MaemoRunConfiguration(parent, id, pathFromId(id));
137 138 139 140 141
    if (rc->fromMap(map))
        return rc;

    delete rc;
    return 0;
142 143
}

144
RunConfiguration *MaemoRunConfigurationFactory::clone(Target *parent, RunConfiguration *source)
145 146 147 148
{
    if (!canClone(parent, source))
        return 0;

149
    MaemoRunConfiguration *old = static_cast<MaemoRunConfiguration *>(source);
Tobias Hunger's avatar
Tobias Hunger committed
150 151 152 153 154 155 156 157 158 159
    return new MaemoRunConfiguration(parent, old);
}

bool MaemoRunConfigurationFactory::canHandle(Target *t) const
{
    if (!t->project()->supportsProfile(t->profile()))
        return false;
    if (!qobject_cast<Qt4Project *>(t->project()))
        return false;
    Core::Id devType = DeviceTypeProfileInformation::deviceTypeId(t->profile());
160
    return devType == Maemo5OsType || devType == HarmattanOsType;
Tobias Hunger's avatar
Tobias Hunger committed
161 162 163 164 165 166 167 168 169 170
}

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;
171 172 173 174 175 176 177 178 179 180 181 182
}


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

MaemoRunControlFactory::~MaemoRunControlFactory()
{
}

183
bool MaemoRunControlFactory::canRun(RunConfiguration *runConfiguration, RunMode mode) const
184
{
185 186
    const MaemoRunConfiguration * const maemoRunConfig
        = qobject_cast<MaemoRunConfiguration *>(runConfiguration);
187
    if (!maemoRunConfig || !maemoRunConfig->isEnabled())
188
        return false;
189
    return maemoRunConfig->hasEnoughFreePorts(mode);
190 191
}

192
RunControl* MaemoRunControlFactory::create(RunConfiguration *runConfig, RunMode mode)
193
{
194
    Q_ASSERT(canRun(runConfig, mode));
195 196

    MaemoRunConfiguration *rc = qobject_cast<MaemoRunConfiguration *>(runConfig);
197
    Q_ASSERT(rc);
198

199
    if (mode == NormalRunMode)
200
        return new RemoteLinuxRunControl(rc);
201

202
    const DebuggerStartParameters params = LinuxDeviceDebugSupport::startParameters(rc);
203
    DebuggerRunControl * const runControl = DebuggerPlugin::createDebugger(params, rc);
204 205
    if (!runControl)
        return 0;
206 207 208 209 210 211 212 213 214
    LinuxDeviceDebugSupport * const debugSupport
            = new LinuxDeviceDebugSupport(rc, runControl->engine());
    const Profile * const profile = runConfig->target()->profile();
    MaemoPreRunAction * const preRunAction = new MaemoPreRunAction(
            DeviceProfileInformation::device(profile), MaemoGlobal::maddeRoot(profile),
            rc->remoteMounts()->mountSpecs(), rc);
    MaemoPostRunAction * const postRunAction = new MaemoPostRunAction(preRunAction->mounter(), rc);
    debugSupport->setApplicationRunnerPreRunAction(preRunAction);
    debugSupport->setApplicationRunnerPostRunAction(postRunAction);
215 216
    connect(runControl, SIGNAL(finished()), debugSupport, SLOT(handleDebuggingFinished()));
    return runControl;
217 218 219 220 221 222 223 224
}

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

    } // namespace Internal
225
} // namespace Madde