|
1 /* |
|
2 * Copyright (c) 2005-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: Phonebook 2 application server entry fetcher. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2EntryFetcher.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "MPbk2UiServiceObserver.h" |
|
23 #include "TPbk2ServerMessageDataRetriever.h" |
|
24 #include "CPbk2ServerAppAppUi.h" |
|
25 #include "TPbk2TitlePaneOperator.h" |
|
26 #include "CPbk2ServerAppStoreManager.h" |
|
27 #include "MPbk2ServicePhase.h" |
|
28 #include "CPbk2ContactFetchPhase.h" |
|
29 #include <CPbk2StoreManager.h> |
|
30 #include <Pbk2IPCPackage.h> |
|
31 #include <MPbk2ApplicationServices.h> |
|
32 |
|
33 // Virtual Phonebook |
|
34 #include <CVPbkContactStoreUriArray.h> |
|
35 #include <MVPbkContactLink.h> |
|
36 #include <CVPbkFieldTypeSelector.h> |
|
37 #include <CVPbkContactManager.h> |
|
38 |
|
39 // System includes |
|
40 #include <AiwContactSelectionDataTypes.h> |
|
41 |
|
42 // Debug |
|
43 #include <Pbk2Debug.h> |
|
44 |
|
45 |
|
46 /// Unnamed namespace for local definitions |
|
47 namespace { |
|
48 |
|
49 /** |
|
50 * Sets title pane. |
|
51 * |
|
52 * @param aDataRetriever Server message data retriever. |
|
53 * @param aFlags Fetch flags. |
|
54 * @param aMessage Server message. |
|
55 */ |
|
56 void SetTitlePaneL |
|
57 ( TPbk2ServerMessageDataRetriever& aDataRetriever, TUint aFlags, |
|
58 const RMessage2& aMessage ) |
|
59 { |
|
60 HBufC* titlePaneText = NULL; |
|
61 if ( !( aFlags & ::EUseProviderTitle ) ) |
|
62 { |
|
63 titlePaneText = aDataRetriever.GetTitlePaneTextL( aMessage ); |
|
64 } |
|
65 TPbk2TitlePaneOperator titlePaneOperator; |
|
66 titlePaneOperator.SetTitlePaneL( titlePaneText ); // takes ownership |
|
67 } |
|
68 |
|
69 } /// namespace |
|
70 |
|
71 // -------------------------------------------------------------------------- |
|
72 // CPbk2EntryFetcher::CPbk2EntryFetcher |
|
73 // -------------------------------------------------------------------------- |
|
74 // |
|
75 CPbk2EntryFetcher::CPbk2EntryFetcher |
|
76 ( MPbk2UiServiceObserver& aObserver, |
|
77 TPbk2FetchType aFetchType ) : |
|
78 iObserver( aObserver ), |
|
79 iFetchType( aFetchType ) |
|
80 { |
|
81 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
82 ("CPbk2EntryFetcher::CPbk2EntryFetcher()") ); |
|
83 } |
|
84 |
|
85 // -------------------------------------------------------------------------- |
|
86 // CPbk2EntryFetcher::~CPbk2EntryFetcher |
|
87 // -------------------------------------------------------------------------- |
|
88 // |
|
89 CPbk2EntryFetcher::~CPbk2EntryFetcher() |
|
90 { |
|
91 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
92 ("CPbk2EntryFetcher::~CPbk2EntryFetcher()") ); |
|
93 |
|
94 delete iStoreUris; |
|
95 delete iPreselectedContacts; |
|
96 delete iContactViewFilter; |
|
97 delete iStoreManager; |
|
98 delete iFetchPhase; |
|
99 } |
|
100 |
|
101 // -------------------------------------------------------------------------- |
|
102 // CPbk2EntryFetcher::ConstructL |
|
103 // -------------------------------------------------------------------------- |
|
104 // |
|
105 inline void CPbk2EntryFetcher::ConstructL( const RMessage2& aMessage ) |
|
106 { |
|
107 // Retrieve data from the client-server message |
|
108 CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&> |
|
109 ( *CEikonEnv::Static()->EikAppUi() ); |
|
110 |
|
111 TPbk2ServerMessageDataRetriever dataRetriever; |
|
112 TUint flags = dataRetriever.FetchFlagsL( aMessage ); |
|
113 |
|
114 // Set title pane |
|
115 SetTitlePaneL( dataRetriever, flags, aMessage ); |
|
116 |
|
117 iPreselectedContacts = dataRetriever.GetPreselectedContactLinksL |
|
118 ( aMessage, appUi.ApplicationServices().ContactManager() ); |
|
119 iStoreUris = dataRetriever.GetContactStoreUriArrayL |
|
120 ( aMessage, appUi.ApplicationServices().StoreConfiguration(), |
|
121 iPreselectedContacts, iUseDeviceConfig ); |
|
122 iContactViewFilter = dataRetriever.GetContactViewFilterL |
|
123 ( aMessage, appUi.ApplicationServices().ContactManager(). |
|
124 FieldTypes() ); |
|
125 iFetchResId = dataRetriever.GetFetchDialogResourceL( aMessage ); |
|
126 |
|
127 iStoreManager = CPbk2ServerAppStoreManager::NewL |
|
128 ( appUi.StoreManager(), |
|
129 appUi.ApplicationServices().ContactManager() ); |
|
130 } |
|
131 |
|
132 // -------------------------------------------------------------------------- |
|
133 // CPbk2EntryFetcher::NewL |
|
134 // -------------------------------------------------------------------------- |
|
135 // |
|
136 CPbk2EntryFetcher* CPbk2EntryFetcher::NewL( |
|
137 const RMessage2& aFetchCompleteMessage, |
|
138 MPbk2UiServiceObserver& aObserver, |
|
139 TPbk2FetchType aFetchType ) |
|
140 { |
|
141 CPbk2EntryFetcher* self = |
|
142 new ( ELeave ) CPbk2EntryFetcher( aObserver, aFetchType ); |
|
143 CleanupStack::PushL( self ); |
|
144 self->ConstructL( aFetchCompleteMessage ); |
|
145 CleanupStack::Pop( self ); |
|
146 return self; |
|
147 } |
|
148 |
|
149 // -------------------------------------------------------------------------- |
|
150 // CPbk2EntryFetcher::LaunchServiceL |
|
151 // -------------------------------------------------------------------------- |
|
152 // |
|
153 void CPbk2EntryFetcher::LaunchServiceL() |
|
154 { |
|
155 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
156 ("CPbk2EntryFetcher::LaunchServiceL()") ); |
|
157 |
|
158 iStoreManager->LoadAndOpenContactStoresL( *iStoreUris, *this, EFalse ); |
|
159 } |
|
160 |
|
161 // -------------------------------------------------------------------------- |
|
162 // CPbk2EntryFetcher::CancelService |
|
163 // -------------------------------------------------------------------------- |
|
164 // |
|
165 void CPbk2EntryFetcher::CancelService() |
|
166 { |
|
167 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
168 ("CPbk2EntryFetcher::CancelService()") ); |
|
169 |
|
170 if ( iFetchPhase ) |
|
171 { |
|
172 iFetchPhase->CancelServicePhase(); |
|
173 } |
|
174 } |
|
175 |
|
176 // -------------------------------------------------------------------------- |
|
177 // CPbk2EntryFetcher::AcceptDelayedContactsL |
|
178 // -------------------------------------------------------------------------- |
|
179 // |
|
180 void CPbk2EntryFetcher::AcceptDelayedContactsL |
|
181 ( const TDesC8& aContactLinkBuffer ) |
|
182 { |
|
183 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
184 ("CPbk2EntryFetcher::AcceptDelayedContactsL()") ); |
|
185 |
|
186 if ( iFetchPhase ) |
|
187 { |
|
188 iFetchPhase->AcceptDelayedL( aContactLinkBuffer ); |
|
189 } |
|
190 } |
|
191 |
|
192 // -------------------------------------------------------------------------- |
|
193 // CPbk2EntryFetcher::ExitServiceL |
|
194 // -------------------------------------------------------------------------- |
|
195 // |
|
196 void CPbk2EntryFetcher::ExitServiceL( TInt aExitCommandId ) |
|
197 { |
|
198 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
199 ("CPbk2EntryFetcher::ExitServiceL(%d)"), aExitCommandId ); |
|
200 |
|
201 if ( iFetchPhase ) |
|
202 { |
|
203 iFetchPhase->RequestCancelL( aExitCommandId ); |
|
204 } |
|
205 } |
|
206 |
|
207 // -------------------------------------------------------------------------- |
|
208 // CPbk2EntryFetcher::ServiceResults |
|
209 // -------------------------------------------------------------------------- |
|
210 // |
|
211 void CPbk2EntryFetcher::ServiceResults(TServiceResults* aResults) const |
|
212 { |
|
213 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
214 ("CPbk2EntryFetcher::ServiceResults()") ); |
|
215 |
|
216 if ( iFetchPhase ) |
|
217 { |
|
218 aResults->iLinkArray = iFetchPhase->Results(); |
|
219 aResults->iExtraData = iFetchPhase->ExtraResultData(); |
|
220 aResults->iFieldContent = iFetchPhase->FieldContent(); |
|
221 } |
|
222 } |
|
223 |
|
224 // -------------------------------------------------------------------------- |
|
225 // CPbk2EntryFetcher::NextPhase |
|
226 // -------------------------------------------------------------------------- |
|
227 // |
|
228 void CPbk2EntryFetcher::NextPhase( MPbk2ServicePhase& /*aPhase*/ ) |
|
229 { |
|
230 // There is no other phase than fetch, we are done |
|
231 iObserver.ServiceComplete(); |
|
232 } |
|
233 |
|
234 // -------------------------------------------------------------------------- |
|
235 // CPbk2EntryFetcher::PreviousPhase |
|
236 // -------------------------------------------------------------------------- |
|
237 // |
|
238 void CPbk2EntryFetcher::PreviousPhase( MPbk2ServicePhase& /*aPhase*/ ) |
|
239 { |
|
240 // Do nothing |
|
241 } |
|
242 |
|
243 // -------------------------------------------------------------------------- |
|
244 // CPbk2EntryFetcher::PhaseCanceled |
|
245 // -------------------------------------------------------------------------- |
|
246 // |
|
247 void CPbk2EntryFetcher::PhaseCanceled( MPbk2ServicePhase& /*aPhase*/ ) |
|
248 { |
|
249 iObserver.ServiceCanceled(); |
|
250 } |
|
251 |
|
252 // -------------------------------------------------------------------------- |
|
253 // CPbk2EntryFetcher::PhaseAborted |
|
254 // -------------------------------------------------------------------------- |
|
255 // |
|
256 void CPbk2EntryFetcher::PhaseAborted( MPbk2ServicePhase& /*aPhase*/ ) |
|
257 { |
|
258 iObserver.ServiceAborted(); |
|
259 } |
|
260 |
|
261 // -------------------------------------------------------------------------- |
|
262 // CPbk2EntryFetcher::PhaseError |
|
263 // -------------------------------------------------------------------------- |
|
264 // |
|
265 void CPbk2EntryFetcher::PhaseError |
|
266 ( MPbk2ServicePhase& /*aPhase*/, TInt aErrorCode ) |
|
267 { |
|
268 iObserver.ServiceError( aErrorCode ); |
|
269 } |
|
270 |
|
271 // -------------------------------------------------------------------------- |
|
272 // CPbk2EntryFetcher::PhaseOkToExit |
|
273 // -------------------------------------------------------------------------- |
|
274 // |
|
275 TBool CPbk2EntryFetcher::PhaseOkToExit |
|
276 ( MPbk2ServicePhase& /*aPhase*/, TInt aCommandId ) |
|
277 { |
|
278 // Deny exit and pass an asynchronous query to the consumer, |
|
279 // which may later approve exit |
|
280 iObserver.CompleteExitMessage( aCommandId ); |
|
281 return EFalse; |
|
282 } |
|
283 |
|
284 // -------------------------------------------------------------------------- |
|
285 // CPbk2EntryFetcher::PhaseAccept |
|
286 // -------------------------------------------------------------------------- |
|
287 // |
|
288 void CPbk2EntryFetcher::PhaseAccept |
|
289 ( MPbk2ServicePhase& /*aPhase*/, const TDesC8& aMarkedEntries, |
|
290 const TDesC8& aLinkData ) |
|
291 { |
|
292 iObserver.CompleteAcceptMsg( aMarkedEntries, aLinkData ); |
|
293 } |
|
294 |
|
295 // -------------------------------------------------------------------------- |
|
296 // CPbk2EntryFetcher::ContactUiReadyL |
|
297 // -------------------------------------------------------------------------- |
|
298 // |
|
299 void CPbk2EntryFetcher::ContactUiReadyL |
|
300 ( MPbk2StartupMonitor& aStartupMonitor ) |
|
301 { |
|
302 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
303 ("CPbk2EntryFetcher::ContactUiReadyL()") ); |
|
304 |
|
305 aStartupMonitor.DeregisterEvents( *this ); |
|
306 |
|
307 LaunchFetchPhaseL(); |
|
308 } |
|
309 |
|
310 // -------------------------------------------------------------------------- |
|
311 // CPbk2EntryFetcher::StartupCanceled |
|
312 // -------------------------------------------------------------------------- |
|
313 // |
|
314 void CPbk2EntryFetcher::StartupCanceled( TInt aErrorCode ) |
|
315 { |
|
316 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
317 ("CPbk2EntryFetcher::StartupCanceled(%d)"), aErrorCode ); |
|
318 |
|
319 if ( aErrorCode == KErrCancel ) |
|
320 { |
|
321 iObserver.ServiceCanceled(); |
|
322 } |
|
323 else |
|
324 { |
|
325 iObserver.ServiceError( aErrorCode ); |
|
326 } |
|
327 } |
|
328 |
|
329 // -------------------------------------------------------------------------- |
|
330 // CPbk2EntryFetcher::LaunchFetchPhaseL |
|
331 // -------------------------------------------------------------------------- |
|
332 // |
|
333 void CPbk2EntryFetcher::LaunchFetchPhaseL() |
|
334 { |
|
335 CPbk2FetchDlg::TParams params; |
|
336 |
|
337 params.iResId = iFetchResId; |
|
338 params.iMarkedEntries = iPreselectedContacts; |
|
339 params.iFlags = CPbk2FetchDlg::EFetchSingle; |
|
340 if ( iFetchType == EMultipleEntryFetch ) |
|
341 { |
|
342 params.iFlags = CPbk2FetchDlg::EFetchMultiple; |
|
343 } |
|
344 |
|
345 delete iFetchPhase; |
|
346 iFetchPhase = NULL; |
|
347 iFetchPhase = CPbk2ContactFetchPhase::NewL |
|
348 ( *this, *iStoreManager, params, ETrue, |
|
349 MPbk2FetchDlgObserver::EFetchDelayed, iContactViewFilter, |
|
350 iUseDeviceConfig, iStoreUris ); |
|
351 |
|
352 CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&> |
|
353 ( *CEikonEnv::Static()->EikAppUi() ); |
|
354 |
|
355 // Change layout to fetch's layout |
|
356 appUi.ChangeStatuspaneLayoutL( |
|
357 CPbk2ServerAppAppUi::EStatusPaneLayoutUsual ); |
|
358 |
|
359 iFetchPhase->LaunchServicePhaseL(); |
|
360 } |
|
361 |
|
362 // End of File |