|
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 |
|
18 #include <QVariant> |
|
19 #include <QList> |
|
20 #include <QHash> |
|
21 |
|
22 #include "cxenamespace.h" |
|
23 #include "cxefakesettingsstore.h" |
|
24 |
|
25 CxeFakeSettingsStore::CxeFakeSettingsStore() |
|
26 { |
|
27 // all supported settings are initialized here. |
|
28 mSettingKeyHash.clear(); |
|
29 mSettingKeyHash.insert(CxeSettingIds::FNAME_FOLDER_SUFFIX, QVariant("_Nokia")); |
|
30 mSettingKeyHash.insert(CxeSettingIds::FNAME_MONTH_FOLDER, QVariant("08042009")); |
|
31 mSettingKeyHash.insert(CxeSettingIds::FNAME_IMAGE_COUNTER, QVariant(0)); |
|
32 mSettingKeyHash.insert(CxeSettingIds::FNAME_VIDEO_COUNTER, QVariant(0)); |
|
33 } |
|
34 |
|
35 CxeFakeSettingsStore::~CxeFakeSettingsStore() |
|
36 { |
|
37 } |
|
38 |
|
39 /* |
|
40 * Reads a value from cenrep |
|
41 * @param "key" - setting key |
|
42 * @param "value" - setting value read from cenrep |
|
43 */ |
|
44 CxeError::Id CxeFakeSettingsStore::get(const QString& key, QVariant &value) |
|
45 { |
|
46 CxeError::Id error = CxeError::None; |
|
47 if(mSettingKeyHash.contains(key)) { |
|
48 value = mSettingKeyHash[key]; |
|
49 } else if(mRuntimeKeyHash.contains(key)) { |
|
50 value = mRuntimeKeyHash[key]; |
|
51 } else { |
|
52 error = CxeError::NotFound; |
|
53 } |
|
54 |
|
55 return error; |
|
56 } |
|
57 |
|
58 /* |
|
59 * Reads a value from cenrep |
|
60 * @param "uid" - UID of the component that own setting key |
|
61 * @param "key" - setting key id |
|
62 * @param "type" - type of setting key |
|
63 * @param "value" - setting value read from cenrep |
|
64 */ |
|
65 void CxeFakeSettingsStore::get(long int uid, unsigned long int key, Cxe::SettingKeyType type, QVariant &value) |
|
66 { |
|
67 Q_UNUSED(uid); |
|
68 Q_UNUSED(key); |
|
69 Q_UNUSED(type); |
|
70 Q_UNUSED(value); |
|
71 |
|
72 // no support yet |
|
73 } |
|
74 |
|
75 /* |
|
76 * Reads/loads all run-time settings values from cenrep |
|
77 * @param QList<QString> contains list of all runtime key ids which we use to load values from cenrep. |
|
78 * returns: QHash container, "contains" values associated with each key that are read from cenrep |
|
79 * NOTE: loading runtime settings should be done only ONCE at start-up. |
|
80 */ |
|
81 QHash<QString, QVariantList> CxeFakeSettingsStore::loadRuntimeSettings(QList<QString>& keylist) |
|
82 { |
|
83 QVariant data; |
|
84 CxeError::Id err = CxeError::None; |
|
85 QVariantList list; |
|
86 QHash<QString, QVariantList> settings; |
|
87 mRuntimeKeyHash.clear(); |
|
88 |
|
89 foreach (QString key, keylist) { |
|
90 |
|
91 // before we read from get function we set values to the key |
|
92 mRuntimeKeyHash.insert(key, QVariant(1)); |
|
93 |
|
94 // read the data from cenrep |
|
95 err = get(key, data); |
|
96 // clear the list |
|
97 list.clear(); |
|
98 if (CxeError::None == err) { |
|
99 list.append(data); |
|
100 } |
|
101 // append the values associated with the key to the list. |
|
102 settings.insert(key, list); |
|
103 } // end for |
|
104 |
|
105 return settings; |
|
106 } |
|
107 |
|
108 |
|
109 /* |
|
110 * Sets a new value to cenrep |
|
111 * @param "key" - setting key |
|
112 * @param "newValue" - new value set to the key in cenrep |
|
113 */ |
|
114 CxeError::Id CxeFakeSettingsStore::set(const QString& key, const QVariant newValue) |
|
115 { |
|
116 CxeError::Id error = CxeError::NotFound; |
|
117 if(mSettingKeyHash.contains(key)) { |
|
118 mSettingKeyHash[key] = newValue; |
|
119 error = CxeError::None; |
|
120 } |
|
121 return error; |
|
122 } |
|
123 |
|
124 /* |
|
125 * resets the cenrep store |
|
126 */ |
|
127 void CxeFakeSettingsStore::reset() |
|
128 { |
|
129 } |
|
130 |