1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the Qt Creator.
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
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
33 ****************************************************************************/
35 #ifndef MAEMODEVICECONFIGURATIONS_H
36 #define MAEMODEVICECONFIGURATIONS_H
38 #include <coreplugin/ssh/sshconnection.h>
40 #include <QtCore/QList>
41 #include <QtCore/QObject>
42 #include <QtCore/QPair>
43 #include <QtCore/QString>
49 namespace Qt4ProjectManager {
54 typedef QPair<int, int> Range;
56 void addPort(int port) { addRange(port, port); }
57 void addRange(int startPort, int endPort) {
58 m_ranges << Range(startPort, endPort);
60 bool hasMore() const { return !m_ranges.isEmpty(); }
63 foreach (const Range &r, m_ranges)
64 n += r.second - r.first + 1;
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();
75 QString toString() const
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(',');
84 if (!stringRep.isEmpty())
85 stringRep.remove(stringRep.length() - 1, 1); // Trailing comma.
90 QList<Range> m_ranges;
93 class MaemoDeviceConfig
96 enum DeviceType { Physical, Simulator };
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();
105 static const quint64 InvalidId = 0;
107 Core::SshConnectionParameters server;
114 int defaultSshPort(DeviceType type) const;
115 QString defaultPortsSpec(DeviceType type) const;
116 QString defaultHost(DeviceType type) const;
120 class DevConfNameMatcher
123 DevConfNameMatcher(const QString &name) : m_name(name) {}
124 bool operator()(const MaemoDeviceConfig &devConfig)
126 return devConfig.name == m_name;
129 const QString m_name;
133 class MaemoDeviceConfigurations : public QObject
136 Q_DISABLE_COPY(MaemoDeviceConfigurations)
139 static MaemoDeviceConfigurations &instance(QObject *parent = 0);
141 QList<MaemoDeviceConfig> devConfigs() const { return m_devConfigs; }
142 void setDevConfigs(const QList<MaemoDeviceConfig> &devConfigs);
144 MaemoDeviceConfig find(const QString &name) const;
145 MaemoDeviceConfig find(quint64 id) const;
147 void setDefaultSshKeyFilePath(const QString &path) { m_defaultSshKeyFilePath = path; }
148 QString defaultSshKeyFilePath() const { return m_defaultSshKeyFilePath; }
154 MaemoDeviceConfigurations(QObject *parent);
158 static MaemoDeviceConfigurations *m_instance;
159 QList<MaemoDeviceConfig> m_devConfigs;
161 QString m_defaultSshKeyFilePath;
162 friend class MaemoDeviceConfig;
165 } // namespace Internal
166 } // namespace Qt4ProjectManager
168 #endif // MAEMODEVICECONFIGURATIONS_H