calendarui/controller/src/calencontroller.cpp
changeset 0 f979ecb2b13e
child 10 38571fd2a704
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Calendar controller
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aknnotewrappers.h>            // CAknInformationNote
       
    20 #include <aknViewAppUi.h>               // CAknViewAppUi
       
    21 #include <StringLoader.h>               // Loads strings from resource
       
    22 #include <aknappui.h>
       
    23 #include <bautils.h>
       
    24 #include <data_caging_path_literals.hrh>
       
    25 #include <pathinfo.h>
       
    26 #include <avkon.hrh>
       
    27 #include "calenviewinfo.h"              // View information
       
    28 #include <Calendar.rsg>                 // Calendar resourcess
       
    29 #include <missedalarmstore.h>           // missed alarm store
       
    30 #include <calsession.h>
       
    31 #include <calencommandhandler.h>
       
    32 #include <calencontext.h>
       
    33 #include <calenconstants.h>             // KCalenLostAlarms etc
       
    34 #include <calcalendarinfo.h>
       
    35 
       
    36 #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"
       
    47 #include "calenicons.h"
       
    48 #include "calentoolbarimpl.h"
       
    49 #include "calenmultipledbmanager.h"
       
    50 #include "calenattachmentmodel.h"
       
    51 
       
    52 const TInt KCustomCommandRangeStart     = ECalenLastCommand; 
       
    53 const TInt KNumberOfCommandsPerServices = 100;
       
    54 _LIT( KResourceFile, "calencommonui.rsc" );
       
    55 
       
    56 // ----------------------------------------------------------------------------
       
    57 // CCalenController::NewL
       
    58 // First stage construction. This will leave if an instance of the controller
       
    59 // already exists.  All access to an instance of the controller should be
       
    60 // through the InstanceL function, except for the initial construction
       
    61 // which should be handled by the appui.
       
    62 // This is to prevent usage of this API through the services dll when Calendar
       
    63 // application is not running.
       
    64 // (other items were commented in a header).
       
    65 // ----------------------------------------------------------------------------
       
    66 //
       
    67 EXPORT_C CCalenController* CCalenController::NewL( CAknViewAppUi& aAppUi )
       
    68     {
       
    69     TRACE_ENTRY_POINT;
       
    70 
       
    71     CCalenController* self = NULL;
       
    72     TAny* tlsPtr = Dll::Tls();
       
    73 
       
    74     // Check Thread local storage
       
    75     if( !tlsPtr )
       
    76         {
       
    77         // TLS is NULL, so no CCalenController has been created yet.
       
    78         self = new( ELeave ) CCalenController( aAppUi );
       
    79         CleanupStack::PushL( self );
       
    80         // Store a self pointer in TLS
       
    81         User::LeaveIfError( Dll::SetTls( static_cast<TAny*>( self ) ) );
       
    82         // Increment ref count right away. If we don't do it here, and someone
       
    83         // calls Controller::InstanceL in ConstructL and then ConstructL
       
    84         // leaves, we will double delete the controller.
       
    85         ++self->iRefCount;
       
    86         self->ConstructL();
       
    87         CleanupStack::Pop( self );
       
    88         }
       
    89     else
       
    90         {
       
    91         // An instance of the controller exists already.
       
    92         // This function should only have been called once, by CCalenAppUi
       
    93         User::Leave( KErrAlreadyExists );
       
    94         }
       
    95 
       
    96     TRACE_EXIT_POINT;
       
    97     return self;
       
    98     }
       
    99 
       
   100 // ----------------------------------------------------------------------------
       
   101 // CCalenController::InstanceL
       
   102 // Returns a pointer to the single instance of the Calendar Controller.
       
   103 // 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
       
   105 // but someone is trying to use the services API.
       
   106 // (other items were commented in a header).
       
   107 // ----------------------------------------------------------------------------
       
   108 //
       
   109 EXPORT_C CCalenController* CCalenController::InstanceL()
       
   110     {
       
   111     TRACE_ENTRY_POINT;
       
   112 
       
   113     CCalenController* self = NULL;
       
   114     TAny* tlsPtr = Dll::Tls();
       
   115 
       
   116     // Check Thread local storage
       
   117     if( !tlsPtr )
       
   118         {
       
   119         // The Controller has not yet been constructed.  Someone is probably
       
   120         // trying to use the Services API outside of a customisation
       
   121         // plugin.  We don't allow that.
       
   122         User::Leave( KErrNotReady );
       
   123         }
       
   124     else
       
   125         {
       
   126         self = static_cast<CCalenController*>( tlsPtr );
       
   127         }
       
   128 
       
   129     ++self->iRefCount;
       
   130 
       
   131     TRACE_EXIT_POINT;
       
   132     return self;
       
   133     }
       
   134 
       
   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 // ----------------------------------------------------------------------------
       
   355 // CCalenController::Release
       
   356 // Decrement the reference count of this singleton.
       
   357 // When the reference count is 0, the controller will self delete and free
       
   358 // all resources
       
   359 // (other items were commented in a header).
       
   360 // ----------------------------------------------------------------------------
       
   361 //
       
   362 EXPORT_C void CCalenController::Release()
       
   363     {
       
   364     TRACE_ENTRY_POINT;
       
   365 
       
   366     --iRefCount;
       
   367     
       
   368     // The controller owns its own instance of the services, therefore the
       
   369     // reference count will be one, immediatley before deletion.
       
   370     if (iRefCount == 1)
       
   371         {
       
   372         delete this;
       
   373         }
       
   374 
       
   375     TRACE_EXIT_POINT;
       
   376     }
       
   377     
       
   378 // ----------------------------------------------------------------------------
       
   379 // CCalenController::ReleaseCustomisations
       
   380 // Releases any plugins by deleting the customisation manager
       
   381 // should only be called on exiting by the document.
       
   382 // (other items were commented in a header).
       
   383 // ----------------------------------------------------------------------------
       
   384 //
       
   385 EXPORT_C void CCalenController::ReleaseCustomisations()
       
   386     {
       
   387     TRACE_ENTRY_POINT;
       
   388     
       
   389     delete iCustomisationManager;
       
   390     iCustomisationManager = NULL;
       
   391     
       
   392     TRACE_EXIT_POINT;
       
   393     }
       
   394 
       
   395 // ----------------------------------------------------------------------------
       
   396 // CCalenController::IssueCommmandL
       
   397 // Adds the passed command to the comand queue. Commands are handled
       
   398 // asynchronously in HandleCommandL
       
   399 // Returns EFalse if the passed command is not in the issuers command range
       
   400 // (other items were commented in a header).
       
   401 // ----------------------------------------------------------------------------
       
   402 //
       
   403 EXPORT_C TBool CCalenController::IssueCommandL( TInt aCommand )
       
   404     {
       
   405     TRACE_ENTRY_POINT;
       
   406     TCalenCommand cmd;
       
   407     
       
   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 
       
   432     TBool ret = iStateMachine->HandleCommandL( cmd );
       
   433 
       
   434     TRACE_EXIT_POINT;
       
   435     return ret;
       
   436     }
       
   437 
       
   438 
       
   439 // ----------------------------------------------------------------------------
       
   440 // CCalenController::RequestActivationL
       
   441 // Request activation of a specific view
       
   442 // (other items were commented in a header).
       
   443 // ----------------------------------------------------------------------------
       
   444 //
       
   445 void CCalenController::RequestActivationL( const TVwsViewId& aViewId )
       
   446     {
       
   447     TRACE_ENTRY_POINT;
       
   448 
       
   449     iViewManager->RequestActivationL( aViewId );
       
   450 
       
   451     TRACE_EXIT_POINT;
       
   452     }
       
   453 
       
   454 // ----------------------------------------------------------------------------
       
   455 // CCalenController::BroadcastNotification
       
   456 // Passes the notification to the Calendar Notifier.  The notification will
       
   457 // then be broadcast to all observers
       
   458 // (other items were commented in a header).
       
   459 // ----------------------------------------------------------------------------
       
   460 //
       
   461 EXPORT_C void CCalenController::BroadcastNotification( TCalenNotification aNotification )
       
   462     {
       
   463     TRACE_ENTRY_POINT;
       
   464     
       
   465     iNotifier->BroadcastNotification( aNotification );
       
   466         
       
   467     TRACE_EXIT_POINT;
       
   468     }
       
   469 
       
   470 // ----------------------------------------------------------------------------
       
   471 // CCalenController::RegisterForNotificationsL
       
   472 // Registers the passed notification handler with the Calendar Notifier
       
   473 // (other items were commented in a header).
       
   474 // ----------------------------------------------------------------------------
       
   475 //
       
   476 EXPORT_C void CCalenController::RegisterForNotificationsL( MCalenNotificationHandler* aHandler,
       
   477                                                             TCalenNotification aNotification )
       
   478     {
       
   479     TRACE_ENTRY_POINT;
       
   480 
       
   481     iNotifier->RegisterForNotificationsL( aHandler, aNotification );
       
   482 
       
   483     TRACE_EXIT_POINT;
       
   484     }
       
   485 
       
   486 // ----------------------------------------------------------------------------
       
   487 // CCalenController::RegisterForNotificationsL
       
   488 // Registers the passed notification handler with the Calendar Notifier
       
   489 // (other items were commented in a header).
       
   490 // ----------------------------------------------------------------------------
       
   491 //
       
   492 EXPORT_C void CCalenController::RegisterForNotificationsL( MCalenNotificationHandler* aHandler,
       
   493                                                             RArray<TCalenNotification>& aNotifications )
       
   494     {
       
   495     TRACE_ENTRY_POINT;
       
   496 
       
   497     iNotifier->RegisterForNotificationsL( aHandler, aNotifications );
       
   498 
       
   499     TRACE_EXIT_POINT;
       
   500     }
       
   501 
       
   502 // ----------------------------------------------------------------------------
       
   503 // CCalenController::CancelNotifications
       
   504 // Removes the passed handler from the notifier.
       
   505 // (other items were commented in a header).
       
   506 // ----------------------------------------------------------------------------
       
   507 //
       
   508 EXPORT_C void CCalenController::CancelNotifications( MCalenNotificationHandler* aHandler )
       
   509     {
       
   510     TRACE_ENTRY_POINT;
       
   511 
       
   512     iNotifier->CancelNotifications( aHandler );
       
   513 
       
   514     TRACE_EXIT_POINT;
       
   515     }
       
   516 
       
   517 // ----------------------------------------------------------------------------
       
   518 // CCalenController::GetCommandHandlerL
       
   519 // Searches for a command handler for a particular command.  Customisations
       
   520 // are searched first.  If no customisation wants to handle the command it is
       
   521 // handled by the view manager or the action uis
       
   522 // ----------------------------------------------------------------------------
       
   523 MCalenCommandHandler* CCalenController::GetCommandHandlerL( TInt aCommand )
       
   524     {
       
   525     TRACE_ENTRY_POINT;
       
   526     
       
   527     MCalenCommandHandler* handler( NULL );
       
   528 
       
   529     // Stop non-published commands from being customised
       
   530     if ( aCommand != ECalenShowSettings
       
   531         && aCommand != ECalenSwitchView )
       
   532         {
       
   533         // See if a plugin wants the command
       
   534         handler = iCustomisationManager->GetCommandHandlerL( aCommand );
       
   535         }
       
   536 
       
   537     // See if the view manager wants the command
       
   538     if(!handler)
       
   539         {
       
   540         if( aCommand >= ECalenViewCommandBase
       
   541             && aCommand < ECalenEditCommandBase )
       
   542             {
       
   543             handler = iViewManager;
       
   544             }
       
   545      	else if(aCommand >= ECalenMissedAlarmCommandBase
       
   546       		&& aCommand < ECalenAttachmentCommandBase )
       
   547 	    	{
       
   548 	    	handler = iAlarmManager;
       
   549 	    	} 
       
   550         else 
       
   551             {
       
   552             handler = iActionUi->GetCommandHandlerL(aCommand);
       
   553             }
       
   554         }
       
   555 
       
   556     // No command handler is an error  
       
   557     
       
   558     // return the handler
       
   559     TRACE_EXIT_POINT;
       
   560     return handler;
       
   561     }
       
   562 
       
   563 // ----------------------------------------------------
       
   564 //  CCalenController::CheckSystemTimeAtStartUpL
       
   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
       
   673 // (other items were commented in a header).
       
   674 // ----------------------------------------------------------------------------
       
   675 //
       
   676 EXPORT_C MCalenServices* CCalenController::NewServicesL()
       
   677     {
       
   678     TRACE_ENTRY_POINT;
       
   679 
       
   680     TInt commandRangeStart = iNextServicesCommandBase;
       
   681     TInt commandRangeEnd = commandRangeStart + KNumberOfCommandsPerServices;
       
   682     iNextServicesCommandBase = commandRangeEnd + 1;
       
   683 
       
   684     CCalenServicesImpl* svc = CCalenServicesImpl::NewL( commandRangeStart,
       
   685                                                                               commandRangeEnd );
       
   686     TRACE_EXIT_POINT;
       
   687     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     }
       
   706 
       
   707 // ----------------------------------------------------------------------------
       
   708 // CCalenController::Notifier
       
   709 // Returns the notifier.
       
   710 // (other items were commented in a header).
       
   711 // ----------------------------------------------------------------------------
       
   712 //
       
   713 CCalenNotifier& CCalenController::Notifier()
       
   714     {
       
   715     TRACE_ENTRY_POINT;
       
   716     TRACE_EXIT_POINT;
       
   717     return *iNotifier;
       
   718     }
       
   719 
       
   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 // ----------------------------------------------------------------------------
       
   805 // CCalenController::Infobar
       
   806 // Descriptor passed to plugins to get customised info bar text.
       
   807 // Acts as a conduit between the services and the customisation manager.
       
   808 // (other items were commented in a header).
       
   809 // ----------------------------------------------------------------------------
       
   810 //
       
   811 EXPORT_C CCoeControl* CCalenController::Infobar( const TRect& aRect )
       
   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     {
       
   827     TRACE_ENTRY_POINT;
       
   828     TRACE_EXIT_POINT;
       
   829     return iCustomisationManager->Infobar();
       
   830     }
       
   831 
       
   832 // ----------------------------------------------------------------------------
       
   833 // CCalenController::PreviewPane
       
   834 // Descriptor passed to plugins to get customised preview pane text.
       
   835 // Acts as a conduit between the services and the customisation manager.
       
   836 // (other items were commented in a header).
       
   837 // ----------------------------------------------------------------------------
       
   838 //
       
   839 EXPORT_C CCoeControl* CCalenController::PreviewPane( TRect& aRect )
       
   840     {
       
   841     TRACE_ENTRY_POINT;
       
   842     TRACE_EXIT_POINT;
       
   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 // ----------------------------------------------------------------------------
       
   860 // CCalenController::CustomisationManager
       
   861 // Returns a reference to the customisation manager
       
   862 // (other items were commented in a header).
       
   863 // ----------------------------------------------------------------------------
       
   864 //
       
   865 CCalenCustomisationManager& CCalenController::CustomisationManager()
       
   866     {
       
   867     TRACE_ENTRY_POINT;
       
   868     TRACE_EXIT_POINT;
       
   869     return *iCustomisationManager;
       
   870     }
       
   871 
       
   872 // ----------------------------------------------------------------------------
       
   873 // CCalenController::ViewManager
       
   874 // Returns a reference to the view manager
       
   875 // (other items were commented in a header).
       
   876 // ----------------------------------------------------------------------------
       
   877 CCalenViewManager& CCalenController::ViewManager()
       
   878     {
       
   879     TRACE_ENTRY_POINT;
       
   880     TRACE_EXIT_POINT;
       
   881     return *iViewManager;
       
   882     }
       
   883 
       
   884 // ----------------------------------------------------------------------------
       
   885 // CCalenController::MissedAlarmStore
       
   886 // Returns a reference to the Missed Alarm Store
       
   887 // ----------------------------------------------------------------------------
       
   888 CMissedAlarmStore* CCalenController::MissedAlarmStore()
       
   889     {
       
   890     TRACE_ENTRY_POINT;
       
   891     TRACE_EXIT_POINT;
       
   892 
       
   893     return iAlarmManager->MissedAlarmStore();
       
   894     }
       
   895 
       
   896 // ----------------------------------------------------------------------------
       
   897 // CCalenController::IsFasterAppFlagEnabled
       
   898 // Returns ETrue if the application is fake exited
       
   899 // else return EFalse.
       
   900 // (other items were commented in a header).
       
   901 // ----------------------------------------------------------------------------
       
   902 TBool CCalenController::IsFasterAppFlagEnabled()
       
   903     {
       
   904     TRACE_ENTRY_POINT;
       
   905     TRACE_EXIT_POINT;
       
   906 	return iFasterApp;
       
   907     }
       
   908 
       
   909 // ----------------------------------------------------------------------------
       
   910 // CCalenController::SetFasterAppFlag
       
   911 // Set the flag 'iFasterApp' to ETrue if application is fake exited
       
   912 // and to EFalse once the application comes to foreground.
       
   913 // (other items were commented in a header).
       
   914 // ----------------------------------------------------------------------------
       
   915 void CCalenController::SetFasterAppFlag( TBool aFlag )
       
   916 	{
       
   917     TRACE_ENTRY_POINT;
       
   918     TRACE_EXIT_POINT;
       
   919 	iFasterApp = aFlag;
       
   920 	}
       
   921 
       
   922 // ----------------------------------------------------------------------------
       
   923 // CCalenController::AppUi
       
   924 // Returns a reference to the appui
       
   925 // (other items were commented in a header).
       
   926 // ----------------------------------------------------------------------------
       
   927 //
       
   928 CAknViewAppUi& CCalenController::AppUi()
       
   929     {
       
   930     TRACE_ENTRY_POINT;
       
   931     TRACE_EXIT_POINT;
       
   932     return iAppUi;
       
   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 	
       
  1044 // -----------------------------------------------------------------------------
       
  1045 // CCalenController::IsEditorActive
       
  1046 // Tells framework whether editor is active or not
       
  1047 // -----------------------------------------------------------------------------
       
  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
       
  1114