1 /* |
1 /* |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
4 * |
9 * Initial Contributors: |
5 * This program is free software: you can redistribute it and/or modify |
10 * Nokia Corporation - initial contribution. |
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
11 * |
8 * |
12 * Contributors: |
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
13 * |
13 * |
14 * Description: |
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
15 * |
17 * |
|
18 * Description: |
|
19 * This file defines the DeviceDelegate, DeviceImpl and DefaultDeviceImpl classes. |
16 */ |
20 */ |
17 |
|
18 #ifndef DEVICEDELEGATE_H |
21 #ifndef DEVICEDELEGATE_H |
19 #define DEVICEDELEGATE_H |
22 #define DEVICEDELEGATE_H |
20 |
23 |
21 #include <QObject> |
24 #include <QObject> |
22 #include <QString> |
25 #include <QString> |
23 #ifdef QT_MOBILITY_BEARER_SYSINFO |
|
24 #include "qsysteminfo.h" |
|
25 #include "qnetworkconfiguration.h" |
|
26 #include "qnetworkconfigmanager.h" |
|
27 |
26 |
28 QTM_USE_NAMESPACE // using QtMobility namespace |
27 #ifdef QT_MOBILITY_SYSINFO |
29 |
28 #define DEVICEIMPL SystemDeviceImpl |
30 #endif // QT_MOBILITY_BEARER_SYSINFO |
29 #else |
|
30 #define DEVICEIMPL DefaultDeviceImpl |
|
31 #endif // QT_MOBILITY_SYSINFO |
31 |
32 |
32 namespace GVA { |
33 namespace GVA { |
33 |
34 |
34 /*! |
35 /*! |
35 Class to provide device information. It uses QtMobility to provide |
36 Class to provide device information. It uses QtMobility QSystemDeviceInfo |
36 information about battery level, network signal strength, and network name. |
37 to provide information about battery level. |
37 */ |
38 */ |
38 class DeviceDelegate : public QObject { |
39 class DeviceImpl : public QObject |
39 Q_OBJECT |
40 { |
40 public: |
41 Q_OBJECT |
41 // default constructor and destructor |
42 public: |
42 DeviceDelegate(); |
43 DeviceImpl() : m_batteryCharging(false) {}; |
43 ~DeviceDelegate(); |
44 virtual ~DeviceImpl() {}; |
44 |
45 |
45 // properties accessible to javascript snippets |
46 virtual int getBatteryLevel() const = 0; |
46 Q_PROPERTY(int batteryLevel READ getBatteryLevel) |
47 virtual bool isBatteryCharging() const = 0; |
47 Q_PROPERTY(int networkSignalStrength READ getNetworkSignalStrength) |
48 |
48 Q_PROPERTY(QString networkName READ getNetworkName) |
|
49 Q_PROPERTY(bool batteryCharging READ isBatteryCharging) |
|
50 |
|
51 |
|
52 // public methods |
|
53 int getBatteryLevel() const; |
|
54 int getNetworkSignalStrength() const; |
|
55 QString getNetworkName() const; |
|
56 bool isBatteryCharging() const; |
|
57 |
|
58 private: |
|
59 // private methods |
|
60 #ifdef QT_MOBILITY_BEARER_SYSINFO |
|
61 void updateSignalStrength(int strength); |
|
62 QSystemNetworkInfo::NetworkMode bearerNameToMode(QString) const; |
|
63 QSystemNetworkInfo::NetworkMode getInternetConfigurationMode(); |
|
64 |
|
65 // private member variables |
|
66 QSystemDeviceInfo *m_deviceInfo; |
|
67 QSystemNetworkInfo *m_networkInfo; |
|
68 QSystemNetworkInfo::NetworkMode m_currentMode; |
|
69 QNetworkConfigurationManager *m_networkConfigManager; |
|
70 #endif |
|
71 QString m_currentConfigIdentifier; |
|
72 bool m_batteryCharging; |
|
73 bool m_updating; // updating network configurations |
|
74 |
|
75 signals: |
49 signals: |
76 // Sent when the battery level or charging state changes. |
50 // Sent when the battery level or charging state changes. |
77 void batteryLevelChanged(int); |
51 void batteryLevelChanged(int); |
78 // Sent when the network signal strength changes. |
|
79 void networkSignalStrengthChanged(int); |
|
80 // Sent when the network name changes. |
|
81 void networkNameChanged(const QString&); |
|
82 |
|
83 private slots: |
|
84 #ifdef QT_MOBILITY_BEARER_SYSINFO |
|
85 // handles signals from network configuration manager |
|
86 void configurationAdded(const QNetworkConfiguration &config); |
|
87 void configurationRemoved(const QNetworkConfiguration &config); |
|
88 void configurationChanged(const QNetworkConfiguration &config); |
|
89 void handleUpdateComplete(); |
|
90 |
52 |
91 // handles signals from system network info |
53 protected: |
92 void handleNetworkSignalStrengthChanged(QSystemNetworkInfo::NetworkMode, int); |
54 bool m_batteryCharging; |
93 void handleNetworkNameChanged(QSystemNetworkInfo::NetworkMode, const QString&); |
|
94 |
|
95 // handles signals from system device info |
|
96 void handlePowerStateChanged(QSystemDeviceInfo::PowerState); |
|
97 #endif |
|
98 }; |
55 }; |
99 |
56 |
100 #endif // DEVICEDELEGATE_H |
57 class DefaultDeviceImpl : public DeviceImpl |
|
58 { |
|
59 Q_OBJECT |
|
60 public: |
|
61 DefaultDeviceImpl() {}; |
|
62 ~DefaultDeviceImpl() {}; |
|
63 |
|
64 virtual int getBatteryLevel() const { return 100; }; // can't get real level, return full |
|
65 virtual bool isBatteryCharging() const { return m_batteryCharging; }; |
|
66 }; |
|
67 |
|
68 class DeviceDelegate : public QObject { |
|
69 Q_OBJECT |
|
70 public: |
|
71 DeviceDelegate(DeviceImpl *deviceImpl); |
|
72 virtual ~DeviceDelegate(); |
|
73 |
|
74 // properties accessible to javascript snippets |
|
75 Q_PROPERTY(int batteryLevel READ getBatteryLevel) |
|
76 Q_PROPERTY(bool batteryCharging READ isBatteryCharging) |
|
77 |
|
78 int getBatteryLevel() const; |
|
79 bool isBatteryCharging() const; |
|
80 |
|
81 signals: |
|
82 // Sent when the battery level or charging state changes. |
|
83 void batteryLevelChanged(int); |
|
84 |
|
85 private: |
|
86 DeviceImpl *m_deviceImpl; |
|
87 }; |
101 |
88 |
102 } // GVA |
89 } // GVA |
|
90 |
|
91 #endif // DEVICEDELEGATE_H |