|
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: Fetches contact |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cphcntfetchcontact.h" |
|
20 #include "MPhCntContactStores.h" |
|
21 #include "MVPbkContactLink.h" |
|
22 #include <CVPbkContactLinkArray.h> |
|
23 |
|
24 // ======== MEMBER FUNCTIONS ======== |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // Constructor |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 CPhCntFetchContact::CPhCntFetchContact( |
|
31 MPhCntContactStores& aContactStores ) : |
|
32 iContactStores( aContactStores ) |
|
33 { |
|
34 } |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // Second phase constructor |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 void CPhCntFetchContact::ConstructL() |
|
41 { |
|
42 BaseConstructL(); |
|
43 } |
|
44 |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // Static constructor |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 CPhCntFetchContact* CPhCntFetchContact::NewL( |
|
51 MPhCntContactStores& aContactStores ) |
|
52 { |
|
53 CPhCntFetchContact* self = CPhCntFetchContact::NewLC( aContactStores ); |
|
54 CleanupStack::Pop( self ); |
|
55 return self; |
|
56 } |
|
57 |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // Static constructor |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 CPhCntFetchContact* CPhCntFetchContact::NewLC( |
|
64 MPhCntContactStores& aContactStores ) |
|
65 { |
|
66 CPhCntFetchContact* self = |
|
67 new( ELeave ) CPhCntFetchContact( aContactStores ); |
|
68 CleanupStack::PushL( self ); |
|
69 self->ConstructL(); |
|
70 return self; |
|
71 } |
|
72 |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // Destructor. |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 CPhCntFetchContact::~CPhCntFetchContact() |
|
79 { |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // Starts fetching the contact. |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 TInt CPhCntFetchContact::FetchContact( |
|
87 const MVPbkContactLink& aContactLink, |
|
88 CPhCntContact*& aContact ) |
|
89 { |
|
90 iContactLink = &aContactLink; |
|
91 // Converts asynchronous request to synchronous. |
|
92 const TInt error( MakeAsyncRequest() ); |
|
93 if( !error ) |
|
94 { |
|
95 aContact = iReceivedContact; |
|
96 iReceivedContact = NULL; |
|
97 } |
|
98 iContactLink = NULL; |
|
99 |
|
100 return error; |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // Starts fetching the first contact. |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 TInt CPhCntFetchContact::FetchContact( |
|
108 const TDesC8& aContactLinkArray, |
|
109 CPhCntContact*& aContact ) |
|
110 { |
|
111 CVPbkContactLinkArray* contactLinkArray = NULL; |
|
112 TRAPD( err, |
|
113 contactLinkArray = |
|
114 iContactStores.CreateContactLinkArrayL( aContactLinkArray ) ); |
|
115 |
|
116 if( !err ) |
|
117 { |
|
118 if( contactLinkArray && contactLinkArray->Count() > 0 ) |
|
119 { |
|
120 const MVPbkContactLink& contactLink = contactLinkArray->At( 0 ); |
|
121 err = FetchContact( contactLink, aContact ); |
|
122 } |
|
123 else |
|
124 { |
|
125 err = KErrNotFound; |
|
126 } |
|
127 delete contactLinkArray; |
|
128 } |
|
129 |
|
130 |
|
131 return err; |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // From class CPhCntAsyncToSync |
|
136 // Fetches the contact from contact stores. |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 void CPhCntFetchContact::DoMakeAsyncRequestL() |
|
140 { |
|
141 iContactStores.FetchContactL( *iContactLink, *this ); |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------------------------- |
|
145 // From class MPhCntContactFetchObserver |
|
146 // Takes the contact and notifies base class that contact has been received. |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 void CPhCntFetchContact::ContactReceived( |
|
150 CPhCntContact* aContact, |
|
151 TInt aError ) |
|
152 { |
|
153 iReceivedContact = aContact; |
|
154 ResponseReceived( aError ); // Indicate that asynchronous operation is complete. |
|
155 } |