2009-11-27 16:40:07 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (C) 2011 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>
|
|
|
|
|
|
2010-07-13 15:24:21 +02:00
|
|
|
#include <QtCore/QCoreApplication>
|
2009-11-27 16:40:07 +01:00
|
|
|
#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-08-13 16:39:02 +02:00
|
|
|
#include <cctype>
|
2009-12-01 14:04:25 +01:00
|
|
|
|
2010-07-12 09:33:22 +02:00
|
|
|
typedef Core::SshConnectionParameters::AuthType AuthType;
|
2010-04-26 11:43:25 +02:00
|
|
|
|
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");
|
2011-02-02 10:30:38 +01:00
|
|
|
const QLatin1String OsVersionKey("OsVersion");
|
2009-11-27 16:40:07 +01:00
|
|
|
const QLatin1String TypeKey("Type");
|
|
|
|
|
const QLatin1String HostKey("Host");
|
2010-01-11 18:09:49 +01:00
|
|
|
const QLatin1String SshPortKey("SshPort");
|
2010-08-12 19:12:12 +02:00
|
|
|
const QLatin1String PortsSpecKey("FreePortsSpec");
|
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");
|
2011-01-13 14:32:15 +01:00
|
|
|
const QLatin1String IsDefaultKey("IsDefault");
|
2009-12-01 14:04:25 +01:00
|
|
|
const QLatin1String InternalIdKey("InternalId");
|
2010-12-06 15:28:16 +01:00
|
|
|
const QLatin1String DefaultKeyFilePathKey("DefaultKeyFile");
|
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-07-12 09:33:22 +02:00
|
|
|
const AuthType DefaultAuthType(Core::SshConnectionParameters::AuthByKey);
|
2010-02-03 17:23:17 +01:00
|
|
|
const int DefaultTimeout(30);
|
|
|
|
|
const MaemoDeviceConfig::DeviceType DefaultDeviceType(MaemoDeviceConfig::Physical);
|
2010-12-16 12:05:48 +01:00
|
|
|
}
|
2009-12-01 14:04:25 +01:00
|
|
|
|
2011-01-13 13:49:23 +01:00
|
|
|
class DevConfNameMatcher
|
2009-12-01 14:04:25 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2011-01-13 13:49:23 +01:00
|
|
|
DevConfNameMatcher(const QString &name) : m_name(name) {}
|
|
|
|
|
bool operator()(const MaemoDeviceConfig::ConstPtr &devConfig)
|
2009-12-01 14:04:25 +01:00
|
|
|
{
|
2011-01-13 13:49:23 +01:00
|
|
|
return devConfig->name() == m_name;
|
2009-12-01 14:04:25 +01:00
|
|
|
}
|
|
|
|
|
private:
|
2011-01-13 13:49:23 +01:00
|
|
|
const QString m_name;
|
2009-11-27 16:40:07 +01:00
|
|
|
};
|
|
|
|
|
|
2010-08-12 17:10:39 +02:00
|
|
|
class PortsSpecParser
|
|
|
|
|
{
|
|
|
|
|
struct ParseException {
|
|
|
|
|
ParseException(const char *error) : error(error) {}
|
|
|
|
|
const char * const error;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
PortsSpecParser(const QString &portsSpec)
|
|
|
|
|
: m_pos(0), m_portsSpec(portsSpec) { }
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Grammar: Spec -> [ ElemList ]
|
|
|
|
|
* ElemList -> Elem [ ',' ElemList ]
|
|
|
|
|
* Elem -> Port [ '-' Port ]
|
|
|
|
|
*/
|
2010-08-12 19:12:12 +02:00
|
|
|
MaemoPortList parse()
|
2010-08-12 17:10:39 +02:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
if (!atEnd())
|
|
|
|
|
parseElemList();
|
|
|
|
|
} catch (ParseException &e) {
|
|
|
|
|
qWarning("Malformed ports specification: %s", e.error);
|
|
|
|
|
}
|
2010-08-12 19:12:12 +02:00
|
|
|
return m_portList;
|
2010-08-12 17:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void parseElemList()
|
|
|
|
|
{
|
|
|
|
|
if (atEnd())
|
|
|
|
|
throw ParseException("Element list empty.");
|
|
|
|
|
parseElem();
|
|
|
|
|
if (atEnd())
|
|
|
|
|
return;
|
|
|
|
|
if (nextChar() != ',') {
|
|
|
|
|
throw ParseException("Element followed by something else "
|
|
|
|
|
"than a comma.");
|
|
|
|
|
}
|
|
|
|
|
++m_pos;
|
|
|
|
|
parseElemList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void parseElem()
|
|
|
|
|
{
|
|
|
|
|
const int startPort = parsePort();
|
|
|
|
|
if (atEnd() || nextChar() != '-') {
|
2010-11-26 10:41:39 +01:00
|
|
|
m_portList.addPort(startPort);
|
2010-08-12 17:10:39 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
++m_pos;
|
|
|
|
|
const int endPort = parsePort();
|
|
|
|
|
if (endPort < startPort)
|
|
|
|
|
throw ParseException("Invalid range (end < start).");
|
2010-08-12 19:46:58 +02:00
|
|
|
m_portList.addRange(startPort, endPort);
|
2010-08-12 17:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int parsePort()
|
|
|
|
|
{
|
|
|
|
|
if (atEnd())
|
|
|
|
|
throw ParseException("Empty port string.");
|
|
|
|
|
int port = 0;
|
2010-08-12 19:12:12 +02:00
|
|
|
do {
|
|
|
|
|
const char next = nextChar();
|
2010-08-13 16:30:52 +02:00
|
|
|
if (!std::isdigit(next))
|
2010-08-12 19:12:12 +02:00
|
|
|
break;
|
2010-08-12 17:10:39 +02:00
|
|
|
port = 10*port + next - '0';
|
|
|
|
|
++m_pos;
|
2010-08-12 19:12:12 +02:00
|
|
|
} while (!atEnd());
|
2010-08-12 17:10:39 +02:00
|
|
|
if (port == 0 || port >= 2 << 16)
|
|
|
|
|
throw ParseException("Invalid port value.");
|
|
|
|
|
return port;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool atEnd() const { return m_pos == m_portsSpec.length(); }
|
|
|
|
|
char nextChar() const { return m_portsSpec.at(m_pos).toAscii(); }
|
|
|
|
|
|
2010-08-12 19:12:12 +02:00
|
|
|
MaemoPortList m_portList;
|
2010-08-12 17:10:39 +02:00
|
|
|
int m_pos;
|
|
|
|
|
const QString &m_portsSpec;
|
|
|
|
|
};
|
|
|
|
|
|
2011-01-13 16:24:05 +01:00
|
|
|
|
|
|
|
|
void MaemoPortList::addPort(int port) { addRange(port, port); }
|
|
|
|
|
|
|
|
|
|
void MaemoPortList::addRange(int startPort, int endPort)
|
|
|
|
|
{
|
|
|
|
|
m_ranges << Range(startPort, endPort);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MaemoPortList::hasMore() const { return !m_ranges.isEmpty(); }
|
|
|
|
|
|
|
|
|
|
int MaemoPortList::count() const
|
|
|
|
|
{
|
|
|
|
|
int n = 0;
|
|
|
|
|
foreach (const Range &r, m_ranges)
|
|
|
|
|
n += r.second - r.first + 1;
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int MaemoPortList::getNext()
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(!m_ranges.isEmpty());
|
|
|
|
|
Range &firstRange = m_ranges.first();
|
|
|
|
|
const int next = firstRange.first++;
|
|
|
|
|
if (firstRange.first > firstRange.second)
|
|
|
|
|
m_ranges.removeFirst();
|
|
|
|
|
return next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MaemoPortList::toString() const
|
|
|
|
|
{
|
|
|
|
|
QString stringRep;
|
|
|
|
|
foreach (const Range &range, m_ranges) {
|
|
|
|
|
stringRep += QString::number(range.first);
|
|
|
|
|
if (range.second != range.first)
|
|
|
|
|
stringRep += QLatin1Char('-') + QString::number(range.second);
|
|
|
|
|
stringRep += QLatin1Char(',');
|
|
|
|
|
}
|
|
|
|
|
if (!stringRep.isEmpty())
|
|
|
|
|
stringRep.remove(stringRep.length() - 1, 1); // Trailing comma.
|
|
|
|
|
return stringRep;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-01-13 13:49:23 +01:00
|
|
|
MaemoDeviceConfig::Ptr MaemoDeviceConfig::create(const QString &name,
|
2011-02-02 10:30:38 +01:00
|
|
|
MaemoGlobal::MaemoVersion osVersion, DeviceType type, Id &nextId)
|
2009-11-27 16:40:07 +01:00
|
|
|
{
|
2011-02-02 10:30:38 +01:00
|
|
|
return Ptr(new MaemoDeviceConfig(name, osVersion, type, nextId));
|
2011-01-13 13:49:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaemoDeviceConfig::Ptr MaemoDeviceConfig::create(const QSettings &settings,
|
|
|
|
|
Id &nextId)
|
|
|
|
|
{
|
2011-01-13 14:32:15 +01:00
|
|
|
return Ptr(new MaemoDeviceConfig(settings, nextId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaemoDeviceConfig::Ptr MaemoDeviceConfig::create(const ConstPtr &other)
|
|
|
|
|
{
|
|
|
|
|
return Ptr(new MaemoDeviceConfig(other));
|
2011-01-13 13:49:23 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-02 10:30:38 +01:00
|
|
|
MaemoDeviceConfig::MaemoDeviceConfig(const QString &name,
|
|
|
|
|
MaemoGlobal::MaemoVersion osVersion, DeviceType devType, Id &nextId)
|
2011-01-13 13:49:23 +01:00
|
|
|
: m_sshParameters(Core::SshConnectionParameters::NoProxy),
|
|
|
|
|
m_name(name),
|
2011-02-02 10:30:38 +01:00
|
|
|
m_osVersion(osVersion),
|
2011-01-13 13:49:23 +01:00
|
|
|
m_type(devType),
|
|
|
|
|
m_portsSpec(defaultPortsSpec(m_type)),
|
2011-01-13 14:32:15 +01:00
|
|
|
m_isDefault(false),
|
|
|
|
|
m_internalId(nextId++)
|
2011-01-13 13:49:23 +01:00
|
|
|
{
|
|
|
|
|
m_sshParameters.host = defaultHost(m_type);
|
|
|
|
|
m_sshParameters.port = defaultSshPort(m_type);
|
2011-02-02 10:30:38 +01:00
|
|
|
m_sshParameters.uname = defaultUser(m_osVersion);
|
2011-01-13 13:49:23 +01:00
|
|
|
m_sshParameters.authType = DefaultAuthType;
|
|
|
|
|
m_sshParameters.privateKeyFile
|
|
|
|
|
= MaemoDeviceConfigurations::instance()->defaultSshKeyFilePath();
|
|
|
|
|
m_sshParameters.timeout = DefaultTimeout;
|
2009-11-27 16:40:07 +01:00
|
|
|
}
|
|
|
|
|
|
2009-12-23 10:53:57 +01:00
|
|
|
MaemoDeviceConfig::MaemoDeviceConfig(const QSettings &settings,
|
2011-01-13 15:01:46 +01:00
|
|
|
Id &nextId)
|
2011-01-13 13:49:23 +01:00
|
|
|
: m_sshParameters(Core::SshConnectionParameters::NoProxy),
|
|
|
|
|
m_name(settings.value(NameKey).toString()),
|
2011-02-02 10:30:38 +01:00
|
|
|
m_osVersion(static_cast<MaemoGlobal::MaemoVersion>(settings.value(OsVersionKey, MaemoGlobal::Maemo5).toInt())),
|
2011-01-13 13:49:23 +01:00
|
|
|
m_type(static_cast<DeviceType>(settings.value(TypeKey, DefaultDeviceType).toInt())),
|
|
|
|
|
m_portsSpec(settings.value(PortsSpecKey, defaultPortsSpec(m_type)).toString()),
|
2011-01-13 14:32:15 +01:00
|
|
|
m_isDefault(settings.value(IsDefaultKey, false).toBool()),
|
|
|
|
|
m_internalId(settings.value(InternalIdKey, nextId).toULongLong())
|
2011-01-13 13:49:23 +01:00
|
|
|
{
|
|
|
|
|
if (m_internalId == nextId)
|
2009-12-16 16:05:01 +01:00
|
|
|
++nextId;
|
2011-01-13 13:49:23 +01:00
|
|
|
m_sshParameters.host = settings.value(HostKey, defaultHost(m_type)).toString();
|
|
|
|
|
m_sshParameters.port = settings.value(SshPortKey, defaultSshPort(m_type)).toInt();
|
2011-02-02 10:30:38 +01:00
|
|
|
m_sshParameters.uname = settings.value(UserNameKey, defaultUser(m_osVersion)).toString();
|
2011-01-13 13:49:23 +01:00
|
|
|
m_sshParameters.authType
|
2010-04-26 11:43:25 +02:00
|
|
|
= static_cast<AuthType>(settings.value(AuthKey, DefaultAuthType).toInt());
|
2011-01-13 13:49:23 +01:00
|
|
|
m_sshParameters.pwd = settings.value(PasswordKey).toString();
|
|
|
|
|
m_sshParameters.privateKeyFile
|
2010-04-26 11:43:25 +02:00
|
|
|
= settings.value(KeyFileKey, DefaultKeyFile).toString();
|
2011-01-13 13:49:23 +01:00
|
|
|
m_sshParameters.timeout = settings.value(TimeoutKey, DefaultTimeout).toInt();
|
2009-12-01 14:04:25 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-13 14:32:15 +01:00
|
|
|
MaemoDeviceConfig::MaemoDeviceConfig(const MaemoDeviceConfig::ConstPtr &other)
|
|
|
|
|
: m_sshParameters(other->m_sshParameters),
|
|
|
|
|
m_name(other->m_name),
|
2011-02-02 10:30:38 +01:00
|
|
|
m_osVersion(other->m_osVersion),
|
2011-01-13 14:32:15 +01:00
|
|
|
m_type(other->type()),
|
|
|
|
|
m_portsSpec(other->m_portsSpec),
|
|
|
|
|
m_isDefault(other->m_isDefault),
|
|
|
|
|
m_internalId(other->m_internalId)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-12 17:10:39 +02:00
|
|
|
QString MaemoDeviceConfig::portsRegExpr()
|
|
|
|
|
{
|
|
|
|
|
const QLatin1String portExpr("(\\d)+");
|
|
|
|
|
const QString listElemExpr = QString::fromLatin1("%1(-%1)?").arg(portExpr);
|
|
|
|
|
return QString::fromLatin1("((%1)(,%1)*)?").arg(listElemExpr);
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-08 17:31:55 +02:00
|
|
|
int MaemoDeviceConfig::defaultSshPort(DeviceType type) const
|
|
|
|
|
{
|
|
|
|
|
return type == Physical ? DefaultSshPortHW : DefaultSshPortSim;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-12 19:12:12 +02:00
|
|
|
QString MaemoDeviceConfig::defaultPortsSpec(DeviceType type) const
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String(type == Physical ? "10000-10100" : "13219,14168");
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-08 17:31:55 +02:00
|
|
|
QString MaemoDeviceConfig::defaultHost(DeviceType type) const
|
|
|
|
|
{
|
|
|
|
|
return type == Physical ? DefaultHostNameHW : DefaultHostNameSim;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-02 10:30:38 +01:00
|
|
|
QString MaemoDeviceConfig::defaultUser(MaemoGlobal::MaemoVersion osVersion) const
|
|
|
|
|
{
|
|
|
|
|
switch (osVersion) {
|
|
|
|
|
case MaemoGlobal::Maemo5:
|
|
|
|
|
case MaemoGlobal::Maemo6:
|
|
|
|
|
return QLatin1String("developer");
|
|
|
|
|
case MaemoGlobal::Meego:
|
|
|
|
|
return QLatin1String("meego");
|
|
|
|
|
default:
|
|
|
|
|
Q_ASSERT(false);
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-13 13:49:23 +01:00
|
|
|
MaemoPortList MaemoDeviceConfig::freePorts() const
|
2009-11-27 16:40:07 +01:00
|
|
|
{
|
2011-01-13 13:49:23 +01:00
|
|
|
return PortsSpecParser(m_portsSpec).parse();
|
2009-11-27 16:40:07 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-13 13:49:23 +01:00
|
|
|
void MaemoDeviceConfig::save(QSettings &settings) const
|
2010-08-12 17:10:39 +02:00
|
|
|
{
|
2011-01-13 13:49:23 +01:00
|
|
|
settings.setValue(NameKey, m_name);
|
2011-02-02 10:30:38 +01:00
|
|
|
settings.setValue(OsVersionKey, m_osVersion);
|
2011-01-13 13:49:23 +01:00
|
|
|
settings.setValue(TypeKey, m_type);
|
|
|
|
|
settings.setValue(HostKey, m_sshParameters.host);
|
|
|
|
|
settings.setValue(SshPortKey, m_sshParameters.port);
|
|
|
|
|
settings.setValue(PortsSpecKey, m_portsSpec);
|
|
|
|
|
settings.setValue(UserNameKey, m_sshParameters.uname);
|
|
|
|
|
settings.setValue(AuthKey, m_sshParameters.authType);
|
|
|
|
|
settings.setValue(PasswordKey, m_sshParameters.pwd);
|
|
|
|
|
settings.setValue(KeyFileKey, m_sshParameters.privateKeyFile);
|
|
|
|
|
settings.setValue(TimeoutKey, m_sshParameters.timeout);
|
2011-01-13 14:32:15 +01:00
|
|
|
settings.setValue(IsDefaultKey, m_isDefault);
|
2011-01-13 13:49:23 +01:00
|
|
|
settings.setValue(InternalIdKey, m_internalId);
|
2010-08-12 17:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
2011-01-13 16:24:05 +01:00
|
|
|
const MaemoDeviceConfig::Id MaemoDeviceConfig::InvalidId = 0;
|
|
|
|
|
|
|
|
|
|
|
2011-01-13 13:49:23 +01:00
|
|
|
MaemoDeviceConfigurations *MaemoDeviceConfigurations::instance(QObject *parent)
|
2009-11-27 16:40:07 +01:00
|
|
|
{
|
2011-01-13 13:49:23 +01:00
|
|
|
if (m_instance == 0) {
|
|
|
|
|
m_instance = new MaemoDeviceConfigurations(parent);
|
|
|
|
|
m_instance->load();
|
|
|
|
|
}
|
|
|
|
|
return m_instance;
|
2009-11-27 16:40:07 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-13 13:49:23 +01:00
|
|
|
void MaemoDeviceConfigurations::replaceInstance(const MaemoDeviceConfigurations *other)
|
2009-11-27 16:40:07 +01:00
|
|
|
{
|
2011-01-13 13:49:23 +01:00
|
|
|
Q_ASSERT(m_instance);
|
|
|
|
|
m_instance->beginResetModel();
|
2011-01-13 14:32:15 +01:00
|
|
|
copy(other, m_instance, false);
|
2011-01-13 13:49:23 +01:00
|
|
|
m_instance->save();
|
|
|
|
|
m_instance->endResetModel();
|
|
|
|
|
emit m_instance->updated();
|
2009-11-27 16:40:07 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-13 13:49:23 +01:00
|
|
|
MaemoDeviceConfigurations *MaemoDeviceConfigurations::cloneInstance()
|
2009-11-27 16:40:07 +01:00
|
|
|
{
|
2011-01-13 13:49:23 +01:00
|
|
|
MaemoDeviceConfigurations * const other = new MaemoDeviceConfigurations(0);
|
2011-01-13 14:32:15 +01:00
|
|
|
copy(m_instance, other, true);
|
2011-01-13 13:49:23 +01:00
|
|
|
return other;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDeviceConfigurations::copy(const MaemoDeviceConfigurations *source,
|
2011-01-13 14:32:15 +01:00
|
|
|
MaemoDeviceConfigurations *target, bool deep)
|
2011-01-13 13:49:23 +01:00
|
|
|
{
|
2011-01-13 14:32:15 +01:00
|
|
|
if (deep) {
|
|
|
|
|
foreach (const MaemoDeviceConfig::ConstPtr &devConf, source->m_devConfigs)
|
|
|
|
|
target->m_devConfigs << MaemoDeviceConfig::create(devConf);
|
|
|
|
|
} else {
|
|
|
|
|
target->m_devConfigs = source->m_devConfigs;
|
|
|
|
|
}
|
2011-01-13 13:49:23 +01:00
|
|
|
target->m_defaultSshKeyFilePath = source->m_defaultSshKeyFilePath;
|
|
|
|
|
target->m_nextId = source->m_nextId;
|
|
|
|
|
target->initShadowDevConfs();
|
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);
|
2010-12-06 15:28:16 +01:00
|
|
|
settings->setValue(DefaultKeyFilePathKey, m_defaultSshKeyFilePath);
|
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);
|
2011-01-13 13:49:23 +01:00
|
|
|
m_devConfigs.at(i)->save(*settings);
|
2009-11-30 14:09:08 +01:00
|
|
|
}
|
2009-11-27 16:40:07 +01:00
|
|
|
settings->endArray();
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-13 13:49:23 +01:00
|
|
|
void MaemoDeviceConfigurations::initShadowDevConfs()
|
|
|
|
|
{
|
|
|
|
|
m_shadowDevConfigs.clear();
|
|
|
|
|
for (int i = 0; i < m_devConfigs.count(); ++i)
|
|
|
|
|
m_shadowDevConfigs.push_back(MaemoDeviceConfig::Ptr());
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-13 15:01:46 +01:00
|
|
|
void MaemoDeviceConfigurations::setupShadowDevConf(int idx)
|
2011-01-13 13:49:23 +01:00
|
|
|
{
|
2011-01-13 15:01:46 +01:00
|
|
|
MaemoDeviceConfig::Ptr shadowConf = m_shadowDevConfigs.at(idx);
|
2011-01-13 13:49:23 +01:00
|
|
|
if (shadowConf)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-01-13 15:01:46 +01:00
|
|
|
const MaemoDeviceConfig::Ptr devConf = m_devConfigs.at(idx);
|
2011-01-13 13:49:23 +01:00
|
|
|
const MaemoDeviceConfig::DeviceType shadowType
|
|
|
|
|
= devConf->type() == MaemoDeviceConfig::Physical
|
|
|
|
|
? MaemoDeviceConfig::Simulator : MaemoDeviceConfig::Physical;
|
2011-02-02 10:30:38 +01:00
|
|
|
shadowConf = MaemoDeviceConfig::create(devConf->name(),
|
|
|
|
|
devConf->osVersion(), shadowType, m_nextId);
|
2011-01-13 13:49:23 +01:00
|
|
|
shadowConf->m_sshParameters.authType = devConf->m_sshParameters.authType;
|
|
|
|
|
shadowConf->m_sshParameters.timeout = devConf->m_sshParameters.timeout;
|
|
|
|
|
shadowConf->m_sshParameters.pwd = devConf->m_sshParameters.pwd;
|
|
|
|
|
shadowConf->m_sshParameters.privateKeyFile
|
|
|
|
|
= devConf->m_sshParameters.privateKeyFile;
|
2011-01-13 14:32:15 +01:00
|
|
|
shadowConf->m_isDefault = devConf->m_isDefault;
|
2011-01-13 13:49:23 +01:00
|
|
|
shadowConf->m_internalId = devConf->m_internalId;
|
2011-01-13 15:01:46 +01:00
|
|
|
m_shadowDevConfigs[idx] = shadowConf;
|
2011-01-13 13:49:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDeviceConfigurations::addConfiguration(const QString &name,
|
2011-02-02 10:30:38 +01:00
|
|
|
MaemoGlobal::MaemoVersion osVersion, MaemoDeviceConfig::DeviceType type)
|
2011-01-13 13:49:23 +01:00
|
|
|
{
|
|
|
|
|
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
2011-01-13 14:32:15 +01:00
|
|
|
const MaemoDeviceConfig::Ptr devConf
|
2011-02-02 10:30:38 +01:00
|
|
|
= MaemoDeviceConfig::create(name, osVersion, type, m_nextId);
|
2011-01-13 14:32:15 +01:00
|
|
|
if (m_devConfigs.isEmpty())
|
|
|
|
|
devConf->m_isDefault = true;
|
|
|
|
|
m_devConfigs << devConf;
|
2011-01-13 13:49:23 +01:00
|
|
|
m_shadowDevConfigs << MaemoDeviceConfig::Ptr();
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-13 15:01:46 +01:00
|
|
|
void MaemoDeviceConfigurations::removeConfiguration(int idx)
|
2011-01-13 13:49:23 +01:00
|
|
|
{
|
2011-01-13 15:01:46 +01:00
|
|
|
Q_ASSERT(idx >= 0 && idx < rowCount());
|
|
|
|
|
beginRemoveRows(QModelIndex(), idx, idx);
|
|
|
|
|
const bool wasDefault = deviceAt(idx)->m_isDefault;
|
|
|
|
|
m_devConfigs.removeAt(idx);
|
|
|
|
|
m_shadowDevConfigs.removeAt(idx);
|
2011-01-13 13:49:23 +01:00
|
|
|
endRemoveRows();
|
2011-01-13 14:32:15 +01:00
|
|
|
if (wasDefault && !m_devConfigs.isEmpty()) {
|
|
|
|
|
m_devConfigs.first()->m_isDefault = true;
|
|
|
|
|
const QModelIndex changedIndex = index(0, 0);
|
|
|
|
|
emit dataChanged(changedIndex, changedIndex);
|
|
|
|
|
}
|
2011-01-13 13:49:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDeviceConfigurations::setConfigurationName(int i, const QString &name)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(i >= 0 && i < rowCount());
|
|
|
|
|
m_devConfigs.at(i)->m_name = name;
|
|
|
|
|
const MaemoDeviceConfig::Ptr shadowConfig = m_shadowDevConfigs.at(i);
|
|
|
|
|
if (shadowConfig)
|
|
|
|
|
shadowConfig->m_name = name;
|
|
|
|
|
const QModelIndex changedIndex = index(i, 0);
|
|
|
|
|
emit dataChanged(changedIndex, changedIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDeviceConfigurations::setDeviceType(int i,
|
|
|
|
|
const MaemoDeviceConfig::DeviceType type)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(i >= 0 && i < rowCount());
|
|
|
|
|
MaemoDeviceConfig::Ptr ¤t = m_devConfigs[i];
|
|
|
|
|
if (current->type() == type)
|
|
|
|
|
return;
|
|
|
|
|
setupShadowDevConf(i);
|
|
|
|
|
std::swap(current, m_shadowDevConfigs[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDeviceConfigurations::setSshParameters(int i,
|
|
|
|
|
const Core::SshConnectionParameters ¶ms)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(i >= 0 && i < rowCount());
|
|
|
|
|
m_devConfigs.at(i)->m_sshParameters = params;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDeviceConfigurations::setPortsSpec(int i, const QString &portsSpec)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(i >= 0 && i < rowCount());
|
|
|
|
|
m_devConfigs.at(i)->m_portsSpec = portsSpec;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-13 15:00:48 +01:00
|
|
|
void MaemoDeviceConfigurations::setDefaultDevice(int idx)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(idx >= 0 && idx < rowCount());
|
|
|
|
|
if (m_devConfigs.at(idx)->m_isDefault)
|
|
|
|
|
return;
|
|
|
|
|
QModelIndex oldDefaultIndex;
|
2011-01-13 15:05:10 +01:00
|
|
|
for (int i = 0; i < m_devConfigs.count(); ++i) {
|
2011-01-13 15:00:48 +01:00
|
|
|
const MaemoDeviceConfig::Ptr &oldDefaultDev = m_devConfigs.at(i);
|
|
|
|
|
if (oldDefaultDev->m_isDefault) {
|
|
|
|
|
oldDefaultDev->m_isDefault = false;
|
|
|
|
|
oldDefaultIndex = index(i, 0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Q_ASSERT(oldDefaultIndex.isValid());
|
|
|
|
|
emit dataChanged(oldDefaultIndex, oldDefaultIndex);
|
|
|
|
|
m_devConfigs.at(idx)->m_isDefault = true;
|
|
|
|
|
const QModelIndex newDefaultIndex = index(idx, 0);
|
|
|
|
|
emit dataChanged(newDefaultIndex, newDefaultIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-01 14:04:25 +01:00
|
|
|
MaemoDeviceConfigurations::MaemoDeviceConfigurations(QObject *parent)
|
2011-01-13 13:49:23 +01:00
|
|
|
: QAbstractListModel(parent)
|
2009-11-27 16:40:07 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
2010-12-06 15:28:16 +01:00
|
|
|
m_defaultSshKeyFilePath
|
|
|
|
|
= settings->value(DefaultKeyFilePathKey, DefaultKeyFile).toString();
|
2009-11-27 16:40:07 +01:00
|
|
|
int count = settings->beginReadArray(ConfigListKey);
|
2011-01-13 14:32:15 +01:00
|
|
|
bool hasDefault = false;
|
2009-11-30 14:09:08 +01:00
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
|
settings->setArrayIndex(i);
|
2011-01-13 14:32:15 +01:00
|
|
|
MaemoDeviceConfig::Ptr devConf
|
|
|
|
|
= MaemoDeviceConfig::create(*settings, m_nextId);
|
|
|
|
|
hasDefault |= devConf->m_isDefault;
|
|
|
|
|
m_devConfigs << devConf;
|
2009-11-30 14:09:08 +01:00
|
|
|
}
|
2009-11-27 16:40:07 +01:00
|
|
|
settings->endArray();
|
|
|
|
|
settings->endGroup();
|
2011-01-13 13:49:23 +01:00
|
|
|
initShadowDevConfs();
|
2011-01-13 14:32:15 +01:00
|
|
|
if (!hasDefault && !m_devConfigs.isEmpty())
|
|
|
|
|
m_devConfigs.first()->m_isDefault = true;
|
2009-11-27 16:40:07 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-13 15:01:46 +01:00
|
|
|
MaemoDeviceConfig::ConstPtr MaemoDeviceConfigurations::deviceAt(int idx) const
|
2009-12-01 14:04:25 +01:00
|
|
|
{
|
2011-01-13 15:01:46 +01:00
|
|
|
Q_ASSERT(idx >= 0 && idx < rowCount());
|
|
|
|
|
return m_devConfigs.at(idx);
|
2009-12-01 14:04:25 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-13 13:49:23 +01:00
|
|
|
bool MaemoDeviceConfigurations::hasConfig(const QString &name) const
|
2009-12-01 14:04:25 +01:00
|
|
|
{
|
2011-01-13 13:49:23 +01:00
|
|
|
QList<MaemoDeviceConfig::Ptr>::ConstIterator resultIt =
|
2009-12-01 14:04:25 +01:00
|
|
|
std::find_if(m_devConfigs.constBegin(), m_devConfigs.constEnd(),
|
2011-01-13 13:49:23 +01:00
|
|
|
DevConfNameMatcher(name));
|
|
|
|
|
return resultIt != m_devConfigs.constEnd();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaemoDeviceConfig::ConstPtr MaemoDeviceConfigurations::find(MaemoDeviceConfig::Id id) const
|
|
|
|
|
{
|
|
|
|
|
const int index = indexForInternalId(id);
|
|
|
|
|
return index == -1 ? MaemoDeviceConfig::ConstPtr() : deviceAt(index);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-13 14:32:15 +01:00
|
|
|
MaemoDeviceConfig::ConstPtr MaemoDeviceConfigurations::defaultDeviceConfig() const
|
|
|
|
|
{
|
|
|
|
|
foreach (const MaemoDeviceConfig::ConstPtr &devConf, m_devConfigs) {
|
|
|
|
|
if (devConf->m_isDefault)
|
|
|
|
|
return devConf;
|
|
|
|
|
}
|
|
|
|
|
Q_ASSERT(m_devConfigs.isEmpty());
|
|
|
|
|
return MaemoDeviceConfig::ConstPtr();
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-13 13:49:23 +01:00
|
|
|
int MaemoDeviceConfigurations::indexForInternalId(MaemoDeviceConfig::Id internalId) const
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < m_devConfigs.count(); ++i) {
|
2011-01-13 16:24:05 +01:00
|
|
|
if (deviceAt(i)->m_internalId == internalId)
|
2011-01-13 13:49:23 +01:00
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaemoDeviceConfig::Id MaemoDeviceConfigurations::internalId(MaemoDeviceConfig::ConstPtr devConf) const
|
|
|
|
|
{
|
2011-01-13 16:24:05 +01:00
|
|
|
return devConf ? devConf->m_internalId : MaemoDeviceConfig::InvalidId;
|
2011-01-13 13:49:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int MaemoDeviceConfigurations::rowCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(parent);
|
|
|
|
|
return m_devConfigs.count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant MaemoDeviceConfigurations::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid() || index.row() >= rowCount() || role != Qt::DisplayRole)
|
|
|
|
|
return QVariant();
|
|
|
|
|
const MaemoDeviceConfig::ConstPtr devConf = deviceAt(index.row());
|
|
|
|
|
QString name = devConf->name();
|
|
|
|
|
if (devConf->m_isDefault)
|
|
|
|
|
name += tr(" (default)");
|
|
|
|
|
return name;
|
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
|