camerauis/cameraxui/cxengine/src/cxesettingscenrepstore.cpp
changeset 43 0e652f8f1fbd
parent 28 3075d9b614e6
child 45 24fd82631616
equal deleted inserted replaced
28:3075d9b614e6 43:0e652f8f1fbd
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    23 #include <QMultiMap>
    23 #include <QMultiMap>
    24 #include <QMetaType>
    24 #include <QMetaType>
    25 #include <QString>
    25 #include <QString>
    26 #include <QStringList>
    26 #include <QStringList>
    27 #include <QVariant>
    27 #include <QVariant>
       
    28 #ifdef Q_OS_SYMBIAN
       
    29 #include <ProfileEngineSDKCRKeys.h>
       
    30 #endif
    28 
    31 
    29 #include "xqsettingsmanager.h" // Settings Manager API
    32 #include "xqsettingsmanager.h" // Settings Manager API
    30 #include "xqsettingskey.h"
    33 #include "xqsettingskey.h"
    31 #include "cxesettingscenrepstore.h"
    34 #include "cxesettingscenrepstore.h"
    32 #include "cxenamespace.h"
    35 #include "cxenamespace.h"
    33 #include "cxutils.h"
    36 #include "cxutils.h"
    34 #include "cxenamespace.h"
    37 #include "cxenamespace.h"
    35 #include "cxeerror.h"
    38 #include "cxeerror.h"
    36 #include "cxecenrepkeys.h"
    39 #include "cxecenrepkeys.h"
    37 
    40 
       
    41 #include "OstTraceDefinitions.h"
       
    42 #ifdef OST_TRACE_COMPILER_IN_USE
       
    43 #include "cxesettingscenrepstoreTraces.h"
       
    44 #endif
       
    45 
       
    46 
    38 using namespace CxeSettingIds;
    47 using namespace CxeSettingIds;
    39 
    48 
    40 
    49 
    41 /*
    50 /*!
    42 * CxeSettingsCenRepStore::CxeSettingsCenRepStore
    51 * CxeSettingsCenRepStore::CxeSettingsCenRepStore
    43 */
    52 */
    44 CxeSettingsCenRepStore::CxeSettingsCenRepStore()
    53 CxeSettingsCenRepStore::CxeSettingsCenRepStore()
    45 {
    54 {
    46     CX_DEBUG_ENTER_FUNCTION();
    55     CX_DEBUG_ENTER_FUNCTION();
       
    56     OstTrace0(camerax_performance, CXESETTINGSCENREPSTORE_1, "msg: e_CX_SETTINGSSTORE_CREATE 1");
    47 
    57 
    48     // map keys of type "string" to cenrep ids
    58     // map keys of type "string" to cenrep ids
    49     mapKeys();
    59     mapKeys();
    50 
    60 
    51 	// we create settings handle, scope user::scope
    61 	// we create settings handle, scope user::scope
    52     mSettingsManager = new XQSettingsManager(this);
    62     mSettingsManager = new XQSettingsManager(this);
    53 
    63 
    54     bool ok = false;
    64     bool ok = connect(mSettingsManager, SIGNAL(valueChanged(XQSettingsKey, QVariant)),
    55     ok = connect(mSettingsManager, SIGNAL(valueChanged(XQSettingsKey, QVariant)),
    65                       this, SLOT(handleValueChanged(XQSettingsKey, QVariant)));
    56                  this, SLOT(handleValueChanged(XQSettingsKey, QVariant)));
    66     CX_ASSERT_ALWAYS(ok);
    57     CX_DEBUG_ASSERT(ok);
       
    58 
    67 
    59     CX_DEBUG(("CxeSettingsCenRepStore - mSettingsManager ptr = %d", mSettingsManager));
    68     CX_DEBUG(("CxeSettingsCenRepStore - mSettingsManager ptr = %d", mSettingsManager));
    60 
    69 
       
    70     OstTrace0(camerax_performance, CXESETTINGSCENREPSTORE_2, "msg: e_CX_SETTINGSSTORE_CREATE 0");
    61 	CX_DEBUG_EXIT_FUNCTION();
    71 	CX_DEBUG_EXIT_FUNCTION();
    62 }
    72 }
    63 
    73 
    64 
    74 
    65 
    75 
    72     delete mSettingsManager;
    82     delete mSettingsManager;
    73     CX_DEBUG_EXIT_FUNCTION();
    83     CX_DEBUG_EXIT_FUNCTION();
    74 }
    84 }
    75 
    85 
    76 
    86 
    77 /*
    87 /*!
    78 * Generates XQSettingsKey from given setting/runtime key
    88 * Generates XQSettingsKey from given setting/runtime key
       
    89 * \param key Name of the setting from which to generate the XQSettingsKey
       
    90 * \param[out] error Error code. CxeError::None if everything went fine.
    79 */
    91 */
    80 XQSettingsKey
    92 XQSettingsKey
    81 CxeSettingsCenRepStore::generateXQSettingsKey(const QString& key, CxeError::Id& error)
    93 CxeSettingsCenRepStore::generateXQSettingsKey(const QString& key, CxeError::Id& error)
    82 {
    94 {
    83     CX_DEBUG_ENTER_FUNCTION();
    95     CX_DEBUG_ENTER_FUNCTION();
   101 	return newKey;
   113 	return newKey;
   102 }
   114 }
   103 
   115 
   104 
   116 
   105 
   117 
   106 /*
   118 /*!
   107 * Reads/loads all run-time settings values from cenrep
   119 * Reads/loads all run-time settings values from cenrep
   108 * @param QList<QString> contains list of all runtime key ids which we use to load values from cenrep.
   120 * @param QList<QString> contains list of all runtime key ids which we use to load values from cenrep.
   109 * returns: QHash container, "contains" values associated with each key that are read from cenrep
   121 * returns: QHash container, "contains" values associated with each key that are read from cenrep
   110 * NOTE: loading runtime settings should be done only ONCE at start-up.
   122 * NOTE: loading runtime settings should be done only ONCE at start-up.
   111 */
   123 */
   112 QHash<QString, QVariantList> CxeSettingsCenRepStore::loadRuntimeSettings(QList<QString>& runtimeKeys)
   124 QHash<QString, QVariantList> CxeSettingsCenRepStore::loadRuntimeSettings(QList<QString>& runtimeKeys)
   113 {
   125 {
   114     CX_DEBUG_ENTER_FUNCTION();
   126     CX_DEBUG_ENTER_FUNCTION();
       
   127     OstTrace0(camerax_performance, CXESETTINGSCENREPSTORE_LOADRUNTIME_1, "msg: e_CX_SETTINGSSTORE_LOAD_RUNTIME 1");
   115 
   128 
   116     QHash<QString, QVariantList> settings;
   129     QHash<QString, QVariantList> settings;
   117 	CxeError::Id err = CxeError::None;
   130 	CxeError::Id err = CxeError::None;
   118 	QVariantList list;
   131 	QVariantList list;
   119 	QVariant data;
   132 	QVariant data;
   143 
   156 
   144     } // end for
   157     } // end for
   145 
   158 
   146     CX_DEBUG_EXIT_FUNCTION();
   159     CX_DEBUG_EXIT_FUNCTION();
   147 
   160 
       
   161     OstTrace0(camerax_performance, CXESETTINGSCENREPSTORE_LOADRUNTIME_2, "msg: e_CX_SETTINGSSTORE_LOAD_RUNTIME 0");
   148     return settings;
   162     return settings;
   149 }
   163 }
   150 
   164 
   151 
   165 
   152 
   166 
   153 /*
   167 /*!
   154 * Reads a value from cenrep
   168 * Reads a value from cenrep
   155 * @param key   - setting key
   169 * @param key   - setting key
   156 * @param value - setting value read from cenrep
   170 * @param value - setting value read from cenrep
   157 */
   171 */
   158 
   172 
   181     return err;
   195     return err;
   182 }
   196 }
   183 
   197 
   184 
   198 
   185 
   199 
   186 /*
   200 /*!
   187 * Reads a value from cenrep
   201 * Reads a value from cenrep and starts the value change monitoring.
   188 * @param key   - setting key
   202 * @param key   - setting key
   189 * @param uid   - setting UID of the component that owns the setting key
   203 * @param uid   - setting UID of the component that owns the setting key
   190 * @param type  - the type of key cr key or P&S key (constantly monitoring value)
   204 * @param type  - the type of key cr key or P&S key
   191 * @param value - setting value read from cenrep
   205 * @param value - setting value read from cenrep
   192 */
   206 *
   193 
   207 * @sa handleValueChanged()
   194 void CxeSettingsCenRepStore::get(long int uid,
   208 */
       
   209 void CxeSettingsCenRepStore::startMonitoring(long int uid,
   195                                  unsigned long int key,
   210                                  unsigned long int key,
   196                                  Cxe::SettingKeyType type,
   211                                  Cxe::SettingKeyType type,
   197                                  QVariant &value)
   212                                  QVariant &value)
   198 {
   213 {
   199     CX_DEBUG_ENTER_FUNCTION();
   214     CX_DEBUG_ENTER_FUNCTION();
   206     } else {
   221     } else {
   207         keyType = XQSettingsKey::TargetCentralRepository;
   222         keyType = XQSettingsKey::TargetCentralRepository;
   208     }
   223     }
   209 
   224 
   210 	XQSettingsKey settingsKey(keyType, uid, key);
   225 	XQSettingsKey settingsKey(keyType, uid, key);
   211     CX_DEBUG(("reading values from XQSettingsManager.."));
   226     CX_DEBUG(("reading value from XQSettingsManager.."));
   212     value = mSettingsManager->readItemValue(settingsKey);
   227     value = mSettingsManager->readItemValue(settingsKey);
   213 
   228 
   214     if (keyType == XQSettingsKey::TargetPublishAndSubscribe) {
   229     // start monitoring changes for the key
   215         bool ok = false;
   230     // both P&S and Repository keys are monitored
   216         ok = mSettingsManager->startMonitoring(settingsKey);
   231     bool ok = mSettingsManager->startMonitoring(settingsKey);
   217         CX_DEBUG_ASSERT(ok);
   232     if (!ok) {
   218     }
   233         XQSettingsManager::Error error = mSettingsManager->error();
   219 
   234         CX_DEBUG(("CxeSettingsCenRepStore - got error %d trying to start listening", error));
   220     CX_DEBUG_EXIT_FUNCTION();
   235         // If we try to start listening one key more than once,
   221 }
   236         // we get this error. We can safely ignore it.
   222 
   237         ok = (XQSettingsManager::AlreadyExistsError == error);
   223 
   238     }
   224 
   239     CX_ASSERT_ALWAYS(ok);
   225 /*
   240 
       
   241     CX_DEBUG_EXIT_FUNCTION();
       
   242 }
       
   243 
       
   244 
       
   245 
       
   246 /*!
   226 * Sets a new value to cenrep
   247 * Sets a new value to cenrep
   227 * @param key   - setting key
   248 * @param key   - setting key
   228 * @param newValue - new value set to the key in cenrep
   249 * @param newValue - new value set to the key in cenrep
   229 */
   250 */
   230 CxeError::Id CxeSettingsCenRepStore::set(const QString& key, const QVariant newValue)
   251 CxeError::Id CxeSettingsCenRepStore::set(const QString& key, const QVariant newValue)
   256     return err;
   277     return err;
   257 }
   278 }
   258 
   279 
   259 
   280 
   260 
   281 
   261 /*
   282 /*!
   262 * resets the cenrep store
   283 * resets the cenrep store
   263 */
   284 */
   264 void CxeSettingsCenRepStore::reset()
   285 void CxeSettingsCenRepStore::reset()
   265 {
   286 {
   266     CX_DEBUG_ENTER_FUNCTION();
   287     CX_DEBUG_ENTER_FUNCTION();
   268     //!@Todo: How to reset the repository.
   289     //!@Todo: How to reset the repository.
   269     CX_DEBUG_EXIT_FUNCTION();
   290     CX_DEBUG_EXIT_FUNCTION();
   270 }
   291 }
   271 
   292 
   272 
   293 
   273 /*
   294 /*!
   274 * adds key mapping to all settings
   295 * Maps CxeSettingIds to cenrep key ids that XQSettingsManager understands
   275 */
   296 */
   276 void CxeSettingsCenRepStore::mapKeys()
   297 void CxeSettingsCenRepStore::mapKeys()
   277 {
   298 {
   278     CX_DEBUG_ENTER_FUNCTION();
   299     CX_DEBUG_ENTER_FUNCTION();
       
   300     OstTrace0(camerax_performance, CXESETTINGSCENREPSTORE_MAPKEYS_1, "msg: e_CX_SETTINGSSTORE_INIT_MAPPING 1");
       
   301 
   279     mKeyMapping.clear();
   302     mKeyMapping.clear();
   280 
   303 
   281     // mapping setting keys
   304     // mapping setting keys
   282     addKeyMapping(CxeSettingIds::FNAME_FOLDER_SUFFIX,
   305     addKeyMapping(CxeSettingIds::FNAME_FOLDER_SUFFIX,
   283                   FileNameSuffixCr,
   306                   FileNameSuffixCr,
   311                   VideoQualityCr,
   334                   VideoQualityCr,
   312                   XQSettingsManager::TypeInt);
   335                   XQSettingsManager::TypeInt);
   313 
   336 
   314     addKeyMapping(CxeSettingIds::VIDEO_MUTE_SETTING,
   337     addKeyMapping(CxeSettingIds::VIDEO_MUTE_SETTING,
   315                   AudioMuteCr,
   338                   AudioMuteCr,
       
   339                   XQSettingsManager::TypeInt);
       
   340 
       
   341     addKeyMapping(CxeSettingIds::GEOTAGGING,
       
   342                   GeoTaggingCr,
       
   343                   XQSettingsManager::TypeInt);
       
   344 
       
   345     addKeyMapping(CxeSettingIds::FACE_TRACKING,
       
   346                   FacetrackingCr,
       
   347                   XQSettingsManager::TypeInt);
       
   348 
       
   349     addKeyMapping(CxeSettingIds::IMAGE_SCENE,
       
   350                   SceneModeStillCr,
       
   351                   XQSettingsManager::TypeString);
       
   352 
       
   353     addKeyMapping(CxeSettingIds::VIDEO_SCENE,
       
   354                   SceneModeVideoCr,
       
   355                   XQSettingsManager::TypeString);
       
   356 
       
   357     addKeyMapping(CxeSettingIds::FLASH_MODE,
       
   358                   FlashModeStillCr,
       
   359                   XQSettingsManager::TypeInt);
       
   360 
       
   361     addKeyMapping(CxeSettingIds::CAPTURE_SOUND_ALWAYS_ON,
       
   362                   CaptureSoundAlwaysOnCr,
       
   363                   XQSettingsManager::TypeInt);
       
   364 
       
   365     addKeyMapping(CxeSettingIds::CAMERA_MODE,
       
   366                   CameraModeCr,
       
   367                   XQSettingsManager::TypeInt);
       
   368 
       
   369     addKeyMapping(CxeSettingIds::GEOTAGGING_DISCLAIMER,
       
   370                   GeoTaggingDisclaimerCr,
   316                   XQSettingsManager::TypeInt);
   371                   XQSettingsManager::TypeInt);
   317 
   372 
   318     // mapping run-time keys
   373     // mapping run-time keys
   319     addKeyMapping(CxeRuntimeKeys::PRIMARY_CAMERA_CAPTURE_KEYS,
   374     addKeyMapping(CxeRuntimeKeys::PRIMARY_CAMERA_CAPTURE_KEYS,
   320                   PrimaryCameraCaptureKeysCr,
   375                   PrimaryCameraCaptureKeysCr,
   344     addKeyMapping(CxeRuntimeKeys::VIDEO_MAX_ZOOM_LIMITS,
   399     addKeyMapping(CxeRuntimeKeys::VIDEO_MAX_ZOOM_LIMITS,
   345                   VideoMaxZoomLimitsCr,
   400                   VideoMaxZoomLimitsCr,
   346                   XQSettingsManager::TypeString,
   401                   XQSettingsManager::TypeString,
   347                   true);
   402                   true);
   348 
   403 
       
   404     OstTrace0(camerax_performance, CXESETTINGSCENREPSTORE_MAPKEYS_2, "msg: e_CX_SETTINGSSTORE_INIT_MAPPING 0");
   349 	CX_DEBUG_EXIT_FUNCTION();
   405 	CX_DEBUG_EXIT_FUNCTION();
   350 }
   406 }
   351 
   407 
   352 /*
   408 /*!
   353 * helper class to construct key mappings for each setting key
   409 * helper method to construct key mappings for each setting key
   354 */
   410 */
   355 void CxeSettingsCenRepStore::addKeyMapping(QString key,
   411 void CxeSettingsCenRepStore::addKeyMapping(QString key,
   356                                            unsigned long int keyid,
   412                                            unsigned long int keyid,
   357                                            XQSettingsManager::Type type,
   413                                            XQSettingsManager::Type type,
   358                                            bool readOnly)
   414                                            bool readOnly)
   379 }
   435 }
   380 
   436 
   381 
   437 
   382 
   438 
   383 /*!
   439 /*!
   384 *  Slot that handles value changed signal for Publish & Subscribe  key.
   440 *  Handles value changed signal from the XQSettingsManager.
       
   441 *  Emits signals corresponding the changed setting.
       
   442 *  \sa warningTonesChanged(), settingValueChanged()
   385 */
   443 */
   386 void CxeSettingsCenRepStore::handleValueChanged(XQSettingsKey key, QVariant value)
   444 void CxeSettingsCenRepStore::handleValueChanged(XQSettingsKey key, QVariant value)
   387 {
   445 {
   388     CX_DEBUG_ENTER_FUNCTION();
   446     CX_DEBUG_ENTER_FUNCTION();
   389 
       
   390     emit settingValueChanged(key.uid(), key.key(), value);
   447     emit settingValueChanged(key.uid(), key.key(), value);
   391 
       
   392     CX_DEBUG_EXIT_FUNCTION();
   448     CX_DEBUG_EXIT_FUNCTION();
   393 }
   449 }
   394 
   450 
   395 const QHash<QString, CxeSettingsCenRepStore::CxeCenRepDefinition>& CxeSettingsCenRepStore::keyMapping() const
   451 const QHash<QString, CxeSettingsCenRepStore::CxeCenRepDefinition>& CxeSettingsCenRepStore::keyMapping() const
   396 {
   452 {