calendarui/editors/src/calendbfield.cpp
branchRCL_3
changeset 30 bd7edf625bdd
child 31 97232defd20e
equal deleted inserted replaced
29:12af337248b1 30:bd7edf625bdd
       
     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 <AknQueryDialog.h>
       
    22 #include <badesca.h>
       
    23 #include <calentry.h>
       
    24 #include <centralrepository.h>
       
    25 #include <CalenDefaultEditorsData.rsg>
       
    26 #include <calsession.h>
       
    27 #include <calencontext.h>
       
    28 #include <caleninstanceid.h>            // TCalenInstanceId
       
    29 #include <calenservices.h>
       
    30 #include <calcalendarinfo.h>
       
    31 
       
    32 // user includes
       
    33 #include "calendbfield.h"
       
    34 #include "CalenDefaultEditors.hrh"
       
    35 #include "calenunifiededitor.h"
       
    36 #include "CalendarPrivateCRKeys.h"
       
    37 #include "CleanupResetAndDestroy.h"
       
    38 #include "calendarui_debug.h"
       
    39 
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CCalenDbField::NewL
       
    43 // First Phase constuctor
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CCalenDbField* CCalenDbField::NewL( CCalenUnifiedEditor& aUnifiedEditor,MCalenServices& aServices  )
       
    47     {
       
    48     TRACE_ENTRY_POINT;
       
    49 
       
    50     CCalenDbField* self = 
       
    51         new( ELeave ) CCalenDbField( aUnifiedEditor, aServices );
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL();
       
    54     CleanupStack::Pop();
       
    55 
       
    56     TRACE_EXIT_POINT;
       
    57     return self;
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CCalenDbField::CCalenDbField
       
    62 // C++ constructor
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CCalenDbField::CCalenDbField( CCalenUnifiedEditor& aUnifiedEditor,MCalenServices& aServices )
       
    66     : iUnifiedEditor( aUnifiedEditor ),
       
    67     iServices(&aServices)
       
    68     {
       
    69     TRACE_ENTRY_POINT;
       
    70     TRACE_EXIT_POINT;
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CCalenDbField::ConstructL
       
    75 // second phase constructor
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void CCalenDbField::ConstructL()
       
    79     {
       
    80     TRACE_ENTRY_POINT;    
       
    81     
       
    82     //Get MultipleDbInfo array
       
    83     RPointerArray<CCalCalendarInfo>  calendarInfoList; 
       
    84     iServices->GetAllCalendarInfoL(calendarInfoList);
       
    85     CleanupClosePushL( calendarInfoList );
       
    86     
       
    87     iDbNamesArrayText = new ( ELeave ) CDesCArrayFlat( calendarInfoList.Count()+1 );
       
    88     
       
    89     for(TInt i=0 ; i < calendarInfoList.Count();i++ )
       
    90     	{
       
    91     	HBufC* calendarName=( *calendarInfoList[i] ).NameL().AllocLC();
       
    92     	iDbNamesArrayText->AppendL( *calendarName );   
       
    93     	CleanupStack::PopAndDestroy( calendarName ); 	
       
    94     	}  
       
    95     CleanupStack::PopAndDestroy( &calendarInfoList );
       
    96     
       
    97     // create textarray
       
    98     iDbNamesArray = CAknQueryValueTextArray::NewL();
       
    99     iDbNamesArray->SetArray( *iDbNamesArrayText );
       
   100 
       
   101     iDbNamesTextValues = CAknQueryValueText::NewL();
       
   102     iDbNamesTextValues->SetArrayL( iDbNamesArray );    
       
   103   
       
   104     TRACE_EXIT_POINT;
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CCalenDbField::~CCalenDbField
       
   109 // (other items were commented in a header).
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 CCalenDbField::~CCalenDbField()
       
   113     {
       
   114     TRACE_ENTRY_POINT;
       
   115 
       
   116     if( iAsyncDBquery )
       
   117         {
       
   118         iAsyncDBquery->Cancel();
       
   119         delete iAsyncDBquery;
       
   120         iAsyncDBquery = NULL;
       
   121         }
       
   122     
       
   123     delete iDbNamesArrayText;
       
   124     delete iDbNamesArray;
       
   125     delete iDbNamesTextValues;
       
   126     delete iCalendarFileName;
       
   127    
       
   128     TRACE_EXIT_POINT;
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CCalenDbField::InitDbFieldLayoutL
       
   133 // Updates fields just before the form is shown.
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CCalenDbField::InitDbFieldLayoutL()
       
   137     {
       
   138     TRACE_ENTRY_POINT;
       
   139 
       
   140     CAknPopupField* pops =
       
   141         static_cast<CAknPopupField*>( iUnifiedEditor.Control( ECalenEditorDBName ) );
       
   142     pops->SetQueryValueL( iDbNamesTextValues ); 
       
   143 
       
   144     TRACE_EXIT_POINT;
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CCalenDbField::SetDataToEditorL
       
   149 // update data in form
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 void CCalenDbField::SetDataToEditorL()
       
   153     {
       
   154     TRACE_ENTRY_POINT;
       
   155     //Get MultipleDbInfo array
       
   156     RPointerArray<CCalCalendarInfo> calendarInfoList;
       
   157     iServices->GetAllCalendarInfoL(calendarInfoList);
       
   158     CleanupClosePushL(calendarInfoList);
       
   159 
       
   160     TInt index = KErrNotFound;
       
   161     if (iUnifiedEditor.IsCreatingNewEntry())
       
   162         {
       
   163         TBuf<KMaxFileName> lastUsedCalendar;
       
   164         CRepository* cenRep = CRepository::NewLC(KCRUidCalendar);
       
   165         User::LeaveIfError(cenRep->Get(KCalendarLastUsedCalendar,
       
   166                 lastUsedCalendar));
       
   167         
       
   168         HBufC* name = lastUsedCalendar.AllocLC();
       
   169         index = calendarInfoList.Find(*name,
       
   170                 CCalenDbField::CalendarInfoNameIdentifierL);
       
   171         
       
   172         if (KErrNotFound == index)
       
   173             {
       
   174             User::LeaveIfError(cenRep->Set(KCalendarLastUsedCalendar,
       
   175                     name->Des()));
       
   176             }
       
   177         
       
   178         CleanupStack::PopAndDestroy(name);
       
   179         CleanupStack::PopAndDestroy(cenRep);
       
   180         }
       
   181     else
       
   182         {
       
   183         TCalCollectionId colId = iServices->Context().InstanceId().iColId;
       
   184         HBufC* calendarFileName= iServices->GetCalFileNameForCollectionId(colId).AllocLC();
       
   185         index = calendarInfoList.Find(*calendarFileName,
       
   186                 CCalenDbField::CalendarInfoNameIdentifierL);
       
   187         CleanupStack::PopAndDestroy(calendarFileName);
       
   188         }
       
   189 
       
   190     if (index != KErrNotFound)
       
   191         {
       
   192         iDbNamesTextValues->SetCurrentValueIndex(index);
       
   193         }
       
   194 
       
   195     if (KErrNotFound == index)
       
   196         {
       
   197         iDbNamesTextValues->SetCurrentValueIndex(0);
       
   198         }
       
   199 
       
   200     TInt pos = iDbNamesTextValues->CurrentValueIndex();
       
   201     HBufC* calendarFileName = calendarInfoList[pos]->FileNameL().AllocLC();
       
   202     iPreviousColId = iCurrentColId
       
   203             = iServices->SessionL(*calendarFileName).CollectionIdL();
       
   204     CleanupStack::PopAndDestroy(calendarFileName);
       
   205 
       
   206     iUnifiedEditor.EditorDataHandler().SetCalendarFieldEditedL(
       
   207             IsCalendarEdited(), iPreviousColId, iCurrentColId);
       
   208 
       
   209     CleanupStack::PopAndDestroy(&calendarInfoList);
       
   210    
       
   211     TRACE_EXIT_POINT;
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CCalenDbField::SetDataToEditorL
       
   216 // update data in form
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 void CCalenDbField::SetDataToEditorL(const TCalCollectionId& aColId)
       
   220     {
       
   221     TRACE_ENTRY_POINT;
       
   222     //Get MultipleDbInfo array
       
   223     RPointerArray<CCalCalendarInfo> calendarInfoList;
       
   224     iServices->GetAllCalendarInfoL(calendarInfoList);
       
   225     CleanupClosePushL(calendarInfoList);
       
   226 
       
   227     TInt index = KErrNotFound;   
       
   228     
       
   229     HBufC* calendarFileName= iServices->GetCalFileNameForCollectionId(aColId).AllocLC();
       
   230     index = calendarInfoList.Find(*calendarFileName, CCalenDbField::CalendarInfoNameIdentifierL);
       
   231     CleanupStack::PopAndDestroy(calendarFileName);        
       
   232     
       
   233     if (KErrNotFound == index)
       
   234         {
       
   235         iDbNamesTextValues->SetCurrentValueIndex(0);
       
   236         }
       
   237     else
       
   238         {
       
   239         iDbNamesTextValues->SetCurrentValueIndex(index);
       
   240         }
       
   241     iUnifiedEditor.EditorDataHandler().SetCalendarFieldEditedL(
       
   242             IsCalendarEdited(), iPreviousColId, iCurrentColId);
       
   243 
       
   244     CleanupStack::PopAndDestroy(&calendarInfoList);
       
   245    
       
   246     TRACE_EXIT_POINT;
       
   247     }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CCalenDbField::HandleControlStateChangeL
       
   251 // (other items were commented in a header).
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 void CCalenDbField::HandleControlStateChangeL( TInt aControlId )
       
   255     {
       
   256     TRACE_ENTRY_POINT;
       
   257     
       
   258     switch(aControlId)
       
   259         {
       
   260         case ECalenEditorDBName:
       
   261             {
       
   262             TBool continueOnError = EFalse;
       
   263             ReadDataFromFormL( continueOnError );
       
   264             iUnifiedEditor.EditorDataHandler().SetCalendarFieldEditedL(IsCalendarEdited()
       
   265                                                             ,iPreviousColId,iCurrentColId);
       
   266             
       
   267             TCallBack callback(DoAsyncShowChangeDBQueryL,this);
       
   268             iAsyncDBquery = new(ELeave) CAsyncCallBack(callback,CActive::EPriorityStandard);
       
   269             iAsyncDBquery->CallBack();
       
   270             break;
       
   271             }
       
   272         default: 
       
   273             break;
       
   274         }               
       
   275     
       
   276     TRACE_EXIT_POINT;
       
   277     }
       
   278 
       
   279 // ----------------------------------------------------------------------------
       
   280 // CallBackForShowinginfonote
       
   281 // (other items were commented in a header).
       
   282 // ----------------------------------------------------------------------------
       
   283 //
       
   284 TInt CCalenDbField::DoAsyncShowChangeDBQueryL(TAny* aThisPtr)
       
   285     {
       
   286     TRACE_ENTRY_POINT
       
   287     CCalenDbField* self = static_cast<CCalenDbField*>(aThisPtr);
       
   288     if(self)
       
   289         {
       
   290         self->ShowChangeDBQueryL();
       
   291         }
       
   292     TRACE_EXIT_POINT
       
   293     return 0;
       
   294     }
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CCalenDbField::ReadDataFromFormL
       
   298 // (other items were commented in a header).
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 void CCalenDbField::ReadDataFromFormL( TBool /*aContinueOnError*/ )
       
   302     {
       
   303     TRACE_ENTRY_POINT;
       
   304     
       
   305     RPointerArray<CCalCalendarInfo> calendarInfoList; 
       
   306     iServices->GetAllCalendarInfoL(calendarInfoList);
       
   307     CleanupClosePushL( calendarInfoList );
       
   308     TInt pos;
       
   309     if( calendarInfoList.Count() == 1 )
       
   310         {
       
   311          pos = 0;
       
   312         }
       
   313     else
       
   314         {
       
   315         pos = iDbNamesTextValues->CurrentValueIndex();
       
   316         }
       
   317     
       
   318     HBufC* calendarFileName = calendarInfoList[pos]->FileNameL().AllocLC();
       
   319     iCurrentColId = iServices->SessionL(*calendarFileName).CollectionIdL();
       
   320     CleanupStack::PopAndDestroy(calendarFileName);
       
   321     CleanupStack::PopAndDestroy( &calendarInfoList );
       
   322 
       
   323     TRACE_EXIT_POINT;
       
   324     }
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CCalenDbField::PrepareForFocusTransitionL
       
   328 // (other items were commented in a header).
       
   329 // -----------------------------------------------------------------------------
       
   330 //
       
   331 void CCalenDbField::PrepareForFocusTransitionL( TInt aFocusedId )
       
   332     {
       
   333     TRACE_ENTRY_POINT;
       
   334 
       
   335     switch(aFocusedId)
       
   336         {
       
   337         case ECalenEditorDBName:
       
   338             {
       
   339             TBool continueOnError = EFalse;
       
   340             ReadDataFromFormL( continueOnError );
       
   341             break;
       
   342             }
       
   343         default: 
       
   344             break;
       
   345         }				
       
   346     TRACE_EXIT_POINT;
       
   347     }
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // CCalenDbField::GetCalendarIndexForEntryL
       
   351 // (other items were commented in a header).
       
   352 // -----------------------------------------------------------------------------
       
   353 //
       
   354 TInt CCalenDbField::GetCalendarIndexForEntryL()
       
   355     {
       
   356     TRACE_ENTRY_POINT;
       
   357     TRACE_EXIT_POINT;
       
   358     return iDbNamesTextValues->CurrentValueIndex();;
       
   359     }
       
   360 
       
   361 // -----------------------------------------------------------------------------
       
   362 // CCalenDbField::GetCalendarNameForEntryL
       
   363 // get calendar name for the entry
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 const TDesC& CCalenDbField::GetCalendarNameForEntryL()
       
   367     {
       
   368     TRACE_ENTRY_POINT
       
   369     
       
   370     if(iCalendarFileName)
       
   371         {
       
   372         delete iCalendarFileName;
       
   373         iCalendarFileName = NULL;
       
   374         }
       
   375     
       
   376     RPointerArray<CCalCalendarInfo> calendarInfoList; 
       
   377     iServices->GetAllCalendarInfoL(calendarInfoList);
       
   378     CleanupClosePushL( calendarInfoList );
       
   379     TInt pos = iDbNamesTextValues->CurrentValueIndex();
       
   380     iCalendarFileName = calendarInfoList[pos]->FileNameL().AllocL();
       
   381     CleanupStack::PopAndDestroy( &calendarInfoList );
       
   382     
       
   383     TRACE_EXIT_POINT
       
   384     return *iCalendarFileName;
       
   385     }
       
   386 
       
   387 // -----------------------------------------------------------------------------
       
   388 // CCalenDbField::GetCalendarNameForEntryL
       
   389 // get calendar index for the entry
       
   390 // -----------------------------------------------------------------------------
       
   391 //
       
   392 TInt CCalenDbField::GetCalendarNameForEntryL(const TDesC& aCalendarFileName)
       
   393     {
       
   394     TRACE_ENTRY_POINT
       
   395     __impl_prints(_L("CCalenDbField::GetCalendarNameForEntryL  2-- start"));
       
   396     HBufC* calendarFilename = aCalendarFileName.AllocLC();
       
   397     RPointerArray<CCalCalendarInfo> calendarInfoList; 
       
   398     iServices->GetAllCalendarInfoL(calendarInfoList);
       
   399     CleanupClosePushL( calendarInfoList );
       
   400     __impl_prints(_L("CCalenDbField::GetCalendarNameForEntryL -- GetAllCalendarInfoL"));
       
   401     TInt index = calendarInfoList.Find(*calendarFilename,
       
   402             CCalenDbField::CalendarInfoNameIdentifierL);
       
   403     __impl_print(_L("CCalenDbField::GetCalendarNameForEntryL 2 -- index = %d"),index);
       
   404     CleanupStack::PopAndDestroy(calendarFilename);     
       
   405     CleanupStack::PopAndDestroy( &calendarInfoList );
       
   406     
       
   407     TRACE_EXIT_POINT
       
   408     return index;
       
   409     }
       
   410 	
       
   411 // -----------------------------------------------------------------------------
       
   412 // CCalenDbField::IsCalendarEdited
       
   413 // (other items were commented in a header).
       
   414 // -----------------------------------------------------------------------------
       
   415 //	
       
   416 TBool CCalenDbField::IsCalendarEdited()
       
   417     {
       
   418     TRACE_ENTRY_POINT
       
   419     TRACE_EXIT_POINT
       
   420     return (iPreviousColId != iCurrentColId);
       
   421     }
       
   422 
       
   423 // -----------------------------------------------------------------------------
       
   424 // CCalenDbField::CalendarInfoNameIdentifierL
       
   425 // (other items were commented in a header).
       
   426 // -----------------------------------------------------------------------------
       
   427 //  
       
   428 TBool CCalenDbField::CalendarInfoNameIdentifierL( const HBufC* aName,
       
   429                                            const CCalCalendarInfo& aInfoItem )
       
   430     {
       
   431     TRACE_ENTRY_POINT;
       
   432     TPtrC calendarFileName = aInfoItem.FileNameL();
       
   433     TRACE_EXIT_POINT;
       
   434     return (!calendarFileName.CompareF(*aName));
       
   435     }
       
   436 // -----------------------------------------------------------------------------
       
   437 // CCalenDbField::ShowChangeDBQueryL
       
   438 // (other items were commented in a header).
       
   439 // -----------------------------------------------------------------------------
       
   440 //  
       
   441 void CCalenDbField::ShowChangeDBQueryL()
       
   442     {
       
   443     
       
   444     //Check the child entries for the repeated entry
       
   445     //The entry which is changing the calendar having any childs 
       
   446     //show this information note to the user.
       
   447     CCalEntry& originalEntry = iUnifiedEditor.EditorDataHandler().Entry();
       
   448     RPointerArray<CCalEntry> childEntries;
       
   449     CleanupResetAndDestroyPushL(childEntries);
       
   450     iServices->EntryViewL(iPreviousColId)->FetchL(originalEntry.UidL(), childEntries);            
       
   451     if(IsCalendarEdited() && (childEntries.Count() > 1))
       
   452         {
       
   453         TCalCollectionId  currentId = iCurrentColId;
       
   454         SetDataToEditorL();                    
       
   455         iUnifiedEditor.UpdateFormL();
       
   456         CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   457         if( dlg->ExecuteLD( R_CALEN_DB_CHANGE_QUERY ) )
       
   458             {
       
   459             iCurrentColId = currentId;
       
   460             SetDataToEditorL(iCurrentColId);
       
   461             iUnifiedEditor.UpdateFormL();
       
   462             }
       
   463         }            
       
   464     CleanupStack::PopAndDestroy( &childEntries );                
       
   465     }
       
   466 // End of File