calendarui/controller/src/calencontroller.cpp
changeset 45 b6db4fd4947b
parent 23 fd30d51f876b
child 46 ecd7b9840282
--- a/calendarui/controller/src/calencontroller.cpp	Mon May 03 12:30:32 2010 +0300
+++ b/calendarui/controller/src/calencontroller.cpp	Mon Jun 28 15:22:02 2010 +0530
@@ -20,6 +20,8 @@
 #include <hbmainwindow.h>
 #include <hbwidget.h>
 #include <hbinstance.h>
+#include <hbapplication.h> //Activity Manager
+#include <xqserviceutil.h> // service utils
 
 // User includes
 #include "calencontroller.h"            // CCalenController
@@ -46,73 +48,99 @@
 // (other items were commented in a header).
 // ----------------------------------------------------------------------------
 //
-CCalenController::CCalenController(bool isFromServiceFrmwrk)
+CCalenController::CCalenController()
 {
     TRACE_ENTRY_POINT;
-    iIsFromServiceFrmWrk = isFromServiceFrmwrk;
-    iNextServicesCommandBase = KCustomCommandRangeStart;
-    
-    // Store the pointer in tls, also avoid multiple creations
-    checkMultipleCreation();
-    
-    // Get an instance of AgendaUtil interface class
-    // This will take care of 
-    mAgendaUtil = new AgendaUtil();
-    
-    iStateMachine = CCalenStateMachine::NewL( *this );
+	// Check the Application Startup reason, set iIsFromServiceFrmWrk if application
+	// is started by service framework, false otherwise
+    /*Hb::ActivationReasonService == qobject_cast<HbApplication*>(qApp)->activateReason() ? 
+        iIsFromServiceFrmWrk = true:
+        iIsFromServiceFrmWrk = false; */
     
-    // Create the notifier.
-    iNotifier = new( ELeave )CalenNotifier( *iStateMachine );
-    
-    // Construct the context
-    mContext = new CalenContextImpl(iNotifier);
+    // Check if calendar is launched thru XQService framework
+    iIsFromServiceFrmWrk = XQServiceUtil::isService(); // Since activateReason 
+    //of hbapplication is not returning right value if the activity is started 
+    //as services so using the above line temporarily untill a fix is available in 
+    // hbappliacation. Need to remove this line after the fix is available for hbapplcation
     
-    // Set the default context.Once will start use of calencmdlinelauncher,
-    // Then need to remove this function
-    SetDefaultContext();
-    
-    RArray<TCalenNotification> notificationArray;
-    // Complete construction of the notifier and register the
-    // global data for notifications
-    iNotifier->ConstructL();
+    iNextServicesCommandBase = KCustomCommandRangeStart;
+    iRefCount = 0;
     
-    // Create the services
-    iServices = CalenServicesImpl::NewL();
-    // Create the customisation manager, and register for 
-    // notifications
-    iCustomisationManager = CCalenCustomisationManager::NewL( *this,
-                                                                  *iServices );
-    // Create the view manager, and register for notifications
-	iViewManager = new CalenViewManager(*this, isFromServiceFrmwrk );
-	
+    TRACE_EXIT_POINT;
+}
+
+// ----------------------------------------------------------------------------
+// CCalenController::constuctController
+// Construct the controller completely
+// (other items were commented in a header).
+// ----------------------------------------------------------------------------
+//
+void CCalenController::constructController()
+{
+	// Store the pointer in tls, also avoid multiple creations
+	checkMultipleCreation();
+
+	// Get an instance of AgendaUtil interface class
+	// This will take care of 
+	mAgendaUtil = new AgendaUtil();
+
+	iStateMachine = CCalenStateMachine::NewL( *this );
+
+	// Create the notifier.
+	iNotifier = new( ELeave )CalenNotifier( *iStateMachine );
+
+	// Construct the context
+	mContext = new CalenContextImpl(iNotifier);
+
+	// Set the default context.Once will start use of calencmdlinelauncher,
+	// Then need to remove this function
+	SetDefaultContext();
+
+	RArray<TCalenNotification> notificationArray;
+	// Complete construction of the notifier and register the
+	// global data for notifications
+	iNotifier->ConstructL();
+
+	// Create the services
+	iServices = CalenServicesImpl::NewL();
+	// Create the customisation manager, and register for 
+	// notifications
+	iCustomisationManager = CCalenCustomisationManager::NewL( *this,
+	                                                          *iServices );
+	// Create the view manager, and register for notifications
+	iViewManager = new CalenViewManager(*this);
+
+	iViewManager->SecondPhaseConstruction();
+
 	hbInstance->allMainWindows().first()->show();
-    
-    // Create the action uis.
-    iActionUi = CCalenActionUi::NewL( *this );
-                                                                    
-    notificationArray.Append(ECalenNotifySettingsChanged);
-    notificationArray.Append(ECalenNotifyCheckPluginUnloading);
-    notificationArray.Append(ECalenNotifyEComRegistryChanged);
-    
-    RegisterForNotificationsL( iCustomisationManager,notificationArray);
-    notificationArray.Reset();
-    
-    notificationArray.Append(ECalenNotifyViewPopulationComplete);
-    notificationArray.Append(ECalenNotifyExternalDatabaseChanged);
-    notificationArray.Append(ECalenNotifyMultipleEntriesDeleted);
-    notificationArray.Append(ECalenNotifyDialogClosed);
-    notificationArray.Append(ECalenNotifyEntrySaved);
-    notificationArray.Append(ECalenNotifyEntryDeleted);
-    notificationArray.Append(ECalenNotifyInstanceDeleted);
-    notificationArray.Append(ECalenNotifySystemLocaleChanged);
-    notificationArray.Append(ECalenNotifySystemTimeChanged);
-    notificationArray.Append(ECalenNotifyEntryClosed);
-    notificationArray.Append(ECalenNotifySettingsClosed);
-    		
-    RegisterForNotificationsL( iViewManager, notificationArray );
-    notificationArray.Reset();  
-    notificationArray.Close();
-    TRACE_EXIT_POINT;
+
+	// Create the action uis.
+	iActionUi = CCalenActionUi::NewL( *this );
+
+	notificationArray.Append(ECalenNotifySettingsChanged);
+	notificationArray.Append(ECalenNotifyCheckPluginUnloading);
+	notificationArray.Append(ECalenNotifyEComRegistryChanged);
+	notificationArray.Append(ECalenNotifySystemLanguageChanged);
+
+	RegisterForNotificationsL( iCustomisationManager,notificationArray);
+	notificationArray.Reset();
+
+	notificationArray.Append(ECalenNotifyViewPopulationComplete);
+	notificationArray.Append(ECalenNotifyExternalDatabaseChanged);
+	notificationArray.Append(ECalenNotifyMultipleEntriesDeleted);
+	notificationArray.Append(ECalenNotifyDialogClosed);
+	notificationArray.Append(ECalenNotifyEntrySaved);
+	notificationArray.Append(ECalenNotifyEntryDeleted);
+	notificationArray.Append(ECalenNotifyInstanceDeleted);
+	notificationArray.Append(ECalenNotifySystemLocaleChanged);
+	notificationArray.Append(ECalenNotifySystemLanguageChanged);
+	notificationArray.Append(ECalenNotifySystemTimeChanged);
+	notificationArray.Append(ECalenNotifyEntryClosed);
+	notificationArray.Append(ECalenNotifySettingsClosed);
+
+	RegisterForNotificationsL( iViewManager, notificationArray );
+	notificationArray.Reset();  
+	notificationArray.Close();
 }
 
 void CCalenController::checkMultipleCreation()
