meetingrequest/mrgui/mrfieldbuilderplugin/src/cmrmulticalenfield.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:  MR multi calendar field implementation
       
    15  *
       
    16 */
       
    17 
       
    18 #include "cmrmulticalenfield.h"
       
    19 #include "cmrimage.h"
       
    20 #include "cmrlabel.h"
       
    21 #include "cesmrtextitem.h"
       
    22 #include "cesmrlistquery.h"
       
    23 #include "nmrlayoutmanager.h"
       
    24 #include "nmrcolormanager.h"
       
    25 #include "mesmrmeetingrequestentry.h"
       
    26 #include "cesmrglobalnote.h"
       
    27 #include <calinstance.h>
       
    28 #include <esmrgui.rsg>
       
    29 #include <stringloader.h>
       
    30 #include <barsread.h>
       
    31 #include <avkon.hrh>
       
    32 #include <aknutils.h>
       
    33 #include <calentry.h>
       
    34 #include <caleninterimutils2.h>
       
    35 // DEBUG
       
    36 #include "emailtrace.h"
       
    37 #include "cesmrcaldbmgr.h"
       
    38 
       
    39 
       
    40 // ======== MEMBER FUNCTIONS ========
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // CMRMultiCalenField::NewL
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 CMRMultiCalenField* CMRMultiCalenField::NewL( )
       
    47     {
       
    48     FUNC_LOG;
       
    49     CMRMultiCalenField* self = new (ELeave) CMRMultiCalenField;
       
    50     CleanupStack::PushL ( self );
       
    51     self->ConstructL ( );
       
    52     CleanupStack::Pop ( self );
       
    53     return self;
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CMRMultiCalenField::~CMRMultiCalenField
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CMRMultiCalenField::~CMRMultiCalenField( )
       
    61     {
       
    62     FUNC_LOG;
       
    63     iCalenNameList.Close();
       
    64     delete iIcon;
       
    65     delete iLockIcon;
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CMRMultiCalenField::InitializeL()
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 void CMRMultiCalenField::InitializeL()
       
    73     {
       
    74     TAknLayoutText text = NMRLayoutManager::GetLayoutText(
       
    75             Rect(),
       
    76             NMRLayoutManager::EMRTextLayoutTextEditor );
       
    77 
       
    78     iCalenName->SetFont( text.Font() );
       
    79     // This is called so that theme changes will apply when changing theme "on the fly"
       
    80     if ( IsFocused() )
       
    81         {
       
    82         iCalenName->FocusChanged( EDrawNow );
       
    83         }
       
    84     }
       
    85 // ---------------------------------------------------------------------------
       
    86 // CMRMultiCalenField::InternalizeL
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void CMRMultiCalenField::InternalizeL( MESMRCalEntry& aEntry )
       
    90     {
       
    91     FUNC_LOG;
       
    92     MESMRCalDbMgr& dbMgr = aEntry.GetDBMgr();
       
    93     iCalenNameList.Reset();
       
    94 
       
    95     dbMgr.GetMultiCalendarNameListL( iCalenNameList );
       
    96     TPtrC calenName = dbMgr.GetCalendarNameByEntryL( aEntry );
       
    97     iIndex = dbMgr.GetCurCalendarIndex();
       
    98     iCalenName->SetTextL( calenName );
       
    99 
       
   100     iEntry = &aEntry;
       
   101 
       
   102     // Set's the calendar type change enabled or disabled.
       
   103     if( FieldMode() == EESMRFieldModeEdit && !TypeChangeEnabledL() )
       
   104         {
       
   105         iTypeChangeEnabled = EFalse;
       
   106 
       
   107         LockL();
       
   108         }
       
   109     else
       
   110         {
       
   111         iTypeChangeEnabled = ETrue;
       
   112         }
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CMRMultiCalenField::SetOutlineFocusL
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CMRMultiCalenField::SetOutlineFocusL( TBool aFocus )
       
   120     {
       
   121     FUNC_LOG;
       
   122     CESMRField::SetOutlineFocusL ( aFocus );
       
   123 
       
   124     //Focus gained
       
   125     if ( aFocus )
       
   126         {
       
   127         ChangeMiddleSoftKeyL( 
       
   128                 EESMRCmdOpenMultiCalenSelectQuery, R_QTN_MSK_OPEN );
       
   129         }
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // CMRMultiCalenField::ExecuteGenericCommandL
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 TBool CMRMultiCalenField::ExecuteGenericCommandL( TInt aCommand )
       
   137     {
       
   138     FUNC_LOG;
       
   139 
       
   140     TBool isUsed( EFalse );
       
   141     if( aCommand == EESMRCmdOpenMultiCalenSelectQuery ||
       
   142        aCommand == EAknCmdOpen )
       
   143         {
       
   144         if( IsLocked() )
       
   145         	{
       
   146 			HandleTactileFeedbackL();
       
   147 			
       
   148         	CESMRGlobalNote::ExecuteL(
       
   149         			CESMRGlobalNote::EESMRUnableToEdit );
       
   150         	isUsed = ETrue;
       
   151 			}
       
   152         		    	
       
   153 		else if( iTypeChangeEnabled )
       
   154             {
       
   155 		    ExecuteTypeQueryL();
       
   156             isUsed = ETrue;
       
   157             
       
   158     		HandleTactileFeedbackL();
       
   159             }
       
   160         }
       
   161 
       
   162     return isUsed;
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // CMRMultiCalenField::Lock
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 void CMRMultiCalenField::LockL()
       
   170 	{
       
   171 	FUNC_LOG;
       
   172 	if( IsLocked() )
       
   173 		{
       
   174 		return;
       
   175 		}
       
   176 
       
   177 	CESMRField::LockL();
       
   178 
       
   179 	delete iLockIcon;	
       
   180 	iLockIcon = NULL;
       
   181 	iLockIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapLockField, ETrue );
       
   182 	iIcon->SetParent( this );		
       
   183 	}
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // CMRMultiCalenField::ExecuteTypeQueryL
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 void CMRMultiCalenField::ExecuteTypeQueryL()
       
   190     {
       
   191     FUNC_LOG;
       
   192     if ( FieldMode() == EESMRFieldModeView )
       
   193     	return;
       
   194 
       
   195     TInt ret =
       
   196         CESMRListQuery::ExecuteL(
       
   197                 CESMRListQuery::EESMRMultiCalenQuery,
       
   198                 iCalenNameList );
       
   199 
       
   200     if ( ret != KErrCancel )
       
   201         {
       
   202         iIndex = ret;
       
   203         iEntry->GetDBMgr().SetCurCalendarByIndex( iIndex );
       
   204 
       
   205         // Send command to dialog
       
   206         NotifyEventAsyncL( EESMRCmdCalendarChange );
       
   207         UpdateLabelL( ret );
       
   208         }
       
   209     }
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // CMRMultiCalenField::CMRMultiCalenField
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 CMRMultiCalenField::CMRMultiCalenField( ) :
       
   216     iIndex( 0 )
       
   217     {
       
   218     FUNC_LOG;
       
   219     SetFieldId( EESMRFieldCalendarName );
       
   220     SetFocusType( EESMRHighlightFocus );
       
   221     }
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 // CMRMultiCalenField::ConstructL
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 void CMRMultiCalenField::ConstructL( )
       
   228     {
       
   229     FUNC_LOG;
       
   230 
       
   231     iCalenName = CMRLabel::NewL();
       
   232     CESMRField::ConstructL( iCalenName );
       
   233     iCalenName->SetTextL( KNullDesC() );
       
   234 
       
   235     TGulAlignment align;
       
   236     align.SetHAlignment( EHLeft );
       
   237     align.SetVAlignment( EVCenter );
       
   238     iCalenName->SetAlignment( align );
       
   239 
       
   240     iIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapCalendarSelection );
       
   241     
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // CMRMultiCalenField::UpdateLabelL
       
   246 // ---------------------------------------------------------------------------
       
   247 //
       
   248 void CMRMultiCalenField::UpdateLabelL( TInt aIndex )
       
   249     {
       
   250     FUNC_LOG;
       
   251 
       
   252     iCalenName->SetTextL( iCalenNameList[aIndex] );
       
   253     iCalenName->DrawDeferred();
       
   254     }
       
   255 
       
   256 // ---------------------------------------------------------------------------
       
   257 // CMRMultiCalenField::CountComponentControls
       
   258 // ---------------------------------------------------------------------------
       
   259 //
       
   260 TInt CMRMultiCalenField::CountComponentControls() const
       
   261     {
       
   262     FUNC_LOG;
       
   263     TInt count( 0 );
       
   264     if ( iIcon )
       
   265     	{
       
   266     	++count;
       
   267     	}
       
   268 
       
   269     if ( iCalenName )
       
   270     	{
       
   271     	++count;
       
   272     	}
       
   273     
       
   274     if ( iLockIcon )
       
   275     	{
       
   276     	++count;
       
   277     	}
       
   278     return count;
       
   279 
       
   280     }
       
   281 
       
   282 // ---------------------------------------------------------------------------
       
   283 // CMRMultiCalenField::ComponentControl
       
   284 // ---------------------------------------------------------------------------
       
   285 //
       
   286 CCoeControl* CMRMultiCalenField::ComponentControl( TInt aIndex ) const
       
   287     {
       
   288     FUNC_LOG;
       
   289     CCoeControl* control = NULL;
       
   290     switch( aIndex )
       
   291         {
       
   292         case 0:
       
   293             {
       
   294             control = iCalenName;
       
   295             break;
       
   296             }
       
   297         case 1:
       
   298             {
       
   299             control = iIcon;
       
   300             break;
       
   301             }
       
   302         case 2:
       
   303         	{
       
   304         	control = iLockIcon;
       
   305         	break;
       
   306         	}
       
   307         default:
       
   308             ASSERT( EFalse );
       
   309         }
       
   310 
       
   311     return control;
       
   312     }
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // CMRMultiCalenField::SizeChanged
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 void CMRMultiCalenField::SizeChanged()
       
   319     {
       
   320     FUNC_LOG;
       
   321     TRect rect( Rect() );
       
   322     TAknLayoutRect iconLayout =
       
   323         NMRLayoutManager::GetLayoutRect(
       
   324                 rect, NMRLayoutManager::EMRLayoutTextEditorIcon );
       
   325     TRect iconRect( iconLayout.Rect() );
       
   326     iIcon->SetRect( iconRect );
       
   327     
       
   328     // Layouting lock icon
       
   329     TAknLayoutRect rowLayoutRect( 
       
   330             NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 ) );
       
   331     TRect rowRect( rowLayoutRect.Rect() );
       
   332     if( iLockIcon )
       
   333         {
       
   334         TAknWindowComponentLayout iconLayout( 
       
   335                 NMRLayoutManager::GetWindowComponentLayout( 
       
   336                     NMRLayoutManager::EMRLayoutSingleRowDColumnGraphic ) );
       
   337         AknLayoutUtils::LayoutImage( iLockIcon, rowRect, iconLayout );
       
   338         }
       
   339 
       
   340     // Layouting label
       
   341     TAknLayoutText viewerLayoutText;
       
   342     if( iLockIcon )
       
   343     	{
       
   344     	viewerLayoutText = NMRLayoutManager::GetLayoutText( rowRect, 
       
   345     			NMRLayoutManager::EMRTextLayoutSingleRowEditorText );
       
   346     	}
       
   347     else
       
   348     	{
       
   349     	viewerLayoutText = NMRLayoutManager::GetLayoutText( rowRect, 
       
   350     			NMRLayoutManager::EMRTextLayoutTextEditor );
       
   351     	}
       
   352 
       
   353     TRect viewerRect( viewerLayoutText.TextRect() );    
       
   354     iCalenName->SetRect( viewerRect );
       
   355     
       
   356     // Move focus rect so that it's relative to field's position.
       
   357     viewerRect.Move( -Position() );
       
   358     SetFocusRect( viewerRect );
       
   359     }
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // CMRMultiCalenField::SetContainerWindowL
       
   363 // ---------------------------------------------------------------------------
       
   364 //
       
   365 void CMRMultiCalenField::SetContainerWindowL(
       
   366         const CCoeControl& aContainer )
       
   367     {
       
   368     FUNC_LOG;
       
   369     CCoeControl::SetContainerWindowL( aContainer );
       
   370     iCalenName->SetContainerWindowL( aContainer );
       
   371     iCalenName->SetParent( this );
       
   372     iIcon->SetContainerWindowL( aContainer );
       
   373     iIcon->SetParent( this );
       
   374     }
       
   375 
       
   376 // ---------------------------------------------------------------------------
       
   377 // CMRMultiCalenField::SetTextDimmed
       
   378 // ---------------------------------------------------------------------------
       
   379 //
       
   380 void CMRMultiCalenField::SetTextDimmed()
       
   381     {
       
   382     FUNC_LOG;
       
   383     
       
   384     NMRColorManager::SetColor(
       
   385             *iCalenName, 
       
   386             NMRColorManager::EMRMainAreaTextColorDimmed );
       
   387     }
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // CMRMultiCalenField::TypeChangeEnabledL
       
   391 // ---------------------------------------------------------------------------
       
   392 //
       
   393 TBool CMRMultiCalenField::TypeChangeEnabledL()
       
   394     {  
       
   395     TBool ret( ETrue );
       
   396     
       
   397     /*
       
   398      * Case 1:
       
   399      * If entry is single occurancy of a series, calendar type change  
       
   400      * is disabled for the user.
       
   401      */
       
   402     if( iEntry->IsRecurrentEventL() && 
       
   403             iEntry->RecurrenceModRule() == MESMRCalEntry::EESMRThisOnly &&
       
   404                 FieldMode() == EESMRFieldModeEdit )
       
   405         {
       
   406         ret = EFalse;
       
   407         }
       
   408     
       
   409     /*
       
   410      * Case 2:
       
   411      * If entry is meeting request, and opened from mailbox that does not
       
   412      * support multiple calendar, calendar type change is disabled 
       
   413      * for the user.
       
   414      */
       
   415     if( ret && CCalenInterimUtils2::IsMeetingRequestL( iEntry->Entry() ) &&
       
   416             FieldMode() == EESMRFieldModeEdit )
       
   417         {
       
   418         MESMRMeetingRequestEntry* entry = 
       
   419             static_cast< MESMRMeetingRequestEntry* >( iEntry );
       
   420         
       
   421         // If entry's current plugin is active sync, it means that 
       
   422         // Mail For Exchange is in use. This means, that multiple calendar 
       
   423         // functionality is not supported.
       
   424         if( entry->CurrentPluginL() == EESMRActiveSync )
       
   425             {
       
   426             ret = EFalse;
       
   427             }
       
   428         }
       
   429     
       
   430     /*
       
   431      * Case 3:
       
   432 	 * When the organizer of the MR edits an already sent MR, calendar 
       
   433 	 * cannot be changed --> calendar selection needs to be locked.
       
   434      */
       
   435     if( ret && CCalenInterimUtils2::IsMeetingRequestL( iEntry->Entry() ) &&
       
   436             FieldMode() == EESMRFieldModeEdit )
       
   437     	{
       
   438 		MESMRMeetingRequestEntry* entry = 
       
   439 				static_cast< MESMRMeetingRequestEntry* >( iEntry );
       
   440 		if( entry->RoleL() == EESMRRoleOrganizer && entry->IsSentL() )
       
   441 			{
       
   442 			ret = EFalse;    
       
   443 			}
       
   444     	}
       
   445     
       
   446     return ret;
       
   447     }
       
   448 
       
   449 // EOF
       
   450