|
1 /* |
|
2 * Copyright (c) 2007-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: An array that manages shared views |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include "CSharedViewArray.h" |
|
21 |
|
22 #include <CVPbkSimContactView.h> |
|
23 |
|
24 // FORWARD DECLARATIONS |
|
25 |
|
26 namespace VPbkSimStoreImpl { |
|
27 |
|
28 // CLASS DECLARATION |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CSharedViewArray::CSharedViewArray |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CSharedViewArray::CSharedViewArray( |
|
37 TViewDestructionPolicy aDestructionPolicy ) |
|
38 : iDestructionPolicy( aDestructionPolicy ) |
|
39 { |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CSharedViewArray::NewL |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CSharedViewArray* CSharedViewArray::NewL( |
|
47 TViewDestructionPolicy aDestructionPolicy ) |
|
48 { |
|
49 return new (ELeave ) CSharedViewArray( aDestructionPolicy ); |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CSharedViewArray::~CSharedViewArray |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CSharedViewArray::~CSharedViewArray() |
|
57 { |
|
58 iSharedViews.ResetAndDestroy(); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CSharedViewArray::CreateNewHandleL |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CViewHandle* CSharedViewArray::CreateNewHandleL( |
|
66 const RVPbkSimFieldTypeArray& aSortOrder, |
|
67 TVPbkSimViewConstructionPolicy aConstructionPolicy, |
|
68 MVPbkSimCntStore& aParentStore, const TDesC& aViewName ) |
|
69 { |
|
70 CSharedViewOwner* viewOwner = FindOwner( aSortOrder, aConstructionPolicy, aViewName ); |
|
71 |
|
72 if ( !viewOwner ) |
|
73 { |
|
74 CVPbkSimContactView* sharedView = |
|
75 CVPbkSimContactView::NewLC( aSortOrder, aConstructionPolicy, |
|
76 aParentStore, aViewName, NULL ); |
|
77 viewOwner = new (ELeave ) CSharedViewOwner( *this, sharedView ); |
|
78 CleanupStack::Pop( sharedView ); |
|
79 CleanupStack::PushL( viewOwner ); |
|
80 iSharedViews.AppendL( viewOwner ); |
|
81 CleanupStack::Pop( viewOwner ); |
|
82 } |
|
83 |
|
84 return viewOwner->CreateNewHandleL(); |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CSharedViewArray::RemoveHandle |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 void CSharedViewArray::RemoveHandle( CViewHandle& aHandle ) |
|
92 { |
|
93 CSharedViewOwner* viewOwner = NULL; |
|
94 for ( TInt i=0; i<iSharedViews.Count()&&!viewOwner; i++ ) |
|
95 { |
|
96 if ( &iSharedViews[i]->View() == &aHandle.SharedView() ) |
|
97 { |
|
98 viewOwner = iSharedViews[i]; |
|
99 } |
|
100 } |
|
101 if ( viewOwner ) |
|
102 { |
|
103 viewOwner->RemoveHandle( aHandle ); |
|
104 if ( iDestructionPolicy == EDestroyViewIfNoHandles && |
|
105 !viewOwner->HasHandles() ) |
|
106 { |
|
107 TInt index = iSharedViews.Find( viewOwner ); |
|
108 delete iSharedViews[index]; |
|
109 iSharedViews.Remove( index ); |
|
110 } |
|
111 } |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CSharedViewArray::FindOwner |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 CSharedViewOwner* CSharedViewArray::FindOwner( |
|
119 const RVPbkSimFieldTypeArray& aSortOrder, |
|
120 TVPbkSimViewConstructionPolicy aConstructionPolicy, |
|
121 const TDesC& aViewName ) |
|
122 { |
|
123 CSharedViewOwner* viewOwner = NULL; |
|
124 const TInt count = iSharedViews.Count(); |
|
125 for ( TInt i = 0; i < count && !viewOwner; ++i ) |
|
126 { |
|
127 if ( iSharedViews[i]->View().IsMatch( aSortOrder, aConstructionPolicy, aViewName ) ) |
|
128 { |
|
129 viewOwner = iSharedViews[i]; |
|
130 } |
|
131 } |
|
132 return viewOwner; |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CViewHandle::CViewHandle |
|
137 // C++ default constructor can NOT contain any code, that |
|
138 // might leave. |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 CViewHandle::CViewHandle( CSharedViewArray& aSharedViewArray, |
|
142 CVPbkSimContactView& aSharedView ) |
|
143 : iSharedViewArray( aSharedViewArray ), |
|
144 iSharedView( aSharedView ) |
|
145 { |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CViewHandle::~CViewHandle |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 CViewHandle::~CViewHandle() |
|
153 { |
|
154 iSharedViewArray.RemoveHandle( *this ); |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CViewHandle::SharedView |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 CVPbkSimContactView& CViewHandle::SharedView() |
|
162 { |
|
163 return iSharedView; |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CViewHandle::Name |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 const TDesC& CViewHandle::Name() const |
|
171 { |
|
172 return iSharedView.Name(); |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CViewHandle::ParentStore |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 MVPbkSimCntStore& CViewHandle::ParentStore() const |
|
180 { |
|
181 return iSharedView.ParentStore(); |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CViewHandle::OpenL |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 void CViewHandle::OpenL( MVPbkSimViewObserver& aObserver ) |
|
189 { |
|
190 iSharedView.OpenL( aObserver ); |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CViewHandle::Close |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void CViewHandle::Close( MVPbkSimViewObserver& aObserver ) |
|
198 { |
|
199 iSharedView.Close( aObserver ); |
|
200 } |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // CViewHandle::CountL |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 TInt CViewHandle::CountL() const |
|
207 { |
|
208 return iSharedView.CountL(); |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CViewHandle::ContactAtL |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 MVPbkSimContact& CViewHandle::ContactAtL( TInt aIndex ) |
|
216 { |
|
217 return iSharedView.ContactAtL( aIndex ); |
|
218 } |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CViewHandle::ChangeSortOrderL |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 void CViewHandle::ChangeSortOrderL( const RVPbkSimFieldTypeArray& aSortOrder ) |
|
225 { |
|
226 iSharedView.ChangeSortOrderL( aSortOrder ); |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CViewHandle::MapSimIndexToViewIndexL |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 TInt CViewHandle::MapSimIndexToViewIndexL( TInt aSimIndex ) |
|
234 { |
|
235 return iSharedView.MapSimIndexToViewIndexL( aSimIndex ); |
|
236 } |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // CViewHandle::ContactMatchingPrefixL |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 MVPbkSimStoreOperation* CViewHandle::ContactMatchingPrefixL( |
|
243 const MDesCArray& aFindStrings, |
|
244 MVPbkSimViewFindObserver& aObserver ) |
|
245 { |
|
246 return iSharedView.ContactMatchingPrefixL( aFindStrings, aObserver ); |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CViewHandle::SortOrderL |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 const RVPbkSimFieldTypeArray& CViewHandle::SortOrderL() const |
|
254 { |
|
255 return iSharedView.SortOrderL(); |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // CSharedViewOwner::CSharedViewOwner |
|
260 // C++ default constructor can NOT contain any code, that |
|
261 // might leave. |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 CSharedViewOwner::CSharedViewOwner( CSharedViewArray& aSharedViewArray, |
|
265 CVPbkSimContactView* aSharedView ) |
|
266 : iSharedViewArray( aSharedViewArray ), |
|
267 iSharedView( aSharedView ) |
|
268 { |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // CSharedViewOwner::~CSharedViewOwner |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 CSharedViewOwner::~CSharedViewOwner() |
|
276 { |
|
277 iViewHandles.Close(); |
|
278 delete iSharedView; |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CSharedViewOwner::View |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 CVPbkSimContactView& CSharedViewOwner::View() const |
|
286 { |
|
287 return *iSharedView; |
|
288 } |
|
289 |
|
290 // ----------------------------------------------------------------------------- |
|
291 // CSharedViewOwner::CreateNewHandleL |
|
292 // ----------------------------------------------------------------------------- |
|
293 // |
|
294 CViewHandle* CSharedViewOwner::CreateNewHandleL() |
|
295 { |
|
296 CViewHandle* handle = |
|
297 new( ELeave ) CViewHandle( iSharedViewArray, *iSharedView ); |
|
298 CleanupStack::PushL( handle ); |
|
299 iViewHandles.AppendL( handle ); |
|
300 CleanupStack::Pop( handle ); |
|
301 return handle; |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // CSharedViewOwner::RemoveHandle |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 void CSharedViewOwner::RemoveHandle( CViewHandle& aHandle ) |
|
309 { |
|
310 TInt index = iViewHandles.Find( &aHandle ); |
|
311 if ( index != KErrNotFound ) |
|
312 { |
|
313 iViewHandles.Remove( index ); |
|
314 } |
|
315 } |
|
316 |
|
317 // ----------------------------------------------------------------------------- |
|
318 // CSharedViewOwner::HasHandles |
|
319 // ----------------------------------------------------------------------------- |
|
320 // |
|
321 TBool CSharedViewOwner::HasHandles() const |
|
322 { |
|
323 return iViewHandles.Count() > 0; |
|
324 } |
|
325 } // namespace VPbkSimStoreImpl |
|
326 |
|
327 // End of File |