meetingrequest/mrgui/mrfieldbuilderplugin/src/cmralarmonofffield.cpp
branchRCL_3
changeset 16 4ce476e64c59
child 17 8592a65ad3fb
equal deleted inserted replaced
13:0396474f30f5 16:4ce476e64c59
       
     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 alarm on off field implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include "cmralarmonofffield.h"
       
    20 #include "cmrlabel.h"
       
    21 #include "cmrimage.h"
       
    22 #include "mesmrcalentry.h"
       
    23 #include "mesmrlistobserver.h"
       
    24 #include "mesmrfieldvalidator.h"
       
    25 #include "nmrlayoutmanager.h"
       
    26 
       
    27 #include <stringloader.h>
       
    28 #include <avkon.hrh>
       
    29 #include <esmrgui.rsg>
       
    30 #include <aknutils.h>
       
    31 
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CMRAlarmOnOffField::NewL
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CMRAlarmOnOffField* CMRAlarmOnOffField::NewL( MESMRFieldValidator* aValidator )
       
    40     {
       
    41     FUNC_LOG;
       
    42     CMRAlarmOnOffField* self = new (ELeave) CMRAlarmOnOffField();
       
    43     CleanupStack::PushL ( self );
       
    44     self->ConstructL ( aValidator );
       
    45     CleanupStack::Pop ( self );
       
    46     return self;
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CMRAlarmOnOffField::CMRAlarmOnOffField
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CMRAlarmOnOffField::CMRAlarmOnOffField() 
       
    54     {
       
    55     FUNC_LOG;
       
    56     iStatus = ETrue;
       
    57     
       
    58     SetFieldId ( EESMRFieldAlarmOnOff );
       
    59     SetFocusType ( EESMRHighlightFocus );
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CMRAlarmOnOffField::ConstructL
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 void CMRAlarmOnOffField::ConstructL( MESMRFieldValidator* aValidator )
       
    67     {
       
    68     FUNC_LOG;
       
    69     iValidator = aValidator;
       
    70     iValidator->SetAbsoluteAlarmOnOffFieldL( *this );
       
    71         
       
    72     iIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapAlarm );
       
    73     iIcon->SetParent( this );
       
    74     
       
    75     iLabel = CMRLabel::NewL();
       
    76     CESMRField::ConstructL( iLabel ); // ownership transfered
       
    77     iLabel->SetTextL( KNullDesC() );
       
    78     iLabel->SetParent( this );
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CMRAlarmOnOffField::~CMRAlarmOnOffField
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CMRAlarmOnOffField::~CMRAlarmOnOffField( )
       
    86     {
       
    87     FUNC_LOG;
       
    88     delete iIcon;
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CMRAlarmOnOffField::InternalizeL
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 void CMRAlarmOnOffField::InternalizeL( MESMRCalEntry& aEntry )
       
    96     {
       
    97     FUNC_LOG;
       
    98     if ( aEntry.IsStoredL() ) // entry is already stored in db
       
    99         {
       
   100         MESMRCalEntry::TESMRAlarmType alarmType;
       
   101         TTime alarmTime;
       
   102         aEntry.GetAlarmL( alarmType, alarmTime );
       
   103 
       
   104         switch( alarmType )
       
   105             {
       
   106             //flow through
       
   107             case MESMRCalEntry::EESMRAlarmAbsolute:
       
   108             case MESMRCalEntry::EESMRAlarmRelative: // Show alarm as - ON
       
   109                 {
       
   110                 iStatus = ETrue;
       
   111                 }
       
   112                 break;
       
   113                 //flow through
       
   114             case MESMRCalEntry::EESMRAlarmNotFound:
       
   115             default: // Show alarm as - OFF
       
   116                 {
       
   117                 iStatus = EFalse;
       
   118                 }
       
   119                 break;
       
   120             }
       
   121         }
       
   122     else // This is a new entry and default implementation is required
       
   123         {
       
   124         switch( aEntry.Type() )
       
   125             {
       
   126             case MESMRCalEntry::EESMRCalEntryTodo: // To-do
       
   127                 {
       
   128                 TTime alarmTime;
       
   129                 MESMRCalEntry::TESMRAlarmType alarmType;
       
   130                 aEntry.GetAlarmL (alarmType, alarmTime );
       
   131 
       
   132                 // Change status to "ON" if alarm has been set by default
       
   133                 iStatus = alarmType != MESMRCalEntry::EESMRAlarmNotFound;
       
   134                 }
       
   135                 break;
       
   136             // Flow through
       
   137             case MESMRCalEntry::EESMRCalEntryMeetingRequest: // Meeting request
       
   138             case MESMRCalEntry::EESMRCalEntryMeeting: // Meeting
       
   139                 {
       
   140                 iStatus = ETrue;// Change the status to "ON" for these dialog default
       
   141                 }
       
   142                 break;
       
   143                 
       
   144             case MESMRCalEntry::EESMRCalEntryAnniversary: // Anniversary    
       
   145                 {
       
   146                 iStatus = ETrue;// Change the status to "ON" for these dialog default
       
   147                 }
       
   148                 break;
       
   149                 // Flow through
       
   150             case MESMRCalEntry::EESMRCalEntryMemo: // Memo
       
   151             case MESMRCalEntry::EESMRCalEntryReminder: // Reminder
       
   152             
       
   153             default:
       
   154                 iStatus = EFalse; // Change the status to "OFF" for these dialog default
       
   155                 break;
       
   156             }
       
   157         }
       
   158     ResetFieldL();
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // CMRAlarmOnOffField::OfferKeyEventL
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 TKeyResponse CMRAlarmOnOffField::OfferKeyEventL( const TKeyEvent& aEvent,
       
   166         TEventCode aType )
       
   167     {
       
   168     FUNC_LOG;
       
   169     TKeyResponse response( EKeyWasNotConsumed );
       
   170     if ( aType == EEventKey )
       
   171         {
       
   172         switch( aEvent.iScanCode )
       
   173             {
       
   174             // Flowthrough, doesn't matter which key was pressed since
       
   175             // the value is always changes from "off" to "on" or vice versus.
       
   176             case EStdKeyDevice3: // selection key
       
   177             case EStdKeyLeftArrow:
       
   178             case EStdKeyRightArrow:
       
   179                 iStatus = !iStatus; // change status
       
   180                 ResetFieldL();
       
   181                 response = EKeyWasConsumed;
       
   182                 break;
       
   183 
       
   184             default:
       
   185                 break;
       
   186             }
       
   187         }
       
   188     return response;
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // CMRAlarmOnOffField::SetOutlineFocusL
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 void CMRAlarmOnOffField::SetOutlineFocusL( TBool aFocus )
       
   196     {
       
   197     FUNC_LOG;
       
   198     CESMRField::SetOutlineFocusL( aFocus );
       
   199 
       
   200     iLabel->SetFocus( aFocus );
       
   201     
       
   202     if( aFocus ) //Focus is gained on the field
       
   203         {
       
   204         if ( iStatus )
       
   205             {
       
   206             ChangeMiddleSoftKeyL( EESMRCmdAlarmOff,R_QTN_MEET_REQ_ALARM_OFF ); //R_TEXT_SOFTKEY_OFF
       
   207             }
       
   208         else
       
   209             {
       
   210             ChangeMiddleSoftKeyL( EESMRCmdAlarmOn,R_QTN_MEET_REQ_ALARM_ON ); //R_TEXT_SOFTKEY_ON
       
   211             }
       
   212         }
       
   213     }
       
   214 
       
   215 // ---------------------------------------------------------------------------
       
   216 // CMRAlarmOnOffField::MakeVisible
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 void CMRAlarmOnOffField::MakeVisible( TBool aVisible )
       
   220     {
       
   221     FUNC_LOG;
       
   222     CCoeControl::MakeVisible( aVisible );
       
   223     if ( iObserver )
       
   224         {
       
   225         TRAP_IGNORE( ResetFieldL() );
       
   226         }
       
   227     }
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 // CMRAlarmOnOffField::ExecuteGenericCommandL()
       
   231 // ---------------------------------------------------------------------------
       
   232 //
       
   233 TBool CMRAlarmOnOffField::ExecuteGenericCommandL( TInt aCommand )
       
   234     {
       
   235     FUNC_LOG;
       
   236     TBool isUsed( EFalse );
       
   237     // EAknCmdOpen is added for the Pointer events, see ListPane
       
   238     if( aCommand == EESMRCmdAlarmOn || aCommand == EESMRCmdAlarmOff 
       
   239             || aCommand == EAknCmdOpen )
       
   240         {    
       
   241         SwitchMiddleSoftKeyL();
       
   242         isUsed = ETrue;
       
   243         
       
   244 		HandleTactileFeedbackL();
       
   245         }
       
   246     return isUsed;
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // CMRAlarmOnOffField::SwitchMiddleSoftKeyL
       
   251 // ---------------------------------------------------------------------------
       
   252 //
       
   253 void CMRAlarmOnOffField::SwitchMiddleSoftKeyL()
       
   254     {
       
   255     FUNC_LOG;
       
   256     iStatus = !iStatus; // change status
       
   257     ResetFieldL();
       
   258     if( iStatus )
       
   259         {
       
   260         ChangeMiddleSoftKeyL( EESMRCmdAlarmOff,R_QTN_MEET_REQ_ALARM_OFF ); 
       
   261         }
       
   262     else
       
   263         {
       
   264         ChangeMiddleSoftKeyL( EESMRCmdAlarmOn,R_QTN_MEET_REQ_ALARM_ON ); 
       
   265         }
       
   266     
       
   267     if( iLabel->IsVisible() )
       
   268         {
       
   269         iLabel->DrawDeferred();
       
   270         }
       
   271     }
       
   272 
       
   273 // ---------------------------------------------------------------------------
       
   274 // CMRAlarmOnOffField::ResetFieldL
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 void CMRAlarmOnOffField::ResetFieldL()
       
   278     {
       
   279     FUNC_LOG;
       
   280     iValidator->SetAlarmOnOffL( iStatus );
       
   281 
       
   282     HBufC* buf = StringLoader::LoadLC( iStatus ?
       
   283     R_QTN_MEET_REQ_ALARM_ON :
       
   284     R_QTN_MEET_REQ_ALARM_OFF );
       
   285 
       
   286     iLabel->SetTextL( *buf );
       
   287     CleanupStack::PopAndDestroy( buf );
       
   288 
       
   289     // if status on 'on', add time and date fields for
       
   290     // all day event alert, otherwise remove them.
       
   291     // if this field is not visible -> alldayevent not set
       
   292     // let's not show the date and time fields either.
       
   293     if ( iStatus && IsVisible() )
       
   294         {
       
   295         iObserver->ShowControl ( EESMRFieldAlarmTime );
       
   296         iObserver->ShowControl ( EESMRFieldAlarmDate );
       
   297         }
       
   298     else
       
   299         {
       
   300         iObserver->HideControl ( EESMRFieldAlarmTime );
       
   301         iObserver->HideControl ( EESMRFieldAlarmDate );
       
   302         }
       
   303     }
       
   304 
       
   305 // ---------------------------------------------------------------------------
       
   306 // CMRAlarmOnOffField::SizeChanged()
       
   307 // ---------------------------------------------------------------------------
       
   308 //
       
   309 void CMRAlarmOnOffField::SizeChanged()
       
   310     {
       
   311     FUNC_LOG;
       
   312     TRect rect = Rect();
       
   313     TAknLayoutRect rowLayoutRect =
       
   314      NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
       
   315     rect = rowLayoutRect.Rect();
       
   316     
       
   317     TAknWindowComponentLayout iconLayout =
       
   318      NMRLayoutManager::GetWindowComponentLayout( 
       
   319              NMRLayoutManager::EMRLayoutTextEditorIcon );
       
   320     AknLayoutUtils::LayoutImage( iIcon, rect, iconLayout );
       
   321     
       
   322     TAknLayoutRect bgLayoutRect =
       
   323      NMRLayoutManager::GetLayoutRect( 
       
   324              rect, NMRLayoutManager::EMRLayoutTextEditorBg );
       
   325     TRect bgRect( bgLayoutRect.Rect() );
       
   326     // Move focus rect so that it's relative to field's position.
       
   327     bgRect.Move( -Position() );
       
   328     SetFocusRect( bgRect );
       
   329     
       
   330     TAknLayoutText labelLayout = 
       
   331      NMRLayoutManager::GetLayoutText( 
       
   332              rect, NMRLayoutManager::EMRTextLayoutTextEditor );
       
   333     iLabel->SetRect( labelLayout.TextRect() );
       
   334     
       
   335     // Setting font for the label also
       
   336     iLabel->SetFont( labelLayout.Font() );
       
   337     }
       
   338 
       
   339 // ---------------------------------------------------------------------------
       
   340 // CMRAlarmOnOffField::CountComponentControls()
       
   341 // ---------------------------------------------------------------------------
       
   342 //
       
   343 TInt CMRAlarmOnOffField::CountComponentControls() const
       
   344     {
       
   345     FUNC_LOG;
       
   346     TInt count( 0 );
       
   347     if ( iIcon )
       
   348         {
       
   349         ++count;
       
   350         }
       
   351 
       
   352     if ( iLabel )
       
   353         {
       
   354         ++count;
       
   355         }
       
   356     return count;
       
   357     }
       
   358 
       
   359 // ---------------------------------------------------------------------------
       
   360 // CMRAlarmOnOffField::ComponentControl()
       
   361 // ---------------------------------------------------------------------------
       
   362 //
       
   363 CCoeControl* CMRAlarmOnOffField::ComponentControl( TInt aIndex ) const
       
   364     {
       
   365     FUNC_LOG;
       
   366     switch ( aIndex )
       
   367         {
       
   368         case 0:
       
   369             return iIcon;
       
   370         case 1:
       
   371             return iLabel;
       
   372         default:
       
   373             return NULL;
       
   374         }
       
   375     }
       
   376 
       
   377 // ---------------------------------------------------------------------------
       
   378 // CMRAlarmOnOffField::SetContainerWindowL
       
   379 // ---------------------------------------------------------------------------
       
   380 //
       
   381 void CMRAlarmOnOffField::SetContainerWindowL( 
       
   382         const CCoeControl& aContainer )
       
   383     {
       
   384     FUNC_LOG;
       
   385     CCoeControl::SetContainerWindowL( aContainer );
       
   386     iLabel->SetContainerWindowL( aContainer );
       
   387     iLabel->SetParent( this );
       
   388     }
       
   389 
       
   390 // ---------------------------------------------------------------------------
       
   391 // CMRAlarmOnOffField::SetAbsoluteAlarmOn
       
   392 // ---------------------------------------------------------------------------
       
   393 //
       
   394 void CMRAlarmOnOffField::SetAbsoluteAlarmOn()
       
   395     {
       
   396     FUNC_LOG;
       
   397     iStatus = ETrue;
       
   398     }
       
   399 
       
   400 // ---------------------------------------------------------------------------
       
   401 // CMRAlarmOnOffField::SetAbsoluteAlarmOn
       
   402 // ---------------------------------------------------------------------------
       
   403 //
       
   404 void CMRAlarmOnOffField::SetAbsoluteAlarmOff()
       
   405     {
       
   406     FUNC_LOG;
       
   407     iStatus = EFalse;
       
   408     }
       
   409 
       
   410 // EOF