|
1 /* |
|
2 * Copyright (c) 2002 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: CCalenSetting has Calendar setting data. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //debug |
|
20 #include "calendarui_debug.h" |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include "calensetting.h" |
|
24 #include "CalendarVariant.hrh" |
|
25 #include "calencustomisationmanager.h" |
|
26 |
|
27 |
|
28 #include <AknUtils.h> |
|
29 |
|
30 |
|
31 #include <centralrepository.h> |
|
32 #include "CalendarPrivateCRKeys.h" // includes CalendarInternalCRKeys.h |
|
33 |
|
34 const TInt KDefaultSnoozeTime( 5 ); // minutes |
|
35 const TInt KComma( ',' ); |
|
36 const TInt KBoolCharTrue( '1' ); // character representing true in string. |
|
37 const TInt KBoolCharFalse( '0' ); // character representing false in string. |
|
38 |
|
39 const TInt KBufferStartingSize( 64 ); // initial size of buffer read from repository. |
|
40 const TInt KBufferSizeIncrement( 32 ); // buffer increases by this amount until we successfully read |
|
41 const TInt KCharsPerPlugin( 10 + 1 + 1 + 1 ); // [int - plugin uid] [comma] [1 or 0, plugin enabled] [comma] |
|
42 |
|
43 // ================= MEMBER FUNCTIONS ======================= |
|
44 |
|
45 // ---------------------------------------------------------------------------- |
|
46 // CCalenController::InstanceL |
|
47 // Returns a pointer to the single instance of the settings object. |
|
48 // ---------------------------------------------------------------------------- |
|
49 // |
|
50 EXPORT_C CCalenSetting* CCalenSetting::InstanceL() |
|
51 { |
|
52 TRACE_ENTRY_POINT; |
|
53 |
|
54 CCalenSetting* self = NULL; |
|
55 TAny* tlsPtr = Dll::Tls(); |
|
56 |
|
57 // Check Thread local storage |
|
58 if ( !tlsPtr ) |
|
59 { |
|
60 // TLS is NULL, so no CCalenController has been created yet. |
|
61 self = new( ELeave ) CCalenSetting(); |
|
62 CleanupStack::PushL( self ); |
|
63 // Store a self pointer in TLS |
|
64 User::LeaveIfError( Dll::SetTls( static_cast<TAny*>( self ) ) ); |
|
65 // Increment ref count right away. If we don't do it here, and someone |
|
66 // calls CCalenSetting::InstanceL in LoadL and then LoadL |
|
67 // leaves, we will double delete the settings. |
|
68 ++self->iRefCount; |
|
69 self->LoadL(); |
|
70 CleanupStack::Pop( self ); |
|
71 } |
|
72 else |
|
73 { |
|
74 self = static_cast<CCalenSetting*>( tlsPtr ); |
|
75 ++self->iRefCount; |
|
76 } |
|
77 |
|
78 TRACE_EXIT_POINT; |
|
79 return self; |
|
80 } |
|
81 |
|
82 // ---------------------------------------------------------------------------- |
|
83 // CCalenSetting::CCalenSetting |
|
84 // C++ default constructor can NOT contain any code, that |
|
85 // might leave. |
|
86 // ---------------------------------------------------------------------------- |
|
87 // |
|
88 CCalenSetting::CCalenSetting() |
|
89 : iWeekFormat( EMonday ), |
|
90 iWeekTitle( EWeekTitleNumber ), |
|
91 iSnoozeTime( KDefaultSnoozeTime ), |
|
92 iToolbar(1) |
|
93 |
|
94 { |
|
95 TRACE_ENTRY_POINT; |
|
96 TRACE_EXIT_POINT; |
|
97 } |
|
98 |
|
99 // ---------------------------------------------------------------------------- |
|
100 // CCalenSetting::Release |
|
101 // Decrement the reference count of this singleton. |
|
102 // When the reference count is 0, the controller will self delete and free |
|
103 // all resources |
|
104 // ---------------------------------------------------------------------------- |
|
105 // |
|
106 EXPORT_C void CCalenSetting::Release() |
|
107 { |
|
108 TRACE_ENTRY_POINT; |
|
109 |
|
110 --iRefCount; |
|
111 if ( iRefCount == 0 ) |
|
112 { |
|
113 delete this; |
|
114 } |
|
115 |
|
116 TRACE_EXIT_POINT; |
|
117 } |
|
118 |
|
119 // ---------------------------------------------------------------------------- |
|
120 // CCalenSetting::~CCalenSetting |
|
121 // Destructor |
|
122 // ---------------------------------------------------------------------------- |
|
123 // |
|
124 CCalenSetting::~CCalenSetting() |
|
125 { |
|
126 TRACE_ENTRY_POINT; |
|
127 |
|
128 Dll::SetTls( NULL ); |
|
129 iPluginAvailability.Reset(); |
|
130 |
|
131 TRACE_EXIT_POINT; |
|
132 } |
|
133 |
|
134 // ---------------------------------------------------------------------------- |
|
135 // CCalenSetting::PluginAvailabilityL |
|
136 // Returns array of plugins known to be enabled or disabled. |
|
137 // ---------------------------------------------------------------------------- |
|
138 // |
|
139 EXPORT_C CCalenCustomisationManager::CCalenPluginStatusArray& |
|
140 CCalenSetting::PluginAvailability() |
|
141 { |
|
142 TRACE_ENTRY_POINT; |
|
143 |
|
144 TRACE_EXIT_POINT; |
|
145 return iPluginAvailability; |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------- |
|
149 // CCalenSetting::DefaultView |
|
150 // Return default view |
|
151 // (other items were commented in a header). |
|
152 // --------------------------------------------------------- |
|
153 // |
|
154 EXPORT_C TUid CCalenSetting::DefaultView() const |
|
155 { |
|
156 TRACE_ENTRY_POINT; |
|
157 |
|
158 TRACE_EXIT_POINT; |
|
159 return iDefaultView; |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------- |
|
163 // CCalenSetting::WeekFormat |
|
164 // Return setting type of week format |
|
165 // (other items were commented in a header). |
|
166 // --------------------------------------------------------- |
|
167 // |
|
168 EXPORT_C TDay CCalenSetting::WeekFormat() const |
|
169 { |
|
170 TRACE_ENTRY_POINT; |
|
171 |
|
172 TRACE_EXIT_POINT; |
|
173 return iWeekFormat; |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------- |
|
177 // CCalenSetting::WeekTitle |
|
178 // Return setting type of week title |
|
179 // (other items were commented in a header). |
|
180 // --------------------------------------------------------- |
|
181 // |
|
182 EXPORT_C TCalenWeekTitle CCalenSetting::WeekTitle() const |
|
183 { |
|
184 TRACE_ENTRY_POINT; |
|
185 TRACE_EXIT_POINT; |
|
186 return iWeekTitle; |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------- |
|
190 // CCalenSetting::SnoozeTime |
|
191 // Return the snooze time setting. |
|
192 // (other items were commented in a header). |
|
193 // --------------------------------------------------------- |
|
194 // |
|
195 EXPORT_C TInt CCalenSetting::SnoozeTime() const |
|
196 { |
|
197 TRACE_ENTRY_POINT; |
|
198 |
|
199 TRACE_EXIT_POINT; |
|
200 return iSnoozeTime; |
|
201 } |
|
202 |
|
203 |
|
204 // --------------------------------------------------------- |
|
205 // CCalenSetting::Toolbar |
|
206 // Return the snooze time setting. |
|
207 // (other items were commented in a header). |
|
208 // --------------------------------------------------------- |
|
209 // |
|
210 EXPORT_C TInt CCalenSetting::Toolbar() |
|
211 { |
|
212 TRACE_ENTRY_POINT; |
|
213 |
|
214 if(AknLayoutUtils::PenEnabled()) |
|
215 { |
|
216 |
|
217 TRACE_EXIT_POINT; |
|
218 return iToolbar; |
|
219 } |
|
220 else |
|
221 { |
|
222 TRACE_EXIT_POINT; |
|
223 return 0; |
|
224 } |
|
225 } |
|
226 |
|
227 |
|
228 |
|
229 // ---------------------------------------------------------------------------- |
|
230 // CCalenSetting::RemovePluginsNoLongerInstalled |
|
231 // Checks the list of enabled/disabled plugins (iPluginAvailability), and if |
|
232 // any are no longer installed, remove them from the list. |
|
233 // Returns ETrue if action taken, EFalse otherwise. |
|
234 // ---------------------------------------------------------------------------- |
|
235 // |
|
236 TBool CCalenSetting::RemovePluginsNoLongerInstalled( const RImplInfoPtrArray& aAvailablePlugins ) |
|
237 { |
|
238 TRACE_ENTRY_POINT; |
|
239 |
|
240 TBool actionTaken( EFalse ); |
|
241 TBool found; |
|
242 |
|
243 for ( TInt i( iPluginAvailability.Count()-1 ); i>=0; --i ) |
|
244 { |
|
245 found = EFalse; |
|
246 for ( TInt j( 0 ); j<aAvailablePlugins.Count(); ++j ) |
|
247 { |
|
248 if ( aAvailablePlugins[j]->ImplementationUid() == iPluginAvailability[i].iUid ) |
|
249 { |
|
250 found = ETrue; |
|
251 break; |
|
252 } |
|
253 } |
|
254 |
|
255 if ( !found ) |
|
256 { |
|
257 // The settings list contains a plugin not in the implementation list. Remove it. |
|
258 iPluginAvailability.Remove( i ); |
|
259 actionTaken = ETrue; |
|
260 } |
|
261 } |
|
262 |
|
263 TRACE_EXIT_POINT; |
|
264 return actionTaken; |
|
265 } |
|
266 |
|
267 // ---------------------------------------------------------------------------- |
|
268 // CCalenSetting::AddPluginsNewlyInstalledL |
|
269 // Checks the list of enabled/disabled plugins (iPluginAvailability) against |
|
270 // the given array of available plugins, and if any plugins are not in the |
|
271 // availability list, add them. |
|
272 // Returns ETrue if action taken, EFalse otherwise. |
|
273 // ---------------------------------------------------------------------------- |
|
274 // |
|
275 TBool CCalenSetting::AddPluginsNewlyInstalledL( const RImplInfoPtrArray& aAvailablePlugins, |
|
276 CCalenCustomisationManager& aCustomisationManager) |
|
277 { |
|
278 TRACE_ENTRY_POINT; |
|
279 |
|
280 TBool actionTaken( EFalse ); |
|
281 TBool found; |
|
282 |
|
283 for ( TInt i( 0 ); i<aAvailablePlugins.Count(); ++i ) |
|
284 { |
|
285 found = EFalse; |
|
286 |
|
287 for ( TInt j( 0 ); j<iPluginAvailability.Count(); ++j ) |
|
288 { |
|
289 if ( aAvailablePlugins[i]->ImplementationUid() == iPluginAvailability[j].iUid ) |
|
290 { |
|
291 found = ETrue; |
|
292 break; |
|
293 } |
|
294 } |
|
295 |
|
296 if ( !found ) |
|
297 { |
|
298 // The plugin implementation isn't in the settings list. Add it. |
|
299 CCalenCustomisationManager::TCalenPluginAvailability newPlugin; |
|
300 newPlugin.iUid = aAvailablePlugins[i]->ImplementationUid(); |
|
301 newPlugin.iEnabled = ETrue; |
|
302 |
|
303 if(aCustomisationManager.CanBeEnabledDisabledL(newPlugin.iUid)) |
|
304 { |
|
305 iPluginAvailability.AppendL( newPlugin ); |
|
306 actionTaken = ETrue; |
|
307 } |
|
308 } |
|
309 } |
|
310 |
|
311 TRACE_EXIT_POINT; |
|
312 return actionTaken; |
|
313 } |
|
314 |
|
315 // ---------------------------------------------------------------------------- |
|
316 // CCalenSetting::UpdatePluginListL |
|
317 // Updates the stored list of enabled/disabled plugins. This should be called |
|
318 // when calendar starts and when any plugins are installed or uninstalled. |
|
319 // ---------------------------------------------------------------------------- |
|
320 // |
|
321 EXPORT_C void CCalenSetting::UpdatePluginListL( CCalenCustomisationManager& aCustomisationManager ) |
|
322 { |
|
323 TRACE_ENTRY_POINT; |
|
324 |
|
325 // Get the list of plugins which exist. |
|
326 const RImplInfoPtrArray& availablePlugins = aCustomisationManager.PluginInfoArray(); |
|
327 |
|
328 // Update the enabled/disabled plugin list. We might have had plugins |
|
329 // added or removed... |
|
330 |
|
331 // ...a plugin which was around but then got uninstalled should be removed |
|
332 // from our enabled/disabled list (otherwise the list could grow to be huge). |
|
333 const TBool anyRemoved = RemovePluginsNoLongerInstalled( availablePlugins ); |
|
334 |
|
335 // ...a new plugin should be enabled by default. |
|
336 const TBool anyAdded = AddPluginsNewlyInstalledL( availablePlugins,aCustomisationManager ); |
|
337 |
|
338 // Update the cenrep when necessary. |
|
339 if ( anyRemoved || anyAdded ) |
|
340 { |
|
341 CRepository *rep = CRepository::NewL( KCRUidCalendar ); |
|
342 CleanupStack::PushL( rep ); |
|
343 SavePluginListL( *rep ); |
|
344 CleanupStack::PopAndDestroy( rep ); |
|
345 } |
|
346 |
|
347 TRACE_EXIT_POINT; |
|
348 } |
|
349 |
|
350 // ---------------------------------------------------------------------------- |
|
351 // CCalenSetting::SetPluginStatusL |
|
352 // Sets a plugin on or off. |
|
353 // ---------------------------------------------------------------------------- |
|
354 // |
|
355 EXPORT_C void CCalenSetting::SetPluginStatusL( TUid aPluginUid, TBool aEnabled ) |
|
356 { |
|
357 TRACE_ENTRY_POINT; |
|
358 |
|
359 #ifdef _DEBUG |
|
360 TBool found = EFalse; |
|
361 #endif // _DEBUG |
|
362 |
|
363 for ( TInt i( 0 ); i<iPluginAvailability.Count(); ++i ) |
|
364 { |
|
365 if ( iPluginAvailability[i].iUid == aPluginUid ) |
|
366 { |
|
367 iPluginAvailability[i].iEnabled = aEnabled; |
|
368 #ifdef _DEBUG |
|
369 found = ETrue; |
|
370 #endif // _DEBUG |
|
371 break; |
|
372 } |
|
373 } |
|
374 |
|
375 // Plugin list should always be up to date. If this fails, |
|
376 // UpdatePluginListL wasn't called when plugins were installed/uninstalled. |
|
377 ASSERT( found ); |
|
378 |
|
379 TRACE_EXIT_POINT; |
|
380 } |
|
381 |
|
382 // ---------------------------------------------------------------------------- |
|
383 // CCalenSetting::SavePluginListL |
|
384 // Saves the list of enabled/disabled plugins. |
|
385 // ---------------------------------------------------------------------------- |
|
386 // |
|
387 void CCalenSetting::SavePluginListL( CRepository& aRepository ) const |
|
388 { |
|
389 TRACE_ENTRY_POINT; |
|
390 |
|
391 RBuf buf; |
|
392 CleanupClosePushL( buf ); |
|
393 buf.CreateL( KCharsPerPlugin * iPluginAvailability.Count() ); |
|
394 PopulateBufferFromPluginAvailabilityL( buf ); |
|
395 |
|
396 User::LeaveIfError( aRepository.Set( KCalendarPluginAvailability, buf ) ); |
|
397 |
|
398 CleanupStack::PopAndDestroy( &buf ); |
|
399 |
|
400 TRACE_EXIT_POINT; |
|
401 } |
|
402 |
|
403 // ---------------------------------------------------------------------------- |
|
404 // CCalenSetting::BoolFromStringL |
|
405 // Converts a character to a bool. |
|
406 // ---------------------------------------------------------------------------- |
|
407 // |
|
408 static TBool BoolFromCharL( const TChar& aChar ) |
|
409 { |
|
410 TRACE_ENTRY_POINT; |
|
411 |
|
412 TBool ret; |
|
413 if ( aChar == KBoolCharTrue ) |
|
414 { |
|
415 ret = ETrue; |
|
416 } |
|
417 else |
|
418 { |
|
419 ASSERT( aChar == KBoolCharFalse ); |
|
420 ret = EFalse; |
|
421 } |
|
422 |
|
423 TRACE_EXIT_POINT; |
|
424 return ret; |
|
425 } |
|
426 |
|
427 // ---------------------------------------------------------------------------- |
|
428 // CCalenSetting::UidFromStringL |
|
429 // Converts a string to a uid. |
|
430 // ---------------------------------------------------------------------------- |
|
431 // |
|
432 static TUid UidFromStringL( const TDesC& aString ) |
|
433 { |
|
434 TRACE_ENTRY_POINT; |
|
435 |
|
436 // Convert the string to an int first. |
|
437 TLex lex( aString ); |
|
438 TInt val; |
|
439 User::LeaveIfError( lex.Val( val ) ); |
|
440 TUid uid = TUid::Uid( val ); |
|
441 |
|
442 TRACE_EXIT_POINT; |
|
443 return uid; |
|
444 } |
|
445 |
|
446 // ---------------------------------------------------------------------------- |
|
447 // CCalenSetting::PopulatePluginAvailabilityFromBufferL |
|
448 // Converts from a text string into a plugin availability array. |
|
449 // ---------------------------------------------------------------------------- |
|
450 // |
|
451 void CCalenSetting::PopulatePluginAvailabilityFromBufferL( const TDesC& aBuf ) |
|
452 { |
|
453 TRACE_ENTRY_POINT; |
|
454 |
|
455 // Calling Reset would give us an invalid array. |
|
456 iPluginAvailability.Reset(); |
|
457 |
|
458 TPtrC marker = aBuf; |
|
459 TInt uidOffset; |
|
460 |
|
461 // aBuf should be of the format "uid,enabled,uid,enabled[etc]" |
|
462 // e.g. "12345,1,67890,0" would be uid 12345 enabled, uid 67890 disabled. |
|
463 while( ( uidOffset = marker.Locate( TChar( KComma ) ) ) != KErrNotFound ) |
|
464 { |
|
465 TUid uid = UidFromStringL( marker.Left( uidOffset ) ); |
|
466 // Set marker to one char after the comma. |
|
467 marker.Set( marker.Mid( uidOffset+1 ) ); |
|
468 |
|
469 TInt enabledOffset = marker.Locate( TChar( KComma ) ); |
|
470 // If this assert fails, a uid was added but no bool followed it. |
|
471 ASSERT( enabledOffset != KErrNotFound ); |
|
472 TBool enabled = BoolFromCharL( marker[0] ); |
|
473 // One after the enabled value. |
|
474 marker.Set( marker.Mid( enabledOffset+1 ) ); |
|
475 |
|
476 CCalenCustomisationManager::TCalenPluginAvailability availability; |
|
477 availability.iUid = uid; |
|
478 availability.iEnabled = enabled; |
|
479 iPluginAvailability.AppendL( availability ); |
|
480 } |
|
481 |
|
482 TRACE_EXIT_POINT; |
|
483 } |
|
484 |
|
485 // ---------------------------------------------------------------------------- |
|
486 // CCalenSetting::PopulateBufferFromPluginAvailabilityL |
|
487 // Converts from a plugin availability array into a text string. |
|
488 // ---------------------------------------------------------------------------- |
|
489 // |
|
490 void CCalenSetting::PopulateBufferFromPluginAvailabilityL( RBuf& aBuf ) const |
|
491 { |
|
492 TRACE_ENTRY_POINT; |
|
493 |
|
494 // At the end of this function, aBuf should be of the format |
|
495 // "uid,enabled,uid,enabled[etc]" e.g. "12345,1,67890,0" would be |
|
496 // uid 12345 enabled, uid 67890 disabled. |
|
497 for ( TInt i( 0 ); i<iPluginAvailability.Count(); ++i ) |
|
498 { |
|
499 aBuf.AppendNum( iPluginAvailability[i].iUid.iUid ); |
|
500 aBuf.Append( KComma ); |
|
501 TChar enabled = iPluginAvailability[i].iEnabled ? |
|
502 KBoolCharTrue : KBoolCharFalse; |
|
503 aBuf.Append( enabled ); |
|
504 aBuf.Append( KComma ); |
|
505 } |
|
506 |
|
507 TRACE_EXIT_POINT; |
|
508 } |
|
509 |
|
510 // --------------------------------------------------------- |
|
511 // CCalenSetting::SetDefaultView |
|
512 // Set default view |
|
513 // (other items were commented in a header). |
|
514 // --------------------------------------------------------- |
|
515 // |
|
516 EXPORT_C void CCalenSetting::SetDefaultView( TUid aDefView ) |
|
517 { |
|
518 TRACE_ENTRY_POINT; |
|
519 |
|
520 iDefaultView = aDefView; |
|
521 |
|
522 TRACE_EXIT_POINT; |
|
523 } |
|
524 |
|
525 // --------------------------------------------------------- |
|
526 // CCalenSetting::SetWeekFormat |
|
527 // Set startday of week |
|
528 // (other items were commented in a header). |
|
529 // --------------------------------------------------------- |
|
530 // |
|
531 EXPORT_C void CCalenSetting::SetWeekFormat( TDay aDay ) |
|
532 { |
|
533 TRACE_ENTRY_POINT; |
|
534 |
|
535 iWeekFormat = aDay; |
|
536 |
|
537 TRACE_EXIT_POINT; |
|
538 } |
|
539 |
|
540 // --------------------------------------------------------- |
|
541 // CCalenSetting::SetWeekTitle |
|
542 // Set week title |
|
543 // (other items were commented in a header). |
|
544 // --------------------------------------------------------- |
|
545 // |
|
546 EXPORT_C void CCalenSetting::SetWeekTitle( TCalenWeekTitle aTitle ) |
|
547 { |
|
548 TRACE_ENTRY_POINT; |
|
549 |
|
550 iWeekTitle = aTitle; |
|
551 |
|
552 TRACE_EXIT_POINT; |
|
553 } |
|
554 |
|
555 // --------------------------------------------------------- |
|
556 // CCalenSetting::SetSnoozeTime |
|
557 // Return the snooze time setting. |
|
558 // (other items were commented in a header). |
|
559 // --------------------------------------------------------- |
|
560 // |
|
561 EXPORT_C void CCalenSetting::SetSnoozeTime( TInt aSnoozeTime ) |
|
562 { |
|
563 TRACE_ENTRY_POINT |
|
564 |
|
565 iSnoozeTime = aSnoozeTime; |
|
566 |
|
567 TRACE_EXIT_POINT |
|
568 } |
|
569 |
|
570 // --------------------------------------------------------- |
|
571 // CCalenSetting::SetToolbar |
|
572 // Return the snooze time setting. |
|
573 // (other items were commented in a header). |
|
574 // --------------------------------------------------------- |
|
575 // |
|
576 EXPORT_C void CCalenSetting::SetToolbar( TInt aShown ) |
|
577 { |
|
578 TRACE_ENTRY_POINT; |
|
579 |
|
580 iToolbar = aShown; |
|
581 |
|
582 TRACE_EXIT_POINT; |
|
583 } |
|
584 |
|
585 |
|
586 // ----------------------------------------------------------------------------- |
|
587 // ?classname::?member_function |
|
588 // ?implementation_description |
|
589 // (other items were commented in a header). |
|
590 // ----------------------------------------------------------------------------- |
|
591 // |
|
592 EXPORT_C void CCalenSetting::LoadL() |
|
593 { |
|
594 TRACE_ENTRY_POINT; |
|
595 |
|
596 // 'Calendar alarm tone' is loaded and saved in CalenFileListSettingItem |
|
597 |
|
598 // 'First day of week' is read from TLocale |
|
599 TLocale locale; |
|
600 iWeekFormat = locale.StartOfWeek(); |
|
601 |
|
602 // other settings are stored in central repository |
|
603 CRepository* repository = CRepository::NewL( KCRUidCalendar ); |
|
604 CleanupStack::PushL( repository ); |
|
605 |
|
606 // There's no real way of telling how big this buffer needs to be. If we |
|
607 // get an overflow we'll just try again with a bigger buffer. |
|
608 TInt bufSize( KBufferStartingSize ); |
|
609 TBool wasRead( EFalse ); |
|
610 |
|
611 do |
|
612 { |
|
613 RBuf buf; |
|
614 CleanupClosePushL( buf ); |
|
615 buf.CreateL( bufSize ); |
|
616 |
|
617 TInt err = repository->Get( KCalendarPluginAvailability, buf ); |
|
618 |
|
619 if ( err == KErrNone ) |
|
620 { |
|
621 wasRead = ETrue; |
|
622 PopulatePluginAvailabilityFromBufferL( buf ); |
|
623 } |
|
624 else if ( err == KErrOverflow ) |
|
625 { |
|
626 bufSize += KBufferSizeIncrement; |
|
627 } |
|
628 else |
|
629 { |
|
630 // If err is KErrNotFound (-1) then your repository files probably |
|
631 // aren't set up correctly. (If on the emulator, be sure |
|
632 // \epoc32\winscw\c\private\10202be9\persists\101f874b.cre |
|
633 // is up to date.) |
|
634 User::Leave( err ); |
|
635 } |
|
636 |
|
637 CleanupStack::PopAndDestroy( &buf ); |
|
638 } while ( !wasRead ); |
|
639 |
|
640 TInt tmp; |
|
641 // TViewType maps |
|
642 // [ENotSet, EMonthView, EWeekView, EDayView, EToDoView to [0..4] |
|
643 // Central Repository data differs: |
|
644 // [EMonthView, EWeekView, EDayView, EToDoView] to [0..3] |
|
645 User::LeaveIfError( repository->Get( KCalendarDefaultStartView, tmp ) ); |
|
646 iDefaultView.iUid = tmp; |
|
647 |
|
648 // TCalenWeekTitle maps [EWeekTitleNumber,EWeekTitleDuration] to [0,1] |
|
649 // Central Repository data matches. |
|
650 User::LeaveIfError( repository->Get( KCalendarWeekViewTitle, tmp ) ); |
|
651 iWeekTitle = static_cast<TCalenWeekTitle>( tmp ); |
|
652 |
|
653 User::LeaveIfError( repository->Get( KCalendarSnoozeTime, tmp ) ); |
|
654 iSnoozeTime = tmp; |
|
655 |
|
656 CleanupStack::PopAndDestroy( repository ); |
|
657 |
|
658 TRACE_EXIT_POINT |
|
659 } |
|
660 |
|
661 // ----------------------------------------------------------------------------- |
|
662 // ?classname::?member_function |
|
663 // ?implementation_description |
|
664 // (other items were commented in a header). |
|
665 // ----------------------------------------------------------------------------- |
|
666 // |
|
667 EXPORT_C void CCalenSetting::SaveL() const |
|
668 { |
|
669 TRACE_ENTRY_POINT; |
|
670 |
|
671 // 'Calendar alarm tone' is loaded and saved in CalenFileListSettingItem |
|
672 |
|
673 TLocale locale; |
|
674 |
|
675 // 'First day of week' is saved in TLocale |
|
676 if ( locale.StartOfWeek() != iWeekFormat ) |
|
677 { |
|
678 locale.SetStartOfWeek( iWeekFormat ); |
|
679 locale.Set(); |
|
680 } |
|
681 |
|
682 // other settings are stored in central repository |
|
683 CRepository* repository = CRepository::NewL( KCRUidCalendar ); |
|
684 CleanupStack::PushL( repository ); |
|
685 |
|
686 SavePluginListL( *repository ); |
|
687 |
|
688 // TViewType maps |
|
689 // [ENotSet, EMonthView, EWeekView, EDayView, EToDoView to [0..4] |
|
690 // Central Repository data differs: |
|
691 // [EMonthView, EWeekView, EDayView, EToDoView] to [0..3] |
|
692 //ASSERT( iDefaultView > 0 ); |
|
693 TInt tmp( static_cast<TInt>( iDefaultView.iUid ) ); |
|
694 User::LeaveIfError( repository->Set( KCalendarDefaultStartView, tmp ) ); |
|
695 |
|
696 // TCalenWeekTitle maps [EWeekTitleNumber,EWeekTitleDuration] to [0,1] |
|
697 // Central Repository data matches. |
|
698 tmp = static_cast<TCalenWeekTitle>( iWeekTitle ); |
|
699 User::LeaveIfError( repository->Set( KCalendarWeekViewTitle, tmp ) ); |
|
700 |
|
701 tmp = iSnoozeTime; |
|
702 User::LeaveIfError( repository->Set( KCalendarSnoozeTime, tmp ) ); |
|
703 |
|
704 CleanupStack::PopAndDestroy( repository ); |
|
705 TRACE_EXIT_POINT; |
|
706 } |
|
707 |
|
708 |
|
709 #ifdef RD_CALEN_EXTERNAL_CAL |
|
710 // --------------------------------------------------------- |
|
711 // CCalenSetting::ExtCalendar |
|
712 // Return cenrep value of external calendar availability |
|
713 // (other items were commented in a header). |
|
714 // --------------------------------------------------------- |
|
715 // |
|
716 EXPORT_C TInt CCalenSetting::ExtCalendar() const |
|
717 { |
|
718 TRACE_ENTRY_POINT; |
|
719 |
|
720 TInt enabled( 0 ); |
|
721 CRepository* repository = NULL; |
|
722 |
|
723 PIM_TRAPD_HANDLE( (repository = CRepository::NewL( KCRUidCalenUIExtensions )) ); |
|
724 |
|
725 if( repository ) |
|
726 { |
|
727 repository->Get( KCalenExternalCalendarEnabled, enabled ); |
|
728 delete repository; |
|
729 } |
|
730 |
|
731 // If value is other than 0/1 for some reason then it is possible to |
|
732 // add limitation to here. Should not be needed ever. |
|
733 TRACE_EXIT_POINT; |
|
734 return enabled; |
|
735 } |
|
736 |
|
737 // --------------------------------------------------------- |
|
738 // CCalenSetting::SetExtCalendar |
|
739 // Return 1 if external calendar is available. This value |
|
740 // is used as a index for enumeration items. |
|
741 // (other items were commented in a header). |
|
742 // --------------------------------------------------------- |
|
743 // |
|
744 EXPORT_C void CCalenSetting::SetExtCalendar(TInt aEnabled) |
|
745 { |
|
746 TRACE_ENTRY_POINT; |
|
747 |
|
748 CRepository* repository = NULL; |
|
749 |
|
750 PIM_TRAPD_HANDLE( (repository = CRepository::NewL( KCRUidCalenUIExtensions )) ); |
|
751 |
|
752 if( repository ) |
|
753 { |
|
754 repository->Set( KCalenExternalCalendarEnabled, aEnabled ); |
|
755 delete repository; |
|
756 } |
|
757 |
|
758 TRACE_EXIT_POINT; |
|
759 } |
|
760 #endif //RD_CALEN_EXTERNAL_CAL |
|
761 |
|
762 // End of File |