|
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 go to URL command object. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2GoToURLCmd.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include <Pbk2ProcessDecoratorFactory.h> |
|
23 #include <MPbk2CommandObserver.h> |
|
24 #include <MPbk2ContactUiControl.h> |
|
25 #include <MPbk2ContactNameFormatter.h> |
|
26 #include <TPbk2AddressSelectParams.h> |
|
27 #include <CPbk2AddressSelect.h> |
|
28 #include <CPbk2ApplicationServices.h> |
|
29 #include <MPbk2AppUi.h> |
|
30 #include <Pbk2UIControls.rsg> |
|
31 #include <CPbk2FieldPropertyArray.h> |
|
32 |
|
33 // Virtual Phonebook |
|
34 #include <CVPbkContactManager.h> |
|
35 #include <MVPbkContactOperationBase.h> |
|
36 #include <MVPbkStoreContact.h> |
|
37 #include <MVPbkContactLink.h> |
|
38 #include <MVPbkContactFieldTextData.h> |
|
39 |
|
40 // System includes |
|
41 #include <BrowserLauncher.h> |
|
42 #include <coemain.h> |
|
43 #include <barsread.h> |
|
44 #include <StringLoader.h> |
|
45 #include <aknnotewrappers.h> |
|
46 |
|
47 /// Unnamed namespace for local definitions |
|
48 namespace { |
|
49 |
|
50 _LIT( KProtocolForURL, "4 " ); // The protocal format |
|
51 |
|
52 #ifdef _DEBUG |
|
53 enum TPanicCode |
|
54 { |
|
55 ERunL_InvalidState = 1, |
|
56 EDoLaunchBrowserL_NullURL, |
|
57 EResolveUrlL_NullField, |
|
58 EPanicPreCond_Null_Pointer |
|
59 }; |
|
60 |
|
61 void Panic(TPanicCode aReason) |
|
62 { |
|
63 _LIT(KPanicText, "CPbk2GoToURLCmd"); |
|
64 User::Panic(KPanicText,aReason); |
|
65 } |
|
66 #endif // _DEBUG |
|
67 |
|
68 } /// namespace |
|
69 |
|
70 |
|
71 // -------------------------------------------------------------------------- |
|
72 // CPbk2GoToURLCmd::CPbk2GoToURLCmd |
|
73 // -------------------------------------------------------------------------- |
|
74 // |
|
75 CPbk2GoToURLCmd::CPbk2GoToURLCmd( MPbk2ContactUiControl& aUiControl ) : |
|
76 CActive( EPriorityIdle ), iUiControl( &aUiControl ) |
|
77 { |
|
78 CActiveScheduler::Add( this ); |
|
79 } |
|
80 |
|
81 // -------------------------------------------------------------------------- |
|
82 // CPbk2GoToURLCmd::~CPbk2GoToURLCmd |
|
83 // -------------------------------------------------------------------------- |
|
84 // |
|
85 CPbk2GoToURLCmd::~CPbk2GoToURLCmd() |
|
86 { |
|
87 Cancel(); |
|
88 |
|
89 delete iURL; |
|
90 delete iContactLink; |
|
91 delete iRetrieveOperation; |
|
92 delete iStoreContact; |
|
93 delete iBrowserLauncher; |
|
94 Release( iAppServices ); |
|
95 } |
|
96 |
|
97 // -------------------------------------------------------------------------- |
|
98 // CPbk2GoToURLCmd::NewL |
|
99 // -------------------------------------------------------------------------- |
|
100 // |
|
101 CPbk2GoToURLCmd* CPbk2GoToURLCmd::NewL |
|
102 ( MPbk2ContactUiControl& aUiControl ) |
|
103 { |
|
104 CPbk2GoToURLCmd* self = new ( ELeave ) CPbk2GoToURLCmd( aUiControl ); |
|
105 CleanupStack::PushL( self ); |
|
106 self->ConstructL(); |
|
107 CleanupStack::Pop( self ); |
|
108 return self; |
|
109 } |
|
110 |
|
111 // -------------------------------------------------------------------------- |
|
112 // CPbk2GoToURLCmd::ConstructL |
|
113 // -------------------------------------------------------------------------- |
|
114 // |
|
115 inline void CPbk2GoToURLCmd::ConstructL() |
|
116 { |
|
117 iAppServices = CPbk2ApplicationServices::InstanceL(); |
|
118 |
|
119 iContactLink = iUiControl->FocusedContactL()->CreateLinkLC(); |
|
120 CleanupStack::Pop(); // iContactLink |
|
121 |
|
122 iFieldPropertyArray = &(iAppServices->FieldProperties()); |
|
123 iBrowserLauncher = CBrowserLauncher::NewL(); |
|
124 } |
|
125 |
|
126 // -------------------------------------------------------------------------- |
|
127 // CPbk2GoToURLCmd::DoCancel |
|
128 // -------------------------------------------------------------------------- |
|
129 // |
|
130 void CPbk2GoToURLCmd::DoCancel() |
|
131 { |
|
132 iBrowserLauncher->Cancel(); |
|
133 } |
|
134 |
|
135 // -------------------------------------------------------------------------- |
|
136 // CPbk2GoToURLCmd::RunL |
|
137 // -------------------------------------------------------------------------- |
|
138 // |
|
139 void CPbk2GoToURLCmd::RunL() |
|
140 { |
|
141 switch (iState) |
|
142 { |
|
143 case ERetrieving: |
|
144 { |
|
145 RetrieveContactL( *iContactLink ); |
|
146 break; |
|
147 } |
|
148 |
|
149 case EResolveURL: |
|
150 { |
|
151 ResolveUrlL(); |
|
152 break; |
|
153 } |
|
154 |
|
155 case EStarting: |
|
156 { |
|
157 DoLaunchBrowserL(); |
|
158 break; |
|
159 } |
|
160 |
|
161 case ELaunching: |
|
162 { |
|
163 // Do nothing |
|
164 break; |
|
165 } |
|
166 |
|
167 case EStopping: |
|
168 { |
|
169 ProcessDismissed(KErrNone); |
|
170 break; |
|
171 } |
|
172 |
|
173 default: |
|
174 { |
|
175 __ASSERT_DEBUG(EFalse, Panic(ERunL_InvalidState)); |
|
176 break; |
|
177 } |
|
178 } |
|
179 } |
|
180 |
|
181 // -------------------------------------------------------------------------- |
|
182 // CPbk2GoToURLCmd::RunError |
|
183 // -------------------------------------------------------------------------- |
|
184 // |
|
185 TInt CPbk2GoToURLCmd::RunError( TInt aError ) |
|
186 { |
|
187 return aError; |
|
188 } |
|
189 |
|
190 // -------------------------------------------------------------------------- |
|
191 // CPbk2GoToURLCmd::ExecuteLD |
|
192 // -------------------------------------------------------------------------- |
|
193 // |
|
194 void CPbk2GoToURLCmd::ExecuteLD() |
|
195 { |
|
196 iState = ERetrieving; |
|
197 IssueRequest(); |
|
198 } |
|
199 |
|
200 // -------------------------------------------------------------------------- |
|
201 // CPbk2GoToURLCmd::AddObserver |
|
202 // -------------------------------------------------------------------------- |
|
203 // |
|
204 void CPbk2GoToURLCmd::AddObserver( MPbk2CommandObserver& aObserver ) |
|
205 { |
|
206 this->iCommandObserver = &aObserver; |
|
207 } |
|
208 |
|
209 // -------------------------------------------------------------------------- |
|
210 // CPbk2GoToURLCmd::ResetUiControl |
|
211 // -------------------------------------------------------------------------- |
|
212 // |
|
213 void CPbk2GoToURLCmd::ResetUiControl( MPbk2ContactUiControl& aUiControl ) |
|
214 { |
|
215 if (iUiControl == &aUiControl) |
|
216 { |
|
217 iUiControl = NULL; |
|
218 } |
|
219 } |
|
220 |
|
221 // -------------------------------------------------------------------------- |
|
222 // CPbk2GoToURLCmd::ProcessDismissed |
|
223 // -------------------------------------------------------------------------- |
|
224 // |
|
225 void CPbk2GoToURLCmd::ProcessDismissed( TInt /*aCancelCode*/ ) |
|
226 { |
|
227 __ASSERT_DEBUG(iCommandObserver, Panic(EPanicPreCond_Null_Pointer)); |
|
228 |
|
229 if (iUiControl) |
|
230 { |
|
231 iUiControl->UpdateAfterCommandExecution(); |
|
232 } |
|
233 |
|
234 // Notify command owner that the command has finished |
|
235 iCommandObserver->CommandFinished(*this); |
|
236 } |
|
237 |
|
238 // -------------------------------------------------------------------------- |
|
239 // CPbk2GoToURLCmd::VPbkSingleContactOperationComplete |
|
240 // Called when retrieve operation completes. |
|
241 // -------------------------------------------------------------------------- |
|
242 // |
|
243 void CPbk2GoToURLCmd::VPbkSingleContactOperationComplete |
|
244 ( MVPbkContactOperationBase& aOperation, |
|
245 MVPbkStoreContact* aContact ) |
|
246 { |
|
247 if (&aOperation == iRetrieveOperation) |
|
248 { |
|
249 delete iRetrieveOperation; |
|
250 iRetrieveOperation = NULL; |
|
251 |
|
252 // We now have a store contact |
|
253 iStoreContact = aContact; |
|
254 iState = EResolveURL; |
|
255 IssueRequest(); |
|
256 } |
|
257 } |
|
258 |
|
259 // -------------------------------------------------------------------------- |
|
260 // CPbk2GoToURLCmd::VPbkSingleContactOperationFailed |
|
261 // Called when retrieve operation fails. |
|
262 // -------------------------------------------------------------------------- |
|
263 // |
|
264 void CPbk2GoToURLCmd::VPbkSingleContactOperationFailed |
|
265 ( MVPbkContactOperationBase& aOperation, TInt aError ) |
|
266 { |
|
267 if (&aOperation == iRetrieveOperation) |
|
268 { |
|
269 delete iRetrieveOperation; |
|
270 iRetrieveOperation = NULL; |
|
271 |
|
272 // We cannot get the contact, so we have to |
|
273 // fail. We cannot continue, since this operation |
|
274 // was executed only in case of one contact. |
|
275 ProcessDismissed(aError); |
|
276 } |
|
277 } |
|
278 |
|
279 // -------------------------------------------------------------------------- |
|
280 // CPbk2GoToURLCmd::HandleServerAppExit |
|
281 // -------------------------------------------------------------------------- |
|
282 // |
|
283 void CPbk2GoToURLCmd::HandleServerAppExit( TInt /*aReason*/ ) |
|
284 { |
|
285 IssueStopRequest(); |
|
286 } |
|
287 |
|
288 // -------------------------------------------------------------------------- |
|
289 // CPbk2GoToURLCmd::RetrieveContactL |
|
290 // -------------------------------------------------------------------------- |
|
291 // |
|
292 void CPbk2GoToURLCmd::RetrieveContactL |
|
293 ( const MVPbkContactLink& aContactLink ) |
|
294 { |
|
295 // Retrieve the actual store contact from the given link |
|
296 iRetrieveOperation = iAppServices-> |
|
297 ContactManager().RetrieveContactL( aContactLink, *this ); |
|
298 } |
|
299 |
|
300 // -------------------------------------------------------------------------- |
|
301 // CPbk2GoToURLCmd::DoLaunchBrowserL |
|
302 // -------------------------------------------------------------------------- |
|
303 // |
|
304 void CPbk2GoToURLCmd::DoLaunchBrowserL() |
|
305 { |
|
306 __ASSERT_DEBUG(iURL,Panic(EDoLaunchBrowserL_NullURL)); |
|
307 |
|
308 iBrowserLauncher->LaunchBrowserEmbeddedL |
|
309 ( *iURL, NULL, this ); |
|
310 |
|
311 iState = ELaunching; |
|
312 IssueRequest(); |
|
313 } |
|
314 |
|
315 // -------------------------------------------------------------------------- |
|
316 // CPbk2GoToURLCmd::ResolveUrlL |
|
317 // -------------------------------------------------------------------------- |
|
318 // |
|
319 void CPbk2GoToURLCmd::ResolveUrlL() |
|
320 { |
|
321 TResourceReader resReader; |
|
322 CCoeEnv::Static()->CreateResourceReaderLC |
|
323 (resReader, R_PBK2_URL_ADDRESS_SELECT); |
|
324 |
|
325 TPbk2AddressSelectParams params( |
|
326 *iStoreContact, |
|
327 iAppServices->ContactManager(), |
|
328 iAppServices->NameFormatter(), |
|
329 *iFieldPropertyArray, |
|
330 resReader); |
|
331 |
|
332 CPbk2AddressSelect* addressSelect = CPbk2AddressSelect::NewL(params); |
|
333 MVPbkStoreContactField* selectedField = addressSelect->ExecuteLD(); |
|
334 |
|
335 CleanupStack::PopAndDestroy(); // resReader |
|
336 |
|
337 // No field selected. Stop command process. |
|
338 if (!selectedField) |
|
339 { |
|
340 IssueStopRequest(); |
|
341 } |
|
342 else |
|
343 { |
|
344 CleanupDeletePushL(selectedField); |
|
345 SetURLFromFieldL(*selectedField); |
|
346 CleanupStack::PopAndDestroy(); // selectedField |
|
347 |
|
348 iState = EStarting; |
|
349 IssueRequest(); |
|
350 } |
|
351 } |
|
352 |
|
353 // -------------------------------------------------------------------------- |
|
354 // CPbk2GoToURLCmd::SetURLFromFieldL |
|
355 // -------------------------------------------------------------------------- |
|
356 // |
|
357 void CPbk2GoToURLCmd::SetURLFromFieldL( MVPbkStoreContactField& aField ) |
|
358 { |
|
359 TPtrC url = MVPbkContactFieldTextData::Cast(aField.FieldData()).Text(); |
|
360 delete iURL; |
|
361 iURL = NULL; |
|
362 // For explanation of the protocal format |
|
363 // refer to Browser API documentation |
|
364 iURL = HBufC::NewL(KProtocolForURL().Length() + url.Length()); |
|
365 TPtr urlPtr = iURL->Des(); |
|
366 urlPtr.Append(KProtocolForURL); |
|
367 urlPtr.Append(url); |
|
368 } |
|
369 |
|
370 // -------------------------------------------------------------------------- |
|
371 // CPbk2GoToURLCmd::IssueRequest |
|
372 // -------------------------------------------------------------------------- |
|
373 // |
|
374 void CPbk2GoToURLCmd::IssueRequest() |
|
375 { |
|
376 TRequestStatus* status = &iStatus; |
|
377 User::RequestComplete( status, KErrNone ); |
|
378 SetActive(); |
|
379 } |
|
380 |
|
381 // -------------------------------------------------------------------------- |
|
382 // CPbk2GoToURLCmd::IssueStopRequest |
|
383 // -------------------------------------------------------------------------- |
|
384 // |
|
385 void CPbk2GoToURLCmd::IssueStopRequest() |
|
386 { |
|
387 iState = EStopping; |
|
388 if (!IsActive()) |
|
389 { |
|
390 IssueRequest(); |
|
391 } |
|
392 } |
|
393 |
|
394 // End of File |