|
1 /* |
|
2 * Copyright (c) 2002-2006 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: Implementation of CMailCRhandler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CMailCRHandler.h" |
|
22 #include "MsgMailDocument.h" |
|
23 #include <centralrepository.h> |
|
24 #include <e32cmn.h> |
|
25 #include "MailLog.h" |
|
26 |
|
27 //repositories |
|
28 #include <MailInternalCRKeys.h> |
|
29 #include <CommonUiInternalCRKeys.h> |
|
30 #include <messaginginternalcrkeys.h> |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS =============================== |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CMailCRHandler::CMailCRHandler |
|
36 // C++ default constructor can NOT contain any code, that |
|
37 // might leave. |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CMailCRHandler::CMailCRHandler(CMsgMailDocument* aModel) |
|
41 : iModel( aModel ) |
|
42 { |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CMailCRHandler::ConstructL |
|
47 // Symbian 2nd phase constructor can leave. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 void CMailCRHandler::ConstructL() |
|
51 { |
|
52 CRepository* mailSession = CRepository::NewLC( KCRUidMail ); |
|
53 iSessions.AppendL(mailSession); |
|
54 CleanupStack::Pop(); // mailSession |
|
55 |
|
56 CRepository* muiuSession = CRepository::NewLC( KCRUidCommonUi ); |
|
57 iSessions.AppendL(muiuSession); |
|
58 CleanupStack::Pop(); // muiuSession |
|
59 |
|
60 CRepository* muiuVariation = CRepository::NewLC( KCRUidMuiuVariation ); |
|
61 iSessions.AppendL(muiuVariation); |
|
62 CleanupStack::Pop(); // muiuVariation |
|
63 |
|
64 GetCRInt( KCRUidMail, KMailLocalVariationFlags, |
|
65 iMailUiLocalVariationFlags ); |
|
66 LOG1( "CMailCRHandler::ConstructL LV-Flags:%d", |
|
67 iMailUiLocalVariationFlags ); |
|
68 |
|
69 GetCRInt( KCRUidMuiuVariation, KMuiuEmailConfigFlags, |
|
70 iMuiuVariationFlags ); |
|
71 LOG1( "CMailCRHandler::ConstructL MUIU-email Flags:%d", |
|
72 iMuiuVariationFlags ); |
|
73 |
|
74 GetCRInt( KCRUidMuiuVariation, KMuiuMmsFeatures, |
|
75 iMmsVariationFags ); |
|
76 LOG1( "CMailCRHandler::ConstructL MUIU-mms Flags:%d", |
|
77 iMmsVariationFags ); |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CMailCRHandler::NewL |
|
82 // Two-phased constructor. |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 EXPORT_C CMailCRHandler* CMailCRHandler::NewL( CMsgMailDocument* aModel ) |
|
86 { |
|
87 CMailCRHandler* self = new( ELeave ) CMailCRHandler( aModel ); |
|
88 |
|
89 CleanupStack::PushL( self ); |
|
90 self->ConstructL(); |
|
91 CleanupStack::Pop(); |
|
92 |
|
93 return self; |
|
94 } |
|
95 |
|
96 |
|
97 // Destructor |
|
98 EXPORT_C CMailCRHandler::~CMailCRHandler() |
|
99 { |
|
100 iSettingsNotifyHandlers.ResetAndDestroy(); |
|
101 iSessions.ResetAndDestroy(); |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CMailCRHandler::HandleNotifyInt |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 void CMailCRHandler::HandleNotifyInt( |
|
109 const TUint32 aID, |
|
110 const TInt aNewValue ) |
|
111 { |
|
112 // then inform the model about it. |
|
113 if( aID == KMailAdditionalHeaderSettings ) |
|
114 { |
|
115 TInt additionalHeaderSettings = aNewValue; |
|
116 if( additionalHeaderSettings >= 0 ) |
|
117 { |
|
118 TRAPD( err, iModel->SetReceivedIntL( |
|
119 CMsgMailDocument::EIndexAddHeaders, |
|
120 additionalHeaderSettings )); |
|
121 if ( err ) |
|
122 { |
|
123 LOG1( "CMailCRHandler::HandleNotifyInt failed err:%d", err ); |
|
124 } |
|
125 } |
|
126 } |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CMailCRHandler::HandleNotifyReal |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 void CMailCRHandler::HandleNotifyReal(TUint32 /*aId*/, TReal /*aNewValue*/) |
|
134 { |
|
135 //NO OPERATION |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CMailCRHandler::HandleNotifyString |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 void CMailCRHandler::HandleNotifyString( |
|
143 TUint32 /*aId*/, const TDesC16& /*aNewValue*/) |
|
144 { |
|
145 //NO OPERATION |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CMailCRHandler::HandleNotifyBinary |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 void CMailCRHandler::HandleNotifyBinary( |
|
153 TUint32 /*aId*/, const TDesC8& /*aNewValue*/) |
|
154 { |
|
155 //NO OPERATION |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CMailCRHandler::HandleNotifyGeneric |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CMailCRHandler::HandleNotifyGeneric( const TUint32 /*aID*/ ) |
|
163 { |
|
164 //NO OPERATION |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CMailCRHandler::HandleNotifyError |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 void CMailCRHandler::HandleNotifyError( |
|
172 const TUint32 /*aID*/, |
|
173 const TInt /*aError*/, |
|
174 CCenRepNotifyHandler* /*aHandler*/ ) |
|
175 { |
|
176 //NO OPERATION |
|
177 } |
|
178 |
|
179 |
|
180 |
|
181 EXPORT_C void CMailCRHandler::UpdateModelFromCentralRepositoryL() |
|
182 { |
|
183 TInt headerSettings; |
|
184 |
|
185 // Get the additional header settings, |
|
186 // if not initialized update with default value |
|
187 TInt err = (iSessions[EMailRepository])->Get( |
|
188 KMailAdditionalHeaderSettings, headerSettings ); |
|
189 if( err == KErrNotFound || err == KErrUnknown || headerSettings < 0 ) |
|
190 { |
|
191 (iSessions[EMailRepository])->Set( KMailAdditionalHeaderSettings, 5 ); // CSI: 47 # See a comment above. |
|
192 } |
|
193 |
|
194 iModel->SetReceivedIntL( |
|
195 CMsgMailDocument::EIndexAddHeaders, headerSettings ); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CMailCRHandler::GetCRInt |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 EXPORT_C TInt CMailCRHandler::GetCRInt( |
|
203 const TUid& aUid, |
|
204 const TUint32 aKey, |
|
205 TInt& aValue ) const |
|
206 { |
|
207 // Prepare and get client |
|
208 CRepository* client(NULL); |
|
209 |
|
210 TInt err = GetClientForUid( aUid, client ); |
|
211 |
|
212 // Check if problems with getting the client |
|
213 if( err == KErrNone ) |
|
214 { |
|
215 err = client->Get( aKey, aValue ); |
|
216 } |
|
217 |
|
218 // Return result |
|
219 return err; |
|
220 } |
|
221 |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // CMailCRHandler::SetCRInt |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 EXPORT_C TInt CMailCRHandler::SetCRInt( |
|
228 const TUid& aUid, |
|
229 const TUint32 aKey, |
|
230 const TInt aValue) const |
|
231 { |
|
232 // Prepare and get client |
|
233 CRepository* client(NULL); |
|
234 |
|
235 TInt err = GetClientForUid( aUid, client ); |
|
236 |
|
237 // Check if problems with getting the client |
|
238 if( err == KErrNone ) |
|
239 { |
|
240 err = client->Set( aKey, aValue ); |
|
241 } |
|
242 |
|
243 // Return result |
|
244 return err; |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CMailCRHandler::GetCRReal |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 EXPORT_C TInt CMailCRHandler::GetCRReal( |
|
252 const TUid& aUid, |
|
253 const TUint32 aKey, |
|
254 TReal& aValue ) const |
|
255 { |
|
256 // Prepare and get client |
|
257 CRepository* client(NULL); |
|
258 |
|
259 TInt err = GetClientForUid( aUid, client ); |
|
260 |
|
261 // Check if problems with getting the client |
|
262 if( err == KErrNone ) |
|
263 { |
|
264 err = client->Get( aKey, aValue ); |
|
265 } |
|
266 |
|
267 // Return result |
|
268 return err; |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // CMailCRHandler::SetCRReal |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 EXPORT_C TInt CMailCRHandler::SetCRReal( |
|
276 const TUid& aUid, |
|
277 const TUint32 aKey, |
|
278 const TReal& aValue ) const |
|
279 { |
|
280 // Prepare and get client |
|
281 CRepository* client(NULL); |
|
282 |
|
283 TInt err = GetClientForUid( aUid, client ); |
|
284 |
|
285 // Check if problems with getting the client |
|
286 if( err == KErrNone ) |
|
287 { |
|
288 err = client->Set( aKey, aValue ); |
|
289 } |
|
290 |
|
291 // Return result |
|
292 return err; |
|
293 } |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // CMailCRHandler::GetCRBinary |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 EXPORT_C TInt CMailCRHandler::GetCRBinary( |
|
300 const TUid& aUid, |
|
301 const TUint32 aKey, |
|
302 TDes8& aValue ) const |
|
303 { |
|
304 // Prepare and get client |
|
305 CRepository* client(NULL); |
|
306 |
|
307 TInt err = GetClientForUid( aUid, client ); |
|
308 |
|
309 // Check if problems with getting the client |
|
310 if( err == KErrNone ) |
|
311 { |
|
312 err = client->Get( aKey, aValue ); |
|
313 } |
|
314 |
|
315 // Return result |
|
316 return err; |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // CMailCRHandler::SetCRBinary |
|
321 // ----------------------------------------------------------------------------- |
|
322 // |
|
323 EXPORT_C TInt CMailCRHandler::SetCRBinary( |
|
324 const TUid& aUid, |
|
325 const TUint32 aKey, |
|
326 const TDesC8& aValue ) const |
|
327 { |
|
328 // Prepare and get client |
|
329 CRepository* client(NULL); |
|
330 |
|
331 TInt err = GetClientForUid( aUid, client ); |
|
332 |
|
333 // Check if problems with getting the client |
|
334 if( err == KErrNone ) |
|
335 { |
|
336 err = client->Set( aKey, aValue ); |
|
337 } |
|
338 |
|
339 // Return result |
|
340 return err; |
|
341 } |
|
342 |
|
343 // --------------------------------------------------------------------------- |
|
344 // CMailCRHandler::GetCRString |
|
345 // ----------------------------------------------------------------------------- |
|
346 // |
|
347 EXPORT_C TInt CMailCRHandler::GetCRString( |
|
348 const TUid& aUid, |
|
349 const TUint32 aKey, |
|
350 TDes16& aValue ) const |
|
351 { |
|
352 // Prepare and get client |
|
353 CRepository* client(NULL); |
|
354 |
|
355 TInt err = GetClientForUid( aUid, client ); |
|
356 |
|
357 // Check if problems with getting the client |
|
358 if( err == KErrNone ) |
|
359 { |
|
360 err = client->Get( aKey, aValue ); |
|
361 } |
|
362 |
|
363 // Return result |
|
364 return err; |
|
365 } |
|
366 |
|
367 // ----------------------------------------------------------------------------- |
|
368 // CMailCRHandler::SetCRString |
|
369 // ----------------------------------------------------------------------------- |
|
370 // |
|
371 EXPORT_C TInt CMailCRHandler::SetCRString( |
|
372 const TUid& aUid, |
|
373 const TUint32 aKey, |
|
374 const TDesC16& aValue ) const |
|
375 { |
|
376 // Prepare and get client |
|
377 CRepository* client(NULL); |
|
378 |
|
379 TInt err = GetClientForUid( aUid, client ); |
|
380 |
|
381 // Check if problems with getting the client |
|
382 if( err == KErrNone ) |
|
383 { |
|
384 err = client->Set( aKey, aValue ); |
|
385 } |
|
386 |
|
387 // Return result |
|
388 return err; |
|
389 } |
|
390 |
|
391 // ----------------------------------------------------------------------------- |
|
392 // CMailCRHandler::GetClientForUid |
|
393 // ----------------------------------------------------------------------------- |
|
394 // |
|
395 TInt CMailCRHandler::GetClientForUid( |
|
396 const TUid& aUid, |
|
397 CRepository*& aClient ) const |
|
398 { |
|
399 TInt error = KErrNone; |
|
400 |
|
401 if( aUid == KCRUidMail ) |
|
402 { |
|
403 // Get mail observer |
|
404 aClient = iSessions[EMailRepository]; |
|
405 } |
|
406 else if( aUid == KCRUidCommonUi ) |
|
407 { |
|
408 // Get common ui observer |
|
409 aClient = iSessions[ECommonUiRepository]; |
|
410 } |
|
411 else if( aUid == KCRUidMuiuVariation ) |
|
412 { |
|
413 aClient = iSessions[EMuiuVariationKeys]; |
|
414 } |
|
415 else |
|
416 { |
|
417 // Return error |
|
418 error = KErrNotFound; |
|
419 } |
|
420 |
|
421 return error; |
|
422 } |
|
423 |
|
424 // ----------------------------------------------------------------------------- |
|
425 // CMailCRHandler::SetNotifyHandlerL |
|
426 // ----------------------------------------------------------------------------- |
|
427 // |
|
428 EXPORT_C void CMailCRHandler::SetNotifyHandlerL( |
|
429 MCenRepNotifyHandlerCallback* aCallBack, |
|
430 CMailCRHandler::ERepository aRepository, |
|
431 CCenRepNotifyHandler::TCenRepKeyType aKeyType, TUint32 aKeyValue ) |
|
432 { |
|
433 __ASSERT_DEBUG( aRepository < ERepositoryOutOfBounds, User::Invariant() ); |
|
434 |
|
435 MCenRepNotifyHandlerCallback* observer; |
|
436 if (!aCallBack) |
|
437 observer = this; |
|
438 else |
|
439 observer = aCallBack; |
|
440 |
|
441 CCenRepNotifyHandler* mailSettingsNotifyHandler = |
|
442 CCenRepNotifyHandler::NewLC( |
|
443 *observer, |
|
444 *iSessions[aRepository], // CSI: 2 # This is checked above in the assert macro. |
|
445 aKeyType, |
|
446 aKeyValue ); |
|
447 |
|
448 mailSettingsNotifyHandler->StartListeningL(); |
|
449 iSettingsNotifyHandlers.AppendL(mailSettingsNotifyHandler); |
|
450 CleanupStack::Pop(mailSettingsNotifyHandler); |
|
451 } |
|
452 |
|
453 // End of File |