|
1 /* |
|
2 * Copyright (c) 2008 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "creator_contactsetcache.h" |
|
20 |
|
21 |
|
22 CContactLinkCacheImp* ContactLinkCache::iImp = 0; |
|
23 |
|
24 CCreatorContactSet* CCreatorContactSet::NewL(TInt aLinkId, TInt aNumOfExistingContacts) |
|
25 { |
|
26 return new (ELeave) CCreatorContactSet(aLinkId, aNumOfExistingContacts); |
|
27 } |
|
28 |
|
29 TInt CCreatorContactSet::LinkId() const |
|
30 { |
|
31 return iLinkId; |
|
32 } |
|
33 |
|
34 #if(!defined __SERIES60_30__ && !defined __SERIES60_31__) |
|
35 void CCreatorContactSet::AppendL(MVPbkContactLink* aContactLink) |
|
36 { |
|
37 iContactLinks.AppendL(aContactLink); |
|
38 } |
|
39 |
|
40 RPointerArray<MVPbkContactLink>& CCreatorContactSet::ContactLinks() |
|
41 { |
|
42 return iContactLinks; |
|
43 } |
|
44 |
|
45 const RPointerArray<MVPbkContactLink>& CCreatorContactSet::ContactLinks() const |
|
46 { |
|
47 return iContactLinks; |
|
48 } |
|
49 |
|
50 |
|
51 TInt CCreatorContactSet::NumberOfExistingContacts() const |
|
52 { |
|
53 return iNumOfExistingContacts; |
|
54 } |
|
55 |
|
56 CCreatorContactSet::~CCreatorContactSet() |
|
57 { |
|
58 iContactLinks.Reset(); |
|
59 iContactLinks.Close(); |
|
60 } |
|
61 |
|
62 #else |
|
63 CCreatorContactSet::~CCreatorContactSet() |
|
64 { |
|
65 } |
|
66 #endif |
|
67 |
|
68 |
|
69 CCreatorContactSet::CCreatorContactSet(TInt aLinkId, TInt aNumOfExistingContacts) |
|
70 { |
|
71 iLinkId = aLinkId; |
|
72 iNumOfExistingContacts = aNumOfExistingContacts; |
|
73 } |
|
74 |
|
75 class CContactLinkCacheImp : public CBase, public MContactLinkCache |
|
76 { |
|
77 public: |
|
78 static CContactLinkCacheImp* NewL(); |
|
79 virtual ~CContactLinkCacheImp(); |
|
80 virtual void AppendL(CCreatorContactSet* aContactSet); |
|
81 #if(!defined __SERIES60_30__ && !defined __SERIES60_31__) |
|
82 virtual RPointerArray<MVPbkContactLink>& ContactLinks(TInt aLinkId); |
|
83 virtual const RPointerArray<MVPbkContactLink>& ContactLinks(TInt aLinkId) const; |
|
84 #endif |
|
85 virtual RPointerArray<CCreatorContactSet>& ContactSets(); |
|
86 virtual const RPointerArray<CCreatorContactSet>& ContactSets() const; |
|
87 virtual const CCreatorContactSet& ContactSet(TInt aLinkId) const; |
|
88 virtual CCreatorContactSet& ContactSet(TInt aLinkId); |
|
89 |
|
90 private: |
|
91 void ConstructL(); |
|
92 CContactLinkCacheImp(); |
|
93 #if(!defined __SERIES60_30__ && !defined __SERIES60_31__) |
|
94 RPointerArray<MVPbkContactLink> iEmptyLinks; |
|
95 #endif |
|
96 RPointerArray<CCreatorContactSet> iContactSets; |
|
97 CCreatorContactSet* iDummyContactSet; |
|
98 }; |
|
99 |
|
100 CContactLinkCacheImp* CContactLinkCacheImp::NewL() |
|
101 { |
|
102 CContactLinkCacheImp* self = new (ELeave) CContactLinkCacheImp(); |
|
103 CleanupStack::PushL(self); |
|
104 self->ConstructL(); |
|
105 CleanupStack::Pop(); |
|
106 return self; |
|
107 } |
|
108 |
|
109 void CContactLinkCacheImp::ConstructL() |
|
110 { |
|
111 if( iDummyContactSet == 0 ) |
|
112 iDummyContactSet = CCreatorContactSet::NewL(-1, 0); |
|
113 } |
|
114 |
|
115 CContactLinkCacheImp::CContactLinkCacheImp() |
|
116 : iDummyContactSet(0) |
|
117 {} |
|
118 |
|
119 CContactLinkCacheImp::~CContactLinkCacheImp() |
|
120 { |
|
121 #if(!defined __SERIES60_30__ && !defined __SERIES60_31__) |
|
122 iEmptyLinks.ResetAndDestroy(); // just in case... |
|
123 iEmptyLinks.Close(); |
|
124 #endif |
|
125 iContactSets.ResetAndDestroy(); |
|
126 iContactSets.Close(); |
|
127 delete iDummyContactSet; |
|
128 } |
|
129 void CContactLinkCacheImp::AppendL(CCreatorContactSet* aContactSet) |
|
130 { |
|
131 iContactSets.AppendL(aContactSet); |
|
132 } |
|
133 |
|
134 #if(!defined __SERIES60_30__ && !defined __SERIES60_31__) |
|
135 |
|
136 RPointerArray<MVPbkContactLink>& CContactLinkCacheImp::ContactLinks(TInt aLinkId) |
|
137 { |
|
138 for( TInt i = 0; i < iContactSets.Count(); ++i ) |
|
139 { |
|
140 if( iContactSets[i]->LinkId() == aLinkId ) |
|
141 { |
|
142 return iContactSets[i]->ContactLinks(); |
|
143 } |
|
144 } |
|
145 return iEmptyLinks; |
|
146 } |
|
147 |
|
148 const RPointerArray<MVPbkContactLink>& CContactLinkCacheImp::ContactLinks(TInt aLinkId) const |
|
149 { |
|
150 for( TInt i = 0; i < iContactSets.Count(); ++i ) |
|
151 { |
|
152 if( iContactSets[i]->LinkId() == aLinkId ) |
|
153 { |
|
154 return iContactSets[i]->ContactLinks(); |
|
155 } |
|
156 } |
|
157 return iEmptyLinks; |
|
158 } |
|
159 |
|
160 #endif |
|
161 |
|
162 const CCreatorContactSet& CContactLinkCacheImp::ContactSet(TInt aLinkId) const |
|
163 { |
|
164 for( TInt i = 0; i < iContactSets.Count(); ++i ) |
|
165 { |
|
166 if( iContactSets[i]->LinkId() == aLinkId ) |
|
167 { |
|
168 return *iContactSets[i]; |
|
169 } |
|
170 } |
|
171 |
|
172 return *iDummyContactSet; |
|
173 } |
|
174 |
|
175 CCreatorContactSet& CContactLinkCacheImp::ContactSet(TInt aLinkId) |
|
176 { |
|
177 for( TInt i = 0; i < iContactSets.Count(); ++i ) |
|
178 { |
|
179 if( iContactSets[i]->LinkId() == aLinkId ) |
|
180 { |
|
181 return *iContactSets[i]; |
|
182 } |
|
183 } |
|
184 |
|
185 return *iDummyContactSet; |
|
186 } |
|
187 |
|
188 RPointerArray<CCreatorContactSet>& CContactLinkCacheImp::ContactSets() |
|
189 { |
|
190 return iContactSets; |
|
191 } |
|
192 |
|
193 const RPointerArray<CCreatorContactSet>& CContactLinkCacheImp::ContactSets() const |
|
194 { |
|
195 return iContactSets; |
|
196 } |
|
197 |
|
198 |
|
199 void ContactLinkCache::InitializeL() |
|
200 { |
|
201 if( iImp == 0 ) |
|
202 { |
|
203 iImp = CContactLinkCacheImp::NewL(); |
|
204 } |
|
205 } |
|
206 |
|
207 void ContactLinkCache::DestroyL() |
|
208 { |
|
209 delete iImp; |
|
210 iImp = 0; |
|
211 } |
|
212 |
|
213 MContactLinkCache* ContactLinkCache::Instance() |
|
214 { |
|
215 return iImp; |
|
216 } |
|
217 |
|
218 |
|
219 /*{ |
|
220 public: |
|
221 static void ; |
|
222 static void DestructLD(); |
|
223 |
|
224 static MContactLinkCache* Instance(); |
|
225 |
|
226 private: |
|
227 CContactLinkImp* iImp; |
|
228 };*/ |
|
229 |