2011-05-31 12:47:53 +02:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2011-05-31 12:47:53 +02:00
|
|
|
**
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
**
|
|
|
|
** 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, Nokia gives you certain additional
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** 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.
|
|
|
|
**
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2011-05-31 12:47:53 +02:00
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
#include "linuxdeviceconfiguration.h"
|
|
|
|
|
2011-08-02 12:20:16 +02:00
|
|
|
#include "portlist.h"
|
2011-07-25 11:55:00 +02:00
|
|
|
#include "remotelinux_constants.h"
|
|
|
|
|
2011-08-02 12:20:16 +02:00
|
|
|
#include <utils/ssh/sshconnection.h>
|
|
|
|
|
2011-05-31 12:47:53 +02:00
|
|
|
#include <QtCore/QSettings>
|
|
|
|
#include <QtGui/QDesktopServices>
|
|
|
|
|
2011-08-02 12:20:16 +02:00
|
|
|
using namespace Utils;
|
|
|
|
typedef SshConnectionParameters::AuthenticationType AuthType;
|
2011-05-31 12:47:53 +02:00
|
|
|
|
|
|
|
namespace RemoteLinux {
|
2011-08-02 12:20:16 +02:00
|
|
|
namespace Internal {
|
2011-05-31 12:47:53 +02:00
|
|
|
namespace {
|
|
|
|
const QLatin1String NameKey("Name");
|
2011-06-07 12:12:30 +02:00
|
|
|
const QLatin1String OldOsVersionKey("OsVersion"); // Outdated, only use for upgrading.
|
|
|
|
const QLatin1String OsTypeKey("OsType");
|
2011-05-31 12:47:53 +02:00
|
|
|
const QLatin1String TypeKey("Type");
|
|
|
|
const QLatin1String HostKey("Host");
|
|
|
|
const QLatin1String SshPortKey("SshPort");
|
|
|
|
const QLatin1String PortsSpecKey("FreePortsSpec");
|
|
|
|
const QLatin1String UserNameKey("Uname");
|
|
|
|
const QLatin1String AuthKey("Authentication");
|
|
|
|
const QLatin1String KeyFileKey("KeyFile");
|
|
|
|
const QLatin1String PasswordKey("Password");
|
|
|
|
const QLatin1String TimeoutKey("Timeout");
|
|
|
|
const QLatin1String IsDefaultKey("IsDefault");
|
|
|
|
const QLatin1String InternalIdKey("InternalId");
|
2011-11-25 12:23:57 +01:00
|
|
|
const QLatin1String AttributesKey("Attributes");
|
2011-05-31 12:47:53 +02:00
|
|
|
|
2011-08-02 12:20:16 +02:00
|
|
|
const AuthType DefaultAuthType(SshConnectionParameters::AuthenticationByKey);
|
2011-06-21 16:52:48 +02:00
|
|
|
const int DefaultTimeout(10);
|
2011-08-02 12:20:16 +02:00
|
|
|
const LinuxDeviceConfiguration::DeviceType DefaultDeviceType(LinuxDeviceConfiguration::Hardware);
|
2011-05-31 12:47:53 +02:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2011-08-02 12:20:16 +02:00
|
|
|
class LinuxDeviceConfigurationPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LinuxDeviceConfigurationPrivate(const SshConnectionParameters &sshParameters)
|
|
|
|
: sshParameters(sshParameters)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SshConnectionParameters sshParameters;
|
2011-11-16 09:37:29 +00:00
|
|
|
QString displayName;
|
2011-08-02 12:20:16 +02:00
|
|
|
QString osType;
|
|
|
|
LinuxDeviceConfiguration::DeviceType deviceType;
|
|
|
|
PortList freePorts;
|
|
|
|
bool isDefault;
|
2011-08-15 10:36:53 +02:00
|
|
|
LinuxDeviceConfiguration::Origin origin;
|
2011-08-02 12:20:16 +02:00
|
|
|
LinuxDeviceConfiguration::Id internalId;
|
2011-11-25 12:23:57 +01:00
|
|
|
QVariantHash attributes;
|
2011-08-02 12:20:16 +02:00
|
|
|
};
|
2011-05-31 12:47:53 +02:00
|
|
|
|
2011-08-02 12:20:16 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
|
|
|
using namespace Internal;
|
|
|
|
|
|
|
|
LinuxDeviceConfiguration::~LinuxDeviceConfiguration()
|
|
|
|
{
|
2011-09-16 11:33:48 +02:00
|
|
|
delete d;
|
2011-08-02 12:20:16 +02:00
|
|
|
}
|
2011-05-31 12:47:53 +02:00
|
|
|
|
|
|
|
LinuxDeviceConfiguration::Ptr LinuxDeviceConfiguration::create(const QSettings &settings,
|
|
|
|
Id &nextId)
|
|
|
|
{
|
|
|
|
return Ptr(new LinuxDeviceConfiguration(settings, nextId));
|
|
|
|
}
|
|
|
|
|
|
|
|
LinuxDeviceConfiguration::Ptr LinuxDeviceConfiguration::create(const ConstPtr &other)
|
|
|
|
{
|
|
|
|
return Ptr(new LinuxDeviceConfiguration(other));
|
|
|
|
}
|
|
|
|
|
2011-06-21 16:52:48 +02:00
|
|
|
LinuxDeviceConfiguration::Ptr LinuxDeviceConfiguration::create(const QString &name,
|
2011-06-22 10:00:50 +02:00
|
|
|
const QString &osType, DeviceType deviceType, const PortList &freePorts,
|
2011-11-25 12:23:57 +01:00
|
|
|
const SshConnectionParameters &sshParams, const QVariantHash &attributes, Origin origin)
|
2011-05-31 12:47:53 +02:00
|
|
|
{
|
2011-11-25 12:23:57 +01:00
|
|
|
return Ptr(new LinuxDeviceConfiguration(name, osType, deviceType, freePorts, sshParams,
|
|
|
|
attributes, origin));
|
2011-05-31 12:47:53 +02:00
|
|
|
}
|
|
|
|
|
2011-06-21 16:52:48 +02:00
|
|
|
LinuxDeviceConfiguration::LinuxDeviceConfiguration(const QString &name, const QString &osType,
|
2011-08-15 10:36:53 +02:00
|
|
|
DeviceType deviceType, const PortList &freePorts, const SshConnectionParameters &sshParams,
|
2011-11-25 12:23:57 +01:00
|
|
|
const QVariantHash &attributes, Origin origin)
|
2011-09-16 11:33:48 +02:00
|
|
|
: d(new LinuxDeviceConfigurationPrivate(sshParams))
|
2011-05-31 12:47:53 +02:00
|
|
|
{
|
2011-11-16 09:37:29 +00:00
|
|
|
d->displayName = name;
|
2011-09-16 11:33:48 +02:00
|
|
|
d->osType = osType;
|
|
|
|
d->deviceType = deviceType;
|
|
|
|
d->freePorts = freePorts;
|
|
|
|
d->isDefault = false;
|
|
|
|
d->origin = origin;
|
2011-11-25 12:23:57 +01:00
|
|
|
d->attributes = attributes;
|
2011-05-31 12:47:53 +02:00
|
|
|
}
|
|
|
|
|
2011-08-02 12:20:16 +02:00
|
|
|
LinuxDeviceConfiguration::LinuxDeviceConfiguration(const QSettings &settings, Id &nextId)
|
2011-09-16 11:33:48 +02:00
|
|
|
: d(new LinuxDeviceConfigurationPrivate(SshConnectionParameters::NoProxy))
|
2011-05-31 12:47:53 +02:00
|
|
|
{
|
2011-09-16 11:33:48 +02:00
|
|
|
d->origin = ManuallyAdded;
|
2011-11-16 09:37:29 +00:00
|
|
|
d->displayName = settings.value(NameKey).toString();
|
2011-09-16 11:33:48 +02:00
|
|
|
d->osType = settings.value(OsTypeKey).toString();
|
|
|
|
d->deviceType = static_cast<DeviceType>(settings.value(TypeKey, DefaultDeviceType).toInt());
|
|
|
|
d->isDefault = settings.value(IsDefaultKey, false).toBool();
|
|
|
|
d->internalId = settings.value(InternalIdKey, nextId).toULongLong();
|
2011-08-02 12:20:16 +02:00
|
|
|
|
2011-09-16 11:33:48 +02:00
|
|
|
if (d->internalId == nextId)
|
2011-05-31 12:47:53 +02:00
|
|
|
++nextId;
|
2011-06-07 12:12:30 +02:00
|
|
|
|
2011-11-25 12:23:57 +01:00
|
|
|
d->attributes = settings.value(AttributesKey).toHash();
|
|
|
|
|
2011-06-07 12:12:30 +02:00
|
|
|
// Convert from version < 2.3.
|
2011-09-16 11:33:48 +02:00
|
|
|
if (d->osType.isEmpty()) {
|
2011-06-07 12:12:30 +02:00
|
|
|
const int oldOsType = settings.value(OldOsVersionKey, -1).toInt();
|
|
|
|
switch (oldOsType) {
|
2011-09-16 11:33:48 +02:00
|
|
|
case 0: d->osType = QLatin1String("Maemo5OsType"); break;
|
|
|
|
case 1: d->osType = QLatin1String("HarmattanOsType"); break;
|
|
|
|
case 2: d->osType = QLatin1String("MeeGoOsType"); break;
|
|
|
|
default: d->osType = QLatin1String(Constants::GenericLinuxOsType);
|
2011-06-07 12:12:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-16 11:33:48 +02:00
|
|
|
d->freePorts = PortList::fromString(settings.value(PortsSpecKey, QLatin1String("10000-10100")).toString());
|
|
|
|
d->sshParameters.host = settings.value(HostKey).toString();
|
|
|
|
d->sshParameters.port = settings.value(SshPortKey, 22).toInt();
|
|
|
|
d->sshParameters.userName = settings.value(UserNameKey).toString();
|
|
|
|
d->sshParameters.authenticationType
|
2011-05-31 12:47:53 +02:00
|
|
|
= static_cast<AuthType>(settings.value(AuthKey, DefaultAuthType).toInt());
|
2011-09-16 11:33:48 +02:00
|
|
|
d->sshParameters.password = settings.value(PasswordKey).toString();
|
|
|
|
d->sshParameters.privateKeyFile
|
2011-05-31 12:47:53 +02:00
|
|
|
= settings.value(KeyFileKey, defaultPrivateKeyFilePath()).toString();
|
2011-09-16 11:33:48 +02:00
|
|
|
d->sshParameters.timeout = settings.value(TimeoutKey, DefaultTimeout).toInt();
|
2011-05-31 12:47:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LinuxDeviceConfiguration::LinuxDeviceConfiguration(const LinuxDeviceConfiguration::ConstPtr &other)
|
2011-09-16 11:33:48 +02:00
|
|
|
: d(new LinuxDeviceConfigurationPrivate(other->d->sshParameters))
|
2011-05-31 12:47:53 +02:00
|
|
|
{
|
2011-11-16 09:37:29 +00:00
|
|
|
d->displayName = other->d->displayName;
|
2011-09-16 11:33:48 +02:00
|
|
|
d->osType = other->d->osType;
|
|
|
|
d->deviceType = other->deviceType();
|
|
|
|
d->freePorts = other->freePorts();
|
|
|
|
d->isDefault = other->d->isDefault;
|
|
|
|
d->origin = other->d->origin;
|
|
|
|
d->internalId = other->d->internalId;
|
2011-11-25 12:23:57 +01:00
|
|
|
d->attributes = other->d->attributes;
|
2011-05-31 12:47:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString LinuxDeviceConfiguration::defaultPrivateKeyFilePath()
|
|
|
|
{
|
|
|
|
return QDesktopServices::storageLocation(QDesktopServices::HomeLocation)
|
|
|
|
+ QLatin1String("/.ssh/id_rsa");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString LinuxDeviceConfiguration::defaultPublicKeyFilePath()
|
|
|
|
{
|
|
|
|
return defaultPrivateKeyFilePath() + QLatin1String(".pub");
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinuxDeviceConfiguration::save(QSettings &settings) const
|
|
|
|
{
|
2011-11-16 09:37:29 +00:00
|
|
|
settings.setValue(NameKey, d->displayName);
|
2011-09-16 11:33:48 +02:00
|
|
|
settings.setValue(OsTypeKey, d->osType);
|
|
|
|
settings.setValue(TypeKey, d->deviceType);
|
|
|
|
settings.setValue(HostKey, d->sshParameters.host);
|
|
|
|
settings.setValue(SshPortKey, d->sshParameters.port);
|
|
|
|
settings.setValue(PortsSpecKey, d->freePorts.toString());
|
|
|
|
settings.setValue(UserNameKey, d->sshParameters.userName);
|
|
|
|
settings.setValue(AuthKey, d->sshParameters.authenticationType);
|
|
|
|
settings.setValue(PasswordKey, d->sshParameters.password);
|
|
|
|
settings.setValue(KeyFileKey, d->sshParameters.privateKeyFile);
|
|
|
|
settings.setValue(TimeoutKey, d->sshParameters.timeout);
|
|
|
|
settings.setValue(IsDefaultKey, d->isDefault);
|
|
|
|
settings.setValue(InternalIdKey, d->internalId);
|
2011-11-25 12:23:57 +01:00
|
|
|
settings.setValue(AttributesKey, d->attributes);
|
2011-05-31 12:47:53 +02:00
|
|
|
}
|
|
|
|
|
2011-08-02 12:20:16 +02:00
|
|
|
SshConnectionParameters LinuxDeviceConfiguration::sshParameters() const
|
|
|
|
{
|
2011-09-16 11:33:48 +02:00
|
|
|
return d->sshParameters;
|
2011-08-02 12:20:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LinuxDeviceConfiguration::DeviceType LinuxDeviceConfiguration::deviceType() const
|
|
|
|
{
|
2011-09-16 11:33:48 +02:00
|
|
|
return d->deviceType;
|
2011-08-02 12:20:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LinuxDeviceConfiguration::Id LinuxDeviceConfiguration::internalId() const
|
|
|
|
{
|
2011-09-16 11:33:48 +02:00
|
|
|
return d->internalId;
|
2011-08-02 12:20:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LinuxDeviceConfiguration::setSshParameters(const SshConnectionParameters &sshParameters)
|
|
|
|
{
|
2011-09-16 11:33:48 +02:00
|
|
|
d->sshParameters = sshParameters;
|
2011-08-02 12:20:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LinuxDeviceConfiguration::setFreePorts(const PortList &freePorts)
|
|
|
|
{
|
2011-09-16 11:33:48 +02:00
|
|
|
d->freePorts = freePorts;
|
2011-08-02 12:20:16 +02:00
|
|
|
}
|
|
|
|
|
2011-08-15 10:36:53 +02:00
|
|
|
bool LinuxDeviceConfiguration::isAutoDetected() const
|
|
|
|
{
|
2011-09-16 11:33:48 +02:00
|
|
|
return d->origin == AutoDetected;
|
2011-08-15 10:36:53 +02:00
|
|
|
}
|
|
|
|
|
2011-11-25 12:23:57 +01:00
|
|
|
QVariantHash LinuxDeviceConfiguration::attributes() const
|
|
|
|
{
|
|
|
|
return d->attributes;
|
|
|
|
}
|
|
|
|
|
2011-09-16 11:33:48 +02:00
|
|
|
PortList LinuxDeviceConfiguration::freePorts() const { return d->freePorts; }
|
2011-11-16 09:37:29 +00:00
|
|
|
QString LinuxDeviceConfiguration::displayName() const { return d->displayName; }
|
2011-09-16 11:33:48 +02:00
|
|
|
QString LinuxDeviceConfiguration::osType() const { return d->osType; }
|
|
|
|
bool LinuxDeviceConfiguration::isDefault() const { return d->isDefault; }
|
2011-08-02 12:20:16 +02:00
|
|
|
|
2011-11-16 09:37:29 +00:00
|
|
|
void LinuxDeviceConfiguration::setDisplayName(const QString &name) { d->displayName = name; }
|
2011-09-16 11:33:48 +02:00
|
|
|
void LinuxDeviceConfiguration::setInternalId(Id id) { d->internalId = id; }
|
|
|
|
void LinuxDeviceConfiguration::setDefault(bool isDefault) { d->isDefault = isDefault; }
|
2011-08-02 12:20:16 +02:00
|
|
|
|
2011-05-31 12:47:53 +02:00
|
|
|
const LinuxDeviceConfiguration::Id LinuxDeviceConfiguration::InvalidId = 0;
|
2011-08-02 12:20:16 +02:00
|
|
|
|
2011-05-31 12:47:53 +02:00
|
|
|
} // namespace RemoteLinux
|