2011-05-31 12:47:53 +02:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2011-05-31 12:47:53 +02:00
|
|
|
**
|
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"
|
|
|
|
|
2012-04-06 18:28:16 +02:00
|
|
|
#include "genericlinuxdeviceconfigurationwidget.h"
|
|
|
|
#include "linuxdevicetestdialog.h"
|
|
|
|
#include "publickeydeploymentdialog.h"
|
|
|
|
#include "remotelinuxprocessesdialog.h"
|
|
|
|
#include "remotelinuxprocesslist.h"
|
2011-07-25 11:55:00 +02:00
|
|
|
#include "remotelinux_constants.h"
|
|
|
|
|
2012-02-28 10:34:50 +01:00
|
|
|
#include <utils/portlist.h>
|
2011-08-02 12:20:16 +02:00
|
|
|
#include <utils/ssh/sshconnection.h>
|
2012-02-15 14:47:45 -08:00
|
|
|
#include <utils/qtcassert.h>
|
2011-08-02 12:20:16 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDesktopServices>
|
2012-03-06 12:31:42 +01:00
|
|
|
#include <QStringList>
|
2011-05-31 12:47:53 +02:00
|
|
|
|
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 {
|
2012-03-05 12:37:32 +01:00
|
|
|
const QLatin1String MachineTypeKey("Type");
|
2011-05-31 12:47:53 +02:00
|
|
|
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");
|
|
|
|
|
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);
|
2012-03-05 12:37:32 +01:00
|
|
|
const LinuxDeviceConfiguration::MachineType DefaultMachineType(LinuxDeviceConfiguration::Hardware);
|
2011-05-31 12:47:53 +02:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2011-08-02 12:20:16 +02:00
|
|
|
class LinuxDeviceConfigurationPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SshConnectionParameters sshParameters;
|
2012-03-05 12:37:32 +01:00
|
|
|
LinuxDeviceConfiguration::MachineType machineType;
|
2011-08-02 12:20:16 +02:00
|
|
|
PortList freePorts;
|
|
|
|
};
|
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
|
|
|
|
2011-06-21 16:52:48 +02:00
|
|
|
LinuxDeviceConfiguration::Ptr LinuxDeviceConfiguration::create(const QString &name,
|
2012-04-25 09:54:31 +02:00
|
|
|
const QString &type, MachineType machineType, Origin origin, Core::Id id)
|
2011-05-31 12:47:53 +02:00
|
|
|
{
|
2012-04-13 15:58:55 +02:00
|
|
|
return Ptr(new LinuxDeviceConfiguration(name, type, machineType, origin, id));
|
2012-03-02 18:09:59 +01:00
|
|
|
}
|
|
|
|
|
2012-04-06 18:28:16 +02:00
|
|
|
QString LinuxDeviceConfiguration::displayType() const
|
|
|
|
{
|
|
|
|
return tr("Generic Linux");
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectExplorer::IDeviceWidget *LinuxDeviceConfiguration::createWidget()
|
|
|
|
{
|
|
|
|
return new GenericLinuxDeviceConfigurationWidget(sharedFromThis()
|
|
|
|
.staticCast<LinuxDeviceConfiguration>());
|
|
|
|
}
|
|
|
|
|
2012-05-01 19:07:55 +02:00
|
|
|
QList<Core::Id> LinuxDeviceConfiguration::actionIds() const
|
2012-04-06 18:28:16 +02:00
|
|
|
{
|
2012-05-01 19:07:55 +02:00
|
|
|
return QList<Core::Id>() << Core::Id(Constants::GenericTestDeviceActionId)
|
|
|
|
<< Core::Id(Constants::GenericDeployKeyToDeviceActionId)
|
|
|
|
<< Core::Id(Constants::GenericRemoteProcessesActionId);
|
2012-04-06 18:28:16 +02:00
|
|
|
}
|
|
|
|
|
2012-05-01 19:07:55 +02:00
|
|
|
QString LinuxDeviceConfiguration::displayNameForActionId(Core::Id actionId) const
|
2012-04-06 18:28:16 +02:00
|
|
|
{
|
|
|
|
QTC_ASSERT(actionIds().contains(actionId), return QString());
|
|
|
|
|
2012-05-01 19:07:55 +02:00
|
|
|
if (actionId == Core::Id(Constants::GenericTestDeviceActionId))
|
2012-04-06 18:28:16 +02:00
|
|
|
return tr("Test");
|
2012-05-01 19:07:55 +02:00
|
|
|
if (actionId == Core::Id(Constants::GenericRemoteProcessesActionId))
|
2012-04-06 18:28:16 +02:00
|
|
|
return tr("Remote Processes...");
|
2012-05-01 19:07:55 +02:00
|
|
|
if (actionId == Core::Id(Constants::GenericDeployKeyToDeviceActionId))
|
2012-04-06 18:28:16 +02:00
|
|
|
return tr("Deploy Public Key...");
|
|
|
|
return QString(); // Can't happen.
|
|
|
|
}
|
|
|
|
|
2012-05-02 16:03:26 +02:00
|
|
|
void LinuxDeviceConfiguration::executeAction(Core::Id actionId, QWidget *parent)
|
2012-04-06 18:28:16 +02:00
|
|
|
{
|
2012-05-02 16:03:26 +02:00
|
|
|
QTC_ASSERT(actionIds().contains(actionId), return);
|
2012-04-06 18:28:16 +02:00
|
|
|
|
2012-05-02 16:03:26 +02:00
|
|
|
QDialog *d;
|
2012-04-06 18:28:16 +02:00
|
|
|
const LinuxDeviceConfiguration::ConstPtr device
|
|
|
|
= sharedFromThis().staticCast<const LinuxDeviceConfiguration>();
|
2012-05-01 19:07:55 +02:00
|
|
|
if (actionId == Core::Id(Constants::GenericTestDeviceActionId))
|
2012-05-02 16:03:26 +02:00
|
|
|
d = new LinuxDeviceTestDialog(device, new GenericLinuxDeviceTester, parent);
|
|
|
|
else if (actionId == Core::Id(Constants::GenericRemoteProcessesActionId))
|
|
|
|
d = new RemoteLinuxProcessesDialog(new GenericRemoteLinuxProcessList(device, parent));
|
|
|
|
else if (actionId == Core::Id(Constants::GenericDeployKeyToDeviceActionId))
|
|
|
|
d = PublicKeyDeploymentDialog::createDialog(device, parent);
|
|
|
|
if (d)
|
|
|
|
d->exec();
|
2012-04-06 18:28:16 +02:00
|
|
|
}
|
|
|
|
|
2012-03-05 12:37:32 +01:00
|
|
|
LinuxDeviceConfiguration::LinuxDeviceConfiguration() : d(new LinuxDeviceConfigurationPrivate)
|
2012-03-02 18:09:59 +01:00
|
|
|
{
|
2011-05-31 12:47:53 +02:00
|
|
|
}
|
|
|
|
|
2012-03-05 12:37:32 +01:00
|
|
|
LinuxDeviceConfiguration::LinuxDeviceConfiguration(const QString &name, const QString &type,
|
2012-04-25 09:54:31 +02:00
|
|
|
MachineType machineType, Origin origin, Core::Id id)
|
2012-04-13 15:58:55 +02:00
|
|
|
: IDevice(type, origin, id), d(new LinuxDeviceConfigurationPrivate)
|
2011-05-31 12:47:53 +02:00
|
|
|
{
|
2012-03-06 12:31:42 +01:00
|
|
|
setDisplayName(name);
|
2012-03-05 12:37:32 +01:00
|
|
|
d->machineType = machineType;
|
2011-05-31 12:47:53 +02:00
|
|
|
}
|
|
|
|
|
2012-03-05 12:37:32 +01:00
|
|
|
LinuxDeviceConfiguration::LinuxDeviceConfiguration(const LinuxDeviceConfiguration &other)
|
2012-03-06 12:31:42 +01:00
|
|
|
: IDevice(other), d(new LinuxDeviceConfigurationPrivate)
|
2011-05-31 12:47:53 +02:00
|
|
|
{
|
2012-03-05 12:37:32 +01:00
|
|
|
d->machineType = other.machineType();
|
|
|
|
d->freePorts = other.freePorts();
|
|
|
|
d->sshParameters = other.d->sshParameters;
|
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");
|
|
|
|
}
|
|
|
|
|
2012-03-02 18:09:59 +01:00
|
|
|
LinuxDeviceConfiguration::Ptr LinuxDeviceConfiguration::create()
|
|
|
|
{
|
|
|
|
return Ptr(new LinuxDeviceConfiguration);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinuxDeviceConfiguration::fromMap(const QVariantMap &map)
|
|
|
|
{
|
2012-03-06 12:31:42 +01:00
|
|
|
IDevice::fromMap(map);
|
2012-03-05 12:37:32 +01:00
|
|
|
d->machineType = static_cast<MachineType>(map.value(MachineTypeKey, DefaultMachineType).toInt());
|
2012-03-02 18:09:59 +01:00
|
|
|
d->freePorts = PortList::fromString(map.value(PortsSpecKey,
|
|
|
|
QLatin1String("10000-10100")).toString());
|
|
|
|
d->sshParameters.host = map.value(HostKey).toString();
|
|
|
|
d->sshParameters.port = map.value(SshPortKey, 22).toInt();
|
|
|
|
d->sshParameters.userName = map.value(UserNameKey).toString();
|
|
|
|
d->sshParameters.authenticationType
|
|
|
|
= static_cast<AuthType>(map.value(AuthKey, DefaultAuthType).toInt());
|
|
|
|
d->sshParameters.password = map.value(PasswordKey).toString();
|
|
|
|
d->sshParameters.privateKeyFile = map.value(KeyFileKey, defaultPrivateKeyFilePath()).toString();
|
|
|
|
d->sshParameters.timeout = map.value(TimeoutKey, DefaultTimeout).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariantMap LinuxDeviceConfiguration::toMap() const
|
|
|
|
{
|
2012-03-06 12:31:42 +01:00
|
|
|
QVariantMap map = IDevice::toMap();
|
2012-03-05 12:37:32 +01:00
|
|
|
map.insert(MachineTypeKey, d->machineType);
|
2012-03-02 18:09:59 +01:00
|
|
|
map.insert(HostKey, d->sshParameters.host);
|
|
|
|
map.insert(SshPortKey, d->sshParameters.port);
|
|
|
|
map.insert(PortsSpecKey, d->freePorts.toString());
|
|
|
|
map.insert(UserNameKey, d->sshParameters.userName);
|
|
|
|
map.insert(AuthKey, d->sshParameters.authenticationType);
|
|
|
|
map.insert(PasswordKey, d->sshParameters.password);
|
|
|
|
map.insert(KeyFileKey, d->sshParameters.privateKeyFile);
|
|
|
|
map.insert(TimeoutKey, d->sshParameters.timeout);
|
|
|
|
return map;
|
2011-05-31 12:47:53 +02:00
|
|
|
}
|
|
|
|
|
2012-03-06 12:31:42 +01:00
|
|
|
ProjectExplorer::IDevice::Ptr LinuxDeviceConfiguration::clone() const
|
2012-03-05 12:37:32 +01:00
|
|
|
{
|
|
|
|
return Ptr(new LinuxDeviceConfiguration(*this));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-03-05 12:37:32 +01:00
|
|
|
LinuxDeviceConfiguration::MachineType LinuxDeviceConfiguration::machineType() const
|
2011-12-06 15:39:25 +01:00
|
|
|
|
2011-08-02 12:20:16 +02:00
|
|
|
{
|
2012-03-05 12:37:32 +01:00
|
|
|
return d->machineType;
|
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-09-16 11:33:48 +02:00
|
|
|
PortList LinuxDeviceConfiguration::freePorts() const { return d->freePorts; }
|
2012-02-15 14:47:45 -08:00
|
|
|
|
2011-05-31 12:47:53 +02:00
|
|
|
} // namespace RemoteLinux
|