camerauis/cameraxui/cxengine/src/cxesettingsimp.cpp
changeset 48 42ba2d16bf40
parent 37 64817133cd1d
child 52 7e18d488ac5f
equal deleted inserted replaced
37:64817133cd1d 48:42ba2d16bf40
    20 
    20 
    21 #include <QCoreApplication>
    21 #include <QCoreApplication>
    22 #include <QVariant>
    22 #include <QVariant>
    23 #include <QList>
    23 #include <QList>
    24 #include <QMetaType>
    24 #include <QMetaType>
    25 #include <ecam.h>
       
    26 #include <ecamadvsettingsuids.hrh>
       
    27 #include <ecamadvsettings.h>
       
    28 #include <QObject>
    25 #include <QObject>
    29 
    26 
    30 #include "cxesettingsmodel.h"
       
    31 #include "cxesettingsimp.h"
    27 #include "cxesettingsimp.h"
    32 #include "cxesettings.h"
       
    33 #include "cxutils.h"
    28 #include "cxutils.h"
    34 #include "cxenamespace.h"
    29 #include "cxenamespace.h"
    35 #include "cxeerror.h"
    30 #include "cxeerror.h"
    36 
    31 #include "cxesettingsstore.h"
       
    32 #include "cxeexception.h"
       
    33 
       
    34 #ifdef Q_OS_SYMBIAN
    37 #include "OstTraceDefinitions.h"
    35 #include "OstTraceDefinitions.h"
    38 #ifdef OST_TRACE_COMPILER_IN_USE
    36 #ifdef OST_TRACE_COMPILER_IN_USE
    39 #include "cxesettingsimpTraces.h"
    37 #include "cxesettingsimpTraces.h"
    40 #endif
    38 #endif
    41 
    39 #endif // Q_OS_SYMBIAN
    42 
    40 
    43 
    41 
    44 
    42 // signatures for setting listener slots
    45 /*!
    43 const char *SETTING_LISTENER_SIGNATURE1 = "settingChanged(const QString &, const QVariant &)";
    46     Load image/video specific settings during mode change or startup
    44 const char *SETTING_LISTENER_SIGNATURE2 = "settingChanged(const QVariant &)";
    47 */
    45 
    48 void CxeSettingsImp::loadSettings(Cxe::CameraMode mode)
    46 
    49 {
    47 /*
    50     CX_DEBUG_ENTER_FUNCTION();
    48 * CxeSettingsImp::CxeSettingsImp
    51     OstTrace0(camerax_performance, CXESETTINGSIMP_LOADSETTINGS_IN, "msg: e_CX_SETTINGS_LOADSETTINGS 1");
    49 */
    52 
    50 CxeSettingsImp::CxeSettingsImp(CxeSettingsStore *settingStore)
    53 
    51 : mSettingStore(settingStore),
    54     // inform the settings model for the change in mode.
    52   mVariationSettings(),
    55     mSettingsModel.cameraModeChanged(mode);
    53   mSceneModeStore(),
    56 
    54   mCameraMode(Cxe::ImageMode)
    57     if (mode == Cxe::ImageMode) {
    55 {
    58         emit sceneChanged(mSettingsModel.currentImageScene());
    56     CX_DEBUG_ENTER_FUNCTION();
    59     } else {
    57     loadVariationSettings();
    60         emit sceneChanged(mSettingsModel.currentVideoScene());
    58 
    61     }
    59     CX_DEBUG_EXIT_FUNCTION();
    62 
    60 }
    63     OstTrace0(camerax_performance, CXESETTINGSIMP_LOADSETTINGS_OUT, "msg: e_CX_SETTINGS_LOADSETTINGS 0");
    61 
    64     CX_DEBUG_EXIT_FUNCTION();
    62 /*
    65 }
    63 * CxeSettingsImp::close
    66 
    64 */
    67 
    65 CxeSettingsImp::~CxeSettingsImp()
    68 
    66 {
    69 /*!
    67     CX_DEBUG_ENTER_FUNCTION();
    70     Return the current integer setting value for the given key
    68     delete mSettingStore;
    71 */
    69 
    72 CxeError::Id CxeSettingsImp::get(const QString &key, int &value) const
    70     mVariationSettings.clear();
    73 {
    71     CX_DEBUG_EXIT_FUNCTION();
    74     CX_DEBUG_ENTER_FUNCTION();
    72 }
    75 
       
    76     QVariant v;
       
    77     CxeError::Id err = mSettingsModel.getSettingValue(key, v);
       
    78 
       
    79     bool isInt;
       
    80     value = v.toInt(&isInt); // 0 denotes base, check the API
       
    81 
       
    82     if (isInt) {
       
    83         CX_DEBUG(("CxeSettingsImp::get - key: %s value: %d",
       
    84                   key.toAscii().data(), value ));
       
    85     } else {
       
    86         err = CxeError::NotSupported;
       
    87     }
       
    88 
       
    89     CX_DEBUG_EXIT_FUNCTION();
       
    90 
       
    91     return err;
       
    92 }
       
    93 
       
    94 
       
    95 
       
    96 
       
    97 /*!
       
    98     Return the current real setting value for the given key
       
    99 */
       
   100 CxeError::Id CxeSettingsImp::get(const QString &key, qreal &value) const
       
   101 {
       
   102     CX_DEBUG_ENTER_FUNCTION();
       
   103 
       
   104     QVariant v;
       
   105     CxeError::Id err = mSettingsModel.getSettingValue(key, v);
       
   106 
       
   107     bool isReal;
       
   108     value = v.toReal(&isReal);
       
   109 
       
   110     if (isReal) {
       
   111         CX_DEBUG(("CxeSettingsImp::get - key: %s value: %f",
       
   112                   key.toAscii().data(), value ));
       
   113     } else {
       
   114         err = CxeError::NotSupported;
       
   115     }
       
   116 
       
   117     CX_DEBUG_EXIT_FUNCTION();
       
   118 
       
   119     return err;
       
   120 }
       
   121 
       
   122 
       
   123 /*!
       
   124     Return the current string setting value for the given key
       
   125 */
       
   126 CxeError::Id CxeSettingsImp::get(
       
   127         const QString &key, QString &stringValue) const
       
   128 {
       
   129     CX_DEBUG_ENTER_FUNCTION();
       
   130 
       
   131     QVariant value;
       
   132     CxeError::Id err = getSceneMode(key, stringValue);
       
   133 
       
   134     if (err == CxeError::NotFound) {
       
   135         // read from settings store
       
   136         err = mSettingsModel.getSettingValue(key, value);
       
   137         stringValue = value.toString();
       
   138     }
       
   139 
       
   140     CX_DEBUG(("CxeSettingsImp::get - key: %s value: %s",
       
   141               key.toAscii().data(), stringValue.toAscii().data()));
       
   142     CX_DEBUG_EXIT_FUNCTION();
       
   143 
       
   144     return err;
       
   145 }
       
   146 
       
   147 
       
   148 
    73 
   149 /*
    74 /*
   150 * Reads a value from cenrep
    75 * Reads a value from cenrep
   151 * @param key   - setting key
    76 * @param key   - setting key
   152 * @param uid   - setting UID of the component that owns the setting key
    77 * @param uid   - setting UID of the component that owns the setting key
   158                          unsigned long int key,
    83                          unsigned long int key,
   159                          Cxe::SettingKeyType type,
    84                          Cxe::SettingKeyType type,
   160                          QVariant &value) const
    85                          QVariant &value) const
   161 {
    86 {
   162     CX_DEBUG_ENTER_FUNCTION();
    87     CX_DEBUG_ENTER_FUNCTION();
   163 
    88     CX_DEBUG_ASSERT(mSettingStore);
   164     mSettingsModel.getSettingValue(uid, key, type, value);
    89 
   165 
    90     mSettingStore->startMonitoring(uid, key, type, value);
   166     CX_DEBUG_EXIT_FUNCTION();
    91 
   167 
    92     CX_DEBUG_EXIT_FUNCTION();
   168 }
    93 
   169 
    94 }
   170 
    95 
   171 
    96 
   172 /*!
    97 /*!
   173     Get the current scene mode setting value for the given key
    98     Reset static settings (persistent settings)
   174 */
    99 */
   175 CxeError::Id CxeSettingsImp::getSceneMode(
   100 void CxeSettingsImp::reset()
   176         const QString &key, QString &stringValue) const
   101 {
       
   102     CX_DEBUG_ENTER_FUNCTION();
       
   103 
       
   104     CX_DEBUG_ASSERT(mSettingStore);
       
   105     mSettingStore->reset();
       
   106 
       
   107     CX_DEBUG_EXIT_FUNCTION();
       
   108 }
       
   109 
       
   110 /*!
       
   111 * Get the configured run-time value associated with the key.
       
   112 * @Param key - Setting key Id ( refer to CxeSettingIds in cxenums.h )
       
   113 * @Param value - contains the value associated with the key.
       
   114 * @returns CxeError::None if successful or any CxeError specific error code.
       
   115 */
       
   116 CxeError::Id CxeSettingsImp::getVariationValue(const QString &key, QVariant &value)
   177 {
   117 {
   178     CX_DEBUG_ENTER_FUNCTION();
   118     CX_DEBUG_ENTER_FUNCTION();
   179 
   119 
   180     CxeError::Id err = CxeError::None;
   120     CxeError::Id err = CxeError::None;
   181     CxeScene scene;
   121 
   182 
   122     // read run-time configuration value
   183     if(CxeSettingIds::IMAGE_SCENE == key) {
   123     if ( mVariationSettings.contains(key) ) {
   184          scene = mSettingsModel.currentImageScene();
   124         value = qVariantFromValue<QVariantList > (mVariationSettings.value(key));
   185     } else if(CxeSettingIds::VIDEO_SCENE == key) {
       
   186         scene = mSettingsModel.currentVideoScene();
       
   187     } else {
   125     } else {
   188         err = CxeError::NotFound;
   126         err = CxeError::NotFound;
   189     }
   127     }
   190 
   128 
   191     if (err == CxeError::None) {
       
   192         stringValue = scene["sceneId"].toString();
       
   193     }
       
   194 
       
   195     CX_DEBUG(("CxeSettingsImp::get - key: %s value: %s",
       
   196               key.toAscii().data(), stringValue.toAscii().data()));
       
   197 
       
   198     CX_DEBUG_EXIT_FUNCTION();
   129     CX_DEBUG_EXIT_FUNCTION();
   199 
   130 
   200     return err;
   131     return err;
   201 }
   132 }
   202 
   133 
   203 
   134 
   204 /*!
   135 /*!
   205     Set new int value for the given key
   136  * Add listener for changes in one setting. When the value of the setting changes, the given
   206 */
   137  * slot is invoked on given object.
   207 CxeError::Id CxeSettingsImp::set(const QString &key, int newValue)
   138  *
   208 {
   139  * @param settingKey Setting to listen to
   209     CX_DEBUG_ENTER_FUNCTION();
   140  * @param target Object that the slot will be invoked for
   210 
   141  * @param slot Slot that will be invoked. The slot can have either of these two signatures:
   211     CX_DEBUG(("CxeSettingsImp::set - key: %s value: %d",
   142  *   slotName(const QVariant&)    only new value of setting is passed as parameter
   212               key.toAscii().data(), newValue));
   143  *   slotName(const QString&, const QVariant&) both setting key and new value are passed as parameter
   213 
   144  *
   214     CxeError::Id error = mSettingsModel.set(key, newValue);
   145  * @return boolean to indicate success
   215     if (error == CxeError::None) {
   146  *
       
   147  */
       
   148 bool CxeSettingsImp::listenForSetting(const QString &settingKey, QObject *target, const char *slot)
       
   149 {
       
   150 
       
   151     CX_DEBUG_ENTER_FUNCTION();
       
   152     CX_DEBUG_ASSERT(target && slot);
       
   153 
       
   154     // SLOT() macro adds '1' to the beginning of string so we use slot+1 to get the name of the slot
       
   155     CX_DEBUG(("Adding listener %s::%s for key %s", target->metaObject()->className(), slot+1, settingKey.toAscii().data()));
       
   156     QByteArray normalizedSlotName = QMetaObject::normalizedSignature(slot+1);
       
   157 
       
   158     int slotIndex = target->metaObject()->indexOfSlot(normalizedSlotName);
       
   159 
       
   160     bool ok = false;
       
   161     if (slotIndex > -1) {
       
   162         CX_DEBUG(("Slot found, checking signature"));
       
   163         // verify that slot is correct type
       
   164         if (QMetaObject::checkConnectArgs(QMetaObject::normalizedSignature(SETTING_LISTENER_SIGNATURE1), normalizedSlotName) ||
       
   165             QMetaObject::checkConnectArgs(QMetaObject::normalizedSignature(SETTING_LISTENER_SIGNATURE2), normalizedSlotName)) {
       
   166 
       
   167             CX_DEBUG(("Slot signature ok, adding listener"));
       
   168 
       
   169             // check if list for given key already exists
       
   170             if (!mSettingListeners.contains(settingKey)) {
       
   171                 mSettingListeners.insert(settingKey, CxeSettingListenerList());
       
   172             }
       
   173 
       
   174             // get QMetaMethod object
       
   175             QMetaMethod method = target->metaObject()->method(slotIndex);
       
   176             // add listener to the list
       
   177             CxeSettingListenerList& list = mSettingListeners[settingKey];
       
   178             list.append(CxeSettingListener(target, method));
       
   179 
       
   180             // connect to destroyed() signal so we can remove listener if it's deleted
       
   181             connect(target, SIGNAL(destroyed(QObject*)), this, SLOT(handleListenerDestroyed(QObject*)));
       
   182 
       
   183             ok = true;
       
   184         } else {
       
   185             CX_DEBUG(("Slot signature doesn't match, can't add listener"));
       
   186         }
       
   187 
       
   188     } else {
       
   189         CX_DEBUG(("Slot not found, can't add listener"));
       
   190     }
       
   191 
       
   192     CX_DEBUG_EXIT_FUNCTION();
       
   193     return ok;
       
   194 }
       
   195 
       
   196 /*!
       
   197     Load image/video specific settings during mode change or startup
       
   198 */
       
   199 void CxeSettingsImp::loadSettings(Cxe::CameraMode mode)
       
   200 {
       
   201     CX_DEBUG_ENTER_FUNCTION();
       
   202     OstTrace0(camerax_performance, CXESETTINGSIMP_LOADSETTINGS_IN, "msg: e_CX_SETTINGS_LOADSETTINGS 1");
       
   203 
       
   204     mCameraMode = mode;
       
   205 
       
   206     // inform the settings model for the change in mode.
       
   207     if (mode == Cxe::ImageMode) {
       
   208         restoreImageSettings();
       
   209         notifyListeners(CxeSettingIds::IMAGE_SCENE_DATA, mSceneModeStore.currentScene(Cxe::ImageMode));
       
   210         notifyListeners(CxeSettingIds::IMAGE_SCENE, mSceneModeStore.currentSceneId(Cxe::ImageMode));
       
   211         emit settingValueChanged(CxeSettingIds::IMAGE_SCENE, mSceneModeStore.currentSceneId(Cxe::ImageMode));
       
   212     } else {
       
   213         restoreVideoSettings();
       
   214         notifyListeners(CxeSettingIds::VIDEO_SCENE_DATA, mSceneModeStore.currentScene(Cxe::VideoMode));
       
   215         notifyListeners(CxeSettingIds::VIDEO_SCENE, mSceneModeStore.currentSceneId(Cxe::VideoMode));
       
   216         emit settingValueChanged(CxeSettingIds::VIDEO_SCENE, mSceneModeStore.currentSceneId(Cxe::VideoMode));
       
   217     }
       
   218 
       
   219     OstTrace0(camerax_performance, CXESETTINGSIMP_LOADSETTINGS_OUT, "msg: e_CX_SETTINGS_LOADSETTINGS 0");
       
   220     CX_DEBUG_EXIT_FUNCTION();
       
   221 }
       
   222 
       
   223 /*!
       
   224 * Get setting value associated with the key.
       
   225 * @Param key - Setting key Id ( refer to CxeSettingIds in cxenums.h )
       
   226 * @Param value - contains the value associated with the key.
       
   227 * @returns CxeError::None if successful or any CxeError specific error code.
       
   228 */
       
   229 void CxeSettingsImp::getValue(const QString &key, QVariant &value) const
       
   230 {
       
   231     CX_DEBUG_ENTER_FUNCTION();
       
   232     CX_DEBUG_ASSERT(mSettingStore);
       
   233 
       
   234 
       
   235     CxeError::Id err = CxeError::None;
       
   236 
       
   237     // check if getting scene mode
       
   238     if(key == CxeSettingIds::IMAGE_SCENE_DATA) {
       
   239         value = mSceneModeStore.currentScene(Cxe::ImageMode);
       
   240     } else if(key == CxeSettingIds::VIDEO_SCENE_DATA) {
       
   241         value = mSceneModeStore.currentScene(Cxe::VideoMode);
       
   242     } else {
       
   243         // Try first to find the item from cenrep store.
       
   244         err = mSettingStore->get(key, value);
       
   245 
       
   246         // If setting is not in cenrep store, try fetching it from scene settings.
       
   247         if (!err) {
       
   248             CX_DEBUG(("Got value %s from settings store", value.toString().toAscii().data()));
       
   249         } else {
       
   250             // setting not found in setting store, try finding if its scene specific setting.
       
   251             CX_DEBUG(( "fetching value from scene settings" ));
       
   252             err = mSceneModeStore.sceneSettingValue(mCameraMode, key, value);
       
   253         }
       
   254         if (err) {
       
   255             throw CxeException(err);
       
   256         }
       
   257     }
       
   258 
       
   259     CX_DEBUG_EXIT_FUNCTION();
       
   260 
       
   261 }
       
   262 
       
   263 /*!
       
   264 * Set a value to the key.
       
   265 * @Param key - Setting key Id ( refer to CxeSettingIds in cxenums.h )
       
   266 * @Param value - contains the value associated with the key.
       
   267 * @returns CxeError::None if successful or any CxeError specific error code.
       
   268 */
       
   269 void CxeSettingsImp::setValue(const QString &key, const QVariant &newValue)
       
   270 {
       
   271     CX_DEBUG_ENTER_FUNCTION();
       
   272     CX_DEBUG_ASSERT(mSettingStore);
       
   273 
       
   274     CxeError::Id err;
       
   275     // check if setting scene mode
       
   276     if(key == CxeSettingIds::IMAGE_SCENE) {
       
   277         setImageScene(newValue.toString());
       
   278     } else if(key == CxeSettingIds::VIDEO_SCENE) {
       
   279         setVideoScene(newValue.toString());
       
   280     } else if(key == CxeSettingIds::IMAGE_SCENE_DATA || key == CxeSettingIds::VIDEO_SCENE_DATA) {
       
   281         // setting whole scene by value is not supported
       
   282         throw CxeException(CxeError::NotSupported);
       
   283     } else {
       
   284         // Try storing new value to cenrep
       
   285         err = mSettingStore->set(key, newValue);
       
   286 
       
   287         if (err) {
       
   288             CX_DEBUG(( "Key not found in cenrepstore, writing value to scene settings" ));
       
   289             err = mSceneModeStore.setSceneSettingValue(mCameraMode, key, newValue);
       
   290         }
       
   291 
       
   292         if (err) {
       
   293             throw CxeException(err);
       
   294         }
       
   295 
       
   296         // send notifications
   216         emit settingValueChanged(key, newValue);
   297         emit settingValueChanged(key, newValue);
   217     }
   298         notifyListeners(key, newValue);
   218 
   299     }
   219     CX_DEBUG_EXIT_FUNCTION();
   300 
   220 
   301     CX_DEBUG_EXIT_FUNCTION();
   221     return error;
   302 
   222 }
   303 }
   223 
   304 
   224 
   305 /*!
   225 
   306 * Restores image settings, during mode change or during startup.
   226 /*!
   307 */
   227     Set new int value for the given key
   308 void CxeSettingsImp::restoreImageSettings()
   228 */
   309 {
   229 CxeError::Id CxeSettingsImp::set(const QString &key, qreal newValue)
   310     CX_DEBUG_ENTER_FUNCTION();
   230 {
   311 
   231     CX_DEBUG_ENTER_FUNCTION();
   312     QString currentSceneInUse = mSceneModeStore.currentSceneId(Cxe::ImageMode);
   232 
   313 
   233     CX_DEBUG(("CxeSettingsImp::set - key: %s value: %f",
   314     // get the image scene value from cenrep and load the scene settings
   234               key.toAscii().data(), newValue));
   315     QString key(CxeSettingIds::IMAGE_SCENE);
   235 
   316     QString cenrepSceneValue = CxeSettings::get<QString>(key);
   236     CxeError::Id error = mSettingsModel.set(key, newValue);
   317 
   237 
   318     bool ok2LoadSceneSettings = (cenrepSceneValue != currentSceneInUse);
   238     if (error == CxeError::None) {
   319 
   239         emit settingValueChanged(key, newValue);
   320     if (ok2LoadSceneSettings) {
   240     }
   321         // loading scene settings
   241 
   322         mSceneModeStore.setCurrentScene(Cxe::ImageMode, cenrepSceneValue);
   242     CX_DEBUG_EXIT_FUNCTION();
   323     }
   243 
   324 
   244     return error;
   325     // Updating Flash setting from cenrep
   245 }
   326     key = CxeSettingIds::FLASH_MODE;
   246 
   327     int flashMode = CxeSettings::get<int>(key);
   247 
   328 
   248 /*!
   329     // update local datastructure with flash setting value from cenrep.
   249     Set new string value for the given key
   330     CX_DEBUG(( "flash setting value %d", flashMode));
   250 */
   331     mSceneModeStore.setSceneSettingValue(Cxe::ImageMode, key, flashMode);
   251 CxeError::Id CxeSettingsImp::set(const QString &key, const QString &newValue)
   332 
   252 {
   333     // Updating Face Tracking setting from cenrep
   253     CX_DEBUG_ENTER_FUNCTION();
   334     key = CxeSettingIds::FACE_TRACKING;
   254 
   335     int faceTracking = CxeSettings::get<int>(key);
   255     CX_DEBUG(("CxeSettingsImp::set - key: %s value: %s",
   336 
   256               key.toAscii().data(), newValue.toAscii().data()));
   337     // update local datastructure with flash setting value from cenrep.
   257 
   338     CX_DEBUG(( "Face Tracking setting value %d", faceTracking));
   258     CxeError::Id error = setSceneMode(key, newValue);
   339     mSceneModeStore.setSceneSettingValue(Cxe::ImageMode, key, faceTracking);
   259 
   340 
   260     if (error == CxeError::NotFound) {
   341 
   261         // not scene mode setting, try setting value to settings store
   342     CX_DEBUG_EXIT_FUNCTION();
   262         mSettingsModel.set(key, newValue);
   343 }
   263         emit settingValueChanged(key, newValue);
   344 
   264     }
   345 
   265 
   346 /*!
   266     CX_DEBUG_EXIT_FUNCTION();
   347 * Restores video settings, during mode change or during startup.
   267 
   348 */
   268     return error;
   349 void CxeSettingsImp::restoreVideoSettings()
   269 }
   350 {
   270 
   351     CX_DEBUG_ENTER_FUNCTION();
   271 
   352 
   272 
   353     QString currentSceneInUse = mSceneModeStore.currentSceneId(Cxe::VideoMode);
   273 /*!
   354 
   274     Set the current scene mode setting value for the given key
   355     // get the video scene value from cenrep and load the scene settings
   275 */
   356     QString cenrepSceneValue = CxeSettings::get<QString>(CxeSettingIds::VIDEO_SCENE);
   276 CxeError::Id CxeSettingsImp::setSceneMode(
   357 
   277         const QString &key,const QString &newValue)
   358     bool ok2LoadSceneSettings = (cenrepSceneValue != currentSceneInUse);
   278 {
   359 
   279     CX_DEBUG_ENTER_FUNCTION();
   360     if (ok2LoadSceneSettings) {
   280 
   361         // loading video scene settings
   281     CX_DEBUG(("CxeSettingsImp::set - key: %s value: %s",
   362         mSceneModeStore.setCurrentScene(Cxe::VideoMode, cenrepSceneValue);
   282               key.toAscii().data(), newValue.toAscii().data()));
   363     }
   283 
   364 
   284     CxeError::Id error = CxeError::None;
   365     CX_DEBUG_EXIT_FUNCTION();
   285     CxeScene scene;
   366 }
   286 
   367 
   287     if(CxeSettingIds::IMAGE_SCENE == key) {
   368 /*!
   288         error = mSettingsModel.setImageScene(newValue);
   369 * Set new Image scene mode.
   289         scene = mSettingsModel.currentImageScene();
   370 * @returns CxeError::None if successful or any CxeError specific error code.
   290     } else if(CxeSettingIds::VIDEO_SCENE == key) {
   371 */
   291         error = mSettingsModel.setVideoScene(newValue);
   372 void CxeSettingsImp::setImageScene(const QString &newScene)
   292         scene = mSettingsModel.currentVideoScene();
   373 {
       
   374     CX_DEBUG_ENTER_FUNCTION();
       
   375 
       
   376     // load scene specific settings
       
   377     mSceneModeStore.setCurrentScene(Cxe::ImageMode, newScene);
       
   378 
       
   379     // saving current image scene to cenrep
       
   380     CxeError::Id err = mSettingStore->set(CxeSettingIds::IMAGE_SCENE, newScene);
       
   381     CxeException::throwIfError(err);
       
   382 
       
   383     // saving flash value from scene to cenrep
       
   384     // call CxeSettingStore::set directly because we don't want to send notifications
       
   385     // about these changes
       
   386     QString key(CxeSettingIds::FLASH_MODE);
       
   387     err = mSettingStore->set(key, mSceneModeStore.currentScene(Cxe::ImageMode)[key].toInt());
       
   388 
       
   389     CxeException::throwIfError(err);
       
   390     // saving face tracking value from scene to cenrep
       
   391     key = CxeSettingIds::FACE_TRACKING;
       
   392     err = mSettingStore->set(key, mSceneModeStore.currentScene(Cxe::ImageMode)[key].toInt());
       
   393     CxeException::throwIfError(err);
       
   394 
       
   395     // send notifications
       
   396     emit settingValueChanged(CxeSettingIds::IMAGE_SCENE, mSceneModeStore.currentSceneId(Cxe::ImageMode));
       
   397     notifyListeners(CxeSettingIds::IMAGE_SCENE, mSceneModeStore.currentSceneId(Cxe::ImageMode));
       
   398     notifyListeners(CxeSettingIds::IMAGE_SCENE_DATA, mSceneModeStore.currentScene(Cxe::ImageMode));
       
   399 
       
   400     CX_DEBUG_EXIT_FUNCTION();
       
   401 
       
   402 }
       
   403 
       
   404 /*!
       
   405 * Set new video scene mode.
       
   406 * @returns CxeError::None if successful or any CxeError specific error code.
       
   407 */
       
   408 void CxeSettingsImp::setVideoScene(const QString &newScene)
       
   409 {
       
   410     CX_DEBUG_ENTER_FUNCTION();
       
   411 
       
   412     mSceneModeStore.setCurrentScene(Cxe::VideoMode, newScene);
       
   413 
       
   414     // video scene set successfully, store the scene value to cenrep
       
   415     CxeError::Id err = mSettingStore->set(CxeSettingIds::VIDEO_SCENE, newScene);
       
   416     CxeException::throwIfError(err);
       
   417 
       
   418     emit settingValueChanged(CxeSettingIds::VIDEO_SCENE, mSceneModeStore.currentSceneId(Cxe::VideoMode));
       
   419     notifyListeners(CxeSettingIds::VIDEO_SCENE, mSceneModeStore.currentSceneId(Cxe::VideoMode));
       
   420     notifyListeners(CxeSettingIds::VIDEO_SCENE_DATA, mSceneModeStore.currentScene(Cxe::VideoMode));
       
   421 
       
   422     CX_DEBUG_EXIT_FUNCTION();
       
   423 
       
   424 }
       
   425 
       
   426 /*!
       
   427 * Loads all run-time variation settings
       
   428 */
       
   429 void CxeSettingsImp::loadVariationSettings()
       
   430 {
       
   431     CX_DEBUG_ENTER_FUNCTION();
       
   432     CX_DEBUG_ASSERT( mSettingStore );
       
   433 
       
   434     QList<QString> variationKeys;
       
   435     // all supported runtime variation keys are fetched from here.
       
   436     variationKeys.append(CxeVariationKeys::FREE_MEMORY_LEVELS);
       
   437     variationKeys.append(CxeVariationKeys::STILL_MAX_ZOOM_LIMITS);
       
   438     variationKeys.append(CxeVariationKeys::VIDEO_MAX_ZOOM_LIMITS);
       
   439 
       
   440     // load all run-time setting values from cenrep.
       
   441     mVariationSettings = mSettingStore->loadVariationSettings(variationKeys);
       
   442 
       
   443     CX_DEBUG_EXIT_FUNCTION();
       
   444 }
       
   445 
       
   446 /*!
       
   447  * Notify setting listeners that setting has changed
       
   448  * @param settingKey Setting that has changed
       
   449  * @param newValue New value of the setting
       
   450  */
       
   451 void CxeSettingsImp::notifyListeners(const QString &settingKey, const QVariant &newValue)
       
   452 {
       
   453     CX_DEBUG_ENTER_FUNCTION();
       
   454 
       
   455     CX_DEBUG(("CxeSettingsImp::notifyListeners settingKey=%s", settingKey.toAscii().data()));
       
   456 
       
   457     if (mSettingListeners.contains(settingKey)) {
       
   458         CX_DEBUG(("Listeners found"));
       
   459         // get list of listener
       
   460         CxeSettingListenerList& list = mSettingListeners[settingKey];
       
   461 
       
   462         // iterate through the list and call all listeners
       
   463         CxeSettingListenerList::const_iterator i = list.constBegin();
       
   464         for(; i != list.constEnd(); ++i) {
       
   465 
       
   466             QObject *object = (*i).first;
       
   467             QMetaMethod slot = (*i).second;
       
   468 
       
   469             CX_DEBUG_ASSERT(object);
       
   470 
       
   471             // invoke the slot
       
   472             CX_DEBUG(("Calling slot %s::%s", object->metaObject()->className(), slot.signature()));
       
   473 
       
   474             bool ok = false;
       
   475             if (slot.parameterTypes().size() == 2) {
       
   476                 // slot has two parameters, send settingKey as well
       
   477                 ok = slot.invoke(object,
       
   478                                   Qt::AutoConnection,
       
   479                                   Q_ARG(QString, settingKey),
       
   480                                   Q_ARG(QVariant, newValue));
       
   481             } else {
       
   482                 // don't send settingKey as parameter
       
   483                 ok = slot.invoke(object,
       
   484                                  Qt::AutoConnection,
       
   485                                  Q_ARG(QVariant, newValue));
       
   486             }
       
   487 
       
   488             if (!ok) {
       
   489                 CX_DEBUG(("QMetaMethod::invoke() failed, listener not notified"))
       
   490             }
       
   491 
       
   492         }
       
   493 
   293     } else {
   494     } else {
   294         error = CxeError::NotFound;
   495         CX_DEBUG(("NO listeners found"));
   295     }
   496     }
   296 
   497 
   297     if (error == CxeError::None) {
   498 
   298         // scene mode set, inform clients about scene mode change
   499 
   299         emit sceneChanged(scene);
   500     CX_DEBUG_EXIT_FUNCTION();
   300     }
   501 }
   301 
   502 
   302     CX_DEBUG_EXIT_FUNCTION();
   503 /*!
   303 
   504  * Handle deletion of registered listener.
   304     return error;
   505  */
   305 }
   506 void CxeSettingsImp::handleListenerDestroyed(QObject *object)
   306 
   507 {
   307 /*!
   508     CX_DEBUG_ENTER_FUNCTION();
   308     Reset static settings (persistent settings)
   509 
   309 */
   510     QList<QString> keyList = mSettingListeners.keys();
   310 void CxeSettingsImp::reset()
   511 
   311 {
   512     for (int i = 0; i < keyList.size(); i++) {
   312     CX_DEBUG_ENTER_FUNCTION();
   513 
   313 
   514         QString key = keyList[i];
   314     mSettingsModel.reset();
   515         CxeSettingListenerList& list = mSettingListeners[key];
   315 
   516 
   316     CX_DEBUG_EXIT_FUNCTION();
   517         for (int j = 0; j < list.size(); j++) {
   317 }
   518             CxeSettingListener &listener = list[j];
   318 
   519             if (listener.first == object) {
   319 
   520                 list.removeAt(j--);
   320 
   521             }
   321 /*
   522         }
   322 * CxeSettingsImp::CxeSettingsImp
   523 
   323 */
   524         // removed last listener for this key
   324 CxeSettingsImp::CxeSettingsImp(CxeSettingsModel &settingsModel)
   525         if (list.size() == 0) {
   325 : mSettingsModel(settingsModel)
   526             mSettingListeners.remove(key);
   326 {
   527         }
   327     CX_DEBUG_IN_FUNCTION();
   528     }
   328 }
   529 
   329 
   530     CX_DEBUG_EXIT_FUNCTION();
   330 
       
   331 
       
   332 /*
       
   333 * CxeSettingsImp::close
       
   334 */
       
   335 CxeSettingsImp::~CxeSettingsImp()
       
   336 {
       
   337     CX_DEBUG_IN_FUNCTION();
       
   338 }
   531 }
   339 
   532 
   340 // end of file
   533 // end of file