|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "ccentralrepositoryhandler.h" |
|
43 |
|
44 #include "xqsettingskey.h" |
|
45 |
|
46 CCentralRepositoryHandler* CCentralRepositoryHandler::NewL(TUid aUid) |
|
47 { |
|
48 CCentralRepositoryHandler* self = new (ELeave) CCentralRepositoryHandler(aUid); |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop(self); |
|
52 return self; |
|
53 } |
|
54 |
|
55 void CCentralRepositoryHandler::ConstructL() |
|
56 { |
|
57 iRepository = CRepository::NewL(m_uid); |
|
58 } |
|
59 |
|
60 CCentralRepositoryHandler::CCentralRepositoryHandler(TUid aUid) : |
|
61 m_uid(aUid) |
|
62 { |
|
63 } |
|
64 |
|
65 CCentralRepositoryHandler::~CCentralRepositoryHandler() |
|
66 { |
|
67 foreach (CCenRepMonitor* monitor, m_monitors) |
|
68 delete monitor; |
|
69 |
|
70 delete iRepository; |
|
71 } |
|
72 |
|
73 void CCentralRepositoryHandler::setObserver(MSettingsHandlerObserver* observer) |
|
74 { |
|
75 m_observer = observer; |
|
76 } |
|
77 |
|
78 TInt CCentralRepositoryHandler::deleteKey(unsigned long key) |
|
79 { |
|
80 return iRepository->Delete(key); |
|
81 } |
|
82 |
|
83 TInt CCentralRepositoryHandler::resetKey(unsigned long key) |
|
84 { |
|
85 return iRepository->Reset(key); |
|
86 } |
|
87 |
|
88 TInt CCentralRepositoryHandler::resetRepository() |
|
89 { |
|
90 return iRepository->Reset(); |
|
91 } |
|
92 |
|
93 TInt CCentralRepositoryHandler::getValue(unsigned long key, TInt& value) |
|
94 { |
|
95 return iRepository->Get(key, value); |
|
96 } |
|
97 |
|
98 TInt CCentralRepositoryHandler::getValue(unsigned long key, TReal& value) |
|
99 { |
|
100 return iRepository->Get(key, value); |
|
101 } |
|
102 |
|
103 void CCentralRepositoryHandler::getValueL(unsigned long key, RBuf8& value) |
|
104 { |
|
105 TInt actualLength; |
|
106 TInt err = iRepository->Get(key, value, actualLength); |
|
107 if (err == KErrOverflow) |
|
108 { |
|
109 value.ReAllocL(actualLength); |
|
110 err = iRepository->Get(key, value); |
|
111 } |
|
112 User::LeaveIfError(err); |
|
113 } |
|
114 |
|
115 void CCentralRepositoryHandler::getValueL(unsigned long key, RBuf16& value) |
|
116 { |
|
117 TInt actualLength; |
|
118 TInt err = iRepository->Get(key, value, actualLength); |
|
119 if (err == KErrOverflow) |
|
120 { |
|
121 value.ReAllocL(actualLength); |
|
122 err = iRepository->Get(key, value); |
|
123 } |
|
124 User::LeaveIfError(err); |
|
125 } |
|
126 |
|
127 TInt CCentralRepositoryHandler::setValue(unsigned long key, const TInt& value) |
|
128 { |
|
129 return iRepository->Set(key, value); |
|
130 } |
|
131 |
|
132 TInt CCentralRepositoryHandler::setValue(unsigned long key, const TReal& value) |
|
133 { |
|
134 return iRepository->Set(key, value); |
|
135 } |
|
136 |
|
137 TInt CCentralRepositoryHandler::setValue(unsigned long key, const TDesC8& value) |
|
138 { |
|
139 return iRepository->Set(key, value); |
|
140 } |
|
141 |
|
142 TInt CCentralRepositoryHandler::setValue(unsigned long key, const TDesC16& value) |
|
143 { |
|
144 return iRepository->Set(key, value); |
|
145 } |
|
146 |
|
147 TInt CCentralRepositoryHandler::createKey(unsigned long key, const TInt& value) |
|
148 { |
|
149 return iRepository->Create(key, value); |
|
150 } |
|
151 |
|
152 TInt CCentralRepositoryHandler::createKey(unsigned long key, const TReal& value) |
|
153 { |
|
154 return iRepository->Create(key, value); |
|
155 } |
|
156 |
|
157 TInt CCentralRepositoryHandler::createKey(unsigned long key, const TDesC8& value) |
|
158 { |
|
159 return iRepository->Create(key, value); |
|
160 } |
|
161 |
|
162 TInt CCentralRepositoryHandler::createKey(unsigned long key, const TDesC16& value) |
|
163 { |
|
164 return iRepository->Create(key, value); |
|
165 } |
|
166 |
|
167 bool CCentralRepositoryHandler::handleStartMonitoring(const XQSettingsKey& key, XQSettingsManager::Type type, MSettingsHandlerObserver& observer, TInt& error) |
|
168 { |
|
169 if (m_monitors.contains(key.key())) |
|
170 { |
|
171 error = KErrAlreadyExists; |
|
172 return false; |
|
173 } |
|
174 CCenRepMonitor* newMonitor = new CCenRepMonitor(*iRepository, key, type, observer); |
|
175 if (newMonitor) |
|
176 { |
|
177 m_monitors[key.key()] = newMonitor; |
|
178 error = newMonitor->StartMonitoring(); |
|
179 return error == KErrNone; |
|
180 } |
|
181 error = KErrNoMemory; |
|
182 return false; |
|
183 } |
|
184 |
|
185 bool CCentralRepositoryHandler::handleStopMonitoring(const XQSettingsKey& key, TInt& error) |
|
186 { |
|
187 if (!m_monitors.contains(key.key())) |
|
188 { |
|
189 error = KErrNotFound; |
|
190 return false; |
|
191 } |
|
192 const long int itemKey = key.key(); |
|
193 CCenRepMonitor* monitor = m_monitors[itemKey]; |
|
194 m_monitors.remove(itemKey); |
|
195 delete monitor; |
|
196 |
|
197 return error == KErrNone; |
|
198 } |
|
199 |
|
200 TInt CCentralRepositoryHandler::findKeyL(unsigned long partialKey, TUint32 mask, RArray<TUint32>& aFoundKeys) |
|
201 { |
|
202 return iRepository->FindL(partialKey, mask, aFoundKeys); |
|
203 } |
|
204 |
|
205 TInt CCentralRepositoryHandler::findKeyL(unsigned long partialKey, TUint32 mask, const TInt& value, bool negative, RArray<TUint32>& aFoundKeys) |
|
206 { |
|
207 return negative ? iRepository->FindNeqL(partialKey, mask, value, aFoundKeys) : iRepository->FindEqL(partialKey, mask, value, aFoundKeys); |
|
208 } |
|
209 |
|
210 TInt CCentralRepositoryHandler::findKeyL(unsigned long partialKey, TUint32 mask, const TReal& value, bool negative, RArray<TUint32>& aFoundKeys) |
|
211 { |
|
212 return negative ? iRepository->FindNeqL(partialKey, mask, value, aFoundKeys) : iRepository->FindEqL(partialKey, mask, value, aFoundKeys); |
|
213 } |
|
214 |
|
215 TInt CCentralRepositoryHandler::findKeyL(unsigned long partialKey, TUint32 mask, const TDesC8& value, bool negative, RArray<TUint32>& aFoundKeys) |
|
216 { |
|
217 return negative ? iRepository->FindNeqL(partialKey, mask, value, aFoundKeys) : iRepository->FindEqL(partialKey, mask, value, aFoundKeys); |
|
218 } |
|
219 |
|
220 TInt CCentralRepositoryHandler::findKeyL(unsigned long partialKey, TUint32 mask, const TDesC16& value, bool negative, RArray<TUint32>& aFoundKeys) |
|
221 { |
|
222 return negative ? iRepository->FindNeqL(partialKey, mask, value, aFoundKeys) : iRepository->FindEqL(partialKey, mask, value, aFoundKeys); |
|
223 } |
|
224 |
|
225 #ifndef XQSETTINGSMANAGER_NO_TRANSACTIONS |
|
226 TInt CCentralRepositoryHandler::startTransaction(CRepository::TTransactionMode transactionMode) |
|
227 { |
|
228 return iRepository->StartTransaction(transactionMode); |
|
229 } |
|
230 #else |
|
231 TInt CCentralRepositoryHandler::startTransaction(CRepository::TTransactionMode /*transactionMode*/) |
|
232 { |
|
233 return KErrNotSupported; |
|
234 } |
|
235 #endif |
|
236 |
|
237 TInt CCentralRepositoryHandler::commitTransaction() |
|
238 { |
|
239 #ifndef XQSETTINGSMANAGER_NO_TRANSACTIONS |
|
240 TUint32 keyInfo; |
|
241 return iRepository->CommitTransaction(keyInfo); |
|
242 #else |
|
243 return KErrNotSupported; |
|
244 #endif |
|
245 } |
|
246 |
|
247 void CCentralRepositoryHandler::cancelTransaction() |
|
248 { |
|
249 #ifndef XQSETTINGSMANAGER_NO_TRANSACTIONS |
|
250 iRepository->CancelTransaction(); |
|
251 #endif |
|
252 } |
|
253 |
|
254 void CCentralRepositoryHandler::failTransaction() |
|
255 { |
|
256 #ifndef XQSETTINGSMANAGER_NO_TRANSACTIONS |
|
257 iRepository->FailTransaction(); |
|
258 #endif |
|
259 } |
|
260 |
|
261 TInt CCentralRepositoryHandler::transactionState() const |
|
262 { |
|
263 #ifndef XQSETTINGSMANAGER_NO_TRANSACTIONS |
|
264 return iRepository->TransactionState(); |
|
265 #else |
|
266 return KErrNotSupported; |
|
267 #endif |
|
268 } |