2009-11-27 16:40:07 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2009-11-27 16:40:07 +01:00
|
|
|
** All rights reserved.
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
|
** No Commercial Usage
|
|
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
|
** this package.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** 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, 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.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
|
|
|
|
**
|
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "maemodeviceconfigurations.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QSettings>
|
2010-01-07 16:42:01 +01:00
|
|
|
#include <QtCore/QStringBuilder>
|
2009-12-01 16:22:50 +01:00
|
|
|
#include <QtGui/QDesktopServices>
|
2009-11-27 16:40:07 +01:00
|
|
|
|
2009-12-01 14:04:25 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
2010-04-26 11:43:25 +02:00
|
|
|
typedef Core::SshServerInfo::AuthType AuthType;
|
|
|
|
|
|
2009-11-27 16:40:07 +01:00
|
|
|
namespace Qt4ProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-01-07 16:42:01 +01:00
|
|
|
QString homeDirOnDevice(const QString &uname)
|
|
|
|
|
{
|
2010-02-08 17:51:58 +01:00
|
|
|
return uname == QLatin1String("root")
|
2010-02-08 13:37:37 +01:00
|
|
|
? QString::fromLatin1("/root")
|
2010-01-20 12:13:08 +01:00
|
|
|
: QLatin1String("/home/") + uname;
|
2010-01-07 16:42:01 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-27 16:40:07 +01:00
|
|
|
namespace {
|
|
|
|
|
const QLatin1String SettingsGroup("MaemoDeviceConfigs");
|
2009-12-01 14:04:25 +01:00
|
|
|
const QLatin1String IdCounterKey("IdCounter");
|
2009-11-27 16:40:07 +01:00
|
|
|
const QLatin1String ConfigListKey("ConfigList");
|
|
|
|
|
const QLatin1String NameKey("Name");
|
|
|
|
|
const QLatin1String TypeKey("Type");
|
|
|
|
|
const QLatin1String HostKey("Host");
|
2010-01-11 18:09:49 +01:00
|
|
|
const QLatin1String SshPortKey("SshPort");
|
|
|
|
|
const QLatin1String GdbServerPortKey("GdbServerPort");
|
2009-11-27 16:40:07 +01:00
|
|
|
const QLatin1String UserNameKey("Uname");
|
2009-12-01 16:22:50 +01:00
|
|
|
const QLatin1String AuthKey("Authentication");
|
|
|
|
|
const QLatin1String KeyFileKey("KeyFile");
|
2009-11-27 16:40:07 +01:00
|
|
|
const QLatin1String PasswordKey("Password");
|
|
|
|
|
const QLatin1String TimeoutKey("Timeout");
|
2009-12-01 14:04:25 +01:00
|
|
|
const QLatin1String InternalIdKey("InternalId");
|
2009-12-01 16:22:50 +01:00
|
|
|
|
|
|
|
|
const QString DefaultKeyFile =
|
|
|
|
|
QDesktopServices::storageLocation(QDesktopServices::HomeLocation)
|
|
|
|
|
+ QLatin1String("/.ssh/id_rsa");
|
2010-04-08 17:31:55 +02:00
|
|
|
const int DefaultSshPortHW(22);
|
|
|
|
|
const int DefaultSshPortSim(6666);
|
|
|
|
|
const int DefaultGdbServerPortHW(10000);
|
|
|
|
|
const int DefaultGdbServerPortSim(13219);
|
|
|
|
|
const QString DefaultHostNameHW(QLatin1String("192.168.2.15"));
|
|
|
|
|
const QString DefaultHostNameSim(QLatin1String("localhost"));
|
2010-02-03 17:23:17 +01:00
|
|
|
const QString DefaultUserName(QLatin1String("developer"));
|
2010-04-26 11:43:25 +02:00
|
|
|
const AuthType DefaultAuthType(Core::SshServerInfo::AuthByKey);
|
2010-02-03 17:23:17 +01:00
|
|
|
const int DefaultTimeout(30);
|
|
|
|
|
const MaemoDeviceConfig::DeviceType DefaultDeviceType(MaemoDeviceConfig::Physical);
|
2009-12-01 14:04:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DevConfIdMatcher
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
DevConfIdMatcher(quint64 id) : m_id(id) {}
|
2009-12-23 10:53:57 +01:00
|
|
|
bool operator()(const MaemoDeviceConfig &devConfig)
|
2009-12-01 14:04:25 +01:00
|
|
|
{
|
|
|
|
|
return devConfig.internalId == m_id;
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
const quint64 m_id;
|
2009-11-27 16:40:07 +01:00
|
|
|
};
|
|
|
|
|
|
2010-04-08 17:31:55 +02:00
|
|
|
MaemoDeviceConfig::MaemoDeviceConfig(const QString &name, MaemoDeviceConfig::DeviceType devType)
|
2009-12-01 14:04:25 +01:00
|
|
|
: name(name),
|
2010-04-08 17:31:55 +02:00
|
|
|
type(devType),
|
|
|
|
|
gdbServerPort(defaultGdbServerPort(type)),
|
2009-12-01 14:04:25 +01:00
|
|
|
internalId(MaemoDeviceConfigurations::instance().m_nextId++)
|
2009-11-27 16:40:07 +01:00
|
|
|
{
|
2010-04-26 11:43:25 +02:00
|
|
|
server.host = defaultHost(type);
|
|
|
|
|
server.port = defaultSshPort(type);
|
|
|
|
|
server.uname = DefaultUserName;
|
|
|
|
|
server.authType = DefaultAuthType;
|
|
|
|
|
server.privateKeyFile = DefaultKeyFile;
|
|
|
|
|
server.timeout = DefaultTimeout;
|
2009-11-27 16:40:07 +01:00
|
|
|
}
|
|
|
|
|
|
2009-12-23 10:53:57 +01:00
|
|
|
MaemoDeviceConfig::MaemoDeviceConfig(const QSettings &settings,
|
|
|
|
|
quint64 &nextId)
|
2009-11-27 16:40:07 +01:00
|
|
|
: name(settings.value(NameKey).toString()),
|
2010-02-03 17:23:17 +01:00
|
|
|
type(static_cast<DeviceType>(settings.value(TypeKey, DefaultDeviceType).toInt())),
|
2010-04-08 17:31:55 +02:00
|
|
|
gdbServerPort(settings.value(GdbServerPortKey, defaultGdbServerPort(type)).toInt()),
|
2009-12-16 16:05:01 +01:00
|
|
|
internalId(settings.value(InternalIdKey, nextId).toInt())
|
2009-12-01 14:04:25 +01:00
|
|
|
{
|
2009-12-16 16:05:01 +01:00
|
|
|
if (internalId == nextId)
|
|
|
|
|
++nextId;
|
2010-04-26 11:43:25 +02:00
|
|
|
server.host = settings.value(HostKey, defaultHost(type)).toString();
|
|
|
|
|
server.port = settings.value(SshPortKey, defaultSshPort(type)).toInt();
|
|
|
|
|
server.uname = settings.value(UserNameKey, DefaultUserName).toString();
|
|
|
|
|
server.authType
|
|
|
|
|
= static_cast<AuthType>(settings.value(AuthKey, DefaultAuthType).toInt());
|
|
|
|
|
server.pwd = settings.value(PasswordKey).toString();
|
|
|
|
|
server.privateKeyFile
|
|
|
|
|
= settings.value(KeyFileKey, DefaultKeyFile).toString();
|
|
|
|
|
server.timeout = settings.value(TimeoutKey, DefaultTimeout).toInt();
|
2009-12-01 14:04:25 +01:00
|
|
|
}
|
|
|
|
|
|
2009-12-23 10:53:57 +01:00
|
|
|
MaemoDeviceConfig::MaemoDeviceConfig()
|
2009-12-01 14:04:25 +01:00
|
|
|
: internalId(InvalidId)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-08 17:31:55 +02:00
|
|
|
int MaemoDeviceConfig::defaultSshPort(DeviceType type) const
|
|
|
|
|
{
|
|
|
|
|
return type == Physical ? DefaultSshPortHW : DefaultSshPortSim;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int MaemoDeviceConfig::defaultGdbServerPort(DeviceType type) const
|
|
|
|
|
{
|
|
|
|
|
return type == Physical ? DefaultGdbServerPortHW : DefaultGdbServerPortSim;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MaemoDeviceConfig::defaultHost(DeviceType type) const
|
|
|
|
|
{
|
|
|
|
|
return type == Physical ? DefaultHostNameHW : DefaultHostNameSim;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-23 10:53:57 +01:00
|
|
|
bool MaemoDeviceConfig::isValid() const
|
2009-11-27 16:40:07 +01:00
|
|
|
{
|
2009-12-01 14:04:25 +01:00
|
|
|
return internalId != InvalidId;
|
2009-11-27 16:40:07 +01:00
|
|
|
}
|
|
|
|
|
|
2009-12-23 10:53:57 +01:00
|
|
|
void MaemoDeviceConfig::save(QSettings &settings) const
|
2009-11-27 16:40:07 +01:00
|
|
|
{
|
|
|
|
|
settings.setValue(NameKey, name);
|
|
|
|
|
settings.setValue(TypeKey, type);
|
2010-04-26 11:43:25 +02:00
|
|
|
settings.setValue(HostKey, server.host);
|
|
|
|
|
settings.setValue(SshPortKey, server.port);
|
2010-01-11 18:09:49 +01:00
|
|
|
settings.setValue(GdbServerPortKey, gdbServerPort);
|
2010-04-26 11:43:25 +02:00
|
|
|
settings.setValue(UserNameKey, server.uname);
|
|
|
|
|
settings.setValue(AuthKey, server.authType);
|
|
|
|
|
settings.setValue(PasswordKey, server.pwd);
|
|
|
|
|
settings.setValue(KeyFileKey, server.privateKeyFile);
|
|
|
|
|
settings.setValue(TimeoutKey, server.timeout);
|
2009-12-01 14:04:25 +01:00
|
|
|
settings.setValue(InternalIdKey, internalId);
|
2009-11-27 16:40:07 +01:00
|
|
|
}
|
|
|
|
|
|
2009-12-23 10:53:57 +01:00
|
|
|
void MaemoDeviceConfigurations::setDevConfigs(const QList<MaemoDeviceConfig> &devConfigs)
|
2009-11-27 16:40:07 +01:00
|
|
|
{
|
|
|
|
|
m_devConfigs = devConfigs;
|
|
|
|
|
save();
|
2009-12-01 14:04:25 +01:00
|
|
|
emit updated();
|
2009-11-27 16:40:07 +01:00
|
|
|
}
|
|
|
|
|
|
2009-12-01 14:04:25 +01:00
|
|
|
MaemoDeviceConfigurations &MaemoDeviceConfigurations::instance(QObject *parent)
|
2009-11-27 16:40:07 +01:00
|
|
|
{
|
2009-12-01 14:04:25 +01:00
|
|
|
if (m_instance == 0)
|
|
|
|
|
m_instance = new MaemoDeviceConfigurations(parent);
|
|
|
|
|
return *m_instance;
|
2009-11-27 16:40:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDeviceConfigurations::save()
|
|
|
|
|
{
|
|
|
|
|
QSettings *settings = Core::ICore::instance()->settings();
|
|
|
|
|
settings->beginGroup(SettingsGroup);
|
2009-12-01 14:04:25 +01:00
|
|
|
settings->setValue(IdCounterKey, m_nextId);
|
2009-11-27 16:40:07 +01:00
|
|
|
settings->beginWriteArray(ConfigListKey, m_devConfigs.count());
|
2009-11-30 14:09:08 +01:00
|
|
|
for (int i = 0; i < m_devConfigs.count(); ++i) {
|
|
|
|
|
settings->setArrayIndex(i);
|
|
|
|
|
m_devConfigs.at(i).save(*settings);
|
|
|
|
|
}
|
2009-11-27 16:40:07 +01:00
|
|
|
settings->endArray();
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-01 14:04:25 +01:00
|
|
|
MaemoDeviceConfigurations::MaemoDeviceConfigurations(QObject *parent)
|
|
|
|
|
: QObject(parent)
|
2009-11-27 16:40:07 +01:00
|
|
|
{
|
|
|
|
|
load();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDeviceConfigurations::load()
|
|
|
|
|
{
|
|
|
|
|
QSettings *settings = Core::ICore::instance()->settings();
|
|
|
|
|
settings->beginGroup(SettingsGroup);
|
2009-12-10 17:34:22 +01:00
|
|
|
m_nextId = settings->value(IdCounterKey, 1).toULongLong();
|
2009-11-27 16:40:07 +01:00
|
|
|
int count = settings->beginReadArray(ConfigListKey);
|
2009-11-30 14:09:08 +01:00
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
|
settings->setArrayIndex(i);
|
2009-12-23 10:53:57 +01:00
|
|
|
m_devConfigs.append(MaemoDeviceConfig(*settings, m_nextId));
|
2009-11-30 14:09:08 +01:00
|
|
|
}
|
2009-11-27 16:40:07 +01:00
|
|
|
settings->endArray();
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-23 10:53:57 +01:00
|
|
|
MaemoDeviceConfig MaemoDeviceConfigurations::find(const QString &name) const
|
2009-12-01 14:04:25 +01:00
|
|
|
{
|
2009-12-23 10:53:57 +01:00
|
|
|
QList<MaemoDeviceConfig>::ConstIterator resultIt =
|
2009-12-01 14:04:25 +01:00
|
|
|
std::find_if(m_devConfigs.constBegin(), m_devConfigs.constEnd(),
|
|
|
|
|
DevConfNameMatcher(name));
|
2009-12-23 10:53:57 +01:00
|
|
|
return resultIt == m_devConfigs.constEnd() ? MaemoDeviceConfig() : *resultIt;
|
2009-12-01 14:04:25 +01:00
|
|
|
}
|
|
|
|
|
|
2009-12-23 10:53:57 +01:00
|
|
|
MaemoDeviceConfig MaemoDeviceConfigurations::find(int id) const
|
2009-12-01 14:04:25 +01:00
|
|
|
{
|
2009-12-23 10:53:57 +01:00
|
|
|
QList<MaemoDeviceConfig>::ConstIterator resultIt =
|
2009-12-01 14:04:25 +01:00
|
|
|
std::find_if(m_devConfigs.constBegin(), m_devConfigs.constEnd(),
|
|
|
|
|
DevConfIdMatcher(id));
|
2009-12-23 10:53:57 +01:00
|
|
|
return resultIt == m_devConfigs.constEnd() ? MaemoDeviceConfig() : *resultIt;
|
2009-12-01 14:04:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaemoDeviceConfigurations *MaemoDeviceConfigurations::m_instance = 0;
|
|
|
|
|
|
2009-11-27 16:40:07 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Qt4ProjectManager
|