phonebookui/Phonebook2/UIControls/src/CPbk2SettingsListState.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
child 85 38bb213f60ba
equal deleted inserted replaced
62:5b6f26637ad3 63: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 settings list state.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPbk2SettingsListState.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include <CPbk2StoreConfiguration.h>
       
    24 #include <CPbk2StorePropertyArray.h>
       
    25 #include <CPbk2StoreProperty.h>
       
    26 #include <Pbk2StoreProperty.hrh>
       
    27 #include <MPbk2ApplicationServices.h>
       
    28 #include <MPbk2AppUi.h>
       
    29 
       
    30 // Virtual Phonebook
       
    31 #include <CVPbkContactStoreUriArray.h>
       
    32 #include <TVPbkContactStoreUriPtr.h>
       
    33 #include <CVPbkContactManager.h>
       
    34 #include <MVPbkContactStore.h>
       
    35 #include <MVPbkContactStoreList.h>
       
    36 #include <MVPbkContactStoreProperties.h>
       
    37 
       
    38 // Ssytem includes
       
    39 #include <badesca.h>
       
    40 #include <aknsettingitemlist.h>
       
    41 #include <akncheckboxsettingpage.h>
       
    42 
       
    43 
       
    44 /// Unnamed namespace for local definitions
       
    45 namespace {
       
    46 
       
    47 const TInt KSelectionListGranularity = 4;
       
    48 
       
    49 #ifdef _DEBUG
       
    50 enum TPanicCode
       
    51     {
       
    52     EPanicSelectionItemListNULL = 1,
       
    53     EPanicContactStoreUriArrayNULL,
       
    54     EPanicItemListStateNULL,
       
    55     EPanic_IsChanged_OOB
       
    56     };
       
    57 
       
    58 void Panic(TPanicCode aReason)
       
    59     {
       
    60     _LIT(KPanicText, "CPbk2SettingsListState");
       
    61     User::Panic(KPanicText, aReason);
       
    62     }
       
    63 
       
    64 #endif // _DEBUG
       
    65 
       
    66 } /// namespace
       
    67 
       
    68 
       
    69 // --------------------------------------------------------------------------
       
    70 // CPbk2SettingsListState::CPbk2SettingsListState
       
    71 // --------------------------------------------------------------------------
       
    72 //
       
    73 CPbk2SettingsListState::CPbk2SettingsListState()
       
    74     {
       
    75     }
       
    76 
       
    77 // --------------------------------------------------------------------------
       
    78 // CPbk2SettingsListState::~CPbk2SettingsListState
       
    79 // --------------------------------------------------------------------------
       
    80 //
       
    81 CPbk2SettingsListState::~CPbk2SettingsListState()
       
    82     {
       
    83     if (iSelectionItemList)
       
    84         {
       
    85         iSelectionItemList->ResetAndDestroy();
       
    86         delete iSelectionItemList;
       
    87         }
       
    88 
       
    89     if ( iItemListState )
       
    90         {
       
    91         iItemListState->ResetAndDestroy();
       
    92         delete iItemListState;
       
    93         }
       
    94 
       
    95     delete iSupportedStores;
       
    96     }
       
    97 
       
    98 // --------------------------------------------------------------------------
       
    99 // CPbk2SettingsListState::NewL
       
   100 // --------------------------------------------------------------------------
       
   101 //
       
   102 CPbk2SettingsListState* CPbk2SettingsListState::NewL()
       
   103     {
       
   104     CPbk2SettingsListState* self = new ( ELeave ) CPbk2SettingsListState;
       
   105     CleanupStack::PushL( self );
       
   106     self->ConstructL();
       
   107     CleanupStack::Pop( self );
       
   108     return self;
       
   109     }
       
   110 
       
   111 // --------------------------------------------------------------------------
       
   112 // CPbk2SettingsListState::ConstructL
       
   113 // --------------------------------------------------------------------------
       
   114 //
       
   115 void CPbk2SettingsListState::ConstructL()
       
   116     {
       
   117     iSelectionItemList =
       
   118         new ( ELeave ) CSelectionItemList( KSelectionListGranularity );
       
   119     iItemListState =
       
   120         new ( ELeave ) CSelectionItemList( KSelectionListGranularity );
       
   121     iSupportedStores =
       
   122         Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   123             StoreConfiguration().SupportedStoreConfigurationL();
       
   124     PopulateSelectionItemListL();
       
   125     }
       
   126 
       
   127 // --------------------------------------------------------------------------
       
   128 // CPbk2SettingsListState::SelectionItemList
       
   129 // --------------------------------------------------------------------------
       
   130 //
       
   131 CSelectionItemList& CPbk2SettingsListState::SelectionItemList()
       
   132     {
       
   133     __ASSERT_DEBUG( iSelectionItemList, Panic(EPanicSelectionItemListNULL));
       
   134     return *iSelectionItemList;
       
   135     }
       
   136 
       
   137 // --------------------------------------------------------------------------
       
   138 // CPbk2SettingsListState::ItemListState
       
   139 // --------------------------------------------------------------------------
       
   140 //
       
   141 CSelectionItemList& CPbk2SettingsListState::ItemListState()
       
   142     {
       
   143     __ASSERT_DEBUG( iItemListState, Panic(EPanicItemListStateNULL));
       
   144     return *iItemListState;
       
   145     }
       
   146 
       
   147 // --------------------------------------------------------------------------
       
   148 // CPbk2SettingsListState::SupportedStores
       
   149 // --------------------------------------------------------------------------
       
   150 //
       
   151 CVPbkContactStoreUriArray& CPbk2SettingsListState::SupportedStores()
       
   152     {
       
   153     __ASSERT_DEBUG( iSupportedStores, Panic(EPanicContactStoreUriArrayNULL));
       
   154     return *iSupportedStores;
       
   155     }
       
   156 
       
   157 // --------------------------------------------------------------------------
       
   158 // CPbk2SettingsListState::StoreItemStateL
       
   159 // --------------------------------------------------------------------------
       
   160 //
       
   161 void CPbk2SettingsListState::StoreItemStateL()
       
   162     {
       
   163     __ASSERT_DEBUG( iItemListState, Panic(EPanicItemListStateNULL) );
       
   164 
       
   165     // Reset old list state
       
   166     iItemListState->ResetAndDestroy();
       
   167 
       
   168     const TInt count( iSelectionItemList->Count() );
       
   169     for ( TInt i(0); i < count; ++i )
       
   170         {
       
   171         TPtrC ptr = iSelectionItemList->At(i)->ItemText();
       
   172         CSelectableItem* item = new (ELeave ) CSelectableItem
       
   173             ( ptr, iSelectionItemList->At(i)->SelectionStatus() );
       
   174         CleanupStack::PushL(item);
       
   175         item->ConstructL();
       
   176         iItemListState->AppendL(item);
       
   177         CleanupStack::Pop(item);
       
   178         }
       
   179     }
       
   180 
       
   181 // --------------------------------------------------------------------------
       
   182 // CPbk2SettingsListState::RestoreItemStateL
       
   183 // --------------------------------------------------------------------------
       
   184 //
       
   185 void CPbk2SettingsListState::RestoreItemStateL()
       
   186     {
       
   187     iSelectionItemList->ResetAndDestroy();
       
   188     const TInt count( iItemListState->Count() );
       
   189     for ( TInt i(0); i < count; ++i )
       
   190         {
       
   191         TPtrC ptr = iItemListState->At(i)->ItemText();
       
   192         CSelectableItem* item = new ( ELeave ) CSelectableItem
       
   193             ( ptr, iItemListState->At(i)->SelectionStatus() );
       
   194         CleanupStack::PushL(item);
       
   195         item->ConstructL();
       
   196         iSelectionItemList->AppendL(item);
       
   197         CleanupStack::Pop(item);
       
   198         }
       
   199     }
       
   200 
       
   201 // --------------------------------------------------------------------------
       
   202 // CPbk2SettingsListState::IsChanged
       
   203 // --------------------------------------------------------------------------
       
   204 //
       
   205 TBool CPbk2SettingsListState::IsChanged()
       
   206     {
       
   207     TBool result( EFalse );
       
   208     const TInt count( iItemListState->Count() );
       
   209 
       
   210     __ASSERT_DEBUG( iSelectionItemList->Count() >= count,
       
   211         Panic( EPanic_IsChanged_OOB ) );
       
   212 
       
   213     for ( TInt i(0); i < count; ++i )
       
   214         {
       
   215         if ( iItemListState->At(i)->SelectionStatus() !=
       
   216              iSelectionItemList->At(i)->SelectionStatus() )
       
   217             {
       
   218             result = ETrue;
       
   219             break;
       
   220             }
       
   221         }
       
   222 
       
   223     return result;
       
   224     }
       
   225 
       
   226 // --------------------------------------------------------------------------
       
   227 // CPbk2SettingsListState::PopulateSelectionItemListL
       
   228 // --------------------------------------------------------------------------
       
   229 //
       
   230 void CPbk2SettingsListState::PopulateSelectionItemListL()
       
   231     {
       
   232     const TInt count = iSupportedStores->Count();
       
   233     for (TInt i = 0; i < count; ++i)
       
   234         {
       
   235         const CPbk2StoreProperty* storeProperty =
       
   236             Phonebook2::Pbk2AppUi()->ApplicationServices().
       
   237                 StoreProperties().FindProperty
       
   238                     ( ( *iSupportedStores )[i] );
       
   239         TPtrC storeName;
       
   240         TBool append = EFalse;
       
   241         if (storeProperty)
       
   242             {
       
   243             TUint32 flags = storeProperty->Flags();
       
   244             if ( flags &= KPbk2ShownInMemorySelectionList )
       
   245                 {
       
   246                 append = ETrue;
       
   247                 storeName.Set( storeProperty->StoreName() );
       
   248                 }
       
   249             }
       
   250         else
       
   251             {
       
   252             storeName.Set( (*iSupportedStores)[i].UriDes() );
       
   253             }
       
   254 
       
   255         if ( append )
       
   256             {
       
   257             CSelectableItem* item = new ( ELeave ) CSelectableItem
       
   258                 ( storeName, EFalse );
       
   259             CleanupStack::PushL(item);
       
   260             item->ConstructL();
       
   261             iSelectionItemList->AppendL(item);
       
   262             CleanupStack::Pop(item);
       
   263             }
       
   264         }
       
   265     }
       
   266 
       
   267 //  End of File