camerauis/cameraxui/cxui/src/cxuiviewmanager.cpp
changeset 28 3075d9b614e6
parent 19 d9aefe59d544
child 29 699651f2666f
child 43 0e652f8f1fbd
equal deleted inserted replaced
19:d9aefe59d544 28:3075d9b614e6
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    16 */
    16 */
    17 #include <QDebug>
    17 #include <QDebug>
    18 #include <QTimer>
    18 #include <QTimer>
    19 #include <hbmainwindow.h>
    19 #include <hbmainwindow.h>
    20 #include <coemain.h>
    20 #include <coemain.h>
    21 #include <avkondomainpskeys.h>  // keyguard
       
    22 #include <hwrmpowerstatesdkpskeys.h> // battery
       
    23 #include <QGraphicsSceneEvent>
    21 #include <QGraphicsSceneEvent>
    24 
    22 
    25 
    23 
       
    24 #include "cxuiapplication.h"
       
    25 #include "cxuiapplicationframeworkmonitor.h"
    26 #include "cxuiviewmanager.h"
    26 #include "cxuiviewmanager.h"
    27 #include "cxuivideoprecaptureview.h"
    27 #include "cxuivideoprecaptureview.h"
    28 #include "cxuivideoprecaptureview2.h"
       
    29 #include "cxuistillprecaptureview.h"
    28 #include "cxuistillprecaptureview.h"
    30 #include "cxuistillprecaptureview2.h"
       
    31 #include "cxuipostcaptureview.h"
    29 #include "cxuipostcaptureview.h"
    32 #include "cxuicapturekeyhandler.h"
    30 #include "cxuicapturekeyhandler.h"
    33 #include "cxeengine.h"
    31 #include "cxeengine.h"
    34 #include "cxecameradevicecontrol.h"
    32 #include "cxecameradevicecontrol.h"
    35 #include "cxefeaturemanager.h" //  mEngine->featureManager()
    33 #include "cxefeaturemanager.h" //  mEngine->featureManager()
    36 #include "cxeviewfindercontrol.h"
    34 #include "cxeviewfindercontrol.h"
    37 #include "cxenamespace.h"
    35 #include "cxenamespace.h"
    38 #include "cxuienums.h"
    36 #include "cxuienums.h"
    39 #include "cxutils.h"
    37 #include "cxutils.h"
    40 #include "xqsettingsmanager.h" // Settings Manager API
       
    41 #include "cxuidocumentloader.h"
    38 #include "cxuidocumentloader.h"
    42 #include "cxuistandby.h"
    39 #include "cxuistandby.h"
    43 #include "cxuierrormanager.h"
    40 #include "cxuierrormanager.h"
       
    41 #include "cxesettings.h"
       
    42 #include "cxememorymonitor.h"
       
    43 #include "cxuiserviceprovider.h"
       
    44 #include "cxuiscenemodeview.h"
       
    45 
    44 #include "OstTraceDefinitions.h"
    46 #include "OstTraceDefinitions.h"
    45 #ifdef OST_TRACE_COMPILER_IN_USE
    47 #ifdef OST_TRACE_COMPILER_IN_USE
    46 #include "cxuiviewmanagerTraces.h"
    48 #include "cxuiviewmanagerTraces.h"
    47 #endif
    49 #endif
    48 #include "cxuiserviceprovider.h"
       
    49 
       
    50 
    50 
    51 
    51 
    52 using namespace Cxe;
    52 using namespace Cxe;
    53 using namespace CxUiLayout;
    53 using namespace CxUiLayout;
    54 
    54 
    56 // ---------------------------------------------------------------------------
    56 // ---------------------------------------------------------------------------
    57 // CxuiViewManager::CxuiViewManager
    57 // CxuiViewManager::CxuiViewManager
    58 //
    58 //
    59 // ---------------------------------------------------------------------------
    59 // ---------------------------------------------------------------------------
    60 //
    60 //
    61 CxuiViewManager::CxuiViewManager(HbMainWindow &mainWindow, CxeEngine &engine, CxuiCaptureKeyHandler &keyHandler) :
    61 CxuiViewManager::CxuiViewManager(CxuiApplication &application, HbMainWindow &mainWindow, CxeEngine &engine) :
       
    62     mApplication(application),
    62     mMainWindow(mainWindow),
    63     mMainWindow(mainWindow),
    63     mStillPrecaptureView(NULL),
    64     mStillPrecaptureView(NULL),
    64     mVideoPrecaptureView(NULL),
    65     mVideoPrecaptureView(NULL),
    65     mPostcaptureView(NULL),
    66     mPostcaptureView(NULL),
    66     mStillPrecaptureView2(NULL),
       
    67     mVideoPrecaptureView2(NULL),
       
    68     mEngine(engine),
    67     mEngine(engine),
    69     mKeyHandler(keyHandler),
    68     mKeyHandler(NULL),
    70     mSettingsManager(NULL),
    69     mApplicationMonitor(NULL),
    71     mFocused(true),
    70     mCameraDocumentLoader(NULL),
    72     mCameraDocumentLoader(NULL)
    71     mSceneModeView(NULL)
    73 {
    72 {
    74     CX_DEBUG_ENTER_FUNCTION();
    73     CX_DEBUG_ENTER_FUNCTION();
       
    74 
       
    75     // Application monitor
       
    76     mApplicationMonitor = new CxuiApplicationFrameworkMonitor(mApplication, mEngine.settings());
       
    77     connect(mApplicationMonitor, SIGNAL(foregroundStateChanged(CxuiApplicationFrameworkMonitor::ForegroundState)),
       
    78             this, SLOT(handleForegroundStateChanged(CxuiApplicationFrameworkMonitor::ForegroundState)));
       
    79     connect(mApplicationMonitor, SIGNAL(batteryEmpty()),
       
    80             this, SLOT(handleBatteryEmpty()));
       
    81 
       
    82     // Connect memory monitor start / stop to focused status
       
    83     connect(this, SIGNAL(focusGained()), &mEngine.memoryMonitor(), SLOT(startMonitoring()));
       
    84     connect(this, SIGNAL(focusLost()),   &mEngine.memoryMonitor(), SLOT(stopMonitoring()));
       
    85 
       
    86     // Key handler
       
    87     mKeyHandler = new CxuiCaptureKeyHandler(mEngine);
    75 
    88 
    76     mMainWindow.installEventFilter(this); // in order to filter capture and AF keys
    89     mMainWindow.installEventFilter(this); // in order to filter capture and AF keys
    77 
    90 
    78     OstTrace0( camerax_performance, CXUIVIEWMANAGER_CXUIVIEWMANAGER, "msg: e_CX_VIEWMANAGER_CREATE_DOCLOADER 1" );
    91     OstTrace0( camerax_performance, CXUIVIEWMANAGER_CXUIVIEWMANAGER, "msg: e_CX_VIEWMANAGER_CREATE_DOCLOADER 1" );
    79     mCameraDocumentLoader = new CxuiDocumentLoader;
    92     mCameraDocumentLoader = new CxuiDocumentLoader(&engine);
    80     OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_CXUIVIEWMANAGER, "msg: e_CX_VIEWMANAGER_CREATE_DOCLOADER 0" );
    93     OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_CXUIVIEWMANAGER, "msg: e_CX_VIEWMANAGER_CREATE_DOCLOADER 0" );
    81 
    94 
    82     // standby functionality and necessary signal connections
    95     // standby functionality and necessary signal connections
    83     mStandbyHandler = new CxuiStandby(keyHandler, mCameraDocumentLoader, &engine);
    96     mStandbyHandler = new CxuiStandby(*mKeyHandler, mCameraDocumentLoader, &mEngine);
    84 
    97 
    85     connect(mStandbyHandler, SIGNAL(aboutToEnterStandby()),this, SLOT(aboutToLooseFocus()));
    98     connect(mStandbyHandler, SIGNAL(aboutToEnterStandby()),this, SLOT(aboutToLooseFocus()));
    86     connect(mStandbyHandler, SIGNAL(aboutToExitStandby()),this, SLOT(aboutToGainFocus()));
    99     connect(mStandbyHandler, SIGNAL(aboutToExitStandby()),this, SLOT(aboutToGainFocus()));
    87 
   100 
    88     // error manager, handling errors and notifying users based on their severity
   101     // error manager, handling errors and notifying users based on their severity
    89     mErrorManager = new CxuiErrorManager(keyHandler, mCameraDocumentLoader);
   102     mErrorManager = new CxuiErrorManager(*mKeyHandler, mCameraDocumentLoader);
    90 
   103 
    91     // connecting necessary signals from error manager to release and init camera.
   104     // connecting necessary signals from error manager to release and init camera.
    92     connect(mErrorManager, SIGNAL(aboutToRecoverError()), this, SLOT(aboutToLooseFocus()));
   105     connect(mErrorManager, SIGNAL(aboutToRecoverError()), this, SLOT(aboutToLooseFocus()));
    93     connect(mErrorManager, SIGNAL(errorRecovered()), this, SLOT(aboutToGainFocus()));
   106     connect(mErrorManager, SIGNAL(errorRecovered()), this, SLOT(aboutToGainFocus()));
    94 
   107 
    95 	if (!CxuiServiceProvider::isCameraEmbedded()) {
   108     if (!CxuiServiceProvider::isCameraEmbedded()) {
    96 		// for embedded mode: don't create view yet, create
   109         // For embedded mode: don't create view yet, create
    97 		// when engine inits to correct mode
   110         // when engine inits to correct mode
    98 #ifdef FORCE_SECONDARY_CAMERA
   111         CX_DEBUG_ASSERT(mEngine.cameraDeviceControl().cameraIndex() == Cxe::PrimaryCameraIndex);
    99 	    // 2nd camera hack: always use 1st camera view
   112         if (mEngine.mode() == Cxe::VideoMode) {
   100 	    if (mEngine.mode() == Cxe::VideoMode) {
   113             createVideoPrecaptureView();
   101 	        createVideoPrecaptureView();
   114             mMainWindow.blockSignals(true);
   102 	
   115             mMainWindow.setCurrentView(mVideoPrecaptureView, false);
   103 	        mMainWindow.blockSignals(true);
   116             mMainWindow.blockSignals(false);
   104 	        mMainWindow.setCurrentView(mVideoPrecaptureView, false);
   117         } else {
   105 	        mMainWindow.blockSignals(false);
   118             createStillPrecaptureView();
   106 	    } else {
   119             mMainWindow.blockSignals(true);
   107 	        createStillPrecaptureView();
   120             mMainWindow.setCurrentView(mStillPrecaptureView, false);
   108 	
   121             mMainWindow.blockSignals(false);
   109 	        mMainWindow.blockSignals(true);
   122         }
   110 	        mMainWindow.setCurrentView(mStillPrecaptureView, false);
   123         connectPreCaptureSignals();
   111 	        mMainWindow.blockSignals(false);
   124     }
   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 
   125 
   146     //connecting initmode signals
   126     //connecting initmode signals
   147     connect(&mEngine.cameraDeviceControl(), SIGNAL(initModeComplete(CxeError::Id)),
   127     connect(&mEngine.cameraDeviceControl(), SIGNAL(initModeComplete(CxeError::Id)),
   148             this, SLOT(createPostcaptureView()));
   128             this, SLOT(createPostcaptureView()));
       
   129 
   149     connect(&mEngine.cameraDeviceControl(), SIGNAL(initModeComplete(CxeError::Id)),
   130     connect(&mEngine.cameraDeviceControl(), SIGNAL(initModeComplete(CxeError::Id)),
       
   131             mErrorManager, SLOT(analyze(CxeError::Id)));
       
   132 
       
   133     connect(&mEngine.stillCaptureControl(), SIGNAL(imageCaptured(CxeError::Id, int)),
   150             mErrorManager, SLOT(analyze(CxeError::Id)));
   134             mErrorManager, SLOT(analyze(CxeError::Id)));
   151 
   135 
   152     if (CxuiServiceProvider::isCameraEmbedded()) {
   136     if (CxuiServiceProvider::isCameraEmbedded()) {
   153         // connect signals to set up the view after image/video prepare
   137         // connect signals to set up the view after image/video prepare
   154         connect(&mEngine.stillCaptureControl(), SIGNAL(imagePrepareComplete(CxeError::Id)),
   138         connect(&mEngine.stillCaptureControl(), SIGNAL(imagePrepareComplete(CxeError::Id)),
   157                 this, SLOT(changeToPrecaptureView()));
   141                 this, SLOT(changeToPrecaptureView()));
   158 
   142 
   159         // start standby timer now because view will not be ready when viewfinder is started
   143         // start standby timer now because view will not be ready when viewfinder is started
   160         mStandbyHandler->startTimer();
   144         mStandbyHandler->startTimer();
   161     }
   145     }
   162             
   146 
   163     CX_DEBUG_EXIT_FUNCTION();
   147     CX_DEBUG_EXIT_FUNCTION();
   164 }
   148 }
   165 
   149 
   166 // ---------------------------------------------------------------------------
   150 // ---------------------------------------------------------------------------
   167 // CxuiViewManager::~CxuiViewManager
   151 // CxuiViewManager::~CxuiViewManager
   171 CxuiViewManager::~CxuiViewManager()
   155 CxuiViewManager::~CxuiViewManager()
   172 {
   156 {
   173     CX_DEBUG_ENTER_FUNCTION();
   157     CX_DEBUG_ENTER_FUNCTION();
   174 
   158 
   175     delete mCameraDocumentLoader;
   159     delete mCameraDocumentLoader;
   176     delete mSettingsManager;
   160     delete mKeyHandler;
       
   161     delete mApplicationMonitor;
   177 
   162 
   178     CX_DEBUG_EXIT_FUNCTION();
   163     CX_DEBUG_EXIT_FUNCTION();
   179 }
   164 }
   180 
   165 
   181 
   166 
   197 //
   182 //
   198 void CxuiViewManager::createStillPrecaptureView()
   183 void CxuiViewManager::createStillPrecaptureView()
   199 {
   184 {
   200     CX_DEBUG_ENTER_FUNCTION();
   185     CX_DEBUG_ENTER_FUNCTION();
   201     OstTrace0( camerax_performance, CXUIVIEWMANAGER_CREATESTILLPRECAPTUREVIEW, "msg: e_CX_CREATE_STILLPRECAPTUREVIEW 1" );
   186     OstTrace0( camerax_performance, CXUIVIEWMANAGER_CREATESTILLPRECAPTUREVIEW, "msg: e_CX_CREATE_STILLPRECAPTUREVIEW 1" );
       
   187 
       
   188     // Use document loader to create widgets and layouts
       
   189     // (non-sectioned parts are parsed and loaded)
       
   190     OstTrace0( camerax_performance, DUP2_CXUIVIEWMANAGER_ADDPRECAPTUREVIEWS, "msg: e_CX_DOCLOADER_LOAD 1" );
       
   191 
   202     bool ok = false;
   192     bool ok = false;
   203     CX_DEBUG_ASSERT(mCameraDocumentLoader);
   193     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);
   194     mCameraDocumentLoader->load(STILL_1ST_XML, &ok);
   210     Q_ASSERT_X(ok, "createStillPrecaptureView", "error in xml file parsing");
   195     Q_ASSERT_X(ok, "createStillPrecaptureView", "error in xml file parsing");
   211 
   196 
       
   197     OstTrace0( camerax_performance, DUP2_CXUIVIEWMANAGER_CREATESTILLPRECAPTUREVIEW, "msg: e_CX_DOCLOADER_LOAD 0" );
       
   198 
       
   199     OstTrace0( camerax_performance, DUP4_CXUIVIEWMANAGER_ADDPRECAPTUREVIEWS, "msg: e_CX_DOCLOADER_FINDWIDGET 1" );
   212     QGraphicsWidget *widget = NULL;
   200     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
   201     // ask for the still precapture view widget pointer
   219     widget = mCameraDocumentLoader->findWidget(STILL_PRE_CAPTURE_VIEW);
   202     widget = mCameraDocumentLoader->findWidget(STILL_PRE_CAPTURE_VIEW);
   220     mStillPrecaptureView = qobject_cast<CxuiStillPrecaptureView *> (widget);
   203     mStillPrecaptureView = qobject_cast<CxuiStillPrecaptureView *> (widget);
   221     CX_DEBUG_ASSERT(mStillPrecaptureView);
   204     CX_DEBUG_ASSERT(mStillPrecaptureView);
   222     OstTrace0( camerax_performance, DUP5_CXUIVIEWMANAGER_ADDPRECAPTUREVIEWS, "msg: e_CX_DOCLOADER_FINDWIDGET 0" );
   205     OstTrace0( camerax_performance, DUP5_CXUIVIEWMANAGER_ADDPRECAPTUREVIEWS, "msg: e_CX_DOCLOADER_FINDWIDGET 0" );
   223 
   206 
   224     // call for needed consturction methods
   207     // call for needed consturction methods
   225     mStillPrecaptureView->construct(&mMainWindow, &mEngine, mCameraDocumentLoader, &mKeyHandler);
   208     mStillPrecaptureView->construct(&mMainWindow, &mEngine, mCameraDocumentLoader, mKeyHandler);
       
   209     // .. and add to main window (which also takes ownership)
       
   210     OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_MAINWINDOW_ADDVIEW, "msg: e_CX_MAINWINDOW_ADDVIEW 1" );
       
   211     mMainWindow.addView(widget);
       
   212     OstTrace0( camerax_performance, DUP2_CXUIVIEWMANAGER_MAINWINDOW_ADDVIEW, "msg: e_CX_MAINWINDOW_ADDVIEW 0" );
       
   213 
       
   214     OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_CREATESTILLPRECAPTUREVIEW, "msg: e_CX_CREATE_STILLPRECAPTUREVIEW 0" );
       
   215 
       
   216     CX_DEBUG_EXIT_FUNCTION();
       
   217 }
       
   218 
       
   219 // ---------------------------------------------------------------------------
       
   220 // CxuiViewManager::createStillScenesView
       
   221 //
       
   222 // ---------------------------------------------------------------------------
       
   223 //
       
   224 void CxuiViewManager::createSceneModesView()
       
   225 {
       
   226     CX_DEBUG_ENTER_FUNCTION();
       
   227 
       
   228     bool ok = false;
       
   229     CX_DEBUG_ASSERT(mCameraDocumentLoader);
       
   230 
       
   231     // Use document loader to create widgets and layouts
       
   232     // (non-sectioned parts are parsed and loaded)
       
   233     mCameraDocumentLoader->load(SCENEMODE_SETTING_XML, &ok);
       
   234 
       
   235     QGraphicsWidget *widget = NULL;
       
   236 
       
   237     // ask for the scenes mode view widget pointer
       
   238     widget = mCameraDocumentLoader->findWidget(STILL_SCENES_VIEW);
       
   239     Q_ASSERT_X(ok && (widget != 0), "camerax ui", "invalid xml file");
       
   240     mSceneModeView = qobject_cast<CxuiSceneModeView *> (widget);
       
   241 
       
   242     // call for needed construction methods
       
   243     mSceneModeView->construct(&mMainWindow, &mEngine, mCameraDocumentLoader, mKeyHandler);
   226     // .. and add to main window (which also takes ownership)
   244     // .. and add to main window (which also takes ownership)
   227     mMainWindow.addView(widget);
   245     mMainWindow.addView(widget);
   228 
   246     mSceneModeView->loadBackgroundImages();
   229     OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_CREATESTILLPRECAPTUREVIEW, "msg: e_CX_CREATE_STILLPRECAPTUREVIEW 0" );
   247 
   230 
   248     connect(mSceneModeView, SIGNAL(viewCloseEvent()), this, SLOT(changeToPrecaptureView()));
   231     CX_DEBUG_EXIT_FUNCTION();
   249     CX_DEBUG_EXIT_FUNCTION();
   232 }
   250 }
   233 
   251 
   234 // ---------------------------------------------------------------------------
   252 /*!
   235 // CxuiViewManager::createStillPrecaptureView2
   253 * CxuiViewManager::showScenesView
   236 //
   254 * A private method for displaying Scene Modes selection view
   237 // ---------------------------------------------------------------------------
   255 */
   238 //
   256 void CxuiViewManager::showScenesView()
   239 void CxuiViewManager::createStillPrecaptureView2()
   257 {
   240 {
   258     CX_DEBUG_ENTER_FUNCTION();
   241     CX_DEBUG_ENTER_FUNCTION();
   259     if (!mSceneModeView) {
   242 
   260         createSceneModesView();
   243     bool ok = false;
   261     }
   244     CX_DEBUG_ASSERT(mCameraDocumentLoader);
   262     else {
   245 
   263         mSceneModeView->loadBackgroundImages();
   246     // Use document loader to create widgets and layouts
   264     }
   247     // (non-sectioned parts are parsed and loaded)
   265     CX_DEBUG_ASSERT(mSceneModeView);
   248     mCameraDocumentLoader->load(STILL_2ND_XML, &ok);
   266     mMainWindow.blockSignals(true);
   249     Q_ASSERT_X(ok, "createStillPrecaptureView2", "error in xml file parsing");
   267     mMainWindow.setCurrentView(mSceneModeView, false);
   250 
   268     emit disableStandbyTimer();
   251     QGraphicsWidget *widget = NULL;
   269     connectCaptureKeySignals();
   252 
   270     mMainWindow.blockSignals(false);
   253     // ask for the still precapture view widget pointer
   271     CX_DEBUG_EXIT_FUNCTION();
   254     widget = mCameraDocumentLoader->findWidget(STILL_PRE_CAPTURE_VIEW2);
   272 }
   255     mStillPrecaptureView2 = qobject_cast<CxuiStillPrecaptureView2 *> (widget);
   273 
   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 
   274 
   266 // ---------------------------------------------------------------------------
   275 // ---------------------------------------------------------------------------
   267 // CxuiViewManager::createVideoPrecaptureView
   276 // CxuiViewManager::createVideoPrecaptureView
   268 //
   277 //
   269 // ---------------------------------------------------------------------------
   278 // ---------------------------------------------------------------------------
   283     // get pointer to videoprecaptureview and do some initialisation
   292     // get pointer to videoprecaptureview and do some initialisation
   284     QGraphicsWidget *widget = NULL;
   293     QGraphicsWidget *widget = NULL;
   285     widget = mCameraDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_VIEW);
   294     widget = mCameraDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_VIEW);
   286     mVideoPrecaptureView = qobject_cast<CxuiVideoPrecaptureView *> (widget);
   295     mVideoPrecaptureView = qobject_cast<CxuiVideoPrecaptureView *> (widget);
   287     CX_DEBUG_ASSERT(mVideoPrecaptureView);
   296     CX_DEBUG_ASSERT(mVideoPrecaptureView);
   288     mVideoPrecaptureView->construct(&mMainWindow, &mEngine, mCameraDocumentLoader, &mKeyHandler);
   297     mVideoPrecaptureView->construct(&mMainWindow, &mEngine, mCameraDocumentLoader, mKeyHandler);
   289 
   298 
   290     // add view to main window
   299     // add view to main window
       
   300     OstTrace0( camerax_performance, DUP3_CXUIVIEWMANAGER_MAINWINDOW_ADDVIEW, "msg: e_CX_MAINWINDOW_ADDVIEW 1" );
   291     mMainWindow.addView(mVideoPrecaptureView);
   301     mMainWindow.addView(mVideoPrecaptureView);
       
   302     OstTrace0( camerax_performance, DUP4_CXUIVIEWMANAGER_MAINWINDOW_ADDVIEW, "msg: e_CX_MAINWINDOW_ADDVIEW 0" );
   292     OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_CREATEVIDEOPRECAPTUREVIEW, "msg: e_CX_CREATE_VIDEOPRECAPTUREVIEW 0" );
   303     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 
   304 
   322     CX_DEBUG_EXIT_FUNCTION();
   305     CX_DEBUG_EXIT_FUNCTION();
   323 }
   306 }
   324 
   307 
   325 // ---------------------------------------------------------------------------
   308 // ---------------------------------------------------------------------------
   363 CxuiViewManager::getPrecaptureView(Cxe::CameraMode mode, Cxe::CameraIndex camera)
   346 CxuiViewManager::getPrecaptureView(Cxe::CameraMode mode, Cxe::CameraIndex camera)
   364 {
   347 {
   365     CX_DEBUG_ENTER_FUNCTION();
   348     CX_DEBUG_ENTER_FUNCTION();
   366     CX_DEBUG(("CxuiViewManager::getPrecaptureView() mode=%d, camera index=%d", mode, camera));
   349     CX_DEBUG(("CxuiViewManager::getPrecaptureView() mode=%d, camera index=%d", mode, camera));
   367 
   350 
   368 #ifdef FORCE_SECONDARY_CAMERA
   351     CX_DEBUG_ASSERT(camera == Cxe::PrimaryCameraIndex);
   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 
   352 
   374     if (mode == ImageMode) {
   353     if (mode == ImageMode) {
   375 
       
   376         CX_DEBUG(("CxuiViewManager::getPrecaptureView() image mode"));
   354         CX_DEBUG(("CxuiViewManager::getPrecaptureView() image mode"));
   377         if (camera == Cxe::PrimaryCameraIndex) {
   355         if(!mStillPrecaptureView) {
   378             CX_DEBUG(("CxuiViewManager::getPrecaptureView() primary camera"));
   356             createStillPrecaptureView();
   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         }
   357         }
       
   358         return mStillPrecaptureView;
   390     } else {
   359     } else {
   391 
       
   392         CX_DEBUG(("CxuiViewManager::getPrecaptureView() video mode"));
   360         CX_DEBUG(("CxuiViewManager::getPrecaptureView() video mode"));
   393         if (camera == Cxe::PrimaryCameraIndex) {
   361         if(!mVideoPrecaptureView) {
   394             CX_DEBUG(("CxuiViewManager::getPrecaptureView() primary camera"));
   362             createVideoPrecaptureView();
   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         }
   363         }
       
   364         return mVideoPrecaptureView;
   406     }
   365     }
   407 }
   366 }
   408 
   367 
   409 CxuiDocumentLoader* CxuiViewManager::documentLoader()
   368 CxuiDocumentLoader* CxuiViewManager::documentLoader()
   410 {
   369 {
   428     mMainWindow.setCurrentView(mPostcaptureView, false);
   387     mMainWindow.setCurrentView(mPostcaptureView, false);
   429     mMainWindow.blockSignals(false);
   388     mMainWindow.blockSignals(false);
   430 
   389 
   431     // connecting all necessary signals for postcapture view
   390     // connecting all necessary signals for postcapture view
   432     connectPostCaptureSignals();
   391     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 
   392 
   437     CX_DEBUG_EXIT_FUNCTION();
   393     CX_DEBUG_EXIT_FUNCTION();
   438 }
   394 }
   439 
   395 
   440 // ---------------------------------------------------------------------------
   396 // ---------------------------------------------------------------------------
   461     mMainWindow.setCurrentView(view, false);
   417     mMainWindow.setCurrentView(view, false);
   462     mMainWindow.blockSignals(false);
   418     mMainWindow.blockSignals(false);
   463 
   419 
   464     // connecting necessary pre-capture view signals
   420     // connecting necessary pre-capture view signals
   465     connectPreCaptureSignals();
   421     connectPreCaptureSignals();
       
   422     emit startStandbyTimer();
   466 
   423 
   467     CX_DEBUG_EXIT_FUNCTION();
   424     CX_DEBUG_EXIT_FUNCTION();
   468 }
   425 }
   469 
   426 
   470 // ---------------------------------------------------------------------------
   427 // ---------------------------------------------------------------------------
   507 //
   464 //
   508 // ---------------------------------------------------------------------------
   465 // ---------------------------------------------------------------------------
   509 //
   466 //
   510 bool CxuiViewManager::eventFilter(QObject *object, QEvent *event)
   467 bool CxuiViewManager::eventFilter(QObject *object, QEvent *event)
   511 {
   468 {
       
   469     Q_UNUSED(object)
       
   470 
   512     bool eventWasConsumed = false;
   471     bool eventWasConsumed = false;
   513 
   472 
   514     switch (event->type())
   473     switch (event->type())
   515     {
   474     {
   516     case QEvent::KeyPress:
   475     case QEvent::KeyPress:
   517     case QEvent::KeyRelease:
   476     case QEvent::KeyRelease:
   518         eventWasConsumed = mKeyHandler.handleKeyEvent(event);
   477         eventWasConsumed = mKeyHandler->handleKeyEvent(event);
   519         break;
   478         break;
   520     case QEvent::WindowActivate:
   479     }
   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.
   480     // No need to call base class implementation, because we derive from QObject directly.
   545     // QObject::eventFilter() implementation always returns false.
   481     // QObject::eventFilter() implementation always returns false.
   546     return eventWasConsumed;
   482     return eventWasConsumed;
   547 }
   483 }
   548 
   484 
   549 // ---------------------------------------------------------------------------
   485 // ---------------------------------------------------------------------------
   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
   486 // CxuiViewManager::connectCaptureKeySignals
   594 //
   487 //
   595 // ---------------------------------------------------------------------------
   488 // ---------------------------------------------------------------------------
   596 //
   489 //
   597 void CxuiViewManager::connectCaptureKeySignals()
   490 void CxuiViewManager::connectCaptureKeySignals()
   598 {
   491 {
   599     CX_DEBUG_ENTER_FUNCTION();
   492     CX_DEBUG_ENTER_FUNCTION();
   600 
   493 
   601     // Disconnect all existing capture key signals
   494     // Disconnect all existing capture key signals
   602     mKeyHandler.disconnect();
   495     mKeyHandler->disconnect();
   603 
   496 
   604     QObject *currentView = mMainWindow.currentView();
   497     QObject *currentView = mMainWindow.currentView();
   605 
   498 
   606     if (currentView) {
   499     if (currentView) {
   607         // If the view class does not implement the named slot, the connect will fail
   500         // 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.
   501         // and output some warnings as debug prints. This is by design.
   609         connect(&mKeyHandler, SIGNAL(autofocusKeyPressed()),  currentView, SLOT(handleAutofocusKeyPressed()));
   502         connect(mKeyHandler, SIGNAL(autofocusKeyPressed()),  currentView, SLOT(handleAutofocusKeyPressed()));
   610         connect(&mKeyHandler, SIGNAL(autofocusKeyReleased()), currentView, SLOT(handleAutofocusKeyReleased()));
   503         connect(mKeyHandler, SIGNAL(autofocusKeyReleased()), currentView, SLOT(handleAutofocusKeyReleased()));
   611         connect(&mKeyHandler, SIGNAL(captureKeyPressed()),    currentView, SLOT(handleCaptureKeyPressed()));
   504         connect(mKeyHandler, SIGNAL(captureKeyPressed()),    currentView, SLOT(handleCaptureKeyPressed()));
   612         connect(&mKeyHandler, SIGNAL(captureKeyReleased()),   currentView, SLOT(handleCaptureKeyReleased()));
   505         connect(mKeyHandler, SIGNAL(captureKeyReleased()),   currentView, SLOT(handleCaptureKeyReleased()));
   613     }
   506     }
   614 
   507 
   615     CX_DEBUG_EXIT_FUNCTION();
   508     CX_DEBUG_EXIT_FUNCTION();
   616 }
   509 }
   617 
   510 
   640 
   533 
   641         // in standby mode, we are interested in focus gain events for dismissing standby
   534         // in standby mode, we are interested in focus gain events for dismissing standby
   642         connect(this, SIGNAL(focusGained()),  mStandbyHandler, SLOT(handleMouseEvent()), Qt::UniqueConnection);
   535         connect(this, SIGNAL(focusGained()),  mStandbyHandler, SLOT(handleMouseEvent()), Qt::UniqueConnection);
   643 
   536 
   644         // connecting key events to standby.
   537         // connecting key events to standby.
   645         connect(&mKeyHandler, SIGNAL(autofocusKeyPressed()),  mStandbyHandler, SLOT(stopTimer()), Qt::UniqueConnection);
   538         connect(mKeyHandler, SIGNAL(autofocusKeyPressed()),  mStandbyHandler, SLOT(stopTimer()), Qt::UniqueConnection);
   646         connect(&mKeyHandler, SIGNAL(autofocusKeyReleased()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
   539         connect(mKeyHandler, SIGNAL(autofocusKeyReleased()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
   647         connect(&mKeyHandler, SIGNAL(captureKeyPressed()),    mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
   540         connect(mKeyHandler, SIGNAL(captureKeyPressed()),    mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
   648         connect(&mKeyHandler, SIGNAL(captureKeyReleased()),   mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
   541         connect(mKeyHandler, SIGNAL(captureKeyReleased()),   mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
       
   542         connect(this, SIGNAL(disableStandbyTimer()), mStandbyHandler, SLOT(stopTimer()), Qt::UniqueConnection);
       
   543         connect(this, SIGNAL(startStandbyTimer()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
   649 
   544 
   650         // connecting pre-capture view signals to standby.
   545         // connecting pre-capture view signals to standby.
   651         connect(currentView, SIGNAL(startStandbyTimer()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
   546         connect(currentView, SIGNAL(startStandbyTimer()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
   652         connect(currentView, SIGNAL(changeToPrecaptureView()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
   547         connect(currentView, SIGNAL(changeToPrecaptureView()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
   653         connect(currentView, SIGNAL(stopStandbyTimer()), mStandbyHandler, SLOT(stopTimer()), Qt::UniqueConnection);
   548         connect(currentView, SIGNAL(stopStandbyTimer()), mStandbyHandler, SLOT(stopTimer()), Qt::UniqueConnection);
   654         connect(currentView, SIGNAL(changeToPostcaptureView()), mStandbyHandler, SLOT(stopTimer()), Qt::UniqueConnection);
   549         connect(currentView, SIGNAL(changeToPostcaptureView()), mStandbyHandler, SLOT(stopTimer()), Qt::UniqueConnection);
   655 
   550 
   656         // connecting precapture view signals to viewmanager slots
   551         // connecting precapture view signals to viewmanager slots
   657         connect(currentView, SIGNAL(changeToPostcaptureView()), this, SLOT(changeToPostcaptureView()), Qt::UniqueConnection);
   552         connect(currentView, SIGNAL(changeToPostcaptureView()), this, SLOT(changeToPostcaptureView()), Qt::UniqueConnection);
   658         connect(currentView, SIGNAL(changeToPrecaptureView()),  this, SLOT(changeToPrecaptureView()), Qt::UniqueConnection);
   553         connect(currentView, SIGNAL(changeToPrecaptureView()),  this, SLOT(changeToPrecaptureView()), Qt::UniqueConnection);
       
   554 
       
   555         //connecting scene modes signal
       
   556         connect(currentView, SIGNAL(showScenesView()), this, SLOT(showScenesView()), Qt::UniqueConnection);
       
   557 
   659         connect(currentView, SIGNAL(switchCamera()), this, SLOT(switchCamera()), Qt::UniqueConnection);
   558         connect(currentView, SIGNAL(switchCamera()), this, SLOT(switchCamera()), Qt::UniqueConnection);
   660 
   559 
   661         // connecting error signals from precapture view to errormanager.
   560         // connecting error signals from precapture view to errormanager.
   662         connect(currentView, SIGNAL(reportError(CxeError::Id)),   mErrorManager, SLOT(analyze(CxeError::Id)), Qt::UniqueConnection);
   561         connect(currentView, SIGNAL(reportError(CxeError::Id)),   mErrorManager, SLOT(analyze(CxeError::Id)), Qt::UniqueConnection);
   663     }
   562     }
   677 
   576 
   678     disconnectSignals();
   577     disconnectSignals();
   679     QObject *currentView = mMainWindow.currentView();
   578     QObject *currentView = mMainWindow.currentView();
   680     if (currentView == mPostcaptureView) {
   579     if (currentView == mPostcaptureView) {
   681         // connecting view manager focus events to pre-capture views
   580         // connecting view manager focus events to pre-capture views
       
   581         connect(this, SIGNAL(focusGained()),  currentView, SLOT(startTimers()), Qt::UniqueConnection);
   682         connect(this, SIGNAL(focusLost()),    currentView, SLOT(handleFocusLost()), Qt::UniqueConnection);
   582         connect(this, SIGNAL(focusLost()),    currentView, SLOT(handleFocusLost()), Qt::UniqueConnection);
   683         connect(currentView, SIGNAL(changeToPrecaptureView()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
   583         connect(currentView, SIGNAL(changeToPrecaptureView()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
   684 
   584 
   685         // connect necessary capturekey signals
   585         // connect necessary capturekey signals
   686         connectCaptureKeySignals();
   586         connectCaptureKeySignals();
   697 void CxuiViewManager::disconnectSignals()
   597 void CxuiViewManager::disconnectSignals()
   698 {
   598 {
   699     CX_DEBUG_ENTER_FUNCTION();
   599     CX_DEBUG_ENTER_FUNCTION();
   700 
   600 
   701     // Disconnect all existing capture key signals
   601     // Disconnect all existing capture key signals
   702     mKeyHandler.disconnect();
   602     mKeyHandler->disconnect();
   703 
   603 
   704     disconnect(SIGNAL(focusGained()));
   604     disconnect(SIGNAL(focusGained()));
   705     disconnect(SIGNAL(focusLost()));
   605     disconnect(SIGNAL(focusLost()));
   706     disconnect(SIGNAL(batteryEmpty()));
   606     disconnect(SIGNAL(batteryEmpty()));
   707 
   607 
   708     CX_DEBUG_EXIT_FUNCTION();
   608     CX_DEBUG_EXIT_FUNCTION();
   709 }
   609 }
   710 
   610 
       
   611 /*!
       
   612 * Raise application to foreground if it's currently (fully) in background.
       
   613 */
       
   614 void CxuiViewManager::toForeground()
       
   615 {
       
   616     CX_DEBUG_ENTER_FUNCTION();
       
   617 
       
   618     if (mApplicationMonitor
       
   619      && mApplicationMonitor->foregroundState() == CxuiApplicationFrameworkMonitor::ForegroundFullyLost) {
       
   620         // Bring to foreground and gain focus.
       
   621         CX_DEBUG(("CxuiViewManager - fully in background, bringing to foreground now."));
       
   622         mMainWindow.raise();
       
   623         mMainWindow.activateWindow();
       
   624     }
       
   625 
       
   626     CX_DEBUG_EXIT_FUNCTION();
       
   627 }
       
   628 
       
   629 /*!
       
   630 * Handle change in foreground state.
       
   631 */
       
   632 void CxuiViewManager::handleForegroundStateChanged(CxuiApplicationFrameworkMonitor::ForegroundState state)
       
   633 {
       
   634     switch (state) {
       
   635     case CxuiApplicationFrameworkMonitor::ForegroundPartiallyLost:
       
   636         break;
       
   637     case CxuiApplicationFrameworkMonitor::ForegroundFullyLost:
       
   638         aboutToLooseFocus();
       
   639         break;
       
   640     case CxuiApplicationFrameworkMonitor::ForegroundOwned:
       
   641         aboutToGainFocus();
       
   642         break;
       
   643     }
       
   644 }
   711 
   645 
   712 // ---------------------------------------------------------------------------
   646 // ---------------------------------------------------------------------------
   713 // CxuiViewManager::aboutToLooseFocus()
   647 // CxuiViewManager::aboutToLooseFocus()
   714 //
   648 //
   715 // ---------------------------------------------------------------------------
   649 // ---------------------------------------------------------------------------
   719     CX_DEBUG_ENTER_FUNCTION();
   653     CX_DEBUG_ENTER_FUNCTION();
   720 
   654 
   721     emit focusLost();
   655     emit focusLost();
   722     disconnectSignals();
   656     disconnectSignals();
   723 
   657 
       
   658     // We do not stop listening to capture key events even if we go to background,
       
   659     // as capture key brings us back to foreground.
       
   660     connect(mKeyHandler, SIGNAL(captureKeyPressed()), this, SLOT(toForeground()));
       
   661 
   724     CX_DEBUG_EXIT_FUNCTION();
   662     CX_DEBUG_EXIT_FUNCTION();
   725 }
   663 }
   726 
   664 
   727 
   665 
   728 // ---------------------------------------------------------------------------
   666 // ---------------------------------------------------------------------------
   731 // ---------------------------------------------------------------------------
   669 // ---------------------------------------------------------------------------
   732 //
   670 //
   733 void CxuiViewManager::aboutToGainFocus()
   671 void CxuiViewManager::aboutToGainFocus()
   734 {
   672 {
   735     CX_DEBUG_ENTER_FUNCTION();
   673     CX_DEBUG_ENTER_FUNCTION();
       
   674 
       
   675     // Disconnect capture key event and bringing us to foreground connection (if there is one).
       
   676     disconnect(mKeyHandler, SIGNAL(captureKeyPressed()), this, SLOT(toForeground()));
   736 
   677 
   737     // we are getting the focus.
   678     // we are getting the focus.
   738     if (mMainWindow.currentView() != mPostcaptureView) {
   679     if (mMainWindow.currentView() != mPostcaptureView) {
   739         connectPreCaptureSignals();
   680         connectPreCaptureSignals();
   740     } else {
   681     } else {
   741         connectPostCaptureSignals();
   682         connectPostCaptureSignals();
   742     }
   683     }
   743 
   684 
       
   685     if (mKeyHandler) {
       
   686         mKeyHandler->listenKeys(true);
       
   687     }
   744     emit focusGained();
   688     emit focusGained();
   745 
   689 
   746     CX_DEBUG_EXIT_FUNCTION();
   690     CX_DEBUG_EXIT_FUNCTION();
   747 }
   691 }
   748 
   692 
   749 
   693 /*!
   750 // ---------------------------------------------------------------------------
   694 * Handle battery emptying
   751 // CxuiViewManager::eventMonitor
   695 */
   752 //
   696 void CxuiViewManager::handleBatteryEmpty()
   753 // ---------------------------------------------------------------------------
   697 {
   754 //
   698     CX_DEBUG_ENTER_FUNCTION();
   755 void CxuiViewManager::eventMonitor( const XQSettingsKey& key, const QVariant& value )
   699     emit batteryEmpty();
   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();
   700     CX_DEBUG_EXIT_FUNCTION();
   807 }
   701 }
   808 
   702 
   809 // end of file
   703 // end of file