maemorunfactories.cpp 6.02 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(const QString &id)
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
{
    if (!id.startsWith(MAEMO_RC_ID_PREFIX))
        return QString();
    return id.mid(QString(MAEMO_RC_ID_PREFIX).size());
}

} // namespace

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

MaemoRunConfigurationFactory::~MaemoRunConfigurationFactory()
{
}

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

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

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

QStringList MaemoRunConfigurationFactory::availableCreationIds(Target *parent) const
{
101 102
    if (AbstractQt4MaemoTarget *t = qobject_cast<AbstractQt4MaemoTarget *>(parent))
        return t->qt4Project()->applicationProFilePathes(QLatin1String(MAEMO_RC_ID_PREFIX));
103 104 105
    return QStringList();
}

kh1's avatar
kh1 committed
106
QString MaemoRunConfigurationFactory::displayNameForId(const QString &id) const
107
{
Christian Kandeler's avatar
Christian Kandeler committed
108
    return QFileInfo(pathFromId(id)).completeBaseName()
109
        + QLatin1String(" (on remote Maemo device)");
110 111 112 113 114 115 116
}

RunConfiguration *MaemoRunConfigurationFactory::create(Target *parent,
    const QString &id)
{
    if (!canCreate(parent, id))
        return 0;
117
    return new MaemoRunConfiguration(qobject_cast<AbstractQt4MaemoTarget *>(parent),
Christian Kandeler's avatar
Christian Kandeler committed
118
        pathFromId(id));
119 120 121 122 123 124 125
}

RunConfiguration *MaemoRunConfigurationFactory::restore(Target *parent,
    const QVariantMap &map)
{
    if (!canRestore(parent, map))
        return 0;
126 127
    MaemoRunConfiguration *rc
        = new MaemoRunConfiguration(qobject_cast<AbstractQt4MaemoTarget *>(parent), QString());
128 129 130 131 132
    if (rc->fromMap(map))
        return rc;

    delete rc;
    return 0;
133 134 135 136 137 138 139 140
}

RunConfiguration *MaemoRunConfigurationFactory::clone(Target *parent,
    RunConfiguration *source)
{
    if (!canClone(parent, source))
        return 0;

141 142
    MaemoRunConfiguration *old = static_cast<MaemoRunConfiguration *>(source);
    return new MaemoRunConfiguration(static_cast<AbstractQt4MaemoTarget *>(parent), old);
143 144 145 146 147 148 149 150 151 152 153 154 155
}

// #pragma mark -- MaemoRunControlFactory

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

MaemoRunControlFactory::~MaemoRunControlFactory()
{
}

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

165
RunControl* MaemoRunControlFactory::create(RunConfiguration *runConfig, RunMode mode)
166
{
167
    Q_ASSERT(mode == NormalRunMode || mode == DebugRunMode);
168
    Q_ASSERT(canRun(runConfig, mode));
169 170

    MaemoRunConfiguration *rc = qobject_cast<MaemoRunConfiguration *>(runConfig);
171
    Q_ASSERT(rc);
172

173
    if (mode == NormalRunMode)
174
        return new MaemoRunControl(rc);
175 176 177 178

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

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

191
RunConfigWidget *MaemoRunControlFactory::createConfigurationWidget(RunConfiguration *config)
192 193 194 195 196 197
{
    Q_UNUSED(config)
    return 0;
}

    } // namespace Internal
198
} // namespace Madde