forked from qt-creator/qt-creator
Maemo: Refactor device configurations list.
This commit is contained in:
@@ -37,9 +37,10 @@
|
||||
|
||||
#include <coreplugin/ssh/sshconnection.h>
|
||||
|
||||
#include <QtCore/QAbstractListModel>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QPair>
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <QtCore/QString>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@@ -92,61 +93,79 @@ private:
|
||||
|
||||
class MaemoDeviceConfig
|
||||
{
|
||||
friend class MaemoDeviceConfigurations;
|
||||
public:
|
||||
typedef QSharedPointer<const MaemoDeviceConfig> ConstPtr;
|
||||
typedef quint64 Id;
|
||||
enum DeviceType { Physical, Simulator };
|
||||
MaemoDeviceConfig();
|
||||
MaemoDeviceConfig(const QString &name, DeviceType type);
|
||||
MaemoDeviceConfig(const QSettings &settings, quint64 &nextId);
|
||||
void save(QSettings &settings) const;
|
||||
bool isValid() const;
|
||||
|
||||
MaemoPortList freePorts() const;
|
||||
Core::SshConnectionParameters sshParameters() const { return m_sshParameters; }
|
||||
QString name() const { return m_name; }
|
||||
DeviceType type() const { return m_type; }
|
||||
QString portsSpec() const { return m_portsSpec; }
|
||||
Id internalId() const { return m_internalId; }
|
||||
static QString portsRegExpr();
|
||||
|
||||
static const quint64 InvalidId = 0;
|
||||
|
||||
Core::SshConnectionParameters server;
|
||||
QString name;
|
||||
DeviceType type;
|
||||
QString portsSpec;
|
||||
quint64 internalId;
|
||||
static const Id InvalidId = 0;
|
||||
|
||||
private:
|
||||
typedef QSharedPointer<MaemoDeviceConfig> Ptr;
|
||||
|
||||
MaemoDeviceConfig(const QString &name, DeviceType type, Id &nextId);
|
||||
MaemoDeviceConfig(const QSettings &settings, Id &nextId);
|
||||
|
||||
MaemoDeviceConfig(const MaemoDeviceConfig &);
|
||||
MaemoDeviceConfig &operator=(const MaemoDeviceConfig &);
|
||||
|
||||
static Ptr create(const QString &name, DeviceType type, Id &nextId);
|
||||
static Ptr create(const QSettings &settings, Id &nextId);
|
||||
|
||||
void save(QSettings &settings) const;
|
||||
int defaultSshPort(DeviceType type) const;
|
||||
QString defaultPortsSpec(DeviceType type) const;
|
||||
QString defaultHost(DeviceType type) const;
|
||||
|
||||
};
|
||||
|
||||
class DevConfNameMatcher
|
||||
{
|
||||
public:
|
||||
DevConfNameMatcher(const QString &name) : m_name(name) {}
|
||||
bool operator()(const MaemoDeviceConfig &devConfig)
|
||||
{
|
||||
return devConfig.name == m_name;
|
||||
}
|
||||
private:
|
||||
const QString m_name;
|
||||
Core::SshConnectionParameters m_sshParameters;
|
||||
QString m_name;
|
||||
DeviceType m_type;
|
||||
QString m_portsSpec;
|
||||
Id m_internalId;
|
||||
bool m_isDefault;
|
||||
};
|
||||
|
||||
|
||||
class MaemoDeviceConfigurations : public QObject
|
||||
class MaemoDeviceConfigurations : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(MaemoDeviceConfigurations)
|
||||
public:
|
||||
static MaemoDeviceConfigurations *instance(QObject *parent = 0);
|
||||
|
||||
static MaemoDeviceConfigurations &instance(QObject *parent = 0);
|
||||
static void replaceInstance(const MaemoDeviceConfigurations *other);
|
||||
static MaemoDeviceConfigurations *cloneInstance();
|
||||
|
||||
QList<MaemoDeviceConfig> devConfigs() const { return m_devConfigs; }
|
||||
void setDevConfigs(const QList<MaemoDeviceConfig> &devConfigs);
|
||||
|
||||
MaemoDeviceConfig find(const QString &name) const;
|
||||
MaemoDeviceConfig find(quint64 id) const;
|
||||
MaemoDeviceConfig::ConstPtr deviceAt(int i) const;
|
||||
MaemoDeviceConfig::ConstPtr find(MaemoDeviceConfig::Id id) const;
|
||||
bool hasConfig(const QString &name) const;
|
||||
int indexForInternalId(MaemoDeviceConfig::Id internalId) const;
|
||||
MaemoDeviceConfig::Id internalId(MaemoDeviceConfig::ConstPtr devConf) const;
|
||||
|
||||
void setDefaultSshKeyFilePath(const QString &path) { m_defaultSshKeyFilePath = path; }
|
||||
QString defaultSshKeyFilePath() const { return m_defaultSshKeyFilePath; }
|
||||
|
||||
void addConfiguration(const QString &name,
|
||||
MaemoDeviceConfig::DeviceType type);
|
||||
void removeConfiguration(int i);
|
||||
void setConfigurationName(int i, const QString &name);
|
||||
void setDeviceType(int i, const MaemoDeviceConfig::DeviceType type);
|
||||
void setSshParameters(int i, const Core::SshConnectionParameters ¶ms);
|
||||
void setPortsSpec(int i, const QString &portsSpec);
|
||||
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual QVariant data(const QModelIndex &index,
|
||||
int role = Qt::DisplayRole) const;
|
||||
|
||||
signals:
|
||||
void updated();
|
||||
|
||||
@@ -154,12 +173,16 @@ private:
|
||||
MaemoDeviceConfigurations(QObject *parent);
|
||||
void load();
|
||||
void save();
|
||||
void initShadowDevConfs();
|
||||
static void copy(const MaemoDeviceConfigurations *source,
|
||||
MaemoDeviceConfigurations *target);
|
||||
void setupShadowDevConf(int i);
|
||||
|
||||
static MaemoDeviceConfigurations *m_instance;
|
||||
QList<MaemoDeviceConfig> m_devConfigs;
|
||||
quint64 m_nextId;
|
||||
MaemoDeviceConfig::Id m_nextId;
|
||||
QList<MaemoDeviceConfig::Ptr> m_devConfigs;
|
||||
QList<MaemoDeviceConfig::Ptr> m_shadowDevConfigs;
|
||||
QString m_defaultSshKeyFilePath;
|
||||
friend class MaemoDeviceConfig;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user