email/mail/ViewerSrc/cmsgmailviewerfinditemhandler.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2006 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: Handles CItemFinder and CFindItemMenu for mail viewer.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "MailLog.h"
       
    19 #include <MsgMailViewer.rsg>
       
    20 #include "msgmailviewer.hrh"
       
    21 #include "cmsgmailviewerfinditemhandler.h"
       
    22 #include "cmsgmailviewercontactmatcher.h"
       
    23 #include <AiwContactAssignDataTypes.h>  // aiw
       
    24 #include <AiwServiceHandler.h>          // aiw
       
    25 #include <finditem.hrh>
       
    26 #include <FindItemmenu.rsg>
       
    27 #include <finditemmenu.h>
       
    28 #include <finditemdialog.h>
       
    29 
       
    30 // LOCAL CONSTANTS
       
    31 
       
    32 // ================= MEMBER FUNCTIONS =======================
       
    33 //
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CMsgMailViewerFindItemHandler::NewL
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CMsgMailViewerFindItemHandler* CMsgMailViewerFindItemHandler::NewL( 
       
    40     CItemFinder* aItemFinder )
       
    41     {
       
    42     CMsgMailViewerFindItemHandler* self = new( 
       
    43         ELeave ) CMsgMailViewerFindItemHandler( aItemFinder );
       
    44     CleanupStack::PushL( self );
       
    45     self->ConstructL();
       
    46     CleanupStack::Pop( self );
       
    47     return self;
       
    48     }
       
    49     
       
    50 // ---------------------------------------------------------------------------
       
    51 // CMsgMailViewerFindItemHandler
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CMsgMailViewerFindItemHandler::CMsgMailViewerFindItemHandler(
       
    55     CItemFinder* aItemFinder )
       
    56     : iFindMode( CItemFinder::ENoneSelected ),
       
    57       iItemFinder( aItemFinder )
       
    58     {
       
    59     }
       
    60 
       
    61 // ------------------------------------------------------------------------------
       
    62 // CMsgMailViewerFindItemHandler::~CMsgMailViewerFindItemHandler()
       
    63 // Destructor
       
    64 // Frees reserved resources
       
    65 // ------------------------------------------------------------------------------
       
    66 //
       
    67 CMsgMailViewerFindItemHandler::~CMsgMailViewerFindItemHandler()
       
    68     {
       
    69     LOG("~CMsgMailViewerFindItemHandler destructor");
       
    70     delete iFindItemMenu;
       
    71     LOG("~CMsgMailViewerFindItemHandler destructor end");
       
    72     }
       
    73 
       
    74 
       
    75 // ------------------------------------------------------------------------------
       
    76 // CMsgMailViewerFindItemHandler::ConstructL()
       
    77 // Symbian OS constructor
       
    78 // ------------------------------------------------------------------------------
       
    79 //
       
    80 void CMsgMailViewerFindItemHandler::ConstructL()
       
    81     {
       
    82     LOG("CMsgMailViewerFindItemHandler::ConstructL");
       
    83     SetFindModeL( iFindMode ); // make sure that finder is really in initial mode
       
    84     iFindItemMenu = CFindItemMenu::NewL( EMsgMailViewerCmdFindItem );
       
    85     iFindItemMenu->AttachItemFinderMenuL( R_MSGMAILVIEWER_OPTIONS_MENU2 );
       
    86     iFindItemMenu->SetSenderDescriptorType( CItemFinder::EEmailAddress );    
       
    87 #if defined(__VOIP) && defined(RD_VOIP_REL_2_2)
       
    88     //hide call menu
       
    89     iFindItemMenu->SetMenuItemVisibility( CFindItemMenu::ECallItem, EFalse );
       
    90 #endif // __VOIP && RD_VOIP_REL_2_2
       
    91 	LOG("CMsgMailViewerFindItemHandler::ConstructL -> End");
       
    92     }
       
    93 
       
    94 // ------------------------------------------------------------------------------
       
    95 // CMsgMailViewerFindItemHandler::::DynInitMenuPaneL()
       
    96 // ------------------------------------------------------------------------------
       
    97 //
       
    98 void CMsgMailViewerFindItemHandler::DynInitMenuPaneL(
       
    99     TInt aResourceId,
       
   100     CEikMenuPane* aMenuPane,
       
   101     const TDesC& aAddress,
       
   102     const TDesC& aName,
       
   103     TMsgControlId aFocusedControl )
       
   104     {
       
   105 #if defined(__VOIP) && defined(RD_VOIP_REL_2_2)  
       
   106     if ( aFocusedControl == EMsgComponentIdBody )
       
   107         {
       
   108         //set call menu visible
       
   109         iFindItemMenu->SetMenuItemVisibility( CFindItemMenu::ECallItem, ETrue );
       
   110         }
       
   111     else
       
   112         {
       
   113         //hide call menu     
       
   114         iFindItemMenu->SetMenuItemVisibility( CFindItemMenu::ECallItem, EFalse );
       
   115         }
       
   116 #endif // __VOIP && RD_VOIP_REL_2_2
       
   117 
       
   118     if ( aResourceId == R_MSGMAILVIEWER_OPTIONS_MENU2 ||
       
   119          aResourceId == R_MSGMAILVIEWER_FINDITEM_MENU)
       
   120         {
       
   121         // If body is not focused, then we must not give CItemFinder
       
   122         // to Find Item -> that way it shows options applicable
       
   123         // for the e-mail address given in aAddress
       
   124         CItemFinder* itemFinder = NULL;
       
   125         if ( aFocusedControl == EMsgComponentIdBody )
       
   126             {
       
   127             itemFinder = iItemFinder;
       
   128             }
       
   129 
       
   130         // If FindMode is ENoneSelected(=find deactivated) give empty address
       
   131         // string for iFindItemMenu
       
   132         const TDesC& address( FindMode() == CItemFinder::ENoneSelected ?
       
   133                               KNullDesC : aAddress );
       
   134           
       
   135         TBool isContextMenu( aResourceId == R_MSGMAILVIEWER_FINDITEM_MENU ?
       
   136                              ETrue : EFalse );
       
   137 
       
   138         TInt index( isContextMenu ?
       
   139                     EFindItemContextMenuPlaceHolder :
       
   140                     EFindItemMenuPlaceHolder );
       
   141         
       
   142         // although method names here refer to "sender", the same functionality
       
   143         // applies to any focused address
       
   144         iFindItemMenu->SetSenderHighlightStatus(
       
   145             IsAddressControl( aFocusedControl ) );
       
   146         const TDesC& displayText( aName.Length() > 0 ? aName : aAddress );
       
   147         iFindItemMenu->SetSenderDisplayText( displayText );
       
   148         iFindItemMenu->AddItemFindMenuL( itemFinder,
       
   149                                          aMenuPane,
       
   150                                          index,
       
   151                                          address,
       
   152                                          EFalse,
       
   153                                          isContextMenu );
       
   154         }
       
   155     else
       
   156         {
       
   157         // all unknown menu panes should be given to UpdateItemFinderMenuL
       
   158         iFindItemMenu->UpdateItemFinderMenuL( aResourceId, aMenuPane );
       
   159         }
       
   160     }
       
   161 
       
   162 TBool CMsgMailViewerFindItemHandler::IsAddressControl(
       
   163     TMsgControlId aFocusedControl ) const
       
   164     {    
       
   165 	return ( aFocusedControl == EMsgComponentIdTo ||
       
   166         	 aFocusedControl == EMsgComponentIdFrom ||
       
   167         	 aFocusedControl == EMsgComponentIdCc ||
       
   168         	 aFocusedControl == EMsgComponentIdBcc );
       
   169     }
       
   170 		 
       
   171 // ------------------------------------------------------------------------------
       
   172 // CMsgMailViewerFindItemHandler::SelectionType()
       
   173 // ------------------------------------------------------------------------------
       
   174 //
       
   175 CItemFinder::TItemType
       
   176 CMsgMailViewerFindItemHandler::SelectionType( TBool aIsFocused ) const
       
   177     {
       
   178     CItemFinder::TItemType itemType( CItemFinder::ENoneSelected );
       
   179     if ( iItemFinder && aIsFocused )
       
   180         {        
       
   181         itemType = iItemFinder->CurrentItemExt().iItemType;
       
   182         }
       
   183     return itemType;
       
   184     }
       
   185 
       
   186 // ------------------------------------------------------------------------------
       
   187 // CMsgMailViewerFindItemHandler::SelectionText()
       
   188 // ------------------------------------------------------------------------------
       
   189 //
       
   190 const TDesC& CMsgMailViewerFindItemHandler::SelectionText(
       
   191     TBool aIsFocused ) const
       
   192     {
       
   193     if ( SelectionType( aIsFocused ) == CItemFinder::ENoneSelected )
       
   194         {
       
   195         return KNullDesC;
       
   196         }
       
   197     else
       
   198         {
       
   199         return *( iItemFinder->CurrentItemExt().iItemDescriptor );
       
   200         }
       
   201     }
       
   202 
       
   203 // ------------------------------------------------------------------------------
       
   204 // CMsgMailViewerFindItemHandler::SetFindModeL()
       
   205 // ------------------------------------------------------------------------------
       
   206 //
       
   207 void CMsgMailViewerFindItemHandler::SetFindModeL( TInt aFindFlags )
       
   208     {
       
   209     if ( iItemFinder )
       
   210         {
       
   211         iItemFinder->SetFindModeL( aFindFlags );
       
   212         iFindMode = aFindFlags;
       
   213         }
       
   214     }
       
   215 
       
   216 // ------------------------------------------------------------------------------
       
   217 // CMsgMailViewerFindItemHandler::FindMode()
       
   218 // ------------------------------------------------------------------------------
       
   219 //
       
   220 TInt CMsgMailViewerFindItemHandler::FindMode() const
       
   221     {
       
   222     return iFindMode;
       
   223     }
       
   224 
       
   225 // ------------------------------------------------------------------------------
       
   226 // CMsgMailViewerFindItemHandler::CanHandleCommand()
       
   227 // ------------------------------------------------------------------------------
       
   228 //
       
   229 TBool CMsgMailViewerFindItemHandler::CanHandleCommand( TInt aCommand ) const
       
   230     {
       
   231     TBool returnValue = EFalse;
       
   232     TRAP_IGNORE( returnValue = iFindItemMenu->CommandIsValidL( aCommand ) );
       
   233     return returnValue;
       
   234     }
       
   235     
       
   236 // ------------------------------------------------------------------------------
       
   237 // CMsgMailViewerFindItemHandler::HandleFinderCommandL()
       
   238 // ------------------------------------------------------------------------------
       
   239 //
       
   240 void CMsgMailViewerFindItemHandler::HandleFinderCommandL( TInt aCommand )
       
   241     {
       
   242     iFindItemMenu->HandleItemFinderCommandL( aCommand );
       
   243     }
       
   244 
       
   245 // End of File