camerauis/cameraxui/cxengine/inc/cxesettingscenrepstore.h
changeset 43 0e652f8f1fbd
parent 19 d9aefe59d544
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".
    29 // forward declarations
    29 // forward declarations
    30 class XQSettingsManager;
    30 class XQSettingsManager;
    31 class XQSettingsKey;
    31 class XQSettingsKey;
    32 
    32 
    33 
    33 
    34 /*
    34 /*!
    35 * Settings store intrerface.
    35 * \class CxeSettingsStore 
       
    36 * \brief Settings store intrerface.
    36 */
    37 */
    37 class CxeSettingsStore
    38 class CxeSettingsStore
    38 {
    39 {
    39 public:
    40 public:
    40 
    41 
    41     /**
    42     /*!
    42     * This needs to be here to be able to delete an object
    43     * This needs to be here to be able to delete an object
    43     * of inherited class through mixin pointer.
    44     * of inherited class through mixin pointer.
    44     * If this is not defined, deleting through the mixin pointer
    45     * If this is not defined, deleting through the mixin pointer
    45     * results in User-42 panic!
    46     * results in User-42 panic!
    46     */
    47     */
    47     virtual ~CxeSettingsStore() {};
    48     virtual ~CxeSettingsStore() {};
    48 
    49 
    49     /*
    50     /*!
    50     * resets the cenrep store
    51     * resets the cenrep store
    51     */
    52     */
    52     virtual void reset() = 0;
    53     virtual void reset() = 0;
    53     
    54     
    54     /*
    55     /*!
    55     * Reads a value from cenrep
    56     * Reads a value from cenrep
    56     * @param "key"   - setting key
    57     * @param "key"   - setting key
    57     * @param "value" - setting value read from cenrep
    58     * @param "value" - setting value read from cenrep
    58     */
    59     */
    59 	virtual CxeError::Id get(const QString& key, QVariant &value) = 0;
    60 	virtual CxeError::Id get(const QString& key, QVariant &value) = 0;
    60 
    61 
    61     /*
    62     /*!
    62     * Reads a value from cenrep
    63     * Reads a value from cenrep and starts monitoring changes
    63     * @param "uid"   - UID of the component that own setting key
    64     * @param "uid"   - UID of the component that own setting key
    64     * @param "key"   - setting key id
    65     * @param "key"   - setting key id
    65     * @param "type"  - type of setting key
    66     * @param "type"  - type of setting key
    66     * @param "value" - setting value read from cenrep
    67     * @param "value" - setting value read from cenrep
    67     */
    68     */
    68 	virtual void get(long int uid, unsigned long int key, Cxe::SettingKeyType type, QVariant &value) = 0;
    69 	virtual void startMonitoring(long int uid, unsigned long int key, Cxe::SettingKeyType type, QVariant &value) = 0;
    69 	
    70 	
    70 	/*
    71 	/*!
    71     * Sets a new value to cenrep
    72     * Sets a new value to cenrep
    72     * @param "key"   - setting key
    73     * @param "key"   - setting key
    73     * @param "newValue" - new value set to the key in cenrep
    74     * @param "newValue" - new value set to the key in cenrep
    74     */
    75     */
    75 	virtual CxeError::Id set(const QString& key,const QVariant newValue) = 0;
    76 	virtual CxeError::Id set(const QString& key,const QVariant newValue) = 0;
    76 	    
    77 	    
    77 	/*
    78 	/*!
    78     * Reads/loads all run-time settings values from cenrep
    79     * Reads/loads all run-time settings values from cenrep
    79     * @param QList<QString> contains list of all runtime key ids which we use to load values from cenrep.
    80     * @param QList<QString> contains list of all runtime key ids which we use to load values from cenrep.
    80     * returns: QHash container, "contains" values associated with each key that are read from cenrep
    81     * returns: QHash container, "contains" values associated with each key that are read from cenrep
    81     * NOTE: loading runtime settings should be done only ONCE at start-up. Its an overhead to read runtime keys
    82     * NOTE: loading runtime settings should be done only ONCE at start-up. Its an overhead to read runtime keys
    82     *       unnecessarily multiple times as the values of the runtime keys are not changed.
    83     *       unnecessarily multiple times as the values of the runtime keys are not changed.
    85 	virtual QHash<QString, QVariantList> loadRuntimeSettings(QList<QString>& settingKeys) = 0;
    86 	virtual QHash<QString, QVariantList> loadRuntimeSettings(QList<QString>& settingKeys) = 0;
    86 };
    87 };
    87 
    88 
    88 
    89 
    89 
    90 
    90 /*
    91 /*!
    91 * CxeSettingsCenRepStore class implements CxeSettingsStore.
    92 * \class CxeSettingsCenRepStore 
       
    93 * \brief Class implements CxeSettingsStore.
    92 * This class uses CenRep key mechanism for storing and retrieving settings information.
    94 * This class uses CenRep key mechanism for storing and retrieving settings information.
    93 */
    95 */
    94 class CxeSettingsCenRepStore : public QObject,
    96 class CxeSettingsCenRepStore : public QObject,
    95                                public CxeSettingsStore
    97                                public CxeSettingsStore
    96 {
    98 {
   101 
   103 
   102     CxeSettingsCenRepStore();
   104     CxeSettingsCenRepStore();
   103 	~CxeSettingsCenRepStore();
   105 	~CxeSettingsCenRepStore();
   104 
   106 
   105 public: // from base class
   107 public: // from base class
   106     /*
   108 
   107     * resets the cenrep store
       
   108     */
       
   109     void reset();
   109     void reset();
   110     
       
   111     /*
       
   112     * Reads a value from cenrep
       
   113     * @param "key"   - setting key
       
   114     * @param "value" - setting value read from cenrep
       
   115     */
       
   116 	CxeError::Id get(const QString& key, QVariant &value);
   110 	CxeError::Id get(const QString& key, QVariant &value);
   117 
   111     void startMonitoring(long int uid, unsigned long int key, Cxe::SettingKeyType type, QVariant &value);
   118     /*
       
   119     * Reads a value from cenrep
       
   120     * @param "uid"   - UID of the component that own setting key
       
   121     * @param "key"   - setting key id
       
   122     * @param "type"  - type of setting key
       
   123     * @param "value" - setting value read from cenrep
       
   124     */
       
   125     void get(long int uid, unsigned long int key, Cxe::SettingKeyType type, QVariant &value);
       
   126 	
       
   127 	/*
       
   128     * Sets a new value to cenrep
       
   129     * @param "key"   - setting key
       
   130     * @param "newValue" - new value set to the key in cenrep
       
   131     */
       
   132 	CxeError::Id set(const QString& key,const QVariant newValue);
   112 	CxeError::Id set(const QString& key,const QVariant newValue);
   133 	    
       
   134 	/*
       
   135     * Reads/loads all run-time settings values from cenrep
       
   136     * @param QList<QString> contains list of all runtime key ids which we use to load values from cenrep.
       
   137     * returns: QHash container, "contains" values associated with each key that are read from cenrep
       
   138     * NOTE: loading runtime settings should be done only ONCE at start-up. Its an overhead to read runtime keys
       
   139     *       unnecessarily multiple times as the values of the runtime keys are not changed.
       
   140     *       Runtime keys are only used to configure camerax application.
       
   141     */
       
   142 	QHash<QString, QVariantList> loadRuntimeSettings(QList<QString>& settingKeys);
   113 	QHash<QString, QVariantList> loadRuntimeSettings(QList<QString>& settingKeys);
   143 
   114 
   144 
   115 
   145 signals:
   116 signals:
   146 
       
   147     void settingValueChanged(long int uid, unsigned long int key, QVariant value);
   117     void settingValueChanged(long int uid, unsigned long int key, QVariant value);
   148 
   118 
   149 private slots:
   119 private slots:
   150 
       
   151     void handleValueChanged(XQSettingsKey key, QVariant value);
   120     void handleValueChanged(XQSettingsKey key, QVariant value);
   152 
   121 
   153 private:
   122 private:
   154 
   123 
   155     class CxeCenRepDefinition
   124     class CxeCenRepDefinition
   161         XQSettingsManager::Type mDataType;  //! type of data that cenrep key holds
   130         XQSettingsManager::Type mDataType;  //! type of data that cenrep key holds
   162         
   131         
   163     };
   132     };
   164 
   133 
   165 private:
   134 private:
   166     
   135 
   167     /*
       
   168      *  add's key mapping to the hash container.
       
   169      */
       
   170     void addKeyMapping(QString key,
   136     void addKeyMapping(QString key,
   171                        unsigned long int keyid,
   137                        unsigned long int keyid,
   172                        XQSettingsManager::Type type,
   138                        XQSettingsManager::Type type,
   173                        bool readOnly = false);
   139                        bool readOnly = false);
   174     /*
   140     
   175     * Generates XQSettingsKey from given setting/runtime key
       
   176     */
       
   177     XQSettingsKey generateXQSettingsKey(const QString& key,CxeError::Id& error);
   141     XQSettingsKey generateXQSettingsKey(const QString& key,CxeError::Id& error);
   178     
       
   179     /*
       
   180     * maps "string" type setting key ids to cenrep key ids that XQSettingsManager understands
       
   181     */
       
   182 	void mapKeys();
   142 	void mapKeys();
   183 	
   143 	
   184 protected:
   144 protected:
   185     const QHash<QString, CxeCenRepDefinition>& keyMapping() const;
   145     const QHash<QString, CxeCenRepDefinition>& keyMapping() const;
   186 
   146 
   189     XQSettingsManager* mSettingsManager;
   149     XQSettingsManager* mSettingsManager;
   190 	QHash<QString, CxeCenRepDefinition> mKeyMapping;
   150 	QHash<QString, CxeCenRepDefinition> mKeyMapping;
   191 };
   151 };
   192 
   152 
   193 
   153 
   194 /*
   154 /*!
   195  * Settings store that reads key values from cenrep and keeps
   155  * \class CxeSettingsLocalStore
       
   156  * \brief Settings store that reads key values from cenrep and keeps
   196  * cached copies of them in memory. Doesn't write anything back
   157  * cached copies of them in memory. Doesn't write anything back
   197  * to cenrep.
   158  * to cenrep.
   198  */
   159  */
   199 class CxeSettingsLocalStore : public CxeSettingsCenRepStore
   160 class CxeSettingsLocalStore : public CxeSettingsCenRepStore
   200 {
   161 {
   202 
   163 
   203 public:
   164 public:
   204      CxeSettingsLocalStore();
   165      CxeSettingsLocalStore();
   205      ~CxeSettingsLocalStore();
   166      ~CxeSettingsLocalStore();
   206 
   167 
   207      /*
       
   208      * Reads a value from local store.
       
   209      * @param "key"   - setting key
       
   210      * @param "value" - setting value read from cenrep
       
   211      */
       
   212      CxeError::Id get(const QString& key, QVariant &value);
   168      CxeError::Id get(const QString& key, QVariant &value);
       
   169      CxeError::Id set(const QString& key, const QVariant newValue);
   213 
   170 
   214      /*
       
   215      * Sets a new value to local store
       
   216      * @param "key"   - setting key
       
   217      * @param "newValue" - new value set to the key in cenrep
       
   218      */
       
   219      CxeError::Id set(const QString& key, const QVariant newValue);
       
   220 private:
   171 private:
   221 
   172 
   222      bool useValueFromCenrep(const QString &key) const;
   173      bool useValueFromCenrep(const QString &key) const;
   223 
   174 
   224      QHash<QString, QVariant> mSettings;
   175      QHash<QString, QVariant> mSettings;