|
1 /* |
|
2 * Copyright (c) 2007-2008 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: Message header URL event handler |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "FreestyleMessageHeaderURLEventHandler.h" |
|
19 #include "FreestyleMessageHeaderURL.h" |
|
20 #include "FreestyleEmailUiConstants.h" |
|
21 #include "FreestyleEmailUiUtilities.h" |
|
22 #include "cfsmailmessage.h" |
|
23 #include "FreestyleEmailUiAppui.h" |
|
24 #include "FreestyleEmailUiHtmlViewerView.h" |
|
25 #include "FreestyleEmailUi.hrh" |
|
26 #include "FreestyleEmailUi.rsg" |
|
27 #include "FSHtmlReloadAO.h" |
|
28 |
|
29 #include <aknnotewrappers.h> |
|
30 #include <aknstyluspopupmenu.h> |
|
31 #include <brctldefs.h> |
|
32 #include <e32std.h> |
|
33 #include <eikmobs.h> |
|
34 #include <coemain.h> |
|
35 #include <schemehandler.h> |
|
36 |
|
37 EXPORT_C CFreestyleMessageHeaderURLEventHandler* CFreestyleMessageHeaderURLEventHandler::NewL( |
|
38 CFreestyleEmailUiAppUi& aAppUi, |
|
39 CFsEmailUiHtmlViewerView& aView ) |
|
40 { |
|
41 CFreestyleMessageHeaderURLEventHandler* obj = new (ELeave) CFreestyleMessageHeaderURLEventHandler( aAppUi, aView ); |
|
42 CleanupStack::PushL( obj ); |
|
43 obj->ConstructL(); |
|
44 CleanupStack::Pop( obj ); |
|
45 return obj; |
|
46 } |
|
47 |
|
48 CFreestyleMessageHeaderURLEventHandler::CFreestyleMessageHeaderURLEventHandler( |
|
49 CFreestyleEmailUiAppUi& aAppUi, |
|
50 CFsEmailUiHtmlViewerView& aView ) |
|
51 : iAppUi( aAppUi ), |
|
52 iView( aView ), |
|
53 iMailMessage( NULL ), |
|
54 iAttachmentsListModel( NULL ) |
|
55 { |
|
56 } |
|
57 |
|
58 void CFreestyleMessageHeaderURLEventHandler::ConstructL() |
|
59 { |
|
60 iMessageHeaderURL = CFreestyleMessageHeaderURL::NewL(); |
|
61 iHTMLReloadAO = CFSHtmlReloadAO::NewL(iView); |
|
62 |
|
63 } |
|
64 |
|
65 CFreestyleMessageHeaderURLEventHandler::~CFreestyleMessageHeaderURLEventHandler () |
|
66 { |
|
67 delete iMessageHeaderURL; |
|
68 delete iHTMLReloadAO; |
|
69 if( iEmailAddressStylusPopup ) |
|
70 { |
|
71 delete iEmailAddressStylusPopup; |
|
72 } |
|
73 |
|
74 if( iAttachmentStylusPopup ) |
|
75 { |
|
76 delete iAttachmentStylusPopup; |
|
77 } |
|
78 |
|
79 if( iWebAddressStylusPopup ) |
|
80 { |
|
81 delete iWebAddressStylusPopup; |
|
82 } |
|
83 |
|
84 delete iUrl; |
|
85 } |
|
86 |
|
87 EXPORT_C TBool CFreestyleMessageHeaderURLEventHandler::HandleEventL( const TDesC& aUri ) |
|
88 { |
|
89 iMailMessage = iView.CurrentMessage(); |
|
90 iAttachmentsListModel = iView.CurrentAttachmentsListModel(); |
|
91 |
|
92 if ( ! CFreestyleMessageHeaderURL::IsMessageHeaderURL( aUri ) ) |
|
93 { |
|
94 //Handle http and https links |
|
95 if( ( aUri.FindF( KURLHttpPrefix ) ) == 0 |
|
96 ||( aUri.FindF( KURLHttpsPrefix ) ) == 0 ) |
|
97 { |
|
98 if ( iUrl ) |
|
99 { |
|
100 delete iUrl; |
|
101 iUrl = NULL; |
|
102 } |
|
103 iUrl = aUri.AllocL(); |
|
104 LaunchWebAddressMenuL( ); |
|
105 return ETrue; |
|
106 } |
|
107 //Link wasn't handled |
|
108 return EFalse; |
|
109 } |
|
110 else |
|
111 { |
|
112 //URL is of the message header format, hence parse it |
|
113 iMessageHeaderURL->InternalizeL( aUri ); |
|
114 iMenuVisible = ETrue; |
|
115 if ( ( iMessageHeaderURL->Type()->CompareF( KURLTypeTo ) == 0 ) |
|
116 || ( iMessageHeaderURL->Type()->CompareF( KURLTypeFrom ) == 0 ) |
|
117 || ( iMessageHeaderURL->Type()->CompareF( KURLTypeCc ) == 0 ) ) |
|
118 { |
|
119 LaunchEmailAddressMenuL( ); |
|
120 } |
|
121 |
|
122 else if ( ( iMessageHeaderURL->Type()->CompareF( KURLTypeAttachment ) == 0 ) ) |
|
123 { |
|
124 LaunchAttachmentMenuL( FindAttachmentL( *iMessageHeaderURL ) ); |
|
125 } |
|
126 else if ( iMessageHeaderURL->Type()->CompareF( KURLTypeSubject ) ) |
|
127 { |
|
128 CSchemeHandler* handler = CSchemeHandler::NewL( aUri ); |
|
129 CleanupStack::PushL( handler ); |
|
130 handler->HandleUrlStandaloneL(); |
|
131 CleanupStack::PopAndDestroy( handler ); |
|
132 } |
|
133 iMenuVisible=EFalse; |
|
134 if( iPendingReload ) |
|
135 { |
|
136 //Load web page aysnchronously |
|
137 iHTMLReloadAO->ReloadPageAysnc(); |
|
138 iPendingReload=EFalse; |
|
139 } |
|
140 return ETrue; |
|
141 } |
|
142 } |
|
143 |
|
144 /* |
|
145 * Launches the avkon stylus popup and dims the inappropriate menu items and handles the user |
|
146 * menu item selection. |
|
147 * @param aType the type of the link the user selected |
|
148 */ |
|
149 void CFreestyleMessageHeaderURLEventHandler::LaunchEmailAddressMenuL() |
|
150 { |
|
151 if ( LaunchEmailAddressMenuHWKeyL() ) |
|
152 { |
|
153 return; |
|
154 } |
|
155 |
|
156 //Change the creation of the stylus menu here to avoid crash when calling SetItemDimmed(ETrue) multiple times |
|
157 //on same instance of the menu (if created only once in constructor). |
|
158 //Creating the menu everytime the user clicks on the link avoids this crash however performance is affected. |
|
159 if( iEmailAddressStylusPopup) |
|
160 { |
|
161 delete iEmailAddressStylusPopup; |
|
162 iEmailAddressStylusPopup = NULL; |
|
163 } |
|
164 |
|
165 TPoint point( 0, 0 ); |
|
166 iEmailAddressStylusPopup = CAknStylusPopUpMenu::NewL( this , point ); |
|
167 TResourceReader reader; |
|
168 CCoeEnv::Static()->CreateResourceReaderLC( reader, R_STYLUS_POPUP_MENU_HTML_VIEW_EMAIL_ADDRESS ); |
|
169 iEmailAddressStylusPopup->ConstructFromResourceL( reader ); |
|
170 CleanupStack::PopAndDestroy(); //resource reader |
|
171 |
|
172 iEmailAddressStylusPopup->SetItemDimmed( EFsEmailUiCmdActionsRemoteLookup, |
|
173 !iView.IsRemoteLookupSupportedL() ); |
|
174 iEmailAddressStylusPopup->SetPosition( iAppUi.LastSeenPointerPosition(), |
|
175 CAknStylusPopUpMenu::EPositionTypeRightBottom ); |
|
176 iEmailAddressStylusPopup->ShowMenu(); |
|
177 } |
|
178 |
|
179 |
|
180 TBool CFreestyleMessageHeaderURLEventHandler::LaunchEmailAddressMenuHWKeyL() |
|
181 { |
|
182 TInt wsEventType = iAppUi.LastSeenWsEventType(); |
|
183 if ( wsEventType != EEventKey ) |
|
184 { |
|
185 return EFalse; // only hw key event handled here |
|
186 } |
|
187 |
|
188 CFreestylePopupMenu* popup = CFreestylePopupMenu::NewL( R_STYLUS_POPUP_MENU_HTML_VIEW_EMAIL_ADDRESS ); |
|
189 CleanupStack::PushL( popup ); |
|
190 |
|
191 popup->SetDimmed( EFsEmailUiCmdActionsRemoteLookup, |
|
192 !iView.IsRemoteLookupSupportedL() ); |
|
193 |
|
194 TInt commandId = popup->LaunchPopupMenuL(); |
|
195 |
|
196 CleanupStack::PopAndDestroy( popup ); |
|
197 |
|
198 if ( commandId != KErrCancel ) |
|
199 { |
|
200 ProcessCommandL( commandId ); |
|
201 } |
|
202 |
|
203 return ETrue; |
|
204 } |
|
205 |
|
206 |
|
207 //From MEikMenuObserver |
|
208 void CFreestyleMessageHeaderURLEventHandler::ProcessCommandL( TInt aCommand ) |
|
209 { |
|
210 |
|
211 switch ( aCommand ) |
|
212 { |
|
213 case EFsEmailUiCmdActionsReply: |
|
214 case EFsEmailUiCmdActionsAddContact: |
|
215 case EFsEmailUiCmdActionsRemoteLookup: |
|
216 case EFsEmailUiCmdActionsCopyToClipboard: |
|
217 case EFsEmailUiCmdActionsContactDetails: |
|
218 { |
|
219 iView.HandleEmailAddressCommandL( aCommand, *iMessageHeaderURL->ItemId() ); |
|
220 break; |
|
221 } |
|
222 |
|
223 case EFsEmailUiCmdCancelDownload: |
|
224 { |
|
225 iView.CancelAttachmentL( FindAttachmentL( *iMessageHeaderURL ) ); |
|
226 break; |
|
227 } |
|
228 |
|
229 case EFsEmailUiCmdCancelAllDownloads: |
|
230 { |
|
231 iView.CancelAllAttachmentsL(); |
|
232 break; |
|
233 } |
|
234 |
|
235 case EFsEmailUiCmdOpenAttachment: |
|
236 { |
|
237 iView.OpenAttachmentL( FindAttachmentL( *iMessageHeaderURL ) ); |
|
238 break; |
|
239 } |
|
240 |
|
241 case EFsEmailUiCmdSave: |
|
242 { |
|
243 iView.SaveAttachmentL( FindAttachmentL( *iMessageHeaderURL ) ); |
|
244 break; |
|
245 } |
|
246 |
|
247 case EFsEmailUiCmdSaveAll: |
|
248 { |
|
249 iView.SaveAllAttachmentsL( ); |
|
250 break; |
|
251 } |
|
252 |
|
253 case EFsEmailUiCmdActionsOpenWeb: |
|
254 case EFsEmailUiCmdActionsAddBookmark: |
|
255 case EFsEmailUiCmdActionsCopyWWWAddressToClipboard: |
|
256 { |
|
257 iView.HandleWebAddressCommandL( aCommand, *iUrl ); |
|
258 break; |
|
259 } |
|
260 |
|
261 } |
|
262 } |
|
263 |
|
264 const TAttachmentData& CFreestyleMessageHeaderURLEventHandler::FindAttachmentL( |
|
265 const CFreestyleMessageHeaderURL& aAttachmentUrl ) |
|
266 { |
|
267 User::LeaveIfNull( iAttachmentsListModel ); |
|
268 TUint id; |
|
269 TLex parser( *aAttachmentUrl.ItemId() ); |
|
270 parser.Val( id ); |
|
271 |
|
272 TInt found = KErrNotFound; |
|
273 for (TInt i=0; i<iAttachmentsListModel->GetModel().Count(); i++) |
|
274 { |
|
275 if ( iAttachmentsListModel->GetModel()[i].partData.iMessagePartId.Id() == id ) |
|
276 { |
|
277 found = i; |
|
278 break; |
|
279 } |
|
280 } |
|
281 |
|
282 if ( found == KErrNotFound ) |
|
283 { |
|
284 // Probably, only the headers were downloaded. Check if attachments |
|
285 // were downloaded later. |
|
286 if( iMailMessage ) |
|
287 { |
|
288 iAttachmentsListModel->UpdateListL( iMailMessage ); |
|
289 } |
|
290 for (TInt i=0; i<iAttachmentsListModel->GetModel().Count(); i++) |
|
291 { |
|
292 if ( iAttachmentsListModel->GetModel()[i].partData.iMessagePartId.Id() == id ) |
|
293 { |
|
294 found = i; |
|
295 break; |
|
296 } |
|
297 } |
|
298 |
|
299 if ( found == KErrNotFound ) |
|
300 { |
|
301 User::Leave( KErrNotFound ); |
|
302 } |
|
303 } |
|
304 |
|
305 return iAttachmentsListModel->GetModel()[found]; |
|
306 } |
|
307 |
|
308 void CFreestyleMessageHeaderURLEventHandler::LaunchAttachmentMenuL( |
|
309 const TAttachmentData& aAttachment ) |
|
310 { |
|
311 ASSERT( iAppUi.DownloadInfoMediator() ); |
|
312 |
|
313 if ( LaunchAttachmentMenuHWKeyL( aAttachment ) ) |
|
314 { |
|
315 return; |
|
316 } |
|
317 |
|
318 |
|
319 //Change the creation of the stylus menu here to avoid crash when calling SetItemDimmed(ETrue) multiple times |
|
320 //on same instance of the menu (if created only once in constructor). |
|
321 //Creating the menu everytime the user clicks on the link avoids this crash however performance is affected. |
|
322 if( iAttachmentStylusPopup ) |
|
323 { |
|
324 delete iAttachmentStylusPopup; |
|
325 iAttachmentStylusPopup = NULL; |
|
326 } |
|
327 TPoint point( 0, 0 ); |
|
328 iAttachmentStylusPopup = CAknStylusPopUpMenu::NewL( this , point ); |
|
329 TResourceReader reader; |
|
330 CCoeEnv::Static()->CreateResourceReaderLC( reader, R_STYLUS_POPUP_MENU_HTML_VIEW_ATTACHMENT ); |
|
331 iAttachmentStylusPopup->ConstructFromResourceL( reader ); |
|
332 CleanupStack::PopAndDestroy(); //resource reader |
|
333 |
|
334 |
|
335 //Dim all item by default |
|
336 iAttachmentStylusPopup->SetItemDimmed( EFsEmailUiCmdOpenAttachment, ETrue ); |
|
337 iAttachmentStylusPopup->SetItemDimmed( EFsEmailUiCmdSave, ETrue ); |
|
338 iAttachmentStylusPopup->SetItemDimmed( EFsEmailUiCmdSaveAll, ETrue ); |
|
339 iAttachmentStylusPopup->SetItemDimmed( EFsEmailUiCmdCancelDownload, ETrue ); |
|
340 iAttachmentStylusPopup->SetItemDimmed( EFsEmailUiCmdCancelAllDownloads, ETrue ); |
|
341 |
|
342 const TBool isMessage( iAttachmentsListModel->IsMessage( aAttachment ) ); |
|
343 |
|
344 if ( iAppUi.DownloadInfoMediator()->IsDownloading( aAttachment.partData.iMessagePartId ) ) |
|
345 { |
|
346 iAttachmentStylusPopup->SetItemDimmed( EFsEmailUiCmdCancelDownload, EFalse ); |
|
347 } |
|
348 else if ( aAttachment.downloadProgress == KComplete ) |
|
349 { |
|
350 iAttachmentStylusPopup->SetItemDimmed( EFsEmailUiCmdOpenAttachment, EFalse ); |
|
351 |
|
352 // block saving of embedded messages if needed. |
|
353 if ( iView.IsEmbeddedMsgView() ) |
|
354 { |
|
355 if ( iView.IsEmbeddedMsgSavingAllowed() || !isMessage ) |
|
356 { |
|
357 iAttachmentStylusPopup->SetItemDimmed( EFsEmailUiCmdSave, EFalse ); |
|
358 } |
|
359 } |
|
360 else |
|
361 { |
|
362 iAttachmentStylusPopup->SetItemDimmed( EFsEmailUiCmdSave, isMessage && !iView.IsEmbeddedMsgSavingAllowed() ); |
|
363 } |
|
364 |
|
365 if ( iAttachmentsListModel->GetModel().Count() > 1 ) |
|
366 { |
|
367 // Save all cannot be shown if there is one message attachment and saving is not supported |
|
368 if ( !( iAttachmentsListModel->IsThereAnyMessageAttachments() && !iView.IsEmbeddedMsgSavingAllowed() ) ) |
|
369 { |
|
370 // In embedded message mode, save all needs to be blocked if there |
|
371 // are any message type attachments. This is due to limitations of Activesync plugin. |
|
372 if( !(iView.IsEmbeddedMsgView() && iAttachmentsListModel->IsThereAnyMessageAttachments()) ) |
|
373 { |
|
374 iAttachmentStylusPopup->SetItemDimmed( EFsEmailUiCmdSaveAll, EFalse ); |
|
375 } |
|
376 } |
|
377 } |
|
378 } |
|
379 else |
|
380 { |
|
381 iAttachmentStylusPopup->SetItemDimmed( EFsEmailUiCmdOpenAttachment, EFalse ); |
|
382 iAttachmentStylusPopup->SetItemDimmed( EFsEmailUiCmdSave, isMessage ); |
|
383 if ( iAttachmentsListModel->GetModel().Count() > 1 ) |
|
384 { |
|
385 iAttachmentStylusPopup->SetItemDimmed( EFsEmailUiCmdSaveAll, |
|
386 iAttachmentsListModel->IsThereAnyMessageAttachments() && !iView.IsEmbeddedMsgSavingAllowed() ); |
|
387 } |
|
388 } |
|
389 |
|
390 if ( iAttachmentsListModel->IsMultiplyDownloadsOngoing() ) |
|
391 { |
|
392 iAttachmentStylusPopup->SetItemDimmed( EFsEmailUiCmdCancelAllDownloads, EFalse ); |
|
393 } |
|
394 |
|
395 iAttachmentStylusPopup->SetPosition( iAppUi.LastSeenPointerPosition(), |
|
396 CAknStylusPopUpMenu::EPositionTypeRightBottom ); |
|
397 iAttachmentStylusPopup->ShowMenu(); |
|
398 } |
|
399 |
|
400 |
|
401 TBool CFreestyleMessageHeaderURLEventHandler::LaunchAttachmentMenuHWKeyL( |
|
402 const TAttachmentData& aAttachment ) |
|
403 { |
|
404 ASSERT( iAppUi.DownloadInfoMediator() ); |
|
405 |
|
406 TInt wsEventType = iAppUi.LastSeenWsEventType(); |
|
407 if ( wsEventType != EEventKey ) |
|
408 { |
|
409 return EFalse; // only hw key event handled here |
|
410 } |
|
411 |
|
412 CFreestylePopupMenu* popup = CFreestylePopupMenu::NewL( R_STYLUS_POPUP_MENU_HTML_VIEW_ATTACHMENT ); |
|
413 CleanupStack::PushL( popup ); |
|
414 |
|
415 //Dim all item by default |
|
416 popup->SetDimmed( EFsEmailUiCmdOpenAttachment, ETrue ); |
|
417 popup->SetDimmed( EFsEmailUiCmdSave, ETrue ); |
|
418 popup->SetDimmed( EFsEmailUiCmdSaveAll, ETrue ); |
|
419 popup->SetDimmed( EFsEmailUiCmdCancelDownload, ETrue ); |
|
420 popup->SetDimmed( EFsEmailUiCmdCancelAllDownloads, ETrue ); |
|
421 |
|
422 const TBool isMessage( iAttachmentsListModel->IsMessage( aAttachment ) ); |
|
423 |
|
424 if ( iAppUi.DownloadInfoMediator()->IsDownloading( aAttachment.partData.iMessagePartId ) ) |
|
425 { |
|
426 popup->SetDimmed( EFsEmailUiCmdCancelDownload, EFalse ); |
|
427 } |
|
428 else if ( aAttachment.downloadProgress == KComplete ) |
|
429 { |
|
430 popup->SetDimmed( EFsEmailUiCmdOpenAttachment, EFalse ); |
|
431 |
|
432 // block saving of embedded messages if needed. |
|
433 if ( iView.IsEmbeddedMsgView() ) |
|
434 { |
|
435 if ( iView.IsEmbeddedMsgSavingAllowed() || !isMessage ) |
|
436 { |
|
437 popup->SetDimmed( EFsEmailUiCmdSave, EFalse ); |
|
438 } |
|
439 } |
|
440 else |
|
441 { |
|
442 popup->SetDimmed( EFsEmailUiCmdSave, isMessage && !iView.IsEmbeddedMsgSavingAllowed() ); |
|
443 } |
|
444 |
|
445 if ( iAttachmentsListModel->GetModel().Count() > 1 ) |
|
446 { |
|
447 // Save all cannot be shown if there is one message attachment and saving is not supported |
|
448 if ( !( iAttachmentsListModel->IsThereAnyMessageAttachments() && !iView.IsEmbeddedMsgSavingAllowed() ) ) |
|
449 { |
|
450 // In embedded message mode, save all needs to be blocked if there |
|
451 // are any message type attachments. This is due to limitations of Activesync plugin. |
|
452 if( !(iView.IsEmbeddedMsgView() && iAttachmentsListModel->IsThereAnyMessageAttachments()) ) |
|
453 { |
|
454 popup->SetDimmed( EFsEmailUiCmdSaveAll, EFalse ); |
|
455 } |
|
456 } |
|
457 } |
|
458 } |
|
459 else |
|
460 { |
|
461 popup->SetDimmed( EFsEmailUiCmdOpenAttachment, EFalse ); |
|
462 popup->SetDimmed( EFsEmailUiCmdSave, isMessage ); |
|
463 if ( iAttachmentsListModel->GetModel().Count() > 1 ) |
|
464 { |
|
465 popup->SetDimmed( EFsEmailUiCmdSaveAll, |
|
466 iAttachmentsListModel->IsThereAnyMessageAttachments() && !iView.IsEmbeddedMsgSavingAllowed() ); |
|
467 } |
|
468 } |
|
469 |
|
470 if ( iAttachmentsListModel->IsMultiplyDownloadsOngoing() ) |
|
471 { |
|
472 popup->SetDimmed( EFsEmailUiCmdCancelAllDownloads, EFalse ); |
|
473 } |
|
474 |
|
475 TInt commandId = popup->LaunchPopupMenuL(); |
|
476 |
|
477 CleanupStack::PopAndDestroy( popup ); |
|
478 |
|
479 if ( commandId != KErrCancel ) |
|
480 { |
|
481 ProcessCommandL( commandId ); |
|
482 } |
|
483 |
|
484 return ETrue; |
|
485 } |
|
486 |
|
487 //Open the Avkon stylus popup when a web address link was pressed |
|
488 void CFreestyleMessageHeaderURLEventHandler::LaunchWebAddressMenuL() |
|
489 { |
|
490 if ( LaunchWebAddressMenuHWKeyL() ) |
|
491 { |
|
492 return; |
|
493 } |
|
494 |
|
495 //Change the creation of the stylus menu here to avoid crash when calling SetItemDimmed(ETrue) multiple times |
|
496 //on same instance of the menu (if created only once in constructor). |
|
497 //Creating the menu everytime the user clicks on the link avoids this crash however performance is affected. |
|
498 if( iWebAddressStylusPopup ) |
|
499 { |
|
500 delete iWebAddressStylusPopup; |
|
501 iWebAddressStylusPopup = NULL; |
|
502 } |
|
503 |
|
504 TPoint point( 0, 0 ); |
|
505 iWebAddressStylusPopup = CAknStylusPopUpMenu::NewL( this , point ); |
|
506 TResourceReader reader; |
|
507 CCoeEnv::Static()->CreateResourceReaderLC( reader, R_STYLUS_POPUP_MENU_HTML_VIEW_WEB_ADDRESS ); |
|
508 iWebAddressStylusPopup->ConstructFromResourceL( reader ); |
|
509 CleanupStack::PopAndDestroy(); //resource reader |
|
510 |
|
511 iWebAddressStylusPopup->SetPosition( iAppUi.LastSeenPointerPosition(), |
|
512 CAknStylusPopUpMenu::EPositionTypeRightBottom ); |
|
513 iWebAddressStylusPopup->ShowMenu(); |
|
514 } |
|
515 |
|
516 |
|
517 TBool CFreestyleMessageHeaderURLEventHandler::LaunchWebAddressMenuHWKeyL() |
|
518 { |
|
519 TInt wsEventType = iAppUi.LastSeenWsEventType(); |
|
520 if ( wsEventType != EEventKey ) |
|
521 { |
|
522 return EFalse; // only hw key event handled here |
|
523 } |
|
524 |
|
525 CFreestylePopupMenu* popup = CFreestylePopupMenu::NewL( R_STYLUS_POPUP_MENU_HTML_VIEW_WEB_ADDRESS ); |
|
526 CleanupStack::PushL( popup ); |
|
527 |
|
528 TInt commandId = popup->LaunchPopupMenuL(); |
|
529 |
|
530 CleanupStack::PopAndDestroy( popup ); |
|
531 |
|
532 if ( commandId != KErrCancel ) |
|
533 { |
|
534 ProcessCommandL( commandId ); |
|
535 } |
|
536 |
|
537 return ETrue; |
|
538 } |
|
539 |
|
540 |
|
541 //From MEikMenuObserver |
|
542 void CFreestyleMessageHeaderURLEventHandler::SetEmphasis(CCoeControl* /*aMenuControl*/,TBool /*aEmphasis*/) |
|
543 { |
|
544 } |
|
545 |
|
546 void CFreestyleMessageHeaderURLEventHandler::DismissMenuAndReload() |
|
547 { |
|
548 CFSEmailUiActionMenu::Dismiss(ETrue); |
|
549 iPendingReload=ETrue; |
|
550 } |
|
551 TBool CFreestyleMessageHeaderURLEventHandler::IsMenuVisible() |
|
552 { |
|
553 return iMenuVisible; |
|
554 } |
|
555 /****************************************************************************** |
|
556 * class CFreestylePopupMenu |
|
557 ******************************************************************************/ |
|
558 |
|
559 |
|
560 CFreestylePopupMenu* CFreestylePopupMenu::NewL( TInt aResourceId ) |
|
561 { |
|
562 CFreestylePopupMenu* self = new (ELeave) CFreestylePopupMenu( aResourceId ); |
|
563 CleanupStack::PushL( self ); |
|
564 self->ConstructL(); |
|
565 CleanupStack::Pop( self ); |
|
566 return self; |
|
567 } |
|
568 |
|
569 CFreestylePopupMenu::CFreestylePopupMenu( TInt aResourceId ) |
|
570 { |
|
571 iResourceId = aResourceId; |
|
572 } |
|
573 |
|
574 void CFreestylePopupMenu::ConstructL() |
|
575 { |
|
576 TResourceReader reader; |
|
577 CCoeEnv::Static()->CreateResourceReaderLC( reader, iResourceId ); |
|
578 |
|
579 ConstructFromResourceL( reader ); |
|
580 |
|
581 CleanupStack::PopAndDestroy(); // TResourceReader |
|
582 } |
|
583 |
|
584 CFreestylePopupMenu::~CFreestylePopupMenu() |
|
585 { |
|
586 iItemList.Close(); |
|
587 } |
|
588 |
|
589 TInt CFreestylePopupMenu::LaunchPopupMenuL() |
|
590 { |
|
591 TInt selectedOption = KErrNotFound; |
|
592 CDesCArrayFlat* arr = new (ELeave) CDesCArrayFlat( 5 ); |
|
593 CleanupStack::PushL( arr ); |
|
594 |
|
595 TInt count = iItemList.Count(); |
|
596 for ( TInt i=0; i<count; i++ ) |
|
597 { |
|
598 TPopupMenuItem& item = iItemList[i]; |
|
599 item.iListIndex = KErrNotFound; |
|
600 if ( !item.iDimmed ) |
|
601 { |
|
602 arr->AppendL( item.iText ); |
|
603 item.iListIndex = arr->MdcaCount() - 1; |
|
604 } |
|
605 } |
|
606 |
|
607 CAknListQueryDialog* dialog = new (ELeave) CAknListQueryDialog( &selectedOption ); |
|
608 dialog->PrepareLC( R_DRAFT_QUERY_DIALOG ); |
|
609 dialog->SetItemTextArray( arr ); |
|
610 dialog->SetOwnershipType( ELbmDoesNotOwnItemArray ); |
|
611 |
|
612 TInt ret = dialog->RunLD(); |
|
613 |
|
614 CleanupStack::PopAndDestroy( arr ); |
|
615 |
|
616 TInt commandId = KErrCancel; |
|
617 if ( ret ) |
|
618 { |
|
619 commandId = CommandIdFromListIndex( selectedOption ); |
|
620 } |
|
621 |
|
622 return commandId; |
|
623 } |
|
624 |
|
625 |
|
626 void CFreestylePopupMenu::SetDimmed( TInt aCommandId, TBool aDimmed ) |
|
627 { |
|
628 TInt count = iItemList.Count(); |
|
629 |
|
630 for ( TInt i=0; i<count; i++ ) |
|
631 { |
|
632 TPopupMenuItem& item = iItemList[i]; |
|
633 if ( item.iCommandId == aCommandId ) |
|
634 { |
|
635 item.iDimmed = aDimmed; |
|
636 break; |
|
637 } |
|
638 } |
|
639 } |
|
640 |
|
641 |
|
642 TInt CFreestylePopupMenu::CommandIdFromListIndex( TInt aListIndex ) |
|
643 { |
|
644 TInt ret = KErrCancel; |
|
645 |
|
646 TInt count = iItemList.Count(); |
|
647 |
|
648 for ( TInt i=0; i<count; i++ ) |
|
649 { |
|
650 TPopupMenuItem& item = iItemList[i]; |
|
651 if ( item.iListIndex == aListIndex ) |
|
652 { |
|
653 ret = item.iCommandId; |
|
654 break; |
|
655 } |
|
656 } |
|
657 |
|
658 return ret; |
|
659 } |
|
660 |
|
661 void CFreestylePopupMenu::ConstructFromResourceL( TResourceReader& aReader ) |
|
662 { |
|
663 TInt count = aReader.ReadInt16(); |
|
664 |
|
665 for ( TInt i=0; i<count; i++ ) |
|
666 { |
|
667 TPopupMenuItem item; |
|
668 |
|
669 TPtrC ptr = aReader.ReadTPtrC(); |
|
670 StrCopy( item.iText, ptr ); |
|
671 item.iCommandId = aReader.ReadInt32(); |
|
672 item.iDimmed = EFalse; |
|
673 item.iListIndex = KErrNotFound; |
|
674 iItemList.AppendL( item ); |
|
675 |
|
676 aReader.ReadInt32(); // extension link |
|
677 } |
|
678 } |
|
679 |
|
680 void CFreestylePopupMenu::StrCopy( TDes& aTarget, const TDesC& aSource ) |
|
681 { |
|
682 TInt len = aTarget.MaxLength(); |
|
683 if( len < aSource.Length() ) |
|
684 { |
|
685 aTarget.Copy( aSource.Left( len ) ); |
|
686 } |
|
687 else |
|
688 { |
|
689 aTarget.Copy( aSource ); |
|
690 } |
|
691 } |
|
692 |