camerauis/cameraxui/cxui/src/cxuiviewmanager.cpp
changeset 37 64817133cd1d
parent 36 b12f3922a74f
child 42 feebad15db8c
child 48 42ba2d16bf40
equal deleted inserted replaced
36:b12f3922a74f 37:64817133cd1d
    18 #include <QTimer>
    18 #include <QTimer>
    19 #include <hbmainwindow.h>
    19 #include <hbmainwindow.h>
    20 #include <coemain.h>
    20 #include <coemain.h>
    21 #include <QGraphicsSceneEvent>
    21 #include <QGraphicsSceneEvent>
    22 #include <hbstyleloader.h>
    22 #include <hbstyleloader.h>
       
    23 #include <hbactivitymanager.h>
       
    24 #include <hbaction.h>
    23 
    25 
    24 #include "cxuiapplication.h"
    26 #include "cxuiapplication.h"
    25 #include "cxuiapplicationframeworkmonitor.h"
    27 #include "cxuiapplicationstate.h"
    26 #include "cxuiviewmanager.h"
    28 #include "cxuiviewmanager.h"
    27 #include "cxuivideoprecaptureview.h"
    29 #include "cxuivideoprecaptureview.h"
    28 #include "cxuistillprecaptureview.h"
    30 #include "cxuistillprecaptureview.h"
    29 #include "cxuipostcaptureview.h"
    31 #include "cxuipostcaptureview.h"
    30 #include "cxuicapturekeyhandler.h"
    32 #include "cxuicapturekeyhandler.h"
    34 #include "cxeviewfindercontrol.h"
    36 #include "cxeviewfindercontrol.h"
    35 #include "cxenamespace.h"
    37 #include "cxenamespace.h"
    36 #include "cxuienums.h"
    38 #include "cxuienums.h"
    37 #include "cxutils.h"
    39 #include "cxutils.h"
    38 #include "cxuidocumentloader.h"
    40 #include "cxuidocumentloader.h"
    39 #include "cxuistandby.h"
       
    40 #include "cxuierrormanager.h"
       
    41 #include "cxesettings.h"
    41 #include "cxesettings.h"
    42 #include "cxememorymonitor.h"
    42 #include "cxememorymonitor.h"
    43 #include "cxuiserviceprovider.h"
    43 #include "cxuiserviceprovider.h"
    44 #include "cxuiscenemodeview.h"
    44 #include "cxuiscenemodeview.h"
    45 
    45 
    50 
    50 
    51 
    51 
    52 using namespace Cxe;
    52 using namespace Cxe;
    53 using namespace CxUiLayout;
    53 using namespace CxUiLayout;
    54 
    54 
    55 
    55 namespace
    56 // ---------------------------------------------------------------------------
    56 {
    57 // CxuiViewManager::CxuiViewManager
    57     static const int CXUI_STANDBY_CAMERA_TIMEOUT = 60000; // 60 seconds
    58 //
    58 }
    59 // ---------------------------------------------------------------------------
    59 
    60 //
    60 
       
    61 /*!
       
    62 * Constructor.
       
    63 */
    61 CxuiViewManager::CxuiViewManager(CxuiApplication &application, HbMainWindow &mainWindow, CxeEngine &engine) :
    64 CxuiViewManager::CxuiViewManager(CxuiApplication &application, HbMainWindow &mainWindow, CxeEngine &engine) :
    62     mApplication(application),
    65     mApplication(application),
    63     mMainWindow(mainWindow),
    66     mMainWindow(mainWindow),
    64     mStillPrecaptureView(NULL),
       
    65     mVideoPrecaptureView(NULL),
       
    66     mPostcaptureView(NULL),
       
    67     mEngine(engine),
    67     mEngine(engine),
    68     mKeyHandler(NULL),
    68     mKeyHandler(NULL),
    69     mApplicationMonitor(NULL),
       
    70     mCameraDocumentLoader(NULL),
    69     mCameraDocumentLoader(NULL),
       
    70     mApplicationState(NULL),
       
    71     mErrorManager(NULL),
    71     mSceneModeView(NULL)
    72     mSceneModeView(NULL)
    72 {
    73 {
    73     CX_DEBUG_ENTER_FUNCTION();
    74     CX_DEBUG_ENTER_FUNCTION();
    74 
    75 
    75     // Application monitor
    76     // create mappings to map view name to correct docml file
    76     mApplicationMonitor = new CxuiApplicationFrameworkMonitor(mApplication, mEngine.settings());
    77     mDocmlFilesByView.insert(STILL_PRE_CAPTURE_VIEW, STILL_1ST_XML);
    77     connect(mApplicationMonitor, SIGNAL(foregroundStateChanged(CxuiApplicationFrameworkMonitor::ForegroundState)),
    78     mDocmlFilesByView.insert(VIDEO_PRE_CAPTURE_VIEW, VIDEO_1ST_XML);
    78             this, SLOT(handleForegroundStateChanged(CxuiApplicationFrameworkMonitor::ForegroundState)));
    79     mDocmlFilesByView.insert(POSTCAPTURE_VIEW, POSTCAPTURE_XML);
    79     connect(mApplicationMonitor, SIGNAL(batteryEmpty()), this, SLOT(handleBatteryEmpty()));
    80     mDocmlFilesByView.insert(STILL_SCENES_VIEW, SCENEMODE_SETTING_XML);
    80     connect(mApplicationMonitor, SIGNAL(usbMassMemoryModeToggled(bool)), this, SLOT(showUsbErrorPopup(bool)));
       
    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 
    81 
    86     // Key handler
    82     // Key handler
    87     mKeyHandler = new CxuiCaptureKeyHandler(mEngine);
    83     mKeyHandler = new CxuiCaptureKeyHandler(mEngine);
    88 
    84 
    89     mMainWindow.installEventFilter(this); // in order to filter capture and AF keys
    85     // Document loader
    90 
       
    91     OstTrace0( camerax_performance, CXUIVIEWMANAGER_CXUIVIEWMANAGER, "msg: e_CX_VIEWMANAGER_CREATE_DOCLOADER 1" );
    86     OstTrace0( camerax_performance, CXUIVIEWMANAGER_CXUIVIEWMANAGER, "msg: e_CX_VIEWMANAGER_CREATE_DOCLOADER 1" );
    92     mCameraDocumentLoader = new CxuiDocumentLoader(&engine);
    87     mCameraDocumentLoader = new CxuiDocumentLoader(&engine);
    93     OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_CXUIVIEWMANAGER, "msg: e_CX_VIEWMANAGER_CREATE_DOCLOADER 0" );
    88     OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_CXUIVIEWMANAGER, "msg: e_CX_VIEWMANAGER_CREATE_DOCLOADER 0" );
    94 
    89 
    95     // standby functionality and necessary signal connections
    90     // Application state
    96     mStandbyHandler = new CxuiStandby(*mKeyHandler, mCameraDocumentLoader, &mEngine);
    91     mApplicationState = new CxuiApplicationState(mApplication, mEngine.settings(), *mKeyHandler, mCameraDocumentLoader);
    97 
    92     CX_ASSERT_ALWAYS(mApplicationState);
    98     connect(mStandbyHandler, SIGNAL(aboutToEnterStandby()),this, SLOT(aboutToLooseFocus()));
    93     bool ok = connect(mApplicationState, SIGNAL(stateChanged(CxuiApplicationState::State, CxuiApplicationState::State)),
    99     connect(mStandbyHandler, SIGNAL(aboutToExitStandby()),this, SLOT(aboutToGainFocus()));
    94                       this, SLOT(handleApplicationStateChanged(CxuiApplicationState::State, CxuiApplicationState::State)));
   100 
    95     Q_ASSERT_X(ok, "CxuiViewManager", "Application state change signal connect failed.");
   101     // error manager, handling errors and notifying users based on their severity
    96     connect(this, SIGNAL(standbyExitRequested()), mApplicationState, SLOT(exitStandby()), Qt::QueuedConnection);
   102     mErrorManager = new CxuiErrorManager(*mKeyHandler, mCameraDocumentLoader);
    97 
   103 
    98     // Standby timer
   104     // connecting necessary signals from error manager to release and init camera.
    99     mStandbyTimer.setInterval(CXUI_STANDBY_CAMERA_TIMEOUT);
   105     connect(mErrorManager, SIGNAL(aboutToRecoverError()), this, SLOT(aboutToLooseFocus()));
   100     mStandbyTimer.setSingleShot(true);
   106     connect(mErrorManager, SIGNAL(errorRecovered()), this, SLOT(aboutToGainFocus()));
   101     connect(&mStandbyTimer, SIGNAL(timeout()), mApplicationState, SLOT(enterStandby()));
       
   102 
       
   103     // Filter capture and AF keys and follow user activity from mouse events.
       
   104     QCoreApplication::instance()->installEventFilter(this);
       
   105 
       
   106     // Monitor memory on normal state, not on standby, error or background.
       
   107     connect(this, SIGNAL(normalStateEntered()), &mEngine.memoryMonitor(), SLOT(startMonitoring()));
       
   108     connect(this, SIGNAL(normalStateExited()), &mEngine.memoryMonitor(), SLOT(stopMonitoring()));
   107 
   109 
   108     //connecting initmode signals
   110     //connecting initmode signals
   109     connect(&mEngine.cameraDeviceControl(), SIGNAL(initModeComplete(CxeError::Id)),
   111     connect(&mEngine.cameraDeviceControl(), SIGNAL(initModeComplete(CxeError::Id)),
   110             this, SLOT(createPostcaptureView()));
   112             mApplicationState, SLOT(handleApplicationError(CxeError::Id)));
   111 
       
   112     connect(&mEngine.cameraDeviceControl(), SIGNAL(initModeComplete(CxeError::Id)),
       
   113             mErrorManager, SLOT(showPopup(CxeError::Id)));
       
   114 
   113 
   115     connect(&mEngine.stillCaptureControl(), SIGNAL(imageCaptured(CxeError::Id, int)),
   114     connect(&mEngine.stillCaptureControl(), SIGNAL(imageCaptured(CxeError::Id, int)),
   116             mErrorManager, SLOT(showPopup(CxeError::Id)));
   115             mApplicationState, SLOT(handleApplicationError(CxeError::Id)));
   117 
   116 
   118     // Register stylesheet. It will be automatically destroyed on application
   117     // Register stylesheet. It will be automatically destroyed on application
   119     // exit.
   118     // exit.
   120     HbStyleLoader::registerFilePath(":/camerax/cxui.css");
   119     HbStyleLoader::registerFilePath(":/camerax/cxui.css");
   121 
   120 
   122     // Create the view we are starting in, or connect signals so it
   121     // Create the view we are starting in, or connect signals so it
   123     // will be created once we know the mode we are starting to.
   122     // will be created once we know the mode we are starting to.
   124     initStartupView();
   123     initStartupView();
   125 
   124 
   126     CX_DEBUG_EXIT_FUNCTION();
   125     // For UI startup testing, we need to emit applicationReady signal once UI is ready to be used.
   127 }
   126     connect(mMainWindow.currentView(), SIGNAL(viewReady()), &mApplication, SIGNAL(applicationReady()));
   128 
   127 
   129 // ---------------------------------------------------------------------------
   128     CX_DEBUG_EXIT_FUNCTION();
   130 // CxuiViewManager::~CxuiViewManager
   129 }
   131 //
   130 
   132 // ---------------------------------------------------------------------------
   131 
   133 //
   132 /*!
       
   133 * Destructor.
       
   134 */
   134 CxuiViewManager::~CxuiViewManager()
   135 CxuiViewManager::~CxuiViewManager()
   135 {
   136 {
   136     CX_DEBUG_ENTER_FUNCTION();
   137     CX_DEBUG_ENTER_FUNCTION();
   137 
   138     QCoreApplication::instance()->removeEventFilter(this);
       
   139 
       
   140     if (!CxuiServiceProvider::isCameraEmbedded()) {
       
   141         currentView()->saveActivity();
       
   142     }
       
   143 
       
   144     delete mApplicationState;
   138     delete mCameraDocumentLoader;
   145     delete mCameraDocumentLoader;
   139     delete mKeyHandler;
   146     delete mKeyHandler;
   140     delete mApplicationMonitor;
   147 
   141 
   148     CX_DEBUG_EXIT_FUNCTION();
       
   149 }
       
   150 
       
   151 
       
   152 
       
   153 /*!
       
   154 * Handle change in overall state of application.
       
   155 * @param newState The new application state.
       
   156 */
       
   157 void CxuiViewManager::handleApplicationStateChanged(CxuiApplicationState::State newState,
       
   158                                                     CxuiApplicationState::State oldState)
       
   159 {
       
   160     Q_UNUSED(oldState);
       
   161     CX_DEBUG_ENTER_FUNCTION();
       
   162 
       
   163     CxuiView *view = qobject_cast<CxuiView *>(mMainWindow.currentView());
       
   164     CX_DEBUG(("CxuiViewManager - current view %d", view));
       
   165 
       
   166     switch (newState) {
       
   167     case CxuiApplicationState::Normal:
       
   168         // Disable raising to foreground with capture key.
       
   169         disconnect(mKeyHandler, SIGNAL(captureKeyPressed()), this, SLOT(toForeground()));
       
   170 
       
   171         connectSignals(view);
       
   172 
       
   173         CX_DEBUG(("CxuiViewManager - emitting normalStateEntered"));
       
   174         emit normalStateEntered();
       
   175         break;
       
   176     case CxuiApplicationState::Standby:
       
   177          if (view && !view->isStandbyModeSupported()) {
       
   178             // If we move to Stanby, and current view does not
       
   179             // support standby mode, move to Normal mode right away.
       
   180             CX_DEBUG(("CxuiViewManager - view does not support stanbdy, exiting standby right away.."));
       
   181             mApplicationState->exitStandby();
       
   182         } else {
       
   183             handleExitingNormalState();
       
   184         }
       
   185         break;
       
   186     case CxuiApplicationState::Error:
       
   187     case CxuiApplicationState::Background:
       
   188         handleExitingNormalState();
       
   189 
       
   190         if (newState == CxuiApplicationState::Background) {
       
   191             // Moved to background.
       
   192             // Bring application back to foreground by capture key press
       
   193             connect(mKeyHandler, SIGNAL(captureKeyPressed()), this, SLOT(toForeground()));
       
   194         }
       
   195         break;
       
   196     }
       
   197 
       
   198     CX_DEBUG_EXIT_FUNCTION();
       
   199 }
       
   200 
       
   201 /*!
       
   202 * Helper method to handle (possible) exiting from normal state.
       
   203 * @param oldState The previous state.
       
   204 */
       
   205 void CxuiViewManager::handleExitingNormalState()
       
   206 {
       
   207     CX_DEBUG_ENTER_FUNCTION();
       
   208     // Store view that is active now.
       
   209     CxuiView *view = qobject_cast<CxuiView *>(mMainWindow.currentView());
       
   210     CX_DEBUG(("CxuiViewManager - current view %d", view));
       
   211 
       
   212     // Emit signal so current view can enter standby.
       
   213     emit normalStateExited();
       
   214     // Disconnect signals so we don't send key event's etc.
       
   215     // Using the view before normalStateExited() signal was emitted,
       
   216     // just in case it caused view switch.
       
   217     disconnectSignals(view);
       
   218     // Make sure standby timer is not running.
       
   219     stopStandbyTimer();
       
   220     CX_DEBUG_EXIT_FUNCTION();
       
   221 }
       
   222 
       
   223 /*!
       
   224 * Slot for starting standby timer.
       
   225 */
       
   226 void CxuiViewManager::startStandbyTimer()
       
   227 {
       
   228     CX_DEBUG_ENTER_FUNCTION();
       
   229     mStandbyTimer.start();
       
   230     CX_DEBUG_EXIT_FUNCTION();
       
   231 }
       
   232 
       
   233 /*!
       
   234 * Slot for stopping standby timer.
       
   235 */
       
   236 void CxuiViewManager::stopStandbyTimer()
       
   237 {
       
   238     CX_DEBUG_ENTER_FUNCTION();
       
   239     mStandbyTimer.stop();
   142     CX_DEBUG_EXIT_FUNCTION();
   240     CX_DEBUG_EXIT_FUNCTION();
   143 }
   241 }
   144 
   242 
   145 /**
   243 /**
   146 * Temporary method to check if camera startup should be proceeded after creating view mananger.
   244  * Init engine to correct mode based on activity being restored.
   147 */
   245  */
   148 bool CxuiViewManager::proceedStartup()
   246 void CxuiViewManager::initEngine()
   149 {
   247 {
   150     return !mStandbyHandler->isActive();
   248     Cxe::CameraMode mode = Cxe::ImageMode;
   151 }
   249     QString activityId = mApplication.activateId();
   152 
   250     if (activityId == CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY ||
   153 
   251         activityId == CxuiActivityIds::VIDEO_POSTCAPTURE_ACTIVITY) {
   154 // ---------------------------------------------------------------------------
   252         mode = Cxe::VideoMode;
   155 // CxuiViewManager::prepareWindow
   253     }
   156 //
   254     if (activityId == CxuiActivityIds::STILL_PRECAPTURE_ACTIVITY ||
   157 // ---------------------------------------------------------------------------
   255         activityId == CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY) {
   158 //
   256         // init engine only if going to pre-capture
   159 void CxuiViewManager::prepareWindow()
   257         mEngine.initMode(mode);
   160 {
   258     } else {
   161     getPrecaptureView(mEngine.mode(), mEngine.cameraDeviceControl().cameraIndex())->prepareWindow();
   259         // in post-capture don't init but set the correct mode to engine
   162 }
   260         // so init can be done later
   163 
   261         mEngine.setMode(mode);
   164 /*!
   262     }
   165 * Check if we need to take special actions in startup.
   263 }
   166 * USB mass memory mode atleast requires us to enter error standby mode,
   264 
   167 * where user can only exit or fix the issue (remove cable).
   265 /*!
   168 */
   266  * Helper function to return current view cast to CxuiView.
   169 void CxuiViewManager::startupCheck()
   267  */
   170 {
   268 CxuiView* CxuiViewManager::currentView() const
   171     CX_DEBUG_ENTER_FUNCTION();
   269 {
   172 
   270     CxuiView *view = qobject_cast<CxuiView*> (mMainWindow.currentView());
   173     if (mApplicationMonitor && mApplicationMonitor->isUsbMassMemoryModeActive()) {
   271     CX_ASSERT_ALWAYS(view);
   174         showUsbErrorPopup(true);
   272     return view;
   175     }
       
   176 
       
   177     CX_DEBUG_EXIT_FUNCTION();
       
   178 }
   273 }
   179 
   274 
   180 /*!
   275 /*!
   181 * Select and initialize the view we need to start into.
   276 * Select and initialize the view we need to start into.
   182 */
   277 */
   183 void CxuiViewManager::initStartupView()
   278 void CxuiViewManager::initStartupView()
   184 {
   279 {
   185     CX_DEBUG_ENTER_FUNCTION();
   280     CX_DEBUG_ENTER_FUNCTION();
   186 
   281 
   187     if (!CxuiServiceProvider::isCameraEmbedded()) {
   282     if (mApplication.activateReason() == Hb::ActivationReasonService) {
   188         // For embedded mode: don't create view yet, create
       
   189         // when engine inits to correct mode
       
   190         CX_DEBUG_ASSERT(mEngine.cameraDeviceControl().cameraIndex() == Cxe::PrimaryCameraIndex);
       
   191         if (mEngine.mode() == Cxe::VideoMode) {
       
   192             createVideoPrecaptureView();
       
   193             mMainWindow.blockSignals(true);
       
   194             mMainWindow.setCurrentView(mVideoPrecaptureView, false);
       
   195             mMainWindow.blockSignals(false);
       
   196         } else {
       
   197             createStillPrecaptureView();
       
   198             mMainWindow.blockSignals(true);
       
   199             mMainWindow.setCurrentView(mStillPrecaptureView, false);
       
   200             mMainWindow.blockSignals(false);
       
   201         }
       
   202         connectPreCaptureSignals();
       
   203 
       
   204         startupCheck();
       
   205     } else {
       
   206         // For embedded mode: don't create view yet, create when engine inits to correct mode.
   283         // For embedded mode: don't create view yet, create when engine inits to correct mode.
   207         // Connect signals to set up the view after image/video prepare
   284         // Connect signals to set up the view after image/video prepare
   208         connect(&mEngine.stillCaptureControl(), SIGNAL(imagePrepareComplete(CxeError::Id)),
   285         connect(&mEngine.stillCaptureControl(), SIGNAL(imagePrepareComplete(CxeError::Id)),
   209                 this, SLOT(changeToPrecaptureView()));
   286                 this, SLOT(changeToPrecaptureView()));
   210         connect(&mEngine.videoCaptureControl(), SIGNAL(videoPrepareComplete(CxeError::Id)),
   287         connect(&mEngine.videoCaptureControl(), SIGNAL(videoPrepareComplete(CxeError::Id)),
   211                 this, SLOT(changeToPrecaptureView()));
   288                 this, SLOT(changeToPrecaptureView()));
   212 
   289 
   213         // start standby timer now because view will not be ready when viewfinder is started
   290     } else if (mApplication.activateReason() == Hb::ActivationReasonActivity ) {
   214         mStandbyHandler->startTimer();
   291         // restoring activity, read startup view from stored activity
   215     }
   292 
   216 
   293         // view to start in
   217     CX_DEBUG_EXIT_FUNCTION();
   294         QString viewName = STILL_PRE_CAPTURE_VIEW;
   218 }
   295 
   219 
   296         bool preCapture = true;
   220 // ---------------------------------------------------------------------------
   297         QString activityId = mApplication.activateId();
   221 // CxuiViewManager::createStillPrecaptureView
   298         if (activityId == CxuiActivityIds::STILL_PRECAPTURE_ACTIVITY) {
   222 //
   299             viewName = STILL_PRE_CAPTURE_VIEW;
   223 // ---------------------------------------------------------------------------
   300         } else if (activityId == CxuiActivityIds::STILL_POSTCAPTURE_ACTIVITY) {
   224 //
   301             viewName = POSTCAPTURE_VIEW;
   225 void CxuiViewManager::createStillPrecaptureView()
   302             preCapture = false;
   226 {
   303         } else if (activityId == CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY) {
   227     CX_DEBUG_ENTER_FUNCTION();
   304             viewName = VIDEO_PRE_CAPTURE_VIEW;
   228     OstTrace0( camerax_performance, CXUIVIEWMANAGER_CREATESTILLPRECAPTUREVIEW, "msg: e_CX_CREATE_STILLPRECAPTUREVIEW 1" );
   305         } else if (activityId == CxuiActivityIds::VIDEO_POSTCAPTURE_ACTIVITY) {
   229 
   306             viewName = POSTCAPTURE_VIEW;
   230     // Use document loader to create widgets and layouts
   307             preCapture = false;
   231     // (non-sectioned parts are parsed and loaded)
   308         }
   232     OstTrace0( camerax_performance, DUP2_CXUIVIEWMANAGER_ADDPRECAPTUREVIEWS, "msg: e_CX_DOCLOADER_LOAD 1" );
   309 
   233 
   310         CxuiView *view = createView(viewName);
   234     bool ok = false;
   311         mMainWindow.setCurrentView(view, false);
   235     CX_DEBUG_ASSERT(mCameraDocumentLoader);
   312 
   236     mCameraDocumentLoader->load(STILL_1ST_XML, &ok);
   313         if (preCapture) {
   237     Q_ASSERT_X(ok, "createStillPrecaptureView", "error in xml file parsing");
   314             connectPreCaptureSignals();
   238 
   315         } else {
   239     OstTrace0( camerax_performance, DUP2_CXUIVIEWMANAGER_CREATESTILLPRECAPTUREVIEW, "msg: e_CX_DOCLOADER_LOAD 0" );
   316             connectPostCaptureSignals();
   240 
   317         }
   241     OstTrace0( camerax_performance, DUP4_CXUIVIEWMANAGER_ADDPRECAPTUREVIEWS, "msg: e_CX_DOCLOADER_FINDWIDGET 1" );
   318 
   242     QGraphicsWidget *widget = NULL;
   319         // Check the current application state, signalled to handleApplicationStateChanged.
   243     // ask for the still precapture view widget pointer
   320         mApplicationState->startMonitoring();
   244     widget = mCameraDocumentLoader->findWidget(STILL_PRE_CAPTURE_VIEW);
   321 
   245     mStillPrecaptureView = qobject_cast<CxuiStillPrecaptureView *> (widget);
   322         // restore view from activity
   246     CX_DEBUG_ASSERT(mStillPrecaptureView);
   323         bool ok = mApplication.activityManager()->waitActivity();
   247     OstTrace0( camerax_performance, DUP5_CXUIVIEWMANAGER_ADDPRECAPTUREVIEWS, "msg: e_CX_DOCLOADER_FINDWIDGET 0" );
   324 
   248 
   325         view->restoreActivity(activityId,
   249     // call for needed consturction methods
   326                               mApplication.activityManager()->activityData(mApplication.activateId()));
   250     mStillPrecaptureView->construct(&mMainWindow, &mEngine, mCameraDocumentLoader, mKeyHandler);
   327 
   251     // .. and add to main window (which also takes ownership)
   328         clearAllActivities();
   252     OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_MAINWINDOW_ADDVIEW, "msg: e_CX_MAINWINDOW_ADDVIEW 1" );
   329     } else {
   253     mMainWindow.addView(widget);
   330         // normal start
   254     OstTrace0( camerax_performance, DUP2_CXUIVIEWMANAGER_MAINWINDOW_ADDVIEW, "msg: e_CX_MAINWINDOW_ADDVIEW 0" );
   331         // no activity id, get default view from engine state
   255 
   332         CxuiView *view = NULL;
   256     OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_CREATESTILLPRECAPTUREVIEW, "msg: e_CX_CREATE_STILLPRECAPTUREVIEW 0" );
   333         if (mEngine.mode() == Cxe::VideoMode) {
   257 
   334             view = createView(VIDEO_PRE_CAPTURE_VIEW);
   258     CX_DEBUG_EXIT_FUNCTION();
   335         } else {
   259 }
   336             view = createView(STILL_PRE_CAPTURE_VIEW);
   260 
   337         }
   261 // ---------------------------------------------------------------------------
   338 
   262 // CxuiViewManager::createStillScenesView
   339         mMainWindow.setCurrentView(view, false);
   263 //
   340         connectPreCaptureSignals();
   264 // ---------------------------------------------------------------------------
   341 
   265 //
   342         // Check the current application state, signalled to handleApplicationStateChanged.
   266 void CxuiViewManager::createSceneModesView()
   343         mApplicationState->startMonitoring();
   267 {
   344 
   268     CX_DEBUG_ENTER_FUNCTION();
   345         clearAllActivities();
   269 
   346     }
   270     bool ok = false;
   347 
   271     CX_DEBUG_ASSERT(mCameraDocumentLoader);
   348     CX_DEBUG_EXIT_FUNCTION();
   272     CxuiDocumentLoader *documentLoader = new CxuiDocumentLoader(&mEngine);
   349 }
   273     // Use document loader to create widgets and layouts
   350 
   274     // (non-sectioned parts are parsed and loaded)
   351 /*!
   275     documentLoader->load(SCENEMODE_SETTING_XML, &ok);
   352 * Create view and add it to main window.
   276 
   353 */
   277     QGraphicsWidget *widget = NULL;
   354 CxuiView* CxuiViewManager::createView(const QString &viewName)
   278 
   355 {
   279     // ask for the scenes mode view widget pointer
   356     CX_DEBUG_ENTER_FUNCTION();
   280     widget = documentLoader->findWidget(STILL_SCENES_VIEW);
   357 
   281     Q_ASSERT_X(ok && (widget != 0), "camerax ui", "invalid xml file");
   358     OstTrace0( camerax_performance, CXUIVIEWMANAGER_CREATEVIEW, "msg: e_CX_CREATE_VIEW 1" );
   282     mSceneModeView = qobject_cast<CxuiSceneModeView *> (widget);
   359 
   283 
   360     CX_DEBUG(("View name: %s", viewName.toAscii().data()));
   284     // call for needed construction methods
   361 
   285     mSceneModeView->construct(&mMainWindow, &mEngine, documentLoader, mKeyHandler);
   362     CxuiView* view = mViews[viewName];
   286     // .. and add to main window (which also takes ownership)
   363     if (view == NULL) {
   287     mMainWindow.addView(widget);
   364         CX_DEBUG(("View not loaded yet, loading now"));
       
   365         bool ok = false;
       
   366         // Use document loader to create widgets and layouts
       
   367         // (non-sectioned parts are parsed and loaded)
       
   368         QString docmlFile = mDocmlFilesByView[viewName];
       
   369         CX_DEBUG_ASSERT(mCameraDocumentLoader);
       
   370         CX_ASSERT_ALWAYS(!docmlFile.isNull());
       
   371 
       
   372         OstTrace0( camerax_performance, DUP2_CXUIVIEWMANAGER_ADDPRECAPTUREVIEWS, "msg: e_CX_DOCLOADER_LOAD 1" );
       
   373 
       
   374         mCameraDocumentLoader->load(docmlFile, &ok);
       
   375 
       
   376         Q_ASSERT_X(ok, "createView", "error in xml file parsing");
       
   377 
       
   378         OstTrace0( camerax_performance, DUP2_CXUIVIEWMANAGER_CREATEVIEW, "msg: e_CX_DOCLOADER_LOAD 0" );
       
   379 
       
   380         OstTrace0( camerax_performance, DUP4_CXUIVIEWMANAGER_ADDVIEWS, "msg: e_CX_DOCLOADER_FINDWIDGET 1" );
       
   381         QGraphicsWidget *widget = NULL;
       
   382         // ask for the view widget pointer
       
   383         widget = mCameraDocumentLoader->findWidget(viewName);
       
   384         view = qobject_cast<CxuiView *> (widget);
       
   385         CX_DEBUG_ASSERT(view);
       
   386         OstTrace0( camerax_performance, DUP5_CXUIVIEWMANAGER_ADDVIEWS, "msg: e_CX_DOCLOADER_FINDWIDGET 0" );
       
   387 
       
   388         // call for needed consturction methods
       
   389         view->construct(&mMainWindow, &mEngine, mCameraDocumentLoader, mKeyHandler, mApplication.activityManager());
       
   390         // .. and add to main window (which also takes ownership)
       
   391         OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_MAINWINDOW_ADDVIEW, "msg: e_CX_MAINWINDOW_ADDVIEW 1" );
       
   392         mMainWindow.addView(view);
       
   393         mViews.insert(viewName, view);
       
   394 
       
   395         OstTrace0( camerax_performance, DUP2_CXUIVIEWMANAGER_MAINWINDOW_ADDVIEW, "msg: e_CX_MAINWINDOW_ADDVIEW 0" );
       
   396         OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_CREATEVIEW, "msg: e_CX_CREATE_STILLPRECAPTUREVIEW 0" );
       
   397 
       
   398     }
       
   399 
       
   400     CX_DEBUG_EXIT_FUNCTION();
       
   401     return view;
       
   402 }
       
   403 
       
   404 /*!
       
   405 * Create scene mode view.
       
   406 */
       
   407 CxuiView* CxuiViewManager::createSceneModesView()
       
   408 {
       
   409     CX_DEBUG_ENTER_FUNCTION();
       
   410 
       
   411     mSceneModeView = qobject_cast<CxuiSceneModeView*>(createView(STILL_SCENES_VIEW));
   288     mSceneModeView->loadBackgroundImages();
   412     mSceneModeView->loadBackgroundImages();
   289 
   413 
   290     connect(mSceneModeView, SIGNAL(viewCloseEvent()), this, SLOT(changeToPrecaptureView()));
   414     CX_DEBUG_EXIT_FUNCTION();
   291     delete documentLoader;
   415     return mSceneModeView;
   292     CX_DEBUG_EXIT_FUNCTION();
       
   293 }
   416 }
   294 
   417 
   295 /*!
   418 /*!
   296 * CxuiViewManager::showScenesView
   419 * CxuiViewManager::showScenesView
   297 * A private method for displaying Scene Modes selection view
   420 * A private method for displaying Scene Modes selection view
   298 */
   421 */
   299 void CxuiViewManager::showScenesView()
   422 void CxuiViewManager::showScenesView()
   300 {
   423 {
   301     CX_DEBUG_ENTER_FUNCTION();
   424     CX_DEBUG_ENTER_FUNCTION();
       
   425     // Disconnect signals from old view.
       
   426     disconnectSignals();
       
   427 
   302     if (!mSceneModeView) {
   428     if (!mSceneModeView) {
   303         createSceneModesView();
   429         createSceneModesView();
   304     }
   430     }
   305     else {
   431     else {
   306         mSceneModeView->loadBackgroundImages();
   432         mSceneModeView->loadBackgroundImages();
   307     }
   433     }
   308     CX_DEBUG_ASSERT(mSceneModeView);
   434     CX_DEBUG_ASSERT(mSceneModeView);
   309     mMainWindow.blockSignals(true);
       
   310     mMainWindow.setCurrentView(mSceneModeView, false);
   435     mMainWindow.setCurrentView(mSceneModeView, false);
   311     emit disableStandbyTimer();
   436     stopStandbyTimer();
   312     connectCaptureKeySignals();
   437     connectSceneModeSignals();
   313     mMainWindow.blockSignals(false);
   438 
   314     CX_DEBUG_EXIT_FUNCTION();
   439     CX_DEBUG_EXIT_FUNCTION();
   315 }
   440 }
   316 
   441 
   317 
   442 /*!
   318 // ---------------------------------------------------------------------------
   443 * Get the precapture view appropriate for given camera mode and index.
   319 // CxuiViewManager::createVideoPrecaptureView
   444 * If the view does not exist, it is created.
   320 //
   445 * @param mode Which camera mode the view should match.
   321 // ---------------------------------------------------------------------------
   446 * @param index Which camera index the view should match.
   322 //
   447 */
   323 void CxuiViewManager::createVideoPrecaptureView()
       
   324 {
       
   325     CX_DEBUG_ENTER_FUNCTION();
       
   326     OstTrace0( camerax_performance, CXUIVIEWMANAGER_CREATEVIDEOPRECAPTUREVIEW, "msg: e_CX_CREATE_VIDEOPRECAPTUREVIEW 1" );
       
   327 
       
   328     CX_DEBUG_ASSERT(mCameraDocumentLoader);
       
   329 
       
   330     bool ok = false;
       
   331     // load and create the default widgets in video xml
       
   332     mCameraDocumentLoader->load(VIDEO_1ST_XML, &ok);
       
   333     CX_DEBUG_ASSERT(ok);
       
   334 
       
   335     // get pointer to videoprecaptureview and do some initialisation
       
   336     QGraphicsWidget *widget = NULL;
       
   337     widget = mCameraDocumentLoader->findWidget(VIDEO_PRE_CAPTURE_VIEW);
       
   338     mVideoPrecaptureView = qobject_cast<CxuiVideoPrecaptureView *> (widget);
       
   339     CX_DEBUG_ASSERT(mVideoPrecaptureView);
       
   340     mVideoPrecaptureView->construct(&mMainWindow, &mEngine, mCameraDocumentLoader, mKeyHandler);
       
   341 
       
   342     // add view to main window
       
   343     OstTrace0( camerax_performance, DUP3_CXUIVIEWMANAGER_MAINWINDOW_ADDVIEW, "msg: e_CX_MAINWINDOW_ADDVIEW 1" );
       
   344     mMainWindow.addView(mVideoPrecaptureView);
       
   345     OstTrace0( camerax_performance, DUP4_CXUIVIEWMANAGER_MAINWINDOW_ADDVIEW, "msg: e_CX_MAINWINDOW_ADDVIEW 0" );
       
   346     OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_CREATEVIDEOPRECAPTUREVIEW, "msg: e_CX_CREATE_VIDEOPRECAPTUREVIEW 0" );
       
   347 
       
   348     CX_DEBUG_EXIT_FUNCTION();
       
   349 }
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // CxuiViewManager::createStillPostcaptureView
       
   353 //
       
   354 // ---------------------------------------------------------------------------
       
   355 //
       
   356 void CxuiViewManager::createPostcaptureView()
       
   357 {
       
   358     CX_DEBUG_ENTER_FUNCTION();
       
   359     CX_DEBUG_ASSERT(mCameraDocumentLoader);
       
   360     OstTrace0( camerax_performance, CXUIVIEWMANAGER_CREATESTILLPOSTCAPTUREVIEW, "msg: e_CX_CREATE_STILLPOSTCAPTUREVIEW 1" );
       
   361 
       
   362     if (!mPostcaptureView) {
       
   363         bool ok = false;
       
   364         mCameraDocumentLoader->load(POSTCAPTURE_XML, &ok);
       
   365         CX_DEBUG_ASSERT(ok);
       
   366 
       
   367         // get pointer to videoprecaptureview and do some initialisation
       
   368         QGraphicsWidget *widget = NULL;
       
   369         widget = mCameraDocumentLoader->findWidget(POSTCAPTURE_VIEW);
       
   370         mPostcaptureView = qobject_cast<CxuiPostcaptureView *> (widget);
       
   371         CX_DEBUG_ASSERT(mPostcaptureView);
       
   372         mPostcaptureView->construct(&mMainWindow, &mEngine, mCameraDocumentLoader);
       
   373 
       
   374         mMainWindow.addView(mPostcaptureView);
       
   375         connect(mPostcaptureView, SIGNAL(changeToPrecaptureView()), this, SLOT(changeToPrecaptureView()));
       
   376 
       
   377     }
       
   378 
       
   379     OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_CREATESTILLPOSTCAPTUREVIEW, "msg: e_CX_CREATE_STILLPOSTCAPTUREVIEW 0" );
       
   380     CX_DEBUG_EXIT_FUNCTION();
       
   381 }
       
   382 
       
   383 // ---------------------------------------------------------------------------
       
   384 // CxuiViewManager::getPrecaptureView
       
   385 //
       
   386 // ---------------------------------------------------------------------------
       
   387 //
       
   388 CxuiPrecaptureView*
   448 CxuiPrecaptureView*
   389 CxuiViewManager::getPrecaptureView(Cxe::CameraMode mode, Cxe::CameraIndex camera)
   449 CxuiViewManager::getPrecaptureView(Cxe::CameraMode mode, Cxe::CameraIndex camera)
   390 {
   450 {
   391     CX_DEBUG_ENTER_FUNCTION();
   451     CX_DEBUG_ENTER_FUNCTION();
   392     CX_DEBUG(("CxuiViewManager::getPrecaptureView() mode=%d, camera index=%d", mode, camera));
   452     CX_DEBUG(("CxuiViewManager::getPrecaptureView - mode=%d, camera index=%d", mode, camera));
   393 
   453 
   394     CX_DEBUG_ASSERT(camera == Cxe::PrimaryCameraIndex);
   454     CX_DEBUG_ASSERT(camera == Cxe::PrimaryCameraIndex);
   395 
   455 
   396     if (mode == ImageMode) {
   456     if (mode == ImageMode) {
   397         CX_DEBUG(("CxuiViewManager::getPrecaptureView() image mode"));
   457         CX_DEBUG(("CxuiViewManager::getPrecaptureView - image mode"));
   398         if(!mStillPrecaptureView) {
   458         return qobject_cast<CxuiPrecaptureView*>(createView(STILL_PRE_CAPTURE_VIEW));
   399             createStillPrecaptureView();
   459 
   400         }
       
   401         return mStillPrecaptureView;
       
   402     } else {
   460     } else {
   403         CX_DEBUG(("CxuiViewManager::getPrecaptureView() video mode"));
   461         CX_DEBUG(("CxuiViewManager::getPrecaptureView - video mode"));
   404         if(!mVideoPrecaptureView) {
   462         return qobject_cast<CxuiPrecaptureView*>(createView(VIDEO_PRE_CAPTURE_VIEW));
   405             createVideoPrecaptureView();
   463     }
   406         }
   464 }
   407         return mVideoPrecaptureView;
   465 
   408     }
   466 /*!
   409 }
   467 * Get a pointer to the document loader instance.
   410 
   468 */
   411 CxuiDocumentLoader* CxuiViewManager::documentLoader()
   469 CxuiDocumentLoader *CxuiViewManager::documentLoader()
   412 {
   470 {
   413     return mCameraDocumentLoader;
   471     return mCameraDocumentLoader;
   414 }
   472 }
   415 
   473 
   416 // ---------------------------------------------------------------------------
   474 /*!
   417 // CxuiViewManager::changeToPostcaptureView
   475 * Get reference to application state instance.
   418 //
   476 */
   419 // ---------------------------------------------------------------------------
   477 CxuiApplicationState &CxuiViewManager::applicationState()
   420 //
   478 {
       
   479     return *mApplicationState;
       
   480 }
       
   481 
       
   482 
       
   483 /*!
       
   484 * Move to post-capture view.
       
   485 */
   421 void CxuiViewManager::changeToPostcaptureView()
   486 void CxuiViewManager::changeToPostcaptureView()
   422 {
   487 {
   423     CX_DEBUG_ENTER_FUNCTION();
   488     CX_DEBUG_ENTER_FUNCTION();
   424 
   489     // Disconnect signals from old view.
   425     if (!mPostcaptureView) {
   490     disconnectSignals();
   426         createPostcaptureView();
   491 
   427     }
   492     CxuiView *postCaptureView = createView(POSTCAPTURE_VIEW);
   428 
   493 
   429     mMainWindow.blockSignals(true);
   494     mMainWindow.setCurrentView(postCaptureView, false);
   430     mMainWindow.setCurrentView(mPostcaptureView, false);
   495 
   431     mMainWindow.blockSignals(false);
   496     // Connecting all necessary signals for postcapture view.
   432 
   497     // Not connected yet if not in normal state. We connect the signals
   433     // connecting all necessary signals for postcapture view
   498     // once we enter normal state again.
   434     connectPostCaptureSignals();
   499     if (mApplicationState->currentState() == CxuiApplicationState::Normal) {
   435 
   500         connectPostCaptureSignals();
   436     CX_DEBUG_EXIT_FUNCTION();
   501     }
   437 }
   502 
   438 
   503     CX_DEBUG_EXIT_FUNCTION();
   439 // ---------------------------------------------------------------------------
   504 }
   440 // CxuiViewManager::changeToPrecaptureView
   505 
   441 //
   506 /*!
   442 // ---------------------------------------------------------------------------
   507 * Move to pre-capture view.
   443 //
   508 */
   444 void CxuiViewManager::changeToPrecaptureView()
   509 void CxuiViewManager::changeToPrecaptureView()
   445 {
   510 {
   446     CX_DEBUG_ENTER_FUNCTION();
   511     CX_DEBUG_ENTER_FUNCTION();
   447 
   512 
   448     if (CxuiServiceProvider::isCameraEmbedded()) {
   513     if (CxuiServiceProvider::isCameraEmbedded()) {
   451                 this, SLOT(changeToPrecaptureView()));
   516                 this, SLOT(changeToPrecaptureView()));
   452         disconnect(&mEngine.videoCaptureControl(), SIGNAL(videoPrepareComplete(CxeError::Id)),
   517         disconnect(&mEngine.videoCaptureControl(), SIGNAL(videoPrepareComplete(CxeError::Id)),
   453                 this, SLOT(changeToPrecaptureView()));
   518                 this, SLOT(changeToPrecaptureView()));
   454     }
   519     }
   455 
   520 
   456     // If standby mode is active, don't switch to precapture view and reserve camera now.
   521     // If normal mode is not active, don't switch to precapture view and reserve camera now.
   457     if (mStandbyHandler->isActive()) {
   522     if (mApplicationState->currentState() != CxuiApplicationState::Normal) {
   458         CX_DEBUG(("CxuiViewManager - Change to precapture blocked as standby mode still active."));
   523         CX_DEBUG(("CxuiViewManager - Change to precapture blocked as not normal mode (error, standby, background)."));
   459     } else {
   524     } else {
       
   525 
       
   526         // Disconnect signals from old view.
       
   527         disconnectSignals();
       
   528 
   460         HbView *view = getPrecaptureView(mEngine.mode(),
   529         HbView *view = getPrecaptureView(mEngine.mode(),
   461             mEngine.cameraDeviceControl().cameraIndex());
   530             mEngine.cameraDeviceControl().cameraIndex());
   462 
       
   463         mMainWindow.blockSignals(true);
       
   464         mMainWindow.setCurrentView(view, false);
   531         mMainWindow.setCurrentView(view, false);
   465         mMainWindow.blockSignals(false);
       
   466 
   532 
   467         if (mSceneModeView){
   533         if (mSceneModeView){
       
   534             mViews.remove(STILL_SCENES_VIEW);
   468             delete mSceneModeView;
   535             delete mSceneModeView;
   469             mSceneModeView = NULL;
   536             mSceneModeView = NULL;
   470         }
   537         }
   471         // connecting necessary pre-capture view signals
   538         // connecting necessary pre-capture view signals
   472         connectPreCaptureSignals();
   539         connectPreCaptureSignals();
   473         emit startStandbyTimer();
   540 
   474     }
   541         // Make sure engine prepares for new image/video if necessary
   475     CX_DEBUG_EXIT_FUNCTION();
   542         mEngine.initMode(mEngine.mode());
   476 }
   543 
   477 
   544         startStandbyTimer();
   478 // ---------------------------------------------------------------------------
   545 
   479 // CxuiViewManager::switchCamera
   546     }
   480 //
   547     CX_DEBUG_EXIT_FUNCTION();
   481 // ---------------------------------------------------------------------------
   548 }
   482 //
   549 
       
   550 /*!
       
   551 * Switch between cameras.
       
   552 */
   483 void CxuiViewManager::switchCamera()
   553 void CxuiViewManager::switchCamera()
   484 {
   554 {
   485     CX_DEBUG_ENTER_FUNCTION();
   555     CX_DEBUG_ENTER_FUNCTION();
   486 
   556 
   487     Cxe::CameraIndex nextCamera;
   557     Cxe::CameraIndex nextCamera;
   494         nextCamera = Cxe::PrimaryCameraIndex;
   564         nextCamera = Cxe::PrimaryCameraIndex;
   495         nextViewOrientation = Qt::Horizontal;
   565         nextViewOrientation = Qt::Horizontal;
   496     }
   566     }
   497 
   567 
   498     CxuiPrecaptureView* view = getPrecaptureView(mEngine.mode(), nextCamera);
   568     CxuiPrecaptureView* view = getPrecaptureView(mEngine.mode(), nextCamera);
   499 
       
   500     mMainWindow.blockSignals(true);
       
   501     mMainWindow.setCurrentView(view, false);
   569     mMainWindow.setCurrentView(view, false);
   502     mMainWindow.blockSignals(false);
       
   503     view->updateOrientation(nextViewOrientation);
   570     view->updateOrientation(nextViewOrientation);
   504     view->prepareWindow();
       
   505 
   571 
   506     connectPreCaptureSignals();
   572     connectPreCaptureSignals();
   507 
   573 
   508     mEngine.cameraDeviceControl().switchCamera(nextCamera);
   574     mEngine.cameraDeviceControl().switchCamera(nextCamera);
   509 
   575 
   510     CX_DEBUG_EXIT_FUNCTION();
   576     CX_DEBUG_EXIT_FUNCTION();
   511 }
   577 }
   512 
   578 
   513 // ---------------------------------------------------------------------------
   579 /*!
   514 // CxuiViewManager::eventFilter
   580 * Event filter function.
   515 //
   581 * Used to get mouse and key events for standby and capture key handling.
   516 // ---------------------------------------------------------------------------
   582 * @param object Target object.
   517 //
   583 * @param event Event to be checked.
       
   584 */
   518 bool CxuiViewManager::eventFilter(QObject *object, QEvent *event)
   585 bool CxuiViewManager::eventFilter(QObject *object, QEvent *event)
   519 {
   586 {
   520     Q_UNUSED(object)
   587     Q_UNUSED(object)
   521 
   588 
   522     bool eventWasConsumed = false;
   589     bool eventWasConsumed = false;
   523 
   590     bool userActivity = false;
   524     switch (event->type())
   591 
   525     {
   592     switch (event->type()) {
   526     case QEvent::KeyPress:
   593     case QEvent::KeyPress:
   527     case QEvent::KeyRelease:
   594     case QEvent::KeyRelease:
       
   595         userActivity = true;
   528         eventWasConsumed = mKeyHandler->handleKeyEvent(event);
   596         eventWasConsumed = mKeyHandler->handleKeyEvent(event);
       
   597         if (eventWasConsumed && mApplicationState->currentState() == CxuiApplicationState::Standby) {
       
   598             // Queued exit from standby.
       
   599             emit standbyExitRequested();
       
   600         }
   529         break;
   601         break;
   530     }
   602 
       
   603     case QEvent::GraphicsSceneMouseMove:
       
   604     case QEvent::GraphicsSceneMousePress:
       
   605         userActivity = true;
       
   606         break;
       
   607     case QEvent::GraphicsSceneMouseRelease:
       
   608         userActivity = true;
       
   609         if (mApplicationState->currentState() == CxuiApplicationState::Standby) {
       
   610             // Queued exit from standby.
       
   611             // Standby popup in view can receive mouse event before it is dismissed.
       
   612             emit standbyExitRequested();
       
   613         }
       
   614         break;
       
   615     }
       
   616 
       
   617     // Restart standby timer if there is user activity.
       
   618     // Only restart the timer if it is running, do not set it running here.
       
   619     if (userActivity && mStandbyTimer.isActive()) {
       
   620         startStandbyTimer();
       
   621     }
       
   622 
   531     // No need to call base class implementation, because we derive from QObject directly.
   623     // No need to call base class implementation, because we derive from QObject directly.
   532     // QObject::eventFilter() implementation always returns false.
   624     // QObject::eventFilter() implementation always returns false.
   533     return eventWasConsumed;
   625     return eventWasConsumed;
   534 }
   626 }
   535 
   627 
   536 // ---------------------------------------------------------------------------
   628 /*!
   537 // CxuiViewManager::connectCaptureKeySignals
   629 * Connect signals specific to given view.
   538 //
   630 */
   539 // ---------------------------------------------------------------------------
   631 void CxuiViewManager::connectSignals(QObject *view)
   540 //
   632 {
       
   633     CX_DEBUG_ENTER_FUNCTION();
       
   634     if (view) {
       
   635         if (view == mViews[POSTCAPTURE_VIEW]) {
       
   636             connectPostCaptureSignals();
       
   637         } else if (view == mSceneModeView) {
       
   638             connectSceneModeSignals();
       
   639         } else {
       
   640             connectPreCaptureSignals();
       
   641         }
       
   642     }
       
   643     CX_DEBUG_EXIT_FUNCTION();
       
   644 }
       
   645 
       
   646 /*!
       
   647 * Disconnect signals.
       
   648 * We don't want to send or receive signals with inactive views, so this is done every time changing a view.
       
   649 * @param view View object from which signals are disconnected. If NULL is given, current view is used.
       
   650 */
       
   651 void CxuiViewManager::disconnectSignals(QObject *view)
       
   652 {
       
   653     CX_DEBUG_ENTER_FUNCTION();
       
   654 
       
   655     // Disconnect all existing capture key signals
       
   656     mKeyHandler->disconnect();
       
   657 
       
   658     if (!view) {
       
   659         // If view is not given, take current view.
       
   660         view = mMainWindow.currentView();
       
   661     }
       
   662 
       
   663     CX_DEBUG(("CxuiViewManager - disconnecting from view %d", view));
       
   664     if (view) {
       
   665         // Disconnect all signals from current view to us.
       
   666         disconnect(view, 0, this, 0);
       
   667         // Disconnect all signals from us to current view.
       
   668         disconnect(this, 0, view, 0);
       
   669     }
       
   670 
       
   671     CX_DEBUG_EXIT_FUNCTION();
       
   672 }
       
   673 
       
   674 /*!
       
   675 * Connect signals to pre-capture view.
       
   676 */
       
   677 void CxuiViewManager::connectPreCaptureSignals()
       
   678 {
       
   679     CX_DEBUG_ENTER_FUNCTION();
       
   680 
       
   681     disconnectSignals();
       
   682 
       
   683     HbView *currentView = mMainWindow.currentView();
       
   684 
       
   685     if (currentView != mViews[POSTCAPTURE_VIEW]) {
       
   686         // connects all capture key signals.
       
   687         connectCaptureKeySignals();
       
   688 
       
   689         // connecting pre-capture view signals to standby timer.
       
   690         connect(currentView, SIGNAL(startStandbyTimer()),       this, SLOT(startStandbyTimer()), Qt::UniqueConnection);
       
   691         connect(currentView, SIGNAL(stopStandbyTimer()),        this, SLOT(stopStandbyTimer()),  Qt::UniqueConnection);
       
   692         connect(currentView, SIGNAL(changeToPrecaptureView()),  this, SLOT(startStandbyTimer()), Qt::UniqueConnection);
       
   693         connect(currentView, SIGNAL(changeToPostcaptureView()), this, SLOT(stopStandbyTimer()),  Qt::UniqueConnection);
       
   694 
       
   695         // connecting pre-capture view signals to viewmanager slots
       
   696         connect(currentView, SIGNAL(changeToPostcaptureView()), this, SLOT(changeToPostcaptureView()), Qt::UniqueConnection);
       
   697         connect(currentView, SIGNAL(changeToPrecaptureView()),  this, SLOT(changeToPrecaptureView()),  Qt::UniqueConnection);
       
   698 
       
   699         //connecting scene modes signal
       
   700         connect(currentView, SIGNAL(showScenesView()), this, SLOT(showScenesView()), Qt::UniqueConnection);
       
   701 
       
   702         connect(currentView, SIGNAL(switchCamera()), this, SLOT(switchCamera()), Qt::UniqueConnection);
       
   703 
       
   704         // connecting error signals from precapture view to application state.
       
   705         connect(currentView, SIGNAL(errorEncountered(CxeError::Id)),
       
   706                 mApplicationState, SLOT(handleApplicationError(CxeError::Id)),
       
   707                 Qt::UniqueConnection);
       
   708 
       
   709         // Standby signals
       
   710         connect(this, SIGNAL(normalStateEntered()), currentView, SLOT(exitStandby()), Qt::UniqueConnection);
       
   711         connect(this, SIGNAL(normalStateExited()), currentView, SLOT(enterStandby()), Qt::UniqueConnection);
       
   712     }
       
   713 
       
   714     CX_DEBUG_EXIT_FUNCTION();
       
   715 }
       
   716 
       
   717 /*!
       
   718 * Connect signals to post-capture view.
       
   719 */
       
   720 void CxuiViewManager::connectPostCaptureSignals()
       
   721 {
       
   722     CX_DEBUG_ENTER_FUNCTION();
       
   723 
       
   724     disconnectSignals();
       
   725     QObject *currentView = mMainWindow.currentView();
       
   726     if (currentView == mViews[POSTCAPTURE_VIEW]) {
       
   727         connect(currentView, SIGNAL(changeToPrecaptureView()), this, SLOT(changeToPrecaptureView()), Qt::UniqueConnection);
       
   728 
       
   729         // Standby signals
       
   730         connect(this, SIGNAL(normalStateEntered()), currentView, SLOT(exitStandby()), Qt::UniqueConnection);
       
   731         connect(this, SIGNAL(normalStateExited()), currentView, SLOT(enterStandby()), Qt::UniqueConnection);
       
   732 
       
   733         // connect necessary capturekey signals
       
   734         connectCaptureKeySignals();
       
   735     }
       
   736 
       
   737     CX_DEBUG_EXIT_FUNCTION();
       
   738 }
       
   739 
       
   740 /*!
       
   741 * Connect signals to scene mode view.
       
   742 */
       
   743 void CxuiViewManager::connectSceneModeSignals()
       
   744 {
       
   745     CX_DEBUG_ENTER_FUNCTION();
       
   746     disconnectSignals();
       
   747 
       
   748     connectCaptureKeySignals();
       
   749 
       
   750     // Standby signals for releasing camera
       
   751     connect(this, SIGNAL(normalStateEntered()), mSceneModeView, SLOT(exitStandby()));
       
   752     connect(this, SIGNAL(normalStateExited()), mSceneModeView, SLOT(enterStandby()));
       
   753 
       
   754     // Moving back to pre-capture view
       
   755     connect(mSceneModeView, SIGNAL(viewCloseEvent()), this, SLOT(changeToPrecaptureView()));
       
   756 
       
   757     CX_DEBUG_EXIT_FUNCTION();
       
   758 }
       
   759 
       
   760 /*!
       
   761 * Connect key handler capture key signals.
       
   762 */
   541 void CxuiViewManager::connectCaptureKeySignals()
   763 void CxuiViewManager::connectCaptureKeySignals()
   542 {
   764 {
   543     CX_DEBUG_ENTER_FUNCTION();
   765     CX_DEBUG_ENTER_FUNCTION();
   544 
   766 
   545     // Disconnect all existing capture key signals
   767     // Disconnect all existing capture key signals
   557     }
   779     }
   558 
   780 
   559     CX_DEBUG_EXIT_FUNCTION();
   781     CX_DEBUG_EXIT_FUNCTION();
   560 }
   782 }
   561 
   783 
   562 
   784 /*!
   563 // ---------------------------------------------------------------------------
   785  * Clears all camera activities from activity manager.
   564 // CxuiViewManager::connectPreCaptureSignals
   786  */
   565 //
   787 void CxuiViewManager::clearAllActivities()
   566 // ---------------------------------------------------------------------------
   788 {
   567 //
   789     HbActivityManager *activityManager = mApplication.activityManager();
   568 void CxuiViewManager::connectPreCaptureSignals()
   790     activityManager->removeActivity(CxuiActivityIds::STILL_PRECAPTURE_ACTIVITY);
   569 {
   791     activityManager->removeActivity(CxuiActivityIds::STILL_POSTCAPTURE_ACTIVITY);
   570     CX_DEBUG_ENTER_FUNCTION();
   792     activityManager->removeActivity(CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY);
   571 
   793     activityManager->removeActivity(CxuiActivityIds::VIDEO_POSTCAPTURE_ACTIVITY);
   572     disconnectSignals();
       
   573 
       
   574     QObject *currentView = mMainWindow.currentView();
       
   575 
       
   576     if (currentView != mPostcaptureView) {
       
   577         // connects all capture key signals.
       
   578         connectCaptureKeySignals();
       
   579 
       
   580         // connecting view manager focus events to pre-capture views
       
   581         connect(this, SIGNAL(focusGained()),  currentView, SLOT(handleFocusGained()), Qt::UniqueConnection);
       
   582         connect(this, SIGNAL(focusLost()),    currentView, SLOT(handleFocusLost()), Qt::UniqueConnection);
       
   583         connect(this, SIGNAL(batteryEmpty()), currentView, SLOT(handleBatteryEmpty()), Qt::UniqueConnection);
       
   584 
       
   585         // in standby mode, we are interested in focus gain events for dismissing standby
       
   586         connect(this, SIGNAL(focusGained()),  mStandbyHandler, SLOT(handleMouseEvent()), Qt::UniqueConnection);
       
   587 
       
   588         // connecting key events to standby.
       
   589         connect(mKeyHandler, SIGNAL(autofocusKeyPressed()),  mStandbyHandler, SLOT(stopTimer()), Qt::UniqueConnection);
       
   590         connect(mKeyHandler, SIGNAL(autofocusKeyReleased()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
       
   591         connect(mKeyHandler, SIGNAL(captureKeyPressed()),    mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
       
   592         connect(mKeyHandler, SIGNAL(captureKeyReleased()),   mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
       
   593         connect(this, SIGNAL(disableStandbyTimer()), mStandbyHandler, SLOT(stopTimer()), Qt::UniqueConnection);
       
   594         connect(this, SIGNAL(startStandbyTimer()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
       
   595 
       
   596         // connecting pre-capture view signals to standby.
       
   597         connect(currentView, SIGNAL(startStandbyTimer()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
       
   598         connect(currentView, SIGNAL(changeToPrecaptureView()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
       
   599         connect(currentView, SIGNAL(stopStandbyTimer()), mStandbyHandler, SLOT(stopTimer()), Qt::UniqueConnection);
       
   600         connect(currentView, SIGNAL(changeToPostcaptureView()), mStandbyHandler, SLOT(stopTimer()), Qt::UniqueConnection);
       
   601 
       
   602         // connecting precapture view signals to viewmanager slots
       
   603         connect(currentView, SIGNAL(changeToPostcaptureView()), this, SLOT(changeToPostcaptureView()), Qt::UniqueConnection);
       
   604         connect(currentView, SIGNAL(changeToPrecaptureView()),  this, SLOT(changeToPrecaptureView()), Qt::UniqueConnection);
       
   605 
       
   606         //connecting scene modes signal
       
   607         connect(currentView, SIGNAL(showScenesView()), this, SLOT(showScenesView()), Qt::UniqueConnection);
       
   608 
       
   609         connect(currentView, SIGNAL(switchCamera()), this, SLOT(switchCamera()), Qt::UniqueConnection);
       
   610 
       
   611         // connecting error signals from precapture view to errormanager.
       
   612         connect(currentView, SIGNAL(reportError(CxeError::Id)),   mErrorManager, SLOT(showPopup(CxeError::Id)), Qt::UniqueConnection);
       
   613     }
       
   614 
       
   615     CX_DEBUG_EXIT_FUNCTION();
       
   616 }
       
   617 
       
   618 
       
   619 // ---------------------------------------------------------------------------
       
   620 // CxuiViewManager::connectPostCaptureSignals
       
   621 //
       
   622 // ---------------------------------------------------------------------------
       
   623 //
       
   624 void CxuiViewManager::connectPostCaptureSignals()
       
   625 {
       
   626     CX_DEBUG_ENTER_FUNCTION();
       
   627 
       
   628     disconnectSignals();
       
   629     QObject *currentView = mMainWindow.currentView();
       
   630     if (currentView == mPostcaptureView) {
       
   631         // connecting view manager focus events to pre-capture views
       
   632         connect(this, SIGNAL(focusGained()),  currentView, SLOT(handleFocusGained()), Qt::UniqueConnection);
       
   633         connect(this, SIGNAL(focusLost()),    currentView, SLOT(handleFocusLost()), Qt::UniqueConnection);
       
   634         connect(currentView, SIGNAL(changeToPrecaptureView()), mStandbyHandler, SLOT(startTimer()), Qt::UniqueConnection);
       
   635 
       
   636         // connect necessary capturekey signals
       
   637         connectCaptureKeySignals();
       
   638     }
       
   639 
       
   640     CX_DEBUG_EXIT_FUNCTION();
       
   641 }
       
   642 
       
   643 
       
   644 
       
   645 /*
       
   646 * CxuiViewManager::disconnectPreCaptureSignals
       
   647 */
       
   648 void CxuiViewManager::disconnectSignals()
       
   649 {
       
   650     CX_DEBUG_ENTER_FUNCTION();
       
   651 
       
   652     // Disconnect all existing capture key signals
       
   653     mKeyHandler->disconnect();
       
   654 
       
   655     disconnect(SIGNAL(focusGained()));
       
   656     disconnect(SIGNAL(focusLost()));
       
   657     disconnect(SIGNAL(batteryEmpty()));
       
   658 
       
   659     CX_DEBUG_EXIT_FUNCTION();
       
   660 }
   794 }
   661 
   795 
   662 /*!
   796 /*!
   663 * Raise application to foreground if it's currently (fully) in background.
   797 * Raise application to foreground if it's currently (fully) in background.
   664 */
   798 */
   665 void CxuiViewManager::toForeground()
   799 void CxuiViewManager::toForeground()
   666 {
   800 {
   667     CX_DEBUG_ENTER_FUNCTION();
   801     CX_DEBUG_ENTER_FUNCTION();
   668 
   802 
   669     if (mApplicationMonitor
   803     if (mApplicationState->currentState() == CxuiApplicationState::Background) {
   670      && mApplicationMonitor->foregroundState() == CxuiApplicationFrameworkMonitor::ForegroundFullyLost) {
       
   671         // Bring to foreground and gain focus.
   804         // Bring to foreground and gain focus.
   672         CX_DEBUG(("CxuiViewManager - fully in background, bringing to foreground now."));
   805         CX_DEBUG(("CxuiViewManager - in background, bringing to foreground now."));
   673         mMainWindow.raise();
   806         mMainWindow.raise();
   674         mMainWindow.activateWindow();
   807         mMainWindow.activateWindow();
   675     }
   808     }
   676 
   809 
   677     CX_DEBUG_EXIT_FUNCTION();
   810     CX_DEBUG_EXIT_FUNCTION();
   678 }
   811 }
   679 
   812 
   680 /*!
       
   681 * Handle change in foreground state.
       
   682 */
       
   683 void CxuiViewManager::handleForegroundStateChanged(CxuiApplicationFrameworkMonitor::ForegroundState state)
       
   684 {
       
   685     switch (state) {
       
   686     case CxuiApplicationFrameworkMonitor::ForegroundPartiallyLost:
       
   687         break;
       
   688     case CxuiApplicationFrameworkMonitor::ForegroundFullyLost:
       
   689         aboutToLooseFocus();
       
   690         break;
       
   691     case CxuiApplicationFrameworkMonitor::ForegroundOwned:
       
   692         aboutToGainFocus();
       
   693         break;
       
   694     }
       
   695 }
       
   696 
       
   697 /*!
       
   698 * Show or hide error popup based on change in USB mass memory mode activity.
       
   699 * @param show Show the popup?
       
   700 */
       
   701 void CxuiViewManager::showUsbErrorPopup(bool show)
       
   702 {
       
   703     CX_DEBUG_ENTER_FUNCTION();
       
   704     if (show) {
       
   705         mStandbyHandler->enterStandby();
       
   706         mStandbyHandler->allowDismiss(false);
       
   707         // Emulate "mass memory not accessible" error to Error Manager
       
   708         // to get the same functionality as if the error came from CxEngine.
       
   709         mErrorManager->showPopup(CxeError::MemoryNotAccessible);
       
   710     } else {
       
   711         mStandbyHandler->allowDismiss(true);
       
   712         // If we are in postcapture view or scene view, we can return right away to normal mode.
       
   713         // For precapture views we expect user action before reserving camera
       
   714         // and starting viewfinder again.
       
   715         QObject *currentView = mMainWindow.currentView();
       
   716         if (currentView == mPostcaptureView || currentView == mSceneModeView) {
       
   717             mStandbyHandler->exitStandby();
       
   718         }
       
   719         mErrorManager->hidePopup(CxeError::MemoryNotAccessible);
       
   720     }
       
   721     CX_DEBUG_EXIT_FUNCTION();
       
   722 }
       
   723 
       
   724 // ---------------------------------------------------------------------------
       
   725 // CxuiViewManager::aboutToLooseFocus()
       
   726 //
       
   727 // ---------------------------------------------------------------------------
       
   728 //
       
   729 void CxuiViewManager::aboutToLooseFocus()
       
   730 {
       
   731     CX_DEBUG_ENTER_FUNCTION();
       
   732 
       
   733     emit focusLost();
       
   734     disconnectSignals();
       
   735 
       
   736     // We do not stop listening to capture key events even if we go to background,
       
   737     // as capture key brings us back to foreground.
       
   738     connect(mKeyHandler, SIGNAL(captureKeyPressed()), this, SLOT(toForeground()));
       
   739 
       
   740     CX_DEBUG_EXIT_FUNCTION();
       
   741 }
       
   742 
       
   743 
       
   744 // ---------------------------------------------------------------------------
       
   745 // CxuiViewManager::aboutToGainFocus
       
   746 //
       
   747 // ---------------------------------------------------------------------------
       
   748 //
       
   749 void CxuiViewManager::aboutToGainFocus()
       
   750 {
       
   751     CX_DEBUG_ENTER_FUNCTION();
       
   752 
       
   753     // If standby mode is still active, no action is needed yet.
       
   754     // This is the case when USB mass memory mode error is cleared.
       
   755     if (mStandbyHandler->isActive()) {
       
   756         CX_DEBUG(("CxuiViewManager - Focus gain event ignored as standby mode still active."));
       
   757     } else {
       
   758 
       
   759         // Disconnect capture key event and bringing us to foreground connection (if there is one).
       
   760         disconnect(mKeyHandler, SIGNAL(captureKeyPressed()), this, SLOT(toForeground()));
       
   761 
       
   762         // we are getting the focus.
       
   763         if (mMainWindow.currentView() != mPostcaptureView) {
       
   764             connectPreCaptureSignals();
       
   765         } else {
       
   766             connectPostCaptureSignals();
       
   767         }
       
   768 
       
   769         if (mKeyHandler) {
       
   770             mKeyHandler->listenKeys(true);
       
   771         }
       
   772         emit focusGained();
       
   773     }
       
   774 
       
   775     CX_DEBUG_EXIT_FUNCTION();
       
   776 }
       
   777 
       
   778 /*!
       
   779 * Handle battery emptying
       
   780 */
       
   781 void CxuiViewManager::handleBatteryEmpty()
       
   782 {
       
   783     CX_DEBUG_ENTER_FUNCTION();
       
   784     emit batteryEmpty();
       
   785     CX_DEBUG_EXIT_FUNCTION();
       
   786 }
       
   787 
       
   788 // end of file
   813 // end of file