|
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 #include <e32cmn.h> |
|
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 NMRBitmapManager::GetSkinBasedBitmapLC( |
|
205 iconID, iconBitmap, iconMaskBitmap, TSize(20,20) ); |
|
206 |
|
207 CGulIcon* icon = CGulIcon::NewL(iconBitmap, iconMaskBitmap); |
|
208 |
|
209 CleanupStack::Pop( 2 ); // iconBitmap, iconMaskBitmap |
|
210 |
|
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 { |
|
247 data.iCommandId = command; |
|
248 command++;//dynamic command ids |
|
249 CCoeEnv::Static()->ReadResourceL( |
|
250 data.iText, R_QTN_MEET_REQ_FSOPTIONS_OPEN_IN_INTRA ); |
|
251 aActionMenuPane->AddMenuItemL( data ); |
|
252 } |
|
253 |
|
254 data.iCommandId = command; |
|
255 CCoeEnv::Static()->ReadResourceL( |
|
256 data.iText, R_QTN_MEET_REQ_VIEWER_OPTIONS_BOOKMARK ); |
|
257 aActionMenuPane->AddMenuItemL( data ); |
|
258 } |
|
259 |
|
260 // --------------------------------------------------------------------------- |
|
261 // CESMRContactMenuUrlHandler::IsServiceAvailableL |
|
262 // --------------------------------------------------------------------------- |
|
263 // |
|
264 TBool CESMRContactMenuUrlHandler::IsServiceAvailableL(TInt aResourceId) |
|
265 { |
|
266 FUNC_LOG; |
|
267 //read resource and check if that service is available |
|
268 TResourceReader reader; |
|
269 CCoeEnv::Static()->CreateResourceReaderLC( reader, aResourceId ); |
|
270 // Read first the count of the Criteria Items in resource. |
|
271 // After this the reader is in correct position at the start |
|
272 // of the first criteria. |
|
273 const TInt count = reader.ReadInt16(); |
|
274 CAiwCriteriaItem* criteriaItem = CAiwCriteriaItem::NewLC(); |
|
275 criteriaItem->ReadFromResoureL( reader ); |
|
276 TInt serviceAvailable = ServiceHandlerL().NbrOfProviders(criteriaItem); |
|
277 CleanupStack::PopAndDestroy( criteriaItem ); |
|
278 // destroy -> resource reader |
|
279 CleanupStack::PopAndDestroy( ); // codescanner::cleanup |
|
280 return serviceAvailable; |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------------------------- |
|
284 // CESMRContactMenuUrlHandler::ExecuteOptionsMenuL |
|
285 // --------------------------------------------------------------------------- |
|
286 // |
|
287 void CESMRContactMenuUrlHandler::ExecuteOptionsMenuL( TInt aCommand ) |
|
288 { |
|
289 FUNC_LOG; |
|
290 TInt command = EESMRCmdActionMenuFirst; |
|
291 |
|
292 if( (aCommand == KUidOpenInBrowser.iUid) || (aCommand == command) ) |
|
293 { |
|
294 OpenUrlInBrowserL(); |
|
295 return; |
|
296 } |
|
297 command++;//next item in the dynamic list |
|
298 |
|
299 if(IsServiceAvailableL(R_INTRANET_AIW_INTEREST)) |
|
300 { |
|
301 if( (aCommand == KUidOpenInIntranet.iUid) || (aCommand == command)) |
|
302 { |
|
303 OpenUrlInIntranetL(); |
|
304 } |
|
305 command++;//next item in the dynamic list |
|
306 } |
|
307 |
|
308 if( (aCommand == KUidBookmark.iUid) || (aCommand == command) ) |
|
309 { |
|
310 BookmarkUrlL(); |
|
311 } |
|
312 } |
|
313 |
|
314 // --------------------------------------------------------------------------- |
|
315 // CESMRContactMenuUrlHandler::ShowActionMenuL( ) |
|
316 // --------------------------------------------------------------------------- |
|
317 // |
|
318 void CESMRContactMenuUrlHandler::ShowActionMenuL( ) |
|
319 { |
|
320 FUNC_LOG; |
|
321 //reset |
|
322 iIconArray.ResetAndDestroy(); |
|
323 iContactActionMenu.Model().RemoveAll(); |
|
324 |
|
325 //fill list |
|
326 CreateMenuItemL( R_QTN_MEET_REQ_VIEWER_OPTIONS_OPEN_IN_WEB, |
|
327 KUidOpenInBrowser); |
|
328 |
|
329 if(IsServiceAvailableL(R_INTRANET_AIW_INTEREST)) |
|
330 { |
|
331 CreateMenuItemL( R_QTN_MEET_REQ_FSOPTIONS_OPEN_IN_INTRA, |
|
332 KUidOpenInIntranet); |
|
333 } |
|
334 |
|
335 CreateMenuItemL(R_QTN_MEET_REQ_VIEWER_OPTIONS_BOOKMARK, KUidBookmark); |
|
336 |
|
337 //show list |
|
338 if ( iContactActionMenu.ExecuteL() == EFscCustomItemSelected ) |
|
339 { |
|
340 TUid uid = iContactActionMenu.FocusedItem().ImplementationUid(); |
|
341 |
|
342 //handle command |
|
343 ExecuteOptionsMenuL(uid.iUid); |
|
344 } |
|
345 } |
|
346 |
|
347 // --------------------------------------------------------------------------- |
|
348 // CESMRContactMenuUrlHandler::OpenUrlInBrowserL( ) |
|
349 // --------------------------------------------------------------------------- |
|
350 // |
|
351 void CESMRContactMenuUrlHandler::OpenUrlInBrowserL( ) |
|
352 { |
|
353 FUNC_LOG; |
|
354 HBufC* param = HBufC::NewLC( KFavouritesMaxUrl ); |
|
355 param->Des().Copy( KBrowserProtocol() ); |
|
356 param->Des().Append( *iUrl ); |
|
357 TApaTaskList taskList( |
|
358 CEikonEnv::Static()->WsSession() ); // codescanner::eikonenvstatic |
|
359 TApaTask task = taskList.FindApp( KUidBrowser ); |
|
360 if ( task.Exists() ) |
|
361 { |
|
362 HBufC8* param8 = HBufC8::NewLC( param->Length() ); |
|
363 param8->Des().Append( *param ); |
|
364 task.SendMessage( TUid::Uid ( 0 ), *param8 ); // Uid is not used |
|
365 CleanupStack::PopAndDestroy( param8 ); |
|
366 } |
|
367 else |
|
368 { |
|
369 RApaLsSession appArcSession; |
|
370 CleanupClosePushL( appArcSession ); |
|
371 // connect to AppArc server |
|
372 User::LeaveIfError( appArcSession.Connect() ); |
|
373 TThreadId id; |
|
374 User::LeaveIfError( appArcSession.StartDocument ( |
|
375 *param, KUidBrowser, id ) ); |
|
376 CleanupStack::PopAndDestroy( &appArcSession ); |
|
377 } |
|
378 CleanupStack::PopAndDestroy( param ); |
|
379 } |
|
380 |
|
381 // --------------------------------------------------------------------------- |
|
382 // CESMRContactMenuUrlHandler::OpenUrlInIntranetL( ) |
|
383 // --------------------------------------------------------------------------- |
|
384 // |
|
385 void CESMRContactMenuUrlHandler::OpenUrlInIntranetL( ) |
|
386 { |
|
387 FUNC_LOG; |
|
388 HBufC8* eightBitUrl = HBufC8::NewLC( iUrl->Length() ); |
|
389 eightBitUrl->Des().Copy( *iUrl ); |
|
390 |
|
391 TAiwGenericParam inParam(EGenericParamURL, TAiwVariant(*eightBitUrl)); |
|
392 CAiwGenericParamList& inParamList = ServiceHandlerL().InParamListL(); |
|
393 inParamList.AppendL( inParam ); |
|
394 |
|
395 ServiceHandlerL().ExecuteServiceCmdL( |
|
396 KAiwCmdView, |
|
397 inParamList, |
|
398 ServiceHandlerL().OutParamListL() ); |
|
399 CleanupStack::PopAndDestroy( eightBitUrl ); |
|
400 } |
|
401 |
|
402 // --------------------------------------------------------------------------- |
|
403 // CESMRContactMenuUrlHandler::BookmarkUrlL( ) |
|
404 // --------------------------------------------------------------------------- |
|
405 // |
|
406 void CESMRContactMenuUrlHandler::BookmarkUrlL( ) |
|
407 { |
|
408 FUNC_LOG; |
|
409 // Create an item |
|
410 CFavouritesItem* item = CFavouritesItem::NewLC(); |
|
411 item->SetParentFolder( KFavouritesRootUid ); |
|
412 item->SetType( CFavouritesItem::EItem ); |
|
413 |
|
414 // Read default name from resources |
|
415 HBufC* defaultName =CCoeEnv::Static()->AllocReadResourceLC ( |
|
416 R_QTN_CALENDAR_DEFAULT_BOOKMARK ); |
|
417 |
|
418 TBuf<KMaxBookmarkNameLength> retName; |
|
419 retName.Copy( defaultName->Des() ); |
|
420 |
|
421 // Query bookmark name from user |
|
422 CAknTextQueryDialog* dlg = CAknTextQueryDialog::NewL( retName ); |
|
423 dlg->SetMaxLength( KMaxBookmarkNameLength ); |
|
424 if ( !dlg->ExecuteLD( R_ADD_BOOKMARK_QUERY_DIALOG ) ) |
|
425 { |
|
426 // User press cancel - do not add bookmark |
|
427 CleanupStack::PopAndDestroy ( 2, item ); // item, defaultName |
|
428 } |
|
429 else |
|
430 { |
|
431 item->SetNameL( retName ); |
|
432 item->SetUrlL( *iUrl ); |
|
433 |
|
434 RFavouritesSession sess; // codescanner::resourcenotoncleanupstack |
|
435 RFavouritesDb db; // codescanner::resourcenotoncleanupstack |
|
436 |
|
437 User::LeaveIfError( sess.Connect() ); |
|
438 CleanupClosePushL<RFavouritesSession> ( sess ); |
|
439 User::LeaveIfError( db.Open( sess, KBrowserBookmarks ) ); |
|
440 CleanupClosePushL<RFavouritesDb> ( db ); |
|
441 |
|
442 // add item |
|
443 db.Add( *item, ETrue ); |
|
444 // Close the database. |
|
445 db.Close(); |
|
446 |
|
447 HBufC * msgBuffer = CCoeEnv::Static()->AllocReadResourceLC( |
|
448 R_QTN_CALENDAR_BOOKMARK_SAVED ); |
|
449 CAknConfirmationNote* note = new(ELeave)CAknConfirmationNote( ETrue ); |
|
450 note->ExecuteLD ( *msgBuffer ); |
|
451 |
|
452 // item, db, sess, defaultName, msgBuffer |
|
453 CleanupStack::PopAndDestroy ( 5, item ); // codescanner::magicnumbers |
|
454 } |
|
455 } |
|
456 |
|
457 // --------------------------------------------------------------------------- |
|
458 // CESMRContactMenuUrlHandler::ServiceHandlerL |
|
459 // --------------------------------------------------------------------------- |
|
460 // |
|
461 CAiwServiceHandler& CESMRContactMenuUrlHandler::ServiceHandlerL() |
|
462 { |
|
463 FUNC_LOG; |
|
464 if ( !iServiceHandler ) |
|
465 { |
|
466 iServiceHandler = CAiwServiceHandler::NewL(); |
|
467 iServiceHandler->AttachL( R_INTRANET_AIW_INTEREST ); |
|
468 } |
|
469 return *iServiceHandler; |
|
470 } |
|
471 // End of file |
|
472 |