camerauis/cameraxui/cxengine/src/cxeenginesymbian.cpp
changeset 48 42ba2d16bf40
parent 37 64817133cd1d
child 63 415ff50d2eca
--- a/camerauis/cameraxui/cxengine/src/cxeenginesymbian.cpp	Tue Jul 06 14:04:02 2010 +0300
+++ b/camerauis/cameraxui/cxengine/src/cxeenginesymbian.cpp	Wed Aug 18 09:37:18 2010 +0300
@@ -31,7 +31,6 @@
 #include "cxutils.h"
 #include "cxesettingsimp.h"
 #include "cxefeaturemanagerimp.h"
-#include "cxesettingsmodelimp.h"
 #include "cxesettingscenrepstore.h"
 #include "cxesoundplayersymbian.h"
 #include "cxesensoreventhandlersymbian.h"
@@ -40,6 +39,7 @@
 #include "cxememorymonitor.h"
 #include "cxediskmonitor.h"
 #include "cxegeotaggingtrail.h"
+#include "cxeexception.h"
 
 #include "OstTraceDefinitions.h"
 #ifdef OST_TRACE_COMPILER_IN_USE
@@ -61,7 +61,6 @@
       mZoomControl(NULL),
       mSettings(NULL),
       mFeatureManager(NULL),
-      mSettingsModel(NULL),
       mFilenameGenerator(NULL),
       mSensorEventHandler(NULL),
       mQualityPresets(NULL),
@@ -97,8 +96,8 @@
     CX_DEBUG_ENTER_FUNCTION();
 
     // Check we do this only once.
