calendarui/controller/src/calencontroller.cpp
changeset 18 c198609911f9
parent 0 f979ecb2b13e
child 23 fd30d51f876b
equal deleted inserted replaced
0:f979ecb2b13e 18:c198609911f9
    14 * Description:  Calendar controller
    14 * Description:  Calendar controller
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <aknnotewrappers.h>            // CAknInformationNote
    19 #include <e32std.h>
    20 #include <aknViewAppUi.h>               // CAknViewAppUi
    20 #include <hbmainwindow.h>
    21 #include <StringLoader.h>               // Loads strings from resource
    21 #include <hbwidget.h>
    22 #include <aknappui.h>
    22 #include <hbinstance.h>
    23 #include <bautils.h>
    23 
    24 #include <data_caging_path_literals.hrh>
    24 // User includes
    25 #include <pathinfo.h>
    25 #include "calencontroller.h"            // CCalenController
    26 #include <avkon.hrh>
    26 #include "calenviewmanager.h"           // Responsible for all view activations        
    27 #include "calenviewinfo.h"              // View information
    27 #include "calenservicesimpl.h"          // MCalenServices implementation
    28 #include <Calendar.rsg>                 // Calendar resourcess
    28 #include "calenactionui.h"              // Default command handling
    29 #include <missedalarmstore.h>           // missed alarm store
    29 #include "calencustomisationmanager.h"  // Customisation Manager
    30 #include <calsession.h>
    30 #include "calennotificationhandler.h"
    31 #include <calencommandhandler.h>
    31 #include "calennotifier.h"
    32 #include <calencontext.h>
    32 #include "hb_calencommands.hrh"
    33 #include <calenconstants.h>             // KCalenLostAlarms etc
       
    34 #include <calcalendarinfo.h>
       
    35 
       
    36 #include "calendarui_debug.h"           // Debug macros
    33 #include "calendarui_debug.h"           // Debug macros
    37 #include "calencontroller.h"            // CCalenController
       
    38 #include "calenactionui.h"              // Default command handling
       
    39 #include "calennotifier.h"              // Broadcasts system events
       
    40 #include "calenviewmanager.h"           // Responsible for all view activations
       
    41 #include "calenalarmmanager.h" 			// Alarm Manager
       
    42 #include "calenservicesimpl.h"          // MCalenServices implementation
       
    43 #include "calensetting.h"
       
    44 #include "calencmdlinelauncher.h"       // Command line launcher
       
    45 #include "calencustomisationmanager.h"  // Customisation Manager
       
    46 #include "calenstatemachine.h"
    34 #include "calenstatemachine.h"
    47 #include "calenicons.h"
    35 #include "calenservicesimpl.h"          // Calendar service implementation
    48 #include "calentoolbarimpl.h"
    36 #include "CalenUid.h"
    49 #include "calenmultipledbmanager.h"
    37 #include "calencontextimpl.h"
    50 #include "calenattachmentmodel.h"
    38 
    51 
    39 // Constants
    52 const TInt KCustomCommandRangeStart     = ECalenLastCommand; 
    40 const TInt KCustomCommandRangeStart     = ECalenLastCommand; 
    53 const TInt KNumberOfCommandsPerServices = 100;
    41 const TInt KNumberOfCommandsPerServices = 100;
    54 _LIT( KResourceFile, "calencommonui.rsc" );
    42 
    55 
    43 // ----------------------------------------------------------------------------
    56 // ----------------------------------------------------------------------------
    44 // CCalenController::CCalenController
    57 // CCalenController::NewL
    45 // Constructor
    58 // First stage construction. This will leave if an instance of the controller
    46 // (other items were commented in a header).
    59 // already exists.  All access to an instance of the controller should be
    47 // ----------------------------------------------------------------------------
    60 // through the InstanceL function, except for the initial construction
    48 //
    61 // which should be handled by the appui.
    49 CCalenController::CCalenController(bool isFromServiceFrmwrk)
    62 // This is to prevent usage of this API through the services dll when Calendar
    50 {
    63 // application is not running.
    51     TRACE_ENTRY_POINT;
    64 // (other items were commented in a header).
    52     iIsFromServiceFrmWrk = isFromServiceFrmwrk;
    65 // ----------------------------------------------------------------------------
    53     iNextServicesCommandBase = KCustomCommandRangeStart;
    66 //
    54     
    67 EXPORT_C CCalenController* CCalenController::NewL( CAknViewAppUi& aAppUi )
    55     // Store the pointer in tls, also avoid multiple creations
    68     {
    56     checkMultipleCreation();
    69     TRACE_ENTRY_POINT;
    57     
    70 
    58     // Get an instance of AgendaUtil interface class
    71     CCalenController* self = NULL;
    59     // This will take care of 
    72     TAny* tlsPtr = Dll::Tls();
    60     mAgendaUtil = new AgendaUtil();
    73 
    61     
    74     // Check Thread local storage
    62     iStateMachine = CCalenStateMachine::NewL( *this );
    75     if( !tlsPtr )
    63     
    76         {
    64     // Create the notifier.
    77         // TLS is NULL, so no CCalenController has been created yet.
    65     iNotifier = new( ELeave )CalenNotifier( *iStateMachine );
    78         self = new( ELeave ) CCalenController( aAppUi );
    66     
    79         CleanupStack::PushL( self );
    67     // Construct the context
    80         // Store a self pointer in TLS
    68     mContext = new CalenContextImpl(iNotifier);
    81         User::LeaveIfError( Dll::SetTls( static_cast<TAny*>( self ) ) );
    69     
    82         // Increment ref count right away. If we don't do it here, and someone
    70     // Set the default context.Once will start use of calencmdlinelauncher,
    83         // calls Controller::InstanceL in ConstructL and then ConstructL
    71     // Then need to remove this function
    84         // leaves, we will double delete the controller.
    72     SetDefaultContext();
    85         ++self->iRefCount;
    73     
    86         self->ConstructL();
    74     RArray<TCalenNotification> notificationArray;
    87         CleanupStack::Pop( self );
    75     // Complete construction of the notifier and register the
    88         }
    76     // global data for notifications
    89     else
    77     iNotifier->ConstructL();
    90         {
    78     
    91         // An instance of the controller exists already.
    79     // Create the services
    92         // This function should only have been called once, by CCalenAppUi
    80     iServices = CalenServicesImpl::NewL();
    93         User::Leave( KErrAlreadyExists );
    81     // Create the customisation manager, and register for 
    94         }
    82     // notifications
    95 
    83     iCustomisationManager = CCalenCustomisationManager::NewL( *this,
    96     TRACE_EXIT_POINT;
    84                                                                   *iServices );
    97     return self;
    85     // Create the view manager, and register for notifications
    98     }
    86 	iViewManager = new CalenViewManager(*this, isFromServiceFrmwrk );
       
    87 	
       
    88 	hbInstance->allMainWindows().first()->show();
       
    89     
       
    90     // Create the action uis.
       
    91     iActionUi = CCalenActionUi::NewL( *this );
       
    92                                                                     
       
    93     notificationArray.Append(ECalenNotifySettingsChanged);
       
    94     notificationArray.Append(ECalenNotifyCheckPluginUnloading);
       
    95     notificationArray.Append(ECalenNotifyEComRegistryChanged);
       
    96     
       
    97     RegisterForNotificationsL( iCustomisationManager,notificationArray);
       
    98     notificationArray.Reset();
       
    99     
       
   100     notificationArray.Append(ECalenNotifyViewPopulationComplete);
       
   101     notificationArray.Append(ECalenNotifyExternalDatabaseChanged);
       
   102     notificationArray.Append(ECalenNotifyMultipleEntriesDeleted);
       
   103     notificationArray.Append(ECalenNotifyDialogClosed);
       
   104     notificationArray.Append(ECalenNotifyEntrySaved);
       
   105     notificationArray.Append(ECalenNotifyEntryDeleted);
       
   106     notificationArray.Append(ECalenNotifyInstanceDeleted);
       
   107     notificationArray.Append(ECalenNotifySystemLocaleChanged);
       
   108     notificationArray.Append(ECalenNotifySystemTimeChanged);
       
   109     notificationArray.Append(ECalenNotifyEntryClosed);
       
   110     notificationArray.Append(ECalenNotifySettingsClosed);
       
   111     		
       
   112     RegisterForNotificationsL( iViewManager, notificationArray );
       
   113     notificationArray.Reset();  
       
   114     notificationArray.Close();
       
   115     if (!isFromServiceFrmwrk) {
       
   116     	iViewManager->constructOtherViews();
       
   117     }
       
   118     TRACE_EXIT_POINT;
       
   119 }
       
   120 
       
   121 void CCalenController::checkMultipleCreation()
       
   122 {
       
   123 	TAny* tlsPtr = Dll::Tls();
       
   124 
       
   125 	// Check Thread local storage
       
   126 	if( !tlsPtr )
       
   127 		{
       
   128 		// Store a self pointer in TLS
       
   129 		User::LeaveIfError( Dll::SetTls( static_cast<TAny*>( this ) ) );
       
   130 		// Increment ref count right away. If we don't do it here, and someone
       
   131 		// calls Controller::InstanceL in ConstructL and then ConstructL
       
   132 		// leaves, we will double delete the controller.
       
   133 		++this->iRefCount;
       
   134 		}
       
   135 	else
       
   136 		{
       
   137 		// An instance of the controller exists already.
       
   138 		// This function should only have been called once, by CCalenAppUi
       
   139 		User::Leave( KErrAlreadyExists );
       
   140 		}	
       
   141 }
    99 
   142 
   100 // ----------------------------------------------------------------------------
   143 // ----------------------------------------------------------------------------
   101 // CCalenController::InstanceL
   144 // CCalenController::InstanceL
   102 // Returns a pointer to the single instance of the Calendar Controller.
   145 // Returns a pointer to the single instance of the Calendar Controller.
   103 // Leaves with KErrNotReady if the controller has not already been created
   146 // Leaves with KErrNotReady if the controller has not already been created
   104 // using NewL.  A leave here means that the Calendar application is not running
   147 // using NewL.  A leave here means that the Calendar application is not running
   105 // but someone is trying to use the services API.
   148 // but someone is trying to use the services API.
   106 // (other items were commented in a header).
   149 // (other items were commented in a header).
   107 // ----------------------------------------------------------------------------
   150 // ----------------------------------------------------------------------------
   108 //
   151 //
   109 EXPORT_C CCalenController* CCalenController::InstanceL()
   152 CCalenController* CCalenController::InstanceL()
   110     {
   153     {
   111     TRACE_ENTRY_POINT;
   154     TRACE_ENTRY_POINT;
   112 
   155 
   113     CCalenController* self = NULL;
   156     CCalenController* self = NULL;
   114     TAny* tlsPtr = Dll::Tls();
   157     TAny* tlsPtr = Dll::Tls();
   127         }
   170         }
   128 
   171 
   129     ++self->iRefCount;
   172     ++self->iRefCount;
   130 
   173 
   131     TRACE_EXIT_POINT;
   174     TRACE_EXIT_POINT;
   132     return self;
   175     return self;    
   133     }
   176     }
   134 
   177     
   135 // ----------------------------------------------------------------------------
       
   136 // CCalenController::ConstructL
       
   137 // 2nd phase of construction
       
   138 // (other items were commented in a header).
       
   139 // ----------------------------------------------------------------------------
       
   140 //
       
   141 void CCalenController::ConstructL()
       
   142     {
       
   143     TRACE_ENTRY_POINT;
       
   144     
       
   145        	TFileName fileName;
       
   146 	// Get the complate path of the DLL from where it is currently loaded
       
   147 	Dll::FileName( fileName );
       
   148 	
       
   149 	TFileName resFile;
       
   150 	
       
   151 	// Append the Drive letters ex., Z: or C:
       
   152 	resFile.Append(fileName.Mid(0,2));
       
   153 	resFile.Append(KDC_RESOURCE_FILES_DIR);
       
   154     resFile.Append(KResourceFile);
       
   155     
       
   156     BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), resFile );
       
   157     
       
   158 	iResourceFileOffset = CEikonEnv::Static()->AddResourceFileL( resFile );
       
   159 	
       
   160     
       
   161 	iStateMachine = CCalenStateMachine::NewL( *this );
       
   162     // Create the notifier.
       
   163     iNotifier = new( ELeave )CCalenNotifier( *this );
       
   164 
       
   165     // Get an instance of the global data
       
   166     iGlobalData = CCalenGlobalData::NewL( *iNotifier, iNotifier );
       
   167     iGlobalData->InitializeGlobalDataL();
       
   168     
       
   169     RArray<TCalenNotification> notificationArray;
       
   170     // Complete construction of the notifier and register the
       
   171     // global data for notifications
       
   172     iNotifier->ConstructL();
       
   173     
       
   174     notificationArray.Append(ECalenNotifyEntryInstanceViewCreated);
       
   175     notificationArray.Append(ECalenNotifyEntryInstanceViewCreationFailed);
       
   176     notificationArray.Append(ECalenNotifyDeleteInstanceView);
       
   177     notificationArray.Append(ECalenNotifyRealExit);
       
   178     notificationArray.Append(ECalenNotifyCalendarInfoCreated);
       
   179     notificationArray.Append(ECalenNotifyCalendarInfoUpdated);
       
   180     
       
   181 
       
   182     RegisterForNotificationsL( iGlobalData,notificationArray);
       
   183     notificationArray.Reset();
       
   184     
       
   185     // Create the cmd line handler
       
   186     iCmdLineLauncher = CCalenCmdLineLauncher::NewL( *this, iAppUi );
       
   187     
       
   188     // Create the services
       
   189     iServices = CCalenServicesImpl::NewL();
       
   190     
       
   191     // Create the action uis.
       
   192     iActionUi = CCalenActionUi::NewL( *this );
       
   193     
       
   194     // Create the settings
       
   195     iSetting = CCalenSetting::InstanceL();
       
   196     
       
   197     // Create the view manager, and register for notifications
       
   198     iViewManager = CCalenViewManager::NewL( iAppUi, *this );
       
   199     
       
   200     notificationArray.Append(ECalenNotifySettingsChanged);
       
   201     notificationArray.Append(ECalenNotifySettingsClosed);
       
   202     notificationArray.Append(ECalenNotifySystemLocaleChanged);
       
   203     notificationArray.Append(ECalenNotifyPluginEnabledDisabled);
       
   204     notificationArray.Append(ECalenNotifyEntrySaved);
       
   205     notificationArray.Append(ECalenNotifyEntryDeleted);
       
   206     notificationArray.Append(ECalenNotifyInstanceDeleted);
       
   207     notificationArray.Append(ECalenNotifyMultipleEntriesDeleted);
       
   208     notificationArray.Append(ECalenNotifyExternalDatabaseChanged);
       
   209     notificationArray.Append(ECalenNotifyDeleteFailed);
       
   210     notificationArray.Append(ECalenNotifyEntryClosed);
       
   211 	notificationArray.Append(ECalenNotifyCancelDelete);
       
   212     notificationArray.Append(ECalenNotifySystemTimeChanged);
       
   213     notificationArray.Append(ECalenNotifyAppForegrounded);
       
   214     notificationArray.Append(ECalenNotifyDayViewClosed);
       
   215     notificationArray.Append(ECalenNotifyAppBackgrounded);
       
   216     notificationArray.Append(ECalenNotifyViewPopulationComplete);
       
   217     notificationArray.Append(ECalenNotifyCalendarFieldChanged);
       
   218     notificationArray.Append(ECalenNotifyCancelStatusUpdation);
       
   219     notificationArray.Append(ECalenNotifyMarkedEntryCompleted);
       
   220     notificationArray.Append(ECalenNotifyAttachmentAdded);
       
   221     notificationArray.Append(ECalenNotifyAttachmentViewerClosed);
       
   222     notificationArray.Append(ECalenNotifyAttachmentRemoved);
       
   223     notificationArray.Append(ECalenNotifyCalendarInfoCreated);
       
   224     notificationArray.Append(ECalenNotifyCalendarInfoUpdated);
       
   225     notificationArray.Append(ECalenNotifyCalendarFileDeleted);
       
   226     
       
   227     RegisterForNotificationsL( iViewManager, notificationArray );
       
   228     notificationArray.Reset();
       
   229                                                          
       
   230     // Create the customisation manager, and register for 
       
   231     // notifications
       
   232     iCustomisationManager = CCalenCustomisationManager::NewL( *this,
       
   233                                                               iSetting->PluginAvailability(),
       
   234                                                               *iServices,
       
   235                                                               iViewManager->ViewInfoArray() );
       
   236                                                                     
       
   237     notificationArray.Append(ECalenNotifySettingsChanged);
       
   238     notificationArray.Append(ECalenNotifyCheckPluginUnloading);
       
   239     notificationArray.Append(ECalenNotifyEComRegistryChanged);
       
   240     
       
   241     RegisterForNotificationsL( iCustomisationManager,notificationArray);
       
   242     notificationArray.Reset();
       
   243     
       
   244     // Some plugins may have been added or removed - update the settings.
       
   245     iSetting->UpdatePluginListL( *iCustomisationManager );
       
   246     
       
   247     // View manager constructs the custom views using the
       
   248     // customisation manager
       
   249     iViewManager->ConstructCustomViewsL( *iCustomisationManager );
       
   250     
       
   251     // for handling missed alarms/msk improvements for alarm
       
   252     iAlarmManager = CCalenAlarmManager::NewL(*this); 
       
   253     
       
   254     notificationArray.Append(ECalenNotifyLostAlarms);
       
   255     notificationArray.Append(ECalenNotifyMissedAlarmViewClosed);
       
   256     notificationArray.Append(ECalenNotifyMissedEventViewClosed);
       
   257     notificationArray.Append(ECalenNotifyEntryDeleted);
       
   258     notificationArray.Append(ECalenNotifyInstanceDeleted);
       
   259     notificationArray.Append(ECalenNotifyEntrySaved);
       
   260     notificationArray.Append(ECalenNotifyMultipleEntriesDeleted);
       
   261     notificationArray.Append(ECalenNotifySystemTimeChanged);
       
   262     notificationArray.Append(ECalenNotifyAlarmStopped);
       
   263     notificationArray.Append(ECalenNotifyAlarmSnoozed);
       
   264     notificationArray.Append(ECalenNotifyEntryClosed);
       
   265     notificationArray.Append(ECalenNotifyAppForegrounded);
       
   266     
       
   267     RegisterForNotificationsL( iAlarmManager, notificationArray );
       
   268     notificationArray.Reset();
       
   269 
       
   270     //iMultipleDbmanager = CCalenMultipleDbManager::NewL();
       
   271     
       
   272     iAttachmentData = CCalenAttachmentModel::NewL();
       
   273     
       
   274     notificationArray.Close();
       
   275     
       
   276     TRACE_EXIT_POINT;
       
   277     }
       
   278 
       
   279 // ----------------------------------------------------------------------------
       
   280 // CCalenController::CCalenController
       
   281 // C++ default constructor.
       
   282 // (other items were commented in a header).
       
   283 // ----------------------------------------------------------------------------
       
   284 //
       
   285 CCalenController::CCalenController( CAknViewAppUi& aAppUi )
       
   286     : iAppUi( aAppUi ),
       
   287       iNextServicesCommandBase( KCustomCommandRangeStart ),
       
   288       iFasterApp( EFalse )
       
   289     {
       
   290     TRACE_ENTRY_POINT;
       
   291     TRACE_EXIT_POINT;
       
   292     }
       
   293 
       
   294 // ----------------------------------------------------------------------------
       
   295 // CCalenController::~CCalenController
       
   296 // Private destructor, called from Release() when reference count is 0.
       
   297 // Frees all resources.
       
   298 // (other items were commented in a header).
       
   299 // ----------------------------------------------------------------------------
       
   300 //
       
   301 CCalenController::~CCalenController()
       
   302     {
       
   303     TRACE_ENTRY_POINT;
       
   304     
       
   305     if ( iServices )
       
   306         {
       
   307         iServices->Release();
       
   308         }
       
   309         
       
   310     delete iActionUi;
       
   311     delete iNotifier;
       
   312 
       
   313     delete iViewManager;
       
   314     delete iStateMachine;
       
   315     
       
   316     if ( iSetting )
       
   317         {
       
   318         iSetting->Release();
       
   319         }
       
   320 
       
   321     if( iGlobalData )
       
   322         {
       
   323         iGlobalData->Release();
       
   324         }
       
   325 
       
   326     Dll::SetTls( NULL );
       
   327 
       
   328     delete iCmdLineLauncher;
       
   329     delete iCustomisationManager;
       
   330 
       
   331     if( iResourceFileOffset )
       
   332         {
       
   333         CCoeEnv::Static()->DeleteResourceFile( iResourceFileOffset );
       
   334         }
       
   335     //delete iMultipleDbmanager;
       
   336     
       
   337     if(iSystemTimeChangedMsgDelayer)
       
   338         {
       
   339         iSystemTimeChangedMsgDelayer->Cancel();
       
   340         delete iSystemTimeChangedMsgDelayer;
       
   341         iSystemTimeChangedMsgDelayer = NULL;
       
   342         }
       
   343     
       
   344     delete iAlarmManager;
       
   345     
       
   346     if(iAttachmentData)
       
   347         {
       
   348         delete iAttachmentData;
       
   349         iAttachmentData = NULL;
       
   350         }
       
   351     TRACE_EXIT_POINT;
       
   352     }
       
   353 
       
   354 // ----------------------------------------------------------------------------
   178 // ----------------------------------------------------------------------------
   355 // CCalenController::Release
   179 // CCalenController::Release
   356 // Decrement the reference count of this singleton.
   180 // Decrement the reference count of this singleton.
   357 // When the reference count is 0, the controller will self delete and free
   181 // When the reference count is 0, the controller will self delete and free
   358 // all resources
   182 // all resources
   359 // (other items were commented in a header).
   183 // (other items were commented in a header).
   360 // ----------------------------------------------------------------------------
   184 // ----------------------------------------------------------------------------
   361 //
   185 //
   362 EXPORT_C void CCalenController::Release()
   186 void CCalenController::Release()
   363     {
   187     {
   364     TRACE_ENTRY_POINT;
   188     TRACE_ENTRY_POINT;
   365 
       
   366     --iRefCount;
   189     --iRefCount;
   367     
   190     
   368     // The controller owns its own instance of the services, therefore the
   191     // The controller owns its own instance of the services, therefore the
   369     // reference count will be one, immediatley before deletion.
   192     // reference count will be one, immediatley before deletion.
   370     if (iRefCount == 1)
   193     if (iRefCount == 1)
   371         {
   194         {
   372         delete this;
   195         delete this;
   373         }
   196         }
   374 
   197     TRACE_EXIT_POINT;
   375     TRACE_EXIT_POINT;
   198     }
   376     }
   199 
   377     
   200 // ----------------------------------------------------------------------------
   378 // ----------------------------------------------------------------------------
   201 // CCalenController::~CCalenController
   379 // CCalenController::ReleaseCustomisations
   202 // Private destructor, called from Release() when reference count is 0.
   380 // Releases any plugins by deleting the customisation manager
   203 // Frees all resources.
   381 // should only be called on exiting by the document.
   204 // (other items were commented in a header).
   382 // (other items were commented in a header).
   205 // ----------------------------------------------------------------------------
   383 // ----------------------------------------------------------------------------
   206 //
   384 //
   207 CCalenController::~CCalenController()
   385 EXPORT_C void CCalenController::ReleaseCustomisations()
   208     {
   386     {
   209     TRACE_ENTRY_POINT;
   387     TRACE_ENTRY_POINT;
   210     if ( iServices )
   388     
   211         {
       
   212         iServices->Release();
       
   213         }
       
   214     delete iNotifier;
       
   215     delete iActionUi;
       
   216     delete iViewManager;
   389     delete iCustomisationManager;
   217     delete iCustomisationManager;
   390     iCustomisationManager = NULL;
   218     
   391     
   219     TRACE_EXIT_POINT;
   392     TRACE_EXIT_POINT;
   220     }
   393     }
   221 
   394 
   222 
   395 // ----------------------------------------------------------------------------
   223 // ----------------------------------------------------------------------------
   396 // CCalenController::IssueCommmandL
   224 // CCalenController::IssueCommmandL
   397 // Adds the passed command to the comand queue. Commands are handled
   225 // Adds the passed command to the comand queue. Commands are handled
   398 // asynchronously in HandleCommandL
   226 // asynchronously in HandleCommandL
   399 // Returns EFalse if the passed command is not in the issuers command range
   227 // Returns EFalse if the passed command is not in the issuers command range
   400 // (other items were commented in a header).
   228 // (other items were commented in a header).
   401 // ----------------------------------------------------------------------------
   229 // ----------------------------------------------------------------------------
   402 //
   230 //
   403 EXPORT_C TBool CCalenController::IssueCommandL( TInt aCommand )
   231 TBool CCalenController::IssueCommandL( TInt aCommand )
   404     {
   232     {
   405     TRACE_ENTRY_POINT;
   233     TRACE_ENTRY_POINT;
   406     TCalenCommand cmd;
   234     TCalenCommand cmd;
   407     
   235     cmd.SetCommandAndContextL( aCommand ,context());
   408     if( aCommand == EAknCmdHideInBackground ||
       
   409 	  ( aCommand == EAknSoftkeyExit && iAppUi.ExitHidesInBackground() ) )
       
   410 	    {
       
   411 	    SetFasterAppFlag( ETrue );
       
   412 	    aCommand = ECalenFasterAppExit;
       
   413 	    }
       
   414     else if( aCommand == EAknCmdExit || aCommand == EEikCmdExit
       
   415              || aCommand == EAknSoftkeyExit )
       
   416         {
       
   417         if( iViewManager->CalenToolbar() )
       
   418             {
       
   419             iViewManager->CalenToolbar()->ResetCalendarToolbar();
       
   420             }
       
   421         }
       
   422     else
       
   423         {
       
   424         if((aCommand < ECalenViewCommandBase ) || (aCommand > iNextServicesCommandBase))
       
   425             {
       
   426             return EFalse;
       
   427             }
       
   428         }
       
   429     
       
   430     cmd.SetCommandAndContextL( aCommand, iGlobalData->Context() );
       
   431 
   236 
   432     TBool ret = iStateMachine->HandleCommandL( cmd );
   237     TBool ret = iStateMachine->HandleCommandL( cmd );
   433 
       
   434     TRACE_EXIT_POINT;
   238     TRACE_EXIT_POINT;
   435     return ret;
   239     return ret;
   436     }
   240     }
   437 
   241 
   438 
   242 // ----------------------------------------------------------------------------
   439 // ----------------------------------------------------------------------------
   243 // CCalenController::Services
   440 // CCalenController::RequestActivationL
   244 // Returns the services
   441 // Request activation of a specific view
   245 // (other items were commented in a header).
   442 // (other items were commented in a header).
   246 // ----------------------------------------------------------------------------
   443 // ----------------------------------------------------------------------------
   247 //
   444 //
   248 MCalenServices& CCalenController::Services()
   445 void CCalenController::RequestActivationL( const TVwsViewId& aViewId )
   249     {
   446     {
   250     TRACE_ENTRY_POINT;
   447     TRACE_ENTRY_POINT;
   251     TRACE_EXIT_POINT;
   448 
   252     return *iServices;
   449     iViewManager->RequestActivationL( aViewId );
   253     }
   450 
   254 
   451     TRACE_EXIT_POINT;
   255 // ----------------------------------------------------------------------------
   452     }
   256 // CCalenController::ViewManager
   453 
   257 // Returns a reference to the view manager
   454 // ----------------------------------------------------------------------------
   258 // (other items were commented in a header).
   455 // CCalenController::BroadcastNotification
   259 // ----------------------------------------------------------------------------
       
   260 CalenViewManager& CCalenController::ViewManager()
       
   261     {
       
   262     TRACE_ENTRY_POINT;
       
   263     TRACE_EXIT_POINT;
       
   264 	return *iViewManager;
       
   265     }
       
   266     
       
   267 // ----------------------------------------------------------------------------
       
   268 // CCalenController::MainWindow
       
   269 // Returns a reference to the MainWindow
       
   270 // (other items were commented in a header).
       
   271 // ----------------------------------------------------------------------------
       
   272 HbMainWindow& CCalenController::MainWindow()
       
   273     {
       
   274     TRACE_ENTRY_POINT;
       
   275     
       
   276     return *(hbInstance->allMainWindows().first());
       
   277 	
       
   278 	TRACE_EXIT_POINT;
       
   279     }    
       
   280 
       
   281 // ----------------------------------------------------------------------------
       
   282 // CCCalenController::BroadcastNotification
   456 // Passes the notification to the Calendar Notifier.  The notification will
   283 // Passes the notification to the Calendar Notifier.  The notification will
   457 // then be broadcast to all observers
   284 // then be broadcast to all observers
   458 // (other items were commented in a header).
   285 // (other items were commented in a header).
   459 // ----------------------------------------------------------------------------
   286 // ----------------------------------------------------------------------------
   460 //
   287 //
   461 EXPORT_C void CCalenController::BroadcastNotification( TCalenNotification aNotification )
   288 void CCalenController::BroadcastNotification( TCalenNotification aNotification )
   462     {
   289     {
   463     TRACE_ENTRY_POINT;
   290     TRACE_ENTRY_POINT;
   464     
   291 
   465     iNotifier->BroadcastNotification( aNotification );
   292     iNotifier->BroadcastNotification( aNotification );
   466         
   293 
   467     TRACE_EXIT_POINT;
   294     TRACE_EXIT_POINT;
   468     }
   295     }
   469 
   296 
   470 // ----------------------------------------------------------------------------
   297 // ----------------------------------------------------------------------------
   471 // CCalenController::RegisterForNotificationsL
   298 // CCCalenController::RegisterForNotificationsL
   472 // Registers the passed notification handler with the Calendar Notifier
   299 // Registers the passed notification handler with the Calendar Notifier
   473 // (other items were commented in a header).
   300 // (other items were commented in a header).
   474 // ----------------------------------------------------------------------------
   301 // ----------------------------------------------------------------------------
   475 //
   302 //
   476 EXPORT_C void CCalenController::RegisterForNotificationsL( MCalenNotificationHandler* aHandler,
   303 void CCalenController::RegisterForNotificationsL( MCalenNotificationHandler* aHandler,
   477                                                             TCalenNotification aNotification )
   304                                                             TCalenNotification aNotification )
   478     {
   305     {
   479     TRACE_ENTRY_POINT;
   306     TRACE_ENTRY_POINT;
   480 
   307 
   481     iNotifier->RegisterForNotificationsL( aHandler, aNotification );
   308     iNotifier->RegisterForNotificationsL( aHandler, aNotification );
   482 
   309 
   483     TRACE_EXIT_POINT;
   310     TRACE_EXIT_POINT;
   484     }
   311     }
   485 
   312 
   486 // ----------------------------------------------------------------------------
   313 // ----------------------------------------------------------------------------
   487 // CCalenController::RegisterForNotificationsL
   314 // CCCalenController::RegisterForNotificationsL
   488 // Registers the passed notification handler with the Calendar Notifier
   315 // Registers the passed notification handler with the Calendar Notifier
   489 // (other items were commented in a header).
   316 // (other items were commented in a header).
   490 // ----------------------------------------------------------------------------
   317 // ----------------------------------------------------------------------------
   491 //
   318 //
   492 EXPORT_C void CCalenController::RegisterForNotificationsL( MCalenNotificationHandler* aHandler,
   319 void CCalenController::RegisterForNotificationsL( MCalenNotificationHandler* aHandler,
   493                                                             RArray<TCalenNotification>& aNotifications )
   320                                                             RArray<TCalenNotification>& aNotifications )
   494     {
   321     {
   495     TRACE_ENTRY_POINT;
   322     TRACE_ENTRY_POINT;
   496 
   323 
   497     iNotifier->RegisterForNotificationsL( aHandler, aNotifications );
   324     iNotifier->RegisterForNotificationsL( aHandler, aNotifications );
   498 
   325 
   499     TRACE_EXIT_POINT;
   326     TRACE_EXIT_POINT;
   500     }
   327     }
   501 
   328 
   502 // ----------------------------------------------------------------------------
   329 // ----------------------------------------------------------------------------
   503 // CCalenController::CancelNotifications
   330 // CCCalenController::CancelNotifications
   504 // Removes the passed handler from the notifier.
   331 // Removes the passed handler from the notifier.
   505 // (other items were commented in a header).
   332 // (other items were commented in a header).
   506 // ----------------------------------------------------------------------------
   333 // ----------------------------------------------------------------------------
   507 //
   334 //
   508 EXPORT_C void CCalenController::CancelNotifications( MCalenNotificationHandler* aHandler )
   335 void CCalenController::CancelNotifications( MCalenNotificationHandler* aHandler )
   509     {
   336     {
   510     TRACE_ENTRY_POINT;
   337     TRACE_ENTRY_POINT;
   511 
   338 
   512     iNotifier->CancelNotifications( aHandler );
   339     iNotifier->CancelNotifications( aHandler );
   513 
   340 
   514     TRACE_EXIT_POINT;
   341     TRACE_EXIT_POINT;
   515     }
   342     }
   516 
   343 
   517 // ----------------------------------------------------------------------------
   344 // ----------------------------------------------------------------------------
   518 // CCalenController::GetCommandHandlerL
   345 // CCCalenController::GetCommandHandlerL
   519 // Searches for a command handler for a particular command.  Customisations
   346 // Searches for a command handler for a particular command.  Customisations
   520 // are searched first.  If no customisation wants to handle the command it is
   347 // are searched first.  If no customisation wants to handle the command it is
   521 // handled by the view manager or the action uis
   348 // handled by the view manager or the action uis
   522 // ----------------------------------------------------------------------------
   349 // ----------------------------------------------------------------------------
   523 MCalenCommandHandler* CCalenController::GetCommandHandlerL( TInt aCommand )
   350 MCalenCommandHandler* CCalenController::GetCommandHandlerL( TInt aCommand )
   533         // See if a plugin wants the command
   360         // See if a plugin wants the command
   534         handler = iCustomisationManager->GetCommandHandlerL( aCommand );
   361         handler = iCustomisationManager->GetCommandHandlerL( aCommand );
   535         }
   362         }
   536 
   363 
   537     // See if the view manager wants the command
   364     // See if the view manager wants the command
   538     if(!handler)
   365     if ( !handler )
   539         {
   366         {
   540         if( aCommand >= ECalenViewCommandBase
   367         if (   aCommand >= ECalenViewCommandBase
   541             && aCommand < ECalenEditCommandBase )
   368             && aCommand < ECalenEditCommandBase )
   542             {
   369             {
   543             handler = iViewManager;
   370             handler = iViewManager;
   544             }
   371             }
   545      	else if(aCommand >= ECalenMissedAlarmCommandBase
   372      	else if( aCommand >= ECalenMissedAlarmCommandBase
   546       		&& aCommand < ECalenAttachmentCommandBase )
   373       		&& aCommand < ECalenLastCommand )
   547 	    	{
   374 	    	{
   548 	    	handler = iAlarmManager;
   375 	    	//handler = iAlarmManager;
   549 	    	} 
   376 	    	} 
   550         else 
   377         else 
   551             {
   378             {
   552             handler = iActionUi->GetCommandHandlerL(aCommand);
   379             handler = iActionUi->GetCommandHandlerL( aCommand );
   553             }
   380             }
   554         }
   381         }
   555 
   382 
   556     // No command handler is an error  
   383     // No command handler is an error  
   557     
   384     
   558     // return the handler
   385     // return the handler
   559     TRACE_EXIT_POINT;
   386     TRACE_EXIT_POINT;
   560     return handler;
   387     return handler;
   561     }
   388     }
   562 
   389 
   563 // ----------------------------------------------------
   390 // ----------------------------------------------------------------------------
   564 //  CCalenController::CheckSystemTimeAtStartUpL
   391 // CCCalenController::NewServicesL
   565 //  Check the system time change at the startup
       
   566 // ----------------------------------------------------
       
   567 //
       
   568 void CCalenController::CheckSystemTimeAtStartUpL()
       
   569     {
       
   570     TRACE_ENTRY_POINT;
       
   571 
       
   572     if(iSystemTimeChangedMsgDelayer)
       
   573         {
       
   574         iSystemTimeChangedMsgDelayer->Cancel();
       
   575         delete iSystemTimeChangedMsgDelayer;
       
   576         iSystemTimeChangedMsgDelayer = NULL;
       
   577         }
       
   578     
       
   579     // Introduce delay (CPeriodic) before showing the note 
       
   580     // to allow time for the active view to display before
       
   581     // note.
       
   582     
       
   583     TCallBack callback;
       
   584     callback = TCallBack( SystemTimeChangeCallback, this );
       
   585                                      
       
   586     iSystemTimeChangedMsgDelayer = new (ELeave) CAsyncCallBack(
       
   587                             callback, CActive::EPriorityStandard);
       
   588     iSystemTimeChangedMsgDelayer->CallBack();
       
   589 
       
   590     TRACE_EXIT_POINT;
       
   591     }
       
   592 
       
   593 // ----------------------------------------------------
       
   594 //  CCalenController::SystemTimeChangeCallback
       
   595 //  This function is called when the System time is changed.
       
   596 // ----------------------------------------------------
       
   597 //
       
   598 TInt CCalenController::SystemTimeChangeCallback(TAny* aThisPtr)
       
   599     {
       
   600     TRACE_ENTRY_POINT;
       
   601 
       
   602     PIM_TRAPD_HANDLE(
       
   603         static_cast<CCalenController*>(aThisPtr)->HandleSystemTimeChangeL());
       
   604 
       
   605     TRACE_EXIT_POINT;
       
   606     return 0;
       
   607     }
       
   608 
       
   609 // ----------------------------------------------------------------------------
       
   610 // CCalenController::HandleSystemTimeChangeL
       
   611 // Checks to see if the system time was changed while Calendar was
       
   612 // not running or in the background, potentially causing alarms to be missed
       
   613 // (other items were commented in a header).
       
   614 // ----------------------------------------------------------------------------
       
   615 //
       
   616 void CCalenController::HandleSystemTimeChangeL()
       
   617     {
       
   618     TRACE_ENTRY_POINT;
       
   619     
       
   620     // get the system time change info
       
   621     TInt timeChanged = iNotifier->SystemTimeChangedL();
       
   622 
       
   623     switch( timeChanged )
       
   624         {
       
   625         case KCalenTimeZoneChanged:
       
   626             {
       
   627             ShowSystemChangeInfoNoteL( R_QTN_CALE_NOTE_SYSTEM_TIME_CHANGED );
       
   628             }
       
   629             break;
       
   630         case KCalenLostAlarms:
       
   631             {
       
   632             // Not displayed since missed alarms are handled in missed alarms view.
       
   633             // No need to show the info note the user.
       
   634             // Part of alarm improvement REQ for calendar.
       
   635             //ShowSystemChangeInfoNoteL( R_QTN_CALE_NOTE_MISSED_ALARMS );
       
   636             }
       
   637             break;
       
   638         case KNoUserInfoNoteDisplay:
       
   639         default:
       
   640             break;
       
   641         }
       
   642     
       
   643     // update system time change info to the cenrep
       
   644     iNotifier->UpdateSytemTimeChangeInfoL();
       
   645  
       
   646     TRACE_EXIT_POINT;
       
   647     }
       
   648 
       
   649 // ----------------------------------------------------------------------------
       
   650 // CCalenController::ShowSystemChangeInfoNoteL
       
   651 // Displays an information note if the system time changed while Calendar
       
   652 // was inactive
       
   653 // (other items were commented in a header).
       
   654 // ----------------------------------------------------------------------------
       
   655 //
       
   656 void CCalenController::ShowSystemChangeInfoNoteL( TInt aResourceId )
       
   657     {
       
   658     TRACE_ENTRY_POINT;
       
   659 
       
   660     HBufC* buf = StringLoader::LoadLC( aResourceId, CEikonEnv::Static() );
       
   661     CAknInformationNote* dialog = new( ELeave ) CAknInformationNote();
       
   662 
       
   663     dialog->ExecuteLD( *buf );
       
   664 
       
   665     CleanupStack::PopAndDestroy( buf );
       
   666 
       
   667     TRACE_EXIT_POINT;
       
   668     }
       
   669 
       
   670 // ----------------------------------------------------------------------------
       
   671 // CCalenController::NewServicesL
       
   672 // Factory function for creating new MCalenServices objects
   392 // Factory function for creating new MCalenServices objects
   673 // (other items were commented in a header).
   393 // (other items were commented in a header).
   674 // ----------------------------------------------------------------------------
   394 // ----------------------------------------------------------------------------
   675 //
   395 //
   676 EXPORT_C MCalenServices* CCalenController::NewServicesL()
   396 MCalenServices* CCalenController::NewServicesL()
   677     {
   397     {
   678     TRACE_ENTRY_POINT;
   398     TRACE_ENTRY_POINT;
   679 
   399     
   680     TInt commandRangeStart = iNextServicesCommandBase;
   400     TInt commandRangeStart = iNextServicesCommandBase;
   681     TInt commandRangeEnd = commandRangeStart + KNumberOfCommandsPerServices;
   401     TInt commandRangeEnd = commandRangeStart + KNumberOfCommandsPerServices;
   682     iNextServicesCommandBase = commandRangeEnd + 1;
   402     iNextServicesCommandBase = commandRangeEnd + 1;
   683 
   403 
   684     CCalenServicesImpl* svc = CCalenServicesImpl::NewL( commandRangeStart,
   404     CalenServicesImpl* svc = CalenServicesImpl::NewL( commandRangeStart,commandRangeEnd );
   685                                                                               commandRangeEnd );
       
   686     TRACE_EXIT_POINT;
   405     TRACE_EXIT_POINT;
   687     return svc;
   406     return svc;
   688     }
       
   689 
       
   690 // ----------------------------------------------------------------------------
       
   691 // CCalenController::ProcessCommandParametersL
       
   692 // Takes care of commandline parameters.
       
   693 // (other items were commented in a header).
       
   694 // ----------------------------------------------------------------------------
       
   695 //
       
   696 EXPORT_C void CCalenController::ProcessCommandParametersL( TApaCommand aCommand,
       
   697                                                        TFileName& aDocumentName,
       
   698                                                        const TDesC8& aTail )
       
   699     {
       
   700     TRACE_ENTRY_POINT;
       
   701 
       
   702     iCmdLineLauncher->ProcessCommandParametersL( aCommand, aDocumentName, aTail );
       
   703 
       
   704     TRACE_EXIT_POINT;
       
   705     }
   407     }
   706 
   408 
   707 // ----------------------------------------------------------------------------
   409 // ----------------------------------------------------------------------------
   708 // CCalenController::Notifier
   410 // CCalenController::Notifier
   709 // Returns the notifier.
   411 // Returns the notifier.
   710 // (other items were commented in a header).
   412 // (other items were commented in a header).
   711 // ----------------------------------------------------------------------------
   413 // ----------------------------------------------------------------------------
   712 //
   414 //
   713 CCalenNotifier& CCalenController::Notifier()
   415 CalenNotifier& CCalenController::Notifier()
   714     {
   416     {
   715     TRACE_ENTRY_POINT;
   417     TRACE_ENTRY_POINT;
   716     TRACE_EXIT_POINT;
   418     TRACE_EXIT_POINT;
   717     return *iNotifier;
   419     return *iNotifier;
   718     }
   420     }
   719 
   421     
   720 // ----------------------------------------------------------------------------
       
   721 // CCalenController::SetExitOnDialogFlag
       
   722 // (other items were commented in a header).
       
   723 // ----------------------------------------------------------------------------
       
   724 //
       
   725 void CCalenController::SetExitOnDialogFlag( TBool aFlag )
       
   726     {
       
   727     TRACE_ENTRY_POINT;
       
   728     
       
   729     iCmdLineLauncher->SetExitOnDialogclose( aFlag );
       
   730     
       
   731     TRACE_EXIT_POINT;
       
   732     }
       
   733 
       
   734 // ----------------------------------------------------------------------------
       
   735 // CCalenController::GetExitOnDialogFlag
       
   736 // (other items were commented in a header).
       
   737 // ----------------------------------------------------------------------------
       
   738 //
       
   739 TBool CCalenController::GetExitOnDialogFlag()
       
   740     {
       
   741     TRACE_ENTRY_POINT;
       
   742 
       
   743     TBool tempVal;
       
   744     tempVal = iCmdLineLauncher->GetExitOnDialogStatus();
       
   745     return tempVal;
       
   746 
       
   747     TRACE_EXIT_POINT;
       
   748     }
       
   749     
       
   750 // ----------------------------------------------------------------------------
       
   751 // CCalenController::Services
       
   752 // Returns the services
       
   753 // (other items were commented in a header).
       
   754 // ----------------------------------------------------------------------------
       
   755 //
       
   756 MCalenServices& CCalenController::Services()
       
   757     {
       
   758     TRACE_ENTRY_POINT;
       
   759     TRACE_EXIT_POINT;
       
   760     return *iServices;
       
   761     }
       
   762 
       
   763 // ----------------------------------------------------------------------------
       
   764 // CCalenController::OfferMenuPaneL
       
   765 // Offers the menu pane to plugins for customisation.
       
   766 // Acts as a conduit between the services and the customisation manager.
       
   767 // (other items were commented in a header).
       
   768 // ----------------------------------------------------------------------------
       
   769 //
       
   770 EXPORT_C void CCalenController::OfferMenuPaneL( TInt aResourceId,
       
   771                                                                      CEikMenuPane* aMenuPane )
       
   772     {
       
   773     TRACE_ENTRY_POINT;
       
   774 
       
   775     iCustomisationManager->OfferMenuPaneL( aResourceId, aMenuPane );
       
   776 
       
   777     if( aResourceId == R_CALENDAR_CHANGE_VIEW_MENUPANE )
       
   778         {
       
   779         // The cascading view switch menu is being displayed
       
   780         // therefore the view manager needs to be asked to remove
       
   781         // the current view
       
   782         iViewManager->RemoveCurrentViewFromMenu( aMenuPane );
       
   783         }
       
   784     
       
   785     TUint32 missedAlarmsCount(0);
       
   786     // get the count from missed alarm store
       
   787     iAlarmManager->MissedAlarmStore()->CountL(missedAlarmsCount);
       
   788     
       
   789     //For adding "Missed Alarms" menu item for native views menu pane
       
   790     if(!missedAlarmsCount)
       
   791         {
       
   792         if( aResourceId == R_CALENDAR_MONTH_MENUPANE
       
   793             || aResourceId == R_CALENDAR_DAY_MENUPANE
       
   794             || aResourceId == R_CALENDAR_WEEK_MENUPANE
       
   795             || aResourceId == R_TODO_LIST_MENUPANE )
       
   796                 {
       
   797                 aMenuPane->DeleteMenuItem(ECalenMissedAlarmsView);
       
   798                 }
       
   799         }
       
   800 
       
   801     TRACE_EXIT_POINT;
       
   802     }
       
   803 
       
   804 // ----------------------------------------------------------------------------
   422 // ----------------------------------------------------------------------------
   805 // CCalenController::Infobar
   423 // CCalenController::Infobar
   806 // Descriptor passed to plugins to get customised info bar text.
   424 // Descriptor passed to plugins to get customised info bar text.
   807 // Acts as a conduit between the services and the customisation manager.
   425 // Acts as a conduit between the services and the customisation manager.
   808 // (other items were commented in a header).
   426 // (other items were commented in a header).
   809 // ----------------------------------------------------------------------------
   427 // ----------------------------------------------------------------------------
   810 //
   428 //
   811 EXPORT_C CCoeControl* CCalenController::Infobar( const TRect& aRect )
   429 HbWidget* CCalenController::Infobar()
   812     {
       
   813     TRACE_ENTRY_POINT;
       
   814     TRACE_EXIT_POINT;
       
   815     return iCustomisationManager->Infobar( aRect );
       
   816     }
       
   817 
       
   818 // ----------------------------------------------------------------------------
       
   819 // CCalenController::Infobar
       
   820 // Descriptor passed to plugins to get customised info bar text.
       
   821 // Acts as a conduit between the services and the customisation manager.
       
   822 // (other items were commented in a header).
       
   823 // ----------------------------------------------------------------------------
       
   824 //
       
   825 EXPORT_C const TDesC& CCalenController::Infobar()
       
   826     {
   430     {
   827     TRACE_ENTRY_POINT;
   431     TRACE_ENTRY_POINT;
   828     TRACE_EXIT_POINT;
   432     TRACE_EXIT_POINT;
   829     return iCustomisationManager->Infobar();
   433     return iCustomisationManager->Infobar();
   830     }
   434     }
   831 
   435 // ----------------------------------------------------------------------------
   832 // ----------------------------------------------------------------------------
   436 // CCalenController::InfobarTextL
   833 // CCalenController::PreviewPane
   437 // @returns info bar text
   834 // Descriptor passed to plugins to get customised preview pane text.
   438 // (other items were commented in a header).
   835 // Acts as a conduit between the services and the customisation manager.
   439 // ----------------------------------------------------------------------------
   836 // (other items were commented in a header).
   440 //
   837 // ----------------------------------------------------------------------------
   441 QString* CCalenController::InfobarTextL()
   838 //
   442     {
   839 EXPORT_C CCoeControl* CCalenController::PreviewPane( TRect& aRect )
   443     TRACE_ENTRY_POINT;
   840     {
   444     TRACE_EXIT_POINT;
   841     TRACE_ENTRY_POINT;
   445     return iCustomisationManager->InfobarTextL();
   842     TRACE_EXIT_POINT;
   446     }
   843     return iCustomisationManager->PreviewPane( aRect );
       
   844     }
       
   845 
       
   846 // ----------------------------------------------------------------------------
       
   847 // CCalenController::CustomPreviewPaneL
       
   848 // Return custom preview pane
       
   849 // (other items were commented in a header).
       
   850 // ----------------------------------------------------------------------------
       
   851 //
       
   852 EXPORT_C MCalenPreview* CCalenController::CustomPreviewPaneL( TRect& aRect )
       
   853     {
       
   854     TRACE_ENTRY_POINT;
       
   855     TRACE_EXIT_POINT;
       
   856     return iCustomisationManager->CustomPreviewPaneL(aRect);
       
   857     }
       
   858 
       
   859 // ----------------------------------------------------------------------------
   447 // ----------------------------------------------------------------------------
   860 // CCalenController::CustomisationManager
   448 // CCalenController::CustomisationManager
   861 // Returns a reference to the customisation manager
   449 // Returns a reference to the customisation manager
   862 // (other items were commented in a header).
   450 // (other items were commented in a header).
   863 // ----------------------------------------------------------------------------
   451 // ----------------------------------------------------------------------------
   868     TRACE_EXIT_POINT;
   456     TRACE_EXIT_POINT;
   869     return *iCustomisationManager;
   457     return *iCustomisationManager;
   870     }
   458     }
   871 
   459 
   872 // ----------------------------------------------------------------------------
   460 // ----------------------------------------------------------------------------
   873 // CCalenController::ViewManager
   461 // CCalenController::SetDefaultContext
   874 // Returns a reference to the view manager
   462 // Sets the default context for today
   875 // (other items were commented in a header).
   463 // (other items were commented in a header).
   876 // ----------------------------------------------------------------------------
   464 // ----------------------------------------------------------------------------
   877 CCalenViewManager& CCalenController::ViewManager()
   465 //       
   878     {
   466 void CCalenController::SetDefaultContext()
   879     TRACE_ENTRY_POINT;
   467     {
   880     TRACE_EXIT_POINT;
   468     TRACE_ENTRY_POINT;  
   881     return *iViewManager;
   469     QDateTime focusTime = mContext->defaultCalTimeForViewsL();
   882     }
   470     mContext->setFocusDateAndTimeL(focusTime,KCalenDayViewUidValue );
   883 
   471     TRACE_EXIT_POINT;
   884 // ----------------------------------------------------------------------------
   472     }
   885 // CCalenController::MissedAlarmStore
   473 
   886 // Returns a reference to the Missed Alarm Store
   474 // ----------------------------------------------------------------------------
   887 // ----------------------------------------------------------------------------
   475 // CCalenController::OfferMenu
   888 CMissedAlarmStore* CCalenController::MissedAlarmStore()
   476 // Offers the menu to plugins for customisation.
   889     {
   477 // Acts as a conduit between the services and the customisation manager.
   890     TRACE_ENTRY_POINT;
   478 // (other items were commented in a header).
   891     TRACE_EXIT_POINT;
   479 // ----------------------------------------------------------------------------
   892 
   480 
   893     return iAlarmManager->MissedAlarmStore();
   481 void CCalenController::OfferMenu(HbMenu* aHbMenu)
   894     }
   482     {
   895 
   483     TRACE_ENTRY_POINT;
   896 // ----------------------------------------------------------------------------
   484     iCustomisationManager->OfferMenu(aHbMenu);
   897 // CCalenController::IsFasterAppFlagEnabled
   485     TRACE_EXIT_POINT;
   898 // Returns ETrue if the application is fake exited
   486     }
   899 // else return EFalse.
   487 
   900 // (other items were commented in a header).
   488 // ----------------------------------------------------------------------------
   901 // ----------------------------------------------------------------------------
   489 // CCalenController::agendaInterface
   902 TBool CCalenController::IsFasterAppFlagEnabled()
   490 // returns the interface to the agenda database
   903     {
   491 // (other items were commented in a header).
   904     TRACE_ENTRY_POINT;
   492 // ---------------------------------------------------------------------------
   905     TRACE_EXIT_POINT;
   493 //
   906 	return iFasterApp;
   494 AgendaUtil* CCalenController::agendaInterface()
   907     }
   495     {
   908 
   496     TRACE_ENTRY_POINT;
   909 // ----------------------------------------------------------------------------
   497     TRACE_EXIT_POINT;
   910 // CCalenController::SetFasterAppFlag
   498     return mAgendaUtil;
   911 // Set the flag 'iFasterApp' to ETrue if application is fake exited
   499     }
   912 // and to EFalse once the application comes to foreground.
   500 
   913 // (other items were commented in a header).
   501 // ----------------------------------------------------------------------------
   914 // ----------------------------------------------------------------------------
   502 // CCalenController::context
   915 void CCalenController::SetFasterAppFlag( TBool aFlag )
   503 // returns the calendar context
   916 	{
   504 // (other items were commented in a header).
   917     TRACE_ENTRY_POINT;
   505 // ---------------------------------------------------------------------------
   918     TRACE_EXIT_POINT;
   506 //
   919 	iFasterApp = aFlag;
   507 MCalenContext& CCalenController::context()
       
   508     {
       
   509 	TRACE_ENTRY_POINT;
       
   510 	TRACE_EXIT_POINT;
       
   511     return *mContext;
       
   512     }
       
   513 
       
   514 // ----------------------------------------------------------------------------
       
   515 // CCalenController::handleServiceManagerSlot
       
   516 // Launches the requested view 
       
   517 // (other items were commented in a header).
       
   518 // ---------------------------------------------------------------------------
       
   519 //
       
   520 void CCalenController::handleServiceManagerSlot(int view, const QDateTime& dateTime)
       
   521 {
       
   522 	
       
   523 	if (iIsFromServiceFrmWrk) {
       
   524 		// Set the context properly
       
   525 		mContext->setFocusDateAndTimeL(dateTime,KCalenMonthViewUidValue);
       
   526 		// launch the appropriate view
       
   527 		iViewManager->constructAndActivateView(view);
       
   528 		
       
   529 		// Construct other views
       
   530 		iViewManager->constructOtherViews();
       
   531 
       
   532 	} else { // Calendar was in backgroung but now its being brought to foreground
       
   533 		// If current state is editing state or printing state
       
   534 		// or deleting state or sending state, then dont do anything as
       
   535 		// user might loose the data
       
   536 		CCalenStateMachine::TCalenStateIndex currentState = iStateMachine->CurrentState();
       
   537 		if ((currentState == CCalenStateMachine::ECalenEditingState) ||
       
   538 			(currentState == CCalenStateMachine::ECalenDeletingState) ||
       
   539 			(currentState == CCalenStateMachine::ECalenPrintingState) ||
       
   540 			(currentState == CCalenStateMachine::ECalenSendingState)) {
       
   541 			// simply return - we dont have anything to do
       
   542 		} else {
       
   543 			// Set the context properly
       
   544 			mContext->setFocusDateAndTimeL(dateTime,KCalenMonthViewUidValue);
       
   545 			IssueCommandL(view);
       
   546 		}
   920 	}
   547 	}
   921 
   548 }
   922 // ----------------------------------------------------------------------------
   549 
   923 // CCalenController::AppUi
   550 // ----------------------------------------------------------------------------
   924 // Returns a reference to the appui
   551 // CCalenController::getFirstView
   925 // (other items were commented in a header).
   552 // returns the first view with which calendar has been launched
   926 // ----------------------------------------------------------------------------
   553 // (other items were commented in a header).
   927 //
   554 // ---------------------------------------------------------------------------
   928 CAknViewAppUi& CCalenController::AppUi()
   555 //
   929     {
   556 int CCalenController::getFirstView()
   930     TRACE_ENTRY_POINT;
   557 {
   931     TRACE_EXIT_POINT;
   558 	TRACE_ENTRY_POINT;
   932     return iAppUi;
   559 	TRACE_EXIT_POINT;
   933     }
       
   934 
       
   935 // ----------------------------------------------------------------------------
       
   936 // CCalenController::GetMissedAlarmsList
       
   937 // Returns the missed alarms list
       
   938 // ----------------------------------------------------------------------------
       
   939 void CCalenController::GetMissedAlarmsList(RArray<TCalenInstanceId>& aMissedAlarmsList)
       
   940     {
       
   941     TRACE_ENTRY_POINT;
       
   942     iAlarmManager->GetMissedAlarmsList(aMissedAlarmsList);
       
   943     TRACE_EXIT_POINT;
       
   944     }
       
   945 
       
   946 // ----------------------------------------------------------------------------
       
   947 // CCalenController::Settings
       
   948 // Returns a reference to the calendar settings
       
   949 // ----------------------------------------------------------------------------
       
   950 CCalenSetting& CCalenController::Settings()
       
   951     {
       
   952     TRACE_ENTRY_POINT;
       
   953     TRACE_EXIT_POINT;
       
   954     return *iSetting;
       
   955     }
       
   956 
       
   957 // ----------------------------------------------------------------------------
       
   958 // CCalenController::GetIconL
       
   959 // Get icon of specific type
       
   960 // ----------------------------------------------------------------------------
       
   961 //
       
   962 CGulIcon* CCalenController::GetIconL( MCalenServices::TCalenIcons aIndex )
       
   963     {
       
   964     TRACE_ENTRY_POINT;
       
   965     
       
   966     // if view requests next view icon
       
   967     if(aIndex == MCalenServices::ECalenNextViewIcon)
       
   968         {
       
   969         return (iViewManager->GetNextViewIconL());
       
   970         }
       
   971     
       
   972     TRACE_EXIT_POINT;
       
   973     return iViewManager->IconsL().GetIconL(aIndex);
       
   974     }
       
   975 
       
   976 // ----------------------------------------------------------------------------
       
   977 // CCalenController::MultipleDbManager
       
   978 // Returns a reference to the CCalenMultipleDbManager
       
   979 // (other items were commented in a header).
       
   980 // ----------------------------------------------------------------------------
       
   981 //
       
   982 CCalenMultipleDbManager& CCalenController::MultipleDbManager()
       
   983     {
       
   984     TRACE_ENTRY_POINT
       
   985     CCalenMultipleDbManager* tmp = NULL;
       
   986     TRACE_EXIT_POINT
       
   987     return *tmp;
       
   988     }
       
   989 
       
   990 // ----------------------------------------------------------------------------
       
   991 // CCalenController::StateMachine
       
   992 // Returns a reference to the CCalenStateMachine
       
   993 // (other items were commented in a header).
       
   994 // ----------------------------------------------------------------------------
       
   995 //
       
   996 CCalenStateMachine& CCalenController::StateMachine()
       
   997     {
       
   998     TRACE_ENTRY_POINT
       
   999     TRACE_EXIT_POINT
       
  1000     return *iStateMachine;
       
  1001     }
       
  1002 
       
  1003 
       
  1004 // -----------------------------------------------------------------------------
       
  1005 // CCalenController::GetActiveCollectionidsL
       
  1006 // -----------------------------------------------------------------------------
       
  1007 //
       
  1008 void CCalenController::GetActiveCollectionidsL(
       
  1009                                            RArray<TInt>& aCollectionIds)
       
  1010     {
       
  1011     TRACE_ENTRY_POINT
       
  1012     RPointerArray<CCalCalendarInfo> calendarInfoList;
       
  1013     CleanupClosePushL(calendarInfoList);
       
  1014     iGlobalData->GetAllCalendarInfoL(calendarInfoList);
       
  1015     
       
  1016     for(TInt index=0;index<calendarInfoList.Count();index++)
       
  1017         {
       
  1018         if(calendarInfoList[index]->Enabled())
       
  1019             {
       
  1020             HBufC* calendarFileName = 
       
  1021                 calendarInfoList[index]->FileNameL().AllocLC();
       
  1022             aCollectionIds.Append(
       
  1023                  iGlobalData->CalSessionL(*calendarFileName).CollectionIdL());
       
  1024             CleanupStack::PopAndDestroy(calendarFileName);
       
  1025             }
       
  1026         }
       
  1027     
       
  1028     CleanupStack::PopAndDestroy(&calendarInfoList);
       
  1029     TRACE_EXIT_POINT
       
  1030     }
       
  1031 
       
  1032 // -----------------------------------------------------------------------------
       
  1033 // CCalenController::AttachmentData
       
  1034 // Returns a reference to the CCalenAttachmentModel
       
  1035 // ----------------------------------------------------------------------------
       
  1036 //
       
  1037 CCalenAttachmentModel& CCalenController::AttachmentData()
       
  1038     {
       
  1039     TRACE_ENTRY_POINT;
       
  1040     TRACE_EXIT_POINT;
       
  1041     return *iAttachmentData;
       
  1042     }
       
  1043 	
   560 	
  1044 // -----------------------------------------------------------------------------
   561 	return iViewManager->getFirstView();
  1045 // CCalenController::IsEditorActive
   562 	
  1046 // Tells framework whether editor is active or not
   563 }
  1047 // -----------------------------------------------------------------------------
   564 
  1048 //
       
  1049 TBool CCalenController::IsEditorActive()
       
  1050     {
       
  1051     return (iActionUi->IsEditorActive());
       
  1052     }
       
  1053 
       
  1054 // -----------------------------------------------------------------------------
       
  1055 // CCalenController::AddCalendarL
       
  1056 // Adds a new calendar file with metadata set
       
  1057 // -----------------------------------------------------------------------------
       
  1058 //
       
  1059 void CCalenController::AddCalendarL(CCalCalendarInfo* aCalendarInfo)
       
  1060     {
       
  1061     TRACE_ENTRY_POINT;
       
  1062     iGlobalData->AddCalendarL(aCalendarInfo);
       
  1063     TRACE_EXIT_POINT;
       
  1064     }
       
  1065 
       
  1066 // -----------------------------------------------------------------------------
       
  1067 // CCalenController::UpdateCalendarL
       
  1068 // Updates calendar file with new calendar info
       
  1069 // -----------------------------------------------------------------------------
       
  1070 //
       
  1071 void CCalenController::UpdateCalendarL(CCalCalendarInfo* aCalendarInfo)
       
  1072     {
       
  1073     TRACE_ENTRY_POINT;
       
  1074     iGlobalData->UpdateCalendarL(aCalendarInfo);
       
  1075     TRACE_EXIT_POINT;
       
  1076     }
       
  1077 
       
  1078 // -----------------------------------------------------------------------------
       
  1079 // CCalenController::RemoveCalendarL
       
  1080 // Removes calendar file based on calendar file name
       
  1081 // -----------------------------------------------------------------------------
       
  1082 //
       
  1083 void CCalenController::RemoveCalendarL(const TDesC& aCalendarFileName)
       
  1084     {
       
  1085     TRACE_ENTRY_POINT;
       
  1086     iGlobalData->RemoveCalendarL(aCalendarFileName);
       
  1087     TRACE_EXIT_POINT;
       
  1088     }
       
  1089 
       
  1090 // -----------------------------------------------------------------------------
       
  1091 // CCalenController::RemoveCalendarL
       
  1092 // Removes all dead calendar files from the file system
       
  1093 // -----------------------------------------------------------------------------
       
  1094 //
       
  1095 void CCalenController::RemoveDeadCalendarsL()
       
  1096     {
       
  1097     TRACE_ENTRY_POINT;
       
  1098     iGlobalData->RemoveDeadCalendarsL();
       
  1099     TRACE_EXIT_POINT;
       
  1100     }
       
  1101 // -----------------------------------------------------------------------------
       
  1102 // CCalenController::GetAllCalendarInfoL
       
  1103 // Get all available calendar info
       
  1104 // -----------------------------------------------------------------------------
       
  1105 //
       
  1106 void CCalenController::GetAllCalendarInfoL(
       
  1107                 RPointerArray<CCalCalendarInfo>& aCalendarInfoList)
       
  1108     {
       
  1109     TRACE_ENTRY_POINT;
       
  1110     iGlobalData->GetAllCalendarInfoL(aCalendarInfoList);
       
  1111     TRACE_EXIT_POINT;
       
  1112     }
       
  1113 // End of file
   565 // End of file
  1114