|
1 /* |
|
2 * Copyright (c) 2008-2009 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: Implementation of class CESMRContactMenuUrlHandler. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cesmrcontactmenuurlhandler.h" |
|
20 #include "esmrhelper.h" |
|
21 #include "cesmriconfield.h" |
|
22 #include "nmrbitmapmanager.h" |
|
23 //<cmail> |
|
24 #include "cfsccontactactionmenu.h" |
|
25 #include "cfsccontactactionmenuitem.h" |
|
26 #include "mfsccontactaction.h" |
|
27 #include "mfsccontactactionmenumodel.h" |
|
28 #include "esmrcommands.h" |
|
29 #include <esmrgui.rsg> |
|
30 //</cmail> |
|
31 #include <eikmenup.h> |
|
32 #include <coemain.h> |
|
33 #include <gulicon.h> |
|
34 #include <AknsUtils.h> |
|
35 #include <FavouritesDb.h> |
|
36 #include <apgtask.h> |
|
37 #include <apgcli.h> |
|
38 #include <AknQueryDialog.h> |
|
39 #include <aknnotewrappers.h> |
|
40 // for intranet application opening |
|
41 #include <AiwServiceHandler.h> |
|
42 #include <data_caging_path_literals.hrh> |
|
43 |
|
44 |
|
45 // DEBUG |
|
46 #include "emailtrace.h" |
|
47 |
|
48 /// Unnamed namespace for local definitions |
|
49 namespace // codescanner::namespace |
|
50 { |
|
51 // URL actionmenu uids |
|
52 const TUid KUidOpenInBrowser = |
|
53 { |
|
54 1 |
|
55 }; |
|
56 |
|
57 const TUid KUidOpenInIntranet = |
|
58 { |
|
59 2 |
|
60 }; |
|
61 |
|
62 const TUid KUidBookmark = |
|
63 { |
|
64 3 // codescanner::magicnumbers |
|
65 }; |
|
66 |
|
67 // Browser app uid |
|
68 const TUid KUidBrowser = |
|
69 { |
|
70 0x10008D39 |
|
71 }; |
|
72 |
|
73 // Maximum length of Browser bookmark |
|
74 const TInt KMaxBookmarkNameLength = 50; |
|
75 // Browser protocol |
|
76 // 4 is number used for opening the browser |
|
77 _LIT( KBrowserProtocol, "4 " ); |
|
78 |
|
79 }//namespace |
|
80 |
|
81 // ======== MEMBER FUNCTIONS ======== |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // CESMRContactMenuUrlHandler::CESMRContactMenuUrlHandler |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 CESMRContactMenuUrlHandler::CESMRContactMenuUrlHandler( |
|
88 CFscContactActionMenu& aContactActionMenu ) : |
|
89 iContactActionMenu( aContactActionMenu ) |
|
90 { |
|
91 FUNC_LOG; |
|
92 // Do nothing |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // CESMRContactMenuUrlHandler::NewL |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 CESMRContactMenuUrlHandler* CESMRContactMenuUrlHandler::NewL( |
|
100 CFscContactActionMenu& aContactActionMenu ) |
|
101 { |
|
102 FUNC_LOG; |
|
103 CESMRContactMenuUrlHandler* self = |
|
104 new (ELeave) CESMRContactMenuUrlHandler( aContactActionMenu ); |
|
105 return self; |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // CESMRContactMenuUrlHandler::~CESMRContactMenuUrlHandler( ) |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 CESMRContactMenuUrlHandler::~CESMRContactMenuUrlHandler( ) |
|
113 { |
|
114 FUNC_LOG; |
|
115 delete iUrl; |
|
116 delete iServiceHandler; |
|
117 iIconArray.ResetAndDestroy(); |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // CESMRContactMenuUrlHandler::Reset( ) |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 void CESMRContactMenuUrlHandler::Reset( ) |
|
125 { |
|
126 FUNC_LOG; |
|
127 delete iUrl; |
|
128 iUrl = NULL; |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // CESMRContactMenuUrlHandler::SetUrlL |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 void CESMRContactMenuUrlHandler::SetUrlL( const TDesC& aUrl ) |
|
136 { |
|
137 FUNC_LOG; |
|
138 HBufC* temp = aUrl.AllocL(); |
|
139 delete iUrl; |
|
140 iUrl = temp; |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // CESMRContactMenuUrlHandler::CreateMenuItemL |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 void CESMRContactMenuUrlHandler::CreateMenuItemL( |
|
148 TInt aResourceId, |
|
149 TUid aCommandUid ) |
|
150 { |
|
151 FUNC_LOG; |
|
152 CGulIcon* itemIcon = CreateIconL(aCommandUid); |
|
153 //ownership transferred |
|
154 CleanupStack::PushL( itemIcon ); |
|
155 iIconArray.AppendL( itemIcon ); |
|
156 CleanupStack::Pop( itemIcon ); |
|
157 |
|
158 HBufC* text = CCoeEnv::Static()->AllocReadResourceLC( aResourceId ); |
|
159 CFscContactActionMenuItem* newItem = |
|
160 iContactActionMenu.Model().NewMenuItemL( *text, |
|
161 itemIcon, |
|
162 1, |
|
163 EFalse, |
|
164 aCommandUid ); |
|
165 |
|
166 CleanupStack::PopAndDestroy( text ); |
|
167 CleanupStack::PushL( newItem ); |
|
168 iContactActionMenu.Model().AddItemL( newItem ); |
|
169 CleanupStack::Pop( newItem ); |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // CESMRContactMenuUrlHandler::CreateActionMenuIconL |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 CGulIcon* CESMRContactMenuUrlHandler::CreateIconL(TUid aCommandUid) |
|
177 { |
|
178 FUNC_LOG; |
|
179 // Define default icon object |
|
180 CFbsBitmap* iconBitmap( NULL ); |
|
181 CFbsBitmap* iconMaskBitmap( NULL ); |
|
182 NMRBitmapManager::TMRBitmapId iconID( NMRBitmapManager::EMRBitmapNotSet ); |
|
183 |
|
184 //select correct icon for item |
|
185 if( aCommandUid == KUidOpenInBrowser ) |
|
186 { |
|
187 //<cmail> icon is not available in Cmail |
|
188 iconID = NMRBitmapManager::EMRBitmapBrowser; |
|
189 //</cmail> |
|
190 } |
|
191 else if( aCommandUid == KUidOpenInIntranet) |
|
192 { |
|
193 //<cmail> icon is not available in Cmail |
|
194 iconID = NMRBitmapManager::EMRBitmapIntranet; |
|
195 //</cmail> |
|
196 } |
|
197 else |
|
198 { |
|
199 //<cmail> icon is not available in Cmail |
|
200 iconID = NMRBitmapManager::EMRBitmapBookmark; |
|
201 //</cmail> |
|
202 } |
|
203 |
|
204 User::LeaveIfError( |
|
205 NMRBitmapManager::GetSkinBasedBitmap( |
|
206 iconID, iconBitmap, iconMaskBitmap, KIconSize ) ); |
|
207 |
|
208 CGulIcon* icon = CGulIcon::NewL(iconBitmap, iconMaskBitmap); |
|
209 return icon; |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // CESMRContactMenuUrlHandler::OptionsMenuAvailable( ) |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 TBool CESMRContactMenuUrlHandler::OptionsMenuAvailable( ) |
|
217 { |
|
218 FUNC_LOG; |
|
219 return iUrl != NULL; |
|
220 } |
|
221 |
|
222 // --------------------------------------------------------------------------- |
|
223 // CESMRContactMenuUrlHandler::InitOptionsMenuL |
|
224 // --------------------------------------------------------------------------- |
|
225 // |
|
226 void CESMRContactMenuUrlHandler::InitOptionsMenuL( |
|
227 CEikMenuPane* aActionMenuPane ) |
|
228 { |
|
229 FUNC_LOG; |
|
230 CEikMenuPaneItem::SData data; |
|
231 data.iFlags = 0; |
|
232 data.iCascadeId = 0; |
|
233 |
|
234 //action menu is dynamic so commands are assigned dynamically here |
|
235 TInt command = EESMRCmdActionMenuFirst; |
|
236 |
|
237 data.iCommandId = command; |
|
238 command++;//dynamic command ids |
|
239 CCoeEnv::Static()->ReadResourceL( |
|
240 data.iText, R_QTN_MEET_REQ_VIEWER_OPTIONS_OPEN_IN_WEB ); |
|
241 aActionMenuPane->AddMenuItemL( data ); |
|
242 |
|
243 if(IsServiceAvailableL(R_INTRANET_AIW_INTEREST)) |
|
244 { |
|
245 data.iCommandId = command; |
|
246 command++;//dynamic command ids |
|
247 CCoeEnv::Static()->ReadResourceL( |
|
248 data.iText, R_QTN_MEET_REQ_FSOPTIONS_OPEN_IN_INTRA ); |
|
249 aActionMenuPane->AddMenuItemL( data ); |
|
250 } |
|
251 |
|
252 data.iCommandId = command; |
|
253 CCoeEnv::Static()->ReadResourceL( |
|
254 data.iText, R_QTN_MEET_REQ_VIEWER_OPTIONS_BOOKMARK ); |
|
255 aActionMenuPane->AddMenuItemL( data ); |
|
256 } |
|
257 |
|
258 // --------------------------------------------------------------------------- |
|
259 // CESMRContactMenuUrlHandler::IsServiceAvailableL |
|
260 // --------------------------------------------------------------------------- |
|
261 // |
|
262 TBool CESMRContactMenuUrlHandler::IsServiceAvailableL(TInt aResourceId) |
|
263 { |
|
264 FUNC_LOG; |
|
265 //read resource and check if that service is available |
|
266 TResourceReader reader; |
|
267 CCoeEnv::Static()->CreateResourceReaderLC( reader, aResourceId ); |
|
268 // Read first the count of the Criteria Items in resource. |
|
269 // After this the reader is in correct position at the start |
|
270 // of the first criteria. |
|
271 const TInt count = reader.ReadInt16(); |
|
272 CAiwCriteriaItem* criteriaItem = CAiwCriteriaItem::NewLC(); |
|
273 criteriaItem->ReadFromResoureL( reader ); |
|
274 TInt serviceAvailable = ServiceHandlerL().NbrOfProviders(criteriaItem); |
|
275 CleanupStack::PopAndDestroy( criteriaItem ); |
|
276 // destroy -> resource reader |
|
277 CleanupStack::PopAndDestroy( ); // codescanner::cleanup |
|
278 return serviceAvailable; |
|
279 } |
|
280 |
|
281 // --------------------------------------------------------------------------- |
|
282 // CESMRContactMenuUrlHandler::ExecuteOptionsMenuL |
|
283 // --------------------------------------------------------------------------- |
|
284 // |
|
285 void CESMRContactMenuUrlHandler::ExecuteOptionsMenuL( TInt aCommand ) |
|
286 { |
|
287 FUNC_LOG; |
|
288 TInt command = EESMRCmdActionMenuFirst; |
|
289 |
|
290 if( (aCommand == KUidOpenInBrowser.iUid) || (aCommand == command) ) |
|
291 { |
|
292 OpenUrlInBrowserL(); |
|
293 return; |
|
294 } |
|
295 command++;//next item in the dynamic list |
|
296 |
|
297 if(IsServiceAvailableL(R_INTRANET_AIW_INTEREST)) |
|
298 { |
|
299 if( (aCommand == KUidOpenInIntranet.iUid) || (aCommand == command)) |
|
300 { |
|
301 OpenUrlInIntranetL(); |
|
302 } |
|
303 command++;//next item in the dynamic list |
|
304 } |
|
305 |
|
306 if( (aCommand == KUidBookmark.iUid) || (aCommand == command) ) |
|
307 { |
|
308 BookmarkUrlL(); |
|
309 } |
|
310 } |
|
311 |
|
312 // --------------------------------------------------------------------------- |
|
313 // CESMRContactMenuUrlHandler::ShowActionMenuL( ) |
|
314 // --------------------------------------------------------------------------- |
|
315 // |
|
316 void CESMRContactMenuUrlHandler::ShowActionMenuL( ) |
|
317 { |
|
318 FUNC_LOG; |
|
319 //reset |
|
320 iIconArray.ResetAndDestroy(); |
|
321 iContactActionMenu.Model().RemoveAll(); |
|
322 |
|
323 //fill list |
|
324 CreateMenuItemL( R_QTN_MEET_REQ_VIEWER_OPTIONS_OPEN_IN_WEB, |
|
325 KUidOpenInBrowser); |
|
326 |
|
327 if(IsServiceAvailableL(R_INTRANET_AIW_INTEREST)) |
|
328 { |
|
329 CreateMenuItemL( R_QTN_MEET_REQ_FSOPTIONS_OPEN_IN_INTRA, |
|
330 KUidOpenInIntranet); |
|
331 } |
|
332 |
|
333 CreateMenuItemL(R_QTN_MEET_REQ_VIEWER_OPTIONS_BOOKMARK, KUidBookmark); |
|
334 |
|
335 //show list |
|
336 if ( iContactActionMenu.ExecuteL() == EFscCustomItemSelected ) |
|
337 { |
|
338 TUid uid = iContactActionMenu.FocusedItem().ImplementationUid(); |
|
339 |
|
340 //handle command |
|
341 ExecuteOptionsMenuL(uid.iUid); |
|
342 } |
|
343 } |
|
344 |
|
345 // --------------------------------------------------------------------------- |
|
346 // CESMRContactMenuUrlHandler::OpenUrlInBrowserL( ) |
|
347 // --------------------------------------------------------------------------- |
|
348 // |
|
349 void CESMRContactMenuUrlHandler::OpenUrlInBrowserL( ) |
|
350 { |
|
351 FUNC_LOG; |
|
352 HBufC* param = HBufC::NewLC( KFavouritesMaxUrl ); |
|
353 param->Des().Copy( KBrowserProtocol() ); |
|
354 param->Des().Append( *iUrl ); |
|
355 TApaTaskList taskList( |
|
356 CEikonEnv::Static()->WsSession() ); // codescanner::eikonenvstatic |
|
357 TApaTask task = taskList.FindApp( KUidBrowser ); |
|
358 if ( task.Exists() ) |
|
359 { |
|
360 HBufC8* param8 = HBufC8::NewLC( param->Length() ); |
|
361 param8->Des().Append( *param ); |
|
362 task.SendMessage( TUid::Uid ( 0 ), *param8 ); // Uid is not used |
|
363 CleanupStack::PopAndDestroy( param8 ); |
|
364 } |
|
365 else |
|
366 { |
|
367 RApaLsSession appArcSession; |
|
368 CleanupClosePushL( appArcSession ); |
|
369 // connect to AppArc server |
|
370 User::LeaveIfError( appArcSession.Connect() ); |
|
371 TThreadId id; |
|
372 User::LeaveIfError( appArcSession.StartDocument ( |
|
373 *param, KUidBrowser, id ) ); |
|
374 CleanupStack::PopAndDestroy( &appArcSession ); |
|
375 } |
|
376 CleanupStack::PopAndDestroy( param ); |
|
377 } |
|
378 |
|
379 // --------------------------------------------------------------------------- |
|
380 // CESMRContactMenuUrlHandler::OpenUrlInIntranetL( ) |
|
381 // --------------------------------------------------------------------------- |
|
382 // |
|
383 void CESMRContactMenuUrlHandler::OpenUrlInIntranetL( ) |
|
384 { |
|
385 FUNC_LOG; |
|
386 HBufC8* eightBitUrl = HBufC8::NewLC( iUrl->Length() ); |
|
387 eightBitUrl->Des().Copy( *iUrl ); |
|
388 |
|
389 TAiwGenericParam inParam(EGenericParamURL, TAiwVariant(*eightBitUrl)); |
|
390 CAiwGenericParamList& inParamList = ServiceHandlerL().InParamListL(); |
|
391 inParamList.AppendL( inParam ); |
|
392 |
|
393 ServiceHandlerL().ExecuteServiceCmdL( |
|
394 KAiwCmdView, |
|
395 inParamList, |
|
396 ServiceHandlerL().OutParamListL() ); |
|
397 CleanupStack::PopAndDestroy( eightBitUrl ); |
|
398 } |
|
399 |
|
400 // --------------------------------------------------------------------------- |
|
401 // CESMRContactMenuUrlHandler::BookmarkUrlL( ) |
|
402 // --------------------------------------------------------------------------- |
|
403 // |
|
404 void CESMRContactMenuUrlHandler::BookmarkUrlL( ) |
|
405 { |
|
406 FUNC_LOG; |
|
407 // Create an item |
|
408 CFavouritesItem* item = CFavouritesItem::NewLC(); |
|
409 item->SetParentFolder( KFavouritesRootUid ); |
|
410 item->SetType( CFavouritesItem::EItem ); |
|
411 |
|
412 // Read default name from resources |
|
413 HBufC* defaultName =CCoeEnv::Static()->AllocReadResourceLC ( |
|
414 R_QTN_CALENDAR_DEFAULT_BOOKMARK ); |
|
415 |
|
416 TBuf<KMaxBookmarkNameLength> retName; |
|
417 retName.Copy( defaultName->Des() ); |
|
418 |
|
419 // Query bookmark name from user |
|
420 CAknTextQueryDialog* dlg = CAknTextQueryDialog::NewL( retName ); |
|
421 dlg->SetMaxLength( KMaxBookmarkNameLength ); |
|
422 if ( !dlg->ExecuteLD( R_ADD_BOOKMARK_QUERY_DIALOG ) ) |
|
423 { |
|
424 // User press cancel - do not add bookmark |
|
425 CleanupStack::PopAndDestroy ( 2, item ); // item, defaultName |
|
426 } |
|
427 else |
|
428 { |
|
429 item->SetNameL( retName ); |
|
430 item->SetUrlL( *iUrl ); |
|
431 |
|
432 RFavouritesSession sess; // codescanner::resourcenotoncleanupstack |
|
433 RFavouritesDb db; // codescanner::resourcenotoncleanupstack |
|
434 |
|
435 User::LeaveIfError( sess.Connect() ); |
|
436 CleanupClosePushL<RFavouritesSession> ( sess ); |
|
437 User::LeaveIfError( db.Open( sess, KBrowserBookmarks ) ); |
|
438 CleanupClosePushL<RFavouritesDb> ( db ); |
|
439 |
|
440 // add item |
|
441 db.Add( *item, ETrue ); |
|
442 // Close the database. |
|
443 db.Close(); |
|
444 |
|
445 HBufC * msgBuffer = CCoeEnv::Static()->AllocReadResourceLC( |
|
446 R_QTN_CALENDAR_BOOKMARK_SAVED ); |
|
447 CAknConfirmationNote* note = new(ELeave)CAknConfirmationNote( ETrue ); |
|
448 note->ExecuteLD ( *msgBuffer ); |
|
449 |
|
450 // item, db, sess, defaultName, msgBuffer |
|
451 CleanupStack::PopAndDestroy ( 5, item ); // codescanner::magicnumbers |
|
452 } |
|
453 } |
|
454 |
|
455 // --------------------------------------------------------------------------- |
|
456 // CESMRContactMenuUrlHandler::ServiceHandlerL |
|
457 // --------------------------------------------------------------------------- |
|
458 // |
|
459 CAiwServiceHandler& CESMRContactMenuUrlHandler::ServiceHandlerL() |
|
460 { |
|
461 FUNC_LOG; |
|
462 if ( !iServiceHandler ) |
|
463 { |
|
464 iServiceHandler = CAiwServiceHandler::NewL(); |
|
465 iServiceHandler->AttachL( R_INTRANET_AIW_INTEREST ); |
|
466 } |
|
467 return *iServiceHandler; |
|
468 } |
|
469 // End of file |
|
470 |