|
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 |
|
33 /*! |
|
34 Class to provide device information. It uses QtMobility to provide |
|
35 information about battery level, network signal strength, and network name. |
|
36 */ |
|
37 class DeviceDelegate : public QObject { |
|
38 Q_OBJECT |
|
39 public: |
|
40 // default constructor and destructor |
|
41 DeviceDelegate(); |
|
42 ~DeviceDelegate(); |
|
43 |
|
44 // properties accessible to javascript snippets |
|
45 Q_PROPERTY(int batteryLevel READ getBatteryLevel) |
|
46 Q_PROPERTY(int networkSignalStrength READ getNetworkSignalStrength) |
|
47 Q_PROPERTY(QString networkName READ getNetworkName) |
|
48 Q_PROPERTY(bool batteryCharging READ isBatteryCharging) |
|
49 |
|
50 |
|
51 // public methods |
|
52 int getBatteryLevel() const; |
|
53 int getNetworkSignalStrength() const; |
|
54 QString getNetworkName() const; |
|
55 bool isBatteryCharging() const; |
|
56 |
|
57 private: |
|
58 // private methods |
|
59 #ifdef QT_MOBILITY_BEARER_SYSINFO |
|
60 void updateSignalStrength(int strength); |
|
61 QSystemNetworkInfo::NetworkMode bearerNameToMode(QString) const; |
|
62 QSystemNetworkInfo::NetworkMode getInternetConfigurationMode(); |
|
63 |
|
64 // private member variables |
|
65 QSystemDeviceInfo *m_deviceInfo; |
|
66 QSystemNetworkInfo *m_networkInfo; |
|
67 QSystemNetworkInfo::NetworkMode m_currentMode; |
|
68 QNetworkConfigurationManager *m_networkConfigManager; |
|
69 #endif |
|
70 QString m_currentConfigIdentifier; |
|
71 bool m_batteryCharging; |
|
72 bool m_updating; // updating network configurations |
|
73 |
|
74 signals: |
|
75 // Sent when the battery level or charging state changes. |
|
76 void batteryLevelChanged(int); |
|
77 // Sent when the network signal strength changes. |
|
78 void networkSignalStrengthChanged(int); |
|
79 // Sent when the network name changes. |
|
80 void networkNameChanged(const QString&); |
|
81 |
|
82 private slots: |
|
83 #ifdef QT_MOBILITY_BEARER_SYSINFO |
|
84 // handles signals from network configuration manager |
|
85 void configurationAdded(const QNetworkConfiguration &config); |
|
86 void configurationRemoved(const QNetworkConfiguration &config); |
|
87 void configurationChanged(const QNetworkConfiguration &config); |
|
88 void handleUpdateComplete(); |
|
89 |
|
90 // handles signals from system network info |
|
91 void handleNetworkSignalStrengthChanged(QSystemNetworkInfo::NetworkMode, int); |
|
92 void handleNetworkNameChanged(QSystemNetworkInfo::NetworkMode, const QString&); |
|
93 |
|
94 // handles signals from system device info |
|
95 void handlePowerStateChanged(QSystemDeviceInfo::PowerState); |
|
96 #endif |
|
97 }; |
|
98 |
|
99 #endif // DEVICEDELEGATE_H |