diff -r 0e652f8f1fbd -r 24fd82631616 camerauis/cameraxui/cxui/src/cxuiviewmanager.cpp --- a/camerauis/cameraxui/cxui/src/cxuiviewmanager.cpp Thu Jul 15 01:55:05 2010 +0300 +++ b/camerauis/cameraxui/cxui/src/cxuiviewmanager.cpp Fri Jul 23 11:35:41 2010 +0300 @@ -21,6 +21,7 @@ #include #include #include +#include #include "cxuiapplication.h" #include "cxuiapplicationstate.h" @@ -163,7 +164,7 @@ Q_UNUSED(oldState); CX_DEBUG_ENTER_FUNCTION(); - CxuiView *view = qobject_cast(mMainWindow.currentView()); + CxuiView *view = currentView(); CX_DEBUG(("CxuiViewManager - current view %d", view)); switch (newState) { @@ -209,7 +210,7 @@ { CX_DEBUG_ENTER_FUNCTION(); // Store view that is active now. - CxuiView *view = qobject_cast(mMainWindow.currentView()); + CxuiView *view = currentView(); CX_DEBUG(("CxuiViewManager - current view %d", view)); // Emit signal so current view can enter standby. @@ -250,7 +251,6 @@ CxuiView* CxuiViewManager::currentView() const { CxuiView *view = qobject_cast (mMainWindow.currentView()); - CX_ASSERT_ALWAYS(view); return view; } @@ -261,7 +261,12 @@ { CX_DEBUG_ENTER_FUNCTION(); - if (mApplication.activateReason() == Hb::ActivationReasonService) { + if (mApplication.activateReason() == Hb::ActivationReasonService || + // @todo: There's a bug in orbit and we never get Hb::ActivationReasonService as + // activation reason. Use XQServiceUtil to determine if starting service as + // a workaround for now + XQServiceUtil::isService()) { + // For embedded mode: don't create view yet, create when engine inits to correct mode. // Connect signals to set up the view after image/video prepare connect(&mEngine.stillCaptureControl(), SIGNAL(imagePrepareComplete(CxeError::Id)), @@ -290,16 +295,12 @@ } CxuiView *view = createView(viewName); - mMainWindow.setCurrentView(view, false); - if (preCapture) { - connectPreCaptureSignals(); + connectPreCaptureSignals(static_cast(view)); } else { connectPostCaptureSignals(); } - - // Check the current application state, signalled to handleApplicationStateChanged. - mApplicationState->startMonitoring(); + mMainWindow.setCurrentView(view, false); // restore view from activity bool ok = mApplication.activityManager()->waitActivity(); @@ -317,16 +318,15 @@ } else { view = createView(STILL_PRE_CAPTURE_VIEW); } - + connectPreCaptureSignals(static_cast(view)); mMainWindow.setCurrentView(view, false); - connectPreCaptureSignals(); - - // Check the current application state, signalled to handleApplicationStateChanged. - mApplicationState->startMonitoring(); clearAllActivities(); } + // Check the current application state, signalled to handleApplicationStateChanged. + mApplicationState->startMonitoring(); + CX_DEBUG_EXIT_FUNCTION(); } @@ -393,9 +393,9 @@ CX_ASSERT_ALWAYS(view); view->loadBackgroundImages(); - mMainWindow.setCurrentView(view, false); stopStandbyTimer(); connectSceneModeSignals(); + mMainWindow.setCurrentView(view, false); CX_DEBUG_EXIT_FUNCTION(); } @@ -435,8 +435,6 @@ CxuiView *postCaptureView = createView(POSTCAPTURE_VIEW); - mMainWindow.setCurrentView(postCaptureView, false); - // Connecting all necessary signals for postcapture view. // Not connected yet if not in normal state. We connect the signals // once we enter normal state again. @@ -444,6 +442,11 @@ connectPostCaptureSignals(); } + // Connect signals before we set the post-capture view as current view. + // We need to have signals connected if post-capture view for example + // needs to move back to pre-capture view already in showEvent. + mMainWindow.setCurrentView(postCaptureView, false); + CX_DEBUG_EXIT_FUNCTION(); } @@ -470,8 +473,12 @@ // Disconnect signals from old view. disconnectSignals(); - HbView *view = getPrecaptureView(mEngine.mode(), - mEngine.cameraDeviceControl().cameraIndex()); + CxuiPrecaptureView *view = + getPrecaptureView(mEngine.mode(), mEngine.cameraDeviceControl().cameraIndex()); + + // Connect necessary pre-capture view signals. + connectPreCaptureSignals(view); + mMainWindow.setCurrentView(view, false); // Release resources needed by scene view. @@ -484,9 +491,6 @@ sceneView = NULL; } - // connecting necessary pre-capture view signals - connectPreCaptureSignals(); - // Make sure engine prepares for new image/video if necessary mEngine.initMode(mEngine.mode()); @@ -515,11 +519,10 @@ } CxuiPrecaptureView* view = getPrecaptureView(mEngine.mode(), nextCamera); + connectPreCaptureSignals(view); mMainWindow.setCurrentView(view, false); view->updateOrientation(nextViewOrientation); - connectPreCaptureSignals(); - mEngine.cameraDeviceControl().switchCamera(nextCamera); CX_DEBUG_EXIT_FUNCTION(); @@ -577,7 +580,7 @@ /*! * Connect signals specific to given view. */ -void CxuiViewManager::connectSignals(QObject *view) +void CxuiViewManager::connectSignals(CxuiView *view) { CX_DEBUG_ENTER_FUNCTION(); OstTrace0(camerax_performance, CXUIVIEWMANAGER_CONNECTSIGNALS_1, "msg: e_CX_VIEWMANAGER_CONNECT_SIGNALS 1"); @@ -588,7 +591,7 @@ } else if (view == mViews[SCENE_MODE_VIEW]) { connectSceneModeSignals(); } else { - connectPreCaptureSignals(); + connectPreCaptureSignals(static_cast(view)); } } @@ -601,7 +604,7 @@ * We don't want to send or receive signals with inactive views, so this is done every time changing a view. * @param view View object from which signals are disconnected. If NULL is given, current view is used. */ -void CxuiViewManager::disconnectSignals(QObject *view) +void CxuiViewManager::disconnectSignals(CxuiView *view) { CX_DEBUG_ENTER_FUNCTION(); OstTrace0(camerax_performance, CXUIVIEWMANAGER_DISCONNECT_1, "msg: e_CX_VIEWMANAGER_DISCONNECT_SIGNALS 1"); @@ -611,7 +614,7 @@ if (!view) { // If view is not given, take current view. - view = mMainWindow.currentView(); + view = currentView(); } CX_DEBUG(("CxuiViewManager - disconnecting from view %d", view)); @@ -629,42 +632,39 @@ /*! * Connect signals to pre-capture view. */ -void CxuiViewManager::connectPreCaptureSignals() +void CxuiViewManager::connectPreCaptureSignals(CxuiPrecaptureView *view) { CX_DEBUG_ENTER_FUNCTION(); + // Disconnect from the current, "old" view disconnectSignals(); - HbView *currentView = mMainWindow.currentView(); - - if (currentView != mViews[POSTCAPTURE_VIEW]) { - // connects all capture key signals. - connectCaptureKeySignals(); + // connecting pre-capture view signals to standby timer. + connect(view, SIGNAL(startStandbyTimer()), this, SLOT(startStandbyTimer()), Qt::UniqueConnection); + connect(view, SIGNAL(stopStandbyTimer()), this, SLOT(stopStandbyTimer()), Qt::UniqueConnection); + connect(view, SIGNAL(changeToPrecaptureView()), this, SLOT(startStandbyTimer()), Qt::UniqueConnection); + connect(view, SIGNAL(changeToPostcaptureView()), this, SLOT(stopStandbyTimer()), Qt::UniqueConnection); - // connecting pre-capture view signals to standby timer. - connect(currentView, SIGNAL(startStandbyTimer()), this, SLOT(startStandbyTimer()), Qt::UniqueConnection); - connect(currentView, SIGNAL(stopStandbyTimer()), this, SLOT(stopStandbyTimer()), Qt::UniqueConnection); - connect(currentView, SIGNAL(changeToPrecaptureView()), this, SLOT(startStandbyTimer()), Qt::UniqueConnection); - connect(currentView, SIGNAL(changeToPostcaptureView()), this, SLOT(stopStandbyTimer()), Qt::UniqueConnection); + // connecting pre-capture view signals to viewmanager slots + connect(view, SIGNAL(changeToPostcaptureView()), this, SLOT(changeToPostcaptureView()), Qt::UniqueConnection); + connect(view, SIGNAL(changeToPrecaptureView()), this, SLOT(changeToPrecaptureView()), Qt::UniqueConnection); + + //connecting scene modes signal + connect(view, SIGNAL(showScenesView()), this, SLOT(showScenesView()), Qt::UniqueConnection); - // connecting pre-capture view signals to viewmanager slots - connect(currentView, SIGNAL(changeToPostcaptureView()), this, SLOT(changeToPostcaptureView()), Qt::UniqueConnection); - connect(currentView, SIGNAL(changeToPrecaptureView()), this, SLOT(changeToPrecaptureView()), Qt::UniqueConnection); + connect(view, SIGNAL(switchCamera()), this, SLOT(switchCamera()), Qt::UniqueConnection); - //connecting scene modes signal - connect(currentView, SIGNAL(showScenesView()), this, SLOT(showScenesView()), Qt::UniqueConnection); - - connect(currentView, SIGNAL(switchCamera()), this, SLOT(switchCamera()), Qt::UniqueConnection); + // connecting error signals from precapture view to application state. + connect(view, SIGNAL(errorEncountered(CxeError::Id)), + mApplicationState, SLOT(handleApplicationError(CxeError::Id)), + Qt::UniqueConnection); - // connecting error signals from precapture view to application state. - connect(currentView, SIGNAL(errorEncountered(CxeError::Id)), - mApplicationState, SLOT(handleApplicationError(CxeError::Id)), - Qt::UniqueConnection); + // Standby signals + connect(this, SIGNAL(normalStateEntered()), view, SLOT(exitStandby()), Qt::UniqueConnection); + connect(this, SIGNAL(normalStateExited()), view, SLOT(enterStandby()), Qt::UniqueConnection); - // Standby signals - connect(this, SIGNAL(normalStateEntered()), currentView, SLOT(exitStandby()), Qt::UniqueConnection); - connect(this, SIGNAL(normalStateExited()), currentView, SLOT(enterStandby()), Qt::UniqueConnection); - } + // connects all capture key signals. + connectCaptureKeySignals(view); CX_DEBUG_EXIT_FUNCTION(); } @@ -676,20 +676,20 @@ { CX_DEBUG_ENTER_FUNCTION(); + // Disconnect from the current, "old" view disconnectSignals(); - QObject *currentView = mMainWindow.currentView(); - if (currentView == mViews[POSTCAPTURE_VIEW]) { - connect(currentView, SIGNAL(changeToPrecaptureView()), this, SLOT(changeToPrecaptureView()), Qt::UniqueConnection); + CxuiView *view = mViews[POSTCAPTURE_VIEW]; + if (view) { + connect(view, SIGNAL(changeToPrecaptureView()), this, SLOT(changeToPrecaptureView()), Qt::UniqueConnection); // Standby signals - connect(this, SIGNAL(normalStateEntered()), currentView, SLOT(exitStandby()), Qt::UniqueConnection); - connect(this, SIGNAL(normalStateExited()), currentView, SLOT(enterStandby()), Qt::UniqueConnection); + connect(this, SIGNAL(normalStateEntered()), view, SLOT(exitStandby()), Qt::UniqueConnection); + connect(this, SIGNAL(normalStateExited()), view, SLOT(enterStandby()), Qt::UniqueConnection); // connect necessary capturekey signals - connectCaptureKeySignals(); + connectCaptureKeySignals(view); } - CX_DEBUG_EXIT_FUNCTION(); } @@ -699,20 +699,20 @@ void CxuiViewManager::connectSceneModeSignals() { CX_DEBUG_ENTER_FUNCTION(); + + // Disconnect from the current, "old" view disconnectSignals(); - HbView *currentView = mMainWindow.currentView(); - - if (currentView == mViews[SCENE_MODE_VIEW]) { - - connectCaptureKeySignals(); - + CxuiView *view = mViews[SCENE_MODE_VIEW]; + if (view) { // Standby signals for releasing camera - connect(this, SIGNAL(normalStateEntered()), currentView, SLOT(exitStandby())); - connect(this, SIGNAL(normalStateExited()), currentView, SLOT(enterStandby())); + connect(this, SIGNAL(normalStateEntered()), view, SLOT(exitStandby())); + connect(this, SIGNAL(normalStateExited()), view, SLOT(enterStandby())); // Moving back to pre-capture view - connect(currentView, SIGNAL(viewCloseEvent()), this, SLOT(changeToPrecaptureView())); + connect(view, SIGNAL(viewCloseEvent()), this, SLOT(changeToPrecaptureView())); + + connectCaptureKeySignals(view); } CX_DEBUG_EXIT_FUNCTION(); } @@ -720,22 +720,20 @@ /*! * Connect key handler capture key signals. */ -void CxuiViewManager::connectCaptureKeySignals() +void CxuiViewManager::connectCaptureKeySignals(CxuiView *view) { CX_DEBUG_ENTER_FUNCTION(); // Disconnect all existing capture key signals mKeyHandler->disconnect(); - QObject *currentView = mMainWindow.currentView(); - - if (currentView) { + if (view) { // If the view class does not implement the named slot, the connect will fail // and output some warnings as debug prints. This is by design. - connect(mKeyHandler, SIGNAL(autofocusKeyPressed()), currentView, SLOT(handleAutofocusKeyPressed())); - connect(mKeyHandler, SIGNAL(autofocusKeyReleased()), currentView, SLOT(handleAutofocusKeyReleased())); - connect(mKeyHandler, SIGNAL(captureKeyPressed()), currentView, SLOT(handleCaptureKeyPressed())); - connect(mKeyHandler, SIGNAL(captureKeyReleased()), currentView, SLOT(handleCaptureKeyReleased())); + connect(mKeyHandler, SIGNAL(autofocusKeyPressed()), view, SLOT(handleAutofocusKeyPressed())); + connect(mKeyHandler, SIGNAL(autofocusKeyReleased()), view, SLOT(handleAutofocusKeyReleased())); + connect(mKeyHandler, SIGNAL(captureKeyPressed()), view, SLOT(handleCaptureKeyPressed())); + connect(mKeyHandler, SIGNAL(captureKeyReleased()), view, SLOT(handleCaptureKeyReleased())); } CX_DEBUG_EXIT_FUNCTION();