remotelinuxrunconfigurationfactory.cpp 4.89 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29 30
#include "remotelinuxrunconfigurationfactory.h"

Tobias Hunger's avatar
Tobias Hunger committed
31
#include "remotelinux_constants.h"
32 33
#include "remotelinuxrunconfiguration.h"

34
#include <projectexplorer/buildtargetinfo.h>
Tobias Hunger's avatar
Tobias Hunger committed
35
#include <projectexplorer/kitinformation.h>
36
#include <projectexplorer/project.h>
Tobias Hunger's avatar
Tobias Hunger committed
37
#include <projectexplorer/target.h>
38 39
#include <utils/qtcassert.h>

40 41
#include <QFileInfo>
#include <QString>
42 43 44 45 46 47 48

using namespace ProjectExplorer;

namespace RemoteLinux {
namespace Internal {

namespace {
49
QString pathFromId(Core::Id id)
50
{
51
    QByteArray idStr = id.name();
52
    if (!idStr.startsWith(RemoteLinuxRunConfiguration::IdPrefix))
53
        return QString();
54
    return QString::fromUtf8(idStr.mid(strlen(RemoteLinuxRunConfiguration::IdPrefix)));
55 56 57 58 59
}

} // namespace

RemoteLinuxRunConfigurationFactory::RemoteLinuxRunConfigurationFactory(QObject *parent)
60 61 62 63
    : IRunConfigurationFactory(parent)
{
    setObjectName(QLatin1String("RemoteLinuxRunConfigurationFactory"));
}
64 65 66 67 68

RemoteLinuxRunConfigurationFactory::~RemoteLinuxRunConfigurationFactory()
{
}

Tobias Hunger's avatar
Tobias Hunger committed
69
bool RemoteLinuxRunConfigurationFactory::canCreate(Target *parent, const Core::Id id) const
70
{
Tobias Hunger's avatar
Tobias Hunger committed
71
    if (!canHandle(parent))
72
        return false;
73
    return !parent->applicationTargets().targetForProject(pathFromId(id)).isEmpty();
74 75 76 77
}

bool RemoteLinuxRunConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const
{
Tobias Hunger's avatar
Tobias Hunger committed
78 79
    if (!canHandle(parent))
        return false;
80
    return idFromMap(map).name().startsWith(RemoteLinuxRunConfiguration::IdPrefix);
81 82 83 84
}

bool RemoteLinuxRunConfigurationFactory::canClone(Target *parent, RunConfiguration *source) const
{
85 86
    const RemoteLinuxRunConfiguration * const rlrc
            = qobject_cast<RemoteLinuxRunConfiguration *>(source);
87
    return rlrc && canCreate(parent, source->id());
88 89
}

90
QList<Core::Id> RemoteLinuxRunConfigurationFactory::availableCreationIds(Target *parent) const
91
{
92
    QList<Core::Id> result;
Tobias Hunger's avatar
Tobias Hunger committed
93 94 95
    if (!canHandle(parent))
        return result;

96
    const Core::Id base = Core::Id(RemoteLinuxRunConfiguration::IdPrefix);
97
    foreach (const BuildTargetInfo &bti, parent->applicationTargets().list)
98
        result << base.withSuffix(bti.projectFilePath.toString());
99
    return result;
100 101
}

102
QString RemoteLinuxRunConfigurationFactory::displayNameForId(const Core::Id id) const
103 104
{
    return QFileInfo(pathFromId(id)).completeBaseName()
105
        + tr(" (on Remote Generic Linux Host)");
106 107
}

108
RunConfiguration *RemoteLinuxRunConfigurationFactory::doCreate(Target *parent, const Core::Id id)
109
{
Tobias Hunger's avatar
Tobias Hunger committed
110
    return new RemoteLinuxRunConfiguration(parent, id, pathFromId(id));
111 112
}

113 114
RunConfiguration *RemoteLinuxRunConfigurationFactory::doRestore(Target *parent,
                                                                const QVariantMap &map)
115
{
116 117 118
    Q_UNUSED(map);
    return new RemoteLinuxRunConfiguration(parent,
                                           Core::Id(RemoteLinuxRunConfiguration::IdPrefix), QString());
119 120 121 122 123 124 125
}

RunConfiguration *RemoteLinuxRunConfigurationFactory::clone(Target *parent,
    RunConfiguration *source)
{
    QTC_ASSERT(canClone(parent, source), return 0);
    RemoteLinuxRunConfiguration *old = static_cast<RemoteLinuxRunConfiguration *>(source);
Tobias Hunger's avatar
Tobias Hunger committed
126 127 128
    return new RemoteLinuxRunConfiguration(parent, old);
}

129
bool RemoteLinuxRunConfigurationFactory::canHandle(const Target *target) const
Tobias Hunger's avatar
Tobias Hunger committed
130
{
131
    if (!target->project()->supportsKit(target->kit()))
Tobias Hunger's avatar
Tobias Hunger committed
132
        return false;
133
    const Core::Id deviceType = DeviceTypeKitInformation::deviceTypeId(target->kit());
134
    return deviceType == RemoteLinux::Constants::GenericLinuxOsType;
Tobias Hunger's avatar
Tobias Hunger committed
135 136
}

137 138
} // namespace Internal
} // namespace RemoteLinux