meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrpriorityfield.cpp
changeset 0 8466d47a6819
child 16 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 priority field implementation
       
    15  *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include "cesmrpriorityfield.h"
       
    20 
       
    21 #include "cesmrlistquery.h"
       
    22 #include "mesmrtitlepaneobserver.h"
       
    23 
       
    24 //<cmail>
       
    25 #include "mesmrcalentry.h"
       
    26 //</cmail>
       
    27 #include <calentry.h>
       
    28 #include <esmrgui.rsg>
       
    29 #include <StringLoader.h>
       
    30 #include <barsread.h>
       
    31 #include <eiklabel.h>
       
    32 #include <avkon.hrh>
       
    33 #include <AknsConstants.h>
       
    34 #include <AknUtils.h>
       
    35 
       
    36 // ======== MEMBER FUNCTIONS ========
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // CESMRPriorityField::NewL
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 CESMRPriorityField* CESMRPriorityField::NewL( )
       
    43     {
       
    44     FUNC_LOG;
       
    45     CESMRPriorityField* self = new (ELeave) CESMRPriorityField;
       
    46     CleanupStack::PushL ( self );
       
    47     self->ConstructL ( );
       
    48     CleanupStack::Pop ( self );
       
    49     return self;
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CESMRPriorityField::~CESMRPriorityField
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CESMRPriorityField::~CESMRPriorityField( )
       
    57     {
       
    58     FUNC_LOG;
       
    59     iArray.ResetAndDestroy ( );
       
    60     iArray.Close ( );
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CESMRPriorityField::InitializeL
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 void CESMRPriorityField::InitializeL()
       
    68     {
       
    69     FUNC_LOG;
       
    70     iPriority->SetFont( iLayout->Font( iCoeEnv, iFieldId ) );
       
    71     iPriority->SetLabelAlignment( CESMRLayoutManager::IsMirrored()
       
    72                                   ? ELayoutAlignRight : ELayoutAlignLeft );
       
    73 
       
    74     AknLayoutUtils::OverrideControlColorL(*iPriority,
       
    75                                           EColorLabelText,
       
    76                                           iLayout->GeneralListAreaTextColor() );
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CESMRPriorityField::InternalizeL
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 void CESMRPriorityField::InternalizeL( MESMRCalEntry& aEntry )
       
    84     {
       
    85     FUNC_LOG;
       
    86     TInt prior = aEntry.GetPriorityL ( );
       
    87 
       
    88     iEntryType = aEntry.Type();
       
    89 
       
    90     // esmrgui.rss
       
    91     TResourceReader reader;
       
    92     TInt resourceId(KErrNotFound);
       
    93     if ( aEntry.Type() == MESMRCalEntry::EESMRCalEntryTodo )
       
    94         {
       
    95         resourceId = R_ESMREDITOR_TODO_PRIORITY;
       
    96         }
       
    97     else
       
    98         {
       
    99         resourceId = R_ESMREDITOR_PRIORITY;
       
   100         }
       
   101 
       
   102     iCoeEnv->CreateResourceReaderLC ( reader, resourceId );
       
   103 
       
   104     iArray.Reset ( );
       
   105     // Read priority items to array
       
   106     TInt count = reader.ReadInt16 ( );
       
   107     for (TInt i(0); i < count; i++ )
       
   108         {
       
   109         CESMRPriority* priority = new (ELeave) CESMRPriority;
       
   110         CleanupStack::PushL ( priority );
       
   111         priority->ConstructFromResourceL ( reader );
       
   112         iArray.AppendL ( priority );
       
   113         CleanupStack::Pop ( priority );
       
   114         if ( priority->Id ( )== prior )
       
   115             {
       
   116             iIndex = i;
       
   117             UpdateTextL ( iIndex );
       
   118             }
       
   119         }
       
   120     // reader
       
   121     CleanupStack::PopAndDestroy(); // codescanner::cleanup 
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // CESMRPriorityField::ExternalizeL
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 void CESMRPriorityField::ExternalizeL( MESMRCalEntry& aEntry )
       
   129     {
       
   130     FUNC_LOG;
       
   131     if ( iIndex < iArray.Count() )
       
   132         {
       
   133         CCalEntry& calEntry = aEntry.Entry ( );
       
   134         calEntry.SetPriorityL ( iArray[iIndex]->Id ( ) );
       
   135         }
       
   136     else
       
   137         {
       
   138         User::Leave( KErrOverflow );
       
   139         }
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CESMRPriorityField::SetOutlineFocusL
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CESMRPriorityField::SetOutlineFocusL( TBool aFocus )
       
   147     {
       
   148     FUNC_LOG;
       
   149     CESMRField::SetOutlineFocusL ( aFocus );
       
   150 
       
   151     //Focus gained
       
   152     if ( aFocus )
       
   153         {
       
   154         ChangeMiddleSoftKeyL(EESMRCmdOpenPriorityQuery, R_QTN_MSK_OPEN);
       
   155         }
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // CESMRPriorityField::ExecuteGenericCommandL()
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 void CESMRPriorityField::ExecuteGenericCommandL( TInt aCommand )
       
   163     {
       
   164     FUNC_LOG;
       
   165     if( aCommand == EESMRCmdOpenPriorityQuery ||
       
   166         aCommand == EAknCmdOpen )
       
   167         {
       
   168         ExecutePriorityQueryL();
       
   169         }
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // CESMRPriorityField::ExecutePriorityQueryL
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CESMRPriorityField::ExecutePriorityQueryL()
       
   177     {
       
   178     FUNC_LOG;
       
   179 
       
   180     TInt ret(KErrNone);
       
   181     if ( iEntryType == MESMRCalEntry::EESMRCalEntryTodo)
       
   182         {
       
   183         ret = CESMRListQuery::ExecuteL (CESMRListQuery::EESMRTodoPriorityPopup );
       
   184         }
       
   185     else
       
   186         {
       
   187         ret = CESMRListQuery::ExecuteL (CESMRListQuery::EESMRPriorityPopup );
       
   188         }
       
   189 
       
   190     if ( ret != KErrCancel )
       
   191         {
       
   192         // ret is priority value, not index
       
   193         for ( TInt i=0; i<iArray.Count(); ++i )
       
   194             {
       
   195             if ( iArray[i]->Id() == ret )
       
   196                 {
       
   197                 iIndex = i;
       
   198                 UpdateTextL( iIndex );
       
   199                 break;
       
   200                 }
       
   201             }
       
   202         }
       
   203 
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // CESMRPriorityField::OfferKeyEventL
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 TKeyResponse CESMRPriorityField::OfferKeyEventL(const TKeyEvent& aEvent,
       
   211         TEventCode aType )
       
   212     {
       
   213     FUNC_LOG;
       
   214     TKeyResponse response( EKeyWasNotConsumed);
       
   215     if ( aType == EEventKey )
       
   216         {
       
   217         switch ( aEvent.iScanCode )
       
   218             {
       
   219             case EStdKeyLeftArrow:
       
   220                 {
       
   221                 if ( iIndex > 0 )
       
   222                     {
       
   223                     UpdateTextL ( --iIndex );
       
   224                     response = EKeyWasConsumed;
       
   225                     }
       
   226                 }
       
   227                 break;
       
   228             case EStdKeyRightArrow:
       
   229                 {
       
   230                 if ( iIndex < iArray.Count ( )- 1 )
       
   231                     {
       
   232                     UpdateTextL ( ++iIndex );
       
   233                     response = EKeyWasConsumed;
       
   234                     }
       
   235                 }
       
   236                 break;
       
   237             case EStdKeyDevice3:
       
   238                 {
       
   239                 TInt ret(KErrNone);
       
   240                 if ( iEntryType == MESMRCalEntry::EESMRCalEntryTodo)
       
   241                     {
       
   242                     ret = CESMRListQuery::ExecuteL (CESMRListQuery::EESMRTodoPriorityPopup );
       
   243                     }
       
   244                 else
       
   245                     {
       
   246                     ret = CESMRListQuery::ExecuteL (CESMRListQuery::EESMRPriorityPopup );
       
   247                     }
       
   248                 if ( ret != KErrCancel )
       
   249                     {
       
   250                     // ret is priority value, not index
       
   251                     for ( TInt i=0; i<iArray.Count(); ++i )
       
   252                         {
       
   253                         if ( iArray[i]->Id() == ret )
       
   254                             {
       
   255                             iIndex = i;
       
   256                             UpdateTextL( iIndex );
       
   257                             break;
       
   258                             }
       
   259                         }
       
   260                     }
       
   261                 response = EKeyWasConsumed;
       
   262                 }
       
   263                 break;
       
   264             default:
       
   265                 break;
       
   266             }
       
   267         }
       
   268     return response;
       
   269     }
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // CESMRPriorityField::CESMRPriorityField
       
   273 // ---------------------------------------------------------------------------
       
   274 //
       
   275 CESMRPriorityField::CESMRPriorityField( )
       
   276     {
       
   277     FUNC_LOG;
       
   278     //do nothing
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // CESMRPriorityField::ConstructL
       
   283 // ---------------------------------------------------------------------------
       
   284 //
       
   285 void CESMRPriorityField::ConstructL( )
       
   286     {
       
   287     FUNC_LOG;
       
   288     SetFieldId ( EESMRFieldPriority );
       
   289     iPriority = new( ELeave ) CEikLabel();
       
   290     _LIT(KEmptyText, "");
       
   291     iPriority->SetTextL( KEmptyText );
       
   292 
       
   293     // ownership transferred
       
   294     CESMRIconField::ConstructL (KAknsIIDQgnFsIndiPriorityNormal, iPriority );
       
   295     }
       
   296 
       
   297 // ---------------------------------------------------------------------------
       
   298 // CESMRPriorityField::UpdateTextL
       
   299 // ---------------------------------------------------------------------------
       
   300 //
       
   301 void CESMRPriorityField::UpdateTextL( TInt aIndex )
       
   302     {
       
   303     FUNC_LOG;
       
   304     CESMRPriority* priority = iArray[ aIndex ];
       
   305     iPriority->SetTextL ( priority->Text ( ) );
       
   306 
       
   307     TAknsItemID iconID = { 0 , 0 };
       
   308 
       
   309     switch ( priority->Id() )
       
   310         {
       
   311         case EFSCalenMRPriorityLow:
       
   312         case EFSCalenTodoPriorityLow:
       
   313             {
       
   314             iconID = KAknsIIDQgnFsIndiPriorityLow;
       
   315             break;
       
   316             }
       
   317         case EFSCalenMRPriorityUnknown:
       
   318         case EFSCalenMRPriorityNormal:
       
   319         case EFSCalenTodoPriorityNormal:
       
   320             {
       
   321             iconID = KAknsIIDQgnFsIndiPriorityNormal;
       
   322             break;
       
   323             }
       
   324         case EFSCalenMRPriorityHigh: // same value as EFSCalenTodoPriorityHigh
       
   325             {
       
   326             iconID = KAknsIIDQgnFsIndiPriorityHigh;
       
   327             break;
       
   328             }
       
   329         default:
       
   330         	ASSERT(EFalse);
       
   331         	break;
       
   332         }
       
   333     IconL( iconID );
       
   334     DrawDeferred ( );
       
   335 
       
   336     // update titlepane priority icon
       
   337     if ( iObserver )
       
   338         {
       
   339         iObserver->UpdateTitlePanePriorityIconL( priority->Id() );
       
   340         }
       
   341 
       
   342     // this is needed to call in order to get new
       
   343     // icon drawn
       
   344     CESMRIconField::SizeChanged();
       
   345     }
       
   346 
       
   347 
       
   348 // ---------------------------------------------------------------------------
       
   349 // CESMRPriorityField::UpdateTextL
       
   350 // ---------------------------------------------------------------------------
       
   351 //
       
   352 void CESMRPriorityField::SetTitlePaneObserver( MESMRTitlePaneObserver* aObserver )
       
   353     {
       
   354     iObserver = aObserver;
       
   355     }
       
   356 
       
   357 // EOF
       
   358