|
1 /* |
|
2 * Copyright (c) 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: Service to show dialogs for user to select contact data. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cphcntcontactdataselectionimpl.h" |
|
20 #include "mphcntservicerequestparamfactory.h" |
|
21 #include "mphcntservicerequestparam.h" |
|
22 #include "MPhCntContactStores.h" |
|
23 #include "CPhCntContact.h" |
|
24 #include "cphcntcontactid.h" |
|
25 |
|
26 CPhCntSelectedDataImpl* CPhCntSelectedDataImpl::NewL( |
|
27 CPhCntContact& aContact ) |
|
28 { |
|
29 CPhCntSelectedDataImpl* self = new( ELeave )CPhCntSelectedDataImpl(); |
|
30 CleanupStack::PushL( self ); |
|
31 self->ConstructL( aContact ); |
|
32 CleanupStack::Pop( self ); |
|
33 return self; |
|
34 } |
|
35 |
|
36 CPhCntSelectedDataImpl::~CPhCntSelectedDataImpl() |
|
37 { |
|
38 delete iSelectedData; |
|
39 delete iFieldLink; |
|
40 } |
|
41 |
|
42 CPhCntSelectedDataImpl::CPhCntSelectedDataImpl() |
|
43 { |
|
44 } |
|
45 |
|
46 void CPhCntSelectedDataImpl::ConstructL( CPhCntContact& aContact ) |
|
47 { |
|
48 iSelectedData = aContact.Number().AllocL(); |
|
49 iFieldLink = aContact.ContactId()->PackLC(); |
|
50 iNumberType = aContact.NumberType(); |
|
51 CleanupStack::Pop( iFieldLink ); |
|
52 } |
|
53 |
|
54 const TDesC& CPhCntSelectedDataImpl::Data() const |
|
55 { |
|
56 return *iSelectedData; |
|
57 } |
|
58 |
|
59 const TDesC8& CPhCntSelectedDataImpl::FieldLink() const |
|
60 { |
|
61 return *iFieldLink; |
|
62 } |
|
63 |
|
64 MPhCntMatch::TNumberType CPhCntSelectedDataImpl::NumberType() const |
|
65 { |
|
66 return iNumberType; |
|
67 } |
|
68 |
|
69 // ======== MEMBER FUNCTIONS ======== |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // Constructor |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CPhCntContactDataSelectionImpl::CPhCntContactDataSelectionImpl( |
|
76 MPhCntAiwService* aService, |
|
77 MPhCntServiceRequestParamFactory* aParamFactory, |
|
78 MPhCntContactStores* aContactStores ) : |
|
79 iService( aService ), |
|
80 iParamFactory( aParamFactory ), |
|
81 iServiceResult( iFieldLink ), |
|
82 iContactStores( aContactStores ) |
|
83 { |
|
84 } |
|
85 |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // 2nd phase constructor |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 void CPhCntContactDataSelectionImpl::ConstructL() |
|
92 { |
|
93 } |
|
94 |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // static constructor |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 CPhCntContactDataSelectionImpl* CPhCntContactDataSelectionImpl::NewL( |
|
101 MPhCntAiwService* aService, |
|
102 MPhCntServiceRequestParamFactory* aParamFactory, |
|
103 MPhCntContactStores* aContactStores ) |
|
104 { |
|
105 CPhCntContactDataSelectionImpl* self = new( ELeave ) |
|
106 CPhCntContactDataSelectionImpl( |
|
107 aService, aParamFactory, aContactStores ); |
|
108 CleanupStack::PushL( self ); |
|
109 self->ConstructL(); |
|
110 CleanupStack::Pop( self ); |
|
111 return self; |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // Destructor |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 CPhCntContactDataSelectionImpl::~CPhCntContactDataSelectionImpl() |
|
119 { |
|
120 if( iService ) |
|
121 { |
|
122 iService->Cancel(); |
|
123 } |
|
124 delete iService; |
|
125 delete iParamFactory; |
|
126 delete iServiceParameter; |
|
127 delete iFieldLink; |
|
128 if( iContactStores ) |
|
129 { |
|
130 iContactStores->CancelRequest(); |
|
131 } |
|
132 delete iContactStores; |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // From class CPhCntContactDataSelection |
|
137 // Determines if there is active request pending. |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 TBool CPhCntContactDataSelectionImpl::IsActive() const |
|
141 { |
|
142 return iService->IsRequestActive() | iContactStores->IsRequestActive(); |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // From class CPhCntContactDataSelection |
|
147 // ?implementation_description |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 void CPhCntContactDataSelectionImpl::Cancel() |
|
151 { |
|
152 iService->Cancel(); |
|
153 iContactStores->CancelRequest(); |
|
154 iObserver = NULL; |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // From class CPhCntContactDataSelection |
|
159 // Starts phone number selection. |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 void CPhCntContactDataSelectionImpl::SelectPhoneNumberForCallL( |
|
163 const TDesC8& aContactLink, |
|
164 const TCallType& aCallType, |
|
165 MPhCntSelectionObserver& aObserver ) |
|
166 { |
|
167 if( IsActive() ) |
|
168 { |
|
169 User::Leave( KErrInUse ); |
|
170 } |
|
171 iObserver = &aObserver; |
|
172 delete iServiceParameter; |
|
173 iServiceParameter = NULL; |
|
174 iServiceParameter = iParamFactory->CreateGetPhoneNumberFromContactParamL( |
|
175 aContactLink, |
|
176 static_cast<CPhCntSingleItemFetch::TCallType>(aCallType ) ); |
|
177 iService->ExecuteRequestL( *iServiceParameter, iServiceResult, *this ); |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // From class MPhCntServiceObserver |
|
182 // Indication from Aiw service that request has completed. |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 void CPhCntContactDataSelectionImpl::RequestComplete( TInt aError ) |
|
186 { |
|
187 if( !aError ) |
|
188 { |
|
189 TRAPD( err, iContactStores->FetchFirstContactL( *iFieldLink, *this ) ); |
|
190 if( iObserver && err ) |
|
191 { |
|
192 iObserver->SelectionDone( NULL, err ); |
|
193 } |
|
194 } |
|
195 else |
|
196 { |
|
197 if( iObserver ) |
|
198 { |
|
199 iObserver->SelectionDone( NULL, aError ); |
|
200 } |
|
201 } |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------------------------- |
|
205 // From class MPhCntContactFetchObserver |
|
206 // Indication from contact stores that contact is now received. |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 void CPhCntContactDataSelectionImpl::ContactReceived( |
|
210 CPhCntContact* aContact, TInt aError ) |
|
211 { |
|
212 if( !aError ) |
|
213 { |
|
214 CPhCntSelectedDataImpl* selectedData = NULL; |
|
215 TRAPD( err, |
|
216 selectedData = CPhCntSelectedDataImpl::NewL( *aContact ) ); |
|
217 iObserver->SelectionDone( selectedData, err ); |
|
218 delete selectedData; |
|
219 } |
|
220 else |
|
221 { |
|
222 iObserver->SelectionDone( NULL, aError ); |
|
223 } |
|
224 delete aContact; |
|
225 } |