phonebookui/Phonebook2/UIControls/src/CPbk2MemorySelectionSettingItem.cpp
branchRCL_3
changeset 20 f4a778e096c2
parent 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Phonebook 2 memory selection setting item.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CPbk2MemorySelectionSettingItem.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include "CPbk2MemorySelectionSettingPage.h"
       
    23 #include <CPbk2StoreConfiguration.h>
       
    24 #include <CPbk2StorePropertyArray.h>
       
    25 #include <CPbk2StoreProperty.h>
       
    26 #include <MPbk2ApplicationServices.h>
       
    27 #include <MPbk2AppUi.h>
       
    28 #include <Pbk2UIControls.rsg>
       
    29 
       
    30 // Virtual Phonebook
       
    31 #include <CVPbkContactStoreUriArray.h>
       
    32 #include <TVPbkContactStoreUriPtr.h>
       
    33 
       
    34 // System includes
       
    35 #include <badesca.h>
       
    36 #include <StringLoader.h>
       
    37 
       
    38 /// Unnamed namespace for local definitions
       
    39 namespace {
       
    40 
       
    41 const TInt KBufferSize( 100 );
       
    42 
       
    43 #ifdef _DEBUG
       
    44 enum TPanicCode
       
    45     {
       
    46     EPanicStoreNotSupported = 1,
       
    47     EPanicIndexOOB
       
    48     };
       
    49 
       
    50 void Panic(TPanicCode aReason)
       
    51     {
       
    52     _LIT(KPanicText, "CPbk2MemorySelectionSettingItem");
       
    53     User::Panic(KPanicText, aReason);
       
    54     }
       
    55 #endif // _DEBUG
       
    56 
       
    57 }  /// namespace
       
    58 
       
    59 // --------------------------------------------------------------------------
       
    60 // CPbk2MemorySelectionSettingItem::CPbk2MemorySelectionSettingItem
       
    61 // --------------------------------------------------------------------------
       
    62 //
       
    63 CPbk2MemorySelectionSettingItem::CPbk2MemorySelectionSettingItem
       
    64         ( TInt aSettingId, CVPbkContactStoreUriArray& aSupportedStores,
       
    65         CSelectionItemList& aSelectionItemList ) :
       
    66             CAknSettingItem( aSettingId ),
       
    67             iSupportedStores( aSupportedStores ),
       
    68             iSelectionItemList( aSelectionItemList )
       
    69     {
       
    70     }
       
    71 
       
    72 // --------------------------------------------------------------------------
       
    73 // CPbk2MemorySelectionSettingItem::~CPbk2MemorySelectionSettingItem
       
    74 // --------------------------------------------------------------------------
       
    75 //
       
    76 CPbk2MemorySelectionSettingItem::~CPbk2MemorySelectionSettingItem()
       
    77     {
       
    78     delete iSeveralMemories;
       
    79     delete iSettingText;
       
    80     }
       
    81 
       
    82 // --------------------------------------------------------------------------
       
    83 // CPbk2MemorySelectionSettingItem::EditItemL
       
    84 // --------------------------------------------------------------------------
       
    85 //
       
    86 TBool CPbk2MemorySelectionSettingItem::EditItemL()
       
    87     {
       
    88     CPbk2MemorySelectionSettingPage* dlg =
       
    89         new ( ELeave ) CPbk2MemorySelectionSettingPage
       
    90             ( SettingPageResourceId(), &iSelectionItemList );
       
    91     dlg->SetSettingPageObserver( this );
       
    92     return dlg->ExecuteLD();
       
    93     }
       
    94 
       
    95 // --------------------------------------------------------------------------
       
    96 // CPbk2MemorySelectionSettingItem::RestoreStateL
       
    97 // --------------------------------------------------------------------------
       
    98 //
       
    99 void CPbk2MemorySelectionSettingItem::RestoreStateL()
       
   100     {
       
   101     UpdateSettingTextL();
       
   102     UpdateListBoxTextL();
       
   103     }
       
   104 
       
   105 // --------------------------------------------------------------------------
       
   106 // CPbk2MemorySelectionSettingItem::CompleteConstructionL
       
   107 // --------------------------------------------------------------------------
       
   108 //
       
   109 void CPbk2MemorySelectionSettingItem::CompleteConstructionL()
       
   110     {
       
   111     iSettingText = HBufC::NewL( KBufferSize );
       
   112     iSeveralMemories = StringLoader::LoadL
       
   113         ( R_PHONEBOOK2_SETTINGS_SEVERAL_MEMORIES );
       
   114     }
       
   115 
       
   116 // --------------------------------------------------------------------------
       
   117 // CPbk2MemorySelectionSettingItem::EditItemL
       
   118 // --------------------------------------------------------------------------
       
   119 //
       
   120 void CPbk2MemorySelectionSettingItem::EditItemL( TBool /*aCalledFromMenu*/ )
       
   121     {
       
   122     __ASSERT_DEBUG( ETrue, Panic(EPanicStoreNotSupported) );
       
   123     }
       
   124 
       
   125 // --------------------------------------------------------------------------
       
   126 // CPbk2MemorySelectionSettingItem::HandleSettingPageEventL
       
   127 // --------------------------------------------------------------------------
       
   128 //
       
   129 void CPbk2MemorySelectionSettingItem::HandleSettingPageEventL
       
   130         ( CAknSettingPage* aSettingPage, TAknSettingPageEvent aEventType )
       
   131     {
       
   132     switch ( aEventType )
       
   133         {
       
   134         case EEventSettingChanged:
       
   135         case EEventSettingCancelled:
       
   136             {
       
   137             break;
       
   138             }
       
   139         case EEventSettingOked:
       
   140             {
       
   141             UpdateSettingTextL();
       
   142             break;
       
   143             }
       
   144         }
       
   145     CAknSettingItem::HandleSettingPageEventL( aSettingPage, aEventType );
       
   146     }
       
   147 
       
   148 // --------------------------------------------------------------------------
       
   149 // CPbk2MemorySelectionSettingItem::StoreL
       
   150 // --------------------------------------------------------------------------
       
   151 //
       
   152 void CPbk2MemorySelectionSettingItem::StoreL()
       
   153     {
       
   154     CVPbkContactStoreUriArray* currentConfig =
       
   155          Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   156             StoreConfiguration().CurrentConfigurationL();
       
   157     CleanupStack::PushL( currentConfig );
       
   158 
       
   159     const TInt count = iSelectionItemList.Count();
       
   160     for ( TInt i = 0; i < count; ++i )
       
   161         {
       
   162         __ASSERT_DEBUG( iSupportedStores.Count() > i, Panic( EPanicIndexOOB ) );
       
   163         if ( iSelectionItemList.At( i )->SelectionStatus() &&
       
   164              !currentConfig->IsIncluded( ( iSupportedStores)[i] ) )
       
   165             {
       
   166             Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   167                 StoreConfiguration().
       
   168                     AddContactStoreURIL( ( iSupportedStores )[i] );
       
   169             }
       
   170         else if( !iSelectionItemList.At( i )->SelectionStatus() &&
       
   171                 currentConfig->IsIncluded( ( iSupportedStores )[i] ) )
       
   172             {
       
   173             Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   174                 StoreConfiguration().
       
   175                     RemoveContactStoreURIL( ( iSupportedStores )[i] );
       
   176             }
       
   177         }
       
   178 
       
   179     CleanupStack::PopAndDestroy( currentConfig );
       
   180     }
       
   181 
       
   182 // --------------------------------------------------------------------------
       
   183 // CPbk2MemorySelectionSettingItem::LoadL
       
   184 // --------------------------------------------------------------------------
       
   185 //
       
   186 void CPbk2MemorySelectionSettingItem::LoadL()
       
   187     {
       
   188     CVPbkContactStoreUriArray* currentConfig =
       
   189         Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   190             StoreConfiguration().CurrentConfigurationL();
       
   191 
       
   192     const TInt count = iSelectionItemList.Count();
       
   193     for ( TInt i = 0; i < count; ++i )
       
   194         {
       
   195         __ASSERT_DEBUG( iSupportedStores.Count() > i, Panic ( EPanicIndexOOB ) );
       
   196         TBool isSelected = currentConfig->IsIncluded
       
   197             ( ( iSupportedStores )[i] );
       
   198         iSelectionItemList.At(i)->SetSelectionStatus( isSelected );
       
   199         }
       
   200     delete currentConfig;
       
   201     UpdateSettingTextL();
       
   202     }
       
   203 
       
   204 // --------------------------------------------------------------------------
       
   205 // CPbk2MemorySelectionSettingItem::SettingTextL
       
   206 // --------------------------------------------------------------------------
       
   207 //
       
   208 const TDesC& CPbk2MemorySelectionSettingItem::SettingTextL()
       
   209     {
       
   210     return *iSettingText;
       
   211     }
       
   212 
       
   213 // --------------------------------------------------------------------------
       
   214 // CPbk2MemorySelectionSettingItem::UpdateSettingTextL
       
   215 // --------------------------------------------------------------------------
       
   216 //
       
   217 void CPbk2MemorySelectionSettingItem::UpdateSettingTextL()
       
   218     {
       
   219     TPtr ptr = iSettingText->Des();
       
   220     ptr.Zero();
       
   221     const TInt count( iSelectionItemList.Count() );
       
   222     TBool onlyOneSelected( ETrue );
       
   223 
       
   224     //loop selection item list and check selected ones
       
   225     for ( TInt i( 0 ); i < count; ++i )
       
   226         {
       
   227         if ( iSelectionItemList.At( i )->SelectionStatus() )
       
   228             {
       
   229             if ( onlyOneSelected )
       
   230                 {
       
   231                 ptr.Append( iSelectionItemList.At( i )->ItemText() );
       
   232                 onlyOneSelected = EFalse;
       
   233                 }
       
   234             else
       
   235                 {
       
   236                 //More than one selected
       
   237                 ptr.Zero();
       
   238                 ptr.Append( *iSeveralMemories );
       
   239                 break;
       
   240                 }
       
   241             }
       
   242         }
       
   243     }
       
   244 
       
   245 // End of File