camerauis/cameraxui/cxui/src/cxuiviewmanager.cpp
changeset 48 42ba2d16bf40
parent 37 64817133cd1d
child 56 01e205c615b9
equal deleted inserted replaced
37:64817133cd1d 48:42ba2d16bf40
    15 *
    15 *
    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>
       
    21 #include <QGraphicsSceneEvent>
    20 #include <QGraphicsSceneEvent>
    22 #include <hbstyleloader.h>
    21 #include <hbstyleloader.h>
    23 #include <hbactivitymanager.h>
    22 #include <hbactivitymanager.h>
    24 #include <hbaction.h>
    23 #include <hbaction.h>
       
    24 #include <xqserviceutil.h>
    25 
    25 
    26 #include "cxuiapplication.h"
    26 #include "cxuiapplication.h"
    27 #include "cxuiapplicationstate.h"
    27 #include "cxuiapplicationstate.h"
    28 #include "cxuiviewmanager.h"
    28 #include "cxuiviewmanager.h"
    29 #include "cxuivideoprecaptureview.h"
    29 #include "cxuivideoprecaptureview.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 
       
    46 
       
    47 #ifdef Q_OS_SYMBIAN
    46 #include "OstTraceDefinitions.h"
    48 #include "OstTraceDefinitions.h"
       
    49 
    47 #ifdef OST_TRACE_COMPILER_IN_USE
    50 #ifdef OST_TRACE_COMPILER_IN_USE
    48 #include "cxuiviewmanagerTraces.h"
    51 #include "cxuiviewmanagerTraces.h"
    49 #endif
    52 #endif
       
    53 
       
    54 #endif //Q_OS_SYMBIAN
    50 
    55 
    51 
    56 
    52 using namespace Cxe;
    57 using namespace Cxe;
    53 using namespace CxUiLayout;
    58 using namespace CxUiLayout;
    54 
    59 
    66     mMainWindow(mainWindow),
    71     mMainWindow(mainWindow),
    67     mEngine(engine),
    72     mEngine(engine),
    68     mKeyHandler(NULL),
    73     mKeyHandler(NULL),
    69     mCameraDocumentLoader(NULL),
    74     mCameraDocumentLoader(NULL),
    70     mApplicationState(NULL),
    75     mApplicationState(NULL),
    71     mErrorManager(NULL),
    76     mErrorManager(NULL)
    72     mSceneModeView(NULL)
       
    73 {
    77 {
    74     CX_DEBUG_ENTER_FUNCTION();
    78     CX_DEBUG_ENTER_FUNCTION();
    75 
    79 
    76     // create mappings to map view name to correct docml file
    80     // create mappings to map view name to correct docml file
    77     mDocmlFilesByView.insert(STILL_PRE_CAPTURE_VIEW, STILL_1ST_XML);
    81     mDocmlFilesByView.insert(STILL_PRE_CAPTURE_VIEW, STILL_1ST_XML);
    78     mDocmlFilesByView.insert(VIDEO_PRE_CAPTURE_VIEW, VIDEO_1ST_XML);
    82     mDocmlFilesByView.insert(VIDEO_PRE_CAPTURE_VIEW, VIDEO_1ST_XML);
    79     mDocmlFilesByView.insert(POSTCAPTURE_VIEW, POSTCAPTURE_XML);
    83     mDocmlFilesByView.insert(POSTCAPTURE_VIEW, POSTCAPTURE_XML);
    80     mDocmlFilesByView.insert(STILL_SCENES_VIEW, SCENEMODE_SETTING_XML);
    84     mDocmlFilesByView.insert(SCENE_MODE_VIEW, SCENEMODE_SETTING_XML);
    81 
    85 
    82     // Key handler
    86     // Key handler
    83     mKeyHandler = new CxuiCaptureKeyHandler(mEngine);
    87     mKeyHandler = new CxuiCaptureKeyHandler(mEngine);
    84 
    88 
    85     // Document loader
    89     // Document loader
    86     OstTrace0( camerax_performance, CXUIVIEWMANAGER_CXUIVIEWMANAGER, "msg: e_CX_VIEWMANAGER_CREATE_DOCLOADER 1" );
    90     OstTrace0(camerax_performance, CXUIVIEWMANAGER_CXUIVIEWMANAGER_1, "msg: e_CX_VIEWMANAGER_CREATE_DOCLOADER 1");
    87     mCameraDocumentLoader = new CxuiDocumentLoader(&engine);
    91     mCameraDocumentLoader = new CxuiDocumentLoader(&engine);
    88     OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_CXUIVIEWMANAGER, "msg: e_CX_VIEWMANAGER_CREATE_DOCLOADER 0" );
    92     OstTrace0(camerax_performance, CXUIVIEWMANAGER_CXUIVIEWMANAGER_2, "msg: e_CX_VIEWMANAGER_CREATE_DOCLOADER 0");
    89 
    93 
    90     // Application state
    94     // Application state
    91     mApplicationState = new CxuiApplicationState(mApplication, mEngine.settings(), *mKeyHandler, mCameraDocumentLoader);
    95     mApplicationState = new CxuiApplicationState(mApplication, mEngine.settings(), mCameraDocumentLoader);
    92     CX_ASSERT_ALWAYS(mApplicationState);
    96     CX_ASSERT_ALWAYS(mApplicationState);
    93     bool ok = connect(mApplicationState, SIGNAL(stateChanged(CxuiApplicationState::State, CxuiApplicationState::State)),
    97     bool ok = connect(mApplicationState, SIGNAL(stateChanged(CxuiApplicationState::State, CxuiApplicationState::State)),
    94                       this, SLOT(handleApplicationStateChanged(CxuiApplicationState::State, CxuiApplicationState::State)));
    98                       this, SLOT(handleApplicationStateChanged(CxuiApplicationState::State, CxuiApplicationState::State)));
    95     Q_ASSERT_X(ok, "CxuiViewManager", "Application state change signal connect failed.");
    99     Q_ASSERT_X(ok, "CxuiViewManager", "Application state change signal connect failed.");
    96     connect(this, SIGNAL(standbyExitRequested()), mApplicationState, SLOT(exitStandby()), Qt::QueuedConnection);
   100     connect(this, SIGNAL(standbyExitRequested()), mApplicationState, SLOT(exitStandby()), Qt::QueuedConnection);
   158                                                     CxuiApplicationState::State oldState)
   162                                                     CxuiApplicationState::State oldState)
   159 {
   163 {
   160     Q_UNUSED(oldState);
   164     Q_UNUSED(oldState);
   161     CX_DEBUG_ENTER_FUNCTION();
   165     CX_DEBUG_ENTER_FUNCTION();
   162 
   166 
   163     CxuiView *view = qobject_cast<CxuiView *>(mMainWindow.currentView());
   167     CxuiView *view = currentView();
   164     CX_DEBUG(("CxuiViewManager - current view %d", view));
   168     CX_DEBUG(("CxuiViewManager - current view %d", view));
   165 
   169 
   166     switch (newState) {
   170     switch (newState) {
   167     case CxuiApplicationState::Normal:
   171     case CxuiApplicationState::Normal:
   168         // Disable raising to foreground with capture key.
   172         // Disable raising to foreground with capture key.
   204 */
   208 */
   205 void CxuiViewManager::handleExitingNormalState()
   209 void CxuiViewManager::handleExitingNormalState()
   206 {
   210 {
   207     CX_DEBUG_ENTER_FUNCTION();
   211     CX_DEBUG_ENTER_FUNCTION();
   208     // Store view that is active now.
   212     // Store view that is active now.
   209     CxuiView *view = qobject_cast<CxuiView *>(mMainWindow.currentView());
   213     CxuiView *view = currentView();
   210     CX_DEBUG(("CxuiViewManager - current view %d", view));
   214     CX_DEBUG(("CxuiViewManager - current view %d", view));
   211 
   215 
   212     // Emit signal so current view can enter standby.
   216     // Emit signal so current view can enter standby.
   213     emit normalStateExited();
   217     emit normalStateExited();
   214     // Disconnect signals so we don't send key event's etc.
   218     // Disconnect signals so we don't send key event's etc.
   215     // Using the view before normalStateExited() signal was emitted,
   219     // Using the view before normalStateExited() signal was emitted,
   216     // just in case it caused view switch.
   220     // just in case it caused view switch.
   217     disconnectSignals(view);
   221     disconnectSignals(view);
   218     // Make sure standby timer is not running.
   222     // Make sure standby timer is not running.
   219     stopStandbyTimer();
   223     stopStandbyTimer();
       
   224 
   220     CX_DEBUG_EXIT_FUNCTION();
   225     CX_DEBUG_EXIT_FUNCTION();
   221 }
   226 }
   222 
   227 
   223 /*!
   228 /*!
   224 * Slot for starting standby timer.
   229 * Slot for starting standby timer.
   236 void CxuiViewManager::stopStandbyTimer()
   241 void CxuiViewManager::stopStandbyTimer()
   237 {
   242 {
   238     CX_DEBUG_ENTER_FUNCTION();
   243     CX_DEBUG_ENTER_FUNCTION();
   239     mStandbyTimer.stop();
   244     mStandbyTimer.stop();
   240     CX_DEBUG_EXIT_FUNCTION();
   245     CX_DEBUG_EXIT_FUNCTION();
   241 }
       
   242 
       
   243 /**
       
   244  * Init engine to correct mode based on activity being restored.
       
   245  */
       
   246 void CxuiViewManager::initEngine()
       
   247 {
       
   248     Cxe::CameraMode mode = Cxe::ImageMode;
       
   249     QString activityId = mApplication.activateId();
       
   250     if (activityId == CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY ||
       
   251         activityId == CxuiActivityIds::VIDEO_POSTCAPTURE_ACTIVITY) {
       
   252         mode = Cxe::VideoMode;
       
   253     }
       
   254     if (activityId == CxuiActivityIds::STILL_PRECAPTURE_ACTIVITY ||
       
   255         activityId == CxuiActivityIds::VIDEO_PRECAPTURE_ACTIVITY) {
       
   256         // init engine only if going to pre-capture
       
   257         mEngine.initMode(mode);
       
   258     } else {
       
   259         // in post-capture don't init but set the correct mode to engine
       
   260         // so init can be done later
       
   261         mEngine.setMode(mode);
       
   262     }
       
   263 }
   246 }
   264 
   247 
   265 /*!
   248 /*!
   266  * Helper function to return current view cast to CxuiView.
   249  * Helper function to return current view cast to CxuiView.
   267  */
   250  */
   268 CxuiView* CxuiViewManager::currentView() const
   251 CxuiView* CxuiViewManager::currentView() const
   269 {
   252 {
   270     CxuiView *view = qobject_cast<CxuiView*> (mMainWindow.currentView());
   253     CxuiView *view = qobject_cast<CxuiView*> (mMainWindow.currentView());
   271     CX_ASSERT_ALWAYS(view);
       
   272     return view;
   254     return view;
   273 }
   255 }
   274 
   256 
   275 /*!
   257 /*!
   276 * Select and initialize the view we need to start into.
   258 * Select and initialize the view we need to start into.
   277 */
   259 */
   278 void CxuiViewManager::initStartupView()
   260 void CxuiViewManager::initStartupView()
   279 {
   261 {
   280     CX_DEBUG_ENTER_FUNCTION();
   262     CX_DEBUG_ENTER_FUNCTION();
   281 
   263 
   282     if (mApplication.activateReason() == Hb::ActivationReasonService) {
   264     if (mApplication.activateReason() == Hb::ActivationReasonService ||
       
   265         // @todo: There's a bug in orbit and we never get Hb::ActivationReasonService as
       
   266         // activation reason. Use XQServiceUtil to determine if starting service as
       
   267         // a workaround for now
       
   268         XQServiceUtil::isService()) {
       
   269 
   283         // For embedded mode: don't create view yet, create when engine inits to correct mode.
   270         // For embedded mode: don't create view yet, create when engine inits to correct mode.
   284         // Connect signals to set up the view after image/video prepare
   271         // Connect signals to set up the view after image/video prepare
   285         connect(&mEngine.stillCaptureControl(), SIGNAL(imagePrepareComplete(CxeError::Id)),
   272         connect(&mEngine.stillCaptureControl(), SIGNAL(imagePrepareComplete(CxeError::Id)),
   286                 this, SLOT(changeToPrecaptureView()));
   273                 this, SLOT(changeToPrecaptureView()));
   287         connect(&mEngine.videoCaptureControl(), SIGNAL(videoPrepareComplete(CxeError::Id)),
   274         connect(&mEngine.videoCaptureControl(), SIGNAL(videoPrepareComplete(CxeError::Id)),
   288                 this, SLOT(changeToPrecaptureView()));
   275                 this, SLOT(changeToPrecaptureView()));
   289 
   276 
   290     } else if (mApplication.activateReason() == Hb::ActivationReasonActivity ) {
   277     } else if (mApplication.activateReason() == Hb::ActivationReasonActivity) {
   291         // restoring activity, read startup view from stored activity
   278         // restoring activity, read startup view from stored activity
   292 
   279 
   293         // view to start in
   280         // view to start in
   294         QString viewName = STILL_PRE_CAPTURE_VIEW;
   281         QString viewName = STILL_PRE_CAPTURE_VIEW;
   295 
   282 
   306             viewName = POSTCAPTURE_VIEW;
   293             viewName = POSTCAPTURE_VIEW;
   307             preCapture = false;
   294             preCapture = false;
   308         }
   295         }
   309 
   296 
   310         CxuiView *view = createView(viewName);
   297         CxuiView *view = createView(viewName);
   311         mMainWindow.setCurrentView(view, false);
       
   312 
       
   313         if (preCapture) {
   298         if (preCapture) {
   314             connectPreCaptureSignals();
   299             connectPreCaptureSignals(static_cast<CxuiPrecaptureView *>(view));
   315         } else {
   300         } else {
   316             connectPostCaptureSignals();
   301             connectPostCaptureSignals();
   317         }
   302         }
   318 
   303         mMainWindow.setCurrentView(view, false);
   319         // Check the current application state, signalled to handleApplicationStateChanged.
       
   320         mApplicationState->startMonitoring();
       
   321 
   304 
   322         // restore view from activity
   305         // restore view from activity
   323         bool ok = mApplication.activityManager()->waitActivity();
   306         bool ok = mApplication.activityManager()->waitActivity();
   324 
   307 
   325         view->restoreActivity(activityId,
   308         view->restoreActivity(activityId,
   333         if (mEngine.mode() == Cxe::VideoMode) {
   316         if (mEngine.mode() == Cxe::VideoMode) {
   334             view = createView(VIDEO_PRE_CAPTURE_VIEW);
   317             view = createView(VIDEO_PRE_CAPTURE_VIEW);
   335         } else {
   318         } else {
   336             view = createView(STILL_PRE_CAPTURE_VIEW);
   319             view = createView(STILL_PRE_CAPTURE_VIEW);
   337         }
   320         }
   338 
   321         connectPreCaptureSignals(static_cast<CxuiPrecaptureView *>(view));
   339         mMainWindow.setCurrentView(view, false);
   322         mMainWindow.setCurrentView(view, false);
   340         connectPreCaptureSignals();
       
   341 
       
   342         // Check the current application state, signalled to handleApplicationStateChanged.
       
   343         mApplicationState->startMonitoring();
       
   344 
   323 
   345         clearAllActivities();
   324         clearAllActivities();
   346     }
   325     }
   347 
   326 
       
   327     // Check the current application state, signalled to handleApplicationStateChanged.
       
   328     mApplicationState->startMonitoring();
       
   329 
   348     CX_DEBUG_EXIT_FUNCTION();
   330     CX_DEBUG_EXIT_FUNCTION();
   349 }
   331 }
   350 
   332 
   351 /*!
   333 /*!
   352 * Create view and add it to main window.
   334 * Create view and add it to main window.
   353 */
   335 */
   354 CxuiView* CxuiViewManager::createView(const QString &viewName)
   336 CxuiView* CxuiViewManager::createView(const QString &viewName)
   355 {
   337 {
   356     CX_DEBUG_ENTER_FUNCTION();
   338     CX_DEBUG_ENTER_FUNCTION();
   357 
   339 
   358     OstTrace0( camerax_performance, CXUIVIEWMANAGER_CREATEVIEW, "msg: e_CX_CREATE_VIEW 1" );
   340     OstTrace0(camerax_performance, CXUIVIEWMANAGER_CREATEVIEW_IN, "msg: e_CX_CREATE_VIEW 1");
   359 
   341 
   360     CX_DEBUG(("View name: %s", viewName.toAscii().data()));
   342     CX_DEBUG(("View name: %s", viewName.toAscii().data()));
   361 
   343 
   362     CxuiView* view = mViews[viewName];
   344     CxuiView* view = mViews[viewName];
   363     if (view == NULL) {
   345     if (view == NULL) {
   364         CX_DEBUG(("View not loaded yet, loading now"));
   346         CX_DEBUG(("View not loaded yet, loading now"));
   365         bool ok = false;
   347         bool ok = false;
   366         // Use document loader to create widgets and layouts
   348         // Use document loader to create widgets and layouts
   367         // (non-sectioned parts are parsed and loaded)
   349         // (non-sectioned parts are parsed and loaded)
   368         QString docmlFile = mDocmlFilesByView[viewName];
   350         QString docmlFile = mDocmlFilesByView[viewName];
   369         CX_DEBUG_ASSERT(mCameraDocumentLoader);
   351         CX_ASSERT_ALWAYS(mCameraDocumentLoader);
   370         CX_ASSERT_ALWAYS(!docmlFile.isNull());
   352         CX_ASSERT_ALWAYS(!docmlFile.isNull());
   371 
   353 
   372         OstTrace0( camerax_performance, DUP2_CXUIVIEWMANAGER_ADDPRECAPTUREVIEWS, "msg: e_CX_DOCLOADER_LOAD 1" );
   354         OstTrace0(camerax_performance, CXUIVIEWMANAGER_CREATEVIEW_2, "msg: e_CX_DOCUMENTLOADER_LOAD 1");
   373 
       
   374         mCameraDocumentLoader->load(docmlFile, &ok);
   355         mCameraDocumentLoader->load(docmlFile, &ok);
   375 
   356         OstTrace0(camerax_performance, CXUIVIEWMANAGER_CREATEVIEW_4, "msg: e_CX_DOCUMENTLOADER_LOAD 0");
   376         Q_ASSERT_X(ok, "createView", "error in xml file parsing");
   357         Q_ASSERT_X(ok, "createView", "error in xml file parsing");
   377 
   358 
   378         OstTrace0( camerax_performance, DUP2_CXUIVIEWMANAGER_CREATEVIEW, "msg: e_CX_DOCLOADER_LOAD 0" );
   359         OstTrace0(camerax_performance, CXUIVIEWMANAGER_CREATEVIEW_6, "msg: e_CX_DOCUMENTLOADER_FINDWIDGET 1");
   379 
       
   380         OstTrace0( camerax_performance, DUP4_CXUIVIEWMANAGER_ADDVIEWS, "msg: e_CX_DOCLOADER_FINDWIDGET 1" );
       
   381         QGraphicsWidget *widget = NULL;
   360         QGraphicsWidget *widget = NULL;
   382         // ask for the view widget pointer
   361         // ask for the view widget pointer
   383         widget = mCameraDocumentLoader->findWidget(viewName);
   362         widget = mCameraDocumentLoader->findWidget(viewName);
   384         view = qobject_cast<CxuiView *> (widget);
   363         view = qobject_cast<CxuiView *> (widget);
   385         CX_DEBUG_ASSERT(view);
   364         CX_ASSERT_ALWAYS(view);
   386         OstTrace0( camerax_performance, DUP5_CXUIVIEWMANAGER_ADDVIEWS, "msg: e_CX_DOCLOADER_FINDWIDGET 0" );
   365         OstTrace0(camerax_performance, CXUIVIEWMANAGER_CREATEVIEW_8, "msg: e_CX_DOCUMENTLOADER_FINDWIDGET 1");
   387 
   366 
   388         // call for needed consturction methods
   367         // call for needed consturction methods
   389         view->construct(&mMainWindow, &mEngine, mCameraDocumentLoader, mKeyHandler, mApplication.activityManager());
   368         view->construct(&mMainWindow, &mEngine, mCameraDocumentLoader, mKeyHandler, mApplication.activityManager());
   390         // .. and add to main window (which also takes ownership)
   369         // .. and add to main window (which also takes ownership)
   391         OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_MAINWINDOW_ADDVIEW, "msg: e_CX_MAINWINDOW_ADDVIEW 1" );
   370         OstTrace0(camerax_performance, CXUIVIEWMANAGER_CREATEVIEW_10, "msg: e_CX_MAINWINDOW_ADDVIEW 1");
   392         mMainWindow.addView(view);
   371         mMainWindow.addView(view);
   393         mViews.insert(viewName, view);
   372         mViews.insert(viewName, view);
   394 
   373         OstTrace0(camerax_performance, CXUIVIEWMANAGER_CREATEVIEW_12, "msg: e_CX_MAINWINDOW_ADDVIEW 0");
   395         OstTrace0( camerax_performance, DUP2_CXUIVIEWMANAGER_MAINWINDOW_ADDVIEW, "msg: e_CX_MAINWINDOW_ADDVIEW 0" );
   374     }
   396         OstTrace0( camerax_performance, DUP1_CXUIVIEWMANAGER_CREATEVIEW, "msg: e_CX_CREATE_STILLPRECAPTUREVIEW 0" );
   375 
   397 
   376     OstTrace0(camerax_performance, CXUIVIEWMANAGER_CREATEVIEW_OUT, "msg: e_CX_CREATE_VIEW 0");
   398     }
       
   399 
   377 
   400     CX_DEBUG_EXIT_FUNCTION();
   378     CX_DEBUG_EXIT_FUNCTION();
   401     return view;
   379     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));
       
   412     mSceneModeView->loadBackgroundImages();
       
   413 
       
   414     CX_DEBUG_EXIT_FUNCTION();
       
   415     return mSceneModeView;
       
   416 }
   380 }
   417 
   381 
   418 /*!
   382 /*!
   419 * CxuiViewManager::showScenesView
   383 * CxuiViewManager::showScenesView
   420 * A private method for displaying Scene Modes selection view
   384 * A private method for displaying Scene Modes selection view
   423 {
   387 {
   424     CX_DEBUG_ENTER_FUNCTION();
   388     CX_DEBUG_ENTER_FUNCTION();
   425     // Disconnect signals from old view.
   389     // Disconnect signals from old view.
   426     disconnectSignals();
   390     disconnectSignals();
   427 
   391 
   428     if (!mSceneModeView) {
   392     CxuiSceneModeView *view = qobject_cast<CxuiSceneModeView*>(createView(SCENE_MODE_VIEW));
   429         createSceneModesView();
   393     CX_ASSERT_ALWAYS(view);
   430     }
   394     view->loadBackgroundImages();
   431     else {
   395 
   432         mSceneModeView->loadBackgroundImages();
       
   433     }
       
   434     CX_DEBUG_ASSERT(mSceneModeView);
       
   435     mMainWindow.setCurrentView(mSceneModeView, false);
       
   436     stopStandbyTimer();
   396     stopStandbyTimer();
   437     connectSceneModeSignals();
   397     connectSceneModeSignals();
       
   398     mMainWindow.setCurrentView(view, false);
   438 
   399 
   439     CX_DEBUG_EXIT_FUNCTION();
   400     CX_DEBUG_EXIT_FUNCTION();
   440 }
   401 }
   441 
   402 
   442 /*!
   403 /*!
   462         return qobject_cast<CxuiPrecaptureView*>(createView(VIDEO_PRE_CAPTURE_VIEW));
   423         return qobject_cast<CxuiPrecaptureView*>(createView(VIDEO_PRE_CAPTURE_VIEW));
   463     }
   424     }
   464 }
   425 }
   465 
   426 
   466 /*!
   427 /*!
   467 * Get a pointer to the document loader instance.
       
   468 */
       
   469 CxuiDocumentLoader *CxuiViewManager::documentLoader()
       
   470 {
       
   471     return mCameraDocumentLoader;
       
   472 }
       
   473 
       
   474 /*!
       
   475 * Get reference to application state instance.
       
   476 */
       
   477 CxuiApplicationState &CxuiViewManager::applicationState()
       
   478 {
       
   479     return *mApplicationState;
       
   480 }
       
   481 
       
   482 
       
   483 /*!
       
   484 * Move to post-capture view.
   428 * Move to post-capture view.
   485 */
   429 */
   486 void CxuiViewManager::changeToPostcaptureView()
   430 void CxuiViewManager::changeToPostcaptureView()
   487 {
   431 {
   488     CX_DEBUG_ENTER_FUNCTION();
   432     CX_DEBUG_ENTER_FUNCTION();
   489     // Disconnect signals from old view.
   433     // Disconnect signals from old view.
   490     disconnectSignals();
   434     disconnectSignals();
   491 
   435 
   492     CxuiView *postCaptureView = createView(POSTCAPTURE_VIEW);
   436     CxuiView *postCaptureView = createView(POSTCAPTURE_VIEW);
   493 
       
   494     mMainWindow.setCurrentView(postCaptureView, false);
       
   495 
   437 
   496     // Connecting all necessary signals for postcapture view.
   438     // Connecting all necessary signals for postcapture view.
   497     // Not connected yet if not in normal state. We connect the signals
   439     // Not connected yet if not in normal state. We connect the signals
   498     // once we enter normal state again.
   440     // once we enter normal state again.
   499     if (mApplicationState->currentState() == CxuiApplicationState::Normal) {
   441     if (mApplicationState->currentState() == CxuiApplicationState::Normal) {
   500         connectPostCaptureSignals();
   442         connectPostCaptureSignals();
   501     }
   443     }
       
   444 
       
   445     // Connect signals before we set the post-capture view as current view.
       
   446     // We need to have signals connected if post-capture view for example
       
   447     // needs to move back to pre-capture view already in showEvent.
       
   448     mMainWindow.setCurrentView(postCaptureView, false);
   502 
   449 
   503     CX_DEBUG_EXIT_FUNCTION();
   450     CX_DEBUG_EXIT_FUNCTION();
   504 }
   451 }
   505 
   452 
   506 /*!
   453 /*!
   524     } else {
   471     } else {
   525 
   472 
   526         // Disconnect signals from old view.
   473         // Disconnect signals from old view.
   527         disconnectSignals();
   474         disconnectSignals();
   528 
   475 
   529         HbView *view = getPrecaptureView(mEngine.mode(),
   476         CxuiPrecaptureView *view =
   530             mEngine.cameraDeviceControl().cameraIndex());
   477             getPrecaptureView(mEngine.mode(), mEngine.cameraDeviceControl().cameraIndex());
       
   478 
       
   479         // Connect necessary pre-capture view signals.
       
   480         connectPreCaptureSignals(view);
       
   481 
   531         mMainWindow.setCurrentView(view, false);
   482         mMainWindow.setCurrentView(view, false);
   532 
   483 
   533         if (mSceneModeView){
   484         // Release resources needed by scene view.
   534             mViews.remove(STILL_SCENES_VIEW);
   485         HbView *sceneView = mViews.take(SCENE_MODE_VIEW);
   535             delete mSceneModeView;
   486         if (sceneView) {
   536             mSceneModeView = NULL;
   487             // This will not delete the view.
   537         }
   488             mMainWindow.removeView(sceneView);
   538         // connecting necessary pre-capture view signals
   489             // We can get to this slot from scene view, so don't delete the object too early.
   539         connectPreCaptureSignals();
   490             sceneView->deleteLater();
       
   491             sceneView = NULL;
       
   492         }
   540 
   493 
   541         // Make sure engine prepares for new image/video if necessary
   494         // Make sure engine prepares for new image/video if necessary
   542         mEngine.initMode(mEngine.mode());
   495         mEngine.initMode(mEngine.mode());
   543 
   496 
   544         startStandbyTimer();
   497         startStandbyTimer();
   564         nextCamera = Cxe::PrimaryCameraIndex;
   517         nextCamera = Cxe::PrimaryCameraIndex;
   565         nextViewOrientation = Qt::Horizontal;
   518         nextViewOrientation = Qt::Horizontal;
   566     }
   519     }
   567 
   520 
   568     CxuiPrecaptureView* view = getPrecaptureView(mEngine.mode(), nextCamera);
   521     CxuiPrecaptureView* view = getPrecaptureView(mEngine.mode(), nextCamera);
       
   522     connectPreCaptureSignals(view);
   569     mMainWindow.setCurrentView(view, false);
   523     mMainWindow.setCurrentView(view, false);
   570     view->updateOrientation(nextViewOrientation);
   524     view->updateOrientation(nextViewOrientation);
   571 
       
   572     connectPreCaptureSignals();
       
   573 
   525 
   574     mEngine.cameraDeviceControl().switchCamera(nextCamera);
   526     mEngine.cameraDeviceControl().switchCamera(nextCamera);
   575 
   527 
   576     CX_DEBUG_EXIT_FUNCTION();
   528     CX_DEBUG_EXIT_FUNCTION();
   577 }
   529 }
   626 }
   578 }
   627 
   579 
   628 /*!
   580 /*!
   629 * Connect signals specific to given view.
   581 * Connect signals specific to given view.
   630 */
   582 */
   631 void CxuiViewManager::connectSignals(QObject *view)
   583 void CxuiViewManager::connectSignals(CxuiView *view)
   632 {
   584 {
   633     CX_DEBUG_ENTER_FUNCTION();
   585     CX_DEBUG_ENTER_FUNCTION();
       
   586     OstTrace0(camerax_performance, CXUIVIEWMANAGER_CONNECTSIGNALS_1, "msg: e_CX_VIEWMANAGER_CONNECT_SIGNALS 1");
       
   587 
   634     if (view) {
   588     if (view) {
   635         if (view == mViews[POSTCAPTURE_VIEW]) {
   589         if (view == mViews[POSTCAPTURE_VIEW]) {
   636             connectPostCaptureSignals();
   590             connectPostCaptureSignals();
   637         } else if (view == mSceneModeView) {
   591         } else if (view == mViews[SCENE_MODE_VIEW]) {
   638             connectSceneModeSignals();
   592             connectSceneModeSignals();
   639         } else {
   593         } else {
   640             connectPreCaptureSignals();
   594             connectPreCaptureSignals(static_cast<CxuiPrecaptureView *>(view));
   641         }
   595         }
   642     }
   596     }
       
   597 
       
   598     OstTrace0(camerax_performance, CXUIVIEWMANAGER_CONNECTSIGNALS_2, "msg: e_CX_VIEWMANAGER_CONNECT_SIGNALS 0");
   643     CX_DEBUG_EXIT_FUNCTION();
   599     CX_DEBUG_EXIT_FUNCTION();
   644 }
   600 }
   645 
   601 
   646 /*!
   602 /*!
   647 * Disconnect signals.
   603 * Disconnect signals.
   648 * We don't want to send or receive signals with inactive views, so this is done every time changing a view.
   604 * 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.
   605 * @param view View object from which signals are disconnected. If NULL is given, current view is used.
   650 */
   606 */
   651 void CxuiViewManager::disconnectSignals(QObject *view)
   607 void CxuiViewManager::disconnectSignals(CxuiView *view)
   652 {
   608 {
   653     CX_DEBUG_ENTER_FUNCTION();
   609     CX_DEBUG_ENTER_FUNCTION();
       
   610     OstTrace0(camerax_performance, CXUIVIEWMANAGER_DISCONNECT_1, "msg: e_CX_VIEWMANAGER_DISCONNECT_SIGNALS 1");
   654 
   611 
   655     // Disconnect all existing capture key signals
   612     // Disconnect all existing capture key signals
   656     mKeyHandler->disconnect();
   613     mKeyHandler->disconnect();
   657 
   614 
   658     if (!view) {
   615     if (!view) {
   659         // If view is not given, take current view.
   616         // If view is not given, take current view.
   660         view = mMainWindow.currentView();
   617         view = currentView();
   661     }
   618     }
   662 
   619 
   663     CX_DEBUG(("CxuiViewManager - disconnecting from view %d", view));
   620     CX_DEBUG(("CxuiViewManager - disconnecting from view %d", view));
   664     if (view) {
   621     if (view) {
   665         // Disconnect all signals from current view to us.
   622         // Disconnect all signals from current view to us.
   666         disconnect(view, 0, this, 0);
   623         disconnect(view, 0, this, 0);
   667         // Disconnect all signals from us to current view.
   624         // Disconnect all signals from us to current view.
   668         disconnect(this, 0, view, 0);
   625         disconnect(this, 0, view, 0);
   669     }
   626     }
   670 
   627 
       
   628     OstTrace0(camerax_performance, CXUIVIEWMANAGER_DISCONNECT_2, "msg: e_CX_VIEWMANAGER_DISCONNECT_SIGNALS 0");
   671     CX_DEBUG_EXIT_FUNCTION();
   629     CX_DEBUG_EXIT_FUNCTION();
   672 }
   630 }
   673 
   631 
   674 /*!
   632 /*!
   675 * Connect signals to pre-capture view.
   633 * Connect signals to pre-capture view.
   676 */
   634 */
   677 void CxuiViewManager::connectPreCaptureSignals()
   635 void CxuiViewManager::connectPreCaptureSignals(CxuiPrecaptureView *view)
   678 {
   636 {
   679     CX_DEBUG_ENTER_FUNCTION();
   637     CX_DEBUG_ENTER_FUNCTION();
   680 
   638 
       
   639     // Disconnect from the current, "old" view
   681     disconnectSignals();
   640     disconnectSignals();
   682 
   641 
   683     HbView *currentView = mMainWindow.currentView();
   642     // connecting pre-capture view signals to standby timer.
   684 
   643     connect(view, SIGNAL(startStandbyTimer()),       this, SLOT(startStandbyTimer()), Qt::UniqueConnection);
   685     if (currentView != mViews[POSTCAPTURE_VIEW]) {
   644     connect(view, SIGNAL(stopStandbyTimer()),        this, SLOT(stopStandbyTimer()),  Qt::UniqueConnection);
   686         // connects all capture key signals.
   645     connect(view, SIGNAL(changeToPrecaptureView()),  this, SLOT(startStandbyTimer()), Qt::UniqueConnection);
   687         connectCaptureKeySignals();
   646     connect(view, SIGNAL(changeToPostcaptureView()), this, SLOT(stopStandbyTimer()),  Qt::UniqueConnection);
   688 
   647 
   689         // connecting pre-capture view signals to standby timer.
   648     // connecting pre-capture view signals to viewmanager slots
   690         connect(currentView, SIGNAL(startStandbyTimer()),       this, SLOT(startStandbyTimer()), Qt::UniqueConnection);
   649     connect(view, SIGNAL(changeToPostcaptureView()), this, SLOT(changeToPostcaptureView()), Qt::UniqueConnection);
   691         connect(currentView, SIGNAL(stopStandbyTimer()),        this, SLOT(stopStandbyTimer()),  Qt::UniqueConnection);
   650     connect(view, SIGNAL(changeToPrecaptureView()),  this, SLOT(changeToPrecaptureView()),  Qt::UniqueConnection);
   692         connect(currentView, SIGNAL(changeToPrecaptureView()),  this, SLOT(startStandbyTimer()), Qt::UniqueConnection);
   651 
   693         connect(currentView, SIGNAL(changeToPostcaptureView()), this, SLOT(stopStandbyTimer()),  Qt::UniqueConnection);
   652     //connecting scene modes signal
   694 
   653     connect(view, SIGNAL(showScenesView()), this, SLOT(showScenesView()), Qt::UniqueConnection);
   695         // connecting pre-capture view signals to viewmanager slots
   654 
   696         connect(currentView, SIGNAL(changeToPostcaptureView()), this, SLOT(changeToPostcaptureView()), Qt::UniqueConnection);
   655     connect(view, SIGNAL(switchCamera()), this, SLOT(switchCamera()), Qt::UniqueConnection);
   697         connect(currentView, SIGNAL(changeToPrecaptureView()),  this, SLOT(changeToPrecaptureView()),  Qt::UniqueConnection);
   656 
   698 
   657     // connecting error signals from precapture view to application state.
   699         //connecting scene modes signal
   658     connect(view, SIGNAL(errorEncountered(CxeError::Id)),
   700         connect(currentView, SIGNAL(showScenesView()), this, SLOT(showScenesView()), Qt::UniqueConnection);
   659             mApplicationState, SLOT(handleApplicationError(CxeError::Id)),
   701 
   660             Qt::UniqueConnection);
   702         connect(currentView, SIGNAL(switchCamera()), this, SLOT(switchCamera()), Qt::UniqueConnection);
   661 
   703 
   662     // Standby signals
   704         // connecting error signals from precapture view to application state.
   663     connect(this, SIGNAL(normalStateEntered()), view, SLOT(exitStandby()), Qt::UniqueConnection);
   705         connect(currentView, SIGNAL(errorEncountered(CxeError::Id)),
   664     connect(this, SIGNAL(normalStateExited()), view, SLOT(enterStandby()), Qt::UniqueConnection);
   706                 mApplicationState, SLOT(handleApplicationError(CxeError::Id)),
   665 
   707                 Qt::UniqueConnection);
   666     // connects all capture key signals.
       
   667     connectCaptureKeySignals(view);
       
   668 
       
   669     CX_DEBUG_EXIT_FUNCTION();
       
   670 }
       
   671 
       
   672 /*!
       
   673 * Connect signals to post-capture view.
       
   674 */
       
   675 void CxuiViewManager::connectPostCaptureSignals()
       
   676 {
       
   677     CX_DEBUG_ENTER_FUNCTION();
       
   678 
       
   679     // Disconnect from the current, "old" view
       
   680     disconnectSignals();
       
   681 
       
   682     CxuiView *view = mViews[POSTCAPTURE_VIEW];
       
   683     if (view) {
       
   684         connect(view, SIGNAL(changeToPrecaptureView()), this, SLOT(changeToPrecaptureView()), Qt::UniqueConnection);
   708 
   685 
   709         // Standby signals
   686         // Standby signals
   710         connect(this, SIGNAL(normalStateEntered()), currentView, SLOT(exitStandby()), Qt::UniqueConnection);
   687         connect(this, SIGNAL(normalStateEntered()), view, SLOT(exitStandby()), Qt::UniqueConnection);
   711         connect(this, SIGNAL(normalStateExited()), currentView, SLOT(enterStandby()), Qt::UniqueConnection);
   688         connect(this, SIGNAL(normalStateExited()), view, SLOT(enterStandby()), Qt::UniqueConnection);
   712     }
   689 
   713 
   690         // connect necessary capturekey signals
   714     CX_DEBUG_EXIT_FUNCTION();
   691         connectCaptureKeySignals(view);
   715 }
   692     }
   716 
   693     CX_DEBUG_EXIT_FUNCTION();
   717 /*!
   694 }
   718 * Connect signals to post-capture view.
   695 
   719 */
   696 /*!
   720 void CxuiViewManager::connectPostCaptureSignals()
   697 * Connect signals to scene mode view.
   721 {
   698 */
   722     CX_DEBUG_ENTER_FUNCTION();
   699 void CxuiViewManager::connectSceneModeSignals()
   723 
   700 {
       
   701     CX_DEBUG_ENTER_FUNCTION();
       
   702 
       
   703     // Disconnect from the current, "old" view
   724     disconnectSignals();
   704     disconnectSignals();
   725     QObject *currentView = mMainWindow.currentView();
   705 
   726     if (currentView == mViews[POSTCAPTURE_VIEW]) {
   706     CxuiView *view = mViews[SCENE_MODE_VIEW];
   727         connect(currentView, SIGNAL(changeToPrecaptureView()), this, SLOT(changeToPrecaptureView()), Qt::UniqueConnection);
   707     if (view) {
   728 
   708         // Standby signals for releasing camera
   729         // Standby signals
   709         connect(this, SIGNAL(normalStateEntered()), view, SLOT(exitStandby()));
   730         connect(this, SIGNAL(normalStateEntered()), currentView, SLOT(exitStandby()), Qt::UniqueConnection);
   710         connect(this, SIGNAL(normalStateExited()), view, SLOT(enterStandby()));
   731         connect(this, SIGNAL(normalStateExited()), currentView, SLOT(enterStandby()), Qt::UniqueConnection);
   711 
   732 
   712         // Moving back to pre-capture view
   733         // connect necessary capturekey signals
   713         connect(view, SIGNAL(viewCloseEvent()), this, SLOT(changeToPrecaptureView()));
   734         connectCaptureKeySignals();
   714 
   735     }
   715         connectCaptureKeySignals(view);
   736 
   716     }
   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();
   717     CX_DEBUG_EXIT_FUNCTION();
   758 }
   718 }
   759 
   719 
   760 /*!
   720 /*!
   761 * Connect key handler capture key signals.
   721 * Connect key handler capture key signals.
   762 */
   722 */
   763 void CxuiViewManager::connectCaptureKeySignals()
   723 void CxuiViewManager::connectCaptureKeySignals(CxuiView *view)
   764 {
   724 {
   765     CX_DEBUG_ENTER_FUNCTION();
   725     CX_DEBUG_ENTER_FUNCTION();
   766 
   726 
   767     // Disconnect all existing capture key signals
   727     // Disconnect all existing capture key signals
   768     mKeyHandler->disconnect();
   728     mKeyHandler->disconnect();
   769 
   729 
   770     QObject *currentView = mMainWindow.currentView();
   730     if (view) {
   771 
       
   772     if (currentView) {
       
   773         // If the view class does not implement the named slot, the connect will fail
   731         // If the view class does not implement the named slot, the connect will fail
   774         // and output some warnings as debug prints. This is by design.
   732         // and output some warnings as debug prints. This is by design.
   775         connect(mKeyHandler, SIGNAL(autofocusKeyPressed()),  currentView, SLOT(handleAutofocusKeyPressed()));
   733         connect(mKeyHandler, SIGNAL(autofocusKeyPressed()),  view, SLOT(handleAutofocusKeyPressed()));
   776         connect(mKeyHandler, SIGNAL(autofocusKeyReleased()), currentView, SLOT(handleAutofocusKeyReleased()));
   734         connect(mKeyHandler, SIGNAL(autofocusKeyReleased()), view, SLOT(handleAutofocusKeyReleased()));
   777         connect(mKeyHandler, SIGNAL(captureKeyPressed()),    currentView, SLOT(handleCaptureKeyPressed()));
   735         connect(mKeyHandler, SIGNAL(captureKeyPressed()),    view, SLOT(handleCaptureKeyPressed()));
   778         connect(mKeyHandler, SIGNAL(captureKeyReleased()),   currentView, SLOT(handleCaptureKeyReleased()));
   736         connect(mKeyHandler, SIGNAL(captureKeyReleased()),   view, SLOT(handleCaptureKeyReleased()));
   779     }
   737     }
   780 
   738 
   781     CX_DEBUG_EXIT_FUNCTION();
   739     CX_DEBUG_EXIT_FUNCTION();
   782 }
   740 }
   783 
   741