@@ -171,7 +199,24 @@
     TRACE_EXIT_POINT;
     return self;    
     }
+
+// ----------------------------------------------------------------------------
+// CCalenController::ReleaseCustomisations
+// Releases any plugins by deleting the customisation manager
+// should only be called on exiting by the application.
+// (other items were commented in a header).
+// ----------------------------------------------------------------------------
+//
+void CCalenController::ReleaseCustomisations()
+    {
+    TRACE_ENTRY_POINT;
     
+    delete iCustomisationManager;
+    iCustomisationManager = NULL;
+    
+    TRACE_EXIT_POINT;
+    }
+
 // ----------------------------------------------------------------------------
 // CCalenController::Release
 // Decrement the reference count of this singleton.
@@ -204,14 +249,48 @@
 CCalenController::~CCalenController()
     {
     TRACE_ENTRY_POINT;
+
+    if(iStateMachine) {
+    	delete iStateMachine;
+    	iStateMachine = NULL;
+    }
+
     if ( iServices )
         {
         iServices->Release();
         }
-    delete iNotifier;
-    delete iActionUi;
-    delete iViewManager;
-    delete iCustomisationManager;
+    
+    if( mContext )
+		{
+		delete mContext;
+		mContext = NULL;
+		}
+    // iActionUi has to be deleted before iNotifier
+    // as the unregistering of the notifications has to be done
+    if( iActionUi )
+ 	   {
+ 	   delete iActionUi;
+ 	   iActionUi = NULL;
+ 	   }
+    
+    if( iNotifier )
+		{
+    	delete iNotifier;
+    	iNotifier = NULL;
+		}
+    
+    if( iViewManager )
+		{
+    	delete iViewManager;
+    	iViewManager = NULL;
+		}
+    
+    if( iCustomisationManager )
+		{
+    	delete iCustomisationManager;
+    	iCustomisationManager = NULL;
+		}
+    Dll::SetTls( NULL );
     
     TRACE_EXIT_POINT;
     }
