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