|
1 /* |
|
2 * Copyright (c) 2009 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 #include <QDebug> |
|
18 #include <QTimer> |
|
19 #include <hbmainwindow.h> |
|
20 #include <coemain.h> |
|
21 #include <avkondomainpskeys.h> // keyguard |
|
22 #include <hwrmpowerstatesdkpskeys.h> // battery |
|
23 #include <QGraphicsSceneEvent> |
|
24 |
|
25 |
|
26 #include "cxuiviewmanager.h" |
|
27 #include "cxuivideoprecaptureview.h" |
|
28 #include "cxuivideoprecaptureview2.h" |
|
29 #include "cxuistillprecaptureview.h" |
|
30 #include "cxuistillprecaptureview2.h" |
|
31 #include "cxuipostcaptureview.h" |
|
32 #include "cxuicapturekeyhandler.h" |
|
33 #include "cxeengine.h" |
|
34 #include "cxecameradevicecontrol.h" |
|
35 #include "cxefeaturemanager.h" // mEngine->featureManager() |
|
36 #include "cxeviewfindercontrol.h" |
|
37 #include "cxenamespace.h" |
|
38 #include "cxuienums.h" |
|
39 #include "cxutils.h" |
|
40 #include "xqsettingsmanager.h" // Settings Manager API |
|
41 #include "cxuidocumentloader.h" |
|
42 #include "cxuistandby.h" |
|
43 #include "cxuierrormanager.h" |
|
44 #include "OstTraceDefinitions.h" |
|
45 #ifdef OST_TRACE_COMPILER_IN_USE |
|
46 #include "cxuiviewmanagerTraces.h" |
|
47 #endif |
|
48 #include "cxuiserviceprovider.h" |
|
49 |
|
50 |
|
51 |
|
52 using namespace Cxe; |
|
53 using namespace CxUiLayout; |
|
54 |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // CxuiViewManager::CxuiViewManager |
|
58 // |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CxuiViewManager::CxuiViewManager(HbMainWindow &mainWindow, CxeEngine &engine, CxuiCaptureKeyHandler &keyHandler) : |
|
62 mMainWindow(mainWindow), |
|
63 mStillPrecaptureView(NULL), |
|
64 mVideoPrecaptureView(NULL), |
|
65 mPostcaptureView(NULL), |
|
66 mStillPrecaptureView2(NULL), |
|
67 mVideoPrecaptureView2(NULL), |
|
68 mEngine(engine), |
|
69 mKeyHandler(keyHandler), |
|
70 mSettingsManager(NULL), |
|
71 mFocused(true), |
|
72 mCameraDocumentLoader(NULL) |
|
73 { |
|
74 CX_DEBUG_ENTER_FUNCTION(); |
|
75 |
|
76 mMainWindow.installEventFilter(this); // in order to filter capture and AF keys |
|
77 |
|
78 OstTrace0( camerax_performance, CXUIVIEWMANAGER_CXUIVIEWMANAGER, "msg: e_CX_VIEWMANAGER_CREATE_DOCLOADER 1" ); |
|
79 mCameraDocumentLoader = new CxuiDocumentLoader; |
|
80 OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_CXUIVIEWMANAGER, "msg: e_CX_VIEWMANAGER_CREATE_DOCLOADER 0" ); |
|
81 |
|
82 // standby functionality and necessary signal connections |
|
83 mStandbyHandler = new CxuiStandby(keyHandler, mCameraDocumentLoader, &engine); |
|
84 |
|
85 connect(mStandbyHandler, SIGNAL(aboutToEnterStandby()),this, SLOT(aboutToLooseFocus())); |
|
86 connect(mStandbyHandler, SIGNAL(aboutToExitStandby()),this, SLOT(aboutToGainFocus())); |
|
87 |
|
88 // error manager, handling errors and notifying users based on their severity |
|
89 mErrorManager = new CxuiErrorManager(keyHandler, mCameraDocumentLoader); |
|
90 |
|
91 // connecting necessary signals from error manager to release and init camera. |
|
92 connect(mErrorManager, SIGNAL(aboutToRecoverError()), this, SLOT(aboutToLooseFocus())); |
|
93 connect(mErrorManager, SIGNAL(errorRecovered()), this, SLOT(aboutToGainFocus())); |
|
94 |
|
95 if (!CxuiServiceProvider::isCameraEmbedded()) { |
|
96 // for embedded mode: don't create view yet, create |
|
97 // when engine inits to correct mode |
|
98 #ifdef FORCE_SECONDARY_CAMERA |
|
99 // 2nd camera hack: always use 1st camera view |
|
100 if (mEngine.mode() == Cxe::VideoMode) { |
|
101 createVideoPrecaptureView(); |
|
102 |
|
103 mMainWindow.blockSignals(true); |
|
104 mMainWindow.setCurrentView(mVideoPrecaptureView, false); |
|
105 mMainWindow.blockSignals(false); |
|
106 } else { |
|
107 createStillPrecaptureView(); |
|
108 |
|
109 mMainWindow.blockSignals(true); |
|
110 mMainWindow.setCurrentView(mStillPrecaptureView, false); |
|
111 mMainWindow.blockSignals(false); |
|
112 } |
|
113 |
|
114 #else |
|
115 if (mEngine.cameraDeviceControl().cameraIndex() == Cxe::PrimaryCameraIndex) { |
|
116 if (mEngine.mode() == Cxe::VideoMode) { |
|
117 createVideoPrecaptureView(); |
|
118 mMainWindow.blockSignals(true); |
|
119 mMainWindow.setCurrentView(mVideoPrecaptureView, false); |
|
120 mMainWindow.blockSignals(false); |
|
121 } else { |
|
122 createStillPrecaptureView(); |
|
123 mMainWindow.blockSignals(true); |
|
124 mMainWindow.setCurrentView(mStillPrecaptureView, false); |
|
125 mMainWindow.blockSignals(false); |
|
126 } |
|
127 } else { |
|
128 if (mEngine.mode() == Cxe::VideoMode) { |
|
129 createVideoPrecaptureView2(); |
|
130 mMainWindow.blockSignals(true); |
|
131 mMainWindow.setCurrentView(mVideoPrecaptureView2, false); |
|
132 mMainWindow.blockSignals(false); |
|
133 } else { |
|
134 createStillPrecaptureView2(); |
|
135 mMainWindow.blockSignals(true); |
|
136 mMainWindow.setCurrentView(mStillPrecaptureView2, false); |
|
137 mMainWindow.blockSignals(false); |
|
138 } |
|
139 } |
|
140 #endif |
|
141 connectPreCaptureSignals(); |
|
142 } |
|
143 |
|
144 startEventMonitors(); |
|
145 |
|
146 //connecting initmode signals |
|
147 connect(&mEngine.cameraDeviceControl(), SIGNAL(initModeComplete(CxeError::Id)), |
|
148 this, SLOT(createPostcaptureView())); |
|
149 connect(&mEngine.cameraDeviceControl(), SIGNAL(initModeComplete(CxeError::Id)), |
|
150 mErrorManager, SLOT(analyze(CxeError::Id))); |
|
151 |
|
152 if (CxuiServiceProvider::isCameraEmbedded()) { |
|
153 // connect signals to set up the view after image/video prepare |
|
154 connect(&mEngine.stillCaptureControl(), SIGNAL(imagePrepareComplete(CxeError::Id)), |
|
155 this, SLOT(changeToPrecaptureView())); |
|
156 connect(&mEngine.videoCaptureControl(), SIGNAL(videoPrepareComplete(CxeError::Id)), |
|
157 this, SLOT(changeToPrecaptureView())); |
|
158 |
|
159 // start standby timer now because view will not be ready when viewfinder is started |
|
160 mStandbyHandler->startTimer(); |
|
161 } |
|
162 |
|
163 CX_DEBUG_EXIT_FUNCTION(); |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // CxuiViewManager::~CxuiViewManager |
|
168 // |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 CxuiViewManager::~CxuiViewManager() |
|
172 { |
|
173 CX_DEBUG_ENTER_FUNCTION(); |
|
174 |
|
175 delete mCameraDocumentLoader; |
|
176 delete mSettingsManager; |
|
177 |
|
178 CX_DEBUG_EXIT_FUNCTION(); |
|
179 } |
|
180 |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // CxuiViewManager::prepareWindow |
|
184 // |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 void CxuiViewManager::prepareWindow() |
|
188 { |
|
189 getPrecaptureView(mEngine.mode(), mEngine.cameraDeviceControl().cameraIndex())->prepareWindow(); |
|
190 } |
|
191 |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // CxuiViewManager::createStillPrecaptureView |
|
195 // |
|
196 // --------------------------------------------------------------------------- |
|
197 // |
|
198 void CxuiViewManager::createStillPrecaptureView() |
|
199 { |
|
200 CX_DEBUG_ENTER_FUNCTION(); |
|
201 OstTrace0( camerax_performance, CXUIVIEWMANAGER_CREATESTILLPRECAPTUREVIEW, "msg: e_CX_CREATE_STILLPRECAPTUREVIEW 1" ); |
|
202 bool ok = false; |
|
203 CX_DEBUG_ASSERT(mCameraDocumentLoader); |
|
204 |
|
205 OstTrace0( camerax_performance, DUP2_CXUIVIEWMANAGER_ADDPRECAPTUREVIEWS, "msg: e_CX_DOCLOADER_LOAD 1" ); |
|
206 |
|
207 // Use document loader to create widgets and layouts |
|
208 // (non-sectioned parts are parsed and loaded) |
|
209 mCameraDocumentLoader->load(STILL_1ST_XML, &ok); |
|
210 Q_ASSERT_X(ok, "createStillPrecaptureView", "error in xml file parsing"); |
|
211 |
|
212 QGraphicsWidget *widget = NULL; |
|
213 |
|
214 OstTrace0( camerax_performance, DUP2_CXUIVIEWMANAGER_CREATESTILLPRECAPTUREVIEW, "msg: e_CX_DOCLOADER_LOAD 0" ); |
|
215 |
|
216 |
|
217 OstTrace0( camerax_performance, DUP4_CXUIVIEWMANAGER_ADDPRECAPTUREVIEWS, "msg: e_CX_DOCLOADER_FINDWIDGET 1" ); |
|
218 // ask for the still precapture view widget pointer |
|
219 widget = mCameraDocumentLoader->findWidget(STILL_PRE_CAPTURE_VIEW); |
|
220 mStillPrecaptureView = qobject_cast<CxuiStillPrecaptureView *> (widget); |
|
221 CX_DEBUG_ASSERT(mStillPrecaptureView); |
|
222 OstTrace0( camerax_performance, DUP5_CXUIVIEWMANAGER_ADDPRECAPTUREVIEWS, "msg: e_CX_DOCLOADER_FINDWIDGET 0" ); |
|
223 |
|
224 // call for needed consturction methods |
|
225 mStillPrecaptureView->construct(&mMainWindow, &mEngine, mCameraDocumentLoader, &mKeyHandler); |
|
226 // .. and add to main window (which also takes ownership) |
|
227 mMainWindow.addView(widget); |
|
228 |
|
229 OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_CREATESTILLPRECAPTUREVIEW, "msg: e_CX_CREATE_STILLPRECAPTUREVIEW 0" ); |
|
230 |
|
231 CX_DEBUG_EXIT_FUNCTION(); |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------------------------- |
|
235 // CxuiViewManager::createStillPrecaptureView2 |
|
236 // |
|
237 // --------------------------------------------------------------------------- |
|
238 // |
|
239 void CxuiViewManager::createStillPrecaptureView2() |
|
240 { |
|
241 CX_DEBUG_ENTER_FUNCTION(); |
|
242 |
|
243 bool ok = false; |
|
244 CX_DEBUG_ASSERT(mCameraDocumentLoader); |
|
245 |
|
246 // Use document loader to create widgets and layouts |
|
247 // (non-sectioned parts are parsed and loaded) |
|
248 mCameraDocumentLoader->load(STILL_2ND_XML, &ok); |
|
249 Q_ASSERT_X(ok, "createStillPrecaptureView2", "error in xml file parsing"); |
|
250 |
|
251 QGraphicsWidget *widget = NULL; |
|
252 |
|
253 // ask for the still precapture view widget pointer |
|
254 widget = mCameraDocumentLoader->findWidget(STILL_PRE_CAPTURE_VIEW2); |
|
255 mStillPrecaptureView2 = qobject_cast<CxuiStillPrecaptureView2 *> (widget); |
|
256 CX_DEBUG_ASSERT(mStillPrecaptureView2); |
|
257 |
|
258 // call for needed consturction methods |
|
259 mStillPrecaptureView2->construct(&mMainWindow, &mEngine, mCameraDocumentLoader, &mKeyHandler); |
|
260 // .. and add to main window (which also takes ownership) |
|
261 mMainWindow.addView(widget); |
|
262 |
|
263 CX_DEBUG_EXIT_FUNCTION(); |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // CxuiViewManager::createVideoPrecaptureView |
|
268 // |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 void CxuiViewManager::createVideoPrecaptureView() |
|
272 { |
|
273 CX_DEBUG_ENTER_FUNCTION(); |
|
274 OstTrace0( camerax_performance, CXUIVIEWMANAGER_CREATEVIDEOPRECAPTUREVIEW, "msg: e_CX_CREATE_VIDEOPRECAPTUREVIEW 1" ); |
|
275 |
|
276 CX_DEBUG_ASSERT(mCameraDocumentLoader); |
|
277 |
|
278 bool ok = false; |
|
279 // load and create the default widgets in video xml |
|
280 mCameraDocumentLoader->load(VIDEO_1ST_XML, &ok); |
|
281 CX_DEBUG_ASSERT(ok); |
|
282 |
|
283 // get pointer to videoprecaptureview and do some initialisation |
|
284 QGraphicsWidget *widget = NULL; |
|
285 widget = mCameraDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_VIEW); |
|
286 mVideoPrecaptureView = qobject_cast<CxuiVideoPrecaptureView *> (widget); |
|
287 CX_DEBUG_ASSERT(mVideoPrecaptureView); |
|
288 mVideoPrecaptureView->construct(&mMainWindow, &mEngine, mCameraDocumentLoader, &mKeyHandler); |
|
289 |
|
290 // add view to main window |
|
291 mMainWindow.addView(mVideoPrecaptureView); |
|
292 OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_CREATEVIDEOPRECAPTUREVIEW, "msg: e_CX_CREATE_VIDEOPRECAPTUREVIEW 0" ); |
|
293 |
|
294 CX_DEBUG_EXIT_FUNCTION(); |
|
295 } |
|
296 |
|
297 // --------------------------------------------------------------------------- |
|
298 // CxuiViewManager::createVideoPrecaptureView2 |
|
299 // |
|
300 // --------------------------------------------------------------------------- |
|
301 // |
|
302 void CxuiViewManager::createVideoPrecaptureView2() |
|
303 { |
|
304 CX_DEBUG_ENTER_FUNCTION(); |
|
305 CX_DEBUG_ASSERT(mCameraDocumentLoader); |
|
306 |
|
307 bool ok = false; |
|
308 // load and create the default widgets in video xml |
|
309 mCameraDocumentLoader->load(VIDEO_2ND_XML, &ok); |
|
310 CX_DEBUG_ASSERT(ok); |
|
311 |
|
312 // get pointer to videoprecaptureview and do some initialisation |
|
313 QGraphicsWidget *widget = NULL; |
|
314 widget = mCameraDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_VIEW2); |
|
315 mVideoPrecaptureView2 = qobject_cast<CxuiVideoPrecaptureView2 *> (widget); |
|
316 CX_DEBUG_ASSERT(mVideoPrecaptureView2); |
|
317 mVideoPrecaptureView2->construct(&mMainWindow, &mEngine, mCameraDocumentLoader); |
|
318 |
|
319 // add view to main window |
|
320 mMainWindow.addView(mVideoPrecaptureView2); |
|
321 |
|
322 CX_DEBUG_EXIT_FUNCTION(); |
|
323 } |
|
324 |
|
325 // --------------------------------------------------------------------------- |
|
326 // CxuiViewManager::createStillPostcaptureView |
|
327 // |
|
328 // --------------------------------------------------------------------------- |
|
329 // |
|
330 void CxuiViewManager::createPostcaptureView() |
|
331 { |
|
332 CX_DEBUG_ENTER_FUNCTION(); |
|
333 CX_DEBUG_ASSERT(mCameraDocumentLoader); |
|
334 OstTrace0( camerax_performance, CXUIVIEWMANAGER_CREATESTILLPOSTCAPTUREVIEW, "msg: e_CX_CREATE_STILLPOSTCAPTUREVIEW 1" ); |
|
335 |
|
336 if (!mPostcaptureView) { |
|
337 bool ok = false; |
|
338 mCameraDocumentLoader->load(POSTCAPTURE_XML, &ok); |
|
339 CX_DEBUG_ASSERT(ok); |
|
340 |
|
341 // get pointer to videoprecaptureview and do some initialisation |
|
342 QGraphicsWidget *widget = NULL; |
|
343 widget = mCameraDocumentLoader->findWidget(POSTCAPTURE_VIEW); |
|
344 mPostcaptureView = qobject_cast<CxuiPostcaptureView *> (widget); |
|
345 CX_DEBUG_ASSERT(mPostcaptureView); |
|
346 mPostcaptureView->construct(&mMainWindow, &mEngine, mCameraDocumentLoader); |
|
347 |
|
348 mMainWindow.addView(mPostcaptureView); |
|
349 connect(mPostcaptureView, SIGNAL(changeToPrecaptureView()), this, SLOT(changeToPrecaptureView())); |
|
350 |
|
351 } |
|
352 |
|
353 OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_CREATESTILLPOSTCAPTUREVIEW, "msg: e_CX_CREATE_STILLPOSTCAPTUREVIEW 0" ); |
|
354 CX_DEBUG_EXIT_FUNCTION(); |
|
355 } |
|
356 |
|
357 // --------------------------------------------------------------------------- |
|
358 // CxuiViewManager::getPrecaptureView |
|
359 // |
|
360 // --------------------------------------------------------------------------- |
|
361 // |
|
362 CxuiPrecaptureView* |
|
363 CxuiViewManager::getPrecaptureView(Cxe::CameraMode mode, Cxe::CameraIndex camera) |
|
364 { |
|
365 CX_DEBUG_ENTER_FUNCTION(); |
|
366 CX_DEBUG(("CxuiViewManager::getPrecaptureView() mode=%d, camera index=%d", mode, camera)); |
|
367 |
|
368 #ifdef FORCE_SECONDARY_CAMERA |
|
369 // 2nd camera forced: always use 1st camera view |
|
370 CX_DEBUG(("CxuiViewManager::getPrecaptureView() forcing primary camera view")); |
|
371 camera = Cxe::PrimaryCameraIndex; |
|
372 #endif // FORCE_SECONDARY_CAMERA |
|
373 |
|
374 if (mode == ImageMode) { |
|
375 |
|
376 CX_DEBUG(("CxuiViewManager::getPrecaptureView() image mode")); |
|
377 if (camera == Cxe::PrimaryCameraIndex) { |
|
378 CX_DEBUG(("CxuiViewManager::getPrecaptureView() primary camera")); |
|
379 if(!mStillPrecaptureView) { |
|
380 createStillPrecaptureView(); |
|
381 } |
|
382 return mStillPrecaptureView; |
|
383 } else { |
|
384 CX_DEBUG(("CxuiViewManager::getPrecaptureView() secondary camera")); |
|
385 if(!mStillPrecaptureView2) { |
|
386 createStillPrecaptureView2(); |
|
387 } |
|
388 return mStillPrecaptureView2; |
|
389 } |
|
390 } else { |
|
391 |
|
392 CX_DEBUG(("CxuiViewManager::getPrecaptureView() video mode")); |
|
393 if (camera == Cxe::PrimaryCameraIndex) { |
|
394 CX_DEBUG(("CxuiViewManager::getPrecaptureView() primary camera")); |
|
395 if(!mVideoPrecaptureView) { |
|
396 createVideoPrecaptureView(); |
|
397 } |
|
398 return mVideoPrecaptureView; |
|
399 } else { |
|
400 CX_DEBUG(("CxuiViewManager::getPrecaptureView() secondary camera")); |
|
401 if(!mVideoPrecaptureView2) { |
|
402 createVideoPrecaptureView2(); |
|
403 } |
|
404 return mVideoPrecaptureView2; |
|
405 } |
|
406 } |
|
407 } |
|
408 |
|
409 CxuiDocumentLoader* CxuiViewManager::documentLoader() |
|
410 { |
|
411 return mCameraDocumentLoader; |
|
412 } |
|
413 |
|
414 // --------------------------------------------------------------------------- |
|
415 // CxuiViewManager::changeToPostcaptureView |
|
416 // |
|
417 // --------------------------------------------------------------------------- |
|
418 // |
|
419 void CxuiViewManager::changeToPostcaptureView() |
|
420 { |
|
421 CX_DEBUG_ENTER_FUNCTION(); |
|
422 |
|
423 if (!mPostcaptureView) { |
|
424 createPostcaptureView(); |
|
425 } |
|
426 |
|
427 mMainWindow.blockSignals(true); |
|
428 mMainWindow.setCurrentView(mPostcaptureView, false); |
|
429 mMainWindow.blockSignals(false); |
|
430 |
|
431 // connecting all necessary signals for postcapture view |
|
432 connectPostCaptureSignals(); |
|
433 |
|
434 //@todo: refactor postcapture view to new focus and state handling as agreed with package owner |
|
435 connect(this, SIGNAL(focusGained()), mPostcaptureView, SLOT(startTimers()), Qt::UniqueConnection); |
|
436 |
|
437 CX_DEBUG_EXIT_FUNCTION(); |
|
438 } |
|
439 |
|
440 // --------------------------------------------------------------------------- |
|
441 // CxuiViewManager::changeToPrecaptureView |
|
442 // |
|
443 // --------------------------------------------------------------------------- |
|
444 // |
|
445 void CxuiViewManager::changeToPrecaptureView() |
|
446 { |
|
447 CX_DEBUG_ENTER_FUNCTION(); |
|
448 |
|
449 if (CxuiServiceProvider::isCameraEmbedded()) { |
|
450 // disconnect signals, we only want to call this once after the initial prepare |
|
451 disconnect(&mEngine.stillCaptureControl(), SIGNAL(imagePrepareComplete(CxeError::Id)), |
|
452 this, SLOT(changeToPrecaptureView())); |
|
453 disconnect(&mEngine.videoCaptureControl(), SIGNAL(videoPrepareComplete(CxeError::Id)), |
|
454 this, SLOT(changeToPrecaptureView())); |
|
455 } |
|
456 |
|
457 HbView *view = getPrecaptureView(mEngine.mode(), |
|
458 mEngine.cameraDeviceControl().cameraIndex()); |
|
459 |
|
460 mMainWindow.blockSignals(true); |
|
461 mMainWindow.setCurrentView(view, false); |
|
462 mMainWindow.blockSignals(false); |
|
463 |
|
464 // connecting necessary pre-capture view signals |
|
465 connectPreCaptureSignals(); |
|
466 |
|
467 CX_DEBUG_EXIT_FUNCTION(); |
|
468 } |
|
469 |
|
470 // --------------------------------------------------------------------------- |
|
471 // CxuiViewManager::switchCamera |
|
472 // |
|
473 // --------------------------------------------------------------------------- |
|
474 // |
|
475 void CxuiViewManager::switchCamera() |
|
476 { |
|
477 CX_DEBUG_ENTER_FUNCTION(); |
|
478 |
|
479 Cxe::CameraIndex nextCamera; |
|
480 Qt::Orientation nextViewOrientation; |
|
481 |
|
482 if (mEngine.cameraDeviceControl().cameraIndex() == Cxe::PrimaryCameraIndex) { |
|
483 nextCamera = Cxe::SecondaryCameraIndex; |
|
484 nextViewOrientation = Qt::Vertical; |
|
485 } else { |
|
486 nextCamera = Cxe::PrimaryCameraIndex; |
|
487 nextViewOrientation = Qt::Horizontal; |
|
488 } |
|
489 |
|
490 CxuiPrecaptureView* view = getPrecaptureView(mEngine.mode(), nextCamera); |
|
491 |
|
492 mMainWindow.blockSignals(true); |
|
493 mMainWindow.setCurrentView(view, false); |
|
494 mMainWindow.blockSignals(false); |
|
495 view->updateOrientation(nextViewOrientation); |
|
496 view->prepareWindow(); |
|
497 |
|
498 connectPreCaptureSignals(); |
|
499 |
|
500 mEngine.cameraDeviceControl().switchCamera(nextCamera); |
|
501 |
|
502 CX_DEBUG_EXIT_FUNCTION(); |
|
503 } |
|
504 |
|
505 // --------------------------------------------------------------------------- |
|
506 // CxuiViewManager::eventFilter |
|
507 // |
|
508 // --------------------------------------------------------------------------- |
|
509 // |
|
510 bool CxuiViewManager::eventFilter(QObject *object, QEvent *event) |
|
511 { |
|
512 bool eventWasConsumed = false; |
|
513 |
|
514 switch (event->type()) |
|
515 { |
|
516 case QEvent::KeyPress: |
|
517 case QEvent::KeyRelease: |
|
518 eventWasConsumed = mKeyHandler.handleKeyEvent(event); |
|
519 break; |
|
520 case QEvent::WindowActivate: |
|
521 if (object == &mMainWindow) { |
|
522 CX_DEBUG(("CxuiViewManager - window activated")); |
|
523 // If we gained focus and keyguard is off. |
|
524 if (!mFocused) { |
|
525 mFocused = true; |
|
526 if (mKeyLockState == EKeyguardNotActive) { |
|
527 aboutToGainFocus(); |
|
528 } |
|
529 } |
|
530 } |
|
531 break; |
|
532 case QEvent::WindowDeactivate: |
|
533 if (object == &mMainWindow) |
|
534 { |
|
535 CX_DEBUG(("CxuiViewManager - window de-activated")); |
|
536 if (mFocused) { |
|
537 mFocused = false; |
|
538 aboutToLooseFocus(); |
|
539 } |
|
540 } |
|
541 break; |
|
542 } |
|
543 |
|
544 // No need to call base class implementation, because we derive from QObject directly. |
|
545 // QObject::eventFilter() implementation always returns false. |
|
546 return eventWasConsumed; |
|
547 } |
|
548 |
|
549 // --------------------------------------------------------------------------- |
|
550 // CxuiViewManager::startEventMonitors |
|
551 // |
|
552 // --------------------------------------------------------------------------- |
|
553 // |
|
554 void CxuiViewManager::startEventMonitors() |
|
555 { |
|
556 CX_DEBUG_ENTER_FUNCTION(); |
|
557 bool ok = false; |
|
558 |
|
559 mSettingsManager = new XQSettingsManager(this); |
|
560 ok = connect(mSettingsManager, SIGNAL(valueChanged(XQSettingsKey, QVariant)), |
|
561 this, SLOT(eventMonitor(XQSettingsKey, QVariant))); |
|
562 CX_DEBUG_ASSERT(ok); |
|
563 |
|
564 // Keyguard status (locked / unlocked) |
|
565 XQSettingsKey keyguard(XQSettingsKey::TargetPublishAndSubscribe, |
|
566 KPSUidAvkonDomain.iUid, |
|
567 KAknKeyguardStatus); |
|
568 |
|
569 QVariant value = mSettingsManager->readItemValue(keyguard); |
|
570 if (value == QVariant::Int) { |
|
571 mKeyLockState = value.toInt(); |
|
572 } |
|
573 ok = mSettingsManager->startMonitoring(keyguard); |
|
574 CX_DEBUG_ASSERT(ok); |
|
575 |
|
576 // Battery status (ok / low / empty) |
|
577 XQSettingsKey battery(XQSettingsKey::TargetPublishAndSubscribe, |
|
578 KPSUidHWRMPowerState.iUid, |
|
579 KHWRMBatteryStatus); |
|
580 value = mSettingsManager->readItemValue(battery); |
|
581 if (value == QVariant::Int) { |
|
582 mBatteryStatus = value.toInt(); |
|
583 } |
|
584 ok = mSettingsManager->startMonitoring(battery); |
|
585 CX_DEBUG_ASSERT(ok); |
|
586 |
|
587 CX_DEBUG_EXIT_FUNCTION(); |
|
588 } |
|
589 |
|
590 |
|
591 |
|
592 // --------------------------------------------------------------------------- |
|
593 // CxuiViewManager::connectCaptureKeySignals |
|
594 // |
|
595 // --------------------------------------------------------------------------- |
|
596 // |
|
597 void CxuiViewManager::connectCaptureKeySignals() |
|
598 { |
|
599 CX_DEBUG_ENTER_FUNCTION(); |
|
600 |
|
601 // Disconnect all existing capture key signals |
|
602 mKeyHandler.disconnect(); |
|
603 |
|
604 QObject *currentView = mMainWindow.currentView(); |
|
605 |
|
606 if (currentView) { |
|
607 // If the view class does not implement the named slot, the connect will fail |
|
608 // and output some warnings as debug prints. This is by design. |
|
609 connect(&mKeyHandler, SIGNAL(autofocusKeyPressed()), currentView, SLOT(handleAutofocusKeyPressed())); |
|
610 connect(&mKeyHandler, SIGNAL(autofocusKeyReleased()), currentView, SLOT(handleAutofocusKeyReleased())); |
|
611 connect(&mKeyHandler, SIGNAL(captureKeyPressed()), currentView, SLOT(handleCaptureKeyPressed())); |
|
612 connect(&mKeyHandler, SIGNAL(captureKeyReleased()), currentView, SLOT(handleCaptureKeyReleased())); |
|
613 } |
|
614 |
|
615 CX_DEBUG_EXIT_FUNCTION(); |
|
616 } |
|
617 |
|
618 |
|
619 // --------------------------------------------------------------------------- |
|
620 // CxuiViewManager::connectPreCaptureSignals |
|
621 // |
|
622 // --------------------------------------------------------------------------- |
|
623 // |
|
624 void CxuiViewManager::connectPreCaptureSignals() |
|
625 { |
|
626 CX_DEBUG_ENTER_FUNCTION(); |
|
627 |
|
628 disconnectSignals(); |
|
629 |
|
630 QObject *currentView = mMainWindow.currentView(); |
|
631 |
|
632 if (currentView != mPostcaptureView) { |
|
633 // connects all capture key signals. |
|
634 connectCaptureKeySignals(); |
|
635 |
|
636 // connecting view manager focus events to pre-capture views |
|
637 connect(this, SIGNAL(focusGained()), currentView, SLOT(handleFocusGained()), Qt::UniqueConnection); |
|
638 connect(this, SIGNAL(focusLost()), currentView, SLOT(handleFocusLost()), Qt::UniqueConnection); |
|
639 connect(this, SIGNAL(batteryEmpty()), currentView, SLOT(handleBatteryEmpty()), Qt::UniqueConnection); |
|
640 |
|
641 // in standby mode, we are interested in focus gain events for dismissing standby |
|
642 connect(this, SIGNAL(focusGained()), mStandbyHandler, SLOT(handleMouseEvent()), Qt::UniqueConnection); |
|
643 |
|
644 // connecting key events to standby. |
|
645 connect(&mKeyHandler, SIGNAL(autofocusKeyPressed()), mStandbyHandler, SLOT(stopTimer()), Qt::UniqueConnection); |
|
646 connect(&mKeyHandler, SIGNAL(autofocusKeyReleased()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection); |
|
647 connect(&mKeyHandler, SIGNAL(captureKeyPressed()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection); |
|
648 connect(&mKeyHandler, SIGNAL(captureKeyReleased()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection); |
|
649 |
|
650 // connecting pre-capture view signals to standby. |
|
651 connect(currentView, SIGNAL(startStandbyTimer()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection); |
|
652 connect(currentView, SIGNAL(changeToPrecaptureView()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection); |
|
653 connect(currentView, SIGNAL(stopStandbyTimer()), mStandbyHandler, SLOT(stopTimer()), Qt::UniqueConnection); |
|
654 connect(currentView, SIGNAL(changeToPostcaptureView()), mStandbyHandler, SLOT(stopTimer()), Qt::UniqueConnection); |
|
655 |
|
656 // connecting precapture view signals to viewmanager slots |
|
657 connect(currentView, SIGNAL(changeToPostcaptureView()), this, SLOT(changeToPostcaptureView()), Qt::UniqueConnection); |
|
658 connect(currentView, SIGNAL(changeToPrecaptureView()), this, SLOT(changeToPrecaptureView()), Qt::UniqueConnection); |
|
659 connect(currentView, SIGNAL(switchCamera()), this, SLOT(switchCamera()), Qt::UniqueConnection); |
|
660 |
|
661 // connecting error signals from precapture view to errormanager. |
|
662 connect(currentView, SIGNAL(reportError(CxeError::Id)), mErrorManager, SLOT(analyze(CxeError::Id)), Qt::UniqueConnection); |
|
663 } |
|
664 |
|
665 CX_DEBUG_EXIT_FUNCTION(); |
|
666 } |
|
667 |
|
668 |
|
669 // --------------------------------------------------------------------------- |
|
670 // CxuiViewManager::connectPostCaptureSignals |
|
671 // |
|
672 // --------------------------------------------------------------------------- |
|
673 // |
|
674 void CxuiViewManager::connectPostCaptureSignals() |
|
675 { |
|
676 CX_DEBUG_ENTER_FUNCTION(); |
|
677 |
|
678 disconnectSignals(); |
|
679 QObject *currentView = mMainWindow.currentView(); |
|
680 if (currentView == mPostcaptureView) { |
|
681 // connecting view manager focus events to pre-capture views |
|
682 connect(this, SIGNAL(focusLost()), currentView, SLOT(handleFocusLost()), Qt::UniqueConnection); |
|
683 connect(currentView, SIGNAL(changeToPrecaptureView()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection); |
|
684 |
|
685 // connect necessary capturekey signals |
|
686 connectCaptureKeySignals(); |
|
687 } |
|
688 |
|
689 CX_DEBUG_EXIT_FUNCTION(); |
|
690 } |
|
691 |
|
692 |
|
693 |
|
694 /* |
|
695 * CxuiViewManager::disconnectPreCaptureSignals |
|
696 */ |
|
697 void CxuiViewManager::disconnectSignals() |
|
698 { |
|
699 CX_DEBUG_ENTER_FUNCTION(); |
|
700 |
|
701 // Disconnect all existing capture key signals |
|
702 mKeyHandler.disconnect(); |
|
703 |
|
704 disconnect(SIGNAL(focusGained())); |
|
705 disconnect(SIGNAL(focusLost())); |
|
706 disconnect(SIGNAL(batteryEmpty())); |
|
707 |
|
708 CX_DEBUG_EXIT_FUNCTION(); |
|
709 } |
|
710 |
|
711 |
|
712 // --------------------------------------------------------------------------- |
|
713 // CxuiViewManager::aboutToLooseFocus() |
|
714 // |
|
715 // --------------------------------------------------------------------------- |
|
716 // |
|
717 void CxuiViewManager::aboutToLooseFocus() |
|
718 { |
|
719 CX_DEBUG_ENTER_FUNCTION(); |
|
720 |
|
721 emit focusLost(); |
|
722 disconnectSignals(); |
|
723 |
|
724 CX_DEBUG_EXIT_FUNCTION(); |
|
725 } |
|
726 |
|
727 |
|
728 // --------------------------------------------------------------------------- |
|
729 // CxuiViewManager::aboutToGainFocus |
|
730 // |
|
731 // --------------------------------------------------------------------------- |
|
732 // |
|
733 void CxuiViewManager::aboutToGainFocus() |
|
734 { |
|
735 CX_DEBUG_ENTER_FUNCTION(); |
|
736 |
|
737 // we are getting the focus. |
|
738 if (mMainWindow.currentView() != mPostcaptureView) { |
|
739 connectPreCaptureSignals(); |
|
740 } else { |
|
741 connectPostCaptureSignals(); |
|
742 } |
|
743 |
|
744 emit focusGained(); |
|
745 |
|
746 CX_DEBUG_EXIT_FUNCTION(); |
|
747 } |
|
748 |
|
749 |
|
750 // --------------------------------------------------------------------------- |
|
751 // CxuiViewManager::eventMonitor |
|
752 // |
|
753 // --------------------------------------------------------------------------- |
|
754 // |
|
755 void CxuiViewManager::eventMonitor( const XQSettingsKey& key, const QVariant& value ) |
|
756 { |
|
757 CX_DEBUG_ENTER_FUNCTION(); |
|
758 |
|
759 if (key.uid() == KPSUidAvkonDomain.iUid && key.key() == KAknKeyguardStatus) { |
|
760 CX_DEBUG(("new Keyguard value = %d, mKeyLockState = %d", value.toInt(), mKeyLockState)); |
|
761 if (mSettingsManager->error() == XQSettingsManager::NoError) { |
|
762 // New key guard state |
|
763 int newKeyLockState = value.toInt(); |
|
764 |
|
765 // Check if the keylock value has actually changed |
|
766 bool keylockValueChanged = (newKeyLockState != mKeyLockState); |
|
767 mKeyLockState = newKeyLockState; |
|
768 |
|
769 // Ignore unlock events when on background |
|
770 bool unlockedOnBackground = (!mFocused && newKeyLockState == EKeyguardNotActive); |
|
771 |
|
772 if (keylockValueChanged && |
|
773 !unlockedOnBackground) { |
|
774 // Key lock value changed and we need to handle it |
|
775 if (mKeyLockState == EKeyguardNotActive) { |
|
776 // All other keylock states are handled as a active in S60 code |
|
777 aboutToGainFocus(); |
|
778 } else { |
|
779 mFocused = false; |
|
780 aboutToLooseFocus(); |
|
781 } |
|
782 } |
|
783 } else { |
|
784 // Error from settings manager - ignore |
|
785 CX_DEBUG(("mSettingsManager indicated error %d for key guard status", mSettingsManager->error())); |
|
786 } |
|
787 } else if (key.uid() == KPSUidHWRMPowerState.iUid && key.key() == KHWRMBatteryStatus ) { |
|
788 CX_DEBUG(("new battery status = %d, mBatteryStatus = %d", value.toInt(), mBatteryStatus)); |
|
789 |
|
790 if (mSettingsManager->error() == XQSettingsManager::NoError) { |
|
791 |
|
792 // If status changed, check if battery is going empty. |
|
793 const int newState = value.toInt(); |
|
794 if( newState != mBatteryStatus ) { |
|
795 mBatteryStatus = newState; |
|
796 |
|
797 // Notify that battery is almost empty, |
|
798 // need to stop any recordings etc. |
|
799 if( mBatteryStatus == EBatteryStatusEmpty ) { |
|
800 emit batteryEmpty(); |
|
801 } |
|
802 } |
|
803 } |
|
804 } |
|
805 |
|
806 CX_DEBUG_EXIT_FUNCTION(); |
|
807 } |
|
808 |
|
809 // end of file |