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