-    if (!mSettingsModel) {
-        OstTrace0(camerax_performance, CXEENGINESYMBIAN_CREATECONTROLS_IN, "e_CX_ENGINE_CREATE_CONTROLS 1");
+    if (!mSettings) {
+        OstTrace0(camerax_performance, CXEENGINESYMBIAN_CREATECONTROLS_IN, "msg: e_CX_ENGINE_CREATE_CONTROLS 1");
 
         CxeCameraDeviceControlSymbian *deviceControl = new CxeCameraDeviceControlSymbian();
         mCameraDeviceControl = deviceControl;
@@ -115,24 +114,23 @@
         } else {
             settingsStore = new CxeSettingsCenRepStore();
         }
-        //ownership of settings store transferred to the settings model.
-        mSettingsModel = new CxeSettingsModelImp(settingsStore);
-        // assert if settings model fails to intialize
-        CX_DEBUG_ASSERT(mSettingsModel);
 
-        mSettings = new CxeSettingsImp(*mSettingsModel);
+        //ownership of settings store transferred to the settings
+        mSettings = new CxeSettingsImp(settingsStore);
 
-        // Loading current camera mode value from settings store and updating 
-		// devicecontrol        
+        // Loading current camera mode value from settings store and updating
+		// devicecontrol
         Cxe::CameraMode cameraMode = Cxe::ImageMode;
-        int value;
-        CxeError::Id err = mSettings->get(CxeSettingIds::CAMERA_MODE, value);
-        if (!err) {
-            cameraMode = static_cast<Cxe::CameraMode>(value);
+
+        try {
+            cameraMode = mSettings->get<Cxe::CameraMode>(CxeSettingIds::CAMERA_MODE);
+        } catch (CxeException &e) {
+            CX_DEBUG(("Failed to read camera mode from settings, using image mode. Error code: %d", e.error()));
         }
+
         // set current camera mode to devicecontrol.
         mCameraDeviceControl->setMode(cameraMode);
-        
+
         //! @todo a temporary hack to change the startup sequence to avoid GOOM problems
         static_cast<CxeSettingsImp*>(mSettings)->loadSettings(mode());
 
@@ -141,7 +139,7 @@
         connect(settingsStore, SIGNAL(settingValueChanged(long int, unsigned long int, QVariant)),
                 mSettings, SIGNAL(settingValueChanged(long int, unsigned long int, QVariant)));
 
-        mFeatureManager = new CxeFeatureManagerImp(*mSettingsModel);
+        mFeatureManager = new CxeFeatureManagerImp(*mSettings);
 
         // Memory monitor needed as early as possible to request free memory.
         // Note: Throws error if enough memory cannot be freed!
@@ -163,7 +161,7 @@
 
         mSnapshotControl = new CxeSnapshotControl(*mCameraDevice);
 
-        mAutoFocusControl = new CxeAutoFocusControlSymbian(*mCameraDevice, 
+        mAutoFocusControl = new CxeAutoFocusControlSymbian(*mCameraDevice,
 		                            *mSettings);
 
         mFileSaveThread = CxeFileSaveThreadFactory::createFileSaveThread();
@@ -186,7 +184,7 @@
                                                   *mVideoCaptureControl,
                                                   *mSettings);
 
-        OstTrace0(camerax_performance, CXEENGINESYMBIAN_CREATECONTROLS_OUT, "e_CX_ENGINE_CREATE_CONTROLS 0");
+        OstTrace0(camerax_performance, CXEENGINESYMBIAN_CREATECONTROLS_OUT, "msg: e_CX_ENGINE_CREATE_CONTROLS 0");
     }
 
     CX_DEBUG_EXIT_FUNCTION();
@@ -198,13 +196,11 @@
 void CxeEngineSymbian::connectSignals()
 {
     CX_DEBUG_ENTER_FUNCTION();
-    OstTrace0(camerax_performance, CXEENGINESYMBIAN_CONNECTSIGNALS_IN, "e_CX_ENGINE_CONNECT_SIGNALS 1");
+    OstTrace0(camerax_performance, CXEENGINESYMBIAN_CONNECTSIGNALS_IN, "msg: e_CX_ENGINE_CONNECT_SIGNALS 1");
 
     // enabling scene setting change callbacks to Autofocus control
-    connect(mSettings,
-            SIGNAL(sceneChanged(CxeScene&)),
-            mAutoFocusControl,
-            SLOT(handleSceneChanged(CxeScene&)));
+    mSettings->listenForSetting(CxeSettingIds::IMAGE_SCENE_DATA, mAutoFocusControl, SLOT(handleSceneChanged(const QVariant&)));
+    mSettings->listenForSetting(CxeSettingIds::VIDEO_SCENE_DATA, mAutoFocusControl, SLOT(handleSceneChanged(const QVariant&)));
 
     // connecting Autofocus state change callbacks to stillcapturecontrol
     connect(mAutoFocusControl,
@@ -272,7 +268,6 @@
             mFileSaveThread,
             SLOT(handleSnapshotReady(CxeError::Id, const QImage&, const QString&)));
 
-
     // stop location trail when releasing camera.
     connect(mCameraDevice,
             SIGNAL(prepareForRelease()),
@@ -280,7 +275,30 @@
             SLOT(stop()),
             Qt::UniqueConnection);
 
-    OstTrace0(camerax_performance, CXEENGINESYMBIAN_CONNECTSIGNALS_OUT, "e_CX_ENGINE_CONNECT_SIGNALS 0");
+    // Use MCameraUseCaseHint API before calling Reserve()
+    connect(mCameraDevice,
+            SIGNAL(aboutToReserve()),
+            mStillCaptureControl,
+            SLOT(hintUseCase()),
+            Qt::UniqueConnection);
+    connect(mCameraDevice,
+            SIGNAL(aboutToReserve()),
+            mVideoCaptureControl,
+            SLOT(hintUseCase()),
+            Qt::UniqueConnection);
+
+    // Start / stop geotagging based on mode.
+    // Do this later to reduce startup time.
+    connect(mStillCaptureControl,
+            SIGNAL(imagePrepareComplete(CxeError::Id)),
+            this,
+            SLOT(initGeotagging()));
+    connect(mVideoCaptureControl,
+            SIGNAL(videoPrepareComplete(CxeError::Id)),
+            this,
+            SLOT(initGeotagging()));
+
+    OstTrace0(camerax_performance, CXEENGINESYMBIAN_CONNECTSIGNALS_OUT, "msg: e_CX_ENGINE_CONNECT_SIGNALS 0");
 
     CX_DEBUG_EXIT_FUNCTION();
 }
@@ -288,10 +306,10 @@
 CxeEngineSymbian::~CxeEngineSymbian()
 {
     CX_DEBUG_ENTER_FUNCTION();
-    
+
     // Saving current camera mode to cenrep
     saveMode();
-    
+
     delete mGeoTaggingTrail;
     delete mAutoFocusControl;
     delete mZoomControl;
@@ -305,7 +323,6 @@
     delete mMemoryMonitor;
     delete mFeatureManager;
     delete mSettings;
-    delete mSettingsModel;
     delete mCameraDeviceControl;
     delete mQualityPresets;
     delete mFileSaveThread;
@@ -356,7 +373,7 @@
     return *mSettings;
 }
 
-/*! 
+/*!
 Returns the sensor event  handle
 */
 CxeSensorEventHandler &CxeEngineSymbian::sensorEventHandler()
@@ -415,7 +432,7 @@
 void CxeEngineSymbian::doInit()
 {
     CX_DEBUG_ENTER_FUNCTION();
-    OstTrace0(camerax_performance, CXEENGINESYMBIAN_DOINIT_IN, "e_CX_ENGINE_DO_INIT 1");
+    OstTrace0(camerax_performance, CXEENGINESYMBIAN_DOINIT_IN, "msg: e_CX_ENGINE_DO_INIT 1");
 
     mFilenameGenerator->init(mode());
     // load settings whenever we change mode or start camera or switch camera
@@ -425,20 +442,14 @@
     }
 
     if (mode() == Cxe::ImageMode) {
-        // start geotagging trail in image mode.
-        startGeotaggingTrail();
         mVideoCaptureControl->deinit();
         mStillCaptureControl->init();
     } else if (mode() == Cxe::VideoMode) {
         mStillCaptureControl->deinit();
-        if (mGeoTaggingTrail) {
-            // in video mode, Geotagging is not supported for now.
-            mGeoTaggingTrail->stop();
-        }
         mVideoCaptureControl->init();
     }
 
-    OstTrace0(camerax_performance, CXEENGINESYMBIAN_DOINIT_OUT, "e_CX_ENGINE_DO_INIT 0");
+    OstTrace0(camerax_performance, CXEENGINESYMBIAN_DOINIT_OUT, "msg: e_CX_ENGINE_DO_INIT 0");
 
     CX_DEBUG_EXIT_FUNCTION();
 }
