calendarui/editors/src/calendbfield.cpp
changeset 0 f979ecb2b13e
child 13 1984aceb8774
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     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:  To handle Calendar Db filed
       
    15 *
       
    16 */
       
    17 
       
    18 // system includes
       
    19 #include <AknPopupField.h>
       
    20 #include <AknQueryValueText.h>
       
    21 #include <badesca.h>
       
    22 #include <calentry.h>
       
    23 #include <centralrepository.h>
       
    24 #include <CalenDefaultEditorsData.rsg>
       
    25 #include <calsession.h>
       
    26 #include <calencontext.h>
       
    27 #include <caleninstanceid.h>            // TCalenInstanceId
       
    28 #include <calenservices.h>
       
    29 #include <calcalendarinfo.h>
       
    30 
       
    31 // user includes
       
    32 #include "calendbfield.h"
       
    33 #include "CalenDefaultEditors.hrh"
       
    34 #include "calenunifiededitor.h"
       
    35 #include "CalendarPrivateCRKeys.h"
       
    36 #include "calendarui_debug.h"
       
    37 
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CCalenDbField::NewL
       
    41 // First Phase constuctor
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CCalenDbField* CCalenDbField::NewL( CCalenUnifiedEditor& aUnifiedEditor,MCalenServices& aServices  )
       
    45     {
       
    46     TRACE_ENTRY_POINT;
       
    47 
       
    48     CCalenDbField* self = 
       
    49         new( ELeave ) CCalenDbField( aUnifiedEditor, aServices );
       
    50     CleanupStack::PushL( self );
       
    51     self->ConstructL();
       
    52     CleanupStack::Pop();
       
    53 
       
    54     TRACE_EXIT_POINT;
       
    55     return self;
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CCalenDbField::CCalenDbField
       
    60 // C++ constructor
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CCalenDbField::CCalenDbField( CCalenUnifiedEditor& aUnifiedEditor,MCalenServices& aServices )
       
    64     : iUnifiedEditor( aUnifiedEditor ),
       
    65     iServices(&aServices)
       
    66     {
       
    67     TRACE_ENTRY_POINT;
       
    68     TRACE_EXIT_POINT;
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CCalenDbField::ConstructL
       
    73 // second phase constructor
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 void CCalenDbField::ConstructL()
       
    77     {
       
    78     TRACE_ENTRY_POINT;    
       
    79     
       
    80     //Get MultipleDbInfo array
       
    81     RPointerArray<CCalCalendarInfo>  calendarInfoList; 
       
    82     iServices->GetAllCalendarInfoL(calendarInfoList);
       
    83     CleanupClosePushL( calendarInfoList );
       
    84     
       
    85     iDbNamesArrayText = new ( ELeave ) CDesCArrayFlat( calendarInfoList.Count()+1 );
       
    86     
       
    87     for(TInt i=0 ; i < calendarInfoList.Count();i++ )
       
    88     	{
       
    89     	HBufC* calendarName=( *calendarInfoList[i] ).NameL().AllocLC();
       
    90     	iDbNamesArrayText->AppendL( *calendarName );   
       
    91     	CleanupStack::PopAndDestroy( calendarName ); 	
       
    92     	}  
       
    93     CleanupStack::PopAndDestroy( &calendarInfoList );
       
    94     
       
    95     // create textarray
       
    96     iDbNamesArray = CAknQueryValueTextArray::NewL();
       
    97     iDbNamesArray->SetArray( *iDbNamesArrayText );
       
    98 
       
    99     iDbNamesTextValues = CAknQueryValueText::NewL();
       
   100     iDbNamesTextValues->SetArrayL( iDbNamesArray );    
       
   101   
       
   102     TRACE_EXIT_POINT;
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CCalenDbField::~CCalenDbField
       
   107 // (other items were commented in a header).
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 CCalenDbField::~CCalenDbField()
       
   111     {
       
   112     TRACE_ENTRY_POINT;
       
   113 
       
   114     delete iDbNamesArrayText;
       
   115     delete iDbNamesArray;
       
   116     delete iDbNamesTextValues;
       
   117     delete iCalendarFileName;
       
   118    
       
   119     TRACE_EXIT_POINT;
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CCalenDbField::InitDbFieldLayoutL
       
   124 // Updates fields just before the form is shown.
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CCalenDbField::InitDbFieldLayoutL()
       
   128     {
       
   129     TRACE_ENTRY_POINT;
       
   130 
       
   131     CAknPopupField* pops =
       
   132         static_cast<CAknPopupField*>( iUnifiedEditor.Control( ECalenEditorDBName ) );
       
   133     pops->SetQueryValueL( iDbNamesTextValues ); 
       
   134 
       
   135     TRACE_EXIT_POINT;
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CCalenDbField::SetDataToEditorL
       
   140 // update data in form
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 void CCalenDbField::SetDataToEditorL()
       
   144     {
       
   145     TRACE_ENTRY_POINT;
       
   146     //Get MultipleDbInfo array
       
   147     RPointerArray<CCalCalendarInfo> calendarInfoList;
       
   148     iServices->GetAllCalendarInfoL(calendarInfoList);
       
   149     CleanupClosePushL(calendarInfoList);
       
   150 
       
   151     TInt index = KErrNotFound;
       
   152     if (iUnifiedEditor.IsCreatingNewEntry())
       
   153         {
       
   154         TBuf<KMaxFileName> lastUsedCalendar;
       
   155         CRepository* cenRep = CRepository::NewLC(KCRUidCalendar);
       
   156         User::LeaveIfError(cenRep->Get(KCalendarLastUsedCalendar,
       
   157                 lastUsedCalendar));
       
   158         
       
   159         HBufC* name = lastUsedCalendar.AllocLC();
       
   160         index = calendarInfoList.Find(*name,
       
   161                 CCalenDbField::CalendarInfoNameIdentifierL);
       
   162         
       
   163         if (KErrNotFound == index)
       
   164             {
       
   165             User::LeaveIfError(cenRep->Set(KCalendarLastUsedCalendar,
       
   166                     name->Des()));
       
   167             }
       
   168         
       
   169         CleanupStack::PopAndDestroy(name);
       
   170         CleanupStack::PopAndDestroy(cenRep);
       
   171         }
       
   172     else
       
   173         {
       
   174         TCalCollectionId colId = iServices->Context().InstanceId().iColId;
       
   175         HBufC* calendarFileName= iServices->GetCalFileNameForCollectionId(colId).AllocLC();
       
   176         index = calendarInfoList.Find(*calendarFileName,
       
   177                 CCalenDbField::CalendarInfoNameIdentifierL);
       
   178         CleanupStack::PopAndDestroy(calendarFileName);
       
   179         }
       
   180 
       
   181     if (index != KErrNotFound)
       
   182         {
       
   183         iDbNamesTextValues->SetCurrentValueIndex(index);
       
   184         }
       
   185 
       
   186     if (KErrNotFound == index)
       
   187         {
       
   188         iDbNamesTextValues->SetCurrentValueIndex(0);
       
   189         }
       
   190 
       
   191     TInt pos = iDbNamesTextValues->CurrentValueIndex();
       
   192     HBufC* calendarFileName = calendarInfoList[pos]->FileNameL().AllocLC();
       
   193     iPreviousColId = iCurrentColId
       
   194             = iServices->SessionL(*calendarFileName).CollectionIdL();
       
   195     CleanupStack::PopAndDestroy(calendarFileName);
       
   196 
       
   197     iUnifiedEditor.EditorDataHandler().SetCalendarFieldEditedL(
       
   198             IsCalendarEdited(), iPreviousColId, iCurrentColId);
       
   199 
       
   200     CleanupStack::PopAndDestroy(&calendarInfoList);
       
   201    
       
   202     TRACE_EXIT_POINT;
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CCalenDbField::HandleControlStateChangeL
       
   207 // (other items were commented in a header).
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 void CCalenDbField::HandleControlStateChangeL( TInt aControlId )
       
   211     {
       
   212     TRACE_ENTRY_POINT;
       
   213     
       
   214     switch(aControlId)
       
   215         {
       
   216         case ECalenEditorDBName:
       
   217             {
       
   218             TBool continueOnError = EFalse;
       
   219             ReadDataFromFormL( continueOnError );
       
   220             iUnifiedEditor.EditorDataHandler().SetCalendarFieldEditedL(IsCalendarEdited()
       
   221                                                             ,iPreviousColId,iCurrentColId);
       
   222             break;
       
   223             }
       
   224         default: 
       
   225             break;
       
   226         }               
       
   227     
       
   228     TRACE_EXIT_POINT;
       
   229     }
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CCalenDbField::ReadDataFromFormL
       
   233 // (other items were commented in a header).
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 void CCalenDbField::ReadDataFromFormL( TBool /*aContinueOnError*/ )
       
   237     {
       
   238     TRACE_ENTRY_POINT;
       
   239     
       
   240     RPointerArray<CCalCalendarInfo> calendarInfoList; 
       
   241     iServices->GetAllCalendarInfoL(calendarInfoList);
       
   242     CleanupClosePushL( calendarInfoList );
       
   243     TInt pos = iDbNamesTextValues->CurrentValueIndex();
       
   244     HBufC* calendarFileName = calendarInfoList[pos]->FileNameL().AllocLC();
       
   245     iCurrentColId = iServices->SessionL(*calendarFileName).CollectionIdL();
       
   246     CleanupStack::PopAndDestroy(calendarFileName);
       
   247     CleanupStack::PopAndDestroy( &calendarInfoList );
       
   248 
       
   249     TRACE_EXIT_POINT;
       
   250     }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CCalenDbField::PrepareForFocusTransitionL
       
   254 // (other items were commented in a header).
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 void CCalenDbField::PrepareForFocusTransitionL( TInt aFocusedId )
       
   258     {
       
   259     TRACE_ENTRY_POINT;
       
   260 
       
   261     switch(aFocusedId)
       
   262         {
       
   263         case ECalenEditorDBName:
       
   264             {
       
   265             TBool continueOnError = EFalse;
       
   266             ReadDataFromFormL( continueOnError );
       
   267             break;
       
   268             }
       
   269         default: 
       
   270             break;
       
   271         }				
       
   272     TRACE_EXIT_POINT;
       
   273     }
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // CCalenDbField::GetCalendarIndexForEntryL
       
   277 // (other items were commented in a header).
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 TInt CCalenDbField::GetCalendarIndexForEntryL()
       
   281     {
       
   282     TRACE_ENTRY_POINT;
       
   283     TRACE_EXIT_POINT;
       
   284     return iDbNamesTextValues->CurrentValueIndex();;
       
   285     }
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // CCalenDbField::GetCalendarNameForEntryL
       
   289 // get calendar name for the entry
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 const TDesC& CCalenDbField::GetCalendarNameForEntryL()
       
   293     {
       
   294     TRACE_ENTRY_POINT
       
   295     
       
   296     if(iCalendarFileName)
       
   297         {
       
   298         delete iCalendarFileName;
       
   299         iCalendarFileName = NULL;
       
   300         }
       
   301     
       
   302     RPointerArray<CCalCalendarInfo> calendarInfoList; 
       
   303     iServices->GetAllCalendarInfoL(calendarInfoList);
       
   304     CleanupClosePushL( calendarInfoList );
       
   305     TInt pos = iDbNamesTextValues->CurrentValueIndex();
       
   306     iCalendarFileName = calendarInfoList[pos]->FileNameL().AllocL();
       
   307     CleanupStack::PopAndDestroy( &calendarInfoList );
       
   308     
       
   309     TRACE_EXIT_POINT
       
   310     return *iCalendarFileName;
       
   311     }
       
   312 	
       
   313 // -----------------------------------------------------------------------------
       
   314 // CCalenDbField::IsCalendarEdited
       
   315 // (other items were commented in a header).
       
   316 // -----------------------------------------------------------------------------
       
   317 //	
       
   318 TBool CCalenDbField::IsCalendarEdited()
       
   319     {
       
   320     TRACE_ENTRY_POINT
       
   321     TRACE_EXIT_POINT
       
   322     return (iPreviousColId != iCurrentColId);
       
   323     }
       
   324 
       
   325 // -----------------------------------------------------------------------------
       
   326 // CCalenDbField::CalendarInfoNameIdentifierL
       
   327 // (other items were commented in a header).
       
   328 // -----------------------------------------------------------------------------
       
   329 //  
       
   330 TBool CCalenDbField::CalendarInfoNameIdentifierL( const HBufC* aName,
       
   331                                            const CCalCalendarInfo& aInfoItem )
       
   332     {
       
   333     TRACE_ENTRY_POINT;
       
   334     TPtrC calendarFileName = aInfoItem.FileNameL();
       
   335     TRACE_EXIT_POINT;
       
   336     return (!calendarFileName.CompareF(*aName));
       
   337     }
       
   338 // End of File