1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
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. |
|
8 * |
|
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 * |
|
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/". |
|
17 * |
|
18 * Description: |
|
19 * |
|
20 */ |
|
21 |
|
22 #include "settingsmanagerexwindow.h" |
|
23 |
|
24 #include <ProfileEngineSDKCRKeys.h> |
|
25 #include <HWRMPowerStateSDKPSKeys.h> |
|
26 #include <QMenuBar> |
|
27 #include <QTimer> |
|
28 |
|
29 #include "xqsettingsmanager.h" |
|
30 #include "xqsettingskey.h" |
|
31 #include "xqpublishandsubscribeutils.h" |
|
32 |
|
33 const quint32 KExampleKey = 0x00000001; |
|
34 const qint32 KExampleProperty = {0xE2F629E4}; //Same as SID |
|
35 |
|
36 SettingsManagerExWindow::SettingsManagerExWindow(QWidget* parent) : QMainWindow(parent) |
|
37 { |
|
38 setupUi(this); |
|
39 createMenus(); |
|
40 |
|
41 m_settingsManager = new XQSettingsManager(this); |
|
42 |
|
43 XQSettingsKey profileKey (XQSettingsKey::TargetCentralRepository, KCRUidProfileEngine.iUid, KProEngActiveProfile); |
|
44 m_settingsManager->startMonitoring(profileKey); |
|
45 currentProfile(m_settingsManager->readItemValue(profileKey)); |
|
46 |
|
47 XQSettingsKey chargerKey(XQSettingsKey::TargetPublishAndSubscribe, KPSUidHWRMPowerState.iUid, KHWRMChargingStatus); |
|
48 m_settingsManager->startMonitoring(chargerKey); |
|
49 currentChargerStatus(m_settingsManager->readItemValue(chargerKey)); |
|
50 |
|
51 connect(m_settingsManager, SIGNAL(itemDeleted(XQSettingsKey)), this, SLOT(itemDeleted(XQSettingsKey))); |
|
52 connect(m_settingsManager, SIGNAL(valueChanged(XQSettingsKey, QVariant)), this, SLOT(handleChanges(XQSettingsKey, QVariant))); |
|
53 } |
|
54 |
|
55 void SettingsManagerExWindow::createMenus() |
|
56 { |
|
57 m_createAction = new QAction(tr("Create item"), this); |
|
58 m_deleteAction = new QAction(tr("Delete item"), this); |
|
59 m_deleteAction->setDisabled(true); |
|
60 QAction* exitAct = new QAction(tr("Exit"), this); |
|
61 menuBar()->addAction(m_createAction); |
|
62 menuBar()->addAction(m_deleteAction); |
|
63 menuBar()->addAction(exitAct); |
|
64 |
|
65 connect(m_createAction, SIGNAL(triggered()), this, SLOT(createPropertyItem())); |
|
66 connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(deletePropertyItem())); |
|
67 connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); |
|
68 } |
|
69 |
|
70 void SettingsManagerExWindow::handleChanges(const XQSettingsKey& key, const QVariant& value) |
|
71 |
|
72 { |
|
73 if (key.uid() == KCRUidProfileEngine.iUid && key.key() == KProEngActiveProfile) |
|
74 { |
|
75 currentProfile(value); |
|
76 } |
|
77 if (key.uid() == KPSUidHWRMPowerState.iUid && key.key() == KHWRMChargingStatus) |
|
78 { |
|
79 currentChargerStatus(value); |
|
80 } |
|
81 } |
|
82 |
|
83 void SettingsManagerExWindow::currentProfile(QVariant value) |
|
84 { |
|
85 switch (value.toInt()) |
|
86 { |
|
87 case 0: |
|
88 { |
|
89 profileLabel->setText("Profile: General"); |
|
90 break; |
|
91 } |
|
92 case 1: |
|
93 { |
|
94 profileLabel->setText("Profile: Silent"); |
|
95 break; |
|
96 } |
|
97 case 2: |
|
98 { |
|
99 profileLabel->setText("Profile: Meeting"); |
|
100 break; |
|
101 } |
|
102 case 3: |
|
103 { |
|
104 profileLabel->setText("Profile: Outdoor"); |
|
105 break; |
|
106 } |
|
107 case 4 : |
|
108 { |
|
109 profileLabel->setText("Profile: Pager"); |
|
110 break; |
|
111 } |
|
112 case 5: |
|
113 { |
|
114 profileLabel->setText("Profile: Off-line"); |
|
115 break; |
|
116 } |
|
117 case 6: |
|
118 { |
|
119 profileLabel->setText("Profile:: Drive"); |
|
120 break; |
|
121 } |
|
122 default: |
|
123 { |
|
124 profileLabel->setText("Profile: User defined"); |
|
125 } |
|
126 } |
|
127 } |
|
128 |
|
129 void SettingsManagerExWindow::currentChargerStatus(QVariant value) |
|
130 { |
|
131 switch (value.toInt()) |
|
132 { |
|
133 case EChargingStatusNotConnected: |
|
134 { |
|
135 chargerLabel->setText("Charger: Is not connected"); |
|
136 break; |
|
137 } |
|
138 case EChargingStatusCharging: |
|
139 { |
|
140 chargerLabel->setText("Charger: Charging"); |
|
141 break; |
|
142 } |
|
143 case EChargingStatusNotCharging: |
|
144 { |
|
145 chargerLabel->setText("Charger: Not charging"); |
|
146 break; |
|
147 } |
|
148 case EChargingStatusAlmostComplete: |
|
149 { |
|
150 chargerLabel->setText("Charger: Almost complete"); |
|
151 break; |
|
152 } |
|
153 case EChargingStatusChargingComplete: |
|
154 { |
|
155 chargerLabel->setText("Charger: Battery full"); |
|
156 break; |
|
157 } |
|
158 case EChargingStatusChargingContinued : |
|
159 { |
|
160 chargerLabel->setText("Charger: Continued after brief interruption"); |
|
161 break; |
|
162 } |
|
163 default: |
|
164 { |
|
165 chargerLabel->setText("Charger: Error"); |
|
166 } |
|
167 } |
|
168 } |
|
169 |
|
170 void SettingsManagerExWindow::deletePropertyItem() |
|
171 { |
|
172 XQPublishAndSubscribeUtils utils(*m_settingsManager); |
|
173 |
|
174 XQPublishAndSubscribeSettingsKey testKey(KExampleProperty, KExampleKey); |
|
175 utils.deleteProperty(testKey); |
|
176 } |
|
177 |
|
178 void SettingsManagerExWindow::itemDeleted(const XQSettingsKey& key) |
|
179 { |
|
180 if (key.uid() == KExampleProperty && key.key() == KExampleKey) |
|
181 { |
|
182 testLabel->setText("Property item deleted!"); |
|
183 } |
|
184 m_deleteAction->setDisabled(true); |
|
185 m_createAction->setEnabled(true); |
|
186 } |
|
187 |
|
188 void SettingsManagerExWindow::createPropertyItem() |
|
189 { |
|
190 XQPublishAndSubscribeUtils utils(*m_settingsManager); |
|
191 |
|
192 XQPublishAndSubscribeSettingsKey testKey(KExampleProperty, KExampleKey); |
|
193 utils.defineProperty(testKey, XQSettingsManager::TypeByteArray); |
|
194 |
|
195 m_settingsManager->writeItemValue(testKey, QByteArray("Property item created!")); |
|
196 |
|
197 m_settingsManager->startMonitoring(testKey); |
|
198 testLabel->setText(m_settingsManager->readItemValue(testKey).toString()); |
|
199 m_createAction->setDisabled(true); |
|
200 m_deleteAction->setEnabled(true); |
|
201 } |
|