|
1 /* |
|
2 * Copyright (c) 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: Implementation of CPhCntSpeedDialImpl class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <spdiadialogs.h> |
|
20 #include <MVPbkContactLink.h> |
|
21 #include <PbkFields.hrh> |
|
22 #include <avkon.mbg> |
|
23 #include <eikimage.h> |
|
24 #include <aknconsts.h> |
|
25 |
|
26 #include "CPhCntSpeedDialMonitor.h" |
|
27 #include "cphcntspeeddialimpl.h" |
|
28 #include "cphcntspeeddialcontactlinkfetch.h" |
|
29 #include "MPhoneCntPbkOwner.h" |
|
30 #include "cphcntfetchcontact.h" |
|
31 #include "CPhCntContactStores.h" |
|
32 #include "MPhCntContactManager.h" |
|
33 #include "CPhCntContact.h" |
|
34 #include "cphcntvpbkcontactid.h" |
|
35 #include "CPhCntContactManager.h" |
|
36 |
|
37 // ======== MEMBER FUNCTIONS ======== |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // Default constructor. |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CPhCntSpeedDialImpl::CPhCntSpeedDialImpl( MPhoneCntPbkOwner& aPbkOwner ) : |
|
44 iContactManager( *aPbkOwner.ContactManager() ), |
|
45 iPbkOwner( aPbkOwner ) |
|
46 { |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // CPhCntSpeedDialImpl::ConstructL |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 void CPhCntSpeedDialImpl::ConstructL() |
|
54 { |
|
55 iSpeedDialContactLinkFetcher = |
|
56 CPhCntSpeedDialContactLinkFetch::NewL( iContactManager ); |
|
57 |
|
58 iContactStores = CPhCntContactStores::NewL( iContactManager ); |
|
59 |
|
60 iContactFetcher = CPhCntFetchContact::NewL( *iContactStores ); |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // CPhCntSpeedDialImpl::FetchContact |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 TInt CPhCntSpeedDialImpl::FetchContact( |
|
68 TInt aSpeedDialPosition, |
|
69 CPhCntContact*& aContact ) |
|
70 { |
|
71 TRAPD( err, |
|
72 const MVPbkContactLink& linkToSpeedDialContact = |
|
73 iSpeedDialContactLinkFetcher->FetchSpeedDialLinkL( |
|
74 aSpeedDialPosition ); |
|
75 |
|
76 |
|
77 err = |
|
78 iContactFetcher->FetchContact( linkToSpeedDialContact, aContact ); |
|
79 ) |
|
80 return err; |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // CPhCntSpeedDialImpl::CopyNumberL |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 void CPhCntSpeedDialImpl::CopyNumberL( |
|
88 TDes& aCopyTo, |
|
89 const TDesC& aNumber ) |
|
90 { |
|
91 if( aCopyTo.MaxLength() >= aNumber.Length() ) |
|
92 { |
|
93 aCopyTo.Copy( aNumber ); |
|
94 } |
|
95 else |
|
96 { |
|
97 User::Leave( KErrArgument ); |
|
98 } |
|
99 } |
|
100 // --------------------------------------------------------------------------- |
|
101 // CPhCntSpeedDialImpl::CopyContactInfoToFieldInfoL |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 void CPhCntSpeedDialImpl::CopyContactInfoToFieldInfoL( |
|
105 CPhCntContact& aContact, |
|
106 TInt aSpeedDialPosition, |
|
107 TSpdDialFieldInfo& aFieldInfo ) |
|
108 { |
|
109 |
|
110 MVPbkContactLink* contactLink = aContact.ContactLink()->CloneLC(); |
|
111 CPhCntVPbkContactId* contactId = |
|
112 CPhCntVPbkContactId::NewL( contactLink, iContactManager ); |
|
113 CleanupStack::Pop(); // contactLink |
|
114 aFieldInfo.iContactId = contactId; |
|
115 |
|
116 aFieldInfo.iThumbIndex = KErrNotFound; |
|
117 TPhCntNumber speedDial = aContact.SpeedDialNumber( aSpeedDialPosition ); |
|
118 aFieldInfo.iNumberType = speedDial.Type(); |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CPhCntSpeedDialImpl::NewL |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 CPhCntSpeedDialImpl* CPhCntSpeedDialImpl::NewL( |
|
126 MPhoneCntPbkOwner& aPbkOwner ) |
|
127 { |
|
128 CPhCntSpeedDialImpl* self = |
|
129 CPhCntSpeedDialImpl::NewLC( aPbkOwner ); |
|
130 |
|
131 CleanupStack::Pop( self ); |
|
132 return self; |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // CPhCntSpeedDialImpl::NewLC |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 CPhCntSpeedDialImpl* CPhCntSpeedDialImpl::NewLC( |
|
140 MPhoneCntPbkOwner& aPbkOwner ) |
|
141 { |
|
142 CPhCntSpeedDialImpl* self = new( ELeave ) |
|
143 CPhCntSpeedDialImpl( aPbkOwner ); |
|
144 |
|
145 CleanupStack::PushL( self ); |
|
146 self->ConstructL(); |
|
147 return self; |
|
148 } |
|
149 |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // Destructor |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 CPhCntSpeedDialImpl::~CPhCntSpeedDialImpl() |
|
156 { |
|
157 delete iContactFetcher; |
|
158 delete iContactStores; |
|
159 delete iSpeedDialContactLinkFetcher; |
|
160 delete iSpdDial; |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // CPhCntSpeedDialImpl::GetSpeedDialFieldInfoL |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 void CPhCntSpeedDialImpl::GetSpeedDialFieldInfoL( |
|
168 TInt aSpeedDialPosition, |
|
169 TSpdDialFieldInfo& aFieldInfo ) |
|
170 { |
|
171 CPhCntContact* contact = NULL; |
|
172 User::LeaveIfError( FetchContact( aSpeedDialPosition, contact ) ); |
|
173 |
|
174 CleanupStack::PushL( contact ); |
|
175 |
|
176 CopyContactInfoToFieldInfoL( *contact, aSpeedDialPosition, aFieldInfo ); |
|
177 |
|
178 CleanupStack::PopAndDestroy( contact ); |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // CPhCntSpeedDialImpl::GetSpeedDialFieldL |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 TInt CPhCntSpeedDialImpl::GetSpeedDialFieldL( |
|
186 TInt aSpeedDialPosition, |
|
187 TDes& aPhoneNumber ) |
|
188 { |
|
189 CPhCntContact* contact = NULL; |
|
190 const TInt err = FetchContact( aSpeedDialPosition, contact ); |
|
191 if( !err ) |
|
192 { |
|
193 CleanupStack::PushL( contact ); |
|
194 TPhCntNumber speedDial( contact->SpeedDialNumber( aSpeedDialPosition ) ); |
|
195 CopyNumberL( aPhoneNumber, speedDial.Number() ); |
|
196 CleanupStack::PopAndDestroy( contact ); |
|
197 } |
|
198 return err; |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // CPhCntSpeedDialImpl::GetSpeedDialFieldL |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 TInt CPhCntSpeedDialImpl::GetSpeedDialFieldL( |
|
206 TInt aSpeedDialPosition, |
|
207 TDes& aPhoneNumber, |
|
208 TSpdDialFieldInfo& aFieldInfo ) |
|
209 { |
|
210 CPhCntContact* contact = NULL; |
|
211 const TInt err = FetchContact( aSpeedDialPosition, contact ); |
|
212 |
|
213 if( !err ) |
|
214 { |
|
215 CleanupStack::PushL( contact ); |
|
216 TPhCntNumber speedDial( contact->SpeedDialNumber( aSpeedDialPosition ) ); |
|
217 CopyNumberL( aPhoneNumber, speedDial.Number() ); |
|
218 CopyContactInfoToFieldInfoL( *contact, aSpeedDialPosition, aFieldInfo ); |
|
219 CleanupStack::PopAndDestroy( contact ); |
|
220 } |
|
221 return err; |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CPhCntSpeedDialImpl::FetchNumberL |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 TInt CPhCntSpeedDialImpl::FetchNumberL( |
|
229 TInt aSpeedDialPosition, |
|
230 TDes& aPhoneNumber ) |
|
231 { |
|
232 CPhCntContact* contact = NULL; |
|
233 TInt err = FetchContact( aSpeedDialPosition, contact ); |
|
234 |
|
235 if( !err ) |
|
236 { |
|
237 CleanupStack::PushL( contact ); |
|
238 TPhCntNumber speedDial( contact->SpeedDialNumber( aSpeedDialPosition ) ); |
|
239 CopyNumberL( aPhoneNumber, speedDial.Number() ); |
|
240 CleanupStack::PopAndDestroy( contact ); |
|
241 } |
|
242 return err; |
|
243 } |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CPhCntSpeedDialImpl::AssignSpeedDialFieldL |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 TInt CPhCntSpeedDialImpl::AssignSpeedDialFieldL( |
|
250 TInt aSpeedDialPosition, |
|
251 TDes& aPhoneNumber ) |
|
252 { |
|
253 CVPbkContactManager* contactMg = |
|
254 &iPbkOwner.ContactManager()->ContactManager(); |
|
255 if ( !iSpdDial ) |
|
256 { |
|
257 iSpdDial = CSpdiaDialogs::NewL( *contactMg ); |
|
258 } |
|
259 MVPbkContactLink *link = NULL; |
|
260 TInt err = iSpdDial->ShowAssign( aSpeedDialPosition, link ); |
|
261 delete iSpdDial; |
|
262 iSpdDial = NULL; |
|
263 if ( err == KErrNone ) |
|
264 { |
|
265 err = FetchNumberL( aSpeedDialPosition, aPhoneNumber ); |
|
266 } |
|
267 return err; |
|
268 } |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CPhCntSpeedDialImpl::AssignSpeedDialFieldL |
|
272 // ----------------------------------------------------------------------------- |
|
273 // |
|
274 TInt CPhCntSpeedDialImpl::AssignSpeedDialFieldL( |
|
275 TInt aSpeedDialPosition, |
|
276 TDes& aPhoneNumber, |
|
277 TSpdDialFieldInfo& aFieldInfo ) |
|
278 { |
|
279 TInt err = AssignSpeedDialFieldL( aSpeedDialPosition, aPhoneNumber ); |
|
280 if ( err == KErrNone ) |
|
281 { |
|
282 GetSpeedDialFieldInfoL( aSpeedDialPosition, aFieldInfo ); |
|
283 } |
|
284 return err; |
|
285 } |
|
286 |
|
287 // ----------------------------------------------------------------------------- |
|
288 // CPhCntSpeedDialImpl::Cancel |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 void CPhCntSpeedDialImpl::Cancel() |
|
292 { |
|
293 if ( iSpdDial ) |
|
294 { |
|
295 iSpdDial->Cancel(); |
|
296 } |
|
297 } |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // CPhCntSpeedDialImpl::CreateNumberTypeIconLC |
|
301 // ----------------------------------------------------------------------------- |
|
302 // |
|
303 CEikImage* CPhCntSpeedDialImpl::CreateNumberTypeIconLC( |
|
304 TInt aNumberType ) |
|
305 { |
|
306 TUint icon; |
|
307 TUint mask; |
|
308 switch ( aNumberType ) |
|
309 { |
|
310 case EPbkFieldIdPhoneNumberMobile: |
|
311 icon = EMbmAvkonQgn_prop_nrtyp_mobile; |
|
312 mask = EMbmAvkonQgn_prop_nrtyp_mobile_mask; |
|
313 break; |
|
314 case EPbkFieldIdPagerNumber: |
|
315 icon = EMbmAvkonQgn_prop_nrtyp_pager; |
|
316 mask = EMbmAvkonQgn_prop_nrtyp_pager_mask; |
|
317 break; |
|
318 case EPbkFieldIdPhoneNumberVideo: |
|
319 icon = EMbmAvkonQgn_prop_nrtyp_video; |
|
320 mask = EMbmAvkonQgn_prop_nrtyp_video_mask; |
|
321 break; |
|
322 case EPbkFieldIdVOIP: |
|
323 icon = EMbmAvkonQgn_prop_nrtyp_voip; |
|
324 mask = EMbmAvkonQgn_prop_nrtyp_voip_mask; |
|
325 break; |
|
326 case EPbkFieldIdPhoneNumberGeneral: |
|
327 case EPbkFieldIdPhoneNumberHome: |
|
328 case EPbkFieldIdPhoneNumberWork: |
|
329 case EPbkFieldIdFaxNumber: |
|
330 default: |
|
331 icon = EMbmAvkonQgn_prop_nrtyp_phone; |
|
332 mask = EMbmAvkonQgn_prop_nrtyp_phone_mask; |
|
333 break; |
|
334 } |
|
335 |
|
336 CEikImage* iconImg = new ( ELeave ) CEikImage; |
|
337 CleanupStack::PushL( iconImg ); |
|
338 |
|
339 CFbsBitmap* iconBmp = new ( ELeave ) CFbsBitmap; |
|
340 CleanupStack::PushL( iconBmp ); |
|
341 User::LeaveIfError( iconBmp->Load( |
|
342 KAvkonBitmapFile(), |
|
343 icon, |
|
344 ETrue ) ); |
|
345 |
|
346 CFbsBitmap* iconMaskBmp = new ( ELeave ) CFbsBitmap; |
|
347 CleanupStack::PushL( iconMaskBmp ); |
|
348 User::LeaveIfError( iconMaskBmp->Load( |
|
349 KAvkonBitmapFile(), |
|
350 mask, |
|
351 ETrue ) ); |
|
352 |
|
353 CleanupStack::Pop( iconMaskBmp ); |
|
354 CleanupStack::Pop( iconBmp ); |
|
355 |
|
356 iconImg->SetPicture( iconBmp, iconMaskBmp ); |
|
357 iconImg->SetPictureOwnedExternally( EFalse ); |
|
358 |
|
359 return iconImg; |
|
360 } |
|
361 |
|
362 // End of File |