calendarui/controller/src/calenmultipledbui.cpp
branchRCL_3
changeset 66 bd7edf625bdd
child 67 1539a383d7b6
child 86 ed599363c2d7
equal deleted inserted replaced
65:12af337248b1 66:bd7edf625bdd
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Container base class of Calendar application.
       
    15  *                This class is the derivation origin of Calendar container.
       
    16  *
       
    17 */
       
    18 
       
    19 // System includes
       
    20 #include <Calendar.rsg>
       
    21 #include <StringLoader.h>
       
    22 #include <AknsBasicBackgroundControlContext.h>
       
    23 #include <layoutmetadata.cdl.h>
       
    24 #include <aknconsts.h>
       
    25 #include <AknIconArray.h>
       
    26 #include <aknlists.h>
       
    27 #include <akntitle.h>
       
    28 #include <eikclbd.h>
       
    29 #include <aknnavi.h>
       
    30 #include <gulicon.h>
       
    31 #include <aknenv.h>
       
    32 #include <aknnotewrappers.h> 
       
    33 #include <centralrepository.h>
       
    34 #include <aknlayoutscalable_apps.cdl.h>
       
    35 #include <AknIconUtils.h>
       
    36 #include <aknbutton.h>
       
    37 #include <akntoolbar.h>
       
    38 #include <avkon.mbg>
       
    39 #include <calencommonui.rsg>
       
    40 #include <calentoolbar.h>
       
    41 #include <calcalendarinfo.h>
       
    42 #include <CalenInterimUtils2.h>
       
    43 #include <calenmulticalutil.h>
       
    44 #include <calenmulticaluids.hrh>
       
    45 #include <featmgr.h>
       
    46 #include <hlplch.h>
       
    47 #include <csxhelp/cale.hlp.hrh>
       
    48 #include <calencontext.h>
       
    49 #include <calenservices.h>
       
    50 
       
    51 // User includes
       
    52 #include "calendarui_debug.h"
       
    53 #include "calenmultipledbui.h"
       
    54 #include "calendar.hrh"
       
    55 #include "calenmultidbeditor.h"
       
    56 #include "CalendarPrivateCRKeys.h"
       
    57 #include "calencontroller.h"
       
    58 #include "CalenUid.h"
       
    59 
       
    60 // Constants
       
    61 _LIT( KListSeparatorFormat, "\t" );
       
    62 const TInt KMultiDbMaxLength = 300;
       
    63 const TInt KBuffLength = 24;
       
    64 
       
    65 
       
    66 
       
    67 // ----------------------------------------------------------------------------
       
    68 // CCalenMultipleDbListboxItemDrawer::CCalenMultipleDbListboxItemDrawer
       
    69 // Constructor
       
    70 // ----------------------------------------------------------------------------
       
    71 //
       
    72 CCalenMultipleDbListboxItemDrawer::CCalenMultipleDbListboxItemDrawer(
       
    73         MTextListBoxModel* aTextListBoxModel,
       
    74         const CFont* aFont,
       
    75         CFormattedCellListBoxData* aFormattedCellData,
       
    76         CEikListBox* aListBox ,
       
    77         const RArray<TInt32>& aColorUidArray )
       
    78     : CFormattedCellListBoxItemDrawer(aTextListBoxModel,aFont,aFormattedCellData),
       
    79       iListBox(aListBox),
       
    80       iColorUidArray(aColorUidArray)
       
    81     {
       
    82     TRACE_ENTRY_POINT
       
    83     TRACE_EXIT_POINT
       
    84     }
       
    85 
       
    86 // ----------------------------------------------------------------------------
       
    87 // CCalenMultipleDbListboxItemDrawer::CCalenMultipleDbListboxItemDrawer
       
    88 // ----------------------------------------------------------------------------
       
    89 //
       
    90 CCalenMultipleDbListboxItemDrawer::~CCalenMultipleDbListboxItemDrawer()
       
    91     {
       
    92     TRACE_ENTRY_POINT
       
    93     TRACE_EXIT_POINT
       
    94     }
       
    95 
       
    96 // ----------------------------------------------------------------------------
       
    97 // CCalenMultipleDbListboxItemDrawer::DrawItem
       
    98 // ----------------------------------------------------------------------------
       
    99 //
       
   100 void CCalenMultipleDbListboxItemDrawer::DrawItem(TInt aItemIndex, 
       
   101                                                        TPoint aItemRectPos, 
       
   102                                                        TBool aItemIsSelected, 
       
   103                                                        TBool aItemIsCurrent, 
       
   104                                                        TBool aViewIsEmphasized,
       
   105                                                        TBool aViewIsDimmed) const
       
   106      {
       
   107      TRACE_ENTRY_POINT
       
   108      TRect actualItemRect(aItemRectPos, iItemCellSize);
       
   109      SetupGc(aItemIndex);
       
   110          
       
   111      CFormattedCellListBoxItemDrawer::DrawItem(aItemIndex,
       
   112                                                     aItemRectPos,
       
   113                                                     aItemIsSelected,
       
   114                                                     aItemIsCurrent,
       
   115                                                     aViewIsEmphasized,
       
   116                                                     aViewIsDimmed);
       
   117      
       
   118      iGc->Reset();
       
   119              
       
   120      TAknWindowComponentLayout tempLayout = AknLayoutScalable_Apps::list_cale_time_pane_g6(0);     
       
   121 
       
   122      TAknLayoutRect colourstrips;
       
   123      colourstrips.LayoutRect( actualItemRect, tempLayout.LayoutLine() );
       
   124       
       
   125      iGc->SetPenColor( CGraphicsContext::ENullPen );
       
   126      iGc->DrawRect( colourstrips.Rect() );
       
   127      iGc->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   128      iGc->SetBrushColor( TRgb(iColorUidArray[aItemIndex] ));
       
   129      iGc->DrawRect( colourstrips.Rect() );
       
   130      
       
   131      iGc->Reset();
       
   132      
       
   133      TRACE_EXIT_POINT
       
   134      }
       
   135 
       
   136 // ----------------------------------------------------------------------------
       
   137 // CCalenMultipleDbListbox::DrawItem
       
   138 // ----------------------------------------------------------------------------
       
   139 //
       
   140 CCalenMultipleDbListbox::CCalenMultipleDbListbox(const RArray<TInt32>& aColorUidArray) :
       
   141                                                             iColorUidArray(aColorUidArray)
       
   142     {
       
   143     TRACE_ENTRY_POINT
       
   144     TRACE_EXIT_POINT
       
   145     }
       
   146                                                 
       
   147 // ----------------------------------------------------------------------------
       
   148 // CCalenMultipleDbListbox::CreateItemDrawerL
       
   149 // ----------------------------------------------------------------------------
       
   150 //
       
   151 void CCalenMultipleDbListbox::CreateItemDrawerL()
       
   152     {
       
   153     TRACE_ENTRY_POINT
       
   154     CFormattedCellListBoxData* cellData=CFormattedCellListBoxData::NewL();
       
   155     CleanupStack::PushL( cellData );
       
   156     iItemDrawer=new(ELeave) CCalenMultipleDbListboxItemDrawer(
       
   157                         Model(), iEikonEnv->NormalFont(), cellData, this,iColorUidArray);
       
   158     CleanupStack::Pop();
       
   159     TRACE_EXIT_POINT
       
   160     }
       
   161 
       
   162 // ----------------------------------------------------------------------------
       
   163 // CCalenMultipleDbListbox::CreateItemDrawerL
       
   164 // ----------------------------------------------------------------------------
       
   165 //
       
   166 void CCalenMultipleDbListbox::SizeChanged()
       
   167     {
       
   168     TRACE_ENTRY_POINT
       
   169     TRAP_IGNORE(SizeChangedL());
       
   170     TRACE_EXIT_POINT
       
   171     }
       
   172 
       
   173 // ----------------------------------------------------------------------------
       
   174 // CCalenMultipleDbListbox::SizeChangedL
       
   175 // ----------------------------------------------------------------------------
       
   176 //
       
   177 void CCalenMultipleDbListbox::SizeChangedL()
       
   178     {
       
   179     TRACE_ENTRY_POINT
       
   180     CAknDoubleGraphicStyleListBox::SizeChanged();
       
   181     TRACE_EXIT_POINT
       
   182     }
       
   183 
       
   184 // ----------------------------------------------------------------------------
       
   185 // CCalenMultipleDbUi::CCalenMultipleDbUi
       
   186 // Constructor
       
   187 // (other items were commented in a header).
       
   188 // ----------------------------------------------------------------------------
       
   189 //
       
   190 CCalenMultipleDbUi::CCalenMultipleDbUi(CCalenController& aController) : 
       
   191     iController(aController)
       
   192     {
       
   193     TRACE_ENTRY_POINT;
       
   194     TRACE_EXIT_POINT;
       
   195     }
       
   196 
       
   197 // ----------------------------------------------------------------------------
       
   198 // CCalenMultipleDbUi::CCalenEditUi
       
   199 // First stage construction
       
   200 // (other items were commented in a header).
       
   201 // ----------------------------------------------------------------------------
       
   202 //
       
   203 CCalenMultipleDbUi* CCalenMultipleDbUi::NewL(CCalenController& aController)
       
   204     {
       
   205     TRACE_ENTRY_POINT;
       
   206     CCalenMultipleDbUi* self = new(ELeave) CCalenMultipleDbUi(aController);
       
   207     CleanupStack::PushL(self);
       
   208     self->ConstructL();
       
   209     CleanupStack::Pop(self);
       
   210     TRACE_EXIT_POINT;
       
   211     return self;
       
   212     }
       
   213 
       
   214 // ----------------------------------------------------------------------------
       
   215 // CCalenMultipleDbUi::ConstructL
       
   216 // Second stage construction
       
   217 // (other items were commented in a header).
       
   218 // ----------------------------------------------------------------------------
       
   219 //
       
   220 void CCalenMultipleDbUi::ConstructL()
       
   221     {
       
   222     TRACE_ENTRY_POINT;
       
   223     CAknDialog::ConstructL( R_CALEN_MULTIPLEDB_MENUBAR );
       
   224     SetTitlePaneL();
       
   225     
       
   226     TCallBack actionCallBack(CCalenMultipleDbUi::AsyncCallBackL, this);
       
   227     iAsyncAction = new(ELeave) CAsyncCallBack(actionCallBack,CActive::EPriorityStandard);
       
   228    
       
   229 	// register for calendar file change notifications
       
   230     RArray<TCalenNotification> notificationArray;
       
   231     notificationArray.Append(ECalenNotifyCalendarInfoCreated);
       
   232     notificationArray.Append(ECalenNotifyCalendarInfoUpdated);
       
   233     notificationArray.Append(ECalenNotifyCalendarFileDeleted);
       
   234     iController.RegisterForNotificationsL(this, notificationArray);
       
   235     
       
   236     notificationArray.Close();
       
   237     
       
   238     iConflictOccured = EFalse;
       
   239     
       
   240     TRACE_EXIT_POINT;
       
   241     }
       
   242 
       
   243 // ----------------------------------------------------------------------------
       
   244 // CCalenMultipleDbUi::~CCalenMultipleDbUi
       
   245 // (other items were commented in a header).
       
   246 // ----------------------------------------------------------------------------
       
   247 //
       
   248 CCalenMultipleDbUi::~CCalenMultipleDbUi()
       
   249     {
       
   250     TRACE_ENTRY_POINT;
       
   251     
       
   252     iController.CancelNotifications(this);
       
   253     
       
   254     if( iNaviContainer )
       
   255         {
       
   256         iNaviContainer->Pop(); // Remove navi pane used by settings view
       
   257         iNaviContainer = NULL; // iNaviContainer is not owned
       
   258         }
       
   259     
       
   260     delete iBgContext;
       
   261     iBgContext = NULL;
       
   262     
       
   263     iListBox->Reset();
       
   264     delete iListBox;
       
   265     iListBox = NULL;
       
   266     
       
   267     delete iDesArray;
       
   268     iDesArray = NULL;
       
   269     
       
   270     iColorUidArray.Close();
       
   271     
       
   272     iIconIndices.Reset();
       
   273     iIconIndices.Close();
       
   274     
       
   275     iAsyncAction->Cancel();
       
   276     delete iAsyncAction;
       
   277     iAsyncAction = NULL;
       
   278         
       
   279     if(iCalendarInfoNew)
       
   280         {
       
   281         delete iCalendarInfoNew;
       
   282         iCalendarInfoNew = NULL;
       
   283         }
       
   284     
       
   285     if(iCalendarInfoOriginal)
       
   286         {
       
   287         delete iCalendarInfoOriginal;
       
   288         iCalendarInfoOriginal = NULL;
       
   289         }
       
   290 if(iCalEditedDefaultName)
       
   291         {
       
   292         delete iCalEditedDefaultName;
       
   293         iCalEditedDefaultName = NULL;
       
   294         }
       
   295     TRACE_EXIT_POINT;
       
   296     }
       
   297 
       
   298 // ----------------------------------------------------------------------------
       
   299 // CCalenMultipleDbUi::FocusChanged
       
   300 // (other items were commented in a header).
       
   301 // ----------------------------------------------------------------------------
       
   302 //
       
   303 void CCalenMultipleDbUi::FocusChanged( TDrawNow aDrawNow )
       
   304     {
       
   305     TRACE_ENTRY_POINT;
       
   306     
       
   307     CAknDialog::FocusChanged( aDrawNow );    
       
   308     
       
   309     TRACE_EXIT_POINT;
       
   310     }
       
   311 
       
   312 // ----------------------------------------------------------------------------
       
   313 // CCalenMultipleDbUi::ConstructListL
       
   314 // Construct listbox , model and icon  
       
   315 // ----------------------------------------------------------------------------
       
   316 //
       
   317 void CCalenMultipleDbUi::ConstructListL()
       
   318     {
       
   319     TRACE_ENTRY_POINT;
       
   320     if(iDesArray && iListBox)
       
   321         {
       
   322         return;
       
   323         }
       
   324     
       
   325     iDesArray = new (ELeave) CDesCArrayFlat(5);
       
   326     iListBox = new (ELeave) CCalenMultipleDbListbox(iColorUidArray);
       
   327     iListBox->SetContainerWindowL( *this );
       
   328     iListBox->ConstructL(this, EAknListBoxSelectionList );
       
   329     
       
   330     //Create scroll bar
       
   331     iListBox->CreateScrollBarFrameL(ETrue);
       
   332     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   333     CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   334     
       
   335     CTextListBoxModel* model = iListBox->Model();
       
   336     model->SetItemTextArray(iDesArray);
       
   337     model->SetOwnershipType(ELbmDoesNotOwnItemArray);
       
   338     
       
   339     iListBox->View()->SetListEmptyTextL( _L("No Items") );
       
   340     
       
   341     iListBox->SetListBoxObserver( this );
       
   342     PrepareIconsL( );
       
   343     TRACE_EXIT_POINT;
       
   344     }
       
   345 
       
   346 // ----------------------------------------------------------------------------
       
   347 // CCalenMultipleDbUi::UpdateListboxL
       
   348 // Update listbox with latest data from metadb 
       
   349 // ----------------------------------------------------------------------------
       
   350 //
       
   351 void CCalenMultipleDbUi::UpdateListboxL()
       
   352     {
       
   353     TRACE_ENTRY_POINT;
       
   354     
       
   355     if(!iListBox)
       
   356         return;
       
   357     
       
   358     iListBox->View()->SetDisableRedraw( ETrue );
       
   359     iDesArray->Reset();
       
   360     iColorUidArray.Close();
       
   361     
       
   362     SetTitlePaneL();
       
   363     RPointerArray<CCalCalendarInfo> calendarInfoList;
       
   364     CleanupClosePushL(calendarInfoList);
       
   365     iController.GetAllCalendarInfoL(calendarInfoList);
       
   366     
       
   367     TInt calendarInfoCount = calendarInfoList.Count();
       
   368         
       
   369     if(calendarInfoCount)
       
   370         {
       
   371         iListBox->ItemDrawer()->ColumnData()->SetIconArray( iIconList );
       
   372         
       
   373         for(TInt i = 0 ; i < calendarInfoCount ; i++)
       
   374             {
       
   375             TBuf<KMultiDbMaxLength> targetBuffer;
       
   376             CCalCalendarInfo* calendarInfo = calendarInfoList[i];
       
   377             
       
   378             HBufC* calendarName = calendarInfo->NameL().AllocLC();
       
   379             
       
   380             //"%d\t%S\t%S\t%d"
       
   381             targetBuffer.Append(KListSeparatorFormat);
       
   382             targetBuffer.Append(calendarName->Des());
       
   383             targetBuffer.Append(KListSeparatorFormat);
       
   384             
       
   385             HBufC* calendarVisibility = NULL; 
       
   386             if(calendarInfo->Enabled())
       
   387                 {
       
   388                 calendarVisibility = StringLoader::LoadLC( 
       
   389                         R_CALE_MULTIPLEDB_VISIBLE, iCoeEnv );
       
   390                 }
       
   391             else
       
   392                 {
       
   393                 calendarVisibility = StringLoader::LoadLC(
       
   394                             R_CALE_MULTIPLEDB_HIDDEN, iCoeEnv );
       
   395                 }
       
   396             
       
   397             targetBuffer.Append(calendarVisibility->Des());
       
   398             CleanupStack::PopAndDestroy(calendarVisibility);
       
   399             
       
   400             targetBuffer.Append(KListSeparatorFormat);
       
   401             
       
   402             //Collect color info to be used in itemdrawer for painting strip
       
   403             iColorUidArray.Append(calendarInfo->Color().Value());
       
   404             
       
   405             iDesArray->AppendL(targetBuffer);
       
   406             CleanupStack::PopAndDestroy(calendarName);
       
   407             }
       
   408         }
       
   409     CleanupStack::PopAndDestroy(&calendarInfoList);
       
   410     
       
   411     iListBox->View()->SetDisableRedraw( EFalse );
       
   412     iListBox->HandleItemAdditionL(); //Update and draw listbox
       
   413     TRACE_EXIT_POINT;
       
   414     }
       
   415 
       
   416 // ----------------------------------------------------------------------------
       
   417 // CCalenMultipleDbUi::PrepareIconsL
       
   418 // Load icon into memory
       
   419 // ----------------------------------------------------------------------------
       
   420 //
       
   421 void CCalenMultipleDbUi::PrepareIconsL()
       
   422     {
       
   423     TRACE_ENTRY_POINT;
       
   424     iIconIndices.Reset();
       
   425     iIconIndices.AppendL( MCalenServices::ECalenSyncIcon );
       
   426     
       
   427     iIconList = CreateIconsL(iIconIndices);
       
   428     
       
   429     TRACE_EXIT_POINT;
       
   430     }
       
   431 
       
   432 // ----------------------------------------------------------------------------
       
   433 // CCalenMultipleDbUi::CreateIconsL
       
   434 // Create CGulIcon from mif
       
   435 // ----------------------------------------------------------------------------
       
   436 //
       
   437 CAknIconArray*   CCalenMultipleDbUi::CreateIconsL( 
       
   438         RArray<MCalenServices::TCalenIcons>& aIndexArray )
       
   439     {
       
   440     TRACE_ENTRY_POINT;
       
   441     const TInt iconCount( aIndexArray.Count() );
       
   442     
       
   443     CAknIconArray* icons = new(ELeave) CAknIconArray( iconCount );
       
   444     CleanupStack::PushL( icons );
       
   445     icons->SetReserveL( iconCount );
       
   446 
       
   447     for( TInt i=0; i < iconCount; ++i )
       
   448         {
       
   449         icons->AppendL( iController.Services().
       
   450          GetIconL( static_cast<MCalenServices::TCalenIcons>(aIndexArray[i])));
       
   451         }
       
   452     
       
   453     CleanupStack::Pop( icons );
       
   454     
       
   455     TRACE_EXIT_POINT;
       
   456     return icons;
       
   457     }
       
   458 
       
   459 // ----------------------------------------------------------------------------
       
   460 // CCalenMultipleDbUi::SetTitlePaneL
       
   461 // Set title pane for calendar management view
       
   462 // ----------------------------------------------------------------------------
       
   463 //
       
   464 void CCalenMultipleDbUi::SetTitlePaneL()
       
   465     {
       
   466     TRACE_ENTRY_POINT;
       
   467     CEikStatusPane* sp = iEikonEnv->AppUiFactory()->StatusPane();
       
   468 
       
   469     // Set empty navi pane label
       
   470     iNaviContainer = static_cast<CAknNavigationControlContainer*>(
       
   471                                  sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
   472     iNaviContainer->PushDefaultL();
       
   473 
       
   474    // Set title text
       
   475     CAknTitlePane* tp = static_cast<CAknTitlePane*>(
       
   476                                  sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   477     HBufC* titleText;
       
   478     if(iIsDbEditorOpen)
       
   479         {
       
   480         titleText = StringLoader::LoadLC( R_QTN_CALE_TITLE_CALENDAR , iCoeEnv );
       
   481         }
       
   482     else
       
   483         {
       
   484         titleText = StringLoader::LoadLC( R_QTN_CALE_TITLE_CALENDARS , iCoeEnv );
       
   485         }
       
   486     tp->SetTextL( *titleText );  // r_qtn_cale_title_calendars
       
   487     CleanupStack::PopAndDestroy( titleText );
       
   488     
       
   489     TRACE_EXIT_POINT;
       
   490     }
       
   491 
       
   492    
       
   493 
       
   494 
       
   495 // ----------------------------------------------------------------------------
       
   496 // CCalenMultipleDbUi::DynInitMenuPaneL
       
   497 // Do functionalites before options menu execs
       
   498 // ----------------------------------------------------------------------------
       
   499 //
       
   500 void CCalenMultipleDbUi::DynInitMenuPaneL( TInt aResourceId,CEikMenuPane* aMenuPane )
       
   501     {
       
   502     TRACE_ENTRY_POINT;
       
   503     switch(aResourceId)
       
   504       {
       
   505       case R_CALEN_MULTIPLEDB_MENUPANE:
       
   506           {
       
   507           if(!iListBox->Model()->ItemTextArray()->MdcaCount())
       
   508               {
       
   509               aMenuPane->DeleteMenuItem(ECalenCmdEdit);
       
   510               aMenuPane->DeleteMenuItem(ECalenCmdItemSelect);
       
   511               aMenuPane->DeleteMenuItem(ECalenCmdItemDeselect);
       
   512               aMenuPane->DeleteMenuItem(ECalenCmdDelete);
       
   513               }
       
   514           else 
       
   515               {
       
   516               RPointerArray<CCalCalendarInfo> calendarInfoList; 
       
   517               iController.GetAllCalendarInfoL(calendarInfoList);
       
   518               CleanupClosePushL(calendarInfoList);
       
   519               TInt currentIndex =  iListBox->CurrentItemIndex();
       
   520               
       
   521               TInt cmd = calendarInfoList[currentIndex]->Enabled() ?
       
   522                                    ECalenCmdItemSelect : ECalenCmdItemDeselect;
       
   523               
       
   524               aMenuPane->DeleteMenuItem(cmd);
       
   525                
       
   526               HBufC* calendarFileName = 
       
   527                   calendarInfoList[currentIndex]->FileNameL().AllocLC();
       
   528               if (!(calendarFileName->CompareF(
       
   529                         iController.Services().SessionL().DefaultFileNameL())))
       
   530                   {
       
   531                   aMenuPane->DeleteMenuItem(ECalenCmdDelete);
       
   532                   }
       
   533               CleanupStack::PopAndDestroy(calendarFileName);
       
   534               CleanupStack::PopAndDestroy(&calendarInfoList);
       
   535               }
       
   536           }
       
   537        break;
       
   538       default:
       
   539        break;
       
   540       }
       
   541       
       
   542     TRACE_EXIT_POINT;  
       
   543     }
       
   544 
       
   545 // ----------------------------------------------------------------------------
       
   546 // CCalenMultipleDbUi::ProcessCommandL
       
   547 // Handle options menu items command
       
   548 // ----------------------------------------------------------------------------
       
   549 //
       
   550 void  CCalenMultipleDbUi::ProcessCommandL( TInt aCommandId )
       
   551     {
       
   552     TRACE_ENTRY_POINT;
       
   553     CAknDialog::ProcessCommandL(aCommandId);
       
   554     
       
   555     switch(aCommandId)
       
   556       {
       
   557       case ECalenCmdEdit:
       
   558           {
       
   559           TInt retValue = EditItemL();
       
   560           if(retValue == EAknCmdExit || retValue == EAknSoftkeyExit )
       
   561               {
       
   562               DoAsyncActionL(retValue);
       
   563               }
       
   564           }
       
   565           break;
       
   566       case ECalenCmdAdd:
       
   567           {
       
   568           TInt retValue = AddItemL();
       
   569           if(retValue == EAknCmdExit || retValue == EAknSoftkeyExit )
       
   570              {
       
   571              DoAsyncActionL(retValue);
       
   572              }
       
   573           }
       
   574           break;
       
   575       case ECalenCmdDelete:
       
   576           {
       
   577           DoAsyncActionL(ECalenCmdDelete);
       
   578           }
       
   579           break;
       
   580       case ECalenCmdItemSelect:
       
   581       case ECalenCmdShow:
       
   582           {
       
   583           DoSelectionL(ETrue);
       
   584           }
       
   585           break;
       
   586       case ECalenCmdItemDeselect:
       
   587       case ECalenCmdHide:
       
   588           {
       
   589           DoSelectionL(EFalse);
       
   590           }
       
   591           break;
       
   592       case EAknCmdExit:
       
   593       case EAknSoftkeyExit:
       
   594           {
       
   595           DoAsyncActionL(EAknSoftkeyExit);
       
   596           }
       
   597           break;
       
   598       case EAknCmdHelp:      
       
   599             if (FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   600                 {
       
   601                 HlpLauncher::LaunchHelpApplicationL(
       
   602                         iCoeEnv->WsSession(),iAvkonAppUi->AppHelpContextL());                        
       
   603                 }
       
   604           break;
       
   605       default:
       
   606           break;
       
   607       }
       
   608     TRACE_EXIT_POINT;
       
   609     }
       
   610 
       
   611 // ----------------------------------------------------------------------------
       
   612 // CCalenMultipleDbUi::GetHelpContext
       
   613 // Gets help context
       
   614 // (other items were commented in a header).
       
   615 // ----------------------------------------------------------------------------
       
   616 //
       
   617 void CCalenMultipleDbUi::GetHelpContext( TCoeHelpContext& aContext ) const
       
   618     {
       
   619     TRACE_ENTRY_POINT;
       
   620 
       
   621     aContext.iMajor = KUidCalendar;
       
   622     // This is specified in HRH file.
       
   623     aContext.iContext = KCALE_HLP_DAY_VIEW; //KCALE_HLP_DAY_VIEW should be replaced with MultipleDbUi related help id
       
   624 
       
   625     TRACE_EXIT_POINT;
       
   626     }
       
   627 
       
   628 // ----------------------------------------------------------------------------
       
   629 // CCalenMultipleDbUi::DoSelectionL
       
   630 // Mark the listbox item as hidden/visible based on aMark status
       
   631 // ----------------------------------------------------------------------------
       
   632 //
       
   633 void CCalenMultipleDbUi::DoSelectionL( TBool aMark )
       
   634     {
       
   635     TRACE_ENTRY_POINT;
       
   636     TInt currentIndex =  iListBox->CurrentItemIndex();
       
   637    
       
   638     RPointerArray<CCalCalendarInfo> calendarInfoList; 
       
   639     iController.GetAllCalendarInfoL(calendarInfoList);
       
   640     CleanupClosePushL(calendarInfoList);
       
   641     
       
   642     CCalCalendarInfo* calendarInfo = calendarInfoList[currentIndex];
       
   643     calendarInfo->SetEnabled(aMark);
       
   644     iController.UpdateCalendarL(calendarInfo);
       
   645     CleanupStack::PopAndDestroy(&calendarInfoList);
       
   646     UpdateListboxL();
       
   647     
       
   648     TRACE_EXIT_POINT;
       
   649     }
       
   650 // ----------------------------------------------------------------------------
       
   651 // CCalenMultipleDbUi::AddItemL
       
   652 // Add new item in listbox 
       
   653 // ----------------------------------------------------------------------------
       
   654 //
       
   655 TInt CCalenMultipleDbUi::AddItemL()
       
   656     {
       
   657     TRACE_ENTRY_POINT
       
   658     TInt retValue = 0;
       
   659     
       
   660     if(iCalendarInfoNew)
       
   661         {
       
   662         delete iCalendarInfoNew;
       
   663         iCalendarInfoNew = NULL;
       
   664         }
       
   665     
       
   666     iCalendarInfoNew = CCalCalendarInfo::NewL();
       
   667     iCalendarInfoNew->SetNameL(KNullDesC16);
       
   668     iCalendarInfoNew->SetColor(KCalenBlue.Value());
       
   669     iCalendarInfoNew->SetEnabled(ETrue);
       
   670     iDbEditor = CCalenMultiDBEditor::NewL(*this,*iCalendarInfoNew, iController, EFalse );
       
   671   
       
   672     //Async dialog
       
   673     retValue = iDbEditor->ExecuteLD();
       
   674     //iDbEditor = NULL;
       
   675      
       
   676     if(EAknCmdExit == retValue )
       
   677         {
       
   678         iController.BroadcastNotification(ECalenNotifyRealExit);
       
   679         }
       
   680     
       
   681     TRACE_EXIT_POINT
       
   682     return retValue;
       
   683     }
       
   684 
       
   685 
       
   686 // ----------------------------------------------------------------------------
       
   687 // CCalenMultipleDbUi::UpdateAddOrEditL
       
   688 // ----------------------------------------------------------------------------
       
   689 //
       
   690 TInt CCalenMultipleDbUi::UpdateOnAddOrEditL(TBool aItemAdded)
       
   691     {
       
   692     TRACE_ENTRY_POINT
       
   693 	TInt retError = KErrNone;
       
   694     
       
   695 	iDbEditor = NULL;
       
   696 	if(iCalEditedDefaultName)
       
   697 	    {
       
   698         delete iCalEditedDefaultName;
       
   699         iCalEditedDefaultName = NULL;
       
   700 	    }
       
   701     
       
   702     if(aItemAdded)
       
   703         {
       
   704         TRAP(retError,
       
   705         // Set calendar properties for new calendar being created.
       
   706         SetCalendarAddPropertiesL(*iCalendarInfoNew);
       
   707        
       
   708         //This makes sure calendarInfo will get deleted anyway!
       
   709         iController.AddCalendarL(iCalendarInfoNew);
       
   710         );
       
   711         
       
   712         iCalendarInfoNew = NULL;
       
   713         
       
   714         //Highlight the newly created list item
       
   715         iListBox->ScrollToMakeItemVisible(iListBox->BottomItemIndex());
       
   716         iListBox->SetCurrentItemIndexAndDraw(iDesArray->Count()-1);
       
   717         }
       
   718     else
       
   719         {
       
   720         //Before checking for changes , check if any conflict occured i.e calendar updated / deleted.
       
   721         //if there is conflict iConflictOccured = true then skip below condition.
       
   722         if (!iConflictOccured && iCalendarInfoOriginal &&
       
   723                 CheckForChangesL(*iCalendarInfoOriginal,
       
   724                 *iCalendarInfoEdited))
       
   725             {
       
   726             TRAP(retError,
       
   727             // update the calendar properties such as modification time, sync status.
       
   728             SetCalendarUpdatePropertiesL(*iCalendarInfoEdited);
       
   729             
       
   730             iController.UpdateCalendarL(iCalendarInfoEdited);
       
   731             );
       
   732             
       
   733             }
       
   734 
       
   735         iConflictOccured = EFalse;
       
   736         delete iCalendarInfoOriginal,iCalendarInfoOriginal = NULL;
       
   737         }
       
   738     
       
   739     iIsDbEditorOpen = EFalse ; //iIsDbEditorOpen should be set before calling UpdateListboxL() 
       
   740     
       
   741     TRAP_IGNORE(UpdateListboxL());
       
   742     
       
   743     
       
   744     TRACE_EXIT_POINT
       
   745 	return retError;
       
   746     }
       
   747 
       
   748 // ----------------------------------------------------------------------------
       
   749 // CCalenMultipleDbUi::ExitDialogL
       
   750 // Edit item from listbox 
       
   751 // ----------------------------------------------------------------------------
       
   752 //
       
   753 void CCalenMultipleDbUi::ExitDialogL()
       
   754     {
       
   755     TRACE_ENTRY_POINT
       
   756     iAsyncActionCmd = EAknSoftkeyExit;
       
   757     iAsyncAction->CallBack();
       
   758     TRACE_EXIT_POINT
       
   759     }
       
   760 
       
   761 // ----------------------------------------------------------------------------
       
   762 // CCalenMultipleDbUi::EditItemL
       
   763 // Edit item from listbox 
       
   764 // ----------------------------------------------------------------------------
       
   765 //
       
   766 TInt CCalenMultipleDbUi::EditItemL()
       
   767     {
       
   768     TRACE_ENTRY_POINT
       
   769     TInt retValue = KErrNotFound;
       
   770     TInt currentIndex = iListBox->CurrentItemIndex();
       
   771     
       
   772     RPointerArray<CCalCalendarInfo> calendarInfoList;
       
   773     iController.GetAllCalendarInfoL(calendarInfoList);
       
   774     CleanupClosePushL(calendarInfoList);
       
   775     
       
   776     iCalendarInfoEdited = calendarInfoList[currentIndex];
       
   777     
       
   778     iCalEditedDefaultName = calendarInfoList[currentIndex]->FileNameL().AllocL();
       
   779     CleanupStack::PopAndDestroy(&calendarInfoList);
       
   780     
       
   781     //Take a copy of original before editing
       
   782     if(iCalendarInfoOriginal)
       
   783         {
       
   784         delete iCalendarInfoOriginal;
       
   785         iCalendarInfoOriginal = NULL;
       
   786         }
       
   787     iCalendarInfoOriginal = CCalCalendarInfo::NewL();
       
   788     
       
   789     iCalendarInfoOriginal->SetNameL(iCalendarInfoEdited->NameL());
       
   790     iCalendarInfoOriginal->SetColor(iCalendarInfoEdited->Color());
       
   791     iCalendarInfoOriginal->SetEnabled(iCalendarInfoEdited->Enabled());
       
   792     TBuf8<KBuffLength> keyBuff;
       
   793           
       
   794 
       
   795     iDbEditor = CCalenMultiDBEditor::NewL(*this,*iCalendarInfoEdited, iController,
       
   796             ETrue);
       
   797 
       
   798     //Async dialog
       
   799     retValue = iDbEditor->ExecuteLD();
       
   800     //iDbEditor = NULL;
       
   801     
       
   802     return retValue;
       
   803     TRACE_EXIT_POINT
       
   804     }
       
   805 
       
   806 // ----------------------------------------------------------------------------
       
   807 // CCalenMultipleDbUi::DeleteItemL
       
   808 // Delete item from listbox 
       
   809 // ----------------------------------------------------------------------------
       
   810 //
       
   811 TInt CCalenMultipleDbUi::DeleteItemL()
       
   812     {
       
   813     TRACE_ENTRY_POINT;
       
   814     
       
   815     TInt currentIndex =  iCurrentIndex;
       
   816     
       
   817     RPointerArray<CCalCalendarInfo> calendarInfoList; 
       
   818     iController.GetAllCalendarInfoL(calendarInfoList);
       
   819     CleanupClosePushL(calendarInfoList);
       
   820     
       
   821     CCalCalendarInfo* calendarInfo = calendarInfoList[currentIndex];
       
   822     HBufC* calendarName = calendarInfo->NameL().AllocLC();
       
   823     
       
   824     CAknQueryDialog *dialog = CAknQueryDialog::NewL( );
       
   825     CleanupStack::PushL( dialog );
       
   826     HBufC* textMessage = StringLoader::LoadLC( 
       
   827             R_CALE_MULTIPLEDB_DELETE , *calendarName, iCoeEnv );
       
   828     dialog->SetPromptL( *textMessage );
       
   829     CleanupStack::PopAndDestroy( textMessage );
       
   830     CleanupStack::Pop( dialog );
       
   831     
       
   832     if(dialog->ExecuteLD(R_CALEN_ERASEQUERY_NOTE))
       
   833         {
       
   834         //BroadcastNotification for whatever instanceView created gets deleted.
       
   835         iController.BroadcastNotification(ECalenNotifyDeleteInstanceView);
       
   836         iController.RemoveCalendarL(calendarInfo->FileNameL());
       
   837        
       
   838         UpdateListboxL();
       
   839         
       
   840         ReAdjustListItemFocusL(currentIndex);
       
   841         }
       
   842     
       
   843     CleanupStack::PopAndDestroy(calendarName);
       
   844     CleanupStack::PopAndDestroy(&calendarInfoList);
       
   845     return 0;
       
   846     TRACE_EXIT_POINT
       
   847     }
       
   848 
       
   849 // ----------------------------------------------------------------------------
       
   850 // CCalenMultipleDbUi::ReAdjustListFocusL
       
   851 // Refocus the items in list when delete action happened.
       
   852 // ----------------------------------------------------------------------------
       
   853 //
       
   854 void CCalenMultipleDbUi::ReAdjustListItemFocusL(const TInt aCurrentIndex)
       
   855     {
       
   856     TRACE_ENTRY_POINT
       
   857     TInt currentIndex = aCurrentIndex; 
       
   858     TInt count = iListBox->Model()->ItemTextArray()->MdcaCount();
       
   859     if (count > 0)
       
   860         {
       
   861         if (currentIndex == 1 && currentIndex == count)
       
   862             {
       
   863             iListBox->SetCurrentItemIndexAndDraw(0);
       
   864             }
       
   865         else if (currentIndex == count && count > 1)
       
   866             {
       
   867             iListBox->SetCurrentItemIndexAndDraw(--currentIndex);
       
   868             }
       
   869         else
       
   870             {
       
   871             iListBox->SetCurrentItemIndexAndDraw(currentIndex);
       
   872             }
       
   873         }
       
   874     TRACE_EXIT_POINT    
       
   875     }
       
   876 
       
   877 // ----------------------------------------------------------------------------
       
   878 // CCalenMultipleDbUi::CheckForChangesL
       
   879 // Check if changes has occured between before and after editing
       
   880 // ----------------------------------------------------------------------------
       
   881 //
       
   882 TBool CCalenMultipleDbUi::CheckForChangesL( CCalCalendarInfo& aCalendarInfoOriginal,
       
   883                             CCalCalendarInfo& aCalendarInfoModified)
       
   884     {
       
   885     TRACE_ENTRY_POINT;
       
   886     TBool changed = EFalse;
       
   887     
       
   888     HBufC* editedName = aCalendarInfoModified.NameL().AllocLC();
       
   889 
       
   890     if (editedName->Compare(aCalendarInfoOriginal.NameL())
       
   891             || aCalendarInfoModified.Color() != aCalendarInfoOriginal.Color()
       
   892             || aCalendarInfoModified.Enabled()!= aCalendarInfoOriginal.Enabled())
       
   893         {
       
   894         changed = ETrue;
       
   895         }
       
   896     
       
   897     CleanupStack::PopAndDestroy(editedName);
       
   898     TRACE_EXIT_POINT;
       
   899     return changed;
       
   900     }
       
   901 
       
   902 // ----------------------------------------------------------------------------
       
   903 // CCalenMultipleDbUi::OfferKeyEventL
       
   904 // Handle key events for dialog 
       
   905 // ----------------------------------------------------------------------------
       
   906 //
       
   907 TKeyResponse CCalenMultipleDbUi::OfferKeyEventL(const TKeyEvent& aKeyEvent,
       
   908                                                                      TEventCode aType)
       
   909     { 
       
   910     TRACE_ENTRY_POINT;
       
   911     TKeyResponse exitCode(EKeyWasNotConsumed);
       
   912     if(aType == EEventKey )
       
   913         {
       
   914         if( aKeyEvent.iCode == EKeyEscape )
       
   915             {
       
   916             TryExitL( EKeyNo );
       
   917             return exitCode; // Chain this one up to the main app so it closes calendar app.
       
   918             }
       
   919          else if(aType == EEventKey && TChar(aKeyEvent.iCode).IsPrint() )
       
   920             {
       
   921             ProcessCommandL(ECalenCmdAdd);
       
   922             }
       
   923          else if(aType == EKeyOK)
       
   924             {
       
   925              // Single click integration
       
   926             iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   927             }
       
   928          else if(aKeyEvent.iCode == EKeyBackspace && 
       
   929                  iMenuBar->ItemSpecificCommandsEnabled())
       
   930             {
       
   931             RPointerArray<CCalCalendarInfo> calendarInfoList; 
       
   932             iController.GetAllCalendarInfoL(calendarInfoList);
       
   933             CleanupClosePushL(calendarInfoList);
       
   934             if(calendarInfoList.Count())
       
   935                 {
       
   936                 TInt currentIndex =  iCurrentIndex = iListBox->CurrentItemIndex();
       
   937                 HBufC* calendarFileName = 
       
   938                         calendarInfoList[currentIndex]->FileNameL().AllocLC();
       
   939                 if ((calendarFileName->CompareF(
       
   940                                         iController.Services().SessionL().DefaultFileNameL())))
       
   941                     {
       
   942                     DeleteItemL();
       
   943                     }
       
   944                 CleanupStack::PopAndDestroy(calendarFileName);
       
   945 				}
       
   946             CleanupStack::PopAndDestroy(&calendarInfoList);
       
   947             exitCode =  EKeyWasConsumed;
       
   948             } 
       
   949          else 
       
   950             {
       
   951             exitCode = EKeyWasConsumed;
       
   952             iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   953            
       
   954             // Draw because pressing up/down means we have to redraw the backgrouns skin.
       
   955             DrawDeferred();
       
   956             }
       
   957         }
       
   958     TRACE_EXIT_POINT;
       
   959     return exitCode;
       
   960     }
       
   961 
       
   962 // ----------------------------------------------------------------------------
       
   963 // CCalenMultipleDbUi::HandlePointerEventL
       
   964 // Handle pointer events for dialog
       
   965 // ----------------------------------------------------------------------------
       
   966 //
       
   967 void CCalenMultipleDbUi::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   968     {
       
   969     TRACE_ENTRY_POINT;
       
   970     //Single click integration
       
   971     if ( iListBox )
       
   972        {
       
   973        iListBox->HandlePointerEventL( aPointerEvent );
       
   974        }
       
   975     TRACE_EXIT_POINT;
       
   976     }
       
   977 
       
   978 // ----------------------------------------------------------------------------
       
   979 // CCalenMultipleDbUi::OkToExitL
       
   980 // Handle softkeys for the dialog
       
   981 // ----------------------------------------------------------------------------
       
   982 //
       
   983 TBool CCalenMultipleDbUi::OkToExitL( TInt aButtonId )
       
   984     {
       
   985     TRACE_ENTRY_POINT;
       
   986     TBool okExit = EFalse;
       
   987     switch(aButtonId)
       
   988        {
       
   989        case EAknSoftkeyChange:
       
   990            {
       
   991            ProcessCommandL(ECalenCmdEdit);
       
   992            }
       
   993            break;
       
   994        case EAknSoftkeyBack:
       
   995        case EKeyEscape:
       
   996            {
       
   997            iController.BroadcastNotification(ECalenNotifyDeleteInstanceView);
       
   998            okExit = ETrue;
       
   999            }
       
  1000            break;
       
  1001        case EKeyNo:
       
  1002            {
       
  1003            iController.BroadcastNotification(ECalenNotifyDeleteInstanceView);
       
  1004            okExit = CAknDialog::OkToExitL(aButtonId);
       
  1005            break;
       
  1006            }
       
  1007        default:
       
  1008            {
       
  1009            okExit = CAknDialog::OkToExitL(aButtonId);
       
  1010            }
       
  1011           break;
       
  1012        }
       
  1013     TRACE_EXIT_POINT;
       
  1014     return okExit;
       
  1015     }
       
  1016 
       
  1017 
       
  1018 // ----------------------------------------------------------------------------
       
  1019 // CCalenMultipleDbUi::SizeChanged
       
  1020 // Set the rect to dialog and listbox
       
  1021 // ----------------------------------------------------------------------------
       
  1022 //
       
  1023 void CCalenMultipleDbUi::SizeChanged()
       
  1024     {
       
  1025     TRACE_ENTRY_POINT;
       
  1026     CAknDialog::SizeChanged();
       
  1027     
       
  1028     TRect rect = iRect = Rect();
       
  1029     if( iBgContext )
       
  1030         {
       
  1031         iBgContext->SetRect( rect );
       
  1032         }
       
  1033     if( iListBox )
       
  1034         {
       
  1035         TInt orientation = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0;
       
  1036         TAknLayoutRect application_window;
       
  1037         
       
  1038         if( ( !orientation ) && AknLayoutUtils::PenEnabled() )
       
  1039             {
       
  1040             TRect appWindow;
       
  1041             TAknLayoutRect application_window;
       
  1042             AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EApplicationWindow, 
       
  1043                                                appWindow );
       
  1044             application_window.LayoutRect( 
       
  1045                     appWindow, 
       
  1046                 AknLayoutScalable_Apps::application_window().LayoutLine() ); 
       
  1047                 
       
  1048             // Find the size of the main pane.
       
  1049             TAknLayoutRect main_pane;                    
       
  1050                                 
       
  1051             main_pane.LayoutRect( 
       
  1052             application_window.Rect(), 
       
  1053             AknLayoutScalable_Apps::main_pane( orientation ).LayoutLine() );
       
  1054             
       
  1055             TRect listboxRect;
       
  1056             listboxRect.SetWidth( main_pane.Rect().Width() );
       
  1057             listboxRect.SetHeight( main_pane.Rect().Height() );
       
  1058             iListBox->SetRect( listboxRect );
       
  1059             }
       
  1060         else
       
  1061             {
       
  1062             iListBox->SetRect( rect );
       
  1063             }
       
  1064         }
       
  1065     
       
  1066     TRACE_EXIT_POINT;
       
  1067     }
       
  1068 
       
  1069 // ----------------------------------------------------------------------------
       
  1070 // CCalenMultipleDbUi::ComponentControl
       
  1071 // (other items were commented in a header).
       
  1072 // ----------------------------------------------------------------------------
       
  1073 //
       
  1074 CCoeControl* CCalenMultipleDbUi::ComponentControl( TInt /*aIndex*/) const
       
  1075     {
       
  1076     TRACE_ENTRY_POINT;
       
  1077     if(iListBox)
       
  1078         {
       
  1079         TRACE_EXIT_POINT;
       
  1080         return iListBox;
       
  1081         }
       
  1082     TRACE_EXIT_POINT;   
       
  1083     return NULL;
       
  1084     }
       
  1085 
       
  1086 // ----------------------------------------------------------------------------
       
  1087 // CCalenMultipleDbUi::CountComponentControls
       
  1088 // (other items were commented in a header).
       
  1089 // ----------------------------------------------------------------------------
       
  1090 //
       
  1091 TInt CCalenMultipleDbUi::CountComponentControls() const
       
  1092     {
       
  1093     TRACE_ENTRY_POINT;
       
  1094     if(iListBox)
       
  1095         {
       
  1096         TRACE_EXIT_POINT;
       
  1097         return 1;
       
  1098         }
       
  1099     TRACE_EXIT_POINT;
       
  1100     return 0;
       
  1101     }
       
  1102 
       
  1103 // ----------------------------------------------------------------------------
       
  1104 // CCalenMultipleDbUi::PreLayoutDynInitL
       
  1105 // (other items were commented in a header).
       
  1106 // ----------------------------------------------------------------------------
       
  1107 //
       
  1108 void  CCalenMultipleDbUi::PreLayoutDynInitL()
       
  1109     {
       
  1110     TRACE_ENTRY_POINT;
       
  1111     iBgContext = CAknsBasicBackgroundControlContext::NewL(
       
  1112             KAknsIIDQsnBgAreaMain, iRect, ETrue);
       
  1113 
       
  1114     ConstructListL();
       
  1115     UpdateListboxL();
       
  1116 
       
  1117     TInt orientation = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0;
       
  1118     if (AknLayoutUtils::PenEnabled())
       
  1119         {
       
  1120         // Find the size of the main pane.
       
  1121         // Find the application window
       
  1122         TRect appWindow;
       
  1123         TAknLayoutRect application_window;
       
  1124         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EApplicationWindow,
       
  1125                 appWindow);
       
  1126         application_window.LayoutRect(appWindow,
       
  1127                 AknLayoutScalable_Apps::application_window().LayoutLine());
       
  1128 
       
  1129         // Find the size of the main pane.
       
  1130         TAknLayoutRect main_pane;
       
  1131 
       
  1132         main_pane.LayoutRect(application_window.Rect(),
       
  1133                 AknLayoutScalable_Apps::main_pane(orientation).LayoutLine());
       
  1134 
       
  1135         TRect listboxRect;
       
  1136         listboxRect.SetWidth(main_pane.Rect().Width());
       
  1137         listboxRect.SetHeight(main_pane.Rect().Height());
       
  1138         iListBox->SetRect(listboxRect);
       
  1139         }TRACE_EXIT_POINT;
       
  1140     }
       
  1141 
       
  1142 // ----------------------------------------------------------------------------
       
  1143 // CCalenMultipleDbUi::PostLayoutDynInitL
       
  1144 // (other items were commented in a header).
       
  1145 // ----------------------------------------------------------------------------
       
  1146 //
       
  1147 void CCalenMultipleDbUi::PostLayoutDynInitL()
       
  1148     {
       
  1149     TRACE_ENTRY_POINT;
       
  1150     iListBox->UpdateScrollBarsL(); 
       
  1151     TRACE_EXIT_POINT;
       
  1152     }
       
  1153 
       
  1154 // ----------------------------------------------------------------------------
       
  1155 // CCalenMultipleDbUi::MopSupplyObject
       
  1156 // (other items were commented in a header).
       
  1157 // ----------------------------------------------------------------------------
       
  1158 //
       
  1159 TTypeUid::Ptr CCalenMultipleDbUi::MopSupplyObject(TTypeUid aId)
       
  1160     {
       
  1161     TRACE_ENTRY_POINT;
       
  1162     if(aId.iUid == MAknsControlContext::ETypeId )
       
  1163         {
       
  1164         MAknsControlContext* cc = iBgContext;
       
  1165         if ( cc )
       
  1166             {
       
  1167             return MAknsControlContext::SupplyMopObject( aId, cc );
       
  1168             }
       
  1169         }
       
  1170     TRACE_EXIT_POINT;
       
  1171     return CAknDialog::MopSupplyObject( aId );
       
  1172     }
       
  1173 
       
  1174 // ----------------------------------------------------------------------------
       
  1175 // CCalenMultipleDbUi::HandleResourceChange
       
  1176 // (other items were commented in a header).
       
  1177 // ----------------------------------------------------------------------------
       
  1178 //
       
  1179 void CCalenMultipleDbUi::HandleResourceChange(TInt aType)
       
  1180     {
       
  1181     TRACE_ENTRY_POINT;
       
  1182     if ( aType == KAknsMessageSkinChange || aType == KEikDynamicLayoutVariantSwitch )
       
  1183         {
       
  1184         SizeChanged();
       
  1185         TRAP_IGNORE(UpdateListboxL());
       
  1186         }
       
  1187     CAknDialog::HandleResourceChange( aType );
       
  1188     TRACE_EXIT_POINT;
       
  1189     }
       
  1190 
       
  1191 // ----------------------------------------------------------------------------
       
  1192 // CCalenMultipleDbUi::AsyncCallBackL
       
  1193 // (other items were commented in a header).
       
  1194 // ----------------------------------------------------------------------------
       
  1195 //
       
  1196 TInt CCalenMultipleDbUi::AsyncCallBackL(TAny* aThisPtr)
       
  1197     {
       
  1198     TRACE_ENTRY_POINT
       
  1199     CCalenMultipleDbUi* self = static_cast<CCalenMultipleDbUi*>(aThisPtr);
       
  1200     self->HandleAsyncCommandL(self->iAsyncActionCmd);
       
  1201     TRACE_EXIT_POINT
       
  1202     return 0;
       
  1203     }
       
  1204 
       
  1205 // ----------------------------------------------------------------------------
       
  1206 // CCalenMultipleDbUi::DoAsyncActionL
       
  1207 // (other items were commented in a header).
       
  1208 // ----------------------------------------------------------------------------
       
  1209 //
       
  1210 void CCalenMultipleDbUi::DoAsyncActionL(const TInt aCommand)
       
  1211     {
       
  1212     TRACE_ENTRY_POINT
       
  1213     iCurrentIndex = iListBox->CurrentItemIndex();
       
  1214     iAsyncActionCmd = aCommand;
       
  1215     iAsyncAction->CallBack();
       
  1216     TRACE_EXIT_POINT
       
  1217     }
       
  1218 
       
  1219 // ----------------------------------------------------------------------------
       
  1220 // CCalenMultipleDbUi::DoAsyncActionL
       
  1221 // (other items were commented in a header).
       
  1222 // ----------------------------------------------------------------------------
       
  1223 //
       
  1224 void CCalenMultipleDbUi::HandleAsyncCommandL(const TInt aCommand)
       
  1225     {
       
  1226     TRACE_ENTRY_POINT
       
  1227     
       
  1228     switch(aCommand)
       
  1229         {
       
  1230         case EAknSoftkeyExit:
       
  1231         case EAknCmdExit:
       
  1232             {
       
  1233             TryExitL(aCommand);
       
  1234             }
       
  1235             break;
       
  1236         case ECalenCmdDelete:
       
  1237             {
       
  1238             DeleteItemL();
       
  1239             }
       
  1240             break;
       
  1241         default:
       
  1242             break;
       
  1243         }
       
  1244     
       
  1245     TRACE_EXIT_POINT
       
  1246     }
       
  1247 
       
  1248 // ----------------------------------------------------------------------------
       
  1249 // CCalenMultipleDbUi::CreateButtonL
       
  1250 // (other items were commented in a header).
       
  1251 // ----------------------------------------------------------------------------
       
  1252 //
       
  1253 CAknButton* CCalenMultipleDbUi::CreateButtonL( CGulIcon* aIcon, TInt aDisplayTextID,
       
  1254                                                TInt aTooltipID, CAknToolbar& aToolbar )
       
  1255     {
       
  1256     TRACE_ENTRY_POINT;
       
  1257     
       
  1258     TInt flags = 0;
       
  1259     CAknButton* button = NULL;
       
  1260     
       
  1261     CleanupStack::PushL( aIcon );
       
  1262     HBufC* tooltipText = StringLoader::LoadLC( aTooltipID );
       
  1263     CleanupStack::Pop( tooltipText );
       
  1264     
       
  1265     HBufC* displayText = StringLoader::LoadLC( aDisplayTextID );
       
  1266     CleanupStack::Pop( displayText );
       
  1267     
       
  1268     // put icon onto cleanup stack before its ownership is transferred to CAknButton
       
  1269     CleanupStack::Pop( aIcon );
       
  1270     CleanupStack::PushL( tooltipText );
       
  1271     CleanupStack::PushL( displayText );
       
  1272     button = CAknButton::NewL( aIcon, NULL, NULL, NULL,
       
  1273                                displayText->Des(), tooltipText->Des(), flags, 0 );
       
  1274     
       
  1275     CleanupStack::PopAndDestroy( displayText );
       
  1276     CleanupStack::PopAndDestroy( tooltipText );
       
  1277     
       
  1278     
       
  1279     button->SetIconScaleMode( EAspectRatioNotPreserved );
       
  1280     button->SetFocusing( EFalse );
       
  1281     button->SetBackground( &aToolbar );
       
  1282     
       
  1283     TRACE_EXIT_POINT;
       
  1284     
       
  1285     return button;
       
  1286     }    
       
  1287 
       
  1288 // ----------------------------------------------------------------------------
       
  1289 // CCalenMultipleDbUi::SetCalendarAddPropertiesL
       
  1290 // (other items were commented in a header).
       
  1291 // ----------------------------------------------------------------------------
       
  1292 //
       
  1293 void CCalenMultipleDbUi::SetCalendarAddPropertiesL(CCalCalendarInfo& aCalendarInfo)
       
  1294     {
       
  1295     TRACE_ENTRY_POINT
       
  1296 
       
  1297     TBuf8<KBuffLength> keyBuff;
       
  1298     keyBuff.AppendNum(EFolderLUID);
       
  1299     TRAPD(err,aCalendarInfo.PropertyValueL(keyBuff));
       
  1300 
       
  1301     if (KErrNotFound == err)
       
  1302         {
       
  1303         TUint calValue = 0;
       
  1304         //Get the available offset value and set as property value.
       
  1305         calValue = CCalenMultiCalUtil::GetNextAvailableOffsetL();
       
  1306         TPckgC<TUint> calValuePckg(calValue);
       
  1307         aCalendarInfo.SetPropertyL(keyBuff, calValuePckg);
       
  1308         }
       
  1309 
       
  1310     TTime currentTime;
       
  1311     currentTime.HomeTime();
       
  1312     
       
  1313     keyBuff.Zero();
       
  1314     keyBuff.AppendNum(ECreationTime);
       
  1315     TRAP( err, aCalendarInfo.PropertyValueL( keyBuff ) );
       
  1316 
       
  1317     if (KErrNotFound == err)
       
  1318         {
       
  1319         TPckgC<TTime> pkgCreationTime(currentTime);
       
  1320         aCalendarInfo.SetPropertyL(keyBuff, pkgCreationTime);
       
  1321         }
       
  1322 
       
  1323     keyBuff.Zero();
       
  1324     keyBuff.AppendNum(EModificationTime);
       
  1325 
       
  1326     //At creation modification time will be same as creation time
       
  1327     TPckgC<TTime> pkgModificationTime(currentTime);
       
  1328     aCalendarInfo.SetPropertyL(keyBuff, pkgModificationTime);
       
  1329 
       
  1330     keyBuff.Zero();
       
  1331     keyBuff.AppendNum(EIsSharedFolder);
       
  1332 
       
  1333     TPckgC<TBool> pkgIsSharedFolder(EFalse);
       
  1334     aCalendarInfo.SetPropertyL(keyBuff, pkgIsSharedFolder);
       
  1335     
       
  1336     //EGlobalUUID
       
  1337     keyBuff.Zero();
       
  1338     keyBuff.AppendNum(EGlobalUUID);
       
  1339     TRAP(err,aCalendarInfo.PropertyValueL(keyBuff));
       
  1340     
       
  1341     if (KErrNotFound == err)
       
  1342         {
       
  1343         HBufC8* guuid = iController.Services().InterimUtilsL().GlobalUidL();
       
  1344         TPtr8 guuidPtr = guuid->Des();
       
  1345         CleanupStack::PushL( guuid );
       
  1346         aCalendarInfo.SetPropertyL(keyBuff, guuidPtr);
       
  1347         CleanupStack::PopAndDestroy( guuid );
       
  1348         }
       
  1349 
       
  1350     // EOwnerName
       
  1351     keyBuff.Zero();
       
  1352     keyBuff.AppendNum(EOwnerName);
       
  1353     TRAP(err,aCalendarInfo.PropertyValueL(keyBuff));
       
  1354     
       
  1355     if (KErrNotFound == err)
       
  1356         {
       
  1357         _LIT8( KCalendarOwnerName, "myself" );
       
  1358         aCalendarInfo.SetPropertyL(keyBuff, KCalendarOwnerName);
       
  1359         }
       
  1360     
       
  1361     TBool syncstatus = ETrue;
       
  1362     keyBuff.Zero();
       
  1363     keyBuff.AppendNum( ESyncStatus ); 
       
  1364     TPckgC<TBool> pckgSyncStatusValue(syncstatus); 
       
  1365     aCalendarInfo.SetPropertyL( keyBuff, pckgSyncStatusValue );
       
  1366         
       
  1367     TRACE_EXIT_POINT    
       
  1368     }
       
  1369 
       
  1370 // ----------------------------------------------------------------------------
       
  1371 // CCalenMultipleDbUi::SetCalendarUpdatePropertiesL
       
  1372 // (other items were commented in a header).
       
  1373 // ----------------------------------------------------------------------------
       
  1374 //
       
  1375 void CCalenMultipleDbUi::SetCalendarUpdatePropertiesL(CCalCalendarInfo& aCalendarInfo)
       
  1376     {
       
  1377     TRACE_ENTRY_POINT
       
  1378     TBuf8<KBuffLength> keyBuff;
       
  1379     keyBuff.AppendNum(EModificationTime);
       
  1380 
       
  1381     TTime modificationTime;
       
  1382     modificationTime.HomeTime();
       
  1383     TPckgC<TTime> pkgModificationTime(modificationTime);
       
  1384     aCalendarInfo.SetPropertyL(keyBuff, pkgModificationTime);
       
  1385 
       
  1386     keyBuff.Zero();
       
  1387     keyBuff.AppendNum(EIsSharedFolder);
       
  1388     
       
  1389     //TODO :Get the status from editor and set;
       
  1390     TPckgC<TBool> pkgIsSharedFolder(EFalse);
       
  1391     aCalendarInfo.SetPropertyL(keyBuff, pkgIsSharedFolder);
       
  1392         
       
  1393     TRACE_EXIT_POINT
       
  1394     }
       
  1395 
       
  1396 // ----------------------------------------------------------------------------
       
  1397 // CCalenMultipleDbUi::Draw
       
  1398 // (other items were commented in a header).
       
  1399 // ----------------------------------------------------------------------------
       
  1400 //
       
  1401 void CCalenMultipleDbUi::Draw(const TRect& aRect) const
       
  1402     {
       
  1403     TRACE_ENTRY_POINT;
       
  1404     CWindowGc& gc = SystemGc();
       
  1405     TRect mainPane;
       
  1406     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPane );
       
  1407     TRect zerodRect( TPoint(0, 0), mainPane.Size() );
       
  1408     iBgContext->SetRect( zerodRect );
       
  1409     iBgContext->SetParentPos( mainPane.iTl );
       
  1410     AknsDrawUtils::Background( AknsUtils::SkinInstance(), iBgContext, this, gc, aRect );
       
  1411     TRACE_EXIT_POINT;
       
  1412     }
       
  1413 
       
  1414 // ----------------------------------------------------------------------------
       
  1415 // CCalenMultipleDbUi::HandleNotification
       
  1416 // Handle notifications
       
  1417 // (other items were commented in a header).
       
  1418 // ----------------------------------------------------------------------------
       
  1419 //
       
  1420 void CCalenMultipleDbUi::HandleNotification(
       
  1421 		const TCalenNotification aNotification )
       
  1422 	{
       
  1423     TRACE_ENTRY_POINT;
       
  1424     switch (aNotification)
       
  1425         {
       
  1426         case ECalenNotifyCalendarInfoCreated:
       
  1427         case ECalenNotifyCalendarInfoUpdated:
       
  1428             {
       
  1429             MCalenContext& context = iController.Services().Context();
       
  1430             TDesC& aConflictCalendarName  = context.GetCalendarFileNameL();
       
  1431             TBool isSameFileEdited = EFalse;
       
  1432             if(iCalEditedDefaultName)
       
  1433                 {
       
  1434                 if(!iCalEditedDefaultName->CompareF(aConflictCalendarName))
       
  1435                     {
       
  1436                     isSameFileEdited = ETrue; 
       
  1437                     }
       
  1438                 else
       
  1439                     {
       
  1440                     isSameFileEdited = EFalse;
       
  1441                     }
       
  1442                 }
       
  1443             
       
  1444             if (iDbEditor && isSameFileEdited)
       
  1445                 {
       
  1446                 iConflictOccured = ETrue;
       
  1447                 iDbEditor->SetConflict(CCalenMultiDBEditor::EConflictUpdate);
       
  1448                 }
       
  1449             }
       
  1450             break;
       
  1451         case ECalenNotifyCalendarFileDeleted:
       
  1452             {
       
  1453             RPointerArray<CCalCalendarInfo> calendarInfoList;
       
  1454             TBool isSameFileDeleted = EFalse;
       
  1455             iController.GetAllCalendarInfoL(calendarInfoList);
       
  1456             CleanupClosePushL(calendarInfoList);
       
  1457             if(iCalEditedDefaultName)
       
  1458                 {
       
  1459                 for(TInt i=0; i<calendarInfoList.Count(); i++)
       
  1460                     {
       
  1461                     if(!iCalEditedDefaultName->CompareF(calendarInfoList[i]->FileNameL()))
       
  1462                         {
       
  1463                         isSameFileDeleted = EFalse;
       
  1464                         break;
       
  1465                         }
       
  1466                     else
       
  1467                         {
       
  1468                         isSameFileDeleted = ETrue;
       
  1469                         }
       
  1470                     }
       
  1471                 }
       
  1472             CleanupStack::PopAndDestroy(&calendarInfoList);
       
  1473             
       
  1474             if (iDbEditor && isSameFileDeleted)
       
  1475                 {
       
  1476                 iConflictOccured = ETrue;
       
  1477                 iDbEditor->SetConflict(CCalenMultiDBEditor::EConflictDelete);
       
  1478                 }
       
  1479             }
       
  1480             break;
       
  1481         default:
       
  1482             break;
       
  1483         }
       
  1484 
       
  1485     // refresh calendar list
       
  1486     TRAP_IGNORE(UpdateListboxL());
       
  1487 
       
  1488     TRACE_EXIT_POINT;
       
  1489     }
       
  1490 
       
  1491 
       
  1492 // ----------------------------------------------------------------------------
       
  1493 // CCalenMultipleDbUi::HandleListBoxEventL
       
  1494 // Handles listbox events.
       
  1495 // (other items were commented in a header).
       
  1496 // ----------------------------------------------------------------------------
       
  1497 //
       
  1498 void CCalenMultipleDbUi::HandleListBoxEventL( CEikListBox* /*aListBox*/, 
       
  1499                                                               TListBoxEvent aEventType )
       
  1500     {
       
  1501     TRACE_ENTRY_POINT;
       
  1502  
       
  1503     if ( !MenuShowing() )
       
  1504        {
       
  1505         //Single click integration
       
  1506        if ( aEventType == EEventEnterKeyPressed ||
       
  1507             
       
  1508             aEventType == EEventItemSingleClicked )
       
  1509            {
       
  1510            const TInt index(iListBox->CurrentItemIndex());
       
  1511            if ( index != KErrNotFound && !iIsDbEditorOpen )
       
  1512                {
       
  1513                iIsDbEditorOpen = ETrue ;
       
  1514                ProcessCommandL( ECalenCmdEdit );
       
  1515                
       
  1516                }
       
  1517            }
       
  1518        }
       
  1519     TRACE_EXIT_POINT;
       
  1520     }
       
  1521 
       
  1522 //EOF