meetingrequest/mrgui/src/cesmrcontactmenuattachmenthandler.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 11 0396474f30f5
child 13 8592a65ad3fb
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
     1 /*
       
     2 * Copyright (c) 2007-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:  Creates and display action menu.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cesmrcontactmenuattachmenthandler.h"
       
    20 #include "cesmrconfirmationquery.h"
       
    21 
       
    22 #include "cfsccontactactionmenu.h"
       
    23 #include "fsccontactactionmenuuids.hrh"
       
    24 #include "cfsccontactactionmenuitem.h" 
       
    25 #include "tfsccontactactionmenuconstructparameters.h"
       
    26 #include "mfsccontactactionmenumodel.h"
       
    27 #include "cesmrattachmentinfo.h"
       
    28 #include "esmrhelper.h"
       
    29 #include "cesmriconfield.h"
       
    30 #include "nmrbitmapmanager.h"
       
    31 #include "cfsccontactactionservice.h"
       
    32 #include "esmrcommands.h"
       
    33 #include <CVPbkContactManager.h>
       
    34 #include <CVPbkContactStoreUriArray.h>
       
    35 #include <VPbkContactStoreUris.h>
       
    36 #include <MVPbkContactStoreList.h>
       
    37 #include <TVPbkContactStoreUriPtr.h>
       
    38 #include <esmrgui.rsg>
       
    39 #include <data_caging_path_literals.hrh>
       
    40 #include <AknsUtils.h>
       
    41 #include <eikmenup.h>
       
    42 #include <gulicon.h>
       
    43 // DEBUG
       
    44 #include "emailtrace.h"
       
    45 
       
    46 /// Unnamed namespace for local definitions
       
    47 namespace {
       
    48 
       
    49 // MR contains one attachment
       
    50 const TInt KOneAttachment( 1 );
       
    51 
       
    52 // Attachment actions menu uids
       
    53 static const TUid KOpenAttachmentViewUid = { 1 };
       
    54 static const TUid KOpenAttachmentUid = { 2 };
       
    55 static const TUid KDownloadAttachmentUid = { 3 };
       
    56 static const TUid KDownloadAllAttachmentsUid = { 4 };
       
    57 static const TUid KSaveAttachmentUid = { 5 };
       
    58 static const TUid KSaveAllAttachmentsUid = { 6 };
       
    59 
       
    60 }  // namespace
       
    61 
       
    62 // ======== MEMBER FUNCTIONS ========
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // C++ default constructor.
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CESMRContactMenuAttachmentHandler::CESMRContactMenuAttachmentHandler(
       
    69         CFscContactActionMenu& aContactActionMenu ) :
       
    70         iContactActionMenu( aContactActionMenu )
       
    71     {
       
    72     FUNC_LOG;
       
    73     // Do nothing
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // Symbian two phased constructor that does not leave a pointer to the cleanup
       
    78 // stack.
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 CESMRContactMenuAttachmentHandler* CESMRContactMenuAttachmentHandler::NewL(
       
    82         CFscContactActionMenu& aContactActionMenu )
       
    83     {
       
    84     FUNC_LOG;
       
    85     CESMRContactMenuAttachmentHandler* self = 
       
    86 		new (ELeave) CESMRContactMenuAttachmentHandler( aContactActionMenu );
       
    87     CleanupStack::PushL( self );
       
    88     self->ConstructL();
       
    89     CleanupStack::Pop( self );
       
    90     return self;
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // Symbian 2nd phase constructor.
       
    95 // Creates the action menu object.
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 void CESMRContactMenuAttachmentHandler::ConstructL()
       
    99     {
       
   100     FUNC_LOG;
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // Destructor.
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 CESMRContactMenuAttachmentHandler::~CESMRContactMenuAttachmentHandler()
       
   108     {
       
   109     FUNC_LOG;
       
   110     iIconArray.ResetAndDestroy();
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // CESMRContactMenuAttachmentHandler::Reset( )
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CESMRContactMenuAttachmentHandler::Reset( )
       
   118     {
       
   119     FUNC_LOG;
       
   120     iOptionsMenuAvailable = EFalse;
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // CESMRContactMenuAttachmentHandler::SetAttachmentInfo( )
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 void CESMRContactMenuAttachmentHandler::SetAttachmentInfo( 
       
   128         CESMRAttachmentInfo* aAttachmentInfo )
       
   129     {
       
   130     iAttachmentInfo = aAttachmentInfo;
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CESMRContactMenuAttachmentHandler::InitActionMenuL
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 void CESMRContactMenuAttachmentHandler::InitActionMenuL( )
       
   138     {
       
   139     FUNC_LOG;
       
   140 
       
   141     if ( iAttachmentInfo )
       
   142         {
       
   143         iOptionsMenuAvailable = ETrue;
       
   144         
       
   145         MFscContactActionMenuModel& actionMenuModel = iContactActionMenu.Model();
       
   146 
       
   147         TInt attachmentCount( iAttachmentInfo->AttachmentCount() );
       
   148         
       
   149         if( attachmentCount > KOneAttachment )
       
   150         	{
       
   151         	CreateMenuItemL( R_QTN_MEET_REQ_VIEWER_ACTION_ATTACH_VIEW_LIST,
       
   152                 KOpenAttachmentViewUid );
       
   153                 
       
   154             // go through the list to see if we need to download 
       
   155             // some attachment
       
   156             TBool needDownload(EFalse);
       
   157             
       
   158             for( TInt ii = attachmentCount-1; ii >= 0 && !needDownload; --ii )
       
   159                 {
       
   160                 const CESMRAttachment& attachment( 
       
   161                     iAttachmentInfo->AttachmentL( ii ) );
       
   162                     
       
   163                 needDownload = attachment.AttachmenState() != 
       
   164                     CESMRAttachment::EAttachmentStateDownloaded;
       
   165                 }
       
   166             
       
   167             // download all command    
       
   168             if( needDownload )
       
   169                 {
       
   170                 CreateMenuItemL( R_QTN_MEET_REQ_VIEWER_ACTION_ATTACH_DOWNLOAD_ALL,
       
   171                     KDownloadAllAttachmentsUid );
       
   172                 }
       
   173             
       
   174             // save all command    
       
   175             CreateMenuItemL( R_QTN_MEET_REQ_VIEWER_ACTION_ATTACH_SAVE_ALL,
       
   176                 KSaveAllAttachmentsUid );
       
   177         	}
       
   178        	else
       
   179        		{
       
   180             // There is one attachment
       
   181             const CESMRAttachment& attachment(
       
   182                     iAttachmentInfo->AttachmentL( 0 ) );
       
   183        		
       
   184        		// open or download command
       
   185        		if( attachment.AttachmenState() == CESMRAttachment::EAttachmentStateDownloaded )
       
   186        			{
       
   187                 CreateMenuItemL( R_QTN_MEET_REQ_VIEWER_ACTION_ATTACH_OPEN,
       
   188                     KOpenAttachmentUid );
       
   189        			}
       
   190        		else
       
   191        			{
       
   192                 CreateMenuItemL( R_QTN_MEET_REQ_VIEWER_ACTION_ATTACH_DOWNLOAD,
       
   193                     KDownloadAttachmentUid );
       
   194        			}
       
   195        		
       
   196        		// save command   		
       
   197             CreateMenuItemL( R_QTN_MEET_REQ_VIEWER_ACTION_ATTACH_SAVE,
       
   198                 KSaveAttachmentUid );
       
   199        		}       		
       
   200         }
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CESMRContactMenuAttachmentHandler::CreateMenuItemL
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 void CESMRContactMenuAttachmentHandler::CreateMenuItemL( 
       
   208 		TInt aResourceId, 
       
   209 		TUid aCommandUid )
       
   210     {
       
   211     FUNC_LOG;
       
   212     CGulIcon* itemIcon = CreateIconL(aCommandUid);
       
   213     //ownership transferred
       
   214     CleanupStack::PushL( itemIcon );
       
   215     iIconArray.AppendL( itemIcon );
       
   216     CleanupStack::Pop( itemIcon );
       
   217 
       
   218     HBufC* text = CCoeEnv::Static()->AllocReadResourceLC( aResourceId );
       
   219     CFscContactActionMenuItem* newItem = 
       
   220 		iContactActionMenu.Model().NewMenuItemL( *text,
       
   221 												 itemIcon,
       
   222                                                  1,
       
   223                                                  EFalse,
       
   224                                                  aCommandUid );
       
   225 
       
   226     CleanupStack::PopAndDestroy( text );
       
   227     CleanupStack::PushL( newItem );
       
   228     iContactActionMenu.Model().AddItemL( newItem );
       
   229     CleanupStack::Pop( newItem );
       
   230     }
       
   231 
       
   232 // ---------------------------------------------------------------------------
       
   233 // CESMRContactMenuAttachmentHandler::CreateIconL
       
   234 // ---------------------------------------------------------------------------
       
   235 //
       
   236 CGulIcon* CESMRContactMenuAttachmentHandler::CreateIconL(TUid aCommandUid)
       
   237     {
       
   238     FUNC_LOG;
       
   239     // Define default icon object
       
   240     CFbsBitmap* iconBitmap( NULL );
       
   241     CFbsBitmap* iconMaskBitmap( NULL );
       
   242     NMRBitmapManager::TMRBitmapId iconID( NMRBitmapManager::EMRBitmapNotSet );
       
   243 
       
   244     //select correct icon for item
       
   245     if( aCommandUid == KOpenAttachmentViewUid )
       
   246         {
       
   247         iconID = NMRBitmapManager::EMRBitmapOpenAttachmentView;
       
   248         }
       
   249     else if ( aCommandUid ==KOpenAttachmentUid )
       
   250         {
       
   251         iconID = NMRBitmapManager::EMRBitmapOpenAttachment;
       
   252         }
       
   253     else if( aCommandUid == KDownloadAttachmentUid )
       
   254         {
       
   255         iconID = NMRBitmapManager::EMRBitmapDownloadAttachment;
       
   256         }
       
   257     else if( aCommandUid == KDownloadAllAttachmentsUid )
       
   258         {
       
   259         iconID = NMRBitmapManager::EMRBitmapDownloadAllAttachments;
       
   260         }
       
   261     else if( aCommandUid == KSaveAttachmentUid )
       
   262         {
       
   263         iconID = NMRBitmapManager::EMRBitmapSaveAttachment;
       
   264         }
       
   265     else if( aCommandUid == KSaveAllAttachmentsUid )
       
   266         {
       
   267         iconID = NMRBitmapManager::EMRBitmapSaveAllAttachments;
       
   268         }
       
   269 
       
   270     User::LeaveIfError( 
       
   271             NMRBitmapManager::GetSkinBasedBitmap( 
       
   272                     iconID, iconBitmap, iconMaskBitmap, KIconSize ) );
       
   273     
       
   274     CGulIcon* icon = CGulIcon::NewL( iconBitmap, iconMaskBitmap );
       
   275     return icon;
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // CESMRContactMenuAttachmentHandler::OptionsMenuAvailable( )
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 TBool CESMRContactMenuAttachmentHandler::OptionsMenuAvailable( )
       
   283     {
       
   284     FUNC_LOG;
       
   285     return iOptionsMenuAvailable;
       
   286     }
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // CESMRContactMenuAttachmentHandler::InitOptionsMenuL
       
   290 // ---------------------------------------------------------------------------
       
   291 //
       
   292 void CESMRContactMenuAttachmentHandler::InitOptionsMenuL( 
       
   293 		CEikMenuPane* aActionMenuPane )
       
   294     {
       
   295     FUNC_LOG;
       
   296 
       
   297     if ( iAttachmentInfo )
       
   298         {
       
   299         iOptionsMenuAvailable = ETrue;
       
   300 
       
   301         CEikMenuPaneItem::SData data;
       
   302 
       
   303         TInt attachmentCount( iAttachmentInfo->AttachmentCount() );
       
   304         
       
   305         CCoeEnv* coeEnv = CCoeEnv::Static();
       
   306         
       
   307         if( attachmentCount > KOneAttachment )
       
   308         	{
       
   309         	// command to open download manager
       
   310             data.iFlags = 0;
       
   311             data.iCascadeId = 0;
       
   312             data.iCommandId = EESMRCmdOpenAttachmentView;
       
   313 
       
   314             TRAP_IGNORE( coeEnv->ReadResourceL( 
       
   315                 	data.iText, R_QTN_MEET_REQ_VIEWER_OPTIONS_ATTACH_VIEW_LIST ) );
       
   316             aActionMenuPane->AddMenuItemL( data );
       
   317             
       
   318             // go through the list to see if we need to download 
       
   319             // some attachment
       
   320             TBool needDownload(EFalse);
       
   321             
       
   322             for( TInt ii = attachmentCount-1; ii >= 0 && !needDownload; --ii )
       
   323                 {
       
   324                 const CESMRAttachment& attachment( 
       
   325                     iAttachmentInfo->AttachmentL( ii ) );
       
   326                     
       
   327                 needDownload = attachment.AttachmenState() != 
       
   328                     CESMRAttachment::EAttachmentStateDownloaded;
       
   329                 }
       
   330             
       
   331             // download all command    
       
   332             if( needDownload )
       
   333                 {
       
   334                 data.iFlags = 0;
       
   335                 data.iCascadeId = 0;
       
   336                 data.iCommandId = EESMRCmdDownloadAllAttachments;
       
   337 
       
   338                 TRAP_IGNORE( coeEnv->ReadResourceL( 
       
   339                     	data.iText, R_QTN_MEET_REQ_VIEWER_OPTIONS_ATTACH_DOWNLOAD_ALL ) );
       
   340                 aActionMenuPane->AddMenuItemL( data );    
       
   341                 }
       
   342             
       
   343             // save all command    
       
   344             data.iFlags = 0;
       
   345             data.iCascadeId = 0;
       
   346             data.iCommandId = EESMRCmdSaveAllAttachments;
       
   347 
       
   348             TRAP_IGNORE( coeEnv->ReadResourceL( 
       
   349                 	data.iText, R_QTN_MEET_REQ_VIEWER_OPTIONS_ATTACH_SAVE_ALL ) );
       
   350             aActionMenuPane->AddMenuItemL( data );            
       
   351         	}
       
   352        	else
       
   353        		{
       
   354             // There is one attachment
       
   355             const CESMRAttachment& attachment(
       
   356                     iAttachmentInfo->AttachmentL( 0 ) );
       
   357        		
       
   358        		// open or download command
       
   359        		if( attachment.AttachmenState() == CESMRAttachment::EAttachmentStateDownloaded )
       
   360        			{
       
   361                 data.iFlags = 0;
       
   362                 data.iCascadeId = 0;
       
   363                 data.iCommandId = EESMRCmdOpenAttachment;
       
   364 
       
   365                 TRAP_IGNORE( coeEnv->ReadResourceL( 
       
   366                 		data.iText, R_QTN_OPTIONS_OPEN ) );
       
   367                 aActionMenuPane->AddMenuItemL( data );                
       
   368        			}
       
   369        		else
       
   370        			{
       
   371                 data.iFlags = 0;
       
   372                 data.iCascadeId = 0;
       
   373                 data.iCommandId = EESMRCmdDownloadAttachment;
       
   374 
       
   375                 TRAP_IGNORE( coeEnv->ReadResourceL( 
       
   376                     	data.iText, R_QTN_MEET_REQ_VIEWER_OPTIONS_ATTACH_DOWNLOAD ) );
       
   377                 aActionMenuPane->AddMenuItemL( data );    
       
   378        			}
       
   379        		
       
   380        		// save command
       
   381             data.iFlags = 0;
       
   382             data.iCascadeId = 0;
       
   383             data.iCommandId = EESMRCmdSaveAttachment;
       
   384 
       
   385             TRAP_IGNORE( coeEnv->ReadResourceL( 
       
   386                 	data.iText, R_QTN_MEET_REQ_VIEWER_OPTIONS_ATTACH_SAVE ) );
       
   387             aActionMenuPane->AddMenuItemL( data );    
       
   388        		}
       
   389         }
       
   390     }
       
   391 
       
   392 // ---------------------------------------------------------------------------
       
   393 // CESMRContactMenuAttachmentHandler::ShowActionMenuL( )
       
   394 // ---------------------------------------------------------------------------
       
   395 //
       
   396 void CESMRContactMenuAttachmentHandler::ShowActionMenuL( )
       
   397     {
       
   398     FUNC_LOG;
       
   399     TFscActionMenuResult menuResult = iContactActionMenu.ExecuteL();
       
   400 
       
   401     if ( menuResult == EFscCustomItemSelected )
       
   402         {
       
   403         TUid uid = iContactActionMenu.FocusedItem().ImplementationUid();
       
   404         if ( uid == KOpenAttachmentViewUid )
       
   405             {
       
   406             //OpenAttachmentViewL();
       
   407             iCommandObserver->ProcessCommandL( EESMRCmdOpenAttachmentView );
       
   408             }
       
   409         else
       
   410         if( uid == KOpenAttachmentUid )
       
   411             {
       
   412             iCommandObserver->ProcessCommandL( EESMRCmdOpenAttachment );
       
   413             }
       
   414         else
       
   415         if( uid == KDownloadAllAttachmentsUid )
       
   416             {
       
   417             iCommandObserver->ProcessCommandL( EESMRCmdDownloadAllAttachments );
       
   418             }
       
   419         else
       
   420         if( uid == KDownloadAttachmentUid )
       
   421             {
       
   422             iCommandObserver->ProcessCommandL( EESMRCmdDownloadAttachment );
       
   423             }
       
   424         else
       
   425         if( uid == KSaveAllAttachmentsUid )
       
   426             {
       
   427             iCommandObserver->ProcessCommandL( EESMRCmdSaveAllAttachments );
       
   428             }
       
   429         else
       
   430         if( uid == KSaveAttachmentUid )
       
   431             {
       
   432             iCommandObserver->ProcessCommandL( EESMRCmdSaveAttachment );
       
   433             }
       
   434         }
       
   435     }
       
   436 
       
   437 // ---------------------------------------------------------------------------
       
   438 // CESMRContactMenuAttachmentHandler::SetCommandObserver()
       
   439 // ---------------------------------------------------------------------------
       
   440 //
       
   441 void CESMRContactMenuAttachmentHandler::SetCommandObserver(
       
   442             MEikCommandObserver* aCommandObserver )
       
   443     {
       
   444     FUNC_LOG;
       
   445     iCommandObserver = aCommandObserver;
       
   446     }
       
   447 // End of file
       
   448