|
1 /* |
|
2 * Copyright (c) 2006 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: Contact store Uris |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <CVPbkContactStoreUriArray.h> |
|
19 #include <VPbkContactStoreUris.h> |
|
20 #include <TVPbkContactStoreUriPtr.h> |
|
21 #include <centralrepository.h> |
|
22 #include <talogger.h> |
|
23 |
|
24 #include "telinternalcrkeys.h" |
|
25 #include "cphcntcontactstoreuris.h" |
|
26 #include "mphcntcontactstoreeventobserver.h" |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // Static constructor |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CPhCntContactStoreUris* CPhCntContactStoreUris::NewL() |
|
36 { |
|
37 TEFLOGSTRING( KTAOBJECT, "CNT CPhCntContactStoreUris::NewL" ); |
|
38 CPhCntContactStoreUris* self = new( ELeave ) CPhCntContactStoreUris; |
|
39 CleanupStack::PushL( self ); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop( self ); |
|
42 return self; |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // Destructor |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CPhCntContactStoreUris::~CPhCntContactStoreUris() |
|
50 { |
|
51 TEFLOGSTRING( KTAOBJECT, "CNT CPhCntContactStoreUris::~CPhCntContactStoreUris" ); |
|
52 delete iContactStoreUriArray; |
|
53 delete iAdditionalContactStoreUriArray; |
|
54 iContactStoreStates.Close(); |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // Contact store uris |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CVPbkContactStoreUriArray& CPhCntContactStoreUris::ContactStores() const |
|
62 { |
|
63 return *iContactStoreUriArray; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // Currently active contact stores. |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 CVPbkContactStoreUriArray* CPhCntContactStoreUris::ActiveContactStoresL() const |
|
71 { |
|
72 TEFLOGSTRING( KTAOBJECT, "CNT CPhCntContactStoreUris::ActiveContactStoresL" ); |
|
73 CVPbkContactStoreUriArray* array = CVPbkContactStoreUriArray::NewLC(); |
|
74 const TInt count( iContactStoreStates.Count() ); |
|
75 for( TInt i = 0; i < count; i++ ) |
|
76 { |
|
77 const TPhCntContactStoreState& storeState = iContactStoreStates[i]; |
|
78 if( storeState.IsAvailable() ) |
|
79 { |
|
80 TEFLOGSTRING2( KTAOBJECT, |
|
81 "CNT CPhCntContactStoreUris::ActiveContactStoresL - Append store: %S", |
|
82 &storeState.ContactStoreUri().UriDes() ); |
|
83 array->AppendL( storeState.ContactStoreUri() ); |
|
84 } |
|
85 } |
|
86 CleanupStack::Pop( array ); |
|
87 return array; |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // Updates store availability |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 void CPhCntContactStoreUris::StoreReady( |
|
95 TVPbkContactStoreUriPtr& aContactStoreUri ) |
|
96 { |
|
97 TEFLOGSTRING2( KTAOBJECT, "CNT CPhCntContactStoreUris::StoreReady = %S", |
|
98 &aContactStoreUri.UriDes() ); |
|
99 SetContactStoreAvailability( aContactStoreUri, ETrue ); |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // Updates store availability |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 void CPhCntContactStoreUris::StoreUnavailable( |
|
107 TVPbkContactStoreUriPtr& aContactStoreUri ) |
|
108 { |
|
109 TEFLOGSTRING2( KTAOBJECT, "CNT CPhCntContactStoreUris::StoreUnavailable = %S", |
|
110 &aContactStoreUri.UriDes() ); |
|
111 SetContactStoreAvailability( aContactStoreUri, EFalse ); |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // Sets observer |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 void CPhCntContactStoreUris::SetObserver( |
|
119 MPhCntContactStoreEventObserver& aObserver ) |
|
120 { |
|
121 iObserver = &aObserver; |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // Constructor |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 CPhCntContactStoreUris::CPhCntContactStoreUris() |
|
129 { |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // Second phase constructor |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 void CPhCntContactStoreUris::ConstructL() |
|
137 { |
|
138 TEFLOGSTRING( KTAOBJECT, "CNT CPhCntContactStoreUris::ConstructL" ); |
|
139 iAdditionalContactStoreUriArray = CVPbkContactStoreUriArray::NewL(); |
|
140 |
|
141 // Read additional, product configured contact stores. |
|
142 HBufC* productSpecificList = HBufC::NewLC( |
|
143 NCentralRepositoryConstants::KMaxUnicodeStringLength ); |
|
144 TPtr productSpecificListPtr( productSpecificList->Des() ); |
|
145 ReadAdditionalContactStoreL( &productSpecificListPtr ); |
|
146 |
|
147 // Append additional stores to contact store array |
|
148 TInt count( iAdditionalContactStoreUriArray->Count() ); |
|
149 for( TInt i = 0; i < count; i++ ) |
|
150 { |
|
151 iContactStoreStates.AppendL( (*iAdditionalContactStoreUriArray)[i] ); |
|
152 } |
|
153 |
|
154 iContactStoreStates.AppendL( |
|
155 TVPbkContactStoreUriPtr( |
|
156 VPbkContactStoreUris::DefaultCntDbUri() ) ); |
|
157 iContactStoreStates.AppendL( |
|
158 TVPbkContactStoreUriPtr( |
|
159 VPbkContactStoreUris::SimGlobalOwnNumberUri() ) ); |
|
160 iContactStoreStates.AppendL( |
|
161 TVPbkContactStoreUriPtr( |
|
162 VPbkContactStoreUris::SimGlobalAdnUri() ) ); |
|
163 iContactStoreStates.AppendL( |
|
164 TVPbkContactStoreUriPtr( |
|
165 VPbkContactStoreUris::SimGlobalFdnUri() ) ); |
|
166 iContactStoreStates.AppendL( |
|
167 TVPbkContactStoreUriPtr( |
|
168 VPbkContactStoreUris::SimGlobalSdnUri() ) ); |
|
169 |
|
170 const TInt count_2( iContactStoreStates.Count() ); |
|
171 iContactStoreUriArray = CVPbkContactStoreUriArray::NewL(); |
|
172 for( TInt i = 0; i < count_2; i++ ) |
|
173 { |
|
174 TEFLOGSTRING3( KTAOBJECT, |
|
175 "CNT CPhCntContactStoreUris::ConstructL - Append store = %S, Available: %d", |
|
176 &iContactStoreStates[i].ContactStoreUri().UriDes(), |
|
177 iContactStoreStates[i].IsAvailable() ); |
|
178 iContactStoreUriArray->AppendL( iContactStoreStates[i].ContactStoreUri() ); |
|
179 } |
|
180 CleanupStack::PopAndDestroy( productSpecificList ); |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // Sets contact stores availability |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 void CPhCntContactStoreUris::SetContactStoreAvailability( |
|
188 TVPbkContactStoreUriPtr& aStoreUri, |
|
189 TBool aIsAvailable ) |
|
190 { |
|
191 TEFLOGSTRING( KTAOBJECT, "CPhCntContactStoreUris::SetContactStoreAvailability" ); |
|
192 const TInt count( iContactStoreStates.Count() ); |
|
193 for( TInt i = 0; i < count; i++ ) |
|
194 { |
|
195 TPhCntContactStoreState& storeState = iContactStoreStates[i]; |
|
196 if( storeState.ContactStoreUri().Compare( |
|
197 aStoreUri, |
|
198 TVPbkContactStoreUriPtr::EContactStoreUriAllComponents ) |
|
199 == KErrNone ) |
|
200 { |
|
201 TEFLOGSTRING2( KTAOBJECT, "SetAvailability: %d", aIsAvailable ); |
|
202 storeState.SetAvailability( aIsAvailable ); |
|
203 } |
|
204 } |
|
205 if( iObserver ) |
|
206 { |
|
207 iObserver->ContactStoreAvailabilityChanged(); |
|
208 } |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // Read list of additional contact stores from cenrep |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 void CPhCntContactStoreUris::ReadAdditionalContactStoreL( TDes* aProductSpecificList ) |
|
216 { |
|
217 // Read The product specific VPBK stores from cenrep |
|
218 CRepository* repository = CRepository::NewLC( KCRUidTelVariation ); |
|
219 |
|
220 TInt err( KErrNone ); |
|
221 err = repository->Get( KTelAdditionalStores, *aProductSpecificList ); |
|
222 |
|
223 if ( err == KErrNone && aProductSpecificList->Length() ) |
|
224 { |
|
225 ParseStoresL( *aProductSpecificList ); |
|
226 } // if ( err == KErrNone && product... |
|
227 CleanupStack::PopAndDestroy( repository ); |
|
228 } |
|
229 |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // Adds contact store. |
|
233 // --------------------------------------------------------------------------- |
|
234 // |
|
235 void CPhCntContactStoreUris::AddContactStoreL( |
|
236 const TVPbkContactStoreUriPtr& aContactStoreUri ) |
|
237 { |
|
238 TPhCntContactStoreState candidate |
|
239 = TPhCntContactStoreState( aContactStoreUri ); |
|
240 |
|
241 TInt index = iContactStoreStates.Find( candidate, MatchUris ); |
|
242 if ( KErrNotFound == index ) |
|
243 { |
|
244 iContactStoreStates.AppendL( candidate ); |
|
245 } |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // Removes contact store. |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 void CPhCntContactStoreUris::RemoveContactStore( |
|
253 const TVPbkContactStoreUriPtr& aContactStoreUri ) |
|
254 { |
|
255 TPhCntContactStoreState candidate |
|
256 = TPhCntContactStoreState( aContactStoreUri ); |
|
257 |
|
258 TInt index = iContactStoreStates.Find( candidate, MatchUris ); |
|
259 if ( KErrNotFound != index ) |
|
260 { |
|
261 iContactStoreStates.Remove( index ); |
|
262 } |
|
263 } |
|
264 |
|
265 // --------------------------------------------------------------------------- |
|
266 // Parses store names from comma separated list. |
|
267 // --------------------------------------------------------------------------- |
|
268 // |
|
269 void CPhCntContactStoreUris::ParseStoresL( const TDesC& aProductSpecificList ) |
|
270 { |
|
271 const TChar KStoreSeparatorComma = ','; |
|
272 TChar chr; |
|
273 TLex storeToken ( aProductSpecificList ); |
|
274 HBufC* db; |
|
275 |
|
276 while ( !storeToken.Eos() ) |
|
277 { |
|
278 // Skip spaces |
|
279 // e.g. " store1,store2" |
|
280 storeToken.SkipSpaceAndMark(); |
|
281 |
|
282 // if several commas in row, skip them all. |
|
283 while ( storeToken.Peek() == KStoreSeparatorComma ) |
|
284 { |
|
285 // e.g. ",,store1,store2" |
|
286 storeToken.SkipAndMark(1); |
|
287 // Or ",[space],," |
|
288 storeToken.SkipSpaceAndMark(); |
|
289 } |
|
290 |
|
291 // Loop until ',' or eof to parse next store |
|
292 do |
|
293 { |
|
294 chr = storeToken.Get(); |
|
295 } |
|
296 while ( chr != KStoreSeparatorComma && !storeToken.Eos() ); |
|
297 |
|
298 if ( !storeToken.Eos() ) |
|
299 { |
|
300 // Reverse not to include comma. |
|
301 storeToken.UnGet(); |
|
302 } |
|
303 |
|
304 if ( storeToken.TokenLength() ) |
|
305 { |
|
306 // Append to parsed stores array, so that visibility of |
|
307 // all additional DB URIs is maintained. |
|
308 db = HBufC::NewLC( storeToken.TokenLength() ); |
|
309 db->Des().Copy( storeToken.MarkedToken() ); |
|
310 |
|
311 // Append to additional store array. |
|
312 iAdditionalContactStoreUriArray->AppendL( TVPbkContactStoreUriPtr( *db ) ); |
|
313 CleanupStack::PopAndDestroy( db ); |
|
314 //CleanupStack::Pop( db ); |
|
315 } |
|
316 |
|
317 } // while ( !storeToken.Eos() ).. |
|
318 } |
|
319 |
|
320 // --------------------------------------------------------------------------- |
|
321 // Additional Contact store uris |
|
322 // --------------------------------------------------------------------------- |
|
323 // |
|
324 const CVPbkContactStoreUriArray& CPhCntContactStoreUris::AdditionalContactStores() const |
|
325 { |
|
326 return *iAdditionalContactStoreUriArray; |
|
327 } |
|
328 |
|
329 // --------------------------------------------------------------------------- |
|
330 // Implements TIdentityRelation for class TPhCntContactStoreState. |
|
331 // --------------------------------------------------------------------------- |
|
332 // |
|
333 TBool CPhCntContactStoreUris::MatchUris( |
|
334 const TPhCntContactStoreState& aState1, |
|
335 const TPhCntContactStoreState& aState2 ) |
|
336 { |
|
337 TVPbkContactStoreUriPtr uri1( aState1.ContactStoreUri() ); |
|
338 TVPbkContactStoreUriPtr uri2( aState2.ContactStoreUri() ); |
|
339 |
|
340 return ( |
|
341 uri1.Compare( uri2, |
|
342 TVPbkContactStoreUriPtr::EContactStoreUriAllComponents ) |
|
343 == 0 ); |
|
344 } |
|
345 |
|
346 |