meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrviewerrecurrencedatefield.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:  Recurrence date field for viewers
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cesmrviewerrecurrencedatefield.h"
       
    20 #include "mesmrresponseobserver.h"
       
    21 #include "mesmrlistobserver.h"
       
    22 #include "esmrfieldbuilderdef.h"
       
    23 #include "cmrlabel.h"
       
    24 #include "nmrlayoutmanager.h"
       
    25 #include "nmrcolormanager.h"
       
    26 #include "cesmrglobalnote.h"
       
    27 
       
    28 #include <eikenv.h>
       
    29 #include <avkon.rsg>
       
    30 #include <avkon.hrh>
       
    31 #include <StringLoader.h>
       
    32 #include <AknUtils.h>
       
    33 #include <esmrgui.rsg>
       
    34 #include <caltime.h>
       
    35 // DEBUG
       
    36 #include "emailtrace.h"
       
    37 namespace // codescanner::namespace
       
    38     {
       
    39     const TInt KComponentCount( 2 );
       
    40     }
       
    41 // ======== MEMBER FUNCTIONS ========
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CESMRViewerRecurrenceDateField::CESMRViewerRecurrenceDateField
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CESMRViewerRecurrenceDateField::CESMRViewerRecurrenceDateField()
       
    48 :   iRepeatUntilDate( Time::NullTTime() )
       
    49     {
       
    50     FUNC_LOG;
       
    51     SetFieldId( EESMRFieldRecurrenceDate );
       
    52     SetFocusType( EESMRHighlightFocus );
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CESMRViewerRecurrenceDateField::~CESMRViewerRecurrenceDateField
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CESMRViewerRecurrenceDateField::~CESMRViewerRecurrenceDateField()
       
    60     {
       
    61     FUNC_LOG;
       
    62     delete iRepeatTopic;
       
    63     delete iRepeatDate;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CESMRViewerRecurrenceDateField::NewL
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CESMRViewerRecurrenceDateField* CESMRViewerRecurrenceDateField::NewL()
       
    71     {
       
    72     FUNC_LOG;
       
    73     CESMRViewerRecurrenceDateField* self =
       
    74             new (ELeave) CESMRViewerRecurrenceDateField();
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     CleanupStack::Pop( self );
       
    78     return self;
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CESMRViewerRecurrenceDateField::ConstructL
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CESMRViewerRecurrenceDateField::ConstructL()
       
    86     {
       
    87     FUNC_LOG;
       
    88     CESMRField::ConstructL( NULL );
       
    89     iRepeatTopic = CMRLabel::NewL( this );
       
    90     iRepeatDate = CMRLabel::NewL( this );
       
    91 
       
    92     iRepeatTopic->SetTextL( KNullDesC );
       
    93     iRepeatDate->SetTextL( KNullDesC );
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CESMRViewerRecurrenceDateField::InitializeL
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CESMRViewerRecurrenceDateField::InitializeL()
       
   101     {
       
   102     FUNC_LOG;
       
   103     NMRColorManager::SetColor( *iRepeatTopic,
       
   104                                NMRColorManager::EMRMainAreaTextColor );
       
   105 
       
   106     NMRColorManager::SetColor( *iRepeatDate,
       
   107                                NMRColorManager::EMRMainAreaTextColor );
       
   108     //this control cannot ever get keyboard focus
       
   109     SetFocusing(EFalse);
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CESMRViewerRecurrenceDateField::ExecuteGenericCommandL
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 TBool CESMRViewerRecurrenceDateField::ExecuteGenericCommandL( TInt aCommand )
       
   117     {
       
   118     FUNC_LOG;
       
   119 
       
   120     TBool retValue( EFalse );
       
   121 
       
   122     if( (aCommand == EAknCmdOpen) && IsLocked()  )
       
   123     	{
       
   124 		HandleTactileFeedbackL();
       
   125 
       
   126     	CESMRGlobalNote::ExecuteL(
       
   127     			CESMRGlobalNote::EESMRUnableToEdit );
       
   128     	retValue = ETrue;
       
   129     	}
       
   130     else if ( EMRCmdDoEnvironmentChange == aCommand )
       
   131         {
       
   132         FormatRepeatUntilDateL();
       
   133         retValue = ETrue;
       
   134         }
       
   135 
       
   136     return retValue;
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CESMRViewerRecurrenceDateField::SizeChanged
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 void CESMRViewerRecurrenceDateField::SizeChanged()
       
   144     {
       
   145     FUNC_LOG;
       
   146     TRect rect( Rect() );
       
   147     // First row
       
   148     TAknLayoutRect row1LayoutRect =
       
   149         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
       
   150     rect = row1LayoutRect.Rect();
       
   151 
       
   152     TAknTextComponentLayout topicLayoutText =
       
   153             NMRLayoutManager::GetTextComponentLayout(
       
   154                     NMRLayoutManager::EMRTextLayoutMultiRowTextEditor );
       
   155 
       
   156     AknLayoutUtils::LayoutLabel( iRepeatTopic, rect, topicLayoutText );
       
   157 
       
   158     rect = Rect();
       
   159     // Move the iY down the height of the topic field
       
   160     TInt movement = row1LayoutRect.Rect().Height();
       
   161     rect.Move( 0, movement );
       
   162 
       
   163     // Second row
       
   164     TAknLayoutRect row2LayoutRect =
       
   165         NMRLayoutManager::GetFieldRowLayoutRect( rect, 2 );
       
   166     rect = row2LayoutRect.Rect();
       
   167 
       
   168     TAknTextComponentLayout dateLayoutText =
       
   169             NMRLayoutManager::GetTextComponentLayout(
       
   170                     NMRLayoutManager::EMRTextLayoutMultiRowTextEditor );
       
   171 
       
   172     AknLayoutUtils::LayoutLabel( iRepeatDate, rect, dateLayoutText );
       
   173     }
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CESMRViewerRecurrenceDateField::MinimumSize
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 TSize CESMRViewerRecurrenceDateField::MinimumSize()
       
   180     {
       
   181     TInt height( 0 );
       
   182     // First row
       
   183     TAknLayoutRect row1LayoutRect =
       
   184         NMRLayoutManager::GetFieldRowLayoutRect( Rect(), 1 );
       
   185     height += row1LayoutRect.Rect().Height();
       
   186     // Second row
       
   187     TAknLayoutRect row2LayoutRect =
       
   188         NMRLayoutManager::GetFieldRowLayoutRect( Rect(), 2 );
       
   189     height += row2LayoutRect.Rect().Height();
       
   190 
       
   191     TInt width( Parent()->Size().iWidth );
       
   192     return TSize( width, height );
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CESMRViewerRecurrenceDateField::InternalizeL
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void CESMRViewerRecurrenceDateField::InternalizeL(
       
   200         MESMRCalEntry& aEntry )
       
   201     {
       
   202     FUNC_LOG;
       
   203     // Get recurrence
       
   204     TESMRRecurrenceValue recValue( ERecurrenceNot );
       
   205     aEntry.GetRecurrenceL( recValue, iRepeatUntilDate );
       
   206 
       
   207     // Recurrence time has to be shown in the viewer as local time
       
   208     TCalTime recurrenceTime;
       
   209     recurrenceTime.SetTimeUtcL( iRepeatUntilDate );
       
   210     iRepeatUntilDate = recurrenceTime.TimeLocalL();
       
   211 
       
   212     if( aEntry.IsRecurrentEventL() &&
       
   213         recValue != ERecurrenceNot &&
       
   214         Time::NullTTime() != iRepeatUntilDate )
       
   215         {
       
   216         FormatRepeatUntilDateL();
       
   217         }
       
   218     else
       
   219         {
       
   220         MakeVisible( EFalse );
       
   221         }
       
   222     }
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CESMRViewerRecurrenceDateField::CountComponentControls
       
   226 // -----------------------------------------------------------------------------
       
   227 //
       
   228 TInt CESMRViewerRecurrenceDateField::CountComponentControls() const
       
   229     {
       
   230     FUNC_LOG;
       
   231     return KComponentCount;
       
   232     }
       
   233 
       
   234 // -----------------------------------------------------------------------------
       
   235 // CESMRViewerRecurrenceDateField::ComponentControl
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 CCoeControl* CESMRViewerRecurrenceDateField::ComponentControl( TInt aInd ) const
       
   239     {
       
   240     FUNC_LOG;
       
   241     CCoeControl* retVal = NULL;
       
   242     switch( aInd )
       
   243         {
       
   244         case 0:
       
   245             {
       
   246             retVal = iRepeatTopic;
       
   247             break;
       
   248             }
       
   249         case 1:
       
   250             {
       
   251             retVal = iRepeatDate;
       
   252             break;
       
   253             }
       
   254         default:;
       
   255         }
       
   256 
       
   257     return retVal;
       
   258     }
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // CESMRViewerRecurrenceDateField::FormatRepeatUntilDateL
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 void CESMRViewerRecurrenceDateField::FormatRepeatUntilDateL()
       
   265     {
       
   266     FUNC_LOG;
       
   267 
       
   268     HBufC* topicHolder =
       
   269             StringLoader::LoadLC(
       
   270                     R_QTN_MEET_REQ_REPEAT_UNTIL,
       
   271                     iEikonEnv );
       
   272 
       
   273     // Set text for repeat topic (e.g. "Repeat until")
       
   274     iRepeatTopic->SetTextL( *topicHolder );
       
   275     CleanupStack::PopAndDestroy( topicHolder );
       
   276 
       
   277     // Format date string
       
   278     HBufC* timeFormatString = iEikonEnv->AllocReadResourceLC(
       
   279                                     R_QTN_DATE_USUAL);
       
   280 
       
   281     TBuf< KDateStringLength > finalBuf;
       
   282     iRepeatUntilDate.FormatL( finalBuf, *timeFormatString );
       
   283 
       
   284     // Set repeat until date value
       
   285     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( finalBuf );
       
   286     iRepeatDate->SetTextL( finalBuf );
       
   287     CleanupStack::PopAndDestroy( timeFormatString );
       
   288     timeFormatString = NULL;
       
   289     }
       
   290 
       
   291 // End of file
       
   292 
       
   293