2009-11-27 16:40:07 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
** 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>
|
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>
|
|
|
|
|
|
2009-11-27 16:40:07 +01:00
|
|
|
namespace Qt4ProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
const QLatin1String PortKey("Port");
|
|
|
|
|
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");
|
2009-12-01 14:04:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DevConfIdMatcher
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
DevConfIdMatcher(quint64 id) : m_id(id) {}
|
|
|
|
|
bool operator()(const MaemoDeviceConfigurations::DeviceConfig &devConfig)
|
|
|
|
|
{
|
|
|
|
|
return devConfig.internalId == m_id;
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
const quint64 m_id;
|
2009-11-27 16:40:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MaemoDeviceConfigurations::DeviceConfig::DeviceConfig(const QString &name)
|
2009-12-01 14:04:25 +01:00
|
|
|
: name(name),
|
|
|
|
|
type(Physical),
|
|
|
|
|
port(22),
|
2009-12-01 16:22:50 +01:00
|
|
|
authentication(Key),
|
|
|
|
|
keyFile(DefaultKeyFile),
|
2009-12-01 14:04:25 +01:00
|
|
|
timeout(30),
|
|
|
|
|
internalId(MaemoDeviceConfigurations::instance().m_nextId++)
|
2009-11-27 16:40:07 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaemoDeviceConfigurations::DeviceConfig::DeviceConfig(const QSettings &settings)
|
|
|
|
|
: name(settings.value(NameKey).toString()),
|
|
|
|
|
type(static_cast<DeviceType>(settings.value(TypeKey, Physical).toInt())),
|
|
|
|
|
host(settings.value(HostKey).toString()),
|
|
|
|
|
port(settings.value(PortKey, 22).toInt()),
|
|
|
|
|
uname(settings.value(UserNameKey).toString()),
|
2009-12-01 16:22:50 +01:00
|
|
|
authentication(static_cast<AuthType>(settings.value(AuthKey).toInt())),
|
2009-11-27 16:40:07 +01:00
|
|
|
pwd(settings.value(PasswordKey).toString()),
|
2009-12-01 16:22:50 +01:00
|
|
|
keyFile(settings.value(KeyFileKey).toString()),
|
2009-12-01 14:04:25 +01:00
|
|
|
timeout(settings.value(TimeoutKey, 30).toInt()),
|
|
|
|
|
internalId(settings.value(InternalIdKey, MaemoDeviceConfigurations::instance().m_nextId).toInt())
|
|
|
|
|
{
|
|
|
|
|
if (internalId == MaemoDeviceConfigurations::instance().m_nextId)
|
|
|
|
|
++MaemoDeviceConfigurations::instance().m_nextId;
|
|
|
|
|
qDebug("%s: name = %s, id = %llu", Q_FUNC_INFO, qPrintable(name), internalId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaemoDeviceConfigurations::DeviceConfig::DeviceConfig()
|
|
|
|
|
: internalId(InvalidId)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MaemoDeviceConfigurations::DeviceConfig::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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDeviceConfigurations::DeviceConfig::save(QSettings &settings) const
|
|
|
|
|
{
|
|
|
|
|
settings.setValue(NameKey, name);
|
|
|
|
|
settings.setValue(TypeKey, type);
|
|
|
|
|
settings.setValue(HostKey, host);
|
|
|
|
|
settings.setValue(PortKey, port);
|
|
|
|
|
settings.setValue(UserNameKey, uname);
|
2009-12-01 16:22:50 +01:00
|
|
|
settings.setValue(AuthKey, authentication);
|
2009-11-27 16:40:07 +01:00
|
|
|
settings.setValue(PasswordKey, pwd);
|
2009-12-01 16:22:50 +01:00
|
|
|
settings.setValue(KeyFileKey, keyFile);
|
2009-11-27 16:40:07 +01:00
|
|
|
settings.setValue(TimeoutKey, timeout);
|
2009-12-01 14:04:25 +01:00
|
|
|
settings.setValue(InternalIdKey, internalId);
|
2009-11-27 16:40:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDeviceConfigurations::setDevConfigs(const QList<DeviceConfig> &devConfigs)
|
|
|
|
|
{
|
|
|
|
|
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();
|
2009-12-01 14:04:25 +01:00
|
|
|
m_nextId = settings->value(IdCounterKey, 1).toULongLong();
|
2009-11-27 16:40:07 +01:00
|
|
|
settings->beginGroup(SettingsGroup);
|
|
|
|
|
int count = settings->beginReadArray(ConfigListKey);
|
2009-11-30 14:09:08 +01:00
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
|
settings->setArrayIndex(i);
|
2009-11-27 16:40:07 +01:00
|
|
|
m_devConfigs.append(DeviceConfig(*settings));
|
2009-11-30 14:09:08 +01:00
|
|
|
}
|
2009-11-27 16:40:07 +01:00
|
|
|
settings->endArray();
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-01 14:04:25 +01:00
|
|
|
MaemoDeviceConfigurations::DeviceConfig MaemoDeviceConfigurations::find(const QString &name) const
|
|
|
|
|
{
|
|
|
|
|
qDebug("%s: Looking for name %s", Q_FUNC_INFO, qPrintable(name));
|
|
|
|
|
QList<DeviceConfig>::ConstIterator resultIt =
|
|
|
|
|
std::find_if(m_devConfigs.constBegin(), m_devConfigs.constEnd(),
|
|
|
|
|
DevConfNameMatcher(name));
|
|
|
|
|
qDebug("Found: %d", resultIt != m_devConfigs.constEnd());
|
|
|
|
|
return resultIt == m_devConfigs.constEnd() ? DeviceConfig() : *resultIt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaemoDeviceConfigurations::DeviceConfig MaemoDeviceConfigurations::find(int id) const
|
|
|
|
|
{
|
|
|
|
|
qDebug("%s: Looking for id %d", Q_FUNC_INFO, id);
|
|
|
|
|
QList<DeviceConfig>::ConstIterator resultIt =
|
|
|
|
|
std::find_if(m_devConfigs.constBegin(), m_devConfigs.constEnd(),
|
|
|
|
|
DevConfIdMatcher(id));
|
|
|
|
|
qDebug("Found: %d", resultIt != m_devConfigs.constEnd());
|
|
|
|
|
return resultIt == m_devConfigs.constEnd() ? DeviceConfig() : *resultIt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaemoDeviceConfigurations *MaemoDeviceConfigurations::m_instance = 0;
|
|
|
|
|
|
2009-11-27 16:40:07 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Qt4ProjectManager
|