|
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 |
|
27 #include <aknnotewrappers.h> |
|
28 #include <BrCtlDefs.h> |
|
29 #include <e32std.h> |
|
30 |
|
31 EXPORT_C CFreestyleMessageHeaderURLEventHandler* CFreestyleMessageHeaderURLEventHandler::NewL( |
|
32 CFreestyleEmailUiAppUi& aAppUi, |
|
33 CFsEmailUiHtmlViewerView& aView ) |
|
34 { |
|
35 CFreestyleMessageHeaderURLEventHandler* obj = new (ELeave) CFreestyleMessageHeaderURLEventHandler( aAppUi, aView ); |
|
36 CleanupStack::PushL( obj ); |
|
37 obj->ConstructL(); |
|
38 CleanupStack::Pop( obj ); |
|
39 return obj; |
|
40 } |
|
41 |
|
42 CFreestyleMessageHeaderURLEventHandler::CFreestyleMessageHeaderURLEventHandler( |
|
43 CFreestyleEmailUiAppUi& aAppUi, |
|
44 CFsEmailUiHtmlViewerView& aView ) |
|
45 : iAppUi( aAppUi ), |
|
46 iView( aView ), |
|
47 iMailMessage( NULL ), |
|
48 iAttachmentsListModel( NULL ) |
|
49 { |
|
50 } |
|
51 |
|
52 void CFreestyleMessageHeaderURLEventHandler::ConstructL() |
|
53 { |
|
54 iMessageHeaderURL = CFreestyleMessageHeaderURL::NewL(); |
|
55 } |
|
56 |
|
57 CFreestyleMessageHeaderURLEventHandler::~CFreestyleMessageHeaderURLEventHandler () |
|
58 { |
|
59 delete iMessageHeaderURL; |
|
60 } |
|
61 |
|
62 EXPORT_C TBool CFreestyleMessageHeaderURLEventHandler::HandleEventL( const TDesC& aUri ) |
|
63 { |
|
64 iMailMessage = iView.CurrentMessage(); |
|
65 iAttachmentsListModel = iView.CurrentAttachmentsListModel(); |
|
66 |
|
67 if ( ! CFreestyleMessageHeaderURL::IsMessageHeaderURL( aUri ) ) |
|
68 { |
|
69 return EFalse; |
|
70 } |
|
71 else |
|
72 { |
|
73 //URL is of the message header format, hence parse it |
|
74 iMessageHeaderURL->InternalizeL( aUri ); |
|
75 |
|
76 if ( ( iMessageHeaderURL->Type()->CompareF( KURLTypeTo ) == 0 ) |
|
77 || ( iMessageHeaderURL->Type()->CompareF( KURLTypeFrom ) == 0 ) |
|
78 || ( iMessageHeaderURL->Type()->CompareF( KURLTypeCc ) == 0 ) ) |
|
79 { |
|
80 LaunchEmailAddressMenuL( *iMessageHeaderURL ); |
|
81 } |
|
82 |
|
83 else if ( ( iMessageHeaderURL->Type()->CompareF( KURLTypeAttachment ) == 0 ) ) |
|
84 { |
|
85 LaunchAttachmentMenuL( FindAttachmentL( *iMessageHeaderURL ) ); |
|
86 } |
|
87 |
|
88 return ETrue; |
|
89 } |
|
90 } |
|
91 |
|
92 /* |
|
93 * Launches the menu and populates it with the appropriate menu items and handles the user |
|
94 * menu item selection. |
|
95 * @param aType the type of the link the user selected |
|
96 */ |
|
97 void CFreestyleMessageHeaderURLEventHandler::LaunchEmailAddressMenuL( |
|
98 const CFreestyleMessageHeaderURL& iMessageHeaderURL ) |
|
99 { |
|
100 CFSEmailUiActionMenu::RemoveAllL(); |
|
101 |
|
102 RArray<TActionMenuCustomItemId> uids; |
|
103 CleanupClosePushL( uids ); |
|
104 uids.Append( FsEActionMenuCall ); |
|
105 uids.Append( FsEActionMenuCreateMessage ); |
|
106 uids.Append( FsEActionMenuCreateEmail ); |
|
107 uids.Append( FsEActionMenuContactDetails ); |
|
108 uids.Append( FsEActionMenuAddToContacts ); |
|
109 |
|
110 if ( iView.IsRemoteLookupSupportedL() ) |
|
111 { |
|
112 uids.Append( FsEActionMenuRemoteLookup ); |
|
113 } |
|
114 |
|
115 |
|
116 for ( TInt i = 0; i < uids.Count(); i++ ) |
|
117 { |
|
118 CFSEmailUiActionMenu::AddCustomItemL( uids[i] ); ///here is where you add stuff |
|
119 } |
|
120 |
|
121 CleanupStack::PopAndDestroy( &uids ); |
|
122 TActionMenuCustomItemId menuResult = CFSEmailUiActionMenu::ExecuteL( EFscCenter ); |
|
123 |
|
124 if ( menuResult != FsEActionMenuCasItemSelectedAndExecuted && |
|
125 menuResult != FsEActionMenuDismissed ) |
|
126 { |
|
127 HandleEmailAddressActionMenuCommandL( menuResult, iMessageHeaderURL ); |
|
128 } |
|
129 } |
|
130 |
|
131 void CFreestyleMessageHeaderURLEventHandler::HandleEmailAddressActionMenuCommandL( |
|
132 TActionMenuCustomItemId aSelectedActionMenuItem, |
|
133 const CFreestyleMessageHeaderURL& iMessageHeaderURL ) |
|
134 { |
|
135 TInt command( 0 ); |
|
136 |
|
137 switch ( aSelectedActionMenuItem ) |
|
138 { |
|
139 case FsEActionMenuCreateEmail: // Create message |
|
140 { |
|
141 command = EFsEmailUiCmdActionsReply; |
|
142 } |
|
143 break; |
|
144 case FsEActionMenuAddToContacts: // Add to Contacts |
|
145 { |
|
146 command = FsEActionMenuAddToContacts; |
|
147 } |
|
148 break; |
|
149 case FsEActionMenuCall: // Call |
|
150 { |
|
151 command = EFsEmailUiCmdActionsCall; |
|
152 } |
|
153 break; |
|
154 case FsEActionMenuCreateMessage: // Create message |
|
155 { |
|
156 command = EFsEmailUiCmdActionsCreateMessage; |
|
157 } |
|
158 break; |
|
159 case FsEActionMenuContactDetails: // Contact details |
|
160 { |
|
161 command = EFsEmailUiCmdActionsContactDetails; |
|
162 } |
|
163 break; |
|
164 case FsEActionMenuRemoteLookup: // Remote lookup |
|
165 { |
|
166 command = EFsEmailUiCmdActionsRemoteLookup; |
|
167 } |
|
168 break; |
|
169 } |
|
170 |
|
171 iView.HandleEmailAddressCommandL( command, *iMessageHeaderURL.ItemId() ); |
|
172 } |
|
173 |
|
174 const TAttachmentData& CFreestyleMessageHeaderURLEventHandler::FindAttachmentL( |
|
175 const CFreestyleMessageHeaderURL& aAttachmentUrl ) |
|
176 { |
|
177 User::LeaveIfNull( iAttachmentsListModel ); |
|
178 TUint id; |
|
179 TLex parser( *aAttachmentUrl.ItemId() ); |
|
180 parser.Val( id ); |
|
181 |
|
182 TInt found = KErrNotFound; |
|
183 for (TInt i=0; i<iAttachmentsListModel->GetModel().Count(); i++) |
|
184 { |
|
185 if ( iAttachmentsListModel->GetModel()[i].partData.iMessagePartId.Id() == id ) |
|
186 { |
|
187 found = i; |
|
188 break; |
|
189 } |
|
190 } |
|
191 |
|
192 if ( found == KErrNotFound ) |
|
193 { |
|
194 User::Leave( KErrNotFound ); |
|
195 } |
|
196 |
|
197 return iAttachmentsListModel->GetModel()[found]; |
|
198 } |
|
199 |
|
200 void CFreestyleMessageHeaderURLEventHandler::LaunchAttachmentMenuL( |
|
201 const TAttachmentData& aAttachment ) |
|
202 { |
|
203 ASSERT( iAppUi.DownloadInfoMediator() ); |
|
204 CFSEmailUiActionMenu::RemoveAllL(); |
|
205 |
|
206 if ( iAppUi.DownloadInfoMediator()->IsDownloading( aAttachment.partData.iMessagePartId ) ) |
|
207 { |
|
208 CFSEmailUiActionMenu::AddCustomItemL( FsEActionAttachmentCancelDownload ); |
|
209 } |
|
210 else if ( aAttachment.downloadProgress == KComplete ) |
|
211 { |
|
212 CFSEmailUiActionMenu::AddCustomItemL( FsEActionAttachmentOpen ); |
|
213 |
|
214 // block saving of embedded messages if needed. |
|
215 if ( iView.IsEmbeddedMsgView() ) |
|
216 { |
|
217 if ( iView.IsEmbeddedMsgSavingAllowed() || !iAttachmentsListModel->IsMessage( aAttachment ) ) |
|
218 { |
|
219 CFSEmailUiActionMenu::AddCustomItemL( FsEActionAttachmentSave ); |
|
220 } |
|
221 |
|
222 } |
|
223 else |
|
224 { |
|
225 CFSEmailUiActionMenu::AddCustomItemL( FsEActionAttachmentSave ); |
|
226 } |
|
227 |
|
228 if ( iAttachmentsListModel->GetModel().Count() > 1 ) |
|
229 { |
|
230 // In embedded message mode, save all needs to be blocked if there |
|
231 // are any message type attachments. This is due to limitations of Activesync plugin. |
|
232 if( !(iView.IsEmbeddedMsgView() && iAttachmentsListModel->IsThereAnyMessageAttachments()) ) |
|
233 { |
|
234 CFSEmailUiActionMenu::AddCustomItemL( FsEActionAttachmentSaveAll ); |
|
235 } |
|
236 |
|
237 } |
|
238 } |
|
239 else |
|
240 { |
|
241 CFSEmailUiActionMenu::AddCustomItemL( FsEActionAttachmentOpen ); |
|
242 CFSEmailUiActionMenu::AddCustomItemL( FsEActionAttachmentSave ); |
|
243 if ( iAttachmentsListModel->GetModel().Count() > 1 ) |
|
244 { |
|
245 CFSEmailUiActionMenu::AddCustomItemL( FsEActionAttachmentSaveAll ); |
|
246 } |
|
247 } |
|
248 |
|
249 TActionMenuCustomItemId menuResult = CFSEmailUiActionMenu::ExecuteL( EFscCenter ); |
|
250 |
|
251 if ( menuResult != FsEActionMenuCasItemSelectedAndExecuted && |
|
252 menuResult != FsEActionMenuDismissed ) |
|
253 { |
|
254 HandAttachmentActionMenuCommandL( menuResult, aAttachment ); |
|
255 } |
|
256 } |
|
257 |
|
258 void CFreestyleMessageHeaderURLEventHandler::HandAttachmentActionMenuCommandL( |
|
259 TActionMenuCustomItemId aSelectedActionMenuItem, |
|
260 const TAttachmentData& aAttachment ) |
|
261 { |
|
262 switch ( aSelectedActionMenuItem ) |
|
263 { |
|
264 case FsEActionAttachmentCancelDownload: |
|
265 iView.CancelAttachmentL( aAttachment ); |
|
266 break; |
|
267 |
|
268 case FsEActionAttachmentOpen: |
|
269 iView.OpenAttachmentL( aAttachment ); |
|
270 break; |
|
271 |
|
272 case FsEActionAttachmentSave: |
|
273 iView.SaveAttachmentL( aAttachment ); |
|
274 break; |
|
275 |
|
276 case FsEActionAttachmentSaveAll: |
|
277 iView.SaveAllAttachmentsL(); |
|
278 break; |
|
279 |
|
280 case FsEActionAttachmentClearFetchedContent: |
|
281 iView.RemoveAttachmentContentL( aAttachment ); |
|
282 break; |
|
283 |
|
284 case FsEActionAttachmentDownload: |
|
285 iView.DownloadAttachmentL( aAttachment ); |
|
286 break; |
|
287 |
|
288 case FsEActionAttachmentDownloadAll: |
|
289 iView.DownloadAllAttachmentsL(); |
|
290 break; |
|
291 |
|
292 case FsEActionAttachmentViewAll: |
|
293 iView.OpenAttachmentsListViewL(); |
|
294 break; |
|
295 } |
|
296 } |
|
297 |
|
298 |