calendarui/controller/src/calenmultipledbui.cpp
branchRCL_3
changeset 13 1984aceb8774
parent 11 0f07cd1b5772
child 14 21239b3bcd78
equal deleted inserted replaced
11:0f07cd1b5772 13:1984aceb8774
   181 // Constructor
   181 // Constructor
   182 // (other items were commented in a header).
   182 // (other items were commented in a header).
   183 // ----------------------------------------------------------------------------
   183 // ----------------------------------------------------------------------------
   184 //
   184 //
   185 CCalenMultipleDbUi::CCalenMultipleDbUi(CCalenController& aController) : 
   185 CCalenMultipleDbUi::CCalenMultipleDbUi(CCalenController& aController) : 
   186     iController(aController),
   186     iController(aController)
   187     iDialogLaunched(EFalse)
       
   188     {
   187     {
   189     TRACE_ENTRY_POINT;
   188     TRACE_ENTRY_POINT;
   190     TRACE_EXIT_POINT;
   189     TRACE_EXIT_POINT;
   191     }
   190     }
   192 
   191 
   226     notificationArray.Append(ECalenNotifyCalendarInfoCreated);
   225     notificationArray.Append(ECalenNotifyCalendarInfoCreated);
   227     notificationArray.Append(ECalenNotifyCalendarInfoUpdated);
   226     notificationArray.Append(ECalenNotifyCalendarInfoUpdated);
   228     notificationArray.Append(ECalenNotifyCalendarFileDeleted);
   227     notificationArray.Append(ECalenNotifyCalendarFileDeleted);
   229     iController.RegisterForNotificationsL(this, notificationArray);
   228     iController.RegisterForNotificationsL(this, notificationArray);
   230     
   229     
       
   230     notificationArray.Close();
       
   231     
   231     iConflictOccured = EFalse;
   232     iConflictOccured = EFalse;
       
   233     
       
   234     TCallBack callBackDeleteQuery(CCalenMultipleDbUi::DoAsyncDeleteTemL, this);
       
   235     iAsyncDeletequery = new(ELeave) CAsyncCallBack(callBackDeleteQuery,CActive::EPriorityStandard);
   232     
   236     
   233     TRACE_EXIT_POINT;
   237     TRACE_EXIT_POINT;
   234     }
   238     }
   235 
   239 
   236 // ----------------------------------------------------------------------------
   240 // ----------------------------------------------------------------------------
   249         iNaviContainer->Pop(); // Remove navi pane used by settings view
   253         iNaviContainer->Pop(); // Remove navi pane used by settings view
   250         iNaviContainer = NULL; // iNaviContainer is not owned
   254         iNaviContainer = NULL; // iNaviContainer is not owned
   251         }
   255         }
   252     
   256     
   253     delete iBgContext;
   257     delete iBgContext;
       
   258     iBgContext = NULL;
   254     
   259     
   255     iListBox->Reset();
   260     iListBox->Reset();
   256     delete iListBox; 
   261     delete iListBox;
       
   262     iListBox = NULL;
   257     
   263     
   258     delete iDesArray;
   264     delete iDesArray;
       
   265     iDesArray = NULL;
   259     
   266     
   260     iColorUidArray.Close();
   267     iColorUidArray.Close();
   261     
   268     
   262     iIconIndices.Reset();
   269     iIconIndices.Reset();
   263     iIconIndices.Close();
   270     iIconIndices.Close();
   264     
   271     
   265     iAsyncExit->Cancel();
   272     iAsyncExit->Cancel();
   266     delete iAsyncExit;
   273     delete iAsyncExit;
       
   274     iAsyncExit = NULL;
       
   275     
       
   276     iAsyncDeletequery->Cancel();
       
   277     delete iAsyncDeletequery;
       
   278     iAsyncDeletequery = NULL;
       
   279         
       
   280     if(iCalendarInfoNew)
       
   281         {
       
   282         delete iCalendarInfoNew;
       
   283         iCalendarInfoNew = NULL;
       
   284         }
       
   285     
       
   286     if(iCalendarInfoOriginal)
       
   287         {
       
   288         delete iCalendarInfoOriginal;
       
   289         iCalendarInfoOriginal = NULL;
       
   290         }
   267 
   291 
   268     TRACE_EXIT_POINT;
   292     TRACE_EXIT_POINT;
   269     }
   293     }
   270 
   294 
   271 // ----------------------------------------------------------------------------
   295 // ----------------------------------------------------------------------------
   322 // ----------------------------------------------------------------------------
   346 // ----------------------------------------------------------------------------
   323 //
   347 //
   324 void CCalenMultipleDbUi::UpdateListboxL()
   348 void CCalenMultipleDbUi::UpdateListboxL()
   325     {
   349     {
   326     TRACE_ENTRY_POINT;
   350     TRACE_ENTRY_POINT;
       
   351     
       
   352     if(!iListBox)
       
   353         return;
       
   354     
   327     iListBox->View()->SetDisableRedraw( ETrue );
   355     iListBox->View()->SetDisableRedraw( ETrue );
   328     iDesArray->Reset();
   356     iDesArray->Reset();
   329     iColorUidArray.Close();
   357     iColorUidArray.Close();
   330     
   358     
   331     SetTitlePaneL();
   359     SetTitlePaneL();
   441     iNaviContainer->PushDefaultL();
   469     iNaviContainer->PushDefaultL();
   442 
   470 
   443    // Set title text
   471    // Set title text
   444     CAknTitlePane* tp = static_cast<CAknTitlePane*>(
   472     CAknTitlePane* tp = static_cast<CAknTitlePane*>(
   445                                  sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
   473                                  sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
   446 
   474     HBufC* titleText;
   447     HBufC* titleText = StringLoader::LoadLC( R_QTN_CALE_TITLE_CALENDARS , iCoeEnv );
   475     if(iIsDbEditorOpen)
       
   476         {
       
   477         titleText = StringLoader::LoadLC( R_QTN_CALE_TITLE_CALENDAR , iCoeEnv );
       
   478         }
       
   479     else
       
   480         {
       
   481         titleText = StringLoader::LoadLC( R_QTN_CALE_TITLE_CALENDARS , iCoeEnv );
       
   482         }
   448     tp->SetTextL( *titleText );  // r_qtn_cale_title_calendars
   483     tp->SetTextL( *titleText );  // r_qtn_cale_title_calendars
   449     CleanupStack::PopAndDestroy( titleText );
   484     CleanupStack::PopAndDestroy( titleText );
   450     
   485     
   451     TRACE_EXIT_POINT;
   486     TRACE_EXIT_POINT;
   452     }
   487     }
       
   488 
       
   489    
   453 
   490 
   454 
   491 
   455 // ----------------------------------------------------------------------------
   492 // ----------------------------------------------------------------------------
   456 // CCalenMultipleDbUi::DynInitMenuPaneL
   493 // CCalenMultipleDbUi::DynInitMenuPaneL
   457 // Do functionalites before options menu execs
   494 // Do functionalites before options menu execs
   536              }
   573              }
   537           }
   574           }
   538           break;
   575           break;
   539       case ECalenCmdDelete:
   576       case ECalenCmdDelete:
   540           {
   577           {
   541           DeleteItemL();
   578           iAsyncDeletequery->CallBack();
   542           }
   579 		  }
   543           break;
   580           break;
   544       case ECalenCmdItemSelect:
   581       case ECalenCmdItemSelect:
       
   582       case ECalenCmdShow:
   545           {
   583           {
   546           DoSelectionL(ETrue);
   584           DoSelectionL(ETrue);
   547           }
   585           }
   548           break;
   586           break;
   549       case ECalenCmdItemDeselect:
   587       case ECalenCmdItemDeselect:
       
   588       case ECalenCmdHide:
   550           {
   589           {
   551           DoSelectionL(EFalse);
   590           DoSelectionL(EFalse);
   552           }
   591           }
   553           break;
   592           break;
   554       case EAknCmdExit:
   593       case EAknCmdExit:
   556           {
   595           {
   557           iAsyncExitCmd = EAknSoftkeyExit;
   596           iAsyncExitCmd = EAknSoftkeyExit;
   558           iAsyncExit->CallBack();
   597           iAsyncExit->CallBack();
   559           }
   598           }
   560           break;
   599           break;
   561      case ECalenCmdShow:
       
   562           {
       
   563           DoSelectionL( ETrue );
       
   564           }
       
   565           break;
       
   566 
       
   567       case ECalenCmdHide:   
       
   568           {
       
   569           DoSelectionL( EFalse );
       
   570           }
       
   571           break;             
       
   572           
       
   573       default:
   600       default:
   574           break;
   601           break;
   575       }
   602       }
   576     TRACE_EXIT_POINT;
   603     TRACE_EXIT_POINT;
   577     }
   604     }
   604 // ----------------------------------------------------------------------------
   631 // ----------------------------------------------------------------------------
   605 //
   632 //
   606 TInt CCalenMultipleDbUi::AddItemL()
   633 TInt CCalenMultipleDbUi::AddItemL()
   607     {
   634     {
   608     TRACE_ENTRY_POINT
   635     TRACE_ENTRY_POINT
   609     TInt retValue = KErrNotFound;
   636     TInt retValue = 0;
   610     
   637     
   611     CCalCalendarInfo* calendarInfo = CCalCalendarInfo::NewL();
   638     if(iCalendarInfoNew)
   612     calendarInfo->SetNameL(KNullDesC16);
   639         {
   613     calendarInfo->SetColor(255);
   640         delete iCalendarInfoNew;
   614     calendarInfo->SetEnabled(ETrue);
   641         iCalendarInfoNew = NULL;
   615     iDbEditor = CCalenMultiDBEditor::NewL( *calendarInfo, iController, EFalse );
   642         }
       
   643     
       
   644     iCalendarInfoNew = CCalCalendarInfo::NewL();
       
   645     iCalendarInfoNew->SetNameL(KNullDesC16);
       
   646     iCalendarInfoNew->SetColor(255);
       
   647     iCalendarInfoNew->SetEnabled(ETrue);
       
   648     iDbEditor = CCalenMultiDBEditor::NewL(*this,*iCalendarInfoNew, iController, EFalse );
   616   
   649   
   617     iDialogLaunched = ETrue;
   650     //Async dialog
   618     retValue = iDbEditor->ExecuteLD();
   651     retValue = iDbEditor->ExecuteLD();
   619     iDbEditor = NULL;
   652     iDbEditor = NULL;
   620     iDialogLaunched = EFalse; 
   653      
   621     
       
   622     if(EAknCmdExit == retValue )
   654     if(EAknCmdExit == retValue )
   623         {
   655         {
   624         iController.BroadcastNotification(ECalenNotifyRealExit);
   656         iController.BroadcastNotification(ECalenNotifyRealExit);
   625         }
   657         }
   626     
   658     
   627     HBufC* calendarName = calendarInfo->NameL().AllocLC();
   659     TRACE_EXIT_POINT
   628     calendarName->Des().Trim();
   660     return retValue;
   629     if(calendarName->Length() > 0)
   661     }
   630         {
   662 
   631         
   663 
       
   664 // ----------------------------------------------------------------------------
       
   665 // CCalenMultipleDbUi::UpdateAddOrEditL
       
   666 // ----------------------------------------------------------------------------
       
   667 //
       
   668 void CCalenMultipleDbUi::UpdateOnAddOrEditL(TBool aItemAdded)
       
   669     {
       
   670     TRACE_ENTRY_POINT
       
   671     
       
   672     if(aItemAdded)
       
   673         {
   632         // Set calendar properties for new calendar being created.
   674         // Set calendar properties for new calendar being created.
   633         SetCalendarAddPropertiesL(*calendarInfo);
   675         SetCalendarAddPropertiesL(*iCalendarInfoNew);
   634         
   676        
   635         iController.AddCalendarL(calendarInfo);
   677         iController.AddCalendarL(iCalendarInfoNew);
   636         
   678         iCalendarInfoNew = NULL;
   637         UpdateListboxL();
   679        
   638         
       
   639         //Highlight the newly created list item
   680         //Highlight the newly created list item
   640         iListBox->ScrollToMakeItemVisible(iListBox->BottomItemIndex());
   681         iListBox->ScrollToMakeItemVisible(iListBox->BottomItemIndex());
   641         iListBox->SetCurrentItemIndexAndDraw(iDesArray->Count()-1);
   682         iListBox->SetCurrentItemIndexAndDraw(iDesArray->Count()-1);
   642         }
   683         }
   643     else 
   684     else
   644         {
   685         {
   645         delete calendarInfo;
   686         //Before checking for changes , check if any conflict occured i.e calendar updated / deleted.
   646         }
   687         //if there is conflict iConflictOccured = true then skip below condition.
   647     
   688         if (!iConflictOccured && iCalendarInfoOriginal &&
   648     CleanupStack::PopAndDestroy(calendarName);  
   689                 CheckForChangesL(*iCalendarInfoOriginal,
       
   690                 *iCalendarInfoEdited))
       
   691             {
       
   692             // update the calendar properties such as modification time, sync status.
       
   693             SetCalendarUpdatePropertiesL(*iCalendarInfoEdited);
       
   694             
       
   695             iController.UpdateCalendarL(iCalendarInfoEdited);
       
   696             }
       
   697 
       
   698         iConflictOccured = EFalse;
       
   699         delete iCalendarInfoOriginal,iCalendarInfoOriginal = NULL;
       
   700         }
       
   701     iIsDbEditorOpen = EFalse ; //iIsDbEditorOpen should be set before calling UpdateListboxL() 
       
   702     UpdateListboxL();
   649     
   703     
   650     TRACE_EXIT_POINT
   704     TRACE_EXIT_POINT
   651     return retValue;
   705     }
       
   706 
       
   707 // ----------------------------------------------------------------------------
       
   708 // CCalenMultipleDbUi::ExitDialogL
       
   709 // Edit item from listbox 
       
   710 // ----------------------------------------------------------------------------
       
   711 //
       
   712 void CCalenMultipleDbUi::ExitDialogL()
       
   713     {
       
   714     TRACE_ENTRY_POINT
       
   715     iAsyncExitCmd = EAknSoftkeyExit;
       
   716     iAsyncExit->CallBack();
       
   717     TRACE_EXIT_POINT
   652     }
   718     }
   653 
   719 
   654 // ----------------------------------------------------------------------------
   720 // ----------------------------------------------------------------------------
   655 // CCalenMultipleDbUi::EditItemL
   721 // CCalenMultipleDbUi::EditItemL
   656 // Edit item from listbox 
   722 // Edit item from listbox 
   659 TInt CCalenMultipleDbUi::EditItemL()
   725 TInt CCalenMultipleDbUi::EditItemL()
   660     {
   726     {
   661     TRACE_ENTRY_POINT
   727     TRACE_ENTRY_POINT
   662     TInt retValue = KErrNotFound;
   728     TInt retValue = KErrNotFound;
   663     TInt currentIndex = iListBox->CurrentItemIndex();
   729     TInt currentIndex = iListBox->CurrentItemIndex();
   664     TInt listCount = iListBox->Model()->ItemTextArray()->MdcaCount();
   730     
   665 
       
   666     RPointerArray<CCalCalendarInfo> calendarInfoList;
   731     RPointerArray<CCalCalendarInfo> calendarInfoList;
   667     iController.GetAllCalendarInfoL(calendarInfoList);
   732     iController.GetAllCalendarInfoL(calendarInfoList);
   668     CleanupClosePushL(calendarInfoList);
   733     CleanupClosePushL(calendarInfoList);
   669     
   734     
   670     CCalCalendarInfo* calendarInfoedited = calendarInfoList[currentIndex];
   735     iCalendarInfoEdited = calendarInfoList[currentIndex];
       
   736     
       
   737     CleanupStack::PopAndDestroy(&calendarInfoList);
   671     
   738     
   672     //Take a copy of original before editing
   739     //Take a copy of original before editing
   673     CCalCalendarInfo* calendarInfoOriginal = CCalCalendarInfo::NewL();
   740     if(iCalendarInfoOriginal)
   674     CleanupStack::PushL(calendarInfoOriginal);
   741         {
   675     calendarInfoOriginal->SetNameL(calendarInfoedited->NameL());
   742         delete iCalendarInfoOriginal;
   676     calendarInfoOriginal->SetColor(calendarInfoedited->Color());
   743         iCalendarInfoOriginal = NULL;
   677     calendarInfoOriginal->SetEnabled(calendarInfoedited->Enabled());
   744         }
       
   745     iCalendarInfoOriginal = CCalCalendarInfo::NewL();
       
   746     
       
   747     iCalendarInfoOriginal->SetNameL(iCalendarInfoEdited->NameL());
       
   748     iCalendarInfoOriginal->SetColor(iCalendarInfoEdited->Color());
       
   749     iCalendarInfoOriginal->SetEnabled(iCalendarInfoEdited->Enabled());
   678     TBuf8<KBuffLength> keyBuff;
   750     TBuf8<KBuffLength> keyBuff;
   679     TBool syncstatus = EFalse;
   751     TBool syncstatus = EFalse;
   680     keyBuff.Zero();
   752     keyBuff.Zero();
   681     keyBuff.AppendNum( ESyncStatus ); 
   753     keyBuff.AppendNum( ESyncStatus ); 
   682     TPckgC<TBool> pckgSyncStatusValue(syncstatus);
   754     TPckgC<TBool> pckgSyncStatusValue(syncstatus);
   683     pckgSyncStatusValue.Set(calendarInfoedited->PropertyValueL( keyBuff ));
   755     pckgSyncStatusValue.Set(iCalendarInfoEdited->PropertyValueL( keyBuff ));
   684     calendarInfoOriginal->SetPropertyL( keyBuff, pckgSyncStatusValue );                
   756     iCalendarInfoOriginal->SetPropertyL( keyBuff, pckgSyncStatusValue );                
   685 
   757 
   686     iDbEditor = CCalenMultiDBEditor::NewL(*calendarInfoedited, iController,
   758     iDbEditor = CCalenMultiDBEditor::NewL(*this,*iCalendarInfoEdited, iController,
   687             ETrue);
   759             ETrue);
   688 
   760 
   689     iDialogLaunched = ETrue;
   761     //Async dialog
   690     retValue = iDbEditor->ExecuteLD();
   762     retValue = iDbEditor->ExecuteLD();
   691     iDbEditor = NULL;
   763     iDbEditor = NULL;
   692     iDialogLaunched = EFalse;
   764     
   693 
       
   694     //Before checking for changes , check if any conflict occured i.e calendar updated / deleted.
       
   695     //if there is conflict iConflictOccured = true then skip below condition.
       
   696     if (!iConflictOccured && CheckForChangesL(*calendarInfoOriginal,
       
   697             *calendarInfoedited))
       
   698         {
       
   699         // update the calendar properties such as modification time, sync status.
       
   700         SetCalendarUpdatePropertiesL(*calendarInfoedited);
       
   701         
       
   702         iController.UpdateCalendarL(calendarInfoedited);
       
   703         }
       
   704 
       
   705     iConflictOccured = EFalse;
       
   706 
       
   707     UpdateListboxL();
       
   708 
       
   709     //If conflict occured i.e calendar deleted check for list count before and after
       
   710     //and update focus accordingly
       
   711     if (listCount != iListBox->Model()->ItemTextArray()->MdcaCount())
       
   712         {
       
   713         ReAdjustListItemFocusL(currentIndex);
       
   714         }
       
   715 
       
   716     CleanupStack::PopAndDestroy(calendarInfoOriginal);
       
   717     CleanupStack::PopAndDestroy(&calendarInfoList);
       
   718     return retValue;
   765     return retValue;
   719     TRACE_EXIT_POINT
   766     TRACE_EXIT_POINT
   720     }
   767     }
   721 
   768 
   722 // ----------------------------------------------------------------------------
   769 // ----------------------------------------------------------------------------
   838     TKeyResponse exitCode(EKeyWasNotConsumed);
   885     TKeyResponse exitCode(EKeyWasNotConsumed);
   839     if(aType == EEventKey )
   886     if(aType == EEventKey )
   840         {
   887         {
   841         if( aKeyEvent.iCode == EKeyEscape )
   888         if( aKeyEvent.iCode == EKeyEscape )
   842             {
   889             {
   843             TryExitL( EKeyNo );
   890             TryExitL( EKeyEscape );
   844             return exitCode; // Chain this one up to the main app so it closes calendar app.
   891             return exitCode; // Chain this one up to the main app so it closes calendar app.
   845             }
   892             }
   846          else if(aType == EEventKey && TChar(aKeyEvent.iCode).IsPrint() )
   893          else if(aType == EEventKey && TChar(aKeyEvent.iCode).IsPrint() )
   847             {
   894             {
   848             ProcessCommandL(ECalenCmdAdd);
   895             ProcessCommandL(ECalenCmdAdd);
   917            {
   964            {
   918            ProcessCommandL(ECalenCmdEdit);
   965            ProcessCommandL(ECalenCmdEdit);
   919            }
   966            }
   920            break;
   967            break;
   921        case EAknSoftkeyBack:
   968        case EAknSoftkeyBack:
       
   969        case EKeyEscape:
   922            {
   970            {
   923            iController.BroadcastNotification(ECalenNotifyDeleteInstanceView);
   971            iController.BroadcastNotification(ECalenNotifyDeleteInstanceView);
   924            okExit = ETrue;
       
   925            }
       
   926            break;
       
   927 	   case EKeyEscape:
       
   928            {
       
   929            okExit = ETrue;
   972            okExit = ETrue;
   930            }
   973            }
   931            break;
   974            break;
   932        default:
   975        default:
   933            {
   976            {
  1124     CCalenMultipleDbUi* self = static_cast<CCalenMultipleDbUi*>(aPtr);
  1167     CCalenMultipleDbUi* self = static_cast<CCalenMultipleDbUi*>(aPtr);
  1125     self->TryExitL(self->iAsyncExitCmd);
  1168     self->TryExitL(self->iAsyncExitCmd);
  1126     TRACE_EXIT_POINT
  1169     TRACE_EXIT_POINT
  1127     return 0;
  1170     return 0;
  1128     }
  1171     }
       
  1172 // ----------------------------------------------------------------------------
       
  1173 // CCalenMultipleDbUi::CallBackForDeleteItemL
       
  1174 // (other items were commented in a header).
       
  1175 // ----------------------------------------------------------------------------
       
  1176 //
       
  1177 TInt CCalenMultipleDbUi::DoAsyncDeleteTemL(TAny* aPtr)
       
  1178     {
       
  1179     TRACE_ENTRY_POINT
       
  1180     CCalenMultipleDbUi* self = static_cast<CCalenMultipleDbUi*>(aPtr);
       
  1181     self->DeleteItemL();
       
  1182     TRACE_EXIT_POINT
       
  1183     return 0;
       
  1184     }
  1129 
  1185 
  1130 // ----------------------------------------------------------------------------
  1186 // ----------------------------------------------------------------------------
  1131 // CCalenMultipleDbUi::CreateButtonL
  1187 // CCalenMultipleDbUi::CreateButtonL
  1132 // (other items were commented in a header).
  1188 // (other items were commented in a header).
  1133 // ----------------------------------------------------------------------------
  1189 // ----------------------------------------------------------------------------
  1351            const TInt index(iListBox->CurrentItemIndex());
  1407            const TInt index(iListBox->CurrentItemIndex());
  1352            if ( index != KErrNotFound && !iIsDbEditorOpen )
  1408            if ( index != KErrNotFound && !iIsDbEditorOpen )
  1353                {
  1409                {
  1354                iIsDbEditorOpen = ETrue ;
  1410                iIsDbEditorOpen = ETrue ;
  1355                ProcessCommandL( ECalenCmdEdit );
  1411                ProcessCommandL( ECalenCmdEdit );
  1356                iIsDbEditorOpen = EFalse ;
  1412                
  1357                }
  1413                }
  1358            }
  1414            }
  1359        }
  1415        }
  1360     TRACE_EXIT_POINT;
  1416     TRACE_EXIT_POINT;
  1361     }
  1417     }