1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef MAEMODEVICECONFIGURATIONS_H
35 #define MAEMODEVICECONFIGURATIONS_H
37 #include "maemoglobal.h"
39 #include <utils/ssh/sshconnection.h>
41 #include <QtCore/QAbstractListModel>
42 #include <QtCore/QList>
43 #include <QtCore/QPair>
44 #include <QtCore/QSharedPointer>
45 #include <QtCore/QString>
51 namespace Qt4ProjectManager {
57 void addPort(int port);
58 void addRange(int startPort, int endPort);
62 QString toString() const;
65 typedef QPair<int, int> Range;
66 QList<Range> m_ranges;
70 class MaemoDeviceConfig
72 friend class MaemoDeviceConfigurations;
74 typedef QSharedPointer<const MaemoDeviceConfig> ConstPtr;
76 enum DeviceType { Physical, Emulator };
78 MaemoPortList freePorts() const;
79 Utils::SshConnectionParameters sshParameters() const { return m_sshParameters; }
80 QString name() const { return m_name; }
81 MaemoGlobal::MaemoVersion osVersion() const { return m_osVersion; }
82 DeviceType type() const { return m_type; }
83 QString portsSpec() const { return m_portsSpec; }
84 Id internalId() const { return m_internalId; }
85 bool isDefault() const { return m_isDefault; }
86 static QString portsRegExpr();
87 static QString defaultHost(DeviceType type);
88 static QString defaultPrivateKeyFilePath();
89 static QString defaultPublicKeyFilePath();
90 static QString defaultUser(MaemoGlobal::MaemoVersion osVersion);
91 static int defaultSshPort(DeviceType type);
92 static QString defaultQemuPassword(MaemoGlobal::MaemoVersion osVersion);
94 static const Id InvalidId;
97 typedef QSharedPointer<MaemoDeviceConfig> Ptr;
99 MaemoDeviceConfig(const QString &name, MaemoGlobal::MaemoVersion osVersion,
100 DeviceType type, const Utils::SshConnectionParameters &sshParams,
102 MaemoDeviceConfig(const QSettings &settings, Id &nextId);
103 MaemoDeviceConfig(const ConstPtr &other);
105 MaemoDeviceConfig(const MaemoDeviceConfig &);
106 MaemoDeviceConfig &operator=(const MaemoDeviceConfig &);
108 static Ptr createHardwareConfig(const QString &name,
109 MaemoGlobal::MaemoVersion osVersion, const QString &hostName,
110 const QString privateKeyFilePath, Id &nextId);
111 static Ptr createEmulatorConfig(const QString &name,
112 MaemoGlobal::MaemoVersion osVersion, Id &nextId);
113 static Ptr create(const QSettings &settings, Id &nextId);
114 static Ptr create(const ConstPtr &other);
116 void save(QSettings &settings) const;
117 QString defaultPortsSpec(DeviceType type) const;
119 Utils::SshConnectionParameters m_sshParameters;
121 MaemoGlobal::MaemoVersion m_osVersion;
129 class MaemoDeviceConfigurations : public QAbstractListModel
132 Q_DISABLE_COPY(MaemoDeviceConfigurations)
134 static MaemoDeviceConfigurations *instance(QObject *parent = 0);
136 static void replaceInstance(const MaemoDeviceConfigurations *other);
137 static MaemoDeviceConfigurations *cloneInstance();
139 MaemoDeviceConfig::ConstPtr deviceAt(int index) const;
140 MaemoDeviceConfig::ConstPtr find(MaemoDeviceConfig::Id id) const;
141 MaemoDeviceConfig::ConstPtr defaultDeviceConfig(const MaemoGlobal::MaemoVersion osVersion) const;
142 bool hasConfig(const QString &name) const;
143 int indexForInternalId(MaemoDeviceConfig::Id internalId) const;
144 MaemoDeviceConfig::Id internalId(MaemoDeviceConfig::ConstPtr devConf) const;
146 void setDefaultSshKeyFilePath(const QString &path) { m_defaultSshKeyFilePath = path; }
147 QString defaultSshKeyFilePath() const { return m_defaultSshKeyFilePath; }
149 void addHardwareDeviceConfiguration(const QString &name,
150 MaemoGlobal::MaemoVersion osVersion, const QString &hostName,
151 const QString privateKeyFilePath);
152 void addEmulatorDeviceConfiguration(const QString &name,
153 MaemoGlobal::MaemoVersion osVersion);
154 void removeConfiguration(int index);
155 void setConfigurationName(int i, const QString &name);
156 void setSshParameters(int i, const Utils::SshConnectionParameters ¶ms);
157 void setPortsSpec(int i, const QString &portsSpec);
158 void setDefaultDevice(int index);
160 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
161 virtual QVariant data(const QModelIndex &index,
162 int role = Qt::DisplayRole) const;
168 MaemoDeviceConfigurations(QObject *parent);
171 static void copy(const MaemoDeviceConfigurations *source,
172 MaemoDeviceConfigurations *target, bool deep);
173 void addConfiguration(const MaemoDeviceConfig::Ptr &devConfig);
174 void ensureDefaultExists(MaemoGlobal::MaemoVersion osVersion);
176 static MaemoDeviceConfigurations *m_instance;
177 MaemoDeviceConfig::Id m_nextId;
178 QList<MaemoDeviceConfig::Ptr> m_devConfigs;
179 QString m_defaultSshKeyFilePath;
182 } // namespace Internal
183 } // namespace Qt4ProjectManager
185 #endif // MAEMODEVICECONFIGURATIONS_H