meetingrequest/mrgui/mrfieldbuilderpluginextension/src/cesmrtrackstatus.cpp
changeset 0 8466d47a6819
child 16 4ce476e64c59
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2003-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:  Holds the tracking status for MR attendee
       
    15  *
       
    16 */
       
    17 
       
    18 // CLASS HEADER
       
    19 #include "cesmrtrackstatus.h"
       
    20 #include "cesmrfield.h"
       
    21 #include "cesmriconfield.h"
       
    22 #include "cesmrborderlayer.h"
       
    23 #include "esmrdef.h"
       
    24 #include "mesmrlistobserver.h"
       
    25 #include "cesmrcontactmenuhandler.h"
       
    26 #include "esmrhelper.h"
       
    27 #include "nmrbitmapmanager.h"
       
    28 #include <eiklabel.h>
       
    29 #include <eikimage.h>
       
    30 #include <calentry.h>
       
    31 #include <caluser.h>
       
    32 #include <eikenv.h>
       
    33 #include <StringLoader.h>
       
    34 #include <AknsUtils.h>
       
    35 #include <AknUtils.h>
       
    36 #include <AknsConstants.h>
       
    37 #include <AknBidiTextUtils.h>
       
    38 #include <esmrgui.rsg>
       
    39 #include <data_caging_path_literals.hrh>
       
    40 
       
    41 // DEBUG
       
    42 #include "emailtrace.h"
       
    43 
       
    44 using namespace ESMRLayout;
       
    45 
       
    46 // ======== MEMBER FUNCTIONS ========
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // CESMRTrackStatus::NewL()
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CESMRTrackStatus* CESMRTrackStatus::NewL()
       
    53     {
       
    54     FUNC_LOG;
       
    55     CESMRTrackStatus* self = new (ELeave) CESMRTrackStatus();
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59     return self;
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CESMRTrackStatus::~CESMRTrackStatus()
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CESMRTrackStatus::~CESMRTrackStatus()
       
    67     {
       
    68     FUNC_LOG;
       
    69     if ( iMenuHandler )
       
    70         {
       
    71         iMenuHandler->Reset();
       
    72         }
       
    73     iESMRStatic.Close();
       
    74     delete iDefaultAddress;
       
    75     delete iAddress;
       
    76     delete iCommonName;
       
    77     delete iIcon;
       
    78     delete iActionMenuIcon;
       
    79     delete iActionMenuIconMask;
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CESMRTrackStatus::CESMRTrackStatus()
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 CESMRTrackStatus::CESMRTrackStatus()
       
    87     {
       
    88     FUNC_LOG;
       
    89     //do nothing
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CESMRTrackStatus::ConstructL()
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 void CESMRTrackStatus::ConstructL()
       
    97     {
       
    98     FUNC_LOG;
       
    99     // As a default set icon and text as it should be in status Needs action
       
   100     SetFieldId( EESMRTrackStatus );
       
   101     CESMRViewerLabelField::ConstructL( KAknsIIDQgnFsIndiCaleTrackingNone );
       
   102     iESMRStatic.ConnectL();
       
   103     iMenuHandler = &iESMRStatic.ContactMenuHandlerL();
       
   104 
       
   105     iIcon = new (ELeave) CEikImage;
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // CESMRTrackStatus::InternalizeL()
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 void CESMRTrackStatus::InternalizeL( MESMRCalEntry& aEntry )
       
   113     {
       
   114     FUNC_LOG;
       
   115     TAknsItemID statusIconId = KAknsIIDQgnFsIndiCaleTrackingNone;
       
   116     RPointerArray<CCalAttendee> attendee = aEntry.Entry().AttendeesL();
       
   117     // The array is already in sorted order with ReqAttendee coming first and
       
   118     // OptAttendee  coming later.
       
   119     TInt currentIndex = iESMRStatic.CurrentFieldIndex();
       
   120     
       
   121     if(currentIndex >= attendee.Count())
       
   122         {
       
   123         User::Leave( KErrArgument );
       
   124         }
       
   125         
       
   126     TPtrC text;
       
   127     CCalAttendee::TCalStatus status = attendee[currentIndex]->StatusL();    
       
   128     if (attendee[currentIndex]->Address().Length() >0 )
       
   129         {
       
   130         if ( attendee[currentIndex]->CommonName().Length() > 0 )
       
   131             {
       
   132             text.Set( attendee[currentIndex]->CommonName() );
       
   133             iCommonName = text.AllocL();
       
   134             }
       
   135         else
       
   136             {
       
   137             text.Set( attendee[currentIndex]->Address() );
       
   138             }
       
   139         iAddress = attendee[currentIndex]->Address().AllocL();
       
   140         }
       
   141 
       
   142     const CFont* font = iLayout->Font (iCoeEnv, iFieldId );        
       
   143     TInt maxLineWidth = iLabel->Size().iWidth;        
       
   144     maxLineWidth -= KIconSize.iWidth;
       
   145     
       
   146     HBufC* clippedTextHBufC = ClipTextLC( text, *font, maxLineWidth );
       
   147     TPtr clippedText = clippedTextHBufC->Des();
       
   148     clippedText.Trim();
       
   149     iLabel->SetTextL( clippedText );
       
   150     CleanupStack::PopAndDestroy( clippedTextHBufC );
       
   151     clippedTextHBufC = NULL;
       
   152     
       
   153     switch( status )
       
   154         {
       
   155         case CCalAttendee::ENeedsAction:
       
   156             {
       
   157             statusIconId = KAknsIIDQgnFsIndiCaleTrackingNone;
       
   158             break;
       
   159             }
       
   160         case CCalAttendee::ETentative:
       
   161             {
       
   162             statusIconId = KAknsIIDQgnFsIndiCaleTrackingTentative;
       
   163             break;
       
   164             }
       
   165         case CCalAttendee::EAccepted:
       
   166         case CCalAttendee::EConfirmed:
       
   167             {
       
   168             statusIconId = KAknsIIDQgnFsIndiCaleTrackingAccept;
       
   169             break;
       
   170             }
       
   171         case CCalAttendee::EDeclined:
       
   172             {
       
   173             statusIconId = KAknsIIDQgnFsIndiCaleTrackingReject;
       
   174             break;
       
   175             }
       
   176         default:
       
   177             {
       
   178             statusIconId = KAknsIIDQgnFsIndiCaleTrackingNone;
       
   179             break;
       
   180             }
       
   181         }
       
   182 
       
   183         iESMRStatic.SetCurrentFieldIndex(++currentIndex); // Move to next index
       
   184 
       
   185         IconL( statusIconId );
       
   186         
       
   187         //store default list selection to contactmenuhandler
       
   188         iDefaultAddress = attendee[0]->Address().AllocL();
       
   189         iMenuHandler->SetValueL(*iDefaultAddress, CESMRContactMenuHandler::EValueTypeEmail);
       
   190 
       
   191         // This needs to be called so icon will be redrawn
       
   192         SizeChanged();
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // CESMRTrackStatus::OfferKeyEventL
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 TKeyResponse CESMRTrackStatus::OfferKeyEventL( const TKeyEvent& aEvent, TEventCode aType )
       
   200     {
       
   201     FUNC_LOG;
       
   202     if ( aEvent.iScanCode == EStdKeyRightArrow )
       
   203         {
       
   204         // Show right click menu (action menu)
       
   205 
       
   206         iMenuHandler->ShowActionMenuL();
       
   207         return EKeyWasConsumed;
       
   208         }
       
   209 
       
   210     return CESMRViewerLabelField::OfferKeyEventL(aEvent,aType);
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // CESMRTrackStatus::SetOutlineFocusL
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 void CESMRTrackStatus::SetOutlineFocusL(TBool aFocus )
       
   218     {
       
   219     FUNC_LOG;
       
   220     CESMRViewerLabelField::SetOutlineFocusL (aFocus );
       
   221     SetActionMenuIconL(aFocus);
       
   222     TRgb fontColor( 0, 0, 0 );
       
   223     if ( aFocus )
       
   224         {
       
   225         if(iAddress)
       
   226             {
       
   227             //no longer needed
       
   228             delete iDefaultAddress;
       
   229             iDefaultAddress = NULL;
       
   230             //give contact to actionmenuhandler
       
   231             iMenuHandler->SetValueL(*iAddress, CESMRContactMenuHandler::EValueTypeEmail);
       
   232             }
       
   233         fontColor = iLayout->ViewerListAreaHighlightedTextColor();
       
   234         }
       
   235     else
       
   236         {
       
   237         iMenuHandler->Reset();
       
   238         fontColor = iLayout->ViewerListAreaTextColor();
       
   239         }
       
   240 
       
   241     TRAP_IGNORE( AknLayoutUtils::OverrideControlColorL(
       
   242                                       *iLabel,
       
   243                                       EColorLabelText,
       
   244                                       fontColor ) );
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 // CESMRCheckbox::CountComponentControls
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 TInt CESMRTrackStatus::CountComponentControls( ) const
       
   252     {
       
   253     FUNC_LOG;
       
   254     TInt count = CESMRViewerLabelField::CountComponentControls ( );
       
   255     if ( iIcon )
       
   256         {
       
   257         ++count;
       
   258         }
       
   259     return count;
       
   260     }
       
   261 
       
   262 // ---------------------------------------------------------------------------
       
   263 // CESMRTrackStatus::ComponentControl
       
   264 // ---------------------------------------------------------------------------
       
   265 //
       
   266 CCoeControl* CESMRTrackStatus::ComponentControl( TInt aInd ) const
       
   267     {
       
   268     FUNC_LOG;
       
   269     if ( aInd == 2 )
       
   270         {
       
   271         return iIcon;
       
   272         }
       
   273     return CESMRViewerLabelField::ComponentControl ( aInd );
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------------------------
       
   277 // CESMRCheckbox::SetIconL
       
   278 // ---------------------------------------------------------------------------
       
   279 //
       
   280 void CESMRTrackStatus::SetActionMenuIconL( TBool aFocused )
       
   281     {
       
   282     FUNC_LOG;
       
   283     delete iIcon;
       
   284     iIcon = NULL;
       
   285     delete iActionMenuIcon;
       
   286     iActionMenuIcon = NULL;
       
   287     delete iActionMenuIconMask;
       
   288     iActionMenuIconMask = NULL;
       
   289 
       
   290     if( aFocused )
       
   291         {
       
   292         User::LeaveIfError( 
       
   293                 NMRBitmapManager::GetSkinBasedBitmap( 
       
   294                         NMRBitmapManager::EMRBitmapRightClickArrow, 
       
   295                             iActionMenuIcon, iActionMenuIconMask, KIconSize ) );
       
   296 
       
   297         // Even if creating mask failed, bitmap can be used (background is just not displayed correctly)
       
   298         if( iActionMenuIcon )
       
   299             {
       
   300             iIcon = new (ELeave) CEikImage;
       
   301             iIcon->SetPictureOwnedExternally(ETrue);
       
   302             iIcon->SetPicture( iActionMenuIcon, iActionMenuIconMask );
       
   303 
       
   304             TRect rect = Rect ( );
       
   305             TInt iconTopMargin = ( rect.Height() - KIconSize.iHeight ) / 2;
       
   306             TPoint iconPos( rect.iBr.iX - KIconSize.iWidth - KIconBorderMargin,
       
   307                                 rect.iBr.iY - iconTopMargin - KIconSize.iHeight);
       
   308             iIcon->SetPosition ( iconPos );
       
   309             iIcon->SetSize ( KIconSize );           
       
   310             }
       
   311         }
       
   312     }
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // CESMRTrackStatus::SizeChanged
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 void CESMRTrackStatus::SizeChanged( )
       
   319     {
       
   320     FUNC_LOG;
       
   321     CESMRViewerLabelField::SizeChanged();
       
   322 
       
   323     if ( iIcon )
       
   324         {
       
   325         TRect rect = Rect ( );
       
   326         TInt iconTopMargin = ( rect.Height() - KIconSize.iHeight ) / 2;
       
   327         TPoint iconPos( rect.iBr.iX - KIconSize.iWidth - KIconBorderMargin,
       
   328                             rect.iBr.iY - iconTopMargin - KIconSize.iHeight);
       
   329 
       
   330         iIcon->SetPosition ( iconPos );
       
   331         iIcon->SetSize ( KIconSize );
       
   332         }
       
   333     }
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // CESMRTrackStatus::ClipTextLC
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 HBufC* CESMRTrackStatus::ClipTextLC( 
       
   340         const TDesC& aText, 
       
   341         const CFont& aFont, 
       
   342         TInt aWidth )
       
   343     {
       
   344     FUNC_LOG;
       
   345     HBufC* text = HBufC::NewLC( aText.Length() + KAknBidiExtraSpacePerLine );
       
   346     TPtr textPtr = text->Des();
       
   347     AknBidiTextUtils::ConvertToVisualAndClip( aText, textPtr, aFont, aWidth, aWidth );
       
   348     return text;
       
   349     }
       
   350 
       
   351 // End of file
       
   352