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