maemorunfactories.cpp 6.95 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 31
#include "maemorunfactories.h"

#include "maemoconstants.h"
ck's avatar
ck committed
32
#include "maemodebugsupport.h"
33
#include "maemoremotemountsmodel.h"
34
#include "maemorunconfiguration.h"
35 36
#include "maemoruncontrol.h"

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
using namespace Debugger;
49
using namespace ProjectExplorer;
50
using namespace Qt4ProjectManager;
51
using namespace RemoteLinux;
52

53
namespace Madde {
54
namespace Internal {
55 56 57

namespace {

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

} // namespace

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

MaemoRunConfigurationFactory::~MaemoRunConfigurationFactory()
{
}

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

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

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

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

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

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

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

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

    delete rc;
    return 0;
140 141
}

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

147
    MaemoRunConfiguration *old = static_cast<MaemoRunConfiguration *>(source);
Tobias Hunger's avatar
Tobias Hunger committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
    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());
    return devType == Core::Id(Maemo5OsType) || devType == Core::Id(HarmattanOsType)
            || devType == Core::Id(MeeGoOsType);
}

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

// #pragma mark -- MaemoRunControlFactory

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 MaemoRunControl(rc);
201 202 203 204

    const DebuggerStartParameters params
        = AbstractRemoteLinuxDebugSupport::startParameters(rc);
    DebuggerRunControl * const runControl = DebuggerPlugin::createDebugger(params, rc);
205 206
    if (!runControl)
        return 0;
207 208 209
    MaemoDebugSupport *debugSupport = new MaemoDebugSupport(rc, runControl->engine());
    connect(runControl, SIGNAL(finished()), debugSupport, SLOT(handleDebuggingFinished()));
    return runControl;
210 211 212 213 214 215 216 217
}

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

    } // namespace Internal
218
} // namespace Madde