meetingrequest/mrguicommon/src/cesmrcontactmenuurlhandler.cpp
branchRCL_3
changeset 12 4ce476e64c59
child 16 b5fbb9b25d57
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
       
     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     // TODO: correct to use XML layout
       
   205     NMRBitmapManager::GetSkinBasedBitmapLC( 
       
   206                     iconID, iconBitmap, iconMaskBitmap, TSize(20,20) );
       
   207     
       
   208     CGulIcon* icon = CGulIcon::NewL(iconBitmap, iconMaskBitmap);
       
   209     
       
   210     CleanupStack::Pop( 2 ); // iconBitmap, iconMaskBitmap
       
   211     
       
   212     return icon;
       
   213     }
       
   214 
       
   215 // ---------------------------------------------------------------------------
       
   216 // CESMRContactMenuUrlHandler::OptionsMenuAvailable( )
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 TBool CESMRContactMenuUrlHandler::OptionsMenuAvailable( )
       
   220     {
       
   221     FUNC_LOG;
       
   222     return iUrl != NULL;
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // CESMRContactMenuUrlHandler::InitOptionsMenuL
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void CESMRContactMenuUrlHandler::InitOptionsMenuL( 
       
   230 		CEikMenuPane* aActionMenuPane )
       
   231     {
       
   232     FUNC_LOG;
       
   233     CEikMenuPaneItem::SData data;
       
   234     data.iFlags = 0;
       
   235     data.iCascadeId = 0;
       
   236 
       
   237     //action menu is dynamic so commands are assigned dynamically here
       
   238     TInt command = EESMRCmdActionMenuFirst;
       
   239 
       
   240     data.iCommandId = command;
       
   241     command++;//dynamic command ids
       
   242     CCoeEnv::Static()->ReadResourceL( 
       
   243     		data.iText, R_QTN_MEET_REQ_VIEWER_OPTIONS_OPEN_IN_WEB );
       
   244     aActionMenuPane->AddMenuItemL( data );
       
   245 
       
   246     if(IsServiceAvailableL(R_INTRANET_AIW_INTEREST))
       
   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         {
       
   302         if( (aCommand == KUidOpenInIntranet.iUid) || (aCommand == command))
       
   303             {
       
   304             OpenUrlInIntranetL();
       
   305             }
       
   306         command++;//next item in the dynamic list
       
   307         }
       
   308 
       
   309     if( (aCommand == KUidBookmark.iUid) || (aCommand == command) )
       
   310         {
       
   311         BookmarkUrlL();
       
   312         }
       
   313     }
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 // CESMRContactMenuUrlHandler::ShowActionMenuL( )
       
   317 // ---------------------------------------------------------------------------
       
   318 //
       
   319 void CESMRContactMenuUrlHandler::ShowActionMenuL( )
       
   320     {
       
   321     FUNC_LOG;
       
   322     //reset
       
   323     iIconArray.ResetAndDestroy();
       
   324     iContactActionMenu.Model().RemoveAll();
       
   325 
       
   326     //fill list
       
   327     CreateMenuItemL( R_QTN_MEET_REQ_VIEWER_OPTIONS_OPEN_IN_WEB, 
       
   328 					 KUidOpenInBrowser);
       
   329 
       
   330     if(IsServiceAvailableL(R_INTRANET_AIW_INTEREST))
       
   331         {
       
   332         CreateMenuItemL( R_QTN_MEET_REQ_FSOPTIONS_OPEN_IN_INTRA, 
       
   333 						 KUidOpenInIntranet);
       
   334         }
       
   335 
       
   336     CreateMenuItemL(R_QTN_MEET_REQ_VIEWER_OPTIONS_BOOKMARK, KUidBookmark);
       
   337 
       
   338     //show list
       
   339     if ( iContactActionMenu.ExecuteL() == EFscCustomItemSelected )
       
   340         {
       
   341         TUid uid = iContactActionMenu.FocusedItem().ImplementationUid();
       
   342 
       
   343         //handle command
       
   344         ExecuteOptionsMenuL(uid.iUid);
       
   345         }
       
   346     }
       
   347 
       
   348 // ---------------------------------------------------------------------------
       
   349 // CESMRContactMenuUrlHandler::OpenUrlInBrowserL( )
       
   350 // ---------------------------------------------------------------------------
       
   351 //
       
   352 void CESMRContactMenuUrlHandler::OpenUrlInBrowserL( )
       
   353     {
       
   354     FUNC_LOG;
       
   355     HBufC* param = HBufC::NewLC( KFavouritesMaxUrl );
       
   356     param->Des().Copy( KBrowserProtocol() );
       
   357     param->Des().Append( *iUrl );
       
   358     TApaTaskList taskList(
       
   359             CEikonEnv::Static()->WsSession() ); // codescanner::eikonenvstatic
       
   360     TApaTask task = taskList.FindApp( KUidBrowser );
       
   361     if ( task.Exists() )
       
   362         {
       
   363         HBufC8* param8 = HBufC8::NewLC( param->Length() );
       
   364         param8->Des().Append( *param );
       
   365         task.SendMessage( TUid::Uid ( 0 ), *param8 ); // Uid is not used
       
   366         CleanupStack::PopAndDestroy( param8 );
       
   367         }
       
   368     else
       
   369         {
       
   370         RApaLsSession appArcSession;
       
   371         CleanupClosePushL( appArcSession );
       
   372         // connect to AppArc server
       
   373         User::LeaveIfError( appArcSession.Connect() ); 
       
   374         TThreadId id;
       
   375         User::LeaveIfError( appArcSession.StartDocument ( 
       
   376         		*param, KUidBrowser, id ) );
       
   377         CleanupStack::PopAndDestroy( &appArcSession );
       
   378         }
       
   379     CleanupStack::PopAndDestroy( param );
       
   380     }
       
   381 
       
   382 // ---------------------------------------------------------------------------
       
   383 // CESMRContactMenuUrlHandler::OpenUrlInIntranetL( )
       
   384 // ---------------------------------------------------------------------------
       
   385 //
       
   386 void CESMRContactMenuUrlHandler::OpenUrlInIntranetL( )
       
   387     {
       
   388     FUNC_LOG;
       
   389     HBufC8* eightBitUrl = HBufC8::NewLC( iUrl->Length() );
       
   390     eightBitUrl->Des().Copy( *iUrl );
       
   391 
       
   392     TAiwGenericParam inParam(EGenericParamURL, TAiwVariant(*eightBitUrl));
       
   393     CAiwGenericParamList& inParamList = ServiceHandlerL().InParamListL();
       
   394     inParamList.AppendL( inParam );
       
   395 
       
   396     ServiceHandlerL().ExecuteServiceCmdL( 
       
   397 							KAiwCmdView, 
       
   398 							inParamList, 
       
   399 							ServiceHandlerL().OutParamListL() );
       
   400     CleanupStack::PopAndDestroy( eightBitUrl );
       
   401     }
       
   402 
       
   403 // ---------------------------------------------------------------------------
       
   404 // CESMRContactMenuUrlHandler::BookmarkUrlL( )
       
   405 // ---------------------------------------------------------------------------
       
   406 //
       
   407 void CESMRContactMenuUrlHandler::BookmarkUrlL( )
       
   408     {
       
   409     FUNC_LOG;
       
   410     // Create an item
       
   411     CFavouritesItem* item = CFavouritesItem::NewLC();
       
   412     item->SetParentFolder( KFavouritesRootUid );
       
   413     item->SetType( CFavouritesItem::EItem );
       
   414 
       
   415     // Read default name from resources
       
   416     HBufC* defaultName =CCoeEnv::Static()->AllocReadResourceLC ( 
       
   417 									R_QTN_CALENDAR_DEFAULT_BOOKMARK );
       
   418 
       
   419     TBuf<KMaxBookmarkNameLength> retName;
       
   420     retName.Copy( defaultName->Des() );
       
   421 
       
   422     // Query bookmark name from user
       
   423     CAknTextQueryDialog* dlg = CAknTextQueryDialog::NewL( retName );
       
   424     dlg->SetMaxLength( KMaxBookmarkNameLength );
       
   425     if ( !dlg->ExecuteLD( R_ADD_BOOKMARK_QUERY_DIALOG ) )
       
   426         {
       
   427         // User press cancel - do not add bookmark
       
   428         CleanupStack::PopAndDestroy ( 2, item ); // item, defaultName
       
   429         }
       
   430     else
       
   431     	{
       
   432     	item->SetNameL( retName );
       
   433 		item->SetUrlL( *iUrl );
       
   434 
       
   435 		RFavouritesSession sess; // codescanner::resourcenotoncleanupstack
       
   436 		RFavouritesDb db; // codescanner::resourcenotoncleanupstack
       
   437 
       
   438 		User::LeaveIfError( sess.Connect() );
       
   439 		CleanupClosePushL<RFavouritesSession> ( sess );
       
   440 		User::LeaveIfError( db.Open( sess, KBrowserBookmarks ) );
       
   441 		CleanupClosePushL<RFavouritesDb> ( db );
       
   442 
       
   443 		// add item
       
   444 		db.Add( *item, ETrue );
       
   445 		// Close the database.
       
   446 		db.Close();
       
   447 
       
   448 		HBufC * msgBuffer = CCoeEnv::Static()->AllocReadResourceLC( 
       
   449 										R_QTN_CALENDAR_BOOKMARK_SAVED );
       
   450 		CAknConfirmationNote* note = new(ELeave)CAknConfirmationNote( ETrue );
       
   451 		note->ExecuteLD ( *msgBuffer );
       
   452 
       
   453 		// item, db, sess, defaultName, msgBuffer
       
   454 		CleanupStack::PopAndDestroy ( 5, item ); // codescanner::magicnumbers
       
   455     	}
       
   456     }
       
   457 
       
   458 // ---------------------------------------------------------------------------
       
   459 // CESMRContactMenuUrlHandler::ServiceHandlerL
       
   460 // ---------------------------------------------------------------------------
       
   461 //
       
   462 CAiwServiceHandler& CESMRContactMenuUrlHandler::ServiceHandlerL()
       
   463     {
       
   464     FUNC_LOG;
       
   465     if ( !iServiceHandler )
       
   466         {
       
   467         iServiceHandler = CAiwServiceHandler::NewL();
       
   468         iServiceHandler->AttachL( R_INTRANET_AIW_INTEREST );
       
   469         }
       
   470     return *iServiceHandler;
       
   471     }
       
   472 // End of file
       
   473