@@ -526,6 +537,7 @@
 void CxeEngineSymbian::initMode(Cxe::CameraMode cameraMode)
 {
     CX_DEBUG_ENTER_FUNCTION();
+    OstTrace0(camerax_performance, CXEENGINE_INITMODE_IN, "msg: e_CX_ENGINE_INIT_MODE 1");
 
     if (mode() == cameraMode) {
         CX_DEBUG(("initMode() called for current mode"));
@@ -577,12 +589,14 @@
         }
     }
 
+    OstTrace0(camerax_performance, CXEENGINE_INITMODE_OUT, "msg: e_CX_ENGINE_INIT_MODE 0");
     CX_DEBUG_EXIT_FUNCTION();
 }
 
 void CxeEngineSymbian::reserve()
 {
     CX_DEBUG_ENTER_FUNCTION();
+    // Start reserving camera HW.
     mCameraDeviceControl->reserve();
     emit reserveStarted();
     CX_DEBUG_EXIT_FUNCTION();
@@ -597,8 +611,11 @@
     CX_DEBUG_ENTER_FUNCTION();
 
     if (mCameraDeviceControl && mSettings) {
-        int value = mCameraDeviceControl->mode();
-        mSettings->set(CxeSettingIds::CAMERA_MODE, value);
+        try {
+            mSettings->set(CxeSettingIds::CAMERA_MODE, mCameraDeviceControl->mode());
+        } catch (CxeException &e) {
+            CX_DEBUG(("Failed to save camera mode, error=%d", e.error()));
+        }
     }
 
     CX_DEBUG_EXIT_FUNCTION();
@@ -606,23 +623,32 @@
 
 
 /*!
-* Start geotagging trail.
+* Initialize geotagging.
+* Check if we are allowed to start the geotagging and if it's supported in current mode.
 */
-void CxeEngineSymbian::startGeotaggingTrail()
+void CxeEngineSymbian::initGeotagging()
 {
     CX_DEBUG_ENTER_FUNCTION();
-    
+    OstTrace0(camerax_performance, CXEENGINE_START_GEO_IN, "msg: e_CX_ENGINE_START_GEOTAGGING 1");
+
     if (mGeoTaggingTrail && mSettings) {
-        // location trail is limited to image mode only for now.
-        int value = Cxe::GeoTaggingDisclaimerDisabled;
-        mSettings->get(CxeSettingIds::GEOTAGGING_DISCLAIMER, value);
+        if (mode() == Cxe::ImageMode) {
+            // Location trail is limited to image mode only for now.
+            Cxe::GeoTaggingDisclaimer value =
+                mSettings->get<Cxe::GeoTaggingDisclaimer>(
+                    CxeSettingIds::GEOTAGGING_DISCLAIMER, Cxe::GeoTaggingDisclaimerDisabled);
 
-        // we start location trail only when Geotagging First-time-use note is accepted by user.
-        if (value == Cxe::GeoTaggingDisclaimerDisabled) {
-            mGeoTaggingTrail->start();
+            // we start location trail only when Geotagging First-time-use note is accepted by user.
+            if (value == Cxe::GeoTaggingDisclaimerDisabled) {
+                mGeoTaggingTrail->start();
+            }
+        } else {
+            // Geotagging is not (yet) supported in video mode.
+            mGeoTaggingTrail->stop();
         }
     }
-    
+
+    OstTrace0(camerax_performance, CXEENGINE_START_GEO_OUT, "msg: e_CX_ENGINE_START_GEOTAGGING 0");
     CX_DEBUG_EXIT_FUNCTION();
 }