OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qt-maemo / maemodeviceconfigurations.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the Qt Creator.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
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 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 ** $QT_END_LICENSE$
32 **
33 ****************************************************************************/
34
35 #ifndef MAEMODEVICECONFIGURATIONS_H
36 #define MAEMODEVICECONFIGURATIONS_H
37
38 #include <coreplugin/ssh/sshconnection.h>
39
40 #include <QtCore/QList>
41 #include <QtCore/QObject>
42 #include <QtCore/QPair>
43 #include <QtCore/QString>
44
45 QT_BEGIN_NAMESPACE
46 class QSettings;
47 QT_END_NAMESPACE
48
49 namespace Qt4ProjectManager {
50 namespace Internal {
51
52 class MaemoPortList
53 {
54     typedef QPair<int, int> Range;
55 public:
56     void addPort(int port) { addRange(port, port); }
57     void addRange(int startPort, int endPort) {
58         m_ranges << Range(startPort, endPort);
59     }
60     bool hasMore() const { return !m_ranges.isEmpty(); }
61     int count() const {
62         int n = 0;
63         foreach (const Range &r, m_ranges)
64             n += r.second - r.first + 1;
65         return n;
66     }
67     int getNext() {
68         Q_ASSERT(!m_ranges.isEmpty());
69         Range &firstRange = m_ranges.first();
70         const int next = firstRange.first++;
71         if (firstRange.first > firstRange.second)
72             m_ranges.removeFirst();
73         return next;
74     }
75     QString toString() const
76     {
77         QString stringRep;
78         foreach (const Range &range, m_ranges) {
79             stringRep += QString::number(range.first);
80             if (range.second != range.first)
81                 stringRep += QLatin1Char('-') + QString::number(range.second);
82             stringRep += QLatin1Char(',');
83         }
84         if (!stringRep.isEmpty())
85             stringRep.remove(stringRep.length() - 1, 1); // Trailing comma.
86         return stringRep;
87     }
88
89 private:
90     QList<Range> m_ranges;
91 };
92
93 class MaemoDeviceConfig
94 {
95 public:
96     enum DeviceType { Physical, Simulator };
97     MaemoDeviceConfig();
98     MaemoDeviceConfig(const QString &name, DeviceType type);
99     MaemoDeviceConfig(const QSettings &settings, quint64 &nextId);
100     void save(QSettings &settings) const;
101     bool isValid() const;
102     MaemoPortList freePorts() const;
103     static QString portsRegExpr();
104
105     static const quint64 InvalidId = 0;
106
107     Core::SshConnectionParameters server;
108     QString name;
109     DeviceType type;
110     QString portsSpec;
111     quint64 internalId;
112
113 private:
114     int defaultSshPort(DeviceType type) const;
115     QString defaultPortsSpec(DeviceType type) const;
116     QString defaultHost(DeviceType type) const;
117
118 };
119
120 class DevConfNameMatcher
121 {
122 public:
123     DevConfNameMatcher(const QString &name) : m_name(name) {}
124     bool operator()(const MaemoDeviceConfig &devConfig)
125     {
126         return devConfig.name == m_name;
127     }
128 private:
129     const QString m_name;
130 };
131
132
133 class MaemoDeviceConfigurations : public QObject
134 {
135     Q_OBJECT
136     Q_DISABLE_COPY(MaemoDeviceConfigurations)
137 public:
138
139     static MaemoDeviceConfigurations &instance(QObject *parent = 0);
140
141     QList<MaemoDeviceConfig> devConfigs() const { return m_devConfigs; }
142     void setDevConfigs(const QList<MaemoDeviceConfig> &devConfigs);
143
144     MaemoDeviceConfig find(const QString &name) const;
145     MaemoDeviceConfig find(quint64 id) const;
146
147     void setDefaultSshKeyFilePath(const QString &path) { m_defaultSshKeyFilePath = path; }
148     QString defaultSshKeyFilePath() const { return m_defaultSshKeyFilePath; }
149
150 signals:
151     void updated();
152
153 private:
154     MaemoDeviceConfigurations(QObject *parent);
155     void load();
156     void save();
157
158     static MaemoDeviceConfigurations *m_instance;
159     QList<MaemoDeviceConfig> m_devConfigs;
160     quint64 m_nextId;
161     QString m_defaultSshKeyFilePath;
162     friend class MaemoDeviceConfig;
163 };
164
165 } // namespace Internal
166 } // namespace Qt4ProjectManager
167
168 #endif // MAEMODEVICECONFIGURATIONS_H