@@ -464,7 +543,7 @@
     {
     TRACE_ENTRY_POINT;  
     QDateTime focusTime = mContext->defaultCalTimeForViewsL();
-    mContext->setFocusDateAndTimeL(focusTime,KCalenDayViewUidValue );
+    mContext->setFocusDateAndTime(focusTime);
     TRACE_EXIT_POINT;
     }
 
@@ -519,13 +598,10 @@
 	
 	if (iIsFromServiceFrmWrk) {
 		// Set the context properly
-		mContext->setFocusDateAndTimeL(dateTime,KCalenMonthViewUidValue);
+		mContext->setFocusDateAndTime(dateTime);
 		// launch the appropriate view
 		iViewManager->constructAndActivateView(view);
 		
-		// Construct other views
-		iViewManager->constructOtherViews();
-
 	} else { // Calendar was in backgroung but now its being brought to foreground
 		// If current state is editing state or printing state
 		// or deleting state or sending state, then dont do anything as
@@ -538,7 +614,7 @@
 			// simply return - we dont have anything to do
 		} else {
 			// Set the context properly
-			mContext->setFocusDateAndTimeL(dateTime,KCalenMonthViewUidValue);
+			mContext->setFocusDateAndTime(dateTime);
 			IssueCommandL(view);
 		}
 	}
@@ -559,4 +635,26 @@
 	
 }
 
+// ----------------------------------------------------------------------------
+// CCalenController::eventFilter
+// Filters and handles the changes in events
+// (other items were commented in a header).
+// ---------------------------------------------------------------------------
+//
+bool CCalenController::eventFilter(QObject *object, QEvent *event)
+{
+    switch (event->type())
+        {
+        case QEvent::LanguageChange:
+        	//TODO: Unload the translator and install the locale specific translator
+        	iNotifier->BroadcastNotification( ECalenNotifySystemLanguageChanged );
+            break;
+        case QEvent::LocaleChange:
+        	// TODO: handle the locale changes
+            break;
+        default:
+            break;
+        }
+    return QObject::eventFilter(object, event);
+}
 // End of file