remotelinuxrunconfigurationfactory.cpp 5.77 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 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
#include "remotelinuxcustomrunconfiguration.h"
33 34
#include "remotelinuxrunconfiguration.h"

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

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

using namespace ProjectExplorer;

namespace RemoteLinux {
namespace Internal {

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

} // namespace

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

RemoteLinuxRunConfigurationFactory::~RemoteLinuxRunConfigurationFactory()
{
}

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

bool RemoteLinuxRunConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const
{
Tobias Hunger's avatar
Tobias Hunger committed
80 81
    if (!canHandle(parent))
        return false;
82 83 84
    const Core::Id id = idFromMap(map);
    return id == RemoteLinuxCustomRunConfiguration::runConfigId()
            || id.name().startsWith(RemoteLinuxRunConfiguration::IdPrefix);
85 86 87 88
}

bool RemoteLinuxRunConfigurationFactory::canClone(Target *parent, RunConfiguration *source) const
{
89 90
    const RemoteLinuxRunConfiguration * const rlrc
            = qobject_cast<RemoteLinuxRunConfiguration *>(source);
91
    return rlrc && canCreate(parent, source->id());
92 93
}

94
QList<Core::Id> RemoteLinuxRunConfigurationFactory::availableCreationIds(Target *parent, CreationMode mode) const
95
{
96
    Q_UNUSED(mode)
97
    QList<Core::Id> result;
Tobias Hunger's avatar
Tobias Hunger committed
98 99 100
    if (!canHandle(parent))
        return result;

101
    const Core::Id base = Core::Id(RemoteLinuxRunConfiguration::IdPrefix);
102
    foreach (const BuildTargetInfo &bti, parent->applicationTargets().list)
103
        result << base.withSuffix(bti.projectFilePath.toString());
104
    result << RemoteLinuxCustomRunConfiguration::runConfigId();
105
    return result;
106 107
}

108
QString RemoteLinuxRunConfigurationFactory::displayNameForId(const Core::Id id) const
109
{
110 111
    if (id == RemoteLinuxCustomRunConfiguration::runConfigId())
        return RemoteLinuxCustomRunConfiguration::runConfigDefaultDisplayName();
112
    return QFileInfo(pathFromId(id)).completeBaseName()
113
        + QLatin1Char(' ') + tr("(on Remote Generic Linux Host)");
114 115
}

116
RunConfiguration *RemoteLinuxRunConfigurationFactory::doCreate(Target *parent, const Core::Id id)
117
{
118 119
    if (id == RemoteLinuxCustomRunConfiguration::runConfigId())
        return new RemoteLinuxCustomRunConfiguration(parent);
Tobias Hunger's avatar
Tobias Hunger committed
120
    return new RemoteLinuxRunConfiguration(parent, id, pathFromId(id));
121 122
}

123 124
RunConfiguration *RemoteLinuxRunConfigurationFactory::doRestore(Target *parent,
                                                                const QVariantMap &map)
125
{
126 127
    if (idFromMap(map) == RemoteLinuxCustomRunConfiguration::runConfigId())
        return new RemoteLinuxCustomRunConfiguration(parent);
128 129
    return new RemoteLinuxRunConfiguration(parent,
                                           Core::Id(RemoteLinuxRunConfiguration::IdPrefix), QString());
130 131 132 133 134 135
}

RunConfiguration *RemoteLinuxRunConfigurationFactory::clone(Target *parent,
    RunConfiguration *source)
{
    QTC_ASSERT(canClone(parent, source), return 0);
136 137
    if (RemoteLinuxCustomRunConfiguration *old = qobject_cast<RemoteLinuxCustomRunConfiguration *>(source))
        return new RemoteLinuxCustomRunConfiguration(parent, old);
138
    RemoteLinuxRunConfiguration *old = static_cast<RemoteLinuxRunConfiguration *>(source);
Tobias Hunger's avatar
Tobias Hunger committed
139 140 141
    return new RemoteLinuxRunConfiguration(parent, old);
}

142
bool RemoteLinuxRunConfigurationFactory::canHandle(const Target *target) const
Tobias Hunger's avatar
Tobias Hunger committed
143
{
144
    if (!target->project()->supportsKit(target->kit()))
Tobias Hunger's avatar
Tobias Hunger committed
145
        return false;
146
    const Core::Id deviceType = DeviceTypeKitInformation::deviceTypeId(target->kit());
147
    return deviceType == RemoteLinux::Constants::GenericLinuxOsType;
Tobias Hunger's avatar
Tobias Hunger committed
148 149
}

150 151
} // namespace Internal
} // namespace RemoteLinux