calendarui/controller/src/calencontroller.cpp
changeset 45 b6db4fd4947b
parent 23 fd30d51f876b
child 46 ecd7b9840282
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
    18 
    18 
    19 #include <e32std.h>
    19 #include <e32std.h>
    20 #include <hbmainwindow.h>
    20 #include <hbmainwindow.h>
    21 #include <hbwidget.h>
    21 #include <hbwidget.h>
    22 #include <hbinstance.h>
    22 #include <hbinstance.h>
       
    23 #include <hbapplication.h> //Activity Manager
       
    24 #include <xqserviceutil.h> // service utils
    23 
    25 
    24 // User includes
    26 // User includes
    25 #include "calencontroller.h"            // CCalenController
    27 #include "calencontroller.h"            // CCalenController
    26 #include "calenviewmanager.h"           // Responsible for all view activations        
    28 #include "calenviewmanager.h"           // Responsible for all view activations        
    27 #include "calenservicesimpl.h"          // MCalenServices implementation
    29 #include "calenservicesimpl.h"          // MCalenServices implementation
    44 // CCalenController::CCalenController
    46 // CCalenController::CCalenController
    45 // Constructor
    47 // Constructor
    46 // (other items were commented in a header).
    48 // (other items were commented in a header).
    47 // ----------------------------------------------------------------------------
    49 // ----------------------------------------------------------------------------
    48 //
    50 //
    49 CCalenController::CCalenController(bool isFromServiceFrmwrk)
    51 CCalenController::CCalenController()
    50 {
    52 {
    51     TRACE_ENTRY_POINT;
    53     TRACE_ENTRY_POINT;
    52     iIsFromServiceFrmWrk = isFromServiceFrmwrk;
    54 	// Check the Application Startup reason, set iIsFromServiceFrmWrk if application
       
    55 	// is started by service framework, false otherwise
       
    56     /*Hb::ActivationReasonService == qobject_cast<HbApplication*>(qApp)->activateReason() ? 
       
    57         iIsFromServiceFrmWrk = true:
       
    58         iIsFromServiceFrmWrk = false; */
       
    59     
       
    60     // Check if calendar is launched thru XQService framework
       
    61     iIsFromServiceFrmWrk = XQServiceUtil::isService(); // Since activateReason 
       
    62     //of hbapplication is not returning right value if the activity is started 
       
    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
       
    65     
    53     iNextServicesCommandBase = KCustomCommandRangeStart;
    66     iNextServicesCommandBase = KCustomCommandRangeStart;
    54     
    67     iRefCount = 0;
    55     // Store the pointer in tls, also avoid multiple creations
    68     
    56     checkMultipleCreation();
    69     TRACE_EXIT_POINT;
    57     
    70 }
    58     // Get an instance of AgendaUtil interface class
    71 
    59     // This will take care of 
    72 // ----------------------------------------------------------------------------
    60     mAgendaUtil = new AgendaUtil();
    73 // CCalenController::constuctController
    61     
    74 // Construct the controller completely
    62     iStateMachine = CCalenStateMachine::NewL( *this );
    75 // (other items were commented in a header).
    63     
    76 // ----------------------------------------------------------------------------
    64     // Create the notifier.
    77 //
    65     iNotifier = new( ELeave )CalenNotifier( *iStateMachine );
    78 void CCalenController::constructController()
    66     
    79 {
    67     // Construct the context
    80 	// Store the pointer in tls, also avoid multiple creations
    68     mContext = new CalenContextImpl(iNotifier);
    81 	checkMultipleCreation();
    69     
    82 
    70     // Set the default context.Once will start use of calencmdlinelauncher,
    83 	// Get an instance of AgendaUtil interface class
    71     // Then need to remove this function
    84 	// This will take care of 
    72     SetDefaultContext();
    85 	mAgendaUtil = new AgendaUtil();
    73     
    86 
    74     RArray<TCalenNotification> notificationArray;
    87 	iStateMachine = CCalenStateMachine::NewL( *this );
    75     // Complete construction of the notifier and register the
    88 
    76     // global data for notifications
    89 	// Create the notifier.
    77     iNotifier->ConstructL();
    90 	iNotifier = new( ELeave )CalenNotifier( *iStateMachine );
    78     
    91 
    79     // Create the services
    92 	// Construct the context
    80     iServices = CalenServicesImpl::NewL();
    93 	mContext = new CalenContextImpl(iNotifier);
    81     // Create the customisation manager, and register for 
    94 
    82     // notifications
    95 	// Set the default context.Once will start use of calencmdlinelauncher,
    83     iCustomisationManager = CCalenCustomisationManager::NewL( *this,
    96 	// Then need to remove this function
    84                                                                   *iServices );
    97 	SetDefaultContext();
    85     // Create the view manager, and register for notifications
    98 
    86 	iViewManager = new CalenViewManager(*this, isFromServiceFrmwrk );
    99 	RArray<TCalenNotification> notificationArray;
    87 	
   100 	// Complete construction of the notifier and register the
       
   101 	// global data for notifications
       
   102 	iNotifier->ConstructL();
       
   103 
       
   104 	// Create the services
       
   105 	iServices = CalenServicesImpl::NewL();
       
   106 	// Create the customisation manager, and register for 
       
   107 	// notifications
       
   108 	iCustomisationManager = CCalenCustomisationManager::NewL( *this,
       
   109 	                                                          *iServices );
       
   110 	// Create the view manager, and register for notifications
       
   111 	iViewManager = new CalenViewManager(*this);
       
   112 
       
   113 	iViewManager->SecondPhaseConstruction();
       
   114 
    88 	hbInstance->allMainWindows().first()->show();
   115 	hbInstance->allMainWindows().first()->show();
    89     
   116 
    90     // Create the action uis.
   117 	// Create the action uis.
    91     iActionUi = CCalenActionUi::NewL( *this );
   118 	iActionUi = CCalenActionUi::NewL( *this );
    92                                                                     
   119 
    93     notificationArray.Append(ECalenNotifySettingsChanged);
   120 	notificationArray.Append(ECalenNotifySettingsChanged);
    94     notificationArray.Append(ECalenNotifyCheckPluginUnloading);
   121 	notificationArray.Append(ECalenNotifyCheckPluginUnloading);
    95     notificationArray.Append(ECalenNotifyEComRegistryChanged);
   122 	notificationArray.Append(ECalenNotifyEComRegistryChanged);
    96     
   123 	notificationArray.Append(ECalenNotifySystemLanguageChanged);
    97     RegisterForNotificationsL( iCustomisationManager,notificationArray);
   124 
    98     notificationArray.Reset();
   125 	RegisterForNotificationsL( iCustomisationManager,notificationArray);
    99     
   126 	notificationArray.Reset();
   100     notificationArray.Append(ECalenNotifyViewPopulationComplete);
   127 
   101     notificationArray.Append(ECalenNotifyExternalDatabaseChanged);
   128 	notificationArray.Append(ECalenNotifyViewPopulationComplete);
   102     notificationArray.Append(ECalenNotifyMultipleEntriesDeleted);
   129 	notificationArray.Append(ECalenNotifyExternalDatabaseChanged);
   103     notificationArray.Append(ECalenNotifyDialogClosed);
   130 	notificationArray.Append(ECalenNotifyMultipleEntriesDeleted);
   104     notificationArray.Append(ECalenNotifyEntrySaved);
   131 	notificationArray.Append(ECalenNotifyDialogClosed);
   105     notificationArray.Append(ECalenNotifyEntryDeleted);
   132 	notificationArray.Append(ECalenNotifyEntrySaved);
   106     notificationArray.Append(ECalenNotifyInstanceDeleted);
   133 	notificationArray.Append(ECalenNotifyEntryDeleted);
   107     notificationArray.Append(ECalenNotifySystemLocaleChanged);
   134 	notificationArray.Append(ECalenNotifyInstanceDeleted);
   108     notificationArray.Append(ECalenNotifySystemTimeChanged);
   135 	notificationArray.Append(ECalenNotifySystemLocaleChanged);
   109     notificationArray.Append(ECalenNotifyEntryClosed);
   136 	notificationArray.Append(ECalenNotifySystemLanguageChanged);
   110     notificationArray.Append(ECalenNotifySettingsClosed);
   137 	notificationArray.Append(ECalenNotifySystemTimeChanged);
   111     		
   138 	notificationArray.Append(ECalenNotifyEntryClosed);
   112     RegisterForNotificationsL( iViewManager, notificationArray );
   139 	notificationArray.Append(ECalenNotifySettingsClosed);
   113     notificationArray.Reset();  
   140 
   114     notificationArray.Close();
   141 	RegisterForNotificationsL( iViewManager, notificationArray );
   115     TRACE_EXIT_POINT;
   142 	notificationArray.Reset();  
       
   143 	notificationArray.Close();
   116 }
   144 }
   117 
   145 
   118 void CCalenController::checkMultipleCreation()
   146 void CCalenController::checkMultipleCreation()
   119 {
   147 {
   120 	TAny* tlsPtr = Dll::Tls();
   148 	TAny* tlsPtr = Dll::Tls();
   169     ++self->iRefCount;
   197     ++self->iRefCount;
   170 
   198 
   171     TRACE_EXIT_POINT;
   199     TRACE_EXIT_POINT;
   172     return self;    
   200     return self;    
   173     }
   201     }
   174     
   202 
       
   203 // ----------------------------------------------------------------------------
       
   204 // CCalenController::ReleaseCustomisations
       
   205 // Releases any plugins by deleting the customisation manager
       
   206 // should only be called on exiting by the application.
       
   207 // (other items were commented in a header).
       
   208 // ----------------------------------------------------------------------------
       
   209 //
       
   210 void CCalenController::ReleaseCustomisations()
       
   211     {
       
   212     TRACE_ENTRY_POINT;
       
   213     
       
   214     delete iCustomisationManager;
       
   215     iCustomisationManager = NULL;
       
   216     
       
   217     TRACE_EXIT_POINT;
       
   218     }
       
   219 
   175 // ----------------------------------------------------------------------------
   220 // ----------------------------------------------------------------------------
   176 // CCalenController::Release
   221 // CCalenController::Release
   177 // Decrement the reference count of this singleton.
   222 // Decrement the reference count of this singleton.
   178 // When the reference count is 0, the controller will self delete and free
   223 // When the reference count is 0, the controller will self delete and free
   179 // all resources
   224 // all resources
   202 // ----------------------------------------------------------------------------
   247 // ----------------------------------------------------------------------------
   203 //
   248 //
   204 CCalenController::~CCalenController()
   249 CCalenController::~CCalenController()
   205     {
   250     {
   206     TRACE_ENTRY_POINT;
   251     TRACE_ENTRY_POINT;
       
   252 
       
   253     if(iStateMachine) {
       
   254     	delete iStateMachine;
       
   255     	iStateMachine = NULL;
       
   256     }
       
   257 
   207     if ( iServices )
   258     if ( iServices )
   208         {
   259         {
   209         iServices->Release();
   260         iServices->Release();
   210         }
   261         }
   211     delete iNotifier;
   262     
   212     delete iActionUi;
   263     if( mContext )
   213     delete iViewManager;
   264 		{
   214     delete iCustomisationManager;
   265 		delete mContext;
       
   266 		mContext = NULL;
       
   267 		}
       
   268     // iActionUi has to be deleted before iNotifier
       
   269     // as the unregistering of the notifications has to be done
       
   270     if( iActionUi )
       
   271  	   {
       
   272  	   delete iActionUi;
       
   273  	   iActionUi = NULL;
       
   274  	   }
       
   275     
       
   276     if( iNotifier )
       
   277 		{
       
   278     	delete iNotifier;
       
   279     	iNotifier = NULL;
       
   280 		}
       
   281     
       
   282     if( iViewManager )
       
   283 		{
       
   284     	delete iViewManager;
       
   285     	iViewManager = NULL;
       
   286 		}
       
   287     
       
   288     if( iCustomisationManager )
       
   289 		{
       
   290     	delete iCustomisationManager;
       
   291     	iCustomisationManager = NULL;
       
   292 		}
       
   293     Dll::SetTls( NULL );
   215     
   294     
   216     TRACE_EXIT_POINT;
   295     TRACE_EXIT_POINT;
   217     }
   296     }
   218 
   297 
   219 
   298 
   462 //       
   541 //       
   463 void CCalenController::SetDefaultContext()
   542 void CCalenController::SetDefaultContext()
   464     {
   543     {
   465     TRACE_ENTRY_POINT;  
   544     TRACE_ENTRY_POINT;  
   466     QDateTime focusTime = mContext->defaultCalTimeForViewsL();
   545     QDateTime focusTime = mContext->defaultCalTimeForViewsL();
   467     mContext->setFocusDateAndTimeL(focusTime,KCalenDayViewUidValue );
   546     mContext->setFocusDateAndTime(focusTime);
   468     TRACE_EXIT_POINT;
   547     TRACE_EXIT_POINT;
   469     }
   548     }
   470 
   549 
   471 // ----------------------------------------------------------------------------
   550 // ----------------------------------------------------------------------------
   472 // CCalenController::OfferMenu
   551 // CCalenController::OfferMenu
   517 void CCalenController::handleServiceManagerSlot(int view, const QDateTime& dateTime)
   596 void CCalenController::handleServiceManagerSlot(int view, const QDateTime& dateTime)
   518 {
   597 {
   519 	
   598 	
   520 	if (iIsFromServiceFrmWrk) {
   599 	if (iIsFromServiceFrmWrk) {
   521 		// Set the context properly
   600 		// Set the context properly
   522 		mContext->setFocusDateAndTimeL(dateTime,KCalenMonthViewUidValue);
   601 		mContext->setFocusDateAndTime(dateTime);
   523 		// launch the appropriate view
   602 		// launch the appropriate view
   524 		iViewManager->constructAndActivateView(view);
   603 		iViewManager->constructAndActivateView(view);
   525 		
   604 		
   526 		// Construct other views
       
   527 		iViewManager->constructOtherViews();
       
   528 
       
   529 	} else { // Calendar was in backgroung but now its being brought to foreground
   605 	} else { // Calendar was in backgroung but now its being brought to foreground
   530 		// If current state is editing state or printing state
   606 		// If current state is editing state or printing state
   531 		// or deleting state or sending state, then dont do anything as
   607 		// or deleting state or sending state, then dont do anything as
   532 		// user might loose the data
   608 		// user might loose the data
   533 		CCalenStateMachine::TCalenStateIndex currentState = iStateMachine->CurrentState();
   609 		CCalenStateMachine::TCalenStateIndex currentState = iStateMachine->CurrentState();
   536 			(currentState == CCalenStateMachine::ECalenPrintingState) ||
   612 			(currentState == CCalenStateMachine::ECalenPrintingState) ||
   537 			(currentState == CCalenStateMachine::ECalenSendingState)) {
   613 			(currentState == CCalenStateMachine::ECalenSendingState)) {
   538 			// simply return - we dont have anything to do
   614 			// simply return - we dont have anything to do
   539 		} else {
   615 		} else {
   540 			// Set the context properly
   616 			// Set the context properly
   541 			mContext->setFocusDateAndTimeL(dateTime,KCalenMonthViewUidValue);
   617 			mContext->setFocusDateAndTime(dateTime);
   542 			IssueCommandL(view);
   618 			IssueCommandL(view);
   543 		}
   619 		}
   544 	}
   620 	}
   545 }
   621 }
   546 
   622 
   557 	
   633 	
   558 	return iViewManager->getFirstView();
   634 	return iViewManager->getFirstView();
   559 	
   635 	
   560 }
   636 }
   561 
   637 
       
   638 // ----------------------------------------------------------------------------
       
   639 // CCalenController::eventFilter
       
   640 // Filters and handles the changes in events
       
   641 // (other items were commented in a header).
       
   642 // ---------------------------------------------------------------------------
       
   643 //
       
   644 bool CCalenController::eventFilter(QObject *object, QEvent *event)
       
   645 {
       
   646     switch (event->type())
       
   647         {
       
   648         case QEvent::LanguageChange:
       
   649         	//TODO: Unload the translator and install the locale specific translator
       
   650         	iNotifier->BroadcastNotification( ECalenNotifySystemLanguageChanged );
       
   651             break;
       
   652         case QEvent::LocaleChange:
       
   653         	// TODO: handle the locale changes
       
   654             break;
       
   655         default:
       
   656             break;
       
   657         }
       
   658     return QObject::eventFilter(object, event);
       
   659 }
   562 // End of file
   660 // End of file