camerauis/cameraxui/cxui/src/cxuiviewmanager.cpp
changeset 40 2922f70fca82
parent 39 c5025ea871a1
child 37 64817133cd1d
equal deleted inserted replaced
39:c5025ea871a1 40:2922f70fca82
    74 
    74 
    75     // Application monitor
    75     // Application monitor
    76     mApplicationMonitor = new CxuiApplicationFrameworkMonitor(mApplication, mEngine.settings());
    76     mApplicationMonitor = new CxuiApplicationFrameworkMonitor(mApplication, mEngine.settings());
    77     connect(mApplicationMonitor, SIGNAL(foregroundStateChanged(CxuiApplicationFrameworkMonitor::ForegroundState)),
    77     connect(mApplicationMonitor, SIGNAL(foregroundStateChanged(CxuiApplicationFrameworkMonitor::ForegroundState)),
    78             this, SLOT(handleForegroundStateChanged(CxuiApplicationFrameworkMonitor::ForegroundState)));
    78             this, SLOT(handleForegroundStateChanged(CxuiApplicationFrameworkMonitor::ForegroundState)));
    79     connect(mApplicationMonitor, SIGNAL(batteryEmpty()),
    79     connect(mApplicationMonitor, SIGNAL(batteryEmpty()), this, SLOT(handleBatteryEmpty()));
    80             this, SLOT(handleBatteryEmpty()));
    80     connect(mApplicationMonitor, SIGNAL(usbMassMemoryModeToggled(bool)), this, SLOT(showUsbErrorPopup(bool)));
    81 
    81 
    82     // Connect memory monitor start / stop to focused status
    82     // Connect memory monitor start / stop to focused status
    83     connect(this, SIGNAL(focusGained()), &mEngine.memoryMonitor(), SLOT(startMonitoring()));
    83     connect(this, SIGNAL(focusGained()), &mEngine.memoryMonitor(), SLOT(startMonitoring()));
    84     connect(this, SIGNAL(focusLost()),   &mEngine.memoryMonitor(), SLOT(stopMonitoring()));
    84     connect(this, SIGNAL(focusLost()),   &mEngine.memoryMonitor(), SLOT(stopMonitoring()));
    85 
    85 
   102     mErrorManager = new CxuiErrorManager(*mKeyHandler, mCameraDocumentLoader);
   102     mErrorManager = new CxuiErrorManager(*mKeyHandler, mCameraDocumentLoader);
   103 
   103 
   104     // connecting necessary signals from error manager to release and init camera.
   104     // connecting necessary signals from error manager to release and init camera.
   105     connect(mErrorManager, SIGNAL(aboutToRecoverError()), this, SLOT(aboutToLooseFocus()));
   105     connect(mErrorManager, SIGNAL(aboutToRecoverError()), this, SLOT(aboutToLooseFocus()));
   106     connect(mErrorManager, SIGNAL(errorRecovered()), this, SLOT(aboutToGainFocus()));
   106     connect(mErrorManager, SIGNAL(errorRecovered()), this, SLOT(aboutToGainFocus()));
       
   107 
       
   108     //connecting initmode signals
       
   109     connect(&mEngine.cameraDeviceControl(), SIGNAL(initModeComplete(CxeError::Id)),
       
   110             this, SLOT(createPostcaptureView()));
       
   111 
       
   112     connect(&mEngine.cameraDeviceControl(), SIGNAL(initModeComplete(CxeError::Id)),
       
   113             mErrorManager, SLOT(showPopup(CxeError::Id)));
       
   114 
       
   115     connect(&mEngine.stillCaptureControl(), SIGNAL(imageCaptured(CxeError::Id, int)),
       
   116             mErrorManager, SLOT(showPopup(CxeError::Id)));
       
   117 
       
   118     // Register stylesheet. It will be automatically destroyed on application
       
   119     // exit.
       
   120     HbStyleLoader::registerFilePath(":/camerax/cxui.css");
       
   121 
       
   122     // 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.
       
   124     initStartupView();
       
   125 
       
   126     CX_DEBUG_EXIT_FUNCTION();
       
   127 }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // CxuiViewManager::~CxuiViewManager
       
   131 //
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 CxuiViewManager::~CxuiViewManager()
       
   135 {
       
   136     CX_DEBUG_ENTER_FUNCTION();
       
   137 
       
   138     delete mCameraDocumentLoader;
       
   139     delete mKeyHandler;
       
   140     delete mApplicationMonitor;
       
   141 
       
   142     CX_DEBUG_EXIT_FUNCTION();
       
   143 }
       
   144 
       
   145 /**
       
   146 * Temporary method to check if camera startup should be proceeded after creating view mananger.
       
   147 */
       
   148 bool CxuiViewManager::proceedStartup()
       
   149 {
       
   150     return !mStandbyHandler->isActive();
       
   151 }
       
   152 
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // CxuiViewManager::prepareWindow
       
   156 //
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 void CxuiViewManager::prepareWindow()
       
   160 {
       
   161     getPrecaptureView(mEngine.mode(), mEngine.cameraDeviceControl().cameraIndex())->prepareWindow();
       
   162 }
       
   163 
       
   164 /*!
       
   165 * Check if we need to take special actions in startup.
       
   166 * USB mass memory mode atleast requires us to enter error standby mode,
       
   167 * where user can only exit or fix the issue (remove cable).
       
   168 */
       
   169 void CxuiViewManager::startupCheck()
       
   170 {
       
   171     CX_DEBUG_ENTER_FUNCTION();
       
   172 
       
   173     if (mApplicationMonitor && mApplicationMonitor->isUsbMassMemoryModeActive()) {
       
   174         showUsbErrorPopup(true);
       
   175     }
       
   176 
       
   177     CX_DEBUG_EXIT_FUNCTION();
       
   178 }
       
   179 
       
   180 /*!
       
   181 * Select and initialize the view we need to start into.
       
   182 */
       
   183 void CxuiViewManager::initStartupView()
       
   184 {
       
   185     CX_DEBUG_ENTER_FUNCTION();
   107 
   186 
   108     if (!CxuiServiceProvider::isCameraEmbedded()) {
   187     if (!CxuiServiceProvider::isCameraEmbedded()) {
   109         // For embedded mode: don't create view yet, create
   188         // For embedded mode: don't create view yet, create
   110         // when engine inits to correct mode
   189         // when engine inits to correct mode
   111         CX_DEBUG_ASSERT(mEngine.cameraDeviceControl().cameraIndex() == Cxe::PrimaryCameraIndex);
   190         CX_DEBUG_ASSERT(mEngine.cameraDeviceControl().cameraIndex() == Cxe::PrimaryCameraIndex);
   119             mMainWindow.blockSignals(true);
   198             mMainWindow.blockSignals(true);
   120             mMainWindow.setCurrentView(mStillPrecaptureView, false);
   199             mMainWindow.setCurrentView(mStillPrecaptureView, false);
   121             mMainWindow.blockSignals(false);
   200             mMainWindow.blockSignals(false);
   122         }
   201         }
   123         connectPreCaptureSignals();
   202         connectPreCaptureSignals();
   124     }
   203 
   125 
   204         startupCheck();
   126     //connecting initmode signals
   205     } else {
   127     connect(&mEngine.cameraDeviceControl(), SIGNAL(initModeComplete(CxeError::Id)),
   206         // For embedded mode: don't create view yet, create when engine inits to correct mode.
   128             this, SLOT(createPostcaptureView()));
   207         // Connect signals to set up the view after image/video prepare
   129 
       
   130     connect(&mEngine.cameraDeviceControl(), SIGNAL(initModeComplete(CxeError::Id)),
       
   131             mErrorManager, SLOT(analyze(CxeError::Id)));
       
   132 
       
   133     connect(&mEngine.stillCaptureControl(), SIGNAL(imageCaptured(CxeError::Id, int)),
       
   134             mErrorManager, SLOT(analyze(CxeError::Id)));
       
   135 
       
   136     if (CxuiServiceProvider::isCameraEmbedded()) {
       
   137         // connect signals to set up the view after image/video prepare
       
   138         connect(&mEngine.stillCaptureControl(), SIGNAL(imagePrepareComplete(CxeError::Id)),
   208         connect(&mEngine.stillCaptureControl(), SIGNAL(imagePrepareComplete(CxeError::Id)),
   139                 this, SLOT(changeToPrecaptureView()));
   209                 this, SLOT(changeToPrecaptureView()));
   140         connect(&mEngine.videoCaptureControl(), SIGNAL(videoPrepareComplete(CxeError::Id)),
   210         connect(&mEngine.videoCaptureControl(), SIGNAL(videoPrepareComplete(CxeError::Id)),
   141                 this, SLOT(changeToPrecaptureView()));
   211                 this, SLOT(changeToPrecaptureView()));
   142 
   212 
   143         // start standby timer now because view will not be ready when viewfinder is started
   213         // start standby timer now because view will not be ready when viewfinder is started
   144         mStandbyHandler->startTimer();
   214         mStandbyHandler->startTimer();
   145     }
   215     }
   146 
   216 
   147     // Register stylesheet. It will be automatically destroyed on application
   217     CX_DEBUG_EXIT_FUNCTION();
   148     // exit.
   218 }
   149     HbStyleLoader::registerFilePath(":/camerax/cxui.css");
       
   150 
       
   151     CX_DEBUG_EXIT_FUNCTION();
       
   152 }
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // CxuiViewManager::~CxuiViewManager
       
   156 //
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 CxuiViewManager::~CxuiViewManager()
       
   160 {
       
   161     CX_DEBUG_ENTER_FUNCTION();
       
   162 
       
   163     delete mCameraDocumentLoader;
       
   164     delete mKeyHandler;
       
   165     delete mApplicationMonitor;
       
   166 
       
   167     CX_DEBUG_EXIT_FUNCTION();
       
   168 }
       
   169 
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // CxuiViewManager::prepareWindow
       
   173 //
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CxuiViewManager::prepareWindow()
       
   177 {
       
   178     getPrecaptureView(mEngine.mode(), mEngine.cameraDeviceControl().cameraIndex())->prepareWindow();
       
   179 }
       
   180 
       
   181 
   219 
   182 // ---------------------------------------------------------------------------
   220 // ---------------------------------------------------------------------------
   183 // CxuiViewManager::createStillPrecaptureView
   221 // CxuiViewManager::createStillPrecaptureView
   184 //
   222 //
   185 // ---------------------------------------------------------------------------
   223 // ---------------------------------------------------------------------------
   413                 this, SLOT(changeToPrecaptureView()));
   451                 this, SLOT(changeToPrecaptureView()));
   414         disconnect(&mEngine.videoCaptureControl(), SIGNAL(videoPrepareComplete(CxeError::Id)),
   452         disconnect(&mEngine.videoCaptureControl(), SIGNAL(videoPrepareComplete(CxeError::Id)),
   415                 this, SLOT(changeToPrecaptureView()));
   453                 this, SLOT(changeToPrecaptureView()));
   416     }
   454     }
   417 
   455 
   418     HbView *view = getPrecaptureView(mEngine.mode(),
   456     // If standby mode is active, don't switch to precapture view and reserve camera now.
   419         mEngine.cameraDeviceControl().cameraIndex());
   457     if (mStandbyHandler->isActive()) {
   420 
   458         CX_DEBUG(("CxuiViewManager - Change to precapture blocked as standby mode still active."));
   421     mMainWindow.blockSignals(true);
   459     } else {
   422     mMainWindow.setCurrentView(view, false);
   460         HbView *view = getPrecaptureView(mEngine.mode(),
   423     mMainWindow.blockSignals(false);
   461             mEngine.cameraDeviceControl().cameraIndex());
   424 
   462 
   425     if (mSceneModeView){
   463         mMainWindow.blockSignals(true);
   426         delete mSceneModeView;
   464         mMainWindow.setCurrentView(view, false);
   427         mSceneModeView = NULL;
   465         mMainWindow.blockSignals(false);
   428     }
   466 
   429     // connecting necessary pre-capture view signals
   467         if (mSceneModeView){
   430     connectPreCaptureSignals();
   468             delete mSceneModeView;
   431     emit startStandbyTimer();
   469             mSceneModeView = NULL;
   432 
   470         }
       
   471         // connecting necessary pre-capture view signals
       
   472         connectPreCaptureSignals();
       
   473         emit startStandbyTimer();
       
   474     }
   433     CX_DEBUG_EXIT_FUNCTION();
   475     CX_DEBUG_EXIT_FUNCTION();
   434 }
   476 }
   435 
   477 
   436 // ---------------------------------------------------------------------------
   478 // ---------------------------------------------------------------------------
   437 // CxuiViewManager::switchCamera
   479 // CxuiViewManager::switchCamera
   565         connect(currentView, SIGNAL(showScenesView()), this, SLOT(showScenesView()), Qt::UniqueConnection);
   607         connect(currentView, SIGNAL(showScenesView()), this, SLOT(showScenesView()), Qt::UniqueConnection);
   566 
   608 
   567         connect(currentView, SIGNAL(switchCamera()), this, SLOT(switchCamera()), Qt::UniqueConnection);
   609         connect(currentView, SIGNAL(switchCamera()), this, SLOT(switchCamera()), Qt::UniqueConnection);
   568 
   610 
   569         // connecting error signals from precapture view to errormanager.
   611         // connecting error signals from precapture view to errormanager.
   570         connect(currentView, SIGNAL(reportError(CxeError::Id)),   mErrorManager, SLOT(analyze(CxeError::Id)), Qt::UniqueConnection);
   612         connect(currentView, SIGNAL(reportError(CxeError::Id)),   mErrorManager, SLOT(showPopup(CxeError::Id)), Qt::UniqueConnection);
   571     }
   613     }
   572 
   614 
   573     CX_DEBUG_EXIT_FUNCTION();
   615     CX_DEBUG_EXIT_FUNCTION();
   574 }
   616 }
   575 
   617 
   650         aboutToGainFocus();
   692         aboutToGainFocus();
   651         break;
   693         break;
   652     }
   694     }
   653 }
   695 }
   654 
   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 
   655 // ---------------------------------------------------------------------------
   724 // ---------------------------------------------------------------------------
   656 // CxuiViewManager::aboutToLooseFocus()
   725 // CxuiViewManager::aboutToLooseFocus()
   657 //
   726 //
   658 // ---------------------------------------------------------------------------
   727 // ---------------------------------------------------------------------------
   659 //
   728 //
   679 //
   748 //
   680 void CxuiViewManager::aboutToGainFocus()
   749 void CxuiViewManager::aboutToGainFocus()
   681 {
   750 {
   682     CX_DEBUG_ENTER_FUNCTION();
   751     CX_DEBUG_ENTER_FUNCTION();
   683 
   752 
   684     // Disconnect capture key event and bringing us to foreground connection (if there is one).
   753     // If standby mode is still active, no action is needed yet.
   685     disconnect(mKeyHandler, SIGNAL(captureKeyPressed()), this, SLOT(toForeground()));
   754     // This is the case when USB mass memory mode error is cleared.
   686 
   755     if (mStandbyHandler->isActive()) {
   687     // we are getting the focus.
   756         CX_DEBUG(("CxuiViewManager - Focus gain event ignored as standby mode still active."));
   688     if (mMainWindow.currentView() != mPostcaptureView) {
       
   689         connectPreCaptureSignals();
       
   690     } else {
   757     } else {
   691         connectPostCaptureSignals();
   758 
   692     }
   759         // Disconnect capture key event and bringing us to foreground connection (if there is one).
   693 
   760         disconnect(mKeyHandler, SIGNAL(captureKeyPressed()), this, SLOT(toForeground()));
   694     if (mKeyHandler) {
   761 
   695         mKeyHandler->listenKeys(true);
   762         // we are getting the focus.
   696     }
   763         if (mMainWindow.currentView() != mPostcaptureView) {
   697     emit focusGained();
   764             connectPreCaptureSignals();
       
   765         } else {
       
   766             connectPostCaptureSignals();
       
   767         }
       
   768 
       
   769         if (mKeyHandler) {
       
   770             mKeyHandler->listenKeys(true);
       
   771         }
       
   772         emit focusGained();
       
   773     }
   698 
   774 
   699     CX_DEBUG_EXIT_FUNCTION();
   775     CX_DEBUG_EXIT_FUNCTION();
   700 }
   776 }
   701 
   777 
   702 /*!
   778 /*!