calendarui/controller/src/calencontroller.cpp
changeset 50 579cc610882e
parent 49 5de72ea7a065
child 58 ef813d54df51
equal deleted inserted replaced
49:5de72ea7a065 50:579cc610882e
    63     //as services so using the above line temporarily untill a fix is available in 
    63     //as services so using the above line temporarily untill a fix is available in 
    64     // hbappliacation. Need to remove this line after the fix is available for hbapplcation
    64     // hbappliacation. Need to remove this line after the fix is available for hbapplcation
    65     
    65     
    66     iNextServicesCommandBase = KCustomCommandRangeStart;
    66     iNextServicesCommandBase = KCustomCommandRangeStart;
    67     iRefCount = 0;
    67     iRefCount = 0;
    68     
    68     mAgendaUtil = 0;
    69     // Store the pointer in tls, also avoid multiple creations
    69     
    70     checkMultipleCreation();
    70     TRACE_EXIT_POINT;
    71     
    71 }
    72     // Get an instance of AgendaUtil interface class
    72 
    73     // This will take care of 
    73 // ----------------------------------------------------------------------------
    74     mAgendaUtil = new AgendaUtil();
    74 // CCalenController::constuctController
    75     
    75 // Construct the controller completely
    76     iStateMachine = CCalenStateMachine::NewL( *this );
    76 // (other items were commented in a header).
    77     
    77 // ----------------------------------------------------------------------------
    78     // Create the notifier.
    78 //
    79     iNotifier = new( ELeave )CalenNotifier( *iStateMachine );
    79 void CCalenController::constructController()
    80     
    80 {
    81     // Construct the context
    81 	// Store the pointer in tls, also avoid multiple creations
    82     mContext = new CalenContextImpl(iNotifier);
    82 	checkMultipleCreation();
    83     
    83 
    84     // Set the default context.Once will start use of calencmdlinelauncher,
    84 	// Get an instance of AgendaUtil interface class
    85     // Then need to remove this function
    85 	// This will take care of 
    86     SetDefaultContext();
    86 	mAgendaUtil = new AgendaUtil();
    87     
    87 
    88     RArray<TCalenNotification> notificationArray;
    88 	iStateMachine = CCalenStateMachine::NewL( *this );
    89     // Complete construction of the notifier and register the
    89 
    90     // global data for notifications
    90 	// Create the notifier.
    91     iNotifier->ConstructL();
    91 	iNotifier = new( ELeave )CalenNotifier( *iStateMachine );
    92     
    92 
    93     // Create the services
    93 	// Construct the context
    94     iServices = CalenServicesImpl::NewL();
    94 	mContext = new CalenContextImpl(iNotifier);
    95     // Create the customisation manager, and register for 
    95 
    96     // notifications
    96 	// Set the default context.Once will start use of calencmdlinelauncher,
    97     iCustomisationManager = CCalenCustomisationManager::NewL( *this,
    97 	// Then need to remove this function
    98                                                                   *iServices );
    98 	SetDefaultContext();
    99     // Create the view manager, and register for notifications
    99 
       
   100 	RArray<TCalenNotification> notificationArray;
       
   101 	// Complete construction of the notifier and register the
       
   102 	// global data for notifications
       
   103 	iNotifier->ConstructL();
       
   104 
       
   105 	// Create the services
       
   106 	iServices = CalenServicesImpl::NewL();
       
   107 	// Create the customisation manager, and register for 
       
   108 	// notifications
       
   109 	iCustomisationManager = CCalenCustomisationManager::NewL( *this,
       
   110 	                                                          *iServices );
       
   111 	// Create the view manager, and register for notifications
   100 	iViewManager = new CalenViewManager(*this);
   112 	iViewManager = new CalenViewManager(*this);
   101 	
   113 
   102 	iViewManager->SecondPhaseConstruction();
   114 	iViewManager->SecondPhaseConstruction();
   103 	
   115 
   104 	hbInstance->allMainWindows().first()->show();
   116 	hbInstance->allMainWindows().first()->show();
   105     
   117 
   106     // Create the action uis.
   118 	// Create the action uis.
   107     iActionUi = CCalenActionUi::NewL( *this );
   119 	iActionUi = CCalenActionUi::NewL( *this );
   108                                                                     
   120 
   109     notificationArray.Append(ECalenNotifySettingsChanged);
   121 	notificationArray.Append(ECalenNotifySettingsChanged);
   110     notificationArray.Append(ECalenNotifyCheckPluginUnloading);
   122 	notificationArray.Append(ECalenNotifyCheckPluginUnloading);
   111     notificationArray.Append(ECalenNotifyEComRegistryChanged);
   123 	notificationArray.Append(ECalenNotifyEComRegistryChanged);
   112     notificationArray.Append(ECalenNotifySystemLanguageChanged);
   124 	notificationArray.Append(ECalenNotifySystemLanguageChanged);
   113     
   125 
   114     RegisterForNotificationsL( iCustomisationManager,notificationArray);
   126 	RegisterForNotificationsL( iCustomisationManager,notificationArray);
   115     notificationArray.Reset();
   127 	notificationArray.Reset();
   116     
   128 
   117     notificationArray.Append(ECalenNotifyViewPopulationComplete);
   129 	notificationArray.Append(ECalenNotifyViewPopulationComplete);
   118     notificationArray.Append(ECalenNotifyExternalDatabaseChanged);
   130 	notificationArray.Append(ECalenNotifyExternalDatabaseChanged);
   119     notificationArray.Append(ECalenNotifyMultipleEntriesDeleted);
   131 	notificationArray.Append(ECalenNotifyMultipleEntriesDeleted);
   120     notificationArray.Append(ECalenNotifyDialogClosed);
   132 	notificationArray.Append(ECalenNotifyDialogClosed);
   121     notificationArray.Append(ECalenNotifyEntrySaved);
   133 	notificationArray.Append(ECalenNotifyEntrySaved);
   122     notificationArray.Append(ECalenNotifyEntryDeleted);
   134 	notificationArray.Append(ECalenNotifyEntryDeleted);
   123     notificationArray.Append(ECalenNotifyInstanceDeleted);
   135 	notificationArray.Append(ECalenNotifyInstanceDeleted);
   124     notificationArray.Append(ECalenNotifySystemLocaleChanged);
   136 	notificationArray.Append(ECalenNotifySystemLocaleChanged);
   125     notificationArray.Append(ECalenNotifySystemLanguageChanged);
   137 	notificationArray.Append(ECalenNotifySystemLanguageChanged);
   126     notificationArray.Append(ECalenNotifySystemTimeChanged);
   138 	notificationArray.Append(ECalenNotifySystemTimeChanged);
   127     notificationArray.Append(ECalenNotifyEntryClosed);
   139 	notificationArray.Append(ECalenNotifyEntryClosed);
   128     notificationArray.Append(ECalenNotifySettingsClosed);
   140 	notificationArray.Append(ECalenNotifySettingsClosed);
   129     		
   141 
   130     RegisterForNotificationsL( iViewManager, notificationArray );
   142 	RegisterForNotificationsL( iViewManager, notificationArray );
   131     notificationArray.Reset();  
   143 	notificationArray.Reset();  
   132     notificationArray.Close();
   144 	notificationArray.Close();
   133     TRACE_EXIT_POINT;
       
   134 }
   145 }
   135 
   146 
   136 void CCalenController::checkMultipleCreation()
   147 void CCalenController::checkMultipleCreation()
   137 {
   148 {
   138 	TAny* tlsPtr = Dll::Tls();
   149 	TAny* tlsPtr = Dll::Tls();
   248     if ( iServices )
   259     if ( iServices )
   249         {
   260         {
   250         iServices->Release();
   261         iServices->Release();
   251         }
   262         }
   252     
   263     
       
   264     if( mContext )
       
   265 		{
       
   266 		delete mContext;
       
   267 		mContext = NULL;
       
   268 		}
       
   269     // iActionUi has to be deleted before iNotifier
       
   270     // as the unregistering of the notifications has to be done
       
   271     if( iActionUi )
       
   272  	   {
       
   273  	   delete iActionUi;
       
   274  	   iActionUi = NULL;
       
   275  	   }
       
   276     
   253     if( iNotifier )
   277     if( iNotifier )
   254 		{
   278 		{
   255     	delete iNotifier;
   279     	delete iNotifier;
   256     	iNotifier = NULL;
   280     	iNotifier = NULL;
   257 		}
   281 		}
   258 
   282     
   259     if(mContext) {
       
   260     	delete mContext;
       
   261     	mContext = NULL;
       
   262     }
       
   263 	
       
   264    if( iActionUi )
       
   265 	   {
       
   266 	   delete iActionUi;
       
   267 	   iActionUi = NULL;
       
   268 	   }
       
   269    
       
   270     if( iViewManager )
   283     if( iViewManager )
   271 		{
   284 		{
   272     	delete iViewManager;
   285     	delete iViewManager;
   273     	iViewManager = NULL;
   286     	iViewManager = NULL;
   274 		}
   287 		}
   276     if( iCustomisationManager )
   289     if( iCustomisationManager )
   277 		{
   290 		{
   278     	delete iCustomisationManager;
   291     	delete iCustomisationManager;
   279     	iCustomisationManager = NULL;
   292     	iCustomisationManager = NULL;
   280 		}
   293 		}
   281     
   294 		
       
   295     if (mAgendaUtil) {
       
   296         delete mAgendaUtil;
       
   297         mAgendaUtil = 0;
       
   298     }
   282     
   299     
   283     Dll::SetTls( NULL );
   300     Dll::SetTls( NULL );
   284     
   301     
   285     TRACE_EXIT_POINT;
   302     TRACE_EXIT_POINT;
   286     }
   303     }
   531 //       
   548 //       
   532 void CCalenController::SetDefaultContext()
   549 void CCalenController::SetDefaultContext()
   533     {
   550     {
   534     TRACE_ENTRY_POINT;  
   551     TRACE_ENTRY_POINT;  
   535     QDateTime focusTime = mContext->defaultCalTimeForViewsL();
   552     QDateTime focusTime = mContext->defaultCalTimeForViewsL();
   536     mContext->setFocusDateAndTimeL(focusTime,KCalenDayViewUidValue );
   553     mContext->setFocusDateAndTime(focusTime);
   537     TRACE_EXIT_POINT;
   554     TRACE_EXIT_POINT;
   538     }
   555     }
   539 
   556 
   540 // ----------------------------------------------------------------------------
   557 // ----------------------------------------------------------------------------
   541 // CCalenController::OfferMenu
   558 // CCalenController::OfferMenu
   586 void CCalenController::handleServiceManagerSlot(int view, const QDateTime& dateTime)
   603 void CCalenController::handleServiceManagerSlot(int view, const QDateTime& dateTime)
   587 {
   604 {
   588 	
   605 	
   589 	if (iIsFromServiceFrmWrk) {
   606 	if (iIsFromServiceFrmWrk) {
   590 		// Set the context properly
   607 		// Set the context properly
   591 		mContext->setFocusDateAndTimeL(dateTime,KCalenMonthViewUidValue);
   608 		mContext->setFocusDateAndTime(dateTime);
   592 		// launch the appropriate view
   609 		// launch the appropriate view
   593 		iViewManager->constructAndActivateView(view);
   610 		iViewManager->constructAndActivateView(view);
   594 		
   611 		
   595 		// Construct other views
       
   596 		iViewManager->constructOtherViews();
       
   597 
       
   598 	} else { // Calendar was in backgroung but now its being brought to foreground
   612 	} else { // Calendar was in backgroung but now its being brought to foreground
   599 		// If current state is editing state or printing state
   613 		// If current state is editing state or printing state
   600 		// or deleting state or sending state, then dont do anything as
   614 		// or deleting state or sending state, then dont do anything as
   601 		// user might loose the data
   615 		// user might loose the data
   602 		CCalenStateMachine::TCalenStateIndex currentState = iStateMachine->CurrentState();
   616 		CCalenStateMachine::TCalenStateIndex currentState = iStateMachine->CurrentState();
   605 			(currentState == CCalenStateMachine::ECalenPrintingState) ||
   619 			(currentState == CCalenStateMachine::ECalenPrintingState) ||
   606 			(currentState == CCalenStateMachine::ECalenSendingState)) {
   620 			(currentState == CCalenStateMachine::ECalenSendingState)) {
   607 			// simply return - we dont have anything to do
   621 			// simply return - we dont have anything to do
   608 		} else {
   622 		} else {
   609 			// Set the context properly
   623 			// Set the context properly
   610 			mContext->setFocusDateAndTimeL(dateTime,KCalenMonthViewUidValue);
   624 			mContext->setFocusDateAndTime(dateTime);
   611 			IssueCommandL(view);
   625 			IssueCommandL(view);
   612 		}
   626 		}
   613 	}
   627 	}
   614 }
   628 }
   615 
   629