meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrviewertimefield.cpp
branchRCL_3
changeset 25 3533d4323edc
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 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:  Time field for viewers
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cesmrviewertimefield.h"
       
    19 #include "cesmreditor.h"
       
    20 #include "mesmrlistobserver.h"
       
    21 #include "nmrbitmapmanager.h"
       
    22 #include "nmrlayoutmanager.h"
       
    23 #include "cmrlabel.h"
       
    24 #include "cmrimage.h"
       
    25 #include "cesmrglobalnote.h"
       
    26 
       
    27 #include <eiklabel.h>
       
    28 #include <caluser.h>
       
    29 #include <calalarm.h>
       
    30 #include <avkon.rsg>
       
    31 #include <calentry.h>
       
    32 #include <eikenv.h>
       
    33 #include <eikedwin.h>
       
    34 #include <StringLoader.h>
       
    35 #include <AknsConstants.h>
       
    36 #include <AknUtils.h>
       
    37 #include <AknLayout2ScalableDef.h>
       
    38 #include <esmrgui.rsg>
       
    39 // DEBUG
       
    40 #include "emailtrace.h"
       
    41 
       
    42 //unnamed namespace for local constants functions
       
    43 namespace{ // codescanner::namespace
       
    44 
       
    45 const TInt KTimeBufferSize( 50 );
       
    46 
       
    47 const TInt KTempBufferSize( 20 );
       
    48 
       
    49 // Literal for start and end time separator
       
    50 _LIT(KTimeSeparator," - ");
       
    51 
       
    52 }//namespace
       
    53 
       
    54 // ======== MEMBER FUNCTIONS ========
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CESMRViewerTimeField::CESMRViewerTimeField()
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CESMRViewerTimeField::CESMRViewerTimeField()
       
    61     {
       
    62     FUNC_LOG;
       
    63 
       
    64     SetFieldId( EESMRFieldMeetingTime );
       
    65     SetFocusType( EESMRHighlightFocus );
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CESMRViewerTimeField::~CESMRViewerTimeField()
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CESMRViewerTimeField::~CESMRViewerTimeField()
       
    73     {
       
    74     FUNC_LOG;
       
    75     delete iIcon;
       
    76     delete iLockIcon;
       
    77     }
       
    78 
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CESMRViewerTimeField::NewL()
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 CESMRViewerTimeField* CESMRViewerTimeField::NewL()
       
    85     {
       
    86     FUNC_LOG;
       
    87     CESMRViewerTimeField* self = new (ELeave) CESMRViewerTimeField();
       
    88     CleanupStack::PushL( self );
       
    89     self->ConstructL();
       
    90     CleanupStack::Pop( self );
       
    91     return self;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CESMRViewerTimeField::ConstructL()
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 void CESMRViewerTimeField::ConstructL()
       
    99     {
       
   100     FUNC_LOG;
       
   101 
       
   102     iLabel = CMRLabel::NewL( this );
       
   103     CESMRField::ConstructL( iLabel ); // ownership transfered
       
   104 
       
   105     iIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapClock, this );
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // CESMRViewerTimeField::InternalizeL()
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 void CESMRViewerTimeField::InternalizeL( MESMRCalEntry& aEntry )
       
   113     {
       
   114     FUNC_LOG;
       
   115 
       
   116     CCalEntry& entry = aEntry.Entry();
       
   117 
       
   118     iStartTime = entry.StartTimeL().TimeLocalL();
       
   119     iEndTime   = entry.EndTimeL().TimeLocalL();
       
   120 
       
   121     if ( aEntry.IsAllDayEventL() )
       
   122         {
       
   123         // set the field as hidden:
       
   124         iObserver->HideControl( FieldId() );
       
   125         }
       
   126     else
       
   127         {
       
   128         FormatTimeFieldStringL();
       
   129         }
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // CESMRViewerTimeField::InitializeL()
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void CESMRViewerTimeField::InitializeL()
       
   137     {
       
   138     FUNC_LOG;
       
   139 
       
   140     TAknLayoutText text = NMRLayoutManager::GetLayoutText(
       
   141             Rect(),
       
   142             NMRLayoutManager::EMRTextLayoutTextEditor );
       
   143 
       
   144     iLabel->SetFont( text.Font() );
       
   145     // This is called so that theme changes will apply when changing theme "on the fly"
       
   146     if ( IsFocused() )
       
   147         {
       
   148         iLabel->FocusChanged( EDrawNow );
       
   149         }
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // CESMRViewerTimeField::SizeChanged()
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 void CESMRViewerTimeField::SizeChanged()
       
   157     {
       
   158     FUNC_LOG;
       
   159 
       
   160     TRect rect = Rect();
       
   161     TAknLayoutRect rowLayoutRect =
       
   162         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
       
   163     rect = rowLayoutRect.Rect();
       
   164 
       
   165     TAknWindowComponentLayout iconLayout =
       
   166         NMRLayoutManager::GetWindowComponentLayout(
       
   167                 NMRLayoutManager::EMRLayoutTextEditorIcon );
       
   168     AknLayoutUtils::LayoutImage( iIcon, rect, iconLayout );
       
   169 
       
   170     // Layouting lock icon
       
   171     if( iLockIcon )
       
   172         {
       
   173         TAknWindowComponentLayout iconLayout(
       
   174                 NMRLayoutManager::GetWindowComponentLayout(
       
   175                     NMRLayoutManager::EMRLayoutSingleRowDColumnGraphic ) );
       
   176         AknLayoutUtils::LayoutImage( iLockIcon, rect, iconLayout );
       
   177         }
       
   178 
       
   179     // Layouting label
       
   180     TAknTextComponentLayout viewerLayoutText;
       
   181     if( iLockIcon )
       
   182         {
       
   183         viewerLayoutText = NMRLayoutManager::GetTextComponentLayout(
       
   184                 NMRLayoutManager::EMRTextLayoutSingleRowEditorText );
       
   185         }
       
   186     else
       
   187         {
       
   188         viewerLayoutText = NMRLayoutManager::GetTextComponentLayout(
       
   189                 NMRLayoutManager::EMRTextLayoutTextEditor );
       
   190         }
       
   191 
       
   192     AknLayoutUtils::LayoutLabel( iLabel, rect, viewerLayoutText );
       
   193     TRect viewerRect( iLabel->Rect() );
       
   194 
       
   195     // Move focus rect so that it's relative to field's position.
       
   196     viewerRect.Move( -Position() );
       
   197     SetFocusRect( viewerRect );
       
   198     }
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // CESMRViewerTimeField::CountComponentControls()
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 TInt CESMRViewerTimeField::CountComponentControls() const
       
   205     {
       
   206     FUNC_LOG;
       
   207 
       
   208     TInt count( 0 );
       
   209     if ( iIcon )
       
   210     	{
       
   211     	++count;
       
   212     	}
       
   213 
       
   214     if ( iLabel )
       
   215     	{
       
   216     	++count;
       
   217     	}
       
   218 
       
   219     if ( iLockIcon )
       
   220     	{
       
   221     	++count;
       
   222     	}
       
   223     return count;
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------------------------
       
   227 // CESMRViewerTimeField::ComponentControl()
       
   228 // ---------------------------------------------------------------------------
       
   229 //
       
   230 CCoeControl* CESMRViewerTimeField::ComponentControl( TInt aIndex ) const
       
   231     {
       
   232     FUNC_LOG;
       
   233 
       
   234     switch ( aIndex )
       
   235         {
       
   236         case 0:
       
   237             return iIcon;
       
   238         case 1:
       
   239             return iLabel;
       
   240         case 2:
       
   241         	return iLockIcon;
       
   242         default:
       
   243             return NULL;
       
   244         }
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 // CESMRViewerTimeField::SetOutlineFocusL()
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 void CESMRViewerTimeField::SetOutlineFocusL( TBool aFocus )
       
   252     {
       
   253     FUNC_LOG;
       
   254 
       
   255     CESMRField::SetOutlineFocusL ( aFocus );
       
   256 
       
   257     iLabel->SetFocus( aFocus );
       
   258     }
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 // CESMRViewerTimeField::ExecuteGenericCommandL()
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 TBool CESMRViewerTimeField::ExecuteGenericCommandL( TInt aCommand )
       
   265     {
       
   266     FUNC_LOG;
       
   267 
       
   268     TBool retValue( EFalse );
       
   269 
       
   270     if( (aCommand == EAknCmdOpen) && IsLocked()  )
       
   271     	{
       
   272 		HandleTactileFeedbackL();
       
   273 
       
   274     	CESMRGlobalNote::ExecuteL(
       
   275     			CESMRGlobalNote::EESMRUnableToEdit );
       
   276     	retValue = ETrue;
       
   277     	}
       
   278 
       
   279     if ( EMRCmdDoEnvironmentChange == aCommand )
       
   280         {
       
   281         FormatTimeFieldStringL();
       
   282         retValue = ETrue;
       
   283         }
       
   284 
       
   285     return retValue;
       
   286     }
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // CESMRViewerTimeField::LockL()
       
   290 // ---------------------------------------------------------------------------
       
   291 //
       
   292 void CESMRViewerTimeField::LockL()
       
   293 	{
       
   294 	FUNC_LOG;
       
   295 	if( IsLocked() )
       
   296 		{
       
   297 		return;
       
   298 		}
       
   299 
       
   300 	CESMRField::LockL();
       
   301 
       
   302 	delete iLockIcon;
       
   303 	iLockIcon = NULL;
       
   304 	iLockIcon = CMRImage::NewL(
       
   305 	        NMRBitmapManager::EMRBitmapLockField,
       
   306 	        this,
       
   307 	        ETrue );
       
   308 	}
       
   309 
       
   310 // ---------------------------------------------------------------------------
       
   311 // CESMRViewerTimeField::FormatTimeFieldStringL()
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 void CESMRViewerTimeField::FormatTimeFieldStringL()
       
   315     {
       
   316     HBufC* timeFormatString =
       
   317         iEikonEnv->AllocReadResourceLC( R_QTN_TIME_USUAL_WITH_ZERO );
       
   318 
       
   319     HBufC* finalBuf = HBufC::NewLC( KTimeBufferSize );
       
   320     HBufC* startBuf = HBufC::NewLC( KTempBufferSize );
       
   321     HBufC* endBuf = HBufC::NewLC( KTempBufferSize );
       
   322     const TInt KNumBuffers( 4 );
       
   323 
       
   324     TPtr startPtr( startBuf->Des() );
       
   325     iStartTime.FormatL( startPtr, *timeFormatString );
       
   326     TPtr endPtr( endBuf->Des() );
       
   327     iEndTime.FormatL( endPtr, *timeFormatString );
       
   328     TPtr finalPtr( finalBuf->Des() );
       
   329     finalPtr.Append( startPtr );
       
   330     finalPtr.Append( KTimeSeparator );
       
   331     finalPtr.Append( endPtr );
       
   332     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( finalPtr );
       
   333     iLabel->SetTextL( finalPtr );
       
   334     CleanupStack::PopAndDestroy( KNumBuffers, timeFormatString );
       
   335 
       
   336     }
       
   337 
       
   338 // EOF