|
1 /* |
|
2 * Copyright (c) 2006-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: A base class for store list implementations |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <CVPbkContactStoreList.h> |
|
20 |
|
21 #include <CVPbkContactStoreUriArray.h> |
|
22 #include <MVPbkContactStore.h> |
|
23 #include <MVPbkContactStoreListObserver.h> |
|
24 #include <MVPbkContactStoreProperties.h> |
|
25 #include <TVPbkContactStoreUriPtr.h> |
|
26 #include <VPbkError.h> |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // CVPbkContactStoreList::CVPbkContactStoreList |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CVPbkContactStoreList::CVPbkContactStoreList() |
|
35 { |
|
36 } |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // CVPbkContactStoreList::NewL |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 EXPORT_C CVPbkContactStoreList* CVPbkContactStoreList::NewL() |
|
43 { |
|
44 CVPbkContactStoreList* self = new( ELeave ) CVPbkContactStoreList; |
|
45 return self; |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // CVPbkContactStoreList::~CVPbkContactStoreList |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 CVPbkContactStoreList::~CVPbkContactStoreList() |
|
53 { |
|
54 iStoresToOpen.Close(); |
|
55 iStores.ResetAndDestroy(); |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // CVPbkContactStoreList::AppendL |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 EXPORT_C void CVPbkContactStoreList::AppendL( MVPbkContactStore* aStore ) |
|
63 { |
|
64 iStores.AppendL( aStore ); |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // From class MVPbkContactStoreList |
|
69 // CVPbkContactStoreList::Count |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 TInt CVPbkContactStoreList::Count() const |
|
73 { |
|
74 return iStores.Count(); |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // From class MVPbkContactStoreList |
|
79 // CVPbkContactStoreList::Count |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 MVPbkContactStore& CVPbkContactStoreList::At( TInt aIndex ) const |
|
83 { |
|
84 __ASSERT_DEBUG( aIndex < Count(), |
|
85 VPbkError::Panic( VPbkError::EInvalidStoreIndex ) ); |
|
86 return *iStores[aIndex]; |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // From class MVPbkContactStoreList |
|
91 // CVPbkContactStoreList::Find |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 MVPbkContactStore* CVPbkContactStoreList::Find( |
|
95 const TVPbkContactStoreUriPtr& aUri ) const |
|
96 { |
|
97 MVPbkContactStore* result = NULL; |
|
98 |
|
99 const TInt count = iStores.Count(); |
|
100 for (TInt i = 0; i < count; ++i) |
|
101 { |
|
102 if ( iStores[i]->StoreProperties().Uri().Compare(aUri, |
|
103 TVPbkContactStoreUriPtr::EContactStoreUriAllComponents ) == 0 ) |
|
104 { |
|
105 result = iStores[i]; |
|
106 break; |
|
107 } |
|
108 } |
|
109 return result; |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // From class MVPbkContactStoreList |
|
114 // CVPbkContactStoreList::OpenAllL |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 void CVPbkContactStoreList::OpenAllL( |
|
118 MVPbkContactStoreListObserver& aObserver ) |
|
119 { |
|
120 if (iObserver) |
|
121 { |
|
122 // Leave as documented in MVPbkContactStoreList |
|
123 User::Leave( KErrInUse ); |
|
124 } |
|
125 |
|
126 iObserver = &aObserver; |
|
127 iStoresToOpen.Reset(); |
|
128 |
|
129 const TInt count = Count(); |
|
130 for (TInt i = 0; i < count; ++i) |
|
131 { |
|
132 MVPbkContactStore& store = At( i ); |
|
133 store.OpenL( aObserver ); |
|
134 store.OpenL( *this ); |
|
135 // Append stores to list that is used the monitor signalling |
|
136 iStoresToOpen.AppendL( &store ); |
|
137 } |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // From class MVPbkContactStoreList |
|
142 // CVPbkContactStoreList::CloseAll |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 void CVPbkContactStoreList::CloseAll( |
|
146 MVPbkContactStoreListObserver& aObserver ) |
|
147 { |
|
148 const TInt count = Count(); |
|
149 if ( iObserver == &aObserver ) |
|
150 { |
|
151 // If observer is the same that called OpenAllL then stop operning |
|
152 for (TInt i = 0; i < count; ++i) |
|
153 { |
|
154 MVPbkContactStore& store = At( i ); |
|
155 At(i).Close( *this ); |
|
156 At(i).Close( aObserver ); |
|
157 } |
|
158 iObserver = NULL; |
|
159 } |
|
160 else |
|
161 { |
|
162 // If observer is not the same that called OpenAllL then |
|
163 // close stores for that observer only. The observer that |
|
164 // called OpenAllL is still waiting the OpenComplete |
|
165 for (TInt i = 0; i < count; ++i) |
|
166 { |
|
167 MVPbkContactStore& store = At( i ); |
|
168 At(i).Close( aObserver ); |
|
169 } |
|
170 } |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // From class MVPbkContactStoreList |
|
175 // CVPbkContactStoreList::StoreReady |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 void CVPbkContactStoreList::StoreReady( |
|
179 MVPbkContactStore& aContactStore ) |
|
180 { |
|
181 TInt index = iStoresToOpen.Find( &aContactStore ); |
|
182 if ( index != KErrNotFound ) |
|
183 { |
|
184 iStoresToOpen.Remove( index ); |
|
185 } |
|
186 |
|
187 SignalOpenComplete(); |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // From class MVPbkContactStoreList |
|
192 // CVPbkContactStoreList::StoreUnavailable |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 void CVPbkContactStoreList::StoreUnavailable( |
|
196 MVPbkContactStore& aContactStore, TInt /*aReason*/ ) |
|
197 { |
|
198 TInt index = iStoresToOpen.Find( &aContactStore ); |
|
199 if ( index != KErrNotFound ) |
|
200 { |
|
201 iStoresToOpen.Remove( index ); |
|
202 } |
|
203 |
|
204 SignalOpenComplete(); |
|
205 } |
|
206 |
|
207 // --------------------------------------------------------------------------- |
|
208 // From class MVPbkContactStoreList |
|
209 // CVPbkContactStoreList::HandleStoreEventL |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 void CVPbkContactStoreList::HandleStoreEventL( |
|
213 MVPbkContactStore& /*aContactStore*/, |
|
214 TVPbkContactStoreEvent /*aStoreEvent*/ ) |
|
215 { |
|
216 // List is not interested in store events |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // CVPbkContactStoreList::SignalOpenComplete |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 void CVPbkContactStoreList::SignalOpenComplete() |
|
224 { |
|
225 if ( iObserver && iStoresToOpen.Count() == 0 ) |
|
226 { |
|
227 MVPbkContactStoreListObserver* observer = iObserver; |
|
228 iObserver = NULL; |
|
229 observer->OpenComplete(); |
|
230 } |
|
231 } |
|
232 |
|
233 //End of file |