|
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 |
|
19 #include "hbdevicepowermenuwidegt_p.h" |
|
20 #include "hbdevicepowermenupluginerrors_p.h" |
|
21 #include <HbInstance.h> |
|
22 |
|
23 //resuorces |
|
24 QString POWER_MENU_DOCML(":/xml/powermenu.docml"); |
|
25 QString VOLUME_DECREASE_ICON(":/images/decrement.svg"); |
|
26 QString VOLUME_INCREASE_ICON(":/images/increment.svg"); |
|
27 QString VOLUME_UNMUTE_ICON(":/images/unmuted.svg"); |
|
28 QString VOLUME_MUTE_ICON(":/images/muted.svg"); |
|
29 //For Localization |
|
30 QString LOCALE_PATH("/resource/qt/translations/"); |
|
31 QString TS_FILE("power_menu"); |
|
32 |
|
33 //Widget names |
|
34 QString MAIN_DLG("maindialog"); |
|
35 QString PWR_SILENCE("Silence"); |
|
36 QString PWR_VOLUME("Volume"); |
|
37 QString PWR_VIBARTE("Vibrate"); |
|
38 QString PWR_OFFLINE("Offline"); |
|
39 QString PWR_POWEROFF("PowerOff"); |
|
40 QString PWR_CONTAINER("container_1"); |
|
41 |
|
42 //DO not modify these strings |
|
43 QString KVolumeLevel("VolumeLevel"); |
|
44 QString KSilenceLatchOn("SilenceLatchOn"); //Used to latch silencebutton |
|
45 QString KVibrationEnable("VibrationEnable"); |
|
46 QString KOfflineEnable("OfflineEnable"); |
|
47 QString KCypherOff("CypherOff"); //used to poweroffButtonEnabled/Disabled |
|
48 QString KShutDown("ShutDown"); |
|
49 |
|
50 //Used for Orientation of PowerMenu |
|
51 qreal KVerticalX = 175; |
|
52 //width of PowerMenu |
|
53 qreal KPMWidth = 360; |
|
54 |
|
55 /** |
|
56 * Constructor |
|
57 */ |
|
58 HbDevicePowerMenuWidget::HbDevicePowerMenuWidget(const QVariantMap ¶meters) |
|
59 :mDeviceDialogError(NoError), |
|
60 mVolumeLevel(0), |
|
61 mShowVolume(false), |
|
62 mVibrationChecked(true), |
|
63 mOfflineChecked(true), |
|
64 mSilencelatched(true), |
|
65 mCypherOff(true), |
|
66 mDialogWidget(NULL), |
|
67 mSilenceButton(NULL), |
|
68 mVolumeSlider(NULL), |
|
69 mVibarte(NULL), |
|
70 mOffline(NULL), |
|
71 mPowerOffButton(NULL), |
|
72 mLoader(NULL), |
|
73 mHbTranslator(NULL) |
|
74 { |
|
75 // mMainWindow(NULL), |
|
76 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::Constructor:Begin") ) ); |
|
77 if (preConstructDialog()) |
|
78 { |
|
79 //Translator loaded succesfully then olny construct widgets |
|
80 constructDialog(parameters); |
|
81 } |
|
82 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::Constructor:End") ) ); |
|
83 } |
|
84 |
|
85 /** |
|
86 * Destructor |
|
87 */ |
|
88 HbDevicePowerMenuWidget::~HbDevicePowerMenuWidget() |
|
89 { |
|
90 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::Destructor()") ) ); |
|
91 cleanupMemory(); |
|
92 } |
|
93 |
|
94 /** |
|
95 * Implementation of HbDeviceDialogInterface method |
|
96 * sets parameters of custom widget |
|
97 */ |
|
98 bool HbDevicePowerMenuWidget::setDeviceDialogParameters(const QVariantMap ¶meters) |
|
99 { |
|
100 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::setDeviceDialogParameters:Begin") ) ); |
|
101 if(parameters.contains(KVolumeLevel)) |
|
102 { |
|
103 mVolumeLevel = parameters.value(KVolumeLevel).toInt(); |
|
104 } |
|
105 if(parameters.contains(KSilenceLatchOn)) |
|
106 { |
|
107 mSilencelatched = parameters.value(KSilenceLatchOn).toBool(); |
|
108 //If SilenceMode is Enabled then MasterVolume control is Disabled |
|
109 mShowVolume = mSilencelatched? false:true; |
|
110 } |
|
111 if(parameters.contains(KVibrationEnable)) |
|
112 { |
|
113 mVibrationChecked = parameters.value(KVibrationEnable).toBool(); |
|
114 } |
|
115 if(parameters.contains(KOfflineEnable)) |
|
116 { |
|
117 mOfflineChecked = parameters.value(KOfflineEnable).toBool(); |
|
118 } |
|
119 if(parameters.contains(KCypherOff)) |
|
120 { |
|
121 mCypherOff = parameters.value(KCypherOff).toBool(); |
|
122 } |
|
123 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::setDeviceDialogParameters:End") ) ); |
|
124 return true; |
|
125 } |
|
126 |
|
127 /** |
|
128 * Returns error code |
|
129 */ |
|
130 int HbDevicePowerMenuWidget::deviceDialogError() const |
|
131 { |
|
132 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::deviceDialogError") ) ); |
|
133 return mDeviceDialogError; |
|
134 } |
|
135 |
|
136 /** |
|
137 * Close DeviceDialog |
|
138 */ |
|
139 void HbDevicePowerMenuWidget::closeDeviceDialog(bool byClient) |
|
140 { |
|
141 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::closeDeviceDialog:Begin") ) ); |
|
142 Q_UNUSED(byClient); |
|
143 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::closeDeviceDialog:End") ) ); |
|
144 mDialogWidget->close(); |
|
145 } |
|
146 |
|
147 /** |
|
148 * Implementation of HbDeviceDialogInterface method |
|
149 */ |
|
150 HbPopup* HbDevicePowerMenuWidget::deviceDialogWidget() const |
|
151 { |
|
152 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::deviceDialogWidget") ) ); |
|
153 return mDialogWidget; |
|
154 } |
|
155 |
|
156 /** |
|
157 * Implementation of HbDeviceDialogInterface method |
|
158 * to get signals from action events |
|
159 */ |
|
160 QObject* HbDevicePowerMenuWidget::signalSender() const |
|
161 { |
|
162 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::signalSender") ) ); |
|
163 return const_cast<HbDevicePowerMenuWidget*>(this); |
|
164 } |
|
165 |
|
166 /** |
|
167 * Before loading docml and widgets Translator must be loaded |
|
168 */ |
|
169 bool HbDevicePowerMenuWidget::preConstructDialog() |
|
170 { |
|
171 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::preConstructDialog:Begin") ) ); |
|
172 //Translator |
|
173 mHbTranslator = new HbTranslator(LOCALE_PATH,TS_FILE); |
|
174 if(!mHbTranslator) |
|
175 { |
|
176 //Translator is failed to create |
|
177 mDeviceDialogError = UnknownDeviceDialogError; |
|
178 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::preConstructDialog:MemoryAllocation Failed") ) ); |
|
179 return false; |
|
180 } |
|
181 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::preConstructDialog:End") ) ); |
|
182 return true; |
|
183 } |
|
184 |
|
185 /** |
|
186 * Constrcuts customized widget dialog by loading the UI from docml and |
|
187 * initializes all parameters and attributes. |
|
188 * Throws bad-memory on Un-succesful memory allocations |
|
189 */ |
|
190 void HbDevicePowerMenuWidget::constructDialog(const QVariantMap ¶meters) |
|
191 { |
|
192 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::constructDialog:Begin") ) ); |
|
193 bool dialogLoaded(false); |
|
194 //Docml loader |
|
195 mLoader = new HbDocumentLoader(); |
|
196 if(!mLoader) |
|
197 { |
|
198 //Document Loader failed to create |
|
199 mDeviceDialogError = UnknownDeviceDialogError; |
|
200 cleanupMemory(); |
|
201 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::constructDialog:mLoader::MemoryAllocation Failed") ) ); |
|
202 return; |
|
203 } |
|
204 mLoader->load(POWER_MENU_DOCML, &dialogLoaded); |
|
205 Q_ASSERT_X(dialogLoaded, "HbDevicePowerMenuWidget", "Invalid xml file"); |
|
206 //Widgets |
|
207 if (dialogLoaded) |
|
208 { |
|
209 //Dialog loaded succesfully from docml |
|
210 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::constructDialog:dialogLoaded:Begin") ) ); |
|
211 |
|
212 //Initialize Parameters received |
|
213 setDeviceDialogParameters(parameters); |
|
214 mDialogWidget = qobject_cast <HbDialog *>(mLoader->findWidget(MAIN_DLG)); |
|
215 //Find the handles for all widget items |
|
216 mSilenceButton = qobject_cast <HbPushButton *>(mLoader->findWidget(PWR_SILENCE)); |
|
217 mVolumeSlider = qobject_cast <HbSlider *>(mLoader->findWidget(PWR_VOLUME)); |
|
218 mVibarte = qobject_cast <HbCheckBox *>(mLoader->findWidget(PWR_VIBARTE)); |
|
219 mOffline = qobject_cast <HbCheckBox *>(mLoader->findWidget(PWR_OFFLINE)); |
|
220 mPowerOffButton = qobject_cast <HbPushButton *>(mLoader->findWidget(PWR_POWEROFF)); |
|
221 QGraphicsWidget *widget(NULL); |
|
222 widget = mLoader->findWidget(PWR_CONTAINER); |
|
223 if (!(IsValidHandles()&&(widget))) |
|
224 { |
|
225 //Atleast, One of the Handles are not allocated memory |
|
226 mDeviceDialogError = UnknownDeviceDialogError; |
|
227 cleanupMemory(); |
|
228 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::constructDialog:Widgets::MemoryAllocation Failed") ) ); |
|
229 return; |
|
230 } |
|
231 //Sets Speaker icon |
|
232 setSpeakerIcon(); |
|
233 //Customize slider to VolumeSlider |
|
234 customizeVolumeSlider(); |
|
235 mDialogWidget->setContentWidget(widget); |
|
236 //SetWidget Attributes |
|
237 //1. Volume |
|
238 mVolumeSlider->setSliderPosition(mVolumeLevel); |
|
239 mVolumeSlider->setEnabled(mShowVolume); |
|
240 //This will avoid IPC calls while dragging the Slider |
|
241 mVolumeSlider->setTracking(false); |
|
242 bool ok = connect(mVolumeSlider,SIGNAL(valueChanged(int)) , this , SLOT(handleVolumeChanged(int))); |
|
243 Q_ASSERT_X(ok, "VolumeSlider", "Invalid IncrementDecrement Change"); |
|
244 |
|
245 //2.Silence Mode |
|
246 mSilenceButton->setDown(mSilencelatched); |
|
247 ok = connect(mSilenceButton,SIGNAL(clicked(bool)) , this , SLOT(handleSilenceMode(bool))); |
|
248 Q_ASSERT_X(ok, "SilenceButton", "Invalid Clicked"); |
|
249 |
|
250 //3.Master Vibration |
|
251 mVibarte->setChecked(mVibrationChecked); |
|
252 ok = connect(mVibarte,SIGNAL(stateChanged(int)) , this , SLOT(handleVibrationToggled(int))); |
|
253 Q_ASSERT_X(ok, "Vibrator", "Invalid Vibrator Toggeld"); |
|
254 |
|
255 //4.Offline |
|
256 mOffline->setChecked(mOfflineChecked); |
|
257 ok = connect(mOffline,SIGNAL(stateChanged(int)) , this , SLOT(handleOfflineToggled(int))); |
|
258 Q_ASSERT_X(ok, "Vibrator", "Invalid Offline Toggeld"); |
|
259 |
|
260 //5.Power off |
|
261 mPowerOffButton->setEnabled(mCypherOff); |
|
262 ok = connect(mPowerOffButton,SIGNAL(clicked(bool)) , this , SLOT(handlePowerOff(bool))); |
|
263 Q_ASSERT_X(ok, "PowerOffButton", "Invalid Clicked"); |
|
264 |
|
265 //Dialog dismiss only with Tap outside |
|
266 mDialogWidget->setTimeout(HbPopup::NoTimeout); |
|
267 mDialogWidget->setDismissPolicy(HbPopup::TapOutside); |
|
268 mDialogWidget->setPreferredWidth(KPMWidth); |
|
269 |
|
270 connect(mDialogWidget,SIGNAL(aboutToClose()),this, SLOT(closedialog())); |
|
271 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::constructDialog:dialogLoaded:End") ) ); |
|
272 } |
|
273 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::constructDialog:End") ) ); |
|
274 } |
|
275 |
|
276 /** |
|
277 * Checks whether all Hadles for widgets DialogWidget, |
|
278 * SilenceButton, Vibrate, Offline and Poweroff Button allocated memory. |
|
279 * Returns True, if all Handles allocated memory. |
|
280 * Flase, atleast one of them NOT allocated memory. |
|
281 */ |
|
282 bool HbDevicePowerMenuWidget::IsValidHandles() |
|
283 { |
|
284 if((!mDialogWidget) || (!mSilenceButton) || (!mVolumeSlider)||(!mVibarte) || (!mOffline) || (!mPowerOffButton)) |
|
285 { |
|
286 return false; |
|
287 } |
|
288 else{ |
|
289 //All handles are allocated memory |
|
290 return true; |
|
291 } |
|
292 } |
|
293 |
|
294 /** |
|
295 * Sets Mute/Unmute icon for Volume slider |
|
296 * Mute/Unmute icon to display the current status of Silence Mode. |
|
297 * Mute icon dispalyed when Device in Silence mode. |
|
298 * Unmute icon dispalyed when Device Non-Silence mode. |
|
299 */ |
|
300 void HbDevicePowerMenuWidget::setSpeakerIcon() |
|
301 { |
|
302 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::setSpeakerIcon:Begin") ) ); |
|
303 QString speakerIcon= ( mSilencelatched )? VOLUME_MUTE_ICON : VOLUME_UNMUTE_ICON ; |
|
304 mVolumeSlider->setElementIcon(HbSlider:: IconElement,HbIcon(speakerIcon)); |
|
305 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::setSpeakerIcon:End") ) ); |
|
306 } |
|
307 |
|
308 |
|
309 /** |
|
310 * Customizes the slider to Vloume Slider |
|
311 */ |
|
312 void HbDevicePowerMenuWidget::customizeVolumeSlider() |
|
313 { |
|
314 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::customizeVolumeSlider:Begin") ) ); |
|
315 //Construct Volume Slider from the HbSlider |
|
316 mVolumeSlider->setSliderElements(QList<QVariant>() |
|
317 << HbSlider::DecreaseElement |
|
318 << HbSlider::TrackElement |
|
319 << HbSlider::IncreaseElement |
|
320 << HbSlider::IconElement ); |
|
321 |
|
322 // To set DecreaseIcon and IncreseIcon |
|
323 mVolumeSlider->setElementIcon(HbSlider::DecreaseElement, HbIcon(VOLUME_DECREASE_ICON)); |
|
324 mVolumeSlider->setElementIcon(HbSlider:: IncreaseElement, HbIcon(VOLUME_INCREASE_ICON)); |
|
325 //set Range of volume |
|
326 mVolumeSlider->setRange(1,10); |
|
327 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::customizeVolumeSlider:End") ) ); |
|
328 } |
|
329 |
|
330 /** |
|
331 * Slot |
|
332 * Widget is about to Close. |
|
333 */ |
|
334 void HbDevicePowerMenuWidget::closedialog() |
|
335 { |
|
336 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::closedialog:Begin") ) ); |
|
337 emit deviceDialogClosed(); |
|
338 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::closedialog:Begin") ) ); |
|
339 } |
|
340 |
|
341 /** |
|
342 * Slot |
|
343 */ |
|
344 void HbDevicePowerMenuWidget::handleVolumeChanged(int aVolume) |
|
345 { |
|
346 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::handleVolumeChanged:Begin") ) ); |
|
347 mVolumeLevel = aVolume; |
|
348 //inform the client may be through data changed etc. |
|
349 QVariantMap mDataToSend; |
|
350 QVariant volume(mVolumeLevel); |
|
351 mDataToSend.insert(KVolumeLevel, volume); |
|
352 emit deviceDialogData(mDataToSend); |
|
353 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::handleVolumeChanged:Begin") ) ); |
|
354 } |
|
355 |
|
356 /** |
|
357 * Slot |
|
358 * Switch between the states to latch down and latch up. |
|
359 * In case of Silence mode, The Silence button id latched down and Disables Volume control. |
|
360 * In case of Non-Silence mode, The Silence button id latched Up and enables Volume control. |
|
361 */ |
|
362 void HbDevicePowerMenuWidget::handleSilenceMode(bool aState) |
|
363 { |
|
364 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::handleSilenceMode:Begin") ) ); |
|
365 Q_UNUSED(aState); |
|
366 mShowVolume = !(mShowVolume); |
|
367 mSilencelatched = !(mSilencelatched); |
|
368 mSilenceButton->setDown(mSilencelatched); |
|
369 mVolumeSlider->setEnabled(mShowVolume); |
|
370 setSpeakerIcon(); |
|
371 //inform the client may be through data changed etc. |
|
372 QVariantMap mDataToSend; |
|
373 QVariant silence(mSilencelatched); |
|
374 mDataToSend.insert(KSilenceLatchOn, silence); |
|
375 emit deviceDialogData(mDataToSend); |
|
376 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::handleSilenceMode:End") ) ); |
|
377 } |
|
378 |
|
379 /** |
|
380 * Slot |
|
381 */ |
|
382 void HbDevicePowerMenuWidget::handlePowerOff(bool aState) |
|
383 { |
|
384 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::handlePowerOff:Begin") ) ); |
|
385 Q_UNUSED(aState); |
|
386 QVariantMap mDataToSend; |
|
387 QVariant shutdown(true); |
|
388 mDataToSend.insert(KShutDown, shutdown); |
|
389 emit deviceDialogData(mDataToSend); |
|
390 emit deviceDialogClosed(); |
|
391 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::handlePowerOff:End") ) ); |
|
392 } |
|
393 |
|
394 /** |
|
395 * Slot |
|
396 */ |
|
397 void HbDevicePowerMenuWidget::handleOfflineToggled(int aOfflineToggel) |
|
398 { |
|
399 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::handleOfflineToggled:Begin") ) ); |
|
400 mOfflineChecked = aOfflineToggel; |
|
401 QVariantMap mDataToSend; |
|
402 QVariant offline(mOfflineChecked); |
|
403 mDataToSend.insert(KOfflineEnable, offline); |
|
404 emit deviceDialogData(mDataToSend); |
|
405 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::handleOfflineToggled:End") ) ); |
|
406 } |
|
407 |
|
408 /** |
|
409 * Slot |
|
410 */ |
|
411 void HbDevicePowerMenuWidget::handleVibrationToggled(int aVibrationToggel) |
|
412 { |
|
413 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::handleVibrationToggled:Begin") ) ); |
|
414 mVibrationChecked = aVibrationToggel; |
|
415 QVariantMap mDataToSend; |
|
416 QVariant vibration(mVibrationChecked); |
|
417 mDataToSend.insert(KVibrationEnable, vibration); |
|
418 emit deviceDialogData(mDataToSend); |
|
419 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::handleVibrationToggled:End") ) ); |
|
420 } |
|
421 |
|
422 /** |
|
423 * Cleans up memory allocations |
|
424 */ |
|
425 void HbDevicePowerMenuWidget::cleanupMemory() |
|
426 { |
|
427 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::cleanupMemory:Begin") ) ); |
|
428 if(mLoader) |
|
429 { |
|
430 delete mLoader; |
|
431 } |
|
432 if(mHbTranslator) |
|
433 { |
|
434 delete mHbTranslator; |
|
435 } |
|
436 TRACES( RDebug::Print( _L("HbDevicePowerMenuWidget::cleanupMemory:End") ) ); |
|
437 } |
|
438 |