meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrsyncfield.cpp
changeset 0 8466d47a6819
child 12 4ce476e64c59
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007-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 Synchronization field implementation
       
    15  *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include "cesmrsyncfield.h"
       
    20 
       
    21 #include <eiklabel.h>
       
    22 #include <esmrgui.rsg>
       
    23 #include <StringLoader.h>
       
    24 #include <barsread.h>
       
    25 #include <avkon.hrh>
       
    26 #include <AknsConstants.h>
       
    27 #include <AknUtils.h>
       
    28 
       
    29 #include "cesmrsync.h"
       
    30 #include "cesmrlistquery.h"
       
    31 #include <calentry.h>
       
    32 
       
    33 // Unnamed namespace for local definitions and functions
       
    34 namespace{ // codescanner::namespace
       
    35 
       
    36 CCalEntry::TReplicationStatus MapToReplicationStatus(
       
    37         TESMRSyncValue aSyncValue )
       
    38     {
       
    39     CCalEntry::TReplicationStatus ret;
       
    40     switch ( aSyncValue )
       
    41         {
       
    42         case ESyncNone:
       
    43             {
       
    44             ret = CCalEntry::ERestricted;
       
    45             break;
       
    46             }
       
    47         case ESyncPrivate:
       
    48             {
       
    49             ret = CCalEntry::EPrivate;
       
    50             break;
       
    51             }
       
    52         case ESyncPublic:
       
    53             {
       
    54             ret = CCalEntry::EOpen;
       
    55             break;
       
    56             }
       
    57         default:
       
    58             {
       
    59             ret = CCalEntry::ERestricted;
       
    60             }
       
    61         }
       
    62 
       
    63     return ret;
       
    64     }
       
    65 
       
    66 } // namespace
       
    67 
       
    68 // ======== MEMBER FUNCTIONS ========
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CESMRSyncField::NewL
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 CESMRSyncField* CESMRSyncField::NewL( )
       
    75     {
       
    76     FUNC_LOG;
       
    77     CESMRSyncField* self = new (ELeave) CESMRSyncField;
       
    78     CleanupStack::PushL ( self );
       
    79     self->ConstructL ( );
       
    80     CleanupStack::Pop ( self );
       
    81     return self;
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CESMRSyncField::~CESMRSyncField
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 CESMRSyncField::~CESMRSyncField( )
       
    89     {
       
    90     FUNC_LOG;
       
    91     iArray.ResetAndDestroy ( );
       
    92     iArray.Close ( );
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CESMRSyncField::InitializeL
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CESMRSyncField::InitializeL()
       
   100     {
       
   101     FUNC_LOG;
       
   102     iSync->SetFont( iLayout->Font( iCoeEnv, iFieldId ) );
       
   103     iSync->SetLabelAlignment( CESMRLayoutManager::IsMirrored()
       
   104                               ? ELayoutAlignRight : ELayoutAlignLeft );
       
   105     AknLayoutUtils::OverrideControlColorL(*iSync,
       
   106                                            EColorLabelText,
       
   107                                            iLayout->GeneralListAreaTextColor() );
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CESMRSyncField::InternalizeL
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void CESMRSyncField::InternalizeL( MESMRCalEntry& aEntry )
       
   115     {
       
   116     FUNC_LOG;
       
   117     TInt synchValue = aEntry.Entry().ReplicationStatusL ( );
       
   118 
       
   119     // esmrgui.rss
       
   120     TResourceReader reader;
       
   121     iCoeEnv->CreateResourceReaderLC ( reader, R_ESMREDITOR_SYNC );
       
   122 
       
   123     // Read sync items to array
       
   124     iArray.ResetAndDestroy( );
       
   125     TInt count = reader.ReadInt16 ( );
       
   126     for (TInt i(0); i < count; i++ )
       
   127         {
       
   128         CESMRSync* sync = new (ELeave) CESMRSync();
       
   129         CleanupStack::PushL( sync );
       
   130         sync->ConstructFromResourceL ( reader );
       
   131         iArray.AppendL ( sync );
       
   132         CleanupStack::Pop( sync );
       
   133         if ( synchValue == MapToReplicationStatus ( sync->Id ( ) ) )
       
   134             {
       
   135             iIndex = i;
       
   136             iSync->SetTextL ( sync->TextL ( ) );
       
   137             }
       
   138         }
       
   139     // resource reader
       
   140     CleanupStack::PopAndDestroy(); // codescanner::cleanup
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CESMRSyncField::ExternalizeL
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 void CESMRSyncField::ExternalizeL( MESMRCalEntry& aEntry )
       
   148     {
       
   149     FUNC_LOG;
       
   150     if ( iIndex < iArray.Count() )
       
   151         {
       
   152         CCalEntry::TReplicationStatus
       
   153             repStatus = MapToReplicationStatus ( iArray[iIndex]->Id ( ) );
       
   154         aEntry.Entry().SetReplicationStatusL (repStatus );
       
   155         }
       
   156     else
       
   157         {
       
   158         User::Leave( KErrOverflow );
       
   159         }
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // CESMRPriorityField::SetOutlineFocusL
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 void CESMRSyncField::SetOutlineFocusL( TBool aFocus )
       
   167     {
       
   168     FUNC_LOG;
       
   169     CESMRField::SetOutlineFocusL ( aFocus );
       
   170 
       
   171     //Focus gained
       
   172     if ( aFocus )
       
   173         {
       
   174         ChangeMiddleSoftKeyL(EESMRCmdOpenSyncQuery, R_QTN_MSK_OPEN);
       
   175         }
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CESMRPriorityField::ExecuteGenericCommandL
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void CESMRSyncField::ExecuteGenericCommandL( TInt aCommand )
       
   183     {
       
   184     FUNC_LOG;
       
   185     if(aCommand == EESMRCmdOpenSyncQuery ||
       
   186        aCommand == EAknCmdOpen )
       
   187         {
       
   188         ExecuteSyncQueryL();
       
   189         }
       
   190     }
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // CESMRPriorityField::ExecuteSyncQuery
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 void CESMRSyncField::ExecuteSyncQueryL()
       
   197     {
       
   198     FUNC_LOG;
       
   199 
       
   200     TInt ret =
       
   201         CESMRListQuery::ExecuteL( CESMRListQuery::EESMRSynchronizationPopup );
       
   202     if ( ret != KErrCancel )
       
   203         {
       
   204         iIndex = ret;
       
   205         UpdateLabelL (ret );
       
   206         }
       
   207     }
       
   208 
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // CESMRSyncField::OfferKeyEventL
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 TKeyResponse CESMRSyncField::OfferKeyEventL( const TKeyEvent& aEvent,
       
   215         TEventCode aType )
       
   216     {
       
   217     FUNC_LOG;
       
   218     TKeyResponse response( EKeyWasNotConsumed);
       
   219     if ( aType == EEventKey )
       
   220         {
       
   221         switch ( aEvent.iScanCode )
       
   222             {
       
   223             case EStdKeyLeftArrow:
       
   224                 {
       
   225                 if ( iIndex > 0 )
       
   226                     {
       
   227                     UpdateLabelL ( --iIndex );
       
   228                     response = EKeyWasConsumed;
       
   229                     }
       
   230                 }
       
   231                 break;
       
   232 
       
   233             case EStdKeyRightArrow:
       
   234                 {
       
   235                 if ( iIndex < (iArray.Count() - 1) )
       
   236                     {
       
   237                     UpdateLabelL ( ++iIndex );
       
   238                     response = EKeyWasConsumed;
       
   239                     }
       
   240                 }
       
   241                 break;
       
   242 
       
   243             default:
       
   244                 break;
       
   245             }
       
   246         }
       
   247     return response;
       
   248     }
       
   249 
       
   250 // ---------------------------------------------------------------------------
       
   251 // CESMRSyncField::CESMRSyncField
       
   252 // ---------------------------------------------------------------------------
       
   253 //
       
   254 CESMRSyncField::CESMRSyncField( ) :
       
   255     iIndex(0)
       
   256     {
       
   257     FUNC_LOG;
       
   258     //do nothing
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // CESMRSyncField::ConstructL
       
   263 // ---------------------------------------------------------------------------
       
   264 //
       
   265 void CESMRSyncField::ConstructL( )
       
   266     {
       
   267     FUNC_LOG;
       
   268     SetFieldId( EESMRFieldSync );
       
   269 
       
   270     iSync = new (ELeave) CEikLabel;
       
   271     iSync->SetTextL( KNullDesC );
       
   272 
       
   273     TGulAlignment align;
       
   274     align.SetHAlignment( EHLeft );
       
   275     align.SetVAlignment( EVCenter );
       
   276     iSync->SetAlignment( align );
       
   277 
       
   278     CESMRIconField::ConstructL(
       
   279             KAknsIIDQgnFscalIndiSynchronisation,
       
   280             iSync );
       
   281     }
       
   282 
       
   283 // ---------------------------------------------------------------------------
       
   284 // CESMRSyncField::UpdateLabelL
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 void CESMRSyncField::UpdateLabelL( TInt aIndex )
       
   288     {
       
   289     FUNC_LOG;
       
   290     CESMRSync* sync = iArray[ aIndex ];
       
   291     iSync->SetTextL( sync->TextL() );
       
   292     iSync->DrawDeferred();
       
   293     }
       
   294 
       
   295 // EOF
       
   296