|
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::SupportedStores |
|
139 // -------------------------------------------------------------------------- |
|
140 // |
|
141 CVPbkContactStoreUriArray& CPbk2SettingsListState::SupportedStores() |
|
142 { |
|
143 __ASSERT_DEBUG( iSupportedStores, Panic(EPanicContactStoreUriArrayNULL)); |
|
144 return *iSupportedStores; |
|
145 } |
|
146 |
|
147 // -------------------------------------------------------------------------- |
|
148 // CPbk2SettingsListState::StoreItemStateL |
|
149 // -------------------------------------------------------------------------- |
|
150 // |
|
151 void CPbk2SettingsListState::StoreItemStateL() |
|
152 { |
|
153 __ASSERT_DEBUG( iItemListState, Panic(EPanicItemListStateNULL) ); |
|
154 |
|
155 // Reset old list state |
|
156 iItemListState->ResetAndDestroy(); |
|
157 |
|
158 const TInt count( iSelectionItemList->Count() ); |
|
159 for ( TInt i(0); i < count; ++i ) |
|
160 { |
|
161 TPtrC ptr = iSelectionItemList->At(i)->ItemText(); |
|
162 CSelectableItem* item = new (ELeave ) CSelectableItem |
|
163 ( ptr, iSelectionItemList->At(i)->SelectionStatus() ); |
|
164 CleanupStack::PushL(item); |
|
165 item->ConstructL(); |
|
166 iItemListState->AppendL(item); |
|
167 CleanupStack::Pop(item); |
|
168 } |
|
169 } |
|
170 |
|
171 // -------------------------------------------------------------------------- |
|
172 // CPbk2SettingsListState::RestoreItemStateL |
|
173 // -------------------------------------------------------------------------- |
|
174 // |
|
175 void CPbk2SettingsListState::RestoreItemStateL() |
|
176 { |
|
177 iSelectionItemList->ResetAndDestroy(); |
|
178 const TInt count( iItemListState->Count() ); |
|
179 for ( TInt i(0); i < count; ++i ) |
|
180 { |
|
181 TPtrC ptr = iItemListState->At(i)->ItemText(); |
|
182 CSelectableItem* item = new ( ELeave ) CSelectableItem |
|
183 ( ptr, iItemListState->At(i)->SelectionStatus() ); |
|
184 CleanupStack::PushL(item); |
|
185 item->ConstructL(); |
|
186 iSelectionItemList->AppendL(item); |
|
187 CleanupStack::Pop(item); |
|
188 } |
|
189 } |
|
190 |
|
191 // -------------------------------------------------------------------------- |
|
192 // CPbk2SettingsListState::IsChanged |
|
193 // -------------------------------------------------------------------------- |
|
194 // |
|
195 TBool CPbk2SettingsListState::IsChanged() |
|
196 { |
|
197 TBool result( EFalse ); |
|
198 const TInt count( iItemListState->Count() ); |
|
199 |
|
200 __ASSERT_DEBUG( iSelectionItemList->Count() >= count, |
|
201 Panic( EPanic_IsChanged_OOB ) ); |
|
202 |
|
203 for ( TInt i(0); i < count; ++i ) |
|
204 { |
|
205 if ( iItemListState->At(i)->SelectionStatus() != |
|
206 iSelectionItemList->At(i)->SelectionStatus() ) |
|
207 { |
|
208 result = ETrue; |
|
209 break; |
|
210 } |
|
211 } |
|
212 |
|
213 return result; |
|
214 } |
|
215 |
|
216 // -------------------------------------------------------------------------- |
|
217 // CPbk2SettingsListState::PopulateSelectionItemListL |
|
218 // -------------------------------------------------------------------------- |
|
219 // |
|
220 void CPbk2SettingsListState::PopulateSelectionItemListL() |
|
221 { |
|
222 const TInt count = iSupportedStores->Count(); |
|
223 for (TInt i = 0; i < count; ++i) |
|
224 { |
|
225 const CPbk2StoreProperty* storeProperty = |
|
226 Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
227 StoreProperties().FindProperty |
|
228 ( ( *iSupportedStores )[i] ); |
|
229 TPtrC storeName; |
|
230 TBool append = EFalse; |
|
231 if (storeProperty) |
|
232 { |
|
233 TUint32 flags = storeProperty->Flags(); |
|
234 if ( flags &= KPbk2ShownInMemorySelectionList ) |
|
235 { |
|
236 append = ETrue; |
|
237 storeName.Set( storeProperty->StoreName() ); |
|
238 } |
|
239 } |
|
240 else |
|
241 { |
|
242 storeName.Set( (*iSupportedStores)[i].UriDes() ); |
|
243 } |
|
244 |
|
245 if ( append ) |
|
246 { |
|
247 CSelectableItem* item = new ( ELeave ) CSelectableItem |
|
248 ( storeName, EFalse ); |
|
249 CleanupStack::PushL(item); |
|
250 item->ConstructL(); |
|
251 iSelectionItemList->AppendL(item); |
|
252 CleanupStack::Pop(item); |
|
253 } |
|
254 } |
|
255 } |
|
256 |
|
257 // End of File |