|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
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 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef DEVICEDELEGATE_H |
|
19 #define DEVICEDELEGATE_H |
|
20 |
|
21 #include <QObject> |
|
22 #include <QString> |
|
23 #ifdef QT_MOBILITY_BEARER_SYSINFO |
|
24 #include "qsysteminfo.h" |
|
25 #include "qnetworkconfiguration.h" |
|
26 #include "qnetworkconfigmanager.h" |
|
27 |
|
28 QTM_USE_NAMESPACE // using QtMobility namespace |
|
29 |
|
30 #endif // QT_MOBILITY_BEARER_SYSINFO |
|
31 |
|
32 namespace GVA { |
|
33 |
|
34 /*! |
|
35 Class to provide device information. It uses QtMobility to provide |
|
36 information about battery level, network signal strength, and network name. |
|
37 */ |
|
38 class DeviceDelegate : public QObject { |
|
39 Q_OBJECT |
|
40 public: |
|
41 // default constructor and destructor |
|
42 DeviceDelegate(); |
|
43 ~DeviceDelegate(); |
|
44 |
|
45 // properties accessible to javascript snippets |
|
46 Q_PROPERTY(int batteryLevel READ getBatteryLevel) |
|
47 Q_PROPERTY(int networkSignalStrength READ getNetworkSignalStrength) |
|
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: |
|
76 // Sent when the battery level or charging state changes. |
|
77 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 |
|
91 // handles signals from system network info |
|
92 void handleNetworkSignalStrengthChanged(QSystemNetworkInfo::NetworkMode, int); |
|
93 void handleNetworkNameChanged(QSystemNetworkInfo::NetworkMode, const QString&); |
|
94 |
|
95 // handles signals from system device info |
|
96 void handlePowerStateChanged(QSystemDeviceInfo::PowerState); |
|
97 #endif |
|
98 }; |
|
99 |
|
100 #endif // DEVICEDELEGATE_H |
|
101 |
|
102 } // GVA |