maemorunfactories.cpp 6.33 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
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
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
** If you have questions regarding the use of this file, please contact
28
** Nokia at qt-info@nokia.com.
29
**
hjk's avatar
hjk committed
30
**************************************************************************/
31 32 33
#include "maemorunfactories.h"

#include "maemoconstants.h"
ck's avatar
ck committed
34
#include "maemodebugsupport.h"
35
#include "maemoremotemountsmodel.h"
36
#include "maemorunconfiguration.h"
37
#include "maemoruncontrol.h"
38 39
#include "maemotoolchain.h"
#include "qt4maemotarget.h"
40

41
#include <debugger/debuggerconstants.h>
42
#include <debugger/debuggerstartparameters.h>
43 44 45
#include <debugger/debuggerplugin.h>
#include <debugger/debuggerrunner.h>
#include <projectexplorer/projectexplorerconstants.h>
46 47
#include <qt4projectmanager/qt4project.h>

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
{
60 61 62
    QString idStr = QString::fromUtf8(id.name());
    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 70 71 72 73 74 75 76 77
}

} // namespace

MaemoRunConfigurationFactory::MaemoRunConfigurationFactory(QObject *parent)
    : IRunConfigurationFactory(parent)
{
}

MaemoRunConfigurationFactory::~MaemoRunConfigurationFactory()
{
}

78
bool MaemoRunConfigurationFactory::canCreate(Target *parent, Core::Id id) const
79
{
Christian Kandeler's avatar
Christian Kandeler committed
80 81
    return qobject_cast<Qt4BaseTarget *>(parent)->qt4Project()
        ->hasApplicationProFile(pathFromId(id));
82 83 84 85 86
}

bool MaemoRunConfigurationFactory::canRestore(Target *parent,
    const QVariantMap &map) const
{
87
    Q_UNUSED(parent);
88
    return qobject_cast<AbstractQt4MaemoTarget *>(parent)
89
        && QString::fromUtf8(ProjectExplorer::idFromMap(map).name()).startsWith(QLatin1String(MAEMO_RC_ID));
90 91 92 93 94
}

bool MaemoRunConfigurationFactory::canClone(Target *parent,
    RunConfiguration *source) const
{
95 96
    const RemoteLinuxRunConfiguration * const rlrc
            = qobject_cast<RemoteLinuxRunConfiguration *>(source);
97 98
    QString idStr = QString::fromLatin1(source->id().name()) + QLatin1Char('.') + rlrc->proFilePath();
    return rlrc && canCreate(parent, Core::Id(idStr.toUtf8().constData()));
99 100
}

101
QList<Core::Id> MaemoRunConfigurationFactory::availableCreationIds(Target *parent) const
102
{
103 104 105 106 107 108 109
    QList<Core::Id> result;
    if (AbstractQt4MaemoTarget *t = qobject_cast<AbstractQt4MaemoTarget *>(parent)) {
        QStringList proFiles = t->qt4Project()->applicationProFilePathes(QLatin1String(MAEMO_RC_ID_PREFIX));
        foreach (const QString &pf, proFiles)
            result << Core::Id(pf.toUtf8().constData());
    }
    return result;
110 111
}

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

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

RunConfiguration *MaemoRunConfigurationFactory::restore(Target *parent,
    const QVariantMap &map)
{
    if (!canRestore(parent, map))
        return 0;
131 132
    MaemoRunConfiguration *rc
        = new MaemoRunConfiguration(qobject_cast<AbstractQt4MaemoTarget *>(parent), QString());
133 134 135 136 137
    if (rc->fromMap(map))
        return rc;

    delete rc;
    return 0;
138 139
}

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

145 146
    MaemoRunConfiguration *old = static_cast<MaemoRunConfiguration *>(source);
    return new MaemoRunConfiguration(static_cast<AbstractQt4MaemoTarget *>(parent), old);
147 148 149 150 151 152 153 154 155 156 157 158 159
}

// #pragma mark -- MaemoRunControlFactory

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

MaemoRunControlFactory::~MaemoRunControlFactory()
{
}

160
bool MaemoRunControlFactory::canRun(RunConfiguration *runConfiguration, RunMode mode) const
161
{
162 163
    const MaemoRunConfiguration * const maemoRunConfig
        = qobject_cast<MaemoRunConfiguration *>(runConfiguration);
164
    if (!maemoRunConfig || !maemoRunConfig->isEnabled())
165
        return false;
166
    return maemoRunConfig->hasEnoughFreePorts(mode);
167 168
}

169
RunControl* MaemoRunControlFactory::create(RunConfiguration *runConfig, RunMode mode)
170
{
171
    Q_ASSERT(mode == NormalRunMode || mode == DebugRunMode);
172
    Q_ASSERT(canRun(runConfig, mode));
173 174

    MaemoRunConfiguration *rc = qobject_cast<MaemoRunConfiguration *>(runConfig);
175
    Q_ASSERT(rc);
176

177
    if (mode == NormalRunMode)
178
        return new MaemoRunControl(rc);
179 180 181 182

    const DebuggerStartParameters params
        = AbstractRemoteLinuxDebugSupport::startParameters(rc);
    DebuggerRunControl * const runControl = DebuggerPlugin::createDebugger(params, rc);
183 184
    if (!runControl)
        return 0;
185 186 187
    MaemoDebugSupport *debugSupport = new MaemoDebugSupport(rc, runControl->engine());
    connect(runControl, SIGNAL(finished()), debugSupport, SLOT(handleDebuggingFinished()));
    return runControl;
188 189 190 191 192 193 194
}

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

195
RunConfigWidget *MaemoRunControlFactory::createConfigurationWidget(RunConfiguration *config)
196 197 198 199 200 201
{
    Q_UNUSED(config)
    return 0;
}

    } // namespace Internal
202
} // namespace Madde