|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #ifndef CXESETTINGSCENREPSTORE_H_ |
|
18 #define CXESETTINGSCENREPSTORE_H_ |
|
19 |
|
20 // Include Files |
|
21 #include <QHash> |
|
22 #include <QVariant> |
|
23 #include <QMetaType> |
|
24 |
|
25 #include "cxeerror.h" |
|
26 #include "cxenamespace.h" |
|
27 #include "xqsettingsmanager.h" |
|
28 |
|
29 // forward declarations |
|
30 class XQSettingsManager; |
|
31 class XQSettingsKey; |
|
32 |
|
33 |
|
34 /* |
|
35 * Settings store intrerface. |
|
36 */ |
|
37 class CxeSettingsStore |
|
38 { |
|
39 public: |
|
40 |
|
41 /** |
|
42 * This needs to be here to be able to delete an object |
|
43 * of inherited class through mixin pointer. |
|
44 * If this is not defined, deleting through the mixin pointer |
|
45 * results in User-42 panic! |
|
46 */ |
|
47 virtual ~CxeSettingsStore() {}; |
|
48 |
|
49 /* |
|
50 * resets the cenrep store |
|
51 */ |
|
52 virtual void reset() = 0; |
|
53 |
|
54 /* |
|
55 * Reads a value from cenrep |
|
56 * @param "key" - setting key |
|
57 * @param "value" - setting value read from cenrep |
|
58 */ |
|
59 virtual CxeError::Id get(const QString& key, QVariant &value) = 0; |
|
60 |
|
61 /* |
|
62 * Reads a value from cenrep |
|
63 * @param "uid" - UID of the component that own setting key |
|
64 * @param "key" - setting key id |
|
65 * @param "type" - type of setting key |
|
66 * @param "value" - setting value read from cenrep |
|
67 */ |
|
68 virtual void get(long int uid, unsigned long int key, Cxe::SettingKeyType type, QVariant &value) = 0; |
|
69 |
|
70 /* |
|
71 * Sets a new value to cenrep |
|
72 * @param "key" - setting key |
|
73 * @param "newValue" - new value set to the key in cenrep |
|
74 */ |
|
75 virtual CxeError::Id set(const QString& key,const QVariant newValue) = 0; |
|
76 |
|
77 /* |
|
78 * 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 * 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 * unnecessarily multiple times as the values of the runtime keys are not changed. |
|
83 * Runtime keys are only used to configure camerax application. |
|
84 */ |
|
85 virtual QHash<QString, QVariantList> loadRuntimeSettings(QList<QString>& settingKeys) = 0; |
|
86 }; |
|
87 |
|
88 |
|
89 |
|
90 /* |
|
91 * CxeSettingsCenRepStore class implements CxeSettingsStore. |
|
92 * This class uses CenRep key mechanism for storing and retrieving settings information. |
|
93 */ |
|
94 class CxeSettingsCenRepStore : public QObject, |
|
95 public CxeSettingsStore |
|
96 { |
|
97 |
|
98 Q_OBJECT |
|
99 |
|
100 public: |
|
101 |
|
102 CxeSettingsCenRepStore(); |
|
103 ~CxeSettingsCenRepStore(); |
|
104 |
|
105 public: // from base class |
|
106 /* |
|
107 * resets the cenrep store |
|
108 */ |
|
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); |
|
117 |
|
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); |
|
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); |
|
143 |
|
144 |
|
145 signals: |
|
146 |
|
147 void settingValueChanged(long int uid, unsigned long int key, QVariant value); |
|
148 |
|
149 private slots: |
|
150 |
|
151 void handleValueChanged(XQSettingsKey key, QVariant value); |
|
152 |
|
153 private: |
|
154 |
|
155 class CxeCenRepDefinition |
|
156 { |
|
157 public: |
|
158 long int mRepositoryUid; //! UID of the all the setting keys |
|
159 unsigned long int mKeyId; //! key cenrep id |
|
160 bool mReadOnly; //! if the key holds data that is read-only |
|
161 XQSettingsManager::Type mDataType; //! type of data that cenrep key holds |
|
162 |
|
163 }; |
|
164 |
|
165 private: |
|
166 |
|
167 /* |
|
168 * add's key mapping to the hash container. |
|
169 */ |
|
170 void addKeyMapping(QString key, |
|
171 unsigned long int keyid, |
|
172 XQSettingsManager::Type type, |
|
173 bool readOnly = false); |
|
174 /* |
|
175 * Generates XQSettingsKey from given setting/runtime key |
|
176 */ |
|
177 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(); |
|
183 |
|
184 protected: |
|
185 const QHash<QString, CxeCenRepDefinition>& keyMapping() const; |
|
186 |
|
187 private: // data |
|
188 |
|
189 XQSettingsManager* mSettingsManager; |
|
190 QHash<QString, CxeCenRepDefinition> mKeyMapping; |
|
191 }; |
|
192 |
|
193 |
|
194 /* |
|
195 * Settings store that reads key values from cenrep and keeps |
|
196 * cached copies of them in memory. Doesn't write anything back |
|
197 * to cenrep. |
|
198 */ |
|
199 class CxeSettingsLocalStore : public CxeSettingsCenRepStore |
|
200 { |
|
201 Q_OBJECT |
|
202 |
|
203 public: |
|
204 CxeSettingsLocalStore(); |
|
205 ~CxeSettingsLocalStore(); |
|
206 |
|
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); |
|
213 |
|
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: |
|
221 |
|
222 bool useValueFromCenrep(const QString &key) const; |
|
223 |
|
224 QHash<QString, QVariant> mSettings; |
|
225 }; |
|
226 |
|
227 #endif // CXESETTINGSCENREPSTORE_H_ |
|
228 |