OSDN Git Service

d4d6d7370073d38a7e809c7028dff20e3cbb04ce
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qt-maemo / maemodeviceconfigurations.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef MAEMODEVICECONFIGURATIONS_H
35 #define MAEMODEVICECONFIGURATIONS_H
36
37 #include "maemoglobal.h"
38
39 #include <utils/ssh/sshconnection.h>
40
41 #include <QtCore/QAbstractListModel>
42 #include <QtCore/QList>
43 #include <QtCore/QPair>
44 #include <QtCore/QSharedPointer>
45 #include <QtCore/QString>
46
47 QT_BEGIN_NAMESPACE
48 class QSettings;
49 QT_END_NAMESPACE
50
51 namespace Qt4ProjectManager {
52 namespace Internal {
53
54 class MaemoPortList
55 {
56 public:
57     void addPort(int port);
58     void addRange(int startPort, int endPort);
59     bool hasMore() const;
60     int count() const;
61     int getNext();
62     QString toString() const;
63
64 private:
65     typedef QPair<int, int> Range;
66     QList<Range> m_ranges;
67 };
68
69
70 class MaemoDeviceConfig
71 {
72     friend class MaemoDeviceConfigurations;
73 public:
74     typedef QSharedPointer<const MaemoDeviceConfig> ConstPtr;
75     typedef quint64 Id;
76     enum DeviceType { Physical, Emulator };
77
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);
93
94     static const Id InvalidId;
95
96 private:
97     typedef QSharedPointer<MaemoDeviceConfig> Ptr;
98
99     MaemoDeviceConfig(const QString &name, MaemoGlobal::MaemoVersion osVersion,
100         DeviceType type, const Utils::SshConnectionParameters &sshParams,
101         Id &nextId);
102     MaemoDeviceConfig(const QSettings &settings, Id &nextId);
103     MaemoDeviceConfig(const ConstPtr &other);
104
105     MaemoDeviceConfig(const MaemoDeviceConfig &);
106     MaemoDeviceConfig &operator=(const MaemoDeviceConfig &);
107
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);
115
116     void save(QSettings &settings) const;
117     QString defaultPortsSpec(DeviceType type) const;
118
119     Utils::SshConnectionParameters m_sshParameters;
120     QString m_name;
121     MaemoGlobal::MaemoVersion m_osVersion;
122     DeviceType m_type;
123     QString m_portsSpec;
124     bool m_isDefault;
125     Id m_internalId;
126 };
127
128
129 class MaemoDeviceConfigurations : public QAbstractListModel
130 {
131     Q_OBJECT
132     Q_DISABLE_COPY(MaemoDeviceConfigurations)
133 public:
134     static MaemoDeviceConfigurations *instance(QObject *parent = 0);
135
136     static void replaceInstance(const MaemoDeviceConfigurations *other);
137     static MaemoDeviceConfigurations *cloneInstance();
138
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;
145
146     void setDefaultSshKeyFilePath(const QString &path) { m_defaultSshKeyFilePath = path; }
147     QString defaultSshKeyFilePath() const { return m_defaultSshKeyFilePath; }
148
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 &params);
157     void setPortsSpec(int i, const QString &portsSpec);
158     void setDefaultDevice(int index);
159
160     virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
161     virtual QVariant data(const QModelIndex &index,
162         int role = Qt::DisplayRole) const;
163
164 signals:
165     void updated();
166
167 private:
168     MaemoDeviceConfigurations(QObject *parent);
169     void load();
170     void save();
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);
175
176     static MaemoDeviceConfigurations *m_instance;
177     MaemoDeviceConfig::Id m_nextId;
178     QList<MaemoDeviceConfig::Ptr> m_devConfigs;
179     QString m_defaultSshKeyFilePath;
180 };
181
182 } // namespace Internal
183 } // namespace Qt4ProjectManager
184
185 #endif // MAEMODEVICECONFIGURATIONS_H