| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 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 tools applications of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 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 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at qt-info@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef SYMBIANDEVICEMANAGER_H
|
|---|
| 43 | #define SYMBIANDEVICEMANAGER_H
|
|---|
| 44 |
|
|---|
| 45 | #include "symbianutils_global.h"
|
|---|
| 46 |
|
|---|
| 47 | #include <QtCore/QObject>
|
|---|
| 48 | #include <QtCore/QExplicitlySharedDataPointer>
|
|---|
| 49 |
|
|---|
| 50 | QT_BEGIN_NAMESPACE
|
|---|
| 51 | class QDebug;
|
|---|
| 52 | class QTextStream;
|
|---|
| 53 | QT_END_NAMESPACE
|
|---|
| 54 |
|
|---|
| 55 | namespace SymbianUtils {
|
|---|
| 56 |
|
|---|
| 57 | struct SymbianDeviceManagerPrivate;
|
|---|
| 58 | class SymbianDeviceData;
|
|---|
| 59 |
|
|---|
| 60 | enum DeviceCommunicationType {
|
|---|
| 61 | SerialPortCommunication = 0,
|
|---|
| 62 | BlueToothCommunication = 1
|
|---|
| 63 | };
|
|---|
| 64 |
|
|---|
| 65 | // SymbianDevice, explicitly shared.
|
|---|
| 66 | class SYMBIANUTILS_EXPORT SymbianDevice {
|
|---|
| 67 | explicit SymbianDevice(SymbianDeviceData *data);
|
|---|
| 68 | friend class SymbianDeviceManager;
|
|---|
| 69 | public:
|
|---|
| 70 | SymbianDevice();
|
|---|
| 71 | SymbianDevice(const SymbianDevice &rhs);
|
|---|
| 72 | SymbianDevice &operator=(const SymbianDevice &rhs);
|
|---|
| 73 | ~SymbianDevice();
|
|---|
| 74 | int compare(const SymbianDevice &rhs) const;
|
|---|
| 75 |
|
|---|
| 76 | DeviceCommunicationType type() const;
|
|---|
| 77 | bool isNull() const;
|
|---|
| 78 | QString portName() const;
|
|---|
| 79 | QString friendlyName() const;
|
|---|
| 80 |
|
|---|
| 81 | // Windows only.
|
|---|
| 82 | QString deviceDesc() const;
|
|---|
| 83 | QString manufacturer() const;
|
|---|
| 84 |
|
|---|
| 85 | void format(QTextStream &str) const;
|
|---|
| 86 | QString toString() const;
|
|---|
| 87 |
|
|---|
| 88 | private:
|
|---|
| 89 | QExplicitlySharedDataPointer<SymbianDeviceData> m_data;
|
|---|
| 90 | };
|
|---|
| 91 |
|
|---|
| 92 | QDebug operator<<(QDebug d, const SymbianDevice &);
|
|---|
| 93 |
|
|---|
| 94 | inline bool operator==(const SymbianDevice &d1, const SymbianDevice &d2)
|
|---|
| 95 | { return d1.compare(d2) == 0; }
|
|---|
| 96 | inline bool operator!=(const SymbianDevice &d1, const SymbianDevice &d2)
|
|---|
| 97 | { return d1.compare(d2) != 0; }
|
|---|
| 98 | inline bool operator<(const SymbianDevice &d1, const SymbianDevice &d2)
|
|---|
| 99 | { return d1.compare(d2) < 0; }
|
|---|
| 100 |
|
|---|
| 101 | /* SymbianDeviceManager: Singleton that maintains a list of Symbian devices.
|
|---|
| 102 | * and emits change signals.
|
|---|
| 103 | * On Windows, the update slot must be connected to a signal
|
|---|
| 104 | * emitted from an event handler listening for WM_DEVICECHANGE. */
|
|---|
| 105 | class SYMBIANUTILS_EXPORT SymbianDeviceManager : public QObject
|
|---|
| 106 | {
|
|---|
| 107 | Q_OBJECT
|
|---|
| 108 | public:
|
|---|
| 109 | typedef QList<SymbianDevice> SymbianDeviceList;
|
|---|
| 110 |
|
|---|
| 111 | static const char *linuxBlueToothDeviceRootC;
|
|---|
| 112 |
|
|---|
| 113 | // Do not use this constructor, it is just public for Q_GLOBAL_STATIC
|
|---|
| 114 | explicit SymbianDeviceManager(QObject *parent = 0);
|
|---|
| 115 | virtual ~SymbianDeviceManager();
|
|---|
| 116 |
|
|---|
| 117 | // Singleton access.
|
|---|
| 118 | static SymbianDeviceManager *instance();
|
|---|
| 119 |
|
|---|
| 120 | SymbianDeviceList devices() const;
|
|---|
| 121 | QString toString() const;
|
|---|
| 122 |
|
|---|
| 123 | QString friendlyNameForPort(const QString &port) const;
|
|---|
| 124 |
|
|---|
| 125 | public slots:
|
|---|
| 126 | void update();
|
|---|
| 127 |
|
|---|
| 128 | signals:
|
|---|
| 129 | void deviceRemoved(const SymbianDevice &d);
|
|---|
| 130 | void deviceAdded(const SymbianDevice &d);
|
|---|
| 131 | void updated();
|
|---|
| 132 |
|
|---|
| 133 | private:
|
|---|
| 134 | void update(bool emitSignals);
|
|---|
| 135 | SymbianDeviceList serialPorts() const;
|
|---|
| 136 | SymbianDeviceList blueToothDevices() const;
|
|---|
| 137 |
|
|---|
| 138 | SymbianDeviceManagerPrivate *d;
|
|---|
| 139 | };
|
|---|
| 140 |
|
|---|
| 141 | QDebug operator<<(QDebug d, const SymbianDeviceManager &);
|
|---|
| 142 |
|
|---|
| 143 | } // namespace SymbianUtils
|
|---|
| 144 |
|
|---|
| 145 | #endif // SYMBIANDEVICEMANAGER_H
|
|---|