calendarui/controller/src/calenviewmanager.cpp
branchRCL_3
changeset 30 bd7edf625bdd
parent 29 12af337248b1
child 31 97232defd20e
equal deleted inserted replaced
29:12af337248b1 30:bd7edf625bdd
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Calendar view manager
    14 * Description:  Calendar view manager
    15  *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 //system includes
    19 #include <aknViewAppUi.h>
    20 #include <hbmainwindow.h>
    20 #include <centralrepository.h>
    21 #include <hbinstance.h>
    21 #include <AknQueryDialog.h>
    22 #include <hbapplication.h> // hbapplication
    22 #include <Calendar.rsg>
    23 #include <xqserviceutil.h> // service utils
    23 #include <calencommonui.rsg>
    24 
    24 #include <akntoolbar.h>
    25 //user includes
    25 #include <calendateutils.h>
       
    26 #include <calencommandhandler.h>
       
    27 #include <calencommands.hrh>                // Calendar commands
       
    28 #include <calentoolbar.h>
       
    29 #include <akntoolbarextension.h>
       
    30 #include <calenactionuiutils.h>
       
    31 
       
    32 #include "calendarui_debug.h"
    26 #include "calenviewmanager.h"
    33 #include "calenviewmanager.h"
       
    34 #include "CalenUid.h"
    27 #include "calencontroller.h"
    35 #include "calencontroller.h"
    28 #include "hb_calencommands.hrh"
    36 #include "calenviewpopulator.h"
       
    37 #include "calenglobaldata.h"
       
    38 #include "CalendarPrivateCRKeys.h"          // includes CalendarInternalCRKeys.h
       
    39 #include "calenmonthview.h"                 // Native month view
       
    40 #include "calenweekview.h"                  // Native week view
       
    41 #include "calendayview.h"                   // Native day view
       
    42 #include "calentodoview.h"                  // Native todo view
       
    43 #include "caleneventview.h"                 // Event View
       
    44 #include "calenmissedalarmsview.h"			// Missed alarms view
       
    45 #include "calenmissedeventview.h"			// Missed event view
       
    46 #include "calensetting.h"                   // CCalenSetting::TViewType
       
    47 #include "calencmdlinelauncher.h"           // Command line launcher
    29 #include "calenservicesimpl.h"
    48 #include "calenservicesimpl.h"
    30 #include "calenmonthview.h"
    49 #include "CleanupResetAndDestroy.h"
    31 #include "calenagendaview.h"
    50 #include "calentoolbarimpl.h"
    32 #include "calenmonthview.h"
    51 #include "calencustomisationmanager.h"
    33 #include "agendaeventviewer.h"
    52 #include "calenviewinfo.h"
    34 #include "calennotificationhandler.h"
    53 #include "calentitlepane.h"
    35 #include "CalenUid.h"
    54 #include "calenicons.h"
    36 #include "calenactionuiutils.h"
    55 #include "calendummyview.h"
    37 #include "calensettingsview.h"
    56 
    38 #include "calendocloader.h"
    57 const TInt KArrayGranularity = 5;
    39 #include "calendarui_debug.h"
    58 
    40 #include "calencommon.h"
    59 // ----------------------------------------------------------------------------
    41 #include "calendayview.h"
    60 // CCalenViewManager::NewL
    42 #include <agendautil.h>
    61 // 1st phase of construction
    43 #include "OstTraceDefinitions.h"
    62 // (other items were commented in a header).
    44 #ifdef OST_TRACE_COMPILER_IN_USE
    63 // ----------------------------------------------------------------------------
    45 #include "calenviewmanagerTraces.h"
    64 //
    46 #endif
    65 CCalenViewManager* CCalenViewManager::NewL( CAknViewAppUi& aAppUi,
    47 
    66                                             CCalenController& aController )
    48 // ----------------------------------------------------------------------------
    67     {
    49 // CalenViewManager::CalenViewManager
    68     TRACE_ENTRY_POINT;
       
    69 
       
    70     CCalenViewManager* self = new( ELeave ) CCalenViewManager( aAppUi,aController );
       
    71     CleanupStack::PushL( self );
       
    72     self->ConstructL();
       
    73     CleanupStack::Pop( self );
       
    74 
       
    75     TRACE_EXIT_POINT;
       
    76     return self;
       
    77     }
       
    78 
       
    79 // ----------------------------------------------------------------------------
       
    80 // CCalenViewManager::CCalenViewManager
       
    81 // C++ default Constructor.
       
    82 // (other items were commented in a header).
       
    83 // ----------------------------------------------------------------------------
       
    84 //
       
    85 CCalenViewManager::CCalenViewManager( CAknViewAppUi& aAppUi, 
       
    86                                       CCalenController& aController )
       
    87     : iAppUi( aAppUi ), iController( aController )
       
    88     {
       
    89     TRACE_ENTRY_POINT;
       
    90     TRACE_EXIT_POINT;
       
    91     }
       
    92 
       
    93 // ----------------------------------------------------------------------------
       
    94 // CCalenViewManager::~CCalenViewManager
       
    95 // Destructor.
       
    96 // (other items were commented in a header).
       
    97 // ----------------------------------------------------------------------------
       
    98 //
       
    99 CCalenViewManager::~CCalenViewManager()
       
   100     {
       
   101     TRACE_ENTRY_POINT;
       
   102 
       
   103     delete iPopulator;
       
   104     if(iToolbar)
       
   105         {
       
   106         delete iToolbar;
       
   107         iToolbar = NULL;
       
   108         }
       
   109     if( iSetting )
       
   110         {
       
   111         iSetting->Release();
       
   112         }
       
   113 
       
   114     if( iGlobalData )
       
   115         {
       
   116         iGlobalData->Release();
       
   117         }
       
   118 
       
   119     iViewInfoArray.ResetAndDestroy();
       
   120     iKnownPlugins.Reset();
       
   121     
       
   122     delete iRemovedActiveView;
       
   123     delete iViewRemovalCallback;
       
   124     delete iIcons;
       
   125 
       
   126     TRACE_EXIT_POINT;
       
   127     }
       
   128 
       
   129 // ----------------------------------------------------------------------------
       
   130 // CCalenViewManager::ConstructL
    50 // 2nd phase of construction.
   131 // 2nd phase of construction.
    51 // (other items were commented in a header).
   132 // (other items were commented in a header).
    52 // ----------------------------------------------------------------------------
   133 // ----------------------------------------------------------------------------
    53 //
   134 //
    54 CalenViewManager::CalenViewManager( CCalenController& aController)
   135 void CCalenViewManager::ConstructL()
    55 : mController(aController)
   136     {
    56 {
   137     TRACE_ENTRY_POINT;
    57 	OstTraceFunctionEntry0( CALENVIEWMANAGER_CALENVIEWMANAGER_ENTRY );
   138 
       
   139     iGlobalData = CCalenGlobalData::InstanceL();
       
   140     iPopulator = CCalenViewPopulator::NewL( iController );
       
   141 
       
   142     // Only create a toolbar impl if touch is enabled and a CAknToolbar exists
       
   143     if( AknLayoutUtils::PenEnabled() )
       
   144         {
       
   145         CAknAppUi* appUi = static_cast<CAknAppUi*>( CEikonEnv::Static()->EikAppUi() );
       
   146         if (appUi->CurrentFixedToolbar())
       
   147             {
       
   148             iToolbar = CCalenToolbarImpl::NewL( iController );
       
   149             }
       
   150         }
       
   151 
       
   152     iSetting = CCalenSetting::InstanceL();
       
   153     iPreviousViewId.iViewUid = KNullUid;
       
   154     iAvoidRepopulation = EFalse;
       
   155     iStartupComplete = ETrue;
       
   156     
       
   157     TRACE_EXIT_POINT;
       
   158     }
       
   159 
       
   160 // ----------------------------------------------------------------------------
       
   161 // CCalenViewManager::SetCustomisationManagerL
       
   162 // Creates custom views.
       
   163 // (other items were commented in a header).
       
   164 // ----------------------------------------------------------------------------
       
   165 //
       
   166 void CCalenViewManager::ConstructCustomViewsL(
       
   167                              CCalenCustomisationManager& aCustomisationManager )
       
   168     {
       
   169     TRACE_ENTRY_POINT;
       
   170 
       
   171     iCustomisationManager = &aCustomisationManager;
       
   172     ConstructCustomViewsL();
       
   173     ConstructNativeViewsL();
       
   174 
       
   175     TUid defViewUid = iSetting->DefaultView();
       
   176     ActivateDefaultViewL( defViewUid );
       
   177     	
       
   178     // Register for view activation events
       
   179     iAppUi.AddViewActivationObserverL( this );
       
   180 
       
   181     TRACE_EXIT_POINT;
       
   182     }
       
   183 
       
   184 // ----------------------------------------------------------------------------
       
   185 // CCalenViewManager::ViewInfoArray
       
   186 // Get info array
       
   187 // (other items were commented in a header).
       
   188 // ----------------------------------------------------------------------------
       
   189 //
       
   190 RPointerArray<CCalenViewInfo>& CCalenViewManager::ViewInfoArray()
       
   191     {
       
   192     TRACE_ENTRY_POINT;
       
   193     TRACE_EXIT_POINT;
       
   194     return iViewInfoArray;
       
   195     }
       
   196 
       
   197 // ----------------------------------------------------------------------------
       
   198 // CCalenViewManager::CustomiszationManager
       
   199 // Return reference to the customisation manager
       
   200 // (other items were commented in a header).
       
   201 // ----------------------------------------------------------------------------
       
   202 //
       
   203 CCalenCustomisationManager& CCalenViewManager::CustomisationManager()
       
   204     {
       
   205     TRACE_ENTRY_POINT;
       
   206 
       
   207     ASSERT( iCustomisationManager );
       
   208 
       
   209     TRACE_EXIT_POINT;
       
   210     return *iCustomisationManager;
       
   211     }
       
   212 
       
   213 // ----------------------------------------------------------------------------
       
   214 // CCalenViewManager::ConstructNativeViewsL
       
   215 // Constructs the S60 native views and registers them with the view server
       
   216 // (other items were commented in a header).
       
   217 // ----------------------------------------------------------------------------
       
   218 //
       
   219 void CCalenViewManager::ConstructNativeViewsL()
       
   220     {
       
   221     TRACE_ENTRY_POINT;
       
   222 
       
   223     CCalenTitlePane::NewAndSwapL(iAppUi.StatusPane());
       
   224     MCalenServices& services = iController.Services();
       
   225     
       
   226     
       
   227     // Add the native views for the todo view, week view, day view , month
       
   228     // view and event view unless they are already provided by custom views 
       
   229     // in ROM.This is enforced by the customisation manager rejecting any 
       
   230     // views that try to replace the native views but are not in ROM.
       
   231 
       
   232     if (CreateNativeViewL(KUidCalenMonthView))
       
   233         {
       
   234         // Views take ownership of services object instantly. 
       
   235         // No need for cleanup stack.
       
   236         CCalenMonthView* monthView = CCalenMonthView::NewL(services);
       
   237         AddNativeViewL(monthView); // takes ownership immediately.
       
   238         }
       
   239 
       
   240     if (CreateNativeViewL(KUidCalenWeekView))
       
   241         {
       
   242         // Views take ownership of services object instantly. 
       
   243         // No need for cleanup stack.
       
   244         CCalenWeekView* weekView = CCalenWeekView::NewL(services);
       
   245         AddNativeViewL(weekView); // takes ownership immediately.
       
   246         }
       
   247         
       
   248     if (CreateNativeViewL(KUidCalenDayView))
       
   249         {  
       
   250         // Views take ownership of services object instantly. 
       
   251         // No need for cleanup stack.
       
   252         CCalenDayView* dayView = CCalenDayView::NewL(services);
       
   253         AddNativeViewL(dayView); // takes ownership immediately.
       
   254         }
       
   255     
       
   256     if (CreateNativeViewL(KUidCalenTodoView))
       
   257         {
       
   258         // Views take ownership of services object instantly. 
       
   259         // No need for cleanup stack.
       
   260         CCalenTodoView* todoView = CCalenTodoView::NewL(services);
       
   261         AddNativeViewL(todoView); // takes ownership immediately.
       
   262         }
    58 	
   263 	
    59 	// Following block intializes member variables
   264 	if( CreateNativeViewL(KUidCalenEventView))
    60 	mCalenEventViewer = NULL;
   265 		{
    61 	mMonthViewDocLoader = NULL;
   266         // Views take ownership of services object instantly. 
    62 	mAgendaViewDocLoader = NULL;	
   267 		// No need for cleanup stack.
    63 	mAgendaViewAltDocLoader = NULL;
   268         CCalenEventView* eventView = CCalenEventView::NewL(services);
    64 	mCalenAgendaView = NULL;
   269         AddNativeViewL(eventView); // takes ownership immediately.
    65 	mCalenMonthView = NULL;
   270 		}
    66 	mCalenAgendaViewAlt = NULL;
   271 
    67 	mSettingsView = NULL;
   272 	if( CreateNativeViewL(KUidCalenMissedAlarmsView))
    68 	mCalenDayView = NULL;
   273 		{
    69 	mInstanceViewCreated = false;
   274         // Views take ownership of services object instantly. 
       
   275 		// No need for cleanup stack.
       
   276         CCalenMissedAlarmsView* missedAlarmsView = CCalenMissedAlarmsView::NewL(services);
       
   277         AddNativeViewL(missedAlarmsView); // takes ownership immediately.
       
   278 		}
       
   279 
       
   280 	if( CreateNativeViewL(KUidCalenMissedEventView))
       
   281 		{
       
   282         // Views take ownership of services object instantly. 
       
   283 		// No need for cleanup stack.
       
   284         CCalenMissedEventView* missedEventView = CCalenMissedEventView::NewL(services);
       
   285         AddNativeViewL(missedEventView); // takes ownership immediately.
       
   286 		}
    70 	
   287 	
    71 	// Connect to instance view and entry view creation signals from agenda
   288 	if(CreateNativeViewL(KUidCalenDummyView))
    72 	// interface
   289 	    {
    73 	connect(mController.agendaInterface(), SIGNAL(instanceViewCreationCompleted(int)),
   290 	    CCalenDummyView* dummyView = CCalenDummyView::NewL(services);
    74 	        this, SLOT(handleInstanceViewCreation(int)));
   291 	    AddNativeViewL(dummyView);
    75 	connect(mController.agendaInterface(), SIGNAL(entryViewCreationCompleted(int)),
   292 	    }
    76 		        this, SLOT(handleEntryViewCreation(int)));
   293     TRACE_EXIT_POINT;
    77 	connect(mController.agendaInterface(), SIGNAL(entriesChanged(QList<ulong>)),
   294     }
    78 								this, SLOT(handleEntriesChanged(QList<ulong>)));
   295 
    79     connect(mController.agendaInterface(), SIGNAL(entryUpdated(ulong)),
   296 // ----------------------------------------------------------------------------
    80                                 this, SLOT(handleEntryUpdation(ulong)));
   297 // CCalenViewManager::CreateNativeViewL
    81     connect(mController.agendaInterface(), SIGNAL(entryAdded(ulong)),
   298 // Checks to see if the native view needs to created.
    82                                 this, SLOT(handleEntryUpdation(ulong)));
   299 // (other items were commented in a header).
    83 	OstTraceFunctionExit0( CALENVIEWMANAGER_CALENVIEWMANAGER_EXIT );
   300 // ----------------------------------------------------------------------------
    84 }
   301 //
    85 
   302 TBool CCalenViewManager::CreateNativeViewL(TUid aViewUid)
    86 void CalenViewManager::SecondPhaseConstruction()
   303     {
    87 {
   304     TRACE_ENTRY_POINT;
    88     OstTraceFunctionEntry0( CALENVIEWMANAGER_SECONDPHASECONSTRUCTION_ENTRY );
   305     
    89     
   306     TBool createNativeView = ETrue;
    90     // Check the Application Startup reason from Activity Manager
   307     TBool (*compareFn)(const TUid*, const CCalenViewInfo&) 
    91     int activityReason = qobject_cast<HbApplication*>(qApp)->activateReason();
   308                                          = CCalenViewInfo::ViewInfoIdentifier;
    92     
   309                                             
    93     // Check if calendar is launched thru XQService framework
   310     TInt position = iViewInfoArray.Find( aViewUid, compareFn );
    94     bool isFromServiceFrmWrk = XQServiceUtil::isService(); // Since activateReason 
   311     if ( position != KErrNotFound )
    95     //of hbapplication is not returning right value if the activity is started 
   312         {
    96     //as services so using the above line temporarily untill a fix is available in 
   313         // A plugin is trying to replace a native view, find if it is rom
    97     // hbappliacation. Need to remove this line after the fix is available for hbapplcation
   314         // based or not
    98 
   315         TBool romBased = CustomisationManager().IsViewRomBased( aViewUid );
    99     
   316         if ( romBased )
   100     if (Hb::ActivationReasonActivity == activityReason) // Check if application is started 
   317             {
   101     // as an activity
   318             createNativeView = EFalse;
   102         {
   319             }
   103         // Application is started from an activity
   320         else
   104         // Extract activity data
   321             {
   105         QVariant data = qobject_cast<HbApplication*>(qApp)->activateData();
   322             // A non-rom plugin cannot replace the native views, so the view is
   106         // Restore state from activity data
   323             // removed
   107         QByteArray serializedModel = data.toByteArray();
   324             iAppUi.RemoveView( aViewUid );
   108         QDataStream stream(&serializedModel, QIODevice::ReadOnly);
   325             
   109         int viewId; // int declared for debugging purpose
   326             // Remove the entry from the view info array
   110         stream >> viewId; // read stream into an int
   327             iViewInfoArray.Remove( position );
       
   328             
       
   329             createNativeView = ETrue;
       
   330             }
       
   331         }
   111         
   332         
   112         mFirstView = viewId;
   333     TRACE_EXIT_POINT;
   113         if (ECalenMonthView == viewId) // Check if Activity was stored for month view
   334     return createNativeView;
   114             {
   335     }
   115             loadMonthView(); // Load month view
   336  
   116             }
   337 // ----------------------------------------------------------------------------
   117         else if (ECalenAgendaView == viewId) // Check if Activity was stored for agenda view
   338 // CCalenViewManager::ConstructCustomViewsL
   118             {
   339 // Constructs any custom views from all the plugins and registers them 
   119         	loadAgendaView(); // Load agenda view
   340 // with the view server
   120             }
   341 // (other items were commented in a header).
       
   342 // ----------------------------------------------------------------------------
       
   343 //
       
   344 void CCalenViewManager::ConstructCustomViewsL()
       
   345     {
       
   346     TRACE_ENTRY_POINT;
       
   347 
       
   348     // Get the array of active plugins
       
   349     const RArray<TUid>& plugins = CustomisationManager().ActivePlugins();
       
   350 
       
   351     // For every active plugin, discover if it offers any customised views
       
   352     // and adds them to the view server.
       
   353     TInt numPlugins = plugins.Count();
       
   354     for( TInt pluginIndex( 0 ); pluginIndex < numPlugins; ++pluginIndex )
       
   355         {
       
   356         TUid pluginUid = plugins[pluginIndex];
       
   357         ConstructCustomViewL( pluginUid );
       
   358         }
       
   359 
       
   360     TRACE_EXIT_POINT;
       
   361     }
       
   362     
       
   363 // ----------------------------------------------------------------------------
       
   364 // CCalenViewManager::ConstructCustomViewsL
       
   365 // Constructs the custom views from a particular plugin and registers them
       
   366 //  with the view server
       
   367 // (other items were commented in a header).
       
   368 // ----------------------------------------------------------------------------
       
   369 //
       
   370 void CCalenViewManager::ConstructCustomViewL( TUid aPluginUid )
       
   371     {
       
   372     TRACE_ENTRY_POINT;
       
   373 
       
   374     iKnownPlugins.AppendL( aPluginUid );
       
   375 
       
   376     RPointerArray<CCalenView> customViews;
       
   377     CleanupResetAndDestroyPushL( customViews );
       
   378 
       
   379     TRAP_IGNORE(CustomisationManager().GetCustomViewsL( aPluginUid, customViews ));
       
   380     for( TInt viewIndex( customViews.Count()-1 ); viewIndex >= 0; --viewIndex )
       
   381         {
       
   382         CCalenView* customView = customViews[viewIndex];
       
   383         iAppUi.AddViewL( customView );
       
   384         customViews.Remove( viewIndex );
       
   385         }
       
   386     CleanupStack::PopAndDestroy(); // customViews
       
   387 
       
   388     TRACE_EXIT_POINT;
       
   389     }    
       
   390 
       
   391 // ----------------------------------------------------------------------------
       
   392 // CCalenViewManager::ActivateDefaultViewL
       
   393 // Activates the default view (retrieved from settings).
       
   394 // ----------------------------------------------------------------------------
       
   395 //
       
   396 void CCalenViewManager::ActivateDefaultViewL( TUid aDefaultView )
       
   397     {
       
   398     TRACE_ENTRY_POINT;
       
   399 
       
   400     // Find the default view in the view cycle list
       
   401     TInt position = iViewInfoArray.Find(
       
   402                             aDefaultView, CCalenViewInfo::ViewInfoIdentifier );
       
   403     if( position != KErrNotFound )
       
   404         {
       
   405         iAppUi.SetDefaultViewL( *iAppUi.View( aDefaultView ) );
       
   406         iViewCycleIndex = position;
       
   407         }
       
   408 	else
       
   409 	    {
       
   410 	    CRepository* repository = CRepository::NewL( KCRUidCalendar );
       
   411 	    CleanupStack::PushL(repository);
       
   412 	    TInt tmp( static_cast<TInt>( KUidCalenMonthView.iUid ) );
       
   413 	    TInt position = iViewInfoArray.Find( KUidCalenMonthView, CCalenViewInfo::ViewInfoIdentifier );
       
   414 	    User::LeaveIfError( repository->Set( KCalendarDefaultStartView, tmp ) );
       
   415 	    iAppUi.SetDefaultViewL( *iAppUi.View( KUidCalenMonthView ) );
       
   416 	    iViewCycleIndex = position;
       
   417 	    CleanupStack::PopAndDestroy(repository);  
       
   418 	    }
       
   419     TRACE_EXIT_POINT;
       
   420 
       
   421     }
       
   422 
       
   423 // ----------------------------------------------------------------------------
       
   424 // CCalenViewManager::InterruptPopulationL
       
   425 // Interrupts the population of the current view. When the editors are launched
       
   426 // the view population is interrupted as it will be repopulated when the
       
   427 // the editor closes.
       
   428 // ----------------------------------------------------------------------------
       
   429 //
       
   430 void CCalenViewManager::InterruptPopulationL()
       
   431     {
       
   432     TRACE_ENTRY_POINT;
       
   433 
       
   434     // Cancel population of current view, if it's ongoing.
       
   435     iPopulator->InterruptPopulationL();
       
   436 
       
   437     TRACE_EXIT_POINT;
       
   438     }
       
   439 
       
   440 // ----------------------------------------------------------------------------
       
   441 // CCalenViewManager::RemoveCurrentViewFromMenu
       
   442 // Removes the current view from the cascading view switch menu
       
   443 // (other items were commented in a header).
       
   444 // ----------------------------------------------------------------------------
       
   445 //
       
   446 void CCalenViewManager::RemoveCurrentViewFromMenu( CEikMenuPane* aMenuPane )
       
   447     {
       
   448     TRACE_ENTRY_POINT;
       
   449 
       
   450     TUid uid = CurrentView();
       
   451 
       
   452     if( uid == KUidCalenMonthView )
       
   453         {
       
   454         aMenuPane->DeleteMenuItem( ECalenMonthView );
       
   455         }
       
   456     else if( uid == KUidCalenWeekView )
       
   457         {
       
   458         aMenuPane->DeleteMenuItem( ECalenWeekView );
       
   459         }
       
   460     else if( uid == KUidCalenDayView )
       
   461         {
       
   462         aMenuPane->DeleteMenuItem( ECalenDayView );
       
   463         }
       
   464     else if( uid == KUidCalenTodoView )
       
   465         {
       
   466         aMenuPane->DeleteMenuItem( ECalenTodoView );
       
   467         }
       
   468     else
       
   469         {
       
   470         // Assert as this point should never be reached
       
   471         ASSERT( 0 );
       
   472         }
       
   473 
       
   474     TRACE_EXIT_POINT;
       
   475     }
       
   476 
       
   477 // ----------------------------------------------------------------------------
       
   478 // CCalenViewManager::AddNativeViewL
       
   479 // Adds a view to the array.
       
   480 // (other items were commented in a header).
       
   481 // ----------------------------------------------------------------------------
       
   482 //
       
   483 void CCalenViewManager::AddNativeViewL( CCalenView* aView )
       
   484     {
       
   485     TRACE_ENTRY_POINT;
       
   486 
       
   487     CleanupStack::PushL( aView );
       
   488     iAppUi.AddViewL( aView );
       
   489     CleanupStack::Pop( aView );
       
   490 
       
   491     const TDesC& menuName = aView->LocalisedViewNameL( CCalenView::EMenuName );
       
   492     const TDesC& settingsName = aView->LocalisedViewNameL( CCalenView::ESettingsName );
       
   493 
       
   494     TUid viewUid = aView->Id();
       
   495     
       
   496 
       
   497     CCalenViewInfo* viewInfo = CCalenViewInfo::NewL( aView->Id(),
       
   498                                                      KUidCalendar,
       
   499                                                      menuName,
       
   500                                                      settingsName,
       
   501                                                      aView->CyclePosition() );
   121         
   502         
   122         ActivateDefaultViewL(viewId);
   503     // Discover if a native view has been hidden by a plugin.                                             
   123         // Connect to the view ready signal so that we can construct other views 
   504     TBool hidden = iCustomisationManager->HiddenView( viewUid );
   124         // once this view is ready
   505     viewInfo->Hide( hidden );
   125         connect(&mController.MainWindow(), SIGNAL(viewReady()), 
   506     
   126                 this, SLOT(handleMainViewReady()));
   507     // Append to view info array
   127 
   508     iViewInfoArray.InsertInOrderAllowRepeatsL( viewInfo, 
   128         if (ECalenMonthView == viewId) // Check if Activity was stored for month view
   509                                        CCalenViewInfo::CyclePositionComparison );
   129             {
   510 
   130             mController.MainWindow().addView(mCalenMonthView); // Add month view to main window
   511     TRACE_EXIT_POINT;
   131             mController.MainWindow().setCurrentView(mCalenMonthView); // Set month view as current view
   512     }
   132             } 
   513 
   133         else if (ECalenAgendaView == viewId) // Check if Activity was stored for agenda view
   514 // ----------------------------------------------------------------------------
   134             {
   515 // CCalenViewManager::HandleCommandL
   135             mController.MainWindow().addView(mCalenAgendaView); // Add agenda view to main window
   516 // Handles view manager commands.
   136             mController.MainWindow().setCurrentView(mCalenAgendaView); // Set agenda view as current view
   517 // (other items were commented in a header).
   137             }
   518 // ----------------------------------------------------------------------------
   138         } else if (isFromServiceFrmWrk/*Hb::ActivationReasonService == activityReason*/) {
   519 //
   139         // Dont load any views until our remote slot gets called in
   520 TBool  CCalenViewManager::HandleCommandL( const TCalenCommand& aCommand )
   140         // calenserviceprovider.cpp
   521     {
   141         // Just have an empty mainwindow
   522     TRACE_ENTRY_POINT;
   142     } else {
   523     
   143         // Do the normal startup
   524     TBool commandUsed(EFalse);
   144         // Load the month view and active it and add it to main window
   525     
   145         mFirstView = ECalenMonthView;
   526     switch( aCommand.Command() )
   146         loadMonthView();
   527         {
   147         ActivateDefaultViewL(ECalenMonthView);
   528         case ECalenMonthView:
   148         // Connect to the view ready signal so that we construct other view 
   529             {
   149         // once this view is shown
   530             RequestActivationL( KUidCalenMonthView );
   150         connect(&mController.MainWindow(), SIGNAL(viewReady()), 
   531             }
   151                         this, SLOT(handleMainViewReady()));
   532             break;
       
   533         case ECalenWeekView:
       
   534             {
       
   535             RequestActivationL( KUidCalenWeekView );
       
   536             }
       
   537             break;
       
   538         case ECalenDayView:
       
   539             {
       
   540             // reset the flag iForwardedToDayView as view switching is active
       
   541             if(iPreviousToDayView.iViewUid!=KNullUid)
       
   542                 {
       
   543                 iPreviousToDayView.iViewUid = KNullUid;
       
   544                 }
       
   545             RequestActivationL( KUidCalenDayView, KCalenDummyUid, KNullDesC8() );
       
   546             if(iController.IsLaunchFromExternalApp())
       
   547                 {
       
   548                 iAvoidRepopulation = ETrue;
       
   549                 }
       
   550             }
       
   551             break;
       
   552         case ECalenTodoView:
       
   553             {
       
   554             if (iAvoidRepopulation)
       
   555                 {
       
   556                 iAvoidRepopulation = EFalse;
       
   557                 }
       
   558             RequestActivationL( KUidCalenTodoView );
       
   559             }
       
   560             break;
       
   561         case ECalenEventView:
       
   562             {
       
   563             // Fix for EJCU-7LKC2C :: to prevent the display of blank view, 
       
   564             // just set the iAvoidRepopulation to EFalse, 
       
   565             // so that view is populated properly
       
   566 
       
   567             if (iAvoidRepopulation)
       
   568                 {
       
   569                 iAvoidRepopulation = EFalse;
       
   570                 }
       
   571 
       
   572         	RequestActivationL( KUidCalenEventView );
       
   573             }
       
   574         	break;
       
   575         case ECalenForwardsToDayView:
       
   576             {
       
   577             // set the view iPreviousToDayView to handle the day view's cba
       
   578             // when returning from event view.
       
   579             // From month/week view -> day view -> event view -> day view
       
   580             iPreviousToDayView = iCurrentViewId;
       
   581             if(iAvoidRepopulation)
       
   582                 {
       
   583                 iAvoidRepopulation = EFalse;
       
   584                 }
       
   585             RequestActivationL( KUidCalenDayView, KUidCalenShowBackCba );
       
   586             }
       
   587             break;
       
   588         case ECalenForwardsToWeekView:
       
   589             {
       
   590             // set the view iPreviousToWeekView to handle the week view's cba
       
   591             // From month view -> week view 
       
   592             iPreviousToWeekView = iCurrentViewId;
       
   593             if(iAvoidRepopulation)
       
   594                 {
       
   595                 iAvoidRepopulation = EFalse;
       
   596                 }
       
   597             RequestActivationL( KUidCalenWeekView, KUidCalenShowBackCba );
       
   598             }
       
   599             break;
       
   600         case ECalenNextView:
       
   601             {
       
   602             CycleNextViewL();
       
   603             }
       
   604             break;
       
   605         case ECalenPrevView:
       
   606             {
       
   607             CyclePrevViewL();
       
   608             }
       
   609             break;
       
   610         case ECalenSwitchView:
       
   611             {
       
   612             ShowSwitchViewQueryL();
       
   613             }
       
   614             break;
       
   615         case ECalenStartActiveStep:
       
   616             {
       
   617             StartActiveStepL();
       
   618             }
       
   619             break;
       
   620         case ECalenFasterAppExit:
       
   621         	{
       
   622         	HandleFasterAppExitCommandL();
       
   623         	}
       
   624             break;
       
   625         case ECalenGotoToday:
       
   626             {
       
   627             // get today's date
       
   628             TTime today = CalenDateUtils::Today();
       
   629 
       
   630             // get the context    
       
   631             MCalenContext& context = iController.Services().Context();
       
   632             TCalTime todayCalTime;
       
   633             todayCalTime.SetTimeLocalL( today );
       
   634             // set today's date to the context
       
   635             context.SetFocusDateAndTimeL( todayCalTime, iCurrentViewId  );
       
   636             
       
   637             SetRepopulation(EFalse);
       
   638             // reactivate the current view
       
   639             //RequestActivationL(iCurrentViewId.iViewUid);
       
   640             RequestActivationL(KUidCalenDayView);
       
   641 
       
   642 			// dim "today" toolbar item since focus is on today            
       
   643             //iToolbar->Toolbar().SetItemDimmed( ECalenGotoToday, ETrue, ETrue);
       
   644             }
       
   645             break;
       
   646 
       
   647         default:
       
   648             break;
       
   649         }
       
   650 
       
   651     TRACE_EXIT_POINT;
       
   652     return commandUsed;
       
   653     }
       
   654 
       
   655 // ----------------------------------------------------------------------------
       
   656 // CCalenViewManager::CalenCommandHandlerExtensionL
       
   657 // Dummy implementation.
       
   658 // (other items were commented in a header).
       
   659 // ----------------------------------------------------------------------------
       
   660 //
       
   661 TAny* CCalenViewManager::CalenCommandHandlerExtensionL( TUid /*aExtensionUid*/ )
       
   662     {
       
   663     TRACE_ENTRY_POINT;
       
   664     TRACE_EXIT_POINT;
       
   665     return NULL;
       
   666     }
       
   667 
       
   668 // ----------------------------------------------------------------------------
       
   669 // CCalenViewManager::CurrentView
       
   670 // Returns the current view's view uid.
       
   671 // (other items were commented in a header).
       
   672 // ----------------------------------------------------------------------------
       
   673 //
       
   674 TUid CCalenViewManager::CurrentView() const
       
   675     {
       
   676     TRACE_ENTRY_POINT;
       
   677     TRACE_EXIT_POINT;
       
   678     return iCurrentViewId.iViewUid;
       
   679     }
       
   680 
       
   681 // ----------------------------------------------------------------------------
       
   682 // CCalenViewManager::HandleViewActivation
       
   683 // From MCoeViewActivationObserver
       
   684 // Called just before a view in this application is activated by the view server
       
   685 // (other items were commented in a header).
       
   686 // ----------------------------------------------------------------------------
       
   687 //
       
   688 void CCalenViewManager::HandleViewActivation( const TVwsViewId& aNewlyActivatedViewId,
       
   689                                              const TVwsViewId& aViewIdToBeDeactivated )
       
   690     {
       
   691     TRACE_ENTRY_POINT;
       
   692 
       
   693     TBool externalViewSwitch( EFalse );
       
   694     // See if this is an internal or external view switch request
       
   695     if( aViewIdToBeDeactivated.iAppUid != KUidCalendar )
       
   696         {
       
   697         externalViewSwitch = ETrue;
       
   698         }
       
   699 
       
   700     // If this is an internal view switch (view cycling from the '*' key)
       
   701     // then ActivateLocalViewL will handle any necessary state changes.
       
   702     // If this is an external view switch then we need to find out if Calendar was already
       
   703     // running or if it is being launched to a specific view by another application
       
   704     // calling ActivateViewL with Calendars UID and the UID of one of the standard views.
       
   705     // In this case we need to set the current view in the state or we would get the
       
   706     // default view (from the settings) activated instead of the requested view.
       
   707     if( externalViewSwitch )
       
   708         {
       
   709         // Check that the view being activated belongs to Calendar.  Although I don't see
       
   710         // how this would be called if this was false anyway.
       
   711         if( aNewlyActivatedViewId.iAppUid == KUidCalendar )
       
   712             {
       
   713             // Make sure that any when any open dialogs are closed Calendar will not close as well.
       
   714             // This could be true if Calendar was originally launched directly to the editor, and
       
   715             // so should be closed when the dialog is closed.  If an external view switch request
       
   716             // arrives, we want the dialog to close but Calendar to remain open.
       
   717             // Otherwise we get a CONE 44 panic.
       
   718             //iIsExitOnDlgClose = EFalse;
       
   719 
       
   720             iCurrentViewId = aNewlyActivatedViewId;
       
   721             }
       
   722         }
       
   723 
       
   724     iViewsActivated = ETrue;
       
   725     
       
   726     // check for iAvoidRepopulation to avoid repopulation whenever
       
   727     // 1) Application comes to foreground
       
   728     // 2) Applictaion is opened after fake exit
       
   729     if(!iAvoidRepopulation || iController.IsLaunchFromExternalApp() )
       
   730         {
       
   731         TRAPD(error,StartActiveStepL());
       
   732         if(error!=KErrNone)
       
   733             {
       
   734             // do avoid warning
       
   735             }
       
   736         }
       
   737     
       
   738     // Reset the flag iAvoidRepopulation
       
   739     if (iAvoidRepopulation)
       
   740         {
       
   741         iAvoidRepopulation = EFalse;
       
   742         }
       
   743     TRACE_EXIT_POINT;
       
   744     }
       
   745 
       
   746 // ----------------------------------------------------------------------------
       
   747 // CCalenViewManager::RemoveDeActivatedView
       
   748 // Asyncronous callback function to remove the current view after it has been 
       
   749 // disabled.
       
   750 // (other items were commented in a header).
       
   751 // ----------------------------------------------------------------------------
       
   752 //
       
   753 TInt CCalenViewManager::RemoveDeActivatedView( TAny* aObject )
       
   754     {
       
   755     TRACE_ENTRY_POINT;
       
   756     
       
   757     CCalenViewManager* thisPtr( static_cast<CCalenViewManager*>( aObject ) );
       
   758     TRAP_IGNORE( thisPtr->RemoveDeActivatedViewL() );
       
   759     
       
   760     TRACE_EXIT_POINT;
       
   761     return 0;
       
   762     }
       
   763  
       
   764 // ----------------------------------------------------------------------------
       
   765 // CCalenViewManager::RemoveDeActivatedViewL.
       
   766 // (Leaving version)
       
   767 // Asyncronous callback function to remove the current view after it has been 
       
   768 // disabled.
       
   769 // (other items were commented in a header).
       
   770 // ----------------------------------------------------------------------------
       
   771 //   
       
   772 void CCalenViewManager::RemoveDeActivatedViewL()
       
   773     {
       
   774     TRACE_ENTRY_POINT;
       
   775     
       
   776     TUid removedViewUid = iRemovedActiveView->ViewUid();
       
   777     TUid removedPluginUid = iRemovedActiveView->PluginUid();
       
   778     
       
   779     // The view isn't the current view, so we
       
   780     // can remove it directly from the view server
       
   781     iAppUi.RemoveView( removedViewUid );
       
   782 
       
   783     // Delete the view info
       
   784     delete iRemovedActiveView;;
       
   785     iRemovedActiveView = NULL;
       
   786     
       
   787     // Unload the plugin.
       
   788     RArray<TUid> pluginArray;
       
   789     CleanupClosePushL( pluginArray );
       
   790     
       
   791     pluginArray.AppendL( removedPluginUid );
       
   792     iCustomisationManager->UnloadPluginsL( pluginArray );
       
   793     CleanupStack::PopAndDestroy(); // pluginArray
       
   794     
       
   795     if(!iController.IsFasterAppFlagEnabled())
       
   796         {
       
   797         // Refresh the current view by simulating a settings close
       
   798         iController.BroadcastNotification( ECalenNotifySettingsClosed );
       
   799         }
       
   800     else
       
   801         {
       
   802         iController.BroadcastNotification( ECalenNotifyCheckPluginUnloading );
       
   803         }
       
   804 
       
   805     TRACE_EXIT_POINT;
       
   806     }
       
   807 
       
   808 // ----------------------------------------------------------------------------
       
   809 // CCalenViewManager::CycleNextViewL
       
   810 // Requests activation for the next view in the view cycle
       
   811 // (other items were commented in a header).
       
   812 // ----------------------------------------------------------------------------
       
   813 //
       
   814 void CCalenViewManager::CycleNextViewL()
       
   815     {
       
   816     TRACE_ENTRY_POINT;
       
   817 
       
   818     // Increment until we get to a valid view.
       
   819     do{
       
   820         ++iViewCycleIndex;
       
   821 
       
   822         if( iViewCycleIndex >= iViewInfoArray.Count() )
       
   823             {
       
   824             iViewCycleIndex = 0;
       
   825             }
       
   826         }
       
   827     while( iViewInfoArray[iViewCycleIndex]->CyclePosition() == CCalenView::ENoCyclePosition );
       
   828 
       
   829     RequestActivationL( iViewInfoArray[iViewCycleIndex]->ViewUid() );
       
   830 
       
   831     TRACE_EXIT_POINT;
       
   832     }
       
   833 
       
   834 // ----------------------------------------------------------------------------
       
   835 // CCalenViewManager::CyclePrevViewL
       
   836 // Requests activation for the previous view in the view cycle
       
   837 // (other items were commented in a header).
       
   838 // ----------------------------------------------------------------------------
       
   839 //
       
   840 void CCalenViewManager::CyclePrevViewL()
       
   841     {
       
   842     TRACE_ENTRY_POINT;
       
   843 
       
   844     // Decrement until we get to a valid view.
       
   845     do{
       
   846         --iViewCycleIndex;
       
   847 
       
   848         if( iViewCycleIndex < 0 )
       
   849             {
       
   850             iViewCycleIndex = iViewInfoArray.Count()-1;
       
   851             }
       
   852         }
       
   853     while ( iViewInfoArray[iViewCycleIndex]->CyclePosition() == CCalenView::ENoCyclePosition );
       
   854 
       
   855     RequestActivationL( iViewInfoArray[iViewCycleIndex]->ViewUid() );
       
   856 
       
   857     TRACE_EXIT_POINT;
       
   858     }
       
   859 
       
   860 // ----------------------------------------------------------------------------
       
   861 // CCalenViewManager::RequestActivationL
       
   862 // Request activation of a specific view.
       
   863 // (other items were commented in a header).
       
   864 // ----------------------------------------------------------------------------
       
   865 //
       
   866 void CCalenViewManager::RequestActivationL( const TVwsViewId& aViewId )
       
   867     {
       
   868     TRACE_ENTRY_POINT;
       
   869     
       
   870     RequestActivationL( aViewId.iViewUid );
       
   871 
       
   872     TRACE_EXIT_POINT;
       
   873     }
       
   874 
       
   875 // ----------------------------------------------------------------------------
       
   876 // CCalenViewManager::RequestActivationL
       
   877 // Call this to try to activate a view
       
   878 // (other items were commented in a header).
       
   879 // ----------------------------------------------------------------------------
       
   880 //
       
   881 void CCalenViewManager::RequestActivationL( const TUid& aViewUid,
       
   882                                             const TUid& aMessageId,
       
   883                                             const TDesC8& aMessage )
       
   884     {
       
   885     TRACE_ENTRY_POINT;
       
   886 
       
   887     // Cancel population of current view, if it's ongoing.
       
   888     iPopulator->InterruptPopulationL();
       
   889     // We start population of the newly activated view in HandleViewActivationL.
       
   890     
       
   891     // cache the previousviewid as we are getting aViewUid as reference.
       
   892     TUid cachePreviousViewId = iCurrentViewId.iViewUid;
       
   893     
       
   894     iCurrentViewId.iViewUid = aViewUid;
       
   895     // Update the view cycle index as iViewInfoArray would have changed
       
   896 	iViewCycleIndex = iViewInfoArray.Find( iCurrentViewId.iViewUid, 
       
   897                                             CCalenViewInfo::ViewInfoIdentifier );
       
   898     
       
   899 	if( iController.IsFasterAppFlagEnabled() )
       
   900 		{
       
   901 	    // Leave the application in background
       
   902 	    iAppUi.HideInBackground();
       
   903 	    // Disable bring-to-foreground on view activation
       
   904 		iAppUi.SetCustomControl(1); 
       
   905 		
       
   906 		// activate the view
       
   907 		iAppUi.ActivateLocalViewL( aViewUid, KCalenHideInBackGround, KNullDesC8() );
       
   908 	
       
   909 		// Enable bring-to-foreground on view activation.
       
   910 		iAppUi.SetCustomControl(0);  
       
   911 		}
       
   912 	else
       
   913 		{
       
   914 		iAppUi.ActivateLocalViewL( aViewUid, aMessageId, aMessage );
       
   915 		}
       
   916 	
       
   917 	// set the previous view id
       
   918 	if(cachePreviousViewId != KUidCalenEventView) 
       
   919 	    {
       
   920         iPreviousViewId.iViewUid = cachePreviousViewId; 
       
   921 	    }	
       
   922 	TRACE_EXIT_POINT;
       
   923     }
       
   924 
       
   925 // ----------------------------------------------------------------------------
       
   926 // CCalenViewManager::StartActiveStepL
       
   927 // Starts population of the current view.
       
   928 // ----------------------------------------------------------------------------
       
   929 //
       
   930 void CCalenViewManager::StartActiveStepL()
       
   931     {
       
   932     TRACE_ENTRY_POINT;
       
   933     
       
   934     // check for current viewid
       
   935     // populate the view only if iCurrentViewId is set
       
   936     if(iCurrentViewId.iViewUid != KNullUid)
       
   937         {
       
   938         iPopulator->InterruptPopulationL();
       
   939         iPopulator->BeginPopulationL(reinterpret_cast<CCalenView*>(iAppUi.View(CurrentView())));
       
   940         }
       
   941 
       
   942     TRACE_EXIT_POINT;
       
   943     }
       
   944 
       
   945 // ----------------------------------------------------------------------------
       
   946 // CCalenViewManager::ShowSwitchViewQueryL
       
   947 // Prompts the user to chose a view to switch to. If cancelled, returns
       
   948 // KErrCancel, otherwise one of ECalen*view.
       
   949 // (other items were commented in a header).
       
   950 // ----------------------------------------------------------------------------
       
   951 //
       
   952 void CCalenViewManager::ShowSwitchViewQueryL()
       
   953     {
       
   954     TRACE_ENTRY_POINT;
       
   955 
       
   956     // Create list of view names and uids
       
   957     CDesCArrayFlat* viewNames = new( ELeave ) CDesCArrayFlat( KArrayGranularity );
       
   958     CleanupStack::PushL( viewNames );
       
   959 
       
   960     RArray<TUid> viewUids;
       
   961     CleanupClosePushL( viewUids );
       
   962 											
       
   963 	const RArray<TUid>& activePlugins = CustomisationManager().ActivePlugins();											
       
   964 											
       
   965     for( TInt index( 0 ); index < iViewInfoArray.Count(); ++index )
       
   966         {
       
   967         CCalenViewInfo& viewInfo = *( iViewInfoArray[index] );
       
   968         if( index != iViewCycleIndex )
       
   969             {
       
   970             TUid pluginUid = viewInfo.PluginUid();
       
   971             TInt position = activePlugins.Find( pluginUid );
       
   972 	        	
       
   973             // If the view is from plugin or native view with cycle position,
       
   974             // then add it to the switch view list
       
   975             if(( position != KErrNotFound ) ||
       
   976                  ( viewInfo.CyclePosition() != CCalenView::ENoCyclePosition ))
       
   977                 {
       
   978                 // Fetch the view name
       
   979                 TUid viewUid = viewInfo.ViewUid();
       
   980                 const TDesC& viewName = viewInfo.MenuName();
       
   981                 viewNames->AppendL( viewName );
       
   982                 viewUids.AppendL(viewUid );      
       
   983                 }
       
   984             }
       
   985         }
   152         
   986         
   153         mController.MainWindow().addView(mCalenMonthView);
   987     // Show list query.
   154         mController.MainWindow().setCurrentView(mCalenMonthView);
   988     TInt choice = KErrCancel; //KErrNotFound;
   155     }
   989     CAknListQueryDialog* dlg = new( ELeave ) CAknListQueryDialog( &choice );
   156     
   990     dlg->PrepareLC( R_CALENDAR_SWITCH_VIEW_QUERY ); // pushes dlg to CS
   157 
   991     dlg->SetItemTextArray( viewNames );
   158     OstTraceFunctionExit0( CALENVIEWMANAGER_SECONDPHASECONSTRUCTION_EXIT );
   992     dlg->SetOwnershipType( ELbmDoesNotOwnItemArray );
   159 }
   993 
   160 
   994     // Set title
   161 // ----------------------------------------------------------------------------
   995     CAknPopupHeadingPane* heading = dlg->Heading();
   162 // CalenViewManager::~CalenViewManager
   996     HBufC* title = NULL;
   163 // Destructor.
   997     title = CCoeEnv::Static()->AllocReadResourceLC( R_CALENDAR_SWITCH_VIEW_QUERY_TITLE );
   164 // (other items were commented in a header).
   998     heading->SetTextL( *title );
   165 // ----------------------------------------------------------------------------
   999     CleanupStack::PopAndDestroy( title );
   166 //
  1000 
   167 CalenViewManager::~CalenViewManager()
  1001     if( dlg->RunLD() )
   168 {
  1002         {
   169     OstTraceFunctionEntry0( DUP1_CALENVIEWMANAGER_CALENVIEWMANAGER_ENTRY );
  1003         // user made a choice
   170     
  1004         TUid viewUid = viewUids[choice];
   171 	if (mSettingsView) {
  1005         RequestActivationL( viewUid );
   172 		delete mSettingsView;
  1006         }
   173 		mSettingsView = 0;
  1007 
   174 	}
  1008     CleanupStack::PopAndDestroy(); // viewUids
   175 	if (mAgendaViewDocLoader) {
  1009     CleanupStack::PopAndDestroy( viewNames );
   176 		delete mAgendaViewDocLoader;
  1010 
   177 		mAgendaViewDocLoader = 0;
  1011     TRACE_EXIT_POINT;
   178 	}
  1012     }
   179 	if (mAgendaViewAltDocLoader) {
  1013     
   180 		delete mAgendaViewAltDocLoader;
  1014 // ----------------------------------------------------------------------------
   181 		mAgendaViewAltDocLoader = 0;
  1015 // CCalenViewManager::HandleNotification
   182 	}
  1016 // Calls back when notifications that it has been registered for are broadcast
   183 	if (mMonthViewDocLoader) {
  1017 // (other items were commented in a header).
   184 		delete mMonthViewDocLoader;
  1018 // ----------------------------------------------------------------------------
   185 		mMonthViewDocLoader = 0;
  1019 //
   186 	}
  1020 void CCalenViewManager::HandleNotification(const TCalenNotification aNotification )
   187 	
  1021     {
   188 	OstTraceFunctionExit0( DUP1_CALENVIEWMANAGER_CALENVIEWMANAGER_EXIT );
  1022     TRACE_ENTRY_POINT;
   189 }
  1023     
   190 
  1024     PIM_TRAPD_HANDLE( HandleNotificationL( aNotification ) );
   191 // ----------------------------------------------------------------------------
  1025   
   192 // CalenViewManager::constructAndActivateView
  1026     TRACE_EXIT_POINT;
   193 // Constructs and activates the requested view
  1027     }
   194 // (other items were commented in a header).
  1028     
   195 // ----------------------------------------------------------------------------
  1029 // ----------------------------------------------------------------------------
   196 //
  1030 // CCalenViewManager::HandleNotificationL
   197 void CalenViewManager::constructAndActivateView(int view)
  1031 // Called from HandleNotification() when notifications that it has been
   198 {
  1032 //  registered for are broadcast
   199 	OstTraceFunctionEntry0( CALENVIEWMANAGER_CONSTRUCTANDACTIVATEVIEW_ENTRY );
  1033 // (other items were commented in a header).
   200 	
  1034 // ----------------------------------------------------------------------------
   201     // We are here because, some other application is launching calendar with 
  1035 //
   202 	// the view, hence connect to viewReady() signal to do any lazy loading
  1036 void CCalenViewManager::HandleNotificationL( TCalenNotification aNotification )
   203 	// in the slot
  1037     {
   204 	
  1038     TRACE_ENTRY_POINT;
   205 	// Connect to the view ready signal so that we construct other view 
  1039     
   206 	// once this view is shown
  1040     switch( aNotification )
   207 	connect(&mController.MainWindow(), SIGNAL(viewReady()), 
  1041         {
   208 					this, SLOT(handleMainViewReady()));
  1042         case ECalenNotifyPluginEnabledDisabled:
   209 	if (view == ECalenMonthView) {
  1043             {
   210 		mFirstView = ECalenMonthView;
  1044             UpdatePluginListL();
   211 		loadMonthView();
  1045             }
   212 		ActivateDefaultViewL(ECalenMonthView);
  1046             break;
   213 		// Add month view to mainwindow.
  1047         case ECalenNotifySettingsClosed:
   214 		mController.MainWindow().addView(mCalenMonthView);
  1048             {
   215 		mController.MainWindow().setCurrentView(mCalenMonthView);
  1049             // Nothing has changed, refresh statuspane only.
   216 	} else if (view == ECalenAgendaView) {
  1050             iAppUi.StatusPane()->DrawNow();
   217 		mFirstView = ECalenAgendaView;
  1051             }
   218 		loadAgendaView();
  1052             break;
   219 		ActivateDefaultViewL(ECalenAgendaView);
  1053         case ECalenNotifySettingsChanged:
   220 		// Add agenda view to mainwindow.
  1054             {
   221 		mController.MainWindow().addView(mCalenAgendaView);
  1055             HandleSettingsChangeNotificationL();
   222 		mController.MainWindow().setCurrentView(mCalenAgendaView);
  1056             }
   223 		mController.MainWindow().addView(mCalenAgendaViewAlt);
  1057             break;       
   224 	}
  1058         case ECalenNotifyEntryDeleted:
   225 	OstTraceFunctionExit0( CALENVIEWMANAGER_CONSTRUCTANDACTIVATEVIEW_EXIT );
  1059         case ECalenNotifyInstanceDeleted:    
   226 }
  1060 			{
   227 
  1061 			HandleEntryDeleteNotificationL();
   228 // ----------------------------------------------------------------------------
       
   229 // CalenViewManager::loadMonthView
       
   230 // Loads month view frm the docml
       
   231 // (other items were commented in a header).
       
   232 // ----------------------------------------------------------------------------
       
   233 //
       
   234 void CalenViewManager::loadMonthView()
       
   235 {
       
   236     OstTraceFunctionEntry0( CALENVIEWMANAGER_LOADMONTHVIEW_ENTRY );
       
   237     
       
   238 	bool loadSuccess = false;
       
   239 	Qt::Orientation currentOrienation = mController.MainWindow().orientation();
       
   240 	// Create the month view docloader object.
       
   241 	mMonthViewDocLoader = new CalenDocLoader(mController);
       
   242 	mMonthViewDocLoader->load(CALEN_MONTHVIEW_XML_FILE, &loadSuccess);
       
   243 	Q_ASSERT_X(loadSuccess, "calenviewmanager.cpp", 
       
   244 											"Unable to load month view XML");
       
   245 	// Based on the current orientation, load the appropriate section
       
   246 	if (Qt::Vertical == currentOrienation) {
       
   247 		mMonthViewDocLoader->load(CALEN_MONTHVIEW_XML_FILE, 
       
   248 											CALEN_PORTRAIT, &loadSuccess);
       
   249 		} else {
       
   250 			mMonthViewDocLoader->load(CALEN_MONTHVIEW_XML_FILE, 
       
   251 											CALEN_LANDSCAPE, &loadSuccess);
       
   252 		}
       
   253 	Q_ASSERT_X(loadSuccess, "calenviewmanager.cpp", "Unable to load XML");
       
   254 	
       
   255 	// Get the calenmonth view from the loader.
       
   256 	mCalenMonthView = static_cast<CalenMonthView *> 
       
   257 							(mMonthViewDocLoader->findWidget(CALEN_MONTHVIEW));
       
   258 	Q_ASSERT_X(mCalenMonthView, "calenviewmanager.cpp", 
       
   259 											"Unable to load calenMonth view");
       
   260 	
       
   261 	// Set the parent to delete the view once will exit the application
       
   262 	mCalenMonthView->setParent(this);
       
   263 	
       
   264 	// Setup the month view.
       
   265 	mCalenMonthView->setupView(mMonthViewDocLoader);
       
   266 	
       
   267 	OstTraceFunctionExit0( CALENVIEWMANAGER_LOADMONTHVIEW_EXIT );
       
   268 }
       
   269 
       
   270 // ----------------------------------------------------------------------------
       
   271 // CalenViewManager::loadAgendaView
       
   272 // Loads the agenda view frm the docml
       
   273 // (other items were commented in a header).
       
   274 // ----------------------------------------------------------------------------
       
   275 //
       
   276 void CalenViewManager::loadAgendaView()
       
   277 {
       
   278     OstTraceFunctionEntry0( CALENVIEWMANAGER_LOADAGENDAVIEW_ENTRY );
       
   279     
       
   280 	bool loadSuccess = false;
       
   281 	// Create the agenda view docloader object.
       
   282 	mAgendaViewDocLoader = new CalenDocLoader(mController);
       
   283 	
       
   284 	// Load default section
       
   285 	mAgendaViewDocLoader->load(CALEN_AGENDAVIEW_XML_FILE, &loadSuccess);
       
   286 	if (!loadSuccess) {
       
   287 		qFatal("calenviewmanager.cpp : Unable to load XML");
       
   288 	}
       
   289 	
       
   290 	// Get the calenagenda view from the loader
       
   291 	mCalenAgendaView = static_cast<CalenAgendaView *> (mAgendaViewDocLoader->findWidget(CALEN_AGENDAVIEW));
       
   292 	if (!mCalenAgendaView) {
       
   293 		qFatal("calenviewmanager.cpp : Unable to find agenda view");
       
   294 	}
       
   295 	
       
   296 	// Set the parent to delete the view once will exit the application
       
   297 	mCalenAgendaView->setParent(this);
       
   298 	
       
   299 	// Setup the agenda view
       
   300 	mCalenAgendaView->setupView(mAgendaViewDocLoader);
       
   301 	
       
   302 	// The following code is done to provide swipe support
       
   303 	// in agenda view. Idea is to create two views and keep
       
   304 	// switiching between these two using view switch effects
       
   305 	// to provide an illusion of flow to the user
       
   306 	loadAlternateAgendaView();
       
   307 	
       
   308 	OstTraceFunctionExit0( CALENVIEWMANAGER_LOADAGENDAVIEW_EXIT );
       
   309 }
       
   310 
       
   311 // ----------------------------------------------------------------------------
       
   312 // CalenViewManager::loadDayView
       
   313 // Loads day view from the docml
       
   314 // ----------------------------------------------------------------------------
       
   315 void CalenViewManager::loadDayView()
       
   316 {
       
   317     bool loadSuccess = false;
       
   318     
       
   319     // Create the docloader object
       
   320     CalenDocLoader *docLoader = new CalenDocLoader(mController);
       
   321     
       
   322     if (docLoader) {
       
   323         docLoader->load(CALEN_DAYVIEW_DOCML, &loadSuccess);
       
   324         if (!loadSuccess) {
       
   325             qFatal("calenviewmanager.cpp : Unable to load day view XML");
       
   326         }
       
   327         
       
   328         // Get the CalenDayView object from the loader
       
   329         mCalenDayView = static_cast<CalenDayView *>
       
   330             (docLoader->findWidget(CALEN_DAYVIEW));
       
   331         if (!mCalenDayView) {
       
   332             qFatal("calenviewmanager.cpp : Unable to find day view");
       
   333         }
       
   334         
       
   335         // Set the parent to delete the view once will exit the application
       
   336         mCalenDayView->setParent(this);
       
   337         
       
   338         // Set up the day view - day view takes the ownership
       
   339         mCalenDayView->setupView(docLoader);
       
   340     }
       
   341 }
       
   342 
       
   343 // ----------------------------------------------------------------------------
       
   344 // CalenViewManager::handleMainViewReady
       
   345 // Slot to handle viewReady() signal from mainwindow
       
   346 // (other items were commented in a header).
       
   347 // ----------------------------------------------------------------------------
       
   348 //
       
   349 void CalenViewManager::handleMainViewReady()
       
   350 {
       
   351     OstTraceFunctionEntry0( CALENVIEWMANAGER_HANDLEMAINVIEWREADY_ENTRY );
       
   352     
       
   353 	// Construct the month view part that is kept for lazy loading
       
   354     if (mCalenMonthView) {
       
   355 		mCalenMonthView->doLazyLoading();
       
   356 
       
   357 		if (mInstanceViewCreated) {
       
   358 			// populate entries for the month view if the month view is launched 
       
   359 			// from the service APIs. Otherwise the month view is not populated with 
       
   360 			// the entries as CalenViewManager::handleInstanceViewCreation is called 
       
   361 			// before the month view creation so the model array is not populated.
       
   362 			mCalenMonthView->fetchEntriesAndUpdateModel();
       
   363 		}
       
   364 
       
   365 	}
       
   366 	
       
   367 	// Construct other views
       
   368 	constructOtherViews();
       
   369 	
       
   370     // Install the event filter for the controller once the view is ready
       
   371     // so that system language/locale changes can be handled
       
   372 	//hbInstance->allMainWindows().first()->installEventFilter(&mController);
       
   373 	
       
   374 	// disconnect the view ready signal as we dont need it anymore
       
   375 	disconnect(&mController.MainWindow(), SIGNAL(viewReady()), 
       
   376 			   this, SLOT(handleMainViewReady()));
       
   377 	
       
   378 	OstTraceFunctionExit0( CALENVIEWMANAGER_HANDLEMAINVIEWREADY_EXIT );
       
   379 }
       
   380 
       
   381 // ----------------------------------------------------------------------------
       
   382 // CalenViewManager::constructOtherViews
       
   383 // Constructs the other views apart frm firstview and adds them to main window
       
   384 // (other items were commented in a header).
       
   385 // ----------------------------------------------------------------------------
       
   386 //
       
   387 void CalenViewManager::constructOtherViews()
       
   388 {
       
   389     OstTraceFunctionEntry0( CALENVIEWMANAGER_CONSTRUCTOTHERVIEWS_ENTRY );
       
   390     
       
   391 	// Load all other views except mFirstView
       
   392 	
       
   393 	// NOTE: Right now, since Calendar has only two views, month view 
       
   394 	// and agenda view, when client launches agenda view, then there is no need
       
   395 	// to construct the month view as per UI REQ., but tomorrow if new views
       
   396 	// come after agenda view, then we need to construct those views if they are
       
   397 	// native views. Right now, there is a event viewer but its not a native
       
   398 	// view. Hence, if agenda view is launched, dont construct month view
       
   399 	if (mFirstView != ECalenAgendaView) // check if agenda view is not already loaded
       
   400 		{
       
   401 		// Load all other views 
       
   402 		loadAgendaView();
       
   403 		
       
   404 		if (!mCalenDayView) {
       
   405 		    loadDayView();
       
   406 		}
       
   407 	}
       
   408 	else //agenda view was launched as first view
       
   409 	    {
       
   410 		// No implementation yet. UI specs not clear
       
   411 		// to be commented in with some more code once UI specs is frozen
       
   412 		// for agenda view launching as first view after it was saved as activity
       
   413 		// when it was launched from month view
       
   414         // loadMonthView();
       
   415         // mCalenMonthView->doLazyLoading();
       
   416 	    }
       
   417 
       
   418 	// Setup the settings view
       
   419 	mSettingsView = new CalenSettingsView(mController.Services());
       
   420 	
       
   421 	OstTraceFunctionExit0( CALENVIEWMANAGER_CONSTRUCTOTHERVIEWS_EXIT );
       
   422 }
       
   423 
       
   424 // ----------------------------------------------------------------------------
       
   425 // CalenViewManager::getFirstView
       
   426 // Returns the first view
       
   427 // (other items were commented in a header).
       
   428 // ----------------------------------------------------------------------------
       
   429 //
       
   430 int CalenViewManager::getFirstView()
       
   431 {
       
   432     OstTraceFunctionEntry0( CALENVIEWMANAGER_GETFIRSTVIEW_ENTRY );
       
   433     
       
   434 	OstTraceFunctionExit0( CALENVIEWMANAGER_GETFIRSTVIEW_EXIT );
       
   435 	return mFirstView;
       
   436 }
       
   437 
       
   438 // ----------------------------------------------------------------------------
       
   439 // CalenViewManager::showNextDay
       
   440 // other items were commented in a header
       
   441 // ----------------------------------------------------------------------------
       
   442 //
       
   443 void CalenViewManager::showNextDay()
       
   444 {
       
   445     OstTraceFunctionEntry0( CALENVIEWMANAGER_SHOWNEXTDAY_ENTRY );
       
   446     
       
   447     // Set the context for the next day
       
   448     QDateTime currentDay = mController.Services().Context().focusDateAndTime();
       
   449     currentDay = currentDay.addDays(1);
       
   450     mController.Services().Context().setFocusDate(currentDay);
       
   451     mCurrentViewId = ECalenAgendaView;
       
   452     // Check which is the currently activated view
       
   453     if (mController.MainWindow().currentView() == mCalenAgendaView) {
       
   454         mCalenAgendaView->disconnectAboutToQuitEvent(); // disconnect mCalenAgendaView to get aboutToQuit Events
       
   455         HbEffect::add(mCalenAgendaView,
       
   456                       ":/fxml/view_hide",
       
   457                       "hide");
       
   458         HbEffect::add(mCalenAgendaViewAlt,
       
   459                       ":/fxml/view_show",
       
   460                       "show");
       
   461         // Set the other agenda view as the current view
       
   462         // and animate to provide illusion of swipe
       
   463 		// It would also connect for aboutToQuit events
       
   464         mCalenAgendaViewAlt->doPopulation();
       
   465         mController.MainWindow().setCurrentView(mCalenAgendaViewAlt, true, Hb::ViewSwitchUseNormalAnim);
       
   466     } else {
       
   467     mCalenAgendaViewAlt->disconnectAboutToQuitEvent(); // disconnect mCalenAgendaViewAlt to get aboutToQuit Events
       
   468         HbEffect::add(mCalenAgendaViewAlt,
       
   469                       ":/fxml/view_hide",
       
   470                       "hide");
       
   471         HbEffect::add(mCalenAgendaView,
       
   472                       ":/fxml/view_show",
       
   473                       "show");
       
   474 		// It would also connect for aboutToQuit events
       
   475         mCalenAgendaView->doPopulation();
       
   476         mController.MainWindow().setCurrentView(mCalenAgendaView, true, Hb::ViewSwitchUseNormalAnim);
       
   477     }
       
   478     OstTraceFunctionExit0( CALENVIEWMANAGER_SHOWNEXTDAY_EXIT );
       
   479 }
       
   480 
       
   481 // ----------------------------------------------------------------------------
       
   482 // CalenViewManager::showPrevDay
       
   483 // other items were commented in a header
       
   484 // ----------------------------------------------------------------------------
       
   485 //
       
   486 void CalenViewManager::showPrevDay()
       
   487 {
       
   488     OstTraceFunctionEntry0( CALENVIEWMANAGER_SHOWPREVDAY_ENTRY );
       
   489     
       
   490     QDateTime currentDay = mController.Services().Context().focusDateAndTime();
       
   491     currentDay = currentDay.addDays(-1);
       
   492     mController.Services().Context().setFocusDate(currentDay);
       
   493     mCurrentViewId = ECalenAgendaView;
       
   494     if (mController.MainWindow().currentView() == mCalenAgendaView) {
       
   495     mCalenAgendaView->disconnectAboutToQuitEvent(); // disconnect mCalenAgendaView to get aboutToQuit Events
       
   496         HbEffect::add(mCalenAgendaView,
       
   497                       ":/fxml/view_hide_back",
       
   498                       "hide");
       
   499         HbEffect::add(mCalenAgendaViewAlt,
       
   500                       ":/fxml/view_show_back",
       
   501                       "show");
       
   502 		// It would also connect for aboutToQuit events
       
   503         mCalenAgendaViewAlt->doPopulation();
       
   504         mController.MainWindow().setCurrentView(mCalenAgendaViewAlt, true, Hb::ViewSwitchUseNormalAnim);
       
   505     } else {
       
   506     mCalenAgendaViewAlt->disconnectAboutToQuitEvent(); // disconnect mCalenAgendaViewAlt to get aboutToQuit Events
       
   507         HbEffect::add(mCalenAgendaViewAlt,
       
   508                       ":/fxml/view_hide_back",
       
   509                       "hide");
       
   510         HbEffect::add(mCalenAgendaView,
       
   511                       ":/fxml/view_show_back",
       
   512                       "show");
       
   513 		// It would also connect for aboutToQuit events
       
   514         mCalenAgendaView->doPopulation();
       
   515         mController.MainWindow().setCurrentView(mCalenAgendaView, true, Hb::ViewSwitchUseNormalAnim);
       
   516     }
       
   517     
       
   518     OstTraceFunctionExit0( CALENVIEWMANAGER_SHOWPREVDAY_EXIT );
       
   519 }
       
   520 
       
   521 // ----------------------------------------------------------------------------
       
   522 // CalenViewManager::removePreviousView
       
   523 // Remove the previous view from main window
       
   524 // ----------------------------------------------------------------------------
       
   525 //
       
   526 void CalenViewManager::removePreviousView()
       
   527 {
       
   528     OstTraceFunctionEntry0( CALENVIEWMANAGER_REMOVEPREVIOUSVIEW_ENTRY );
       
   529     
       
   530 	if (ECalenAgendaView == mCurrentViewId) {
       
   531 		mCalenAgendaView->clearListModel();
       
   532 		mCalenAgendaViewAlt->clearListModel();
       
   533 		mController.MainWindow().removeView(mCalenAgendaView);
       
   534 		mController.MainWindow().removeView(mCalenAgendaViewAlt);
       
   535 	} else if (ECalenDayView == mCurrentViewId) {
       
   536 		mController.MainWindow().removeView(mCalenDayView);
       
   537 	} else {
       
   538 		if (ECalenMonthView == mCurrentViewId) {
       
   539 			mController.MainWindow().removeView(mCalenMonthView);
       
   540 		}
       
   541 	}
       
   542 
       
   543 	OstTraceFunctionExit0( CALENVIEWMANAGER_REMOVEPREVIOUSVIEW_EXIT );
       
   544 }
       
   545 
       
   546 // ----------------------------------------------------------------------------
       
   547 // CalenViewManager::~ActivateDefaultViewL
       
   548 //  Activates the default view, as retrieved from settings.
       
   549 // (other items were commented in a header).
       
   550 // ----------------------------------------------------------------------------
       
   551 //
       
   552 void CalenViewManager::ActivateDefaultViewL(int defaultView)
       
   553 {
       
   554     OstTraceFunctionEntry0( CALENVIEWMANAGER_ACTIVATEDEFAULTVIEWL_ENTRY );
       
   555     
       
   556 	mCurrentViewId = defaultView;
       
   557 	if (ECalenMonthView == defaultView) {
       
   558 		mCalenMonthView->doPopulation();
       
   559 	} else if (ECalenAgendaView == defaultView) {
       
   560 		mCalenAgendaView->doPopulation();
       
   561 	}
       
   562 	OstTraceFunctionExit0( CALENVIEWMANAGER_ACTIVATEDEFAULTVIEWL_EXIT );
       
   563 }
       
   564 
       
   565 // ----------------------------------------------------------------------------
       
   566 // Refresh current view.
       
   567 // (other items were commented in a header).
       
   568 // ----------------------------------------------------------------------------
       
   569 void CalenViewManager::refreshCurrentViewL()
       
   570 {
       
   571     OstTraceFunctionEntry0( CALENVIEWMANAGER_REFRESHCURRENTVIEWL_ENTRY );
       
   572     
       
   573 	activateCurrentView();
       
   574 	
       
   575 	OstTraceFunctionExit0( CALENVIEWMANAGER_REFRESHCURRENTVIEWL_EXIT );
       
   576 }
       
   577 
       
   578 // ----------------------------------------------------------------------------
       
   579 // Activate current view.
       
   580 // (other items were commented in a header).
       
   581 // ----------------------------------------------------------------------------
       
   582 void CalenViewManager::activateCurrentView()
       
   583 {
       
   584     OstTraceFunctionEntry0( CALENVIEWMANAGER_ACTIVATECURRENTVIEW_ENTRY );
       
   585     
       
   586 	switch (mCurrentViewId) {
       
   587 		case ECalenMonthView:
       
   588 		    mCalenMonthView->doPopulation();
       
   589 		    mController.MainWindow().setCurrentView(mCalenMonthView);
       
   590 			break;
       
   591 		case ECalenAgendaView:
       
   592 		    if (mController.MainWindow().currentView() == mCalenAgendaView) {
       
   593 		        // This happens when settings view or event viewer is opened
       
   594 		        // from the agenda view. Simply repopulate the view
       
   595 		    	if (mCalenAgendaView) {
       
   596 		    		mCalenAgendaView->doPopulation();
       
   597 					mController.MainWindow().setCurrentView(mCalenAgendaView);
       
   598 		    	} 
       
   599 		    } else if (mController.MainWindow().currentView() == mCalenAgendaViewAlt){
       
   600 		        // This happens when settings view or event viewer is opened
       
   601 		        // from the agenda view. Simply repopulate the view
       
   602 		    	if (mCalenAgendaViewAlt) {
       
   603 		    		mCalenAgendaViewAlt->doPopulation();
       
   604 		    		mController.MainWindow().setCurrentView(mCalenAgendaViewAlt);
       
   605 		    	}
       
   606 		    } else {
       
   607 		        // This is called whenever the agenda view is opened from the month
       
   608 		        // view. Since the agenda view is not added to the mainwindow,
       
   609 		        // add the agenda views to mainwindow and set any one of them as 
       
   610 		        // current view
       
   611 		    	if (mCalenAgendaView) {
       
   612 		    		mCalenAgendaView->doPopulation();
       
   613 		    		mController.MainWindow().addView(mCalenAgendaView);
       
   614 		    		mController.MainWindow().setCurrentView(mCalenAgendaView);
       
   615 		    		mController.MainWindow().addView(mCalenAgendaViewAlt);
       
   616 		    	}
       
   617 		    }
       
   618 			break;
       
   619 		case ECalenShowSettings:
       
   620 		    mSettingsView->refreshView();
       
   621 			break;
       
   622 		case ECalenDayView:
       
   623 			mCalenDayView->doPopulation();
       
   624 			mController.MainWindow().setCurrentView(mCalenDayView);
       
   625 			break;
       
   626 	}
       
   627 	
       
   628 	OstTraceFunctionExit0( CALENVIEWMANAGER_ACTIVATECURRENTVIEW_EXIT );
       
   629 }
       
   630 
       
   631 // ----------------------------------------------------------------------------
       
   632 // CalenViewManager::launchEventView
       
   633 // Launch event view.
       
   634 // (other items were commented in a header).
       
   635 // ----------------------------------------------------------------------------
       
   636 //
       
   637 void CalenViewManager::launchEventView()
       
   638 {
       
   639     OstTraceFunctionEntry0( CALENVIEWMANAGER_LAUNCHEVENTVIEW_ENTRY );
       
   640     
       
   641     // capture cureent view in case app closed/quits from AgendaEventViewer
       
   642     if (mCalenMonthView) {
       
   643     mCalenMonthView->captureScreenshot(true);
       
   644     }
       
   645     else if (mCalenAgendaView) {
       
   646     	mCalenAgendaView->captureScreenshot(true);
       
   647     }
       
   648 	MCalenContext& context = mController.Services().Context();
       
   649 	AgendaEntry viewEntry= mController.Services().agendaInterface()->fetchById(
       
   650 			context.instanceId().mEntryLocalUid );
       
   651 	if (viewEntry.isRepeating() 
       
   652 			&& viewEntry.type() != AgendaEntry::TypeTodo) {
       
   653 		QDateTime startDateTime = context.focusDateAndTime();
       
   654 		viewEntry.setStartAndEndTime(startDateTime, 
       
   655 		                     startDateTime.addSecs(viewEntry.durationInSecs()));
       
   656 	}
       
   657 	mCalenEventViewer = new AgendaEventViewer(
       
   658 			mController.Services().agendaInterface(), this);
       
   659 	connect(mCalenEventViewer, SIGNAL(viewingCompleted(const QDate)),
       
   660 	        this, SLOT(handleViewingCompleted(const QDate)));
       
   661 	connect(mCalenEventViewer, SIGNAL(editingStarted()),
       
   662 	        this, SLOT(handleEditingStarted()));
       
   663 	connect(mCalenEventViewer, SIGNAL(editingCompleted()),
       
   664 	        this, SLOT(handleEditingCompleted()));
       
   665 	connect(mCalenEventViewer, SIGNAL(deletingStarted()),
       
   666 		        this, SLOT(handleDeletingStarted()));
       
   667 	connect(mCalenEventViewer, SIGNAL(deletingCompleted()),
       
   668 			        this, SLOT(handleDeletingCompleted()));
       
   669 
       
   670 
       
   671 	// Launch agenda event viewer
       
   672 	mCalenEventViewer->view(viewEntry, AgendaEventViewer::ActionEditDelete);
       
   673 	OstTraceFunctionExit0( CALENVIEWMANAGER_LAUNCHEVENTVIEW_EXIT );
       
   674 }
       
   675 
       
   676 // ----------------------------------------------------------------------------
       
   677 // CalenViewManager::loadAlternateAgendaView
       
   678 // other items were commented in a header
       
   679 // ----------------------------------------------------------------------------
       
   680 //
       
   681 void CalenViewManager::loadAlternateAgendaView()
       
   682 {
       
   683     OstTraceFunctionEntry0( CALENVIEWMANAGER_LOADALTERNATEAGENDAVIEW_ENTRY );
       
   684     
       
   685     bool loadSuccess = false;
       
   686     // Create the agenda view docloader object.
       
   687     mAgendaViewAltDocLoader = new CalenDocLoader(mController);
       
   688 
       
   689     // Load default section
       
   690     mAgendaViewAltDocLoader->load(CALEN_AGENDAVIEW_XML_FILE, &loadSuccess);
       
   691     if (!loadSuccess) {
       
   692         qFatal("calenviewmanager.cpp : Unable to load XML");
       
   693     }
       
   694 
       
   695     // Get the calenagenda view from the loader
       
   696     mCalenAgendaViewAlt = static_cast<CalenAgendaView *> (mAgendaViewAltDocLoader->findWidget(CALEN_AGENDAVIEW));
       
   697     if (!mCalenAgendaViewAlt) {
       
   698         qFatal("calenviewmanager.cpp : Unable to find alternate agenda view");
       
   699     }
       
   700 
       
   701     // Set the parent to delete the view once will exit the application
       
   702     mCalenAgendaViewAlt->setParent(this);
       
   703     
       
   704     // Setup the agenda view
       
   705     mCalenAgendaViewAlt->setupView(mAgendaViewAltDocLoader);
       
   706     OstTraceFunctionExit0( CALENVIEWMANAGER_LOADALTERNATEAGENDAVIEW_EXIT );
       
   707 }
       
   708 
       
   709 // ----------------------------------------------------------------------------
       
   710 // CalenViewManager::HandleCommandL
       
   711 // Handles view manager commands.
       
   712 // @return ETrue if command is handled, EFalse otherwise
       
   713 // ----------------------------------------------------------------------------
       
   714 //
       
   715 TBool CalenViewManager::HandleCommandL(const TCalenCommand& command)
       
   716 {
       
   717     OstTraceFunctionEntry0( CALENVIEWMANAGER_HANDLECOMMANDL_ENTRY );
       
   718     
       
   719 	TBool commandUsed(EFalse);
       
   720 	
       
   721 	switch (command.Command()) {
       
   722 		case ECalenMonthView:
       
   723 			// First remove the previous native view before 
       
   724 			// we set the mCurrentViewId with the current view
       
   725 			removePreviousView();
       
   726 			// Add month view to mainwindow.
       
   727 			mController.MainWindow().addView(mCalenMonthView);
       
   728 			mCurrentViewId = ECalenMonthView;
       
   729 			activateCurrentView();
       
   730 			break;
       
   731 		case ECalenAgendaView:
       
   732 			// First remove the previous native view before 
       
   733 			// we set the mCurrentViewId with the current view
       
   734 			removePreviousView();
       
   735 			mCurrentViewId = ECalenAgendaView;
       
   736 			activateCurrentView();
       
   737 			break;
       
   738 		case ECalenDayView:
       
   739             {
       
   740             // First add new view
       
   741 			mController.MainWindow().addView(mCalenDayView);
       
   742 			
       
   743 			// Removes current view
       
   744 		    // Notice: removing view should be done after new view is set as current to
       
   745 		    // avoid situation that there is no current view in application
       
   746 		    removePreviousView();
       
   747     
       
   748 		    // Sets and activates day view
       
   749 		    mCurrentViewId = ECalenDayView;
       
   750 		    activateCurrentView();
       
   751 			}
  1062 			}
   752 			break;
  1063 			break;
   753 		case ECalenEventView:
  1064         case ECalenNotifySystemLocaleChanged:	
   754 			launchEventView();
  1065         case ECalenNotifyEntrySaved:
   755 			break;
  1066         case ECalenNotifyMultipleEntriesDeleted:
   756 		case ECalenStartActiveStep:
  1067         case ECalenNotifyExternalDatabaseChanged:
   757 			activateCurrentView();
  1068         case ECalenNotifyCancelDelete:
   758 			break;
  1069         case ECalenNotifyCalendarFieldChanged:
   759 		case ECalenShowNextDay:
  1070         case ECalenNotifyMarkedEntryCompleted:
   760 		    showNextDay();
  1071         case ECalenNotifyCalendarInfoCreated:
   761 		    break;
  1072         case ECalenNotifyCalendarInfoUpdated:
   762 		case ECalenShowPrevDay:
  1073             {
   763             showPrevDay();
  1074             StartActiveStepL();
   764 		    break;
  1075             }
       
  1076             break;
       
  1077         case ECalenNotifyCalendarFileDeleted:
       
  1078             {
       
  1079             if(iCurrentViewId.iViewUid==KUidCalenEventView)
       
  1080                 {
       
  1081                 //If the entry which is being viewed belongs to a calendar 
       
  1082                 //that is deleted we check for collection ids of entry and 
       
  1083                 //calendar session if they are same return to previous view
       
  1084                 TPtrC calFileName = iGlobalData->Context().GetCalendarFileNameL();
       
  1085                 TPtrC calFileNameForColId = 
       
  1086                         iGlobalData->GetCalFileNameForCollectionId(iGlobalData->Context().InstanceId().iColId);
       
  1087                 if(!calFileNameForColId.CompareF(calFileName))
       
  1088                     {
       
  1089                     ActivateDefaultViewL(iPreviousToDayView.iViewUid);
       
  1090                     }
       
  1091                 }
       
  1092             else
       
  1093                 {
       
  1094                 // refresh the current view
       
  1095                 StartActiveStepL();
       
  1096                 }
       
  1097             }
       
  1098             break;         
       
  1099         case ECalenNotifyEntryClosed:
       
  1100             {
       
  1101             HandleEntryClosedNotificationL();
       
  1102             }
       
  1103             break;
       
  1104         case ECalenNotifySystemTimeChanged:
       
  1105             {
       
  1106             HandleSystemTimeChangeNotificationL();
       
  1107             }
       
  1108             break;
       
  1109         case ECalenNotifyAppForegrounded:
       
  1110         	{
       
  1111         	// check for system time change whenever fake exit is done
       
  1112         	// or application comes to foreground
       
  1113             if(!iStartupComplete)
       
  1114                 {
       
  1115                 iController.CheckSystemTimeAtStartUpL();
       
  1116                 }
       
  1117         	
       
  1118             if( iController.IsFasterAppFlagEnabled() )
       
  1119 			    {
       
  1120 			    iAppUi.HideApplicationFromFSW(EFalse);
       
  1121 			    iController.SetFasterAppFlag( EFalse );
       
  1122 			    
       
  1123 			    ReloadAllPluginsL();
       
  1124 			    }
       
  1125             else
       
  1126                 {
       
  1127                 iAvoidRepopulation = EFalse;
       
  1128                 }
       
  1129         	}
       
  1130         	break;
       
  1131         case ECalenNotifyDayViewClosed:
       
  1132             {
       
  1133             if(iPreviousToDayView.iViewUid!= KNullUid)
       
  1134                 {
       
  1135                 // activate the previous view from where day view is launched
       
  1136                 // From month/week view -> day view
       
  1137                 RequestActivationL(iPreviousToDayView.iViewUid);
       
  1138                 }
       
  1139             }
       
  1140             break;
       
  1141         case ECalenNotifyWeekViewClosed:
       
  1142             {
       
  1143             if(iPreviousToWeekView.iViewUid!= KNullUid)
       
  1144                 {
       
  1145                 // activate the previous view from where day view is launched
       
  1146                 // From month/week view -> day view
       
  1147                 RequestActivationL(iPreviousToWeekView.iViewUid);
       
  1148                 }
       
  1149             }
       
  1150             break;
       
  1151         case ECalenNotifyAppBackgrounded:
       
  1152             {
       
  1153             // set the flag iAvoidRepopulation to prevent repopulation
       
  1154             // whenever application is brought to foreground
       
  1155             iAvoidRepopulation = ETrue;
       
  1156             
       
  1157             if( iController.IsFasterAppFlagEnabled() )
       
  1158                 {
       
  1159                 TRAP_IGNORE(iController.RemoveDeadCalendarsL());
       
  1160                 }
       
  1161             }
       
  1162             break;
       
  1163         case ECalenNotifyViewPopulationComplete:
       
  1164             {
       
  1165             if(iStartupComplete)
       
  1166                 {
       
  1167                 iController.CheckSystemTimeAtStartUpL();
       
  1168                 iStartupComplete = EFalse;
       
  1169                 }
       
  1170             break;
       
  1171             }
       
  1172         case ECalenNotifyAttachmentViewerClosed:
       
  1173         		{
       
  1174             if( iCurrentViewId.iViewUid==KUidCalenEventView)
       
  1175                 {
       
  1176                 StartActiveStepL();
       
  1177                 }
       
  1178             }            
       
  1179         case ECalenNotifyAttachmentRemoved:
       
  1180         case ECalenNotifyAttachmentAdded:    
       
  1181             {
       
  1182             if( iCurrentViewId.iViewUid==KUidCalenEventView && 
       
  1183                 !iAvoidRepopulation    )
       
  1184                 {
       
  1185                 StartActiveStepL();
       
  1186                 }
       
  1187             }
       
  1188         case ECalenNotifyDeleteFailed:
       
  1189         // Do nothing on deletion failed
       
  1190         default:
       
  1191             break; 
       
  1192         }
       
  1193 
       
  1194     TRACE_EXIT_POINT;
       
  1195     }
       
  1196     
       
  1197 // ----------------------------------------------------------------------------
       
  1198 // CCalenViewManager::UpdatePluginListL
       
  1199 // Discovers if a plugin has been enabled or disabled 
       
  1200 // (other items were commented in a header).
       
  1201 // ----------------------------------------------------------------------------
       
  1202 //
       
  1203 void CCalenViewManager::UpdatePluginListL()
       
  1204     {
       
  1205     TRACE_ENTRY_POINT;
       
  1206     
       
  1207     const RArray<TUid>& activePlugins = CustomisationManager().ActivePlugins();
       
  1208     
       
  1209     // Check for any new plugins
       
  1210     TInt activeCount = activePlugins.Count();
       
  1211     for( TInt index( 0 ); index < activeCount; ++index )
       
  1212         {
       
  1213         // For every active plugin, check to see if it is in the known list,
       
  1214         // if it isn't construct any custom views.
       
  1215         TUid pluginUid = activePlugins[index];
       
  1216         TInt position = iKnownPlugins.Find( pluginUid );
       
  1217         if( position == KErrNotFound )
       
  1218             {
       
  1219             ConstructCustomViewL( pluginUid );
       
  1220             }
       
  1221         }
       
  1222 
       
  1223     RArray<TUid> disabledPlugins;
       
  1224     CleanupClosePushL( disabledPlugins );
       
  1225         
       
  1226     // Check for any disabled plugins
       
  1227     TInt knownCount = iKnownPlugins.Count();
       
  1228     for( TInt index( knownCount - 1 ); index >= 0; --index )
       
  1229         {
       
  1230         // For every known plugin, check to see if it is in the active list,
       
  1231         // if it isn't add to the disable plugin list, and remove from the
       
  1232         // known list.
       
  1233         TUid pluginUid = iKnownPlugins[index];
       
  1234         TInt position = activePlugins.Find( pluginUid );
       
  1235         if ( position == KErrNotFound )
       
  1236             {
       
  1237             disabledPlugins.AppendL( pluginUid );
       
  1238             iKnownPlugins.Remove( index );
       
  1239             }
       
  1240         }
       
  1241     
       
  1242     TInt disabledPluginCount = disabledPlugins.Count();
       
  1243     if( disabledPluginCount != 0 )
       
  1244         {
       
  1245         RemoveDisabledPluginsViewsL( disabledPlugins );
       
  1246         // Re sort the view info array
       
  1247         iViewInfoArray.Sort(  CCalenViewInfo::CyclePositionComparison );
       
  1248         }
       
  1249     else
       
  1250         {      
       
  1251         // Update the view cycle index as iViewInfoArray would have changed
       
  1252         iViewCycleIndex = iViewInfoArray.Find( iCurrentViewId.iViewUid, CCalenViewInfo::ViewInfoIdentifier );       
       
  1253         }
       
  1254     UpdateToolbarNextViewIconL(iCurrentViewId.iViewUid);
       
  1255     
       
  1256     CleanupStack::PopAndDestroy(); // disabledPlugins
       
  1257     TRACE_EXIT_POINT;
       
  1258     } 
       
  1259     
       
  1260 // ----------------------------------------------------------------------------
       
  1261 // CCalenViewManager::RemoveDisabledPluginsViewsL
       
  1262 // Removes any custom views provided by disabled plugins
       
  1263 // from the view server.
       
  1264 // (other items were commented in a header).
       
  1265 // ----------------------------------------------------------------------------
       
  1266 //
       
  1267 void CCalenViewManager::RemoveDisabledPluginsViewsL( RArray<TUid>& aDisabledPlugins )
       
  1268     {
       
  1269     TRACE_ENTRY_POINT;
       
  1270 
       
  1271     // Find what views are provided by the disabled plugins
       
  1272     TInt disabledPluginCount = aDisabledPlugins.Count();
       
  1273     RArray<TUid> removedViews;
       
  1274     CleanupClosePushL( removedViews );
       
  1275     
       
  1276     TUid activeViewUid = CurrentView();
       
  1277     
       
  1278     for( TInt index( disabledPluginCount - 1 ); index >= 0; --index )
       
  1279         {
       
  1280         TUid pluginUid = aDisabledPlugins[index];
       
  1281         
       
  1282         // Does this plugin offer any views
       
  1283         TInt position = iViewInfoArray.Find( pluginUid, 
       
  1284                                              CCalenViewInfo::ViewPluginIdentifier );
       
  1285         TBool alreadySet = EFalse;
       
  1286         while( position != KErrNotFound )
       
  1287             {
       
  1288             CCalenViewInfo* view = iViewInfoArray[position];
       
  1289             TUid viewUid = view->ViewUid();
       
  1290             
       
  1291             // Remove from the view cycle list
       
  1292             iViewInfoArray.Remove( position );
       
  1293             
       
  1294             RArray<TInt> hiddenViews;
       
  1295             iCustomisationManager->GetHiddenViewIdL(pluginUid, hiddenViews);
       
  1296             
       
  1297             if( viewUid == activeViewUid )
       
  1298                 {
       
  1299                 // Removing the active view is done in three parts
       
  1300                 // 1) It is removed from the viewInfo list
       
  1301                 // 2) When settings is closed, the view is switched
       
  1302                 // to the next view in the view cycle list.
       
  1303                 // 3) When the view is deactivated it can be deleted.
       
  1304                 
       
  1305                 // Store the information about the current view.
       
  1306                 iRemovedActiveView = view;
       
  1307                 
       
  1308                 // Update the view cycle index so that hidden view is launched while cycling next view
       
  1309                 if(hiddenViews.Count())
       
  1310                     {
       
  1311                     // Find the index of teh hidden view
       
  1312                     TInt viewInfoIndex = iViewInfoArray.Find(TUid::Uid(hiddenViews[0]), CCalenViewInfo::ViewInfoIdentifier);
       
  1313                     iViewCycleIndex = viewInfoIndex - 1;  // Decrementing it as CycleNextView() funciton will increment it   
       
  1314                     }
       
  1315                 else if(!alreadySet)
       
  1316                     {
       
  1317                     TInt nextViewCycleIndex = iViewCycleIndex - 1; // To update the view cycle index in plugin disable case
       
  1318             
       
  1319                     // Update the view cycle index as iViewInfoArray would have changed
       
  1320                     iViewCycleIndex = iViewInfoArray.Find( iCurrentViewId.iViewUid, CCalenViewInfo::ViewInfoIdentifier ); 
       
  1321                     
       
  1322                     // If the current active view has been removed,
       
  1323                     if(iViewCycleIndex == -1)
       
  1324                         {
       
  1325                             iViewCycleIndex = nextViewCycleIndex;
       
  1326                         } 
       
  1327                     alreadySet = ETrue;
       
  1328                     }
       
  1329                 
       
  1330                 hiddenViews.Reset();
       
  1331                 // Remove the plugin from the disabled plugin list
       
  1332                 // to stop the plugin being deleted.
       
  1333                 aDisabledPlugins.Remove( index );
       
  1334                 }
       
  1335             else
       
  1336                 {
       
  1337                 // The view isn't the current view, so we
       
  1338                 // can remove it directly from the view server
       
  1339                 iAppUi.RemoveView( viewUid );
       
  1340 
       
  1341                 // Delete the view info
       
  1342                 delete view;
       
  1343                 if(!alreadySet)
       
  1344                     {
       
  1345 	                TInt nextViewCycleIndex = iViewCycleIndex - 1; // To update the view cycle index in plugin disable case
       
  1346                         
       
  1347 	                // Update the view cycle index as iViewInfoArray would have changed
       
  1348 	                iViewCycleIndex = iViewInfoArray.Find( iCurrentViewId.iViewUid, CCalenViewInfo::ViewInfoIdentifier ); 
       
  1349                 
       
  1350 	                // If the current active view has been removed,
       
  1351 	                if(iViewCycleIndex == -1)
       
  1352 	                    {
       
  1353 	                        iViewCycleIndex = nextViewCycleIndex;
       
  1354 	                    }
       
  1355 	                alreadySet = ETrue;
       
  1356                     }
       
  1357                
       
  1358                 }
       
  1359                 
       
  1360             position = iViewInfoArray.Find( pluginUid, 
       
  1361                                         CCalenViewInfo::ViewPluginIdentifier );
       
  1362             }
       
  1363         }
       
  1364         
       
  1365     // Unload the disabled plugins
       
  1366     iCustomisationManager->UnloadPluginsL( aDisabledPlugins );
       
  1367         
       
  1368     CleanupStack::PopAndDestroy(); // removedViews
       
  1369     
       
  1370     TRACE_EXIT_POINT;
       
  1371     }
       
  1372     
       
  1373 // ----------------------------------------------------------------------------
       
  1374 // CCalenViewManager::ToolbarOrNull
       
  1375 // Provides access to the calendar toolbar if one is available
       
  1376 // ----------------------------------------------------------------------------
       
  1377 MCalenToolbar* CCalenViewManager::ToolbarOrNull()
       
  1378     {
       
  1379     TRACE_ENTRY_POINT;
       
  1380     TRACE_EXIT_POINT;
       
  1381     if (iToolbar)
       
  1382         {
       
  1383         if (iToolbar->IsICalenToolBar())
       
  1384             {
       
  1385             return iToolbar;
       
  1386             }
       
  1387         }
       
  1388     return NULL;
       
  1389     }        
       
  1390     
       
  1391 // ----------------------------------------------------------------------------
       
  1392 // CCalenViewManager::ViewsActivated
       
  1393 // Returns if the first view activation on start-up has taken place
       
  1394 // ----------------------------------------------------------------------------
       
  1395 TBool CCalenViewManager::ViewsActivated() const
       
  1396     {
       
  1397     TRACE_ENTRY_POINT;
       
  1398     TRACE_EXIT_POINT;
       
  1399     return iViewsActivated;
       
  1400     }
       
  1401 
       
  1402 // ----------------------------------------------------------------------------
       
  1403 // CCalenViewManager::UpdateToolbarNextViewIconL
       
  1404 // Updates the nextview icon on the toolbar when default view is not month view
       
  1405 // ----------------------------------------------------------------------------
       
  1406 void CCalenViewManager::UpdateToolbarNextViewIconL(TUid aViewUid)
       
  1407 	{
       
  1408 	// Set the view cycle index based on the newly activated view,
       
  1409     // if the view is in the cycle array.
       
  1410     TInt index = iViewInfoArray.Find( aViewUid, CCalenViewInfo::ViewInfoIdentifier );
       
  1411     if( index != KErrNotFound )
       
  1412         {
       
  1413         iViewCycleIndex = index;
       
  1414         if( iToolbar )
       
  1415             {
       
  1416             TInt nextVwIndex = iViewCycleIndex;
       
  1417             do{
       
  1418                nextVwIndex = ( nextVwIndex + 1 )%(iViewInfoArray.Count());
       
  1419               }
       
  1420             while( iViewInfoArray[nextVwIndex]->CyclePosition() == CCalenView::ENoCyclePosition );
       
  1421             
       
  1422             CCalenView* nextview = static_cast<CCalenView*>( 
       
  1423                                         iAppUi.View( iViewInfoArray[nextVwIndex]->ViewUid() ) );
       
  1424             iToolbar->SetNextViewIcon( nextview->ViewIconL() );
       
  1425             }
       
  1426         }
   765 	}
  1427 	}
   766 	OstTraceFunctionExit0( CALENVIEWMANAGER_HANDLECOMMANDL_EXIT );
  1428 
   767 	return commandUsed;
  1429 // ----------------------------------------------------------------------------
   768 }
  1430 // CCalenViewManager::HandleFasterAppExitCommandL
   769 
  1431 // Handles ECalenFasterAppExit command
   770 // ----------------------------------------------------------------------------
  1432 // ----------------------------------------------------------------------------
   771 // CalenViewManager::HandleNotification
  1433 void CCalenViewManager::HandleFasterAppExitCommandL()
   772 //  Handles notifications.
  1434     {
   773 // (other items were commented in a header).
  1435     TRACE_ENTRY_POINT;
   774 // ----------------------------------------------------------------------------
  1436     
   775 //
  1437     if(iToolbar)
   776 void CalenViewManager::HandleNotification(
  1438         {
   777                                          const TCalenNotification notification)
  1439         iToolbar->SetToolbarExtensionFocus(EFalse);
   778 {
  1440         }
   779     OstTraceFunctionEntry0( CALENVIEWMANAGER_HANDLENOTIFICATION_ENTRY );
  1441     
   780     
  1442     // For Handling : When the default view is changed keeping that view open, 
   781 	switch (notification) {
  1443     // from day view changing the default view from month view to day view, 
   782 		case ECalenNotifyExternalDatabaseChanged:
  1444     // we need to reset the previous view id.
   783 		case ECalenNotifyDialogClosed:
  1445     if(iPreviousToDayView.iViewUid!=KNullUid)
   784 		case ECalenNotifyMultipleEntriesDeleted:
  1446         {
   785 		case ECalenNotifyEntrySaved:
  1447         iPreviousToDayView.iViewUid = KNullUid;
   786 		case ECalenNotifyEntryDeleted:
  1448         }
   787 		case ECalenNotifyInstanceDeleted:
  1449     
   788 		case ECalenNotifyEntryClosed:
  1450     // For handling specific case::Calendar exited from FSW 
   789 		case ECalenNotifySystemLocaleChanged:
  1451     // iAvoidRepopulation is set when app backgrounded.
   790 		case ECalenNotifySystemTimeChanged:
  1452     // Reset the flag for activating the view in background
   791 		case ECalenNotifySystemLanguageChanged: {
  1453     if(iAvoidRepopulation)
   792 
  1454         {
   793 			if (notification == ECalenNotifySystemTimeChanged) {
  1455         iAvoidRepopulation = EFalse;
   794 				MCalenContext &context = mController.context();
  1456         }
   795 				QDateTime defaultTime = context.defaultCalTimeForViewsL();
  1457     
   796 				context.setFocusDateAndTime(defaultTime);
  1458     // In case of fasterapp exit, first activate the dummy view before deleting the plugin views
   797 			}
  1459     // Get the default view before we remove plugins
   798 			activateCurrentView();
  1460     iPreviousViewId.iViewUid = KNullUid;
   799 			if (mCalenMonthView) {
  1461     
   800 				mCalenMonthView->captureScreenshot();
  1462     iController.SetExitOnDialogFlag( EFalse ); // for making iisexitondialogclose EFalse.
   801 			} else if (mCalenAgendaView) {
  1463 
   802 				mCalenAgendaView->captureScreenshot();
  1464     TUid defView = iSetting->DefaultView();
   803 			}
  1465    
   804 		}
  1466     // unload all plugins
   805 		    break;
  1467     iCustomisationManager->DisableAllPluginsL();
   806 		case ECalenNotifySettingsClosed: {
  1468     ActivateViewOnFakeExitL(defView);
   807 		    //when setting view closed , switch to the previous view
  1469     // Though the current view is active view, there is no need to issue a callback as we are exiting the whole application.
   808 		    mCurrentViewId = mPreviousViewsId ;
  1470     if( iRemovedActiveView )
   809 			mController.Services().IssueCommandL(ECalenStartActiveStep);
  1471         {
   810 			
  1472         
   811 			 // invalidate captured screenshots as either agenda view is activated now
  1473         if( !iViewRemovalCallback )
   812 			if (mCalenMonthView) {
  1474             {
   813 			mCalenMonthView->captureScreenshot();
  1475             TCallBack callback( RemoveDeActivatedView, this );
   814 			} else if (mCalenAgendaView) {
  1476             iViewRemovalCallback = new( ELeave ) CAsyncCallBack( callback,
   815 				mCalenAgendaView->captureScreenshot();
  1477                                                     CActive::EPriorityStandard );
   816 			}
  1478             }
   817 
  1479         iViewRemovalCallback->CallBack();
   818 		    }
  1480         }
   819 			break;
  1481 
   820 		default:
  1482     TRACE_EXIT_POINT;
   821 			break;
  1483     }
   822 	}
  1484 // ----------------------------------------------------------------------------
   823 	OstTraceFunctionExit0( CALENVIEWMANAGER_HANDLENOTIFICATION_EXIT );
  1485 // CCalenViewManager::HandleSettingsChangeNotificationL
   824 }
  1486 // Handles ECalenNotifySettingsChanged notification
   825 
  1487 // ----------------------------------------------------------------------------
   826 // ----------------------------------------------------------------------------
  1488 void CCalenViewManager::HandleSettingsChangeNotificationL()
   827 // CalenViewManager::settingsView
  1489     {
   828 //  Returns the settings view
  1490     TRACE_ENTRY_POINT;
   829 // (other items were commented in a header).
  1491     
   830 // ----------------------------------------------------------------------------
  1492     if( iController.IsFasterAppFlagEnabled() )
   831 //
  1493         {
   832 CalenSettingsView* CalenViewManager::settingsView()
  1494         TUid newViewUid = iSetting->DefaultView();
   833 {
  1495         if(IsNativeView(newViewUid))
   834     OstTraceFunctionEntry0( CALENVIEWMANAGER_SETTINGSVIEW_ENTRY );
  1496             {
   835     
  1497             TUid oldViewUid = CurrentView();
   836 	OstTraceFunctionExit0( CALENVIEWMANAGER_SETTINGSVIEW_EXIT );
  1498             if( newViewUid.iUid != oldViewUid.iUid )
   837 	return mSettingsView;
  1499                 {
   838 }
  1500                 RequestActivationL( newViewUid );
   839 
  1501                 }
   840 // ----------------------------------------------------------------------------
  1502             }
   841 // CalenViewManager::handleViewingCompleted
  1503         
   842 //  Slot to handle signal viewingCompleted by the agenda event viewer
  1504         // If the plugins are activated using general settings.
   843 // (other items were commented in a header).
  1505         // unload all plugins.Only load the plugins when application
   844 // ----------------------------------------------------------------------------
  1506         // comes to foreground
   845 //
  1507         const RArray<TUid>& plugins = CustomisationManager().ActivePlugins();
   846 void CalenViewManager::handleViewingCompleted(const QDate date)
  1508         if(plugins.Count())
   847 {
  1509             {
   848 	Q_UNUSED(date);
  1510             // unload all plugins
   849 	OstTraceFunctionEntry0( CALENVIEWMANAGER_HANDLEVIEWINGCOMPLETED_ENTRY );
  1511             iCustomisationManager->DisableAllPluginsL();
       
  1512             }
       
  1513         }
       
  1514 
       
  1515     if( iRemovedActiveView )
       
  1516         {
       
  1517         // If the active view has been disabled, the next view in 
       
  1518         // the view cycle list is activated and the current view
       
  1519         // is removed asyncronously.
       
  1520         CycleNextViewL();
       
  1521 
       
  1522         if( !iViewRemovalCallback )
       
  1523             {
       
  1524             TCallBack callback( RemoveDeActivatedView, this );
       
  1525             iViewRemovalCallback = new( ELeave ) CAsyncCallBack( callback,
       
  1526                                                     CActive::EPriorityStandard );
       
  1527             }
       
  1528     
       
  1529         iViewRemovalCallback->CallBack();
       
  1530         }
       
  1531     else if(iCustomisationManager->HiddenView(iCurrentViewId.iViewUid))
       
  1532          {
       
  1533          // Get the uid of the plugin view that is hiding the current view
       
  1534          TUid viewUid = iCustomisationManager->GetReplacePluginViewIdL(iCurrentViewId.iViewUid);
       
  1535              
       
  1536          // update the view cycle index before activating the plugin view
       
  1537          iViewCycleIndex = iViewInfoArray.Find( viewUid, 
       
  1538                                     CCalenViewInfo::ViewInfoIdentifier );
       
  1539          RequestActivationL(viewUid);
       
  1540          }
       
  1541    else
       
  1542         {
       
  1543         StartActiveStepL();
       
  1544         }
       
  1545     
       
  1546     TRACE_EXIT_POINT;
       
  1547     }
       
  1548 
       
  1549 // ----------------------------------------------------------------------------
       
  1550 // CCalenViewManager::HandleEntryDeleteNotificationL
       
  1551 // Handles ECalenNotifyEntryDeleted and ECalenNotifyInstanceDeleted
       
  1552 // notifications
       
  1553 // ----------------------------------------------------------------------------
       
  1554 void CCalenViewManager::HandleEntryDeleteNotificationL()
       
  1555     {
       
  1556     TRACE_ENTRY_POINT;
       
  1557     
       
  1558     if(iCurrentViewId.iViewUid == KUidCalenEventView)   
       
  1559         {
       
  1560         // Activate the previous view when an event is deleted from
       
  1561         // the event view 
       
  1562         if(iPreviousViewId.iViewUid != KNullUid)
       
  1563             {
       
  1564             if(iPreviousToDayView.iViewUid != KNullUid)
       
  1565                 {
       
  1566                 RequestActivationL(iPreviousViewId.iViewUid, KUidCalenShowBackCba);
       
  1567                 }
       
  1568             else
       
  1569                 {
       
  1570                 RequestActivationL(iPreviousViewId.iViewUid);
       
  1571                 }
       
  1572             }
       
  1573         }
       
  1574     else
       
  1575         {
       
  1576         // refresh the current view
       
  1577         StartActiveStepL();             
       
  1578         }
       
  1579     
       
  1580     TRACE_EXIT_POINT;
       
  1581     }
       
  1582 
       
  1583 // ----------------------------------------------------------------------------
       
  1584 // CCalenViewManager::HandleEntryClosedNotificationL
       
  1585 // Handles ECalenNotifyEntryClosed notification
       
  1586 // ----------------------------------------------------------------------------
       
  1587 void CCalenViewManager::HandleEntryClosedNotificationL()
       
  1588     {
       
  1589     TRACE_ENTRY_POINT;
   850 	
  1590 	
   851 	// Cleanup.
  1591 	// reset tha flag iAvoidRepopulation to refresh the view.
   852 	mCalenEventViewer->deleteLater();
  1592 	iAvoidRepopulation = EFalse;
   853 	if (!date.isNull() && date.isValid()) {
  1593     
   854 	    mController.Services().Context().setFocusDate(QDateTime(date));
  1594     // if previous view is native view activate that view
   855 	}
  1595     // otherwise commandlauncher will handle  
   856 	mController.Services().IssueNotificationL(ECalenNotifyEntryClosed);
  1596     if(iPreviousViewId.iViewUid != KNullUid)
   857 	
  1597         {
   858 	// invalidate captured screenshots as either agenda view is activated now
  1598         // if iPreviousToDayView is active activate the day view with "Back" cba.
   859 	if (mCalenMonthView) {
  1599         if(iPreviousToDayView.iViewUid!=KNullUid)
   860 	mCalenMonthView->captureScreenshot();
  1600             {
   861 	} else if (mCalenAgendaView) {
  1601             RequestActivationL(iPreviousViewId.iViewUid, KUidCalenShowBackCba);
   862 		mCalenAgendaView->captureScreenshot();
  1602             }
   863 	}
  1603         else
   864 	OstTraceFunctionExit0( CALENVIEWMANAGER_HANDLEVIEWINGCOMPLETED_EXIT );
  1604             {
   865 }
  1605             if( !iController.GetExitOnDialogFlag() )
   866 
  1606                 {
   867 // ----------------------------------------------------------------------------
  1607                 RequestActivationL(iPreviousViewId.iViewUid);
   868 // CalenViewManager::handleEditingStarted
  1608                 }
   869 //  Slot to handle signal editingStarted by the agenda event viewer
  1609             }
   870 // (other items were commented in a header).
  1610         }
   871 // ----------------------------------------------------------------------------
  1611 
   872 //
  1612 	// reset tha flag iAvoidRepopulation to avoid the repopulation.
   873 void CalenViewManager::handleEditingStarted()
  1613 	iAvoidRepopulation = ETrue;
   874 {
  1614     
   875 	OstTraceFunctionEntry0( CALENVIEWMANAGER_HANDLEEDITINGSTARTED_ENTRY );
  1615     TRACE_EXIT_POINT;
   876 	
  1616     }
   877 	mController.IssueCommandL(ECalenEditEntryFromViewer);
  1617 
   878 	
  1618 // ----------------------------------------------------------------------------
   879 	OstTraceFunctionExit0( CALENVIEWMANAGER_HANDLEEDITINGSTARTED_EXIT );
  1619 // CCalenViewManager::HandleSystemTimeChangeNotificationL
   880 }
  1620 // Handles ECalenNotifySystemTimeChanged notification
   881 
  1621 // ----------------------------------------------------------------------------
   882 // ----------------------------------------------------------------------------
  1622 void CCalenViewManager::HandleSystemTimeChangeNotificationL()
   883 // CalenViewManager::handleEditingCompleted
  1623     {
   884 //  Slot to handle signal editingCompleted by the agenda event viewer
  1624     TRACE_ENTRY_POINT;
   885 // (other items were commented in a header).
  1625     
   886 // ----------------------------------------------------------------------------
  1626         //Set the context whenever system time is changed
   887 //
  1627         TUid newViewUid = iSetting->DefaultView();
   888 void CalenViewManager::handleEditingCompleted()
  1628         MCalenContext& context = iController.Services().Context();
   889 {
  1629         TCalTime focusTime = context.DefaultCalTimeForViewsL();
   890 	OstTraceFunctionEntry0( CALENVIEWMANAGER_HANDLEEDITINGCOMPLETED_ENTRY );
  1630         context.SetFocusDateAndTimeL( focusTime,
   891 	
  1631                                       TVwsViewId( KUidCalendar, newViewUid ));
   892 	mController.Services().IssueNotificationL(ECalenNotifyEditorClosedFromViewer);
  1632     if( iController.IsFasterAppFlagEnabled() )
   893 	
  1633         {
   894 	OstTraceFunctionExit0( CALENVIEWMANAGER_HANDLEEDITINGCOMPLETED_EXIT );
  1634         // reset tha flag iAvoidRepopulation to refresh the view whenever
   895 }
  1635         // system time is changed
   896 
  1636         iAvoidRepopulation = EFalse;
   897 // ----------------------------------------------------------------------------
  1637         
   898 // CalenViewManager::handleDeletingStarted
  1638         if(IsNativeView(newViewUid))
   899 //  Slot to handle signal deletingStarted by the agenda event viewer
  1639             {
   900 // (other items were commented in a header).
  1640             // activate the default view in background
   901 // ----------------------------------------------------------------------------
  1641             RequestActivationL( newViewUid );
   902 //
  1642             }
   903 void CalenViewManager::handleDeletingStarted()
  1643         
   904 {
  1644         // set the flag iAvoidRepopulation to avoid repopulation
   905 	OstTraceFunctionEntry0( CALENVIEWMANAGER_HANDLEDELETINGSTARTED_ENTRY );
  1645         iAvoidRepopulation = ETrue;
   906 	
  1646         }
   907 	mController.IssueCommandL(ECalenDeleteEntryFromViewer);
  1647     else
   908 	
  1648         {
   909 	OstTraceFunctionExit0( CALENVIEWMANAGER_HANDLEDELETINGSTARTED_EXIT );
  1649         // refresh the current view
   910 }
  1650         StartActiveStepL();
   911 
  1651         }
   912 // ----------------------------------------------------------------------------
  1652     
   913 // CalenViewManager::handleDeletingCompleted
  1653     TRACE_EXIT_POINT;
   914 //  Slot to handle signal deletingCompleted by the agenda event viewer
  1654     }
   915 // (other items were commented in a header).
  1655 
   916 // ----------------------------------------------------------------------------
  1656 // -----------------------------------------------------------------------------
   917 //
  1657 // CCalenViewManager::IconsL
   918 void CalenViewManager::handleDeletingCompleted()
  1658 // Create a CCalenIcons object if neccessary and return a reference
   919 {
  1659 // (other items were commented in a header).
   920 	OstTraceFunctionEntry0( CALENVIEWMANAGER_HANDLEDELETINGCOMPLETED_ENTRY );
  1660 // -----------------------------------------------------------------------------
   921 	
  1661 CCalenIcons& CCalenViewManager::IconsL()
   922 	mController.Services().IssueNotificationL(ECalenNotifyEntryDeleted);
  1662     {
   923 
  1663     TRACE_ENTRY_POINT;
   924 	// invalidate captured screenshots as either month view or agenda view is activated now
  1664 
   925     if (mCalenMonthView) {
  1665     if (!iIcons)
   926     mCalenMonthView->captureScreenshot();
  1666         {
   927     } else if (mCalenAgendaView) {
  1667         // Icons
   928     	mCalenAgendaView->captureScreenshot();
  1668         iIcons = CCalenIcons::NewL();
   929     }
  1669         }
   930 	
  1670 
   931     OstTraceFunctionExit0( CALENVIEWMANAGER_HANDLEDELETINGCOMPLETED_EXIT );
  1671     TRACE_EXIT_POINT;
   932 }
  1672     return *iIcons;
   933 
  1673     }
   934 // ----------------------------------------------------------------------------
  1674 
   935 // CalenViewManager::handleInstanceViewCreation
  1675 // -----------------------------------------------------------------------------
   936 //  Slot to handle completion of instance view creation
  1676 // CCalenViewManager::GetNextViewIconL
   937 // (other items were commented in a header).
  1677 // Gets next view icon 
   938 // ----------------------------------------------------------------------------
  1678 // -----------------------------------------------------------------------------
   939 //
  1679 CGulIcon* CCalenViewManager::GetNextViewIconL()
   940 void CalenViewManager::handleInstanceViewCreation(int status)
  1680     {
   941 {
  1681     TRACE_ENTRY_POINT;
   942     OstTraceFunctionEntry0( CALENVIEWMANAGER_HANDLEINSTANCEVIEWCREATION_ENTRY );
  1682     
   943     
  1683     // Set the view cycle index based on the newly activated view,
   944 	Q_UNUSED(status);
  1684     // if the view is in the cycle array.
   945 	
  1685     TInt index = iViewInfoArray.Find( iCurrentViewId.iViewUid, CCalenViewInfo::ViewInfoIdentifier );
   946 	// This flag is needed if mCalenMonthView and mCalenAgendaview is not created
  1686     if( index != KErrNotFound )
   947 	// and before that this slot is getting called.
  1687         {
   948 	// if we launch views through services then this slot is getting called 
  1688         iViewCycleIndex = index;
   949 	// before the view construction.
  1689         TInt nextVwIndex = iViewCycleIndex;
   950 	mInstanceViewCreated = true;
  1690         do
   951 	
  1691             {
   952 	// handleInstanceViewCreation function is called only once. Now that the instance
  1692             nextVwIndex = ( nextVwIndex + 1 )%(iViewInfoArray.Count());
   953 	// view creation is successfull. Events need to be populated on screen
  1693             }while( iViewInfoArray[nextVwIndex]->CyclePosition() == CCalenView::ENoCyclePosition );
   954 	// Ideal colution should be to call a uniform function, e.g. PopulateEvents
  1694         
   955 	// where PopulateEvents should be implemeted by all views. Since the current
  1695         // Get the next view icon
   956 	// solution for the month view implements the construction in two phases so 
  1696         CCalenView* nextview = static_cast<CCalenView*>( iAppUi.View( iViewInfoArray[nextVwIndex]->ViewUid() ) );
   957 	// it needs to be refactored and a common solution needs to be put here. So 
  1697         return( nextview->ViewIconL() );
   958 	// that code doesn't break if another view is added tomorow
  1698         }
   959 	HbView *currentview = mController.MainWindow().currentView();
  1699              
   960 	
  1700     TRACE_EXIT_POINT;
   961 	if (mCalenMonthView && currentview == mCalenMonthView) {
  1701     return NULL;
   962 		mCalenMonthView->fetchEntriesAndUpdateModel();
  1702     }
   963 	}
  1703 
   964 	else if (mCalenAgendaView && currentview == mCalenAgendaView) {
  1704 // -----------------------------------------------------------------------------
   965 		mCalenAgendaView->doPopulation();
  1705 // CCalenViewManager::SetRepopulation
   966 	}
  1706 // Resets the flag iAvoidRepopulation to activate the view.
   967     else if (mCalenDayView && currentview == mCalenDayView) {
  1707 // -----------------------------------------------------------------------------
   968         mCalenDayView->doPopulation();
  1708 void CCalenViewManager::SetRepopulation(TBool aRePopulate)
   969     }
  1709     {
   970 	// Calls the emitAppReady function of CalenController. Need to emit this
  1710     TRACE_ENTRY_POINT;
   971 	// signal after the view is fully constructed & populated
  1711     // to prevent the display of blank view, 
   972 	// with actual data and ready to be used. So entry view & instance view
  1712     // set the iAvoidRepopulation to EFalse, 
   973 	// needs to be created so that a new entry can also be created. Finally
  1713     // so that view is populated properly
   974 	// NotesApplication object needs to emit applicationReady Signal.
  1714     
   975 	mController.emitAppReady();
  1715     iAvoidRepopulation = aRePopulate;
   976 	
  1716     
   977 	OstTraceFunctionExit0( CALENVIEWMANAGER_HANDLEINSTANCEVIEWCREATION_EXIT );
  1717     TRACE_EXIT_POINT;
   978 }
  1718     }
   979 
  1719 
   980 // ----------------------------------------------------------------------------
  1720 // -----------------------------------------------------------------------------
   981 // CalenViewManager::handleDeletingCompleted
  1721 // CCalenViewManager::CalenToolbar
   982 //  Slot to handle completion of entry view creation
  1722 // Returns calendar toolbar
   983 // (other items were commented in a header).
  1723 // -----------------------------------------------------------------------------
   984 // ----------------------------------------------------------------------------
  1724 CCalenToolbarImpl* CCalenViewManager::CalenToolbar()
   985 //
  1725     {
   986 void CalenViewManager::handleEntryViewCreation(int status)
  1726     TRACE_ENTRY_POINT;
   987 {
  1727     TRACE_EXIT_POINT;
   988     OstTraceFunctionEntry0( CALENVIEWMANAGER_HANDLEENTRYVIEWCREATION_ENTRY );
  1728     return iToolbar;
   989     
  1729     }
   990 	// Nothing Yet
  1730 
   991 	Q_UNUSED(status);
  1731 // -----------------------------------------------------------------------------
   992 
  1732 // CCalenViewManager::ReloadAllPluginsL
   993 	OstTraceFunctionExit0( CALENVIEWMANAGER_HANDLEENTRYVIEWCREATION_EXIT );
  1733 // Reload all plugins
   994 }
  1734 // -----------------------------------------------------------------------------
   995 
  1735 void CCalenViewManager::ReloadAllPluginsL()
   996 // ----------------------------------------------------------------------------
  1736     {
   997 // CalenViewManager::handleEntriesChanged
  1737     TRACE_ENTRY_POINT;
   998 // this function will be called when someone else has changed the database
  1738     
   999 // ----------------------------------------------------------------------------
  1739     // load all plugins
  1000 //
  1740     iCustomisationManager->DoPluginLoadingL();
  1001 void CalenViewManager::handleEntriesChanged(QList<ulong> ids)
  1741     UpdatePluginListL();
  1002 {
  1742     
  1003 	Q_UNUSED(ids);
  1743     // only activate plugin view if it is default view
  1004 	HbView *currentview = mController.MainWindow().currentView();
  1744     TUid defaultViewUid = iSetting->DefaultView();
  1005 	if((mCalenMonthView == currentview)||(mCalenDayView == currentview)||
  1745     if(!IsNativeView(defaultViewUid))
  1006                                             (mCalenAgendaView == currentview ))
  1746         {
  1007 	    {
  1747         iAvoidRepopulation = EFalse;
  1008         activateCurrentView();
  1748                 
  1009 	    }
  1749         // Find the default view in the view cycle list
  1010 }
  1750         TInt position = iViewInfoArray.Find(
  1011 
  1751                 defaultViewUid, CCalenViewInfo::ViewInfoIdentifier );
  1012 // ----------------------------------------------------------------------------
  1752         if( position != KErrNotFound )
  1013 // CalenViewManager::handleEntryUpdation
  1753             {
  1014 // this function will be called when any entry is updated or added into database
  1754             TVwsViewId targetViewId( KUidCalendar, defaultViewUid);
  1015 // Here we need to set the context to the entry updated or added.
  1755             RequestActivationL(targetViewId);
  1016 // ----------------------------------------------------------------------------
  1756             iViewCycleIndex = position;
  1017 //
  1757             }
  1018 void CalenViewManager::handleEntryUpdation(ulong id)
  1758         else
  1019 {
  1759             {
  1020     AgendaEntry updatedEntry = mController.agendaInterface()->fetchById(id);
  1760             // if plugin providing default view is already uninstalled
  1021 
  1761             // activate month view as default view
  1022     // Agenda entry is not null then refresh the view else close event viewer
  1762             CRepository* repository = CRepository::NewL( KCRUidCalendar );
  1023     if (!updatedEntry.isNull()) {
  1763             CleanupStack::PushL(repository);
  1024         if (AgendaEntry::TypeTodo != updatedEntry.type()) {
  1764             TInt tmp( static_cast<TInt>( KUidCalenMonthView.iUid ) );
  1025             QDate date = updatedEntry.startTime().date();
  1765             TInt position = iViewInfoArray.Find( KUidCalenMonthView, CCalenViewInfo::ViewInfoIdentifier );
  1026             if (!date.isNull() && date.isValid()) {
  1766             User::LeaveIfError( repository->Set( KCalendarDefaultStartView, tmp ) );
  1027                 mController.Services().Context().setFocusDate(QDateTime(date));
  1767             iAppUi.SetDefaultViewL( *iAppUi.View( KUidCalenMonthView ) );
  1028             }
  1768             TVwsViewId targetViewId( KUidCalendar, KUidCalenMonthView);
  1029         }
  1769             RequestActivationL(targetViewId);
  1030     }
  1770             iViewCycleIndex = position;
  1031 
  1771             CleanupStack::PopAndDestroy(repository);  
  1032 }
  1772             }
  1033 
  1773         }
  1034 // ----------------------------------------------------------------------------
  1774     
  1035 // CalenViewManager::launchSettingsView
  1775     TRACE_EXIT_POINT;
  1036 // Launches settings view
  1776     }
  1037 // (other items were commented in a header).
  1777 
  1038 // ----------------------------------------------------------------------------
  1778 // -----------------------------------------------------------------------------
  1039 //
  1779 // CCalenViewManager::GetPreviousViewUid
  1040 void CalenViewManager::launchSettingsView()
  1780 // Rest of the details are commented in header.
  1041 {
  1781 // -----------------------------------------------------------------------------
  1042     OstTraceFunctionEntry0( CALENVIEWMANAGER_LAUNCHSETTINGSVIEW_ENTRY );
  1782 TUid CCalenViewManager::GetPreviousViewUid()
  1043     
  1783     {
  1044     mPreviousViewsId = mCurrentViewId ;  
  1784     return iPreviousViewId.iViewUid;
  1045     mCurrentViewId = ECalenShowSettings;
  1785     }
  1046     mSettingsView->initializeForm();
  1786 
  1047     mController.Services().MainWindow().setCurrentView(mSettingsView);
  1787 // -----------------------------------------------------------------------------
  1048     
  1788 // CCalenViewManager::IsNativeView
  1049     // capture cureent view in case app closed/quits from settings view
  1789 // Check for native view
  1050     if (mCalenMonthView){
  1790 // -----------------------------------------------------------------------------
  1051     mCalenMonthView->captureScreenshot(true);
  1791 TBool CCalenViewManager::IsNativeView(TUid aViewUid)
  1052     } else if(mCalenAgendaView){
  1792     {
  1053     	mCalenAgendaView->captureScreenshot(true);
  1793     TRACE_ENTRY_POINT;
  1054     }
  1794 
  1055     
  1795     if( (aViewUid == KUidCalenMonthView)||
  1056     OstTraceFunctionExit0( CALENVIEWMANAGER_LAUNCHSETTINGSVIEW_EXIT );
  1796         (aViewUid == KUidCalenWeekView) ||
  1057 }
  1797         (aViewUid == KUidCalenDayView) ||
  1058 
  1798         (aViewUid == KUidCalenTodoView) )
  1059 
  1799         {
  1060 // ----------------------------------------------------------------------------
  1800         TRACE_EXIT_POINT;
  1061 // CalenViewManager::removeSettingsView
  1801         return ETrue;
  1062 // remove settings view
  1802         }
  1063 // ----------------------------------------------------------------------------
  1803     TRACE_EXIT_POINT;
  1064 //
  1804     return EFalse;
  1065 void CalenViewManager::removeSettingsView()
  1805     }
  1066 {
  1806 
  1067     if(mSettingsView){
  1807 // -----------------------------------------------------------------------------
  1068         mController.Services().MainWindow().removeView(mSettingsView);
  1808 // CCalenViewManager::ActivateViewOnFakeExitL
  1069     }
  1809 // Check for native view
  1070 }
  1810 // -----------------------------------------------------------------------------
  1071     
  1811 void CCalenViewManager::ActivateViewOnFakeExitL(TUid aDefView)
  1072 // ----------------------------------------------------------------------------
  1812     {
  1073 // CalenViewManager::isEventViewerActive
  1813     TRACE_ENTRY_POINT;
  1074 // check if Agenda Event Viewer is active
  1814     
  1075 // ----------------------------------------------------------------------------
  1815     if(IsNativeView(aDefView))
  1076 //
  1816         {
  1077 bool CalenViewManager::isEventViewerActive()
  1817         // activate the view in background
  1078 {
  1818         RequestActivationL( aDefView, KCalenHideInBackGround, KNullDesC8() );
  1079    if(mCalenEventViewer)
  1819         }
  1080        return true;
  1820     else
  1081    else
  1821         {
  1082        return false;
  1822         RequestActivationL( KUidCalenDummyView, KCalenHideInBackGround, KNullDesC8() );
  1083 }
  1823         }
  1084 
  1824     
  1085 // ----------------------------------------------------------------------------
  1825     // set the flag to avoid repopulation when application is
  1086 // CalenViewManager::saveAndCloseEditor
  1826     // opened after faster exit
  1087 // save the entry and close the editor
  1827     iAvoidRepopulation = ETrue;
  1088 // isEventViewerActive() should be called before this function
  1828     
  1089 // ----------------------------------------------------------------------------
  1829     // set the context 
  1090 //
  1830     MCalenContext& context = iController.Services().Context();
  1091 void CalenViewManager::saveAndCloseEditor()
  1831     TCalTime focusTime = context.DefaultCalTimeForViewsL();
  1092 {
  1832     context.SetFocusDateAndTimeL( focusTime,
  1093    mCalenEventViewer->saveAndCloseEditor();
  1833                                   TVwsViewId( KUidCalendar, aDefView) );
  1094 }
  1834     
  1095 
  1835     TRACE_EXIT_POINT;
  1096 // ----------------------------------------------------------------------------
  1836     }
  1097 // CalenViewManager::closeAgendaEventView
  1837 
  1098 // close the agenda event view 
  1838 // -----------------------------------------------------------------------------
  1099 // isEventViewerActive() should be called before this function
  1839 // CCalenViewManager::ActivateLocalViewL
  1100 // ----------------------------------------------------------------------------
  1840 // Activate the local view if application already in back ground
  1101 //
  1841 // -----------------------------------------------------------------------------
  1102 void CalenViewManager::closeAgendaEventView()
  1842 void CCalenViewManager::ActivateLocalViewL(TUid aDefView)
  1103 {
  1843     {
  1104    mCalenEventViewer->closeAgendaEventView();
  1844     iAppUi.ActivateLocalViewL( aDefView );      
  1105 }
  1845     }
  1106 
  1846 // End of file
  1107 
       
  1108 // End of file	--Don't remove this.