calendarui/controller/src/calenviewmanager.cpp
changeset 50 579cc610882e
parent 49 5de72ea7a065
child 58 ef813d54df51
equal deleted inserted replaced
49:5de72ea7a065 50:579cc610882e
    15  *
    15  *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 //system includes
    19 //system includes
    20 #include <QDebug>
       
    21 #include <hbmainwindow.h>
    20 #include <hbmainwindow.h>
    22 #include <hbinstance.h>
    21 #include <hbinstance.h>
    23 #include <hbapplication.h> // hbapplication
    22 #include <hbapplication.h> // hbapplication
    24 #include <xqserviceutil.h> // service utils
    23 #include <xqserviceutil.h> // service utils
    25 
    24 
    27 #include "calenviewmanager.h"
    26 #include "calenviewmanager.h"
    28 #include "calencontroller.h"
    27 #include "calencontroller.h"
    29 #include "hb_calencommands.hrh"
    28 #include "hb_calencommands.hrh"
    30 #include "calenservicesimpl.h"
    29 #include "calenservicesimpl.h"
    31 #include "calenmonthview.h"
    30 #include "calenmonthview.h"
    32 #include "calendayview.h"
    31 #include "calenagendaview.h"
    33 #include "calenmonthview.h"
    32 #include "calenmonthview.h"
    34 #include "agendaeventviewer.h"
    33 #include "agendaeventviewer.h"
    35 #include "calennotificationhandler.h"
    34 #include "calennotificationhandler.h"
    36 #include "CalenUid.h"
    35 #include "CalenUid.h"
    37 #include "calenactionuiutils.h"
    36 #include "calenactionuiutils.h"
    38 #include "calensettingsview.h"
    37 #include "calensettingsview.h"
    39 #include "calendocloader.h"
    38 #include "calendocloader.h"
    40 #include "calendarui_debug.h"
    39 #include "calendarui_debug.h"
    41 #include "calencommon.h"
    40 #include "calencommon.h"
       
    41 #include "calendayview.h"
    42 
    42 
    43 // ----------------------------------------------------------------------------
    43 // ----------------------------------------------------------------------------
    44 // CalenViewManager::CalenViewManager
    44 // CalenViewManager::CalenViewManager
    45 // 2nd phase of construction.
    45 // 2nd phase of construction.
    46 // (other items were commented in a header).
    46 // (other items were commented in a header).
    52 	TRACE_ENTRY_POINT;
    52 	TRACE_ENTRY_POINT;
    53 	
    53 	
    54 	// Following block intializes member variables
    54 	// Following block intializes member variables
    55 	mCalenEventViewer = NULL;
    55 	mCalenEventViewer = NULL;
    56 	mMonthViewDocLoader = NULL;
    56 	mMonthViewDocLoader = NULL;
    57 	mDayViewDocLoader = NULL;	
    57 	mAgendaViewDocLoader = NULL;	
    58 	mDayViewAltDocLoader = NULL;
    58 	mAgendaViewAltDocLoader = NULL;
       
    59 	mCalenAgendaView = NULL;
       
    60 	mCalenMonthView = NULL;
       
    61 	mCalenAgendaViewAlt = NULL;
       
    62 	mSettingsView = NULL;
    59 	mCalenDayView = NULL;
    63 	mCalenDayView = NULL;
    60 	mCalenMonthView = NULL;
       
    61 	mCalenDayViewAlt = NULL;
       
    62 	mSettingsView = NULL;
       
    63 	
    64 	
    64 	// Connect to instance view and entry view creation signals from agenda
    65 	// Connect to instance view and entry view creation signals from agenda
    65 	// interface
    66 	// interface
    66 	connect(mController.agendaInterface(), SIGNAL(instanceViewCreationCompleted(int)),
    67 	connect(mController.agendaInterface(), SIGNAL(instanceViewCreationCompleted(int)),
    67 	        this, SLOT(handleInstanceViewCreation(int)));
    68 	        this, SLOT(handleInstanceViewCreation(int)));
   101         mFirstView = viewId;
   102         mFirstView = viewId;
   102         if (ECalenMonthView == viewId) // Check if Activity was stored for month view
   103         if (ECalenMonthView == viewId) // Check if Activity was stored for month view
   103             {
   104             {
   104             loadMonthView(); // Load month view
   105             loadMonthView(); // Load month view
   105             }
   106             }
   106         else if (ECalenDayView == viewId) // Check if Activity was stored for day view
   107         else if (ECalenAgendaView == viewId) // Check if Activity was stored for agenda view
   107             {
   108             {
   108             loadDayView(); // Load day view
   109         	loadAgendaView(); // Load agenda view
   109             }
   110             }
   110         
   111         
   111         ActivateDefaultViewL(viewId);
   112         ActivateDefaultViewL(viewId);
   112         // Connect to the view ready signal so that we can construct other views 
   113         // Connect to the view ready signal so that we can construct other views 
   113         // once this view is ready
   114         // once this view is ready
   117         if (ECalenMonthView == viewId) // Check if Activity was stored for month view
   118         if (ECalenMonthView == viewId) // Check if Activity was stored for month view
   118             {
   119             {
   119             mController.MainWindow().addView(mCalenMonthView); // Add month view to main window
   120             mController.MainWindow().addView(mCalenMonthView); // Add month view to main window
   120             mController.MainWindow().setCurrentView(mCalenMonthView); // Set month view as current view
   121             mController.MainWindow().setCurrentView(mCalenMonthView); // Set month view as current view
   121             } 
   122             } 
   122         else if (ECalenDayView == viewId) // Check if Activity was stored for day view
   123         else if (ECalenAgendaView == viewId) // Check if Activity was stored for agenda view
   123             {
   124             {
   124             mController.MainWindow().addView(mCalenDayView); // Add day view to main window
   125             mController.MainWindow().addView(mCalenAgendaView); // Add agenda view to main window
   125             mController.MainWindow().setCurrentView(mCalenDayView); // Set day view as current view
   126             mController.MainWindow().setCurrentView(mCalenAgendaView); // Set agenda view as current view
   126             }
   127             }
   127         } else if (isFromServiceFrmWrk/*Hb::ActivationReasonService == activityReason*/) {
   128         } else if (isFromServiceFrmWrk/*Hb::ActivationReasonService == activityReason*/) {
   128         // Dont load any views until our remote slot gets called in
   129         // Dont load any views until our remote slot gets called in
   129         // calenserviceprovider.cpp
   130         // calenserviceprovider.cpp
   130         // Just have an empty mainwindow
   131         // Just have an empty mainwindow
   159 
   160 
   160 	if (mSettingsView) {
   161 	if (mSettingsView) {
   161 		delete mSettingsView;
   162 		delete mSettingsView;
   162 		mSettingsView = 0;
   163 		mSettingsView = 0;
   163 	}
   164 	}
   164 	if (mDayViewDocLoader) {
   165 	if (mAgendaViewDocLoader) {
   165 		delete mDayViewDocLoader;
   166 		delete mAgendaViewDocLoader;
   166 		mDayViewDocLoader = 0;
   167 		mAgendaViewDocLoader = 0;
   167 	}
   168 	}
   168 	if (mDayViewAltDocLoader) {
   169 	if (mAgendaViewAltDocLoader) {
   169 		delete mDayViewAltDocLoader;
   170 		delete mAgendaViewAltDocLoader;
   170 		mDayViewAltDocLoader = 0;
   171 		mAgendaViewAltDocLoader = 0;
   171 	}
   172 	}
   172 	if (mMonthViewDocLoader) {
   173 	if (mMonthViewDocLoader) {
   173 		delete mMonthViewDocLoader;
   174 		delete mMonthViewDocLoader;
   174 		mMonthViewDocLoader = 0;
   175 		mMonthViewDocLoader = 0;
   175 	}
   176 	}
   198 		loadMonthView();
   199 		loadMonthView();
   199 		ActivateDefaultViewL(ECalenMonthView);
   200 		ActivateDefaultViewL(ECalenMonthView);
   200 		// Add month view to mainwindow.
   201 		// Add month view to mainwindow.
   201 		mController.MainWindow().addView(mCalenMonthView);
   202 		mController.MainWindow().addView(mCalenMonthView);
   202 		mController.MainWindow().setCurrentView(mCalenMonthView);
   203 		mController.MainWindow().setCurrentView(mCalenMonthView);
   203 	} else if (view == ECalenDayView) {
   204 	} else if (view == ECalenAgendaView) {
   204 		mFirstView = ECalenDayView;
   205 		mFirstView = ECalenAgendaView;
   205 		loadDayView();
   206 		loadAgendaView();
   206 		ActivateDefaultViewL(ECalenDayView);
   207 		ActivateDefaultViewL(ECalenAgendaView);
   207 		// Add day view to mainwindow.
   208 		// Add agenda view to mainwindow.
   208 		mController.MainWindow().addView(mCalenDayView);
   209 		mController.MainWindow().addView(mCalenAgendaView);
   209 		mController.MainWindow().setCurrentView(mCalenDayView);
   210 		mController.MainWindow().setCurrentView(mCalenAgendaView);
   210 	}
   211 	}
   211 	TRACE_EXIT_POINT;
   212 	TRACE_EXIT_POINT;
   212 }
   213 }
   213 
   214 
   214 // ----------------------------------------------------------------------------
   215 // ----------------------------------------------------------------------------
   245 	// Setup the month view.
   246 	// Setup the month view.
   246 	mCalenMonthView->setupView(mMonthViewDocLoader);
   247 	mCalenMonthView->setupView(mMonthViewDocLoader);
   247 }
   248 }
   248 
   249 
   249 // ----------------------------------------------------------------------------
   250 // ----------------------------------------------------------------------------
   250 // CalenViewManager::loadDayView
   251 // CalenViewManager::loadAgendaView
   251 // Loads the day view frm the docml
   252 // Loads the agenda view frm the docml
   252 // (other items were commented in a header).
   253 // (other items were commented in a header).
   253 // ----------------------------------------------------------------------------
   254 // ----------------------------------------------------------------------------
   254 //
   255 //
   255 void CalenViewManager::loadDayView()
   256 void CalenViewManager::loadAgendaView()
   256 {
   257 {
   257 	bool loadSuccess = false;
   258 	bool loadSuccess = false;
   258 	// Create the day view docloader object.
   259 	// Create the agenda view docloader object.
   259 	mDayViewDocLoader = new CalenDocLoader(mController);
   260 	mAgendaViewDocLoader = new CalenDocLoader(mController);
   260 	
   261 	
   261 	// Load default section
   262 	// Load default section
   262 	mDayViewDocLoader->load(CALEN_DAYVIEW_XML_FILE, &loadSuccess);
   263 	mAgendaViewDocLoader->load(CALEN_AGENDAVIEW_XML_FILE, &loadSuccess);
   263 	if (!loadSuccess) {
   264 	if (!loadSuccess) {
   264 		qFatal("calenviewmanager.cpp : Unable to load XML");
   265 		qFatal("calenviewmanager.cpp : Unable to load XML");
   265 	}
   266 	}
   266 	
   267 	
   267 	// Get the calenday view from the loader
   268 	// Get the calenagenda view from the loader
   268 	mCalenDayView = static_cast<CalenDayView *> (mDayViewDocLoader->findWidget(CALEN_DAYVIEW));
   269 	mCalenAgendaView = static_cast<CalenAgendaView *> (mAgendaViewDocLoader->findWidget(CALEN_AGENDAVIEW));
   269 	if (!mCalenDayView) {
   270 	if (!mCalenAgendaView) {
   270 		qFatal("calenviewmanager.cpp : Unable to find day view");
   271 		qFatal("calenviewmanager.cpp : Unable to find agenda view");
   271 	}
   272 	}
   272 	
   273 	
   273 	// Setup the day view
   274 	// Setup the agenda view
   274 	mCalenDayView->setupView(mDayViewDocLoader);
   275 	mCalenAgendaView->setupView(mAgendaViewDocLoader);
   275 	
   276 	
   276 	// The following code is done to provide swipe support
   277 	// The following code is done to provide swipe support
   277 	// in day view. Idea is to create two views and keep
   278 	// in agenda view. Idea is to create two views and keep
   278 	// switiching between these two using view switch effects
   279 	// switiching between these two using view switch effects
   279 	// to provide an illusion of flow to the user
   280 	// to provide an illusion of flow to the user
   280 	loadAlternateDayView();
   281 	loadAlternateAgendaView();
       
   282 	
   281 }
   283 }
   282 
   284 
   283 // ----------------------------------------------------------------------------
   285 // ----------------------------------------------------------------------------
   284 // CalenViewManager::handleMainViewReady
   286 // CalenViewManager::handleMainViewReady
   285 // Slot to handle viewReady() signal from mainwindow
   287 // Slot to handle viewReady() signal from mainwindow
   294 	}
   296 	}
   295 	
   297 	
   296 	// Construct other views
   298 	// Construct other views
   297 	constructOtherViews();
   299 	constructOtherViews();
   298 	
   300 	
       
   301     // Install the event filter for the controller once the view is ready
       
   302     // so that system language/locale changes can be handled
       
   303 	//hbInstance->allMainWindows().first()->installEventFilter(&mController);
       
   304 	
   299 	// disconnect the view ready signal as we dont need it anymore
   305 	// disconnect the view ready signal as we dont need it anymore
   300 	disconnect(&mController.MainWindow(), SIGNAL(viewReady()), 
   306 	disconnect(&mController.MainWindow(), SIGNAL(viewReady()), 
   301 			   this, SLOT(handleMainViewReady()));
   307 			   this, SLOT(handleMainViewReady()));
   302 }
   308 }
   303 
   309 
   310 void CalenViewManager::constructOtherViews()
   316 void CalenViewManager::constructOtherViews()
   311 {
   317 {
   312 	// Load all other views except mFirstView
   318 	// Load all other views except mFirstView
   313 	
   319 	
   314 	// NOTE: Right now, since Calendar has only two views, month view 
   320 	// NOTE: Right now, since Calendar has only two views, month view 
   315 	// and day view, when client launches day view, then there is no need
   321 	// and agenda view, when client launches agenda view, then there is no need
   316 	// to construct the month view as per UI REQ., but tomorrow if new views
   322 	// to construct the month view as per UI REQ., but tomorrow if new views
   317 	// come after day view, then we need to construct those views if they are
   323 	// come after agenda view, then we need to construct those views if they are
   318 	// native views. Right now, there is a event viewer but its not a native
   324 	// native views. Right now, there is a event viewer but its not a native
   319 	// view. Hence, if day view is launched, dont construct month view
   325 	// view. Hence, if agenda view is launched, dont construct month view
   320 	if (mFirstView != ECalenDayView) // check if day view is not already loaded
   326 	if (mFirstView != ECalenAgendaView) // check if agenda view is not already loaded
   321 		{
   327 		{
   322 		// Load all other views 
   328 		// Load all other views 
   323 		loadDayView();
   329 		loadAgendaView();
   324 	}
   330 		
   325 	else //day view was launched as first view
   331 		if (!mCalenDayView) {
       
   332 			mCalenDayView = new CalenDayView(mController.Services());
       
   333 		}
       
   334 	}
       
   335 	else //agenda view was launched as first view
   326 	    {
   336 	    {
   327 		// No implementation yet. UI specs not clear
   337 		// No implementation yet. UI specs not clear
   328 		// to be commented in with some more code once UI specs is frozen
   338 		// to be commented in with some more code once UI specs is frozen
   329 		// for day view launching as first view after it was saved as activity
   339 		// for agenda view launching as first view after it was saved as activity
   330 		// when it was launched from month view
   340 		// when it was launched from month view
   331         // loadMonthView();
   341         // loadMonthView();
   332         // mCalenMonthView->doLazyLoading();
   342         // mCalenMonthView->doLazyLoading();
   333 	    }
   343 	    }
   334 
   344 
   353 // ----------------------------------------------------------------------------
   363 // ----------------------------------------------------------------------------
   354 //
   364 //
   355 void CalenViewManager::showNextDay()
   365 void CalenViewManager::showNextDay()
   356 {
   366 {
   357     // Set the context for the next day
   367     // Set the context for the next day
   358     QDateTime currentDay = mController.Services().Context().focusDateAndTimeL();
   368     QDateTime currentDay = mController.Services().Context().focusDateAndTime();
   359     currentDay = currentDay.addDays(1);
   369     currentDay = currentDay.addDays(1);
   360     mController.Services().Context().setFocusDateL(currentDay, ECalenDayView);
   370     mController.Services().Context().setFocusDate(currentDay);
   361     mCurrentViewId = ECalenDayView;
   371     mCurrentViewId = ECalenAgendaView;
   362     // Check which is the currently activated view
   372     // Check which is the currently activated view
   363     if (mController.MainWindow().currentView() == mCalenDayView) {
   373     if (mController.MainWindow().currentView() == mCalenAgendaView) {
   364         mCalenDayView->disconnectAboutToQuitEvent(); // disconnect mCalenDayView to get aboutToQuit Events
   374         mCalenAgendaView->disconnectAboutToQuitEvent(); // disconnect mCalenAgendaView to get aboutToQuit Events
   365         HbEffect::add(mCalenDayView,
   375         HbEffect::add(mCalenAgendaView,
   366                       ":/fxml/view_hide",
   376                       ":/fxml/view_hide",
   367                       "hide");
   377                       "hide");
   368         HbEffect::add(mCalenDayViewAlt,
   378         HbEffect::add(mCalenAgendaViewAlt,
   369                       ":/fxml/view_show",
   379                       ":/fxml/view_show",
   370                       "show");
   380                       "show");
   371         // Set the other day view as the current view
   381         // Set the other agenda view as the current view
   372         // and animate to provide illusion of swipe
   382         // and animate to provide illusion of swipe
   373 		// It would also connect for aboutToQuit events
   383 		// It would also connect for aboutToQuit events
   374         mCalenDayViewAlt->doPopulation();
   384         mCalenAgendaViewAlt->doPopulation();
   375         mController.MainWindow().setCurrentView(mCalenDayViewAlt, true, Hb::ViewSwitchUseNormalAnim);
   385         mController.MainWindow().setCurrentView(mCalenAgendaViewAlt, true, Hb::ViewSwitchUseNormalAnim);
   376     } else {
   386     } else {
   377         mCalenDayViewAlt->disconnectAboutToQuitEvent(); // disconnect mCalenDayViewAlt to get aboutToQuit Events
   387     mCalenAgendaViewAlt->disconnectAboutToQuitEvent(); // disconnect mCalenAgendaViewAlt to get aboutToQuit Events
   378         HbEffect::add(mCalenDayViewAlt,
   388         HbEffect::add(mCalenAgendaViewAlt,
   379                       ":/fxml/view_hide",
   389                       ":/fxml/view_hide",
   380                       "hide");
   390                       "hide");
   381         HbEffect::add(mCalenDayView,
   391         HbEffect::add(mCalenAgendaView,
   382                       ":/fxml/view_show",
   392                       ":/fxml/view_show",
   383                       "show");
   393                       "show");
   384 		// It would also connect for aboutToQuit events
   394 		// It would also connect for aboutToQuit events
   385         mCalenDayView->doPopulation();
   395         mCalenAgendaView->doPopulation();
   386         mController.MainWindow().setCurrentView(mCalenDayView, true, Hb::ViewSwitchUseNormalAnim);
   396         mController.MainWindow().setCurrentView(mCalenAgendaView, true, Hb::ViewSwitchUseNormalAnim);
   387     }
   397     }
   388 }
   398 }
   389 
   399 
   390 // ----------------------------------------------------------------------------
   400 // ----------------------------------------------------------------------------
   391 // CalenViewManager::showPrevDay
   401 // CalenViewManager::showPrevDay
   392 // other items were commented in a header
   402 // other items were commented in a header
   393 // ----------------------------------------------------------------------------
   403 // ----------------------------------------------------------------------------
   394 //
   404 //
   395 void CalenViewManager::showPrevDay()
   405 void CalenViewManager::showPrevDay()
   396 {
   406 {
   397     QDateTime currentDay = mController.Services().Context().focusDateAndTimeL();
   407     QDateTime currentDay = mController.Services().Context().focusDateAndTime();
   398     currentDay = currentDay.addDays(-1);
   408     currentDay = currentDay.addDays(-1);
   399     mController.Services().Context().setFocusDateL(currentDay, ECalenDayView);
   409     mController.Services().Context().setFocusDate(currentDay);
   400     mCurrentViewId = ECalenDayView;
   410     mCurrentViewId = ECalenAgendaView;
   401     if (mController.MainWindow().currentView() == mCalenDayView) {
   411     if (mController.MainWindow().currentView() == mCalenAgendaView) {
   402         mCalenDayView->disconnectAboutToQuitEvent(); // disconnect mCalenDayView to get aboutToQuit Events
   412     mCalenAgendaView->disconnectAboutToQuitEvent(); // disconnect mCalenAgendaView to get aboutToQuit Events
   403         HbEffect::add(mCalenDayView,
   413         HbEffect::add(mCalenAgendaView,
   404                       ":/fxml/view_hide_back",
   414                       ":/fxml/view_hide_back",
   405                       "hide");
   415                       "hide");
   406         HbEffect::add(mCalenDayViewAlt,
   416         HbEffect::add(mCalenAgendaViewAlt,
   407                       ":/fxml/view_show_back",
   417                       ":/fxml/view_show_back",
   408                       "show");
   418                       "show");
   409 		// It would also connect for aboutToQuit events
   419 		// It would also connect for aboutToQuit events
   410         mCalenDayViewAlt->doPopulation();
   420         mCalenAgendaViewAlt->doPopulation();
   411         mController.MainWindow().setCurrentView(mCalenDayViewAlt, true, Hb::ViewSwitchUseNormalAnim);
   421         mController.MainWindow().setCurrentView(mCalenAgendaViewAlt, true, Hb::ViewSwitchUseNormalAnim);
   412     } else {
   422     } else {
   413         mCalenDayViewAlt->disconnectAboutToQuitEvent(); // disconnect mCalenDayViewAlt to get aboutToQuit Events
   423     mCalenAgendaViewAlt->disconnectAboutToQuitEvent(); // disconnect mCalenAgendaViewAlt to get aboutToQuit Events
   414         HbEffect::add(mCalenDayViewAlt,
   424         HbEffect::add(mCalenAgendaViewAlt,
   415                       ":/fxml/view_hide_back",
   425                       ":/fxml/view_hide_back",
   416                       "hide");
   426                       "hide");
   417         HbEffect::add(mCalenDayView,
   427         HbEffect::add(mCalenAgendaView,
   418                       ":/fxml/view_show_back",
   428                       ":/fxml/view_show_back",
   419                       "show");
   429                       "show");
   420 		// It would also connect for aboutToQuit events
   430 		// It would also connect for aboutToQuit events
   421         mCalenDayView->doPopulation();
   431         mCalenAgendaView->doPopulation();
   422         mController.MainWindow().setCurrentView(mCalenDayView, true, Hb::ViewSwitchUseNormalAnim);
   432         mController.MainWindow().setCurrentView(mCalenAgendaView, true, Hb::ViewSwitchUseNormalAnim);
   423     }
   433     }
   424 }
   434 }
   425 
   435 
   426 // ----------------------------------------------------------------------------
   436 // ----------------------------------------------------------------------------
   427 // CalenViewManager::removeDayViews
   437 // CalenViewManager::removePreviousView
   428 // other items were commented in a header
   438 // Remove the previous view from main window
   429 // ----------------------------------------------------------------------------
   439 // ----------------------------------------------------------------------------
   430 //
   440 //
   431 void CalenViewManager::removeDayViews()
   441 void CalenViewManager::removePreviousView()
   432 {
   442 {
   433     mCalenDayView->clearListModel();
   443 	if (ECalenAgendaView == mCurrentViewId) {
   434     mCalenDayViewAlt->clearListModel();
   444 		mCalenAgendaView->clearListModel();
   435     mController.MainWindow().removeView(mCalenDayView);
   445 		mCalenAgendaViewAlt->clearListModel();
   436     mController.MainWindow().removeView(mCalenDayViewAlt);
   446 		mController.MainWindow().removeView(mCalenAgendaView);
       
   447 		mController.MainWindow().removeView(mCalenAgendaViewAlt);
       
   448 	} else if (ECalenDayView == mCurrentViewId) {
       
   449 		mController.MainWindow().removeView(mCalenDayView);
       
   450 	} else {
       
   451 		if (ECalenMonthView == mCurrentViewId) {
       
   452 			mController.MainWindow().removeView(mCalenMonthView);
       
   453 		}
       
   454 	}
       
   455 
   437 }
   456 }
   438 
   457 
   439 // ----------------------------------------------------------------------------
   458 // ----------------------------------------------------------------------------
   440 // CalenViewManager::~ActivateDefaultViewL
   459 // CalenViewManager::~ActivateDefaultViewL
   441 //  Activates the default view, as retrieved from settings.
   460 //  Activates the default view, as retrieved from settings.
   446 {
   465 {
   447 	TRACE_ENTRY_POINT;
   466 	TRACE_ENTRY_POINT;
   448 	mCurrentViewId = defaultView;
   467 	mCurrentViewId = defaultView;
   449 	if (ECalenMonthView == defaultView) {
   468 	if (ECalenMonthView == defaultView) {
   450 		mCalenMonthView->doPopulation();
   469 		mCalenMonthView->doPopulation();
   451 	} else if (ECalenDayView == defaultView) {
   470 	} else if (ECalenAgendaView == defaultView) {
   452 		mCalenDayView->doPopulation();
   471 		mCalenAgendaView->doPopulation();
   453 	}
   472 	}
   454 	TRACE_EXIT_POINT;
   473 	TRACE_EXIT_POINT;
   455 }
   474 }
   456 
   475 
   457 // ----------------------------------------------------------------------------
   476 // ----------------------------------------------------------------------------
   475 	switch (mCurrentViewId) {
   494 	switch (mCurrentViewId) {
   476 		case ECalenMonthView:
   495 		case ECalenMonthView:
   477 		    mCalenMonthView->doPopulation();
   496 		    mCalenMonthView->doPopulation();
   478 		    mController.MainWindow().setCurrentView(mCalenMonthView);
   497 		    mController.MainWindow().setCurrentView(mCalenMonthView);
   479 			break;
   498 			break;
   480 		case ECalenDayView:
   499 		case ECalenAgendaView:
   481 		    if (mController.MainWindow().currentView() == mCalenDayView) {
   500 		    if (mController.MainWindow().currentView() == mCalenAgendaView) {
   482 		        // This happens when settings view or event viewer is opened
   501 		        // This happens when settings view or event viewer is opened
   483 		        // from the agenda view. Simply repopulate the view
   502 		        // from the agenda view. Simply repopulate the view
   484 		    	if (mCalenDayView) {
   503 		    	if (mCalenAgendaView) {
   485 		    		// Remove month view from mainwindow.
   504 		    		mCalenAgendaView->doPopulation();
   486 		    		mController.MainWindow().removeView(mCalenMonthView); // what if month view is never loaded
   505 					mController.MainWindow().setCurrentView(mCalenAgendaView);
   487 					mCalenDayView->doPopulation();
       
   488 					mController.MainWindow().setCurrentView(mCalenDayView);
       
   489 		    	} 
   506 		    	} 
   490 		    } else if (mController.MainWindow().currentView() == mCalenDayViewAlt){
   507 		    } else if (mController.MainWindow().currentView() == mCalenAgendaViewAlt){
   491 		        // This happens when settings view or event viewer is opened
   508 		        // This happens when settings view or event viewer is opened
   492 		        // from the agenda view. Simply repopulate the view
   509 		        // from the agenda view. Simply repopulate the view
   493 		    	if (mCalenDayViewAlt) {
   510 		    	if (mCalenAgendaViewAlt) {
   494 					mCalenDayViewAlt->doPopulation();
   511 		    		mCalenAgendaViewAlt->doPopulation();
   495 					mController.MainWindow().setCurrentView(mCalenDayViewAlt);
   512 		    		mController.MainWindow().setCurrentView(mCalenAgendaViewAlt);
   496 		    	}
   513 		    	}
   497 		    } else {
   514 		    } else {
   498 		        // This is called whenever the day view is opened from the month
   515 		        // This is called whenever the agenda view is opened from the month
   499 		        // view. Since the day view is not added to the mainwindow,
   516 		        // view. Since the agenda view is not added to the mainwindow,
   500 		        // add the day views to mainwindow and set any one of them as 
   517 		        // add the agenda views to mainwindow and set any one of them as 
   501 		        // current view
   518 		        // current view
   502 		    	if (mCalenDayView) {
   519 		    	if (mCalenAgendaView) {
   503 		    		mCalenDayView->doPopulation();
   520 		    		mCalenAgendaView->doPopulation();
   504 					mController.MainWindow().addView(mCalenDayView);
   521 		    		mController.MainWindow().addView(mCalenAgendaView);
   505 					mController.MainWindow().setCurrentView(mCalenDayView);
   522 		    		mController.MainWindow().setCurrentView(mCalenAgendaView);
   506 					mController.MainWindow().addView(mCalenDayViewAlt);
   523 		    		mController.MainWindow().addView(mCalenAgendaViewAlt);
   507 		    	}
   524 		    	}
   508 		    }
   525 		    }
   509 			break;
   526 			break;
   510 		case ECalenShowSettings:
   527 		case ECalenShowSettings:
   511 		    {
       
   512 		    mSettingsView->refreshView();
   528 		    mSettingsView->refreshView();
   513 		    }
   529 			break;
   514 			break;
   530 		case ECalenDayView:
   515 		case ECalenLandscapeDayView:
   531 			mCalenDayView->doPopulation();
   516 			// For later implementation
   532 			mController.MainWindow().setCurrentView(mCalenDayView);
   517 			break;
   533 			break;
   518 	}
   534 	}
   519 	TRACE_EXIT_POINT;
   535 	TRACE_EXIT_POINT;
   520 }
   536 }
   521 
   537 
   529 {
   545 {
   530     // capture cureent view in case app closed/quits from AgendaEventViewer
   546     // capture cureent view in case app closed/quits from AgendaEventViewer
   531     if (mCalenMonthView) {
   547     if (mCalenMonthView) {
   532     mCalenMonthView->captureScreenshot(true);
   548     mCalenMonthView->captureScreenshot(true);
   533     }
   549     }
   534     else if (mCalenDayView) {
   550     else if (mCalenAgendaView) {
   535     mCalenDayView->captureScreenshot(true);
   551     	mCalenAgendaView->captureScreenshot(true);
   536     }
   552     }
   537 	MCalenContext& context = mController.Services().Context();
   553 	MCalenContext& context = mController.Services().Context();
   538 	AgendaEntry viewEntry= mController.Services().agendaInterface()->fetchById(
   554 	AgendaEntry viewEntry= mController.Services().agendaInterface()->fetchById(
   539 			context.instanceId().mEntryLocalUid );
   555 			context.instanceId().mEntryLocalUid );
   540 	if (viewEntry.isRepeating() 
   556 	if (viewEntry.isRepeating() 
   541 			&& viewEntry.type() != AgendaEntry::TypeTodo) {
   557 			&& viewEntry.type() != AgendaEntry::TypeTodo) {
   542 		QDateTime startDateTime = context.focusDateAndTimeL();
   558 		QDateTime startDateTime = context.focusDateAndTime();
   543 		viewEntry.setStartAndEndTime(startDateTime, 
   559 		viewEntry.setStartAndEndTime(startDateTime, 
   544 		                     startDateTime.addSecs(viewEntry.durationInSecs()));
   560 		                     startDateTime.addSecs(viewEntry.durationInSecs()));
   545 	}
   561 	}
   546 	mCalenEventViewer = new AgendaEventViewer(
   562 	mCalenEventViewer = new AgendaEventViewer(
   547 			mController.Services().agendaInterface(), this);
   563 			mController.Services().agendaInterface(), this);
   560 	// Launch agenda event viewer
   576 	// Launch agenda event viewer
   561 	mCalenEventViewer->view(viewEntry, AgendaEventViewer::ActionEditDelete);
   577 	mCalenEventViewer->view(viewEntry, AgendaEventViewer::ActionEditDelete);
   562 }
   578 }
   563 
   579 
   564 // ----------------------------------------------------------------------------
   580 // ----------------------------------------------------------------------------
   565 // CalenViewManager::loadAlternateDayView
   581 // CalenViewManager::loadAlternateAgendaView
   566 // other items were commented in a header
   582 // other items were commented in a header
   567 // ----------------------------------------------------------------------------
   583 // ----------------------------------------------------------------------------
   568 //
   584 //
   569 void CalenViewManager::loadAlternateDayView()
   585 void CalenViewManager::loadAlternateAgendaView()
   570 {
   586 {
   571     bool loadSuccess = false;
   587     bool loadSuccess = false;
   572     // Create the day view docloader object.
   588     // Create the agenda view docloader object.
   573     mDayViewAltDocLoader = new CalenDocLoader(mController);
   589     mAgendaViewAltDocLoader = new CalenDocLoader(mController);
   574 
   590 
   575     // Load default section
   591     // Load default section
   576     mDayViewAltDocLoader->load(CALEN_DAYVIEW_XML_FILE, &loadSuccess);
   592     mAgendaViewAltDocLoader->load(CALEN_AGENDAVIEW_XML_FILE, &loadSuccess);
   577     if (!loadSuccess) {
   593     if (!loadSuccess) {
   578         qFatal("calenviewmanager.cpp : Unable to load XML");
   594         qFatal("calenviewmanager.cpp : Unable to load XML");
   579     }
   595     }
   580 
   596 
   581     // Get the calenday view from the loader
   597     // Get the calenagenda view from the loader
   582     mCalenDayViewAlt = static_cast<CalenDayView *> (mDayViewAltDocLoader->findWidget(CALEN_DAYVIEW));
   598     mCalenAgendaViewAlt = static_cast<CalenAgendaView *> (mAgendaViewAltDocLoader->findWidget(CALEN_AGENDAVIEW));
   583     if (!mCalenDayViewAlt) {
   599     if (!mCalenAgendaViewAlt) {
   584         qFatal("calenviewmanager.cpp : Unable to find alternate day view");
   600         qFatal("calenviewmanager.cpp : Unable to find alternate agenda view");
   585     }
   601     }
   586 
   602 
   587     // Setup the day view
   603     // Setup the agenda view
   588     mCalenDayViewAlt->setupView(mDayViewAltDocLoader);
   604     mCalenAgendaViewAlt->setupView(mAgendaViewAltDocLoader);
   589 }
   605 }
   590 
   606 
   591 // ----------------------------------------------------------------------------
   607 // ----------------------------------------------------------------------------
   592 // CalenViewManager::HandleCommandL
   608 // CalenViewManager::HandleCommandL
   593 // Handles view manager commands.
   609 // Handles view manager commands.
   599 	TRACE_ENTRY_POINT;
   615 	TRACE_ENTRY_POINT;
   600 	TBool commandUsed(EFalse);
   616 	TBool commandUsed(EFalse);
   601 	
   617 	
   602 	switch (command.Command()) {
   618 	switch (command.Command()) {
   603 		case ECalenMonthView:
   619 		case ECalenMonthView:
   604 		    removeDayViews();
   620 			// First remove the previous native view before 
   605 		    // Add month view to mainwindow.
   621 			// we set the mCurrentViewId with the current view
       
   622 			removePreviousView();
       
   623 			// Add month view to mainwindow.
   606 			mController.MainWindow().addView(mCalenMonthView);
   624 			mController.MainWindow().addView(mCalenMonthView);
   607 			mCurrentViewId = ECalenMonthView;
   625 			mCurrentViewId = ECalenMonthView;
   608 			activateCurrentView();
   626 			activateCurrentView();
   609 			break;
   627 			break;
       
   628 		case ECalenAgendaView:
       
   629 			// First remove the previous native view before 
       
   630 			// we set the mCurrentViewId with the current view
       
   631 			removePreviousView();
       
   632 			mCurrentViewId = ECalenAgendaView;
       
   633 			activateCurrentView();
       
   634 			break;
   610 		case ECalenDayView:
   635 		case ECalenDayView:
   611 			mCurrentViewId = ECalenDayView;
   636             {
   612 			activateCurrentView();
   637             // First add new view and use QueuedConnection to assure that
       
   638             // view is ready before setting it as the current view
       
   639 			mController.MainWindow().addView(mCalenDayView);
       
   640 			QMetaObject::invokeMethod(this, "handleDayViewReady", 
       
   641 			    Qt::QueuedConnection);
       
   642 			}
   613 			break;
   643 			break;
   614 		case ECalenEventView:
   644 		case ECalenEventView:
   615 			launchEventView();
   645 			launchEventView();
   616 			break;
       
   617 		case ECalenLandscapeDayView:
       
   618 			mCurrentViewId = ECalenLandscapeDayView;
       
   619 			activateCurrentView();
       
   620 			break;
   646 			break;
   621 		case ECalenStartActiveStep:
   647 		case ECalenStartActiveStep:
   622 			activateCurrentView();
   648 			activateCurrentView();
   623 			break;
   649 			break;
   624 		case ECalenShowNextDay:
   650 		case ECalenShowNextDay:
   660 		    {
   686 		    {
   661 		    //when setting view closed , switch to the previous view
   687 		    //when setting view closed , switch to the previous view
   662 		    mCurrentViewId = mPreviousViewsId ;
   688 		    mCurrentViewId = mPreviousViewsId ;
   663 			mController.Services().IssueCommandL(ECalenStartActiveStep);
   689 			mController.Services().IssueCommandL(ECalenStartActiveStep);
   664 			
   690 			
   665 			 // invalidate captured screenshots as either day view is activated now
   691 			 // invalidate captured screenshots as either agenda view is activated now
   666 			if (mCalenMonthView) {
   692 			if (mCalenMonthView) {
   667 			mCalenMonthView->captureScreenshot();
   693 			mCalenMonthView->captureScreenshot();
   668 			} else if (mCalenDayView) {
   694 			} else if (mCalenAgendaView) {
   669 			mCalenDayView->captureScreenshot();
   695 				mCalenAgendaView->captureScreenshot();
   670 			}
   696 			}
   671 
   697 
   672 		    }
   698 		    }
   673 			break;
   699 			break;
   674 		default:
   700 		default:
   694 // (other items were commented in a header).
   720 // (other items were commented in a header).
   695 // ----------------------------------------------------------------------------
   721 // ----------------------------------------------------------------------------
   696 //
   722 //
   697 void CalenViewManager::handleViewingCompleted(const QDate date)
   723 void CalenViewManager::handleViewingCompleted(const QDate date)
   698 {
   724 {
   699 	qDebug() <<"calendar: CalenViewManager::handleEditingCompleted -->";
       
   700 	
   725 	
   701 	// Cleanup.
   726 	// Cleanup.
   702 	mCalenEventViewer->deleteLater();
   727 	mCalenEventViewer->deleteLater();
   703 	if (!date.isNull() && date.isValid()) {
   728 	if (!date.isNull() && date.isValid()) {
   704 	mController.Services().Context().setFocusDateL(QDateTime(date), 
   729 	mController.Services().Context().setFocusDate(QDateTime(date));
   705 	                                               ECalenDayView);
       
   706 	}
   730 	}
   707 	mController.Services().IssueNotificationL(ECalenNotifyEntryClosed);
   731 	mController.Services().IssueNotificationL(ECalenNotifyEntryClosed);
   708 	
   732 	
   709 	// invalidate captured screenshots as either day view is activated now
   733 	// invalidate captured screenshots as either agenda view is activated now
   710 	if (mCalenMonthView) {
   734 	if (mCalenMonthView) {
   711 	mCalenMonthView->captureScreenshot();
   735 	mCalenMonthView->captureScreenshot();
   712 	} else if (mCalenDayView) {
   736 	} else if (mCalenAgendaView) {
   713 	mCalenDayView->captureScreenshot();
   737 		mCalenAgendaView->captureScreenshot();
   714 	}
   738 	}
   715 	qDebug() <<"calendar: CalenViewManager::handleEditingCompleted <--";
       
   716 }
   739 }
   717 
   740 
   718 // ----------------------------------------------------------------------------
   741 // ----------------------------------------------------------------------------
   719 // CalenViewManager::handleEditingStarted
   742 // CalenViewManager::handleEditingStarted
   720 //  Slot to handle signal editingStarted by the agenda event viewer
   743 //  Slot to handle signal editingStarted by the agenda event viewer
   721 // (other items were commented in a header).
   744 // (other items were commented in a header).
   722 // ----------------------------------------------------------------------------
   745 // ----------------------------------------------------------------------------
   723 //
   746 //
   724 void CalenViewManager::handleEditingStarted()
   747 void CalenViewManager::handleEditingStarted()
   725 {
   748 {
   726 	qDebug() <<"calendar: CalenViewManager::handleEditingStarted -->";
       
   727 	
   749 	
   728 	mController.IssueCommandL(ECalenEditEntryFromViewer);
   750 	mController.IssueCommandL(ECalenEditEntryFromViewer);
   729 	
   751 	
   730 	qDebug() <<"calendar: CalenViewManager::handleEditingStarted <--";
       
   731 }
   752 }
   732 
   753 
   733 // ----------------------------------------------------------------------------
   754 // ----------------------------------------------------------------------------
   734 // CalenViewManager::handleEditingCompleted
   755 // CalenViewManager::handleEditingCompleted
   735 //  Slot to handle signal editingCompleted by the agenda event viewer
   756 //  Slot to handle signal editingCompleted by the agenda event viewer
   736 // (other items were commented in a header).
   757 // (other items were commented in a header).
   737 // ----------------------------------------------------------------------------
   758 // ----------------------------------------------------------------------------
   738 //
   759 //
   739 void CalenViewManager::handleEditingCompleted()
   760 void CalenViewManager::handleEditingCompleted()
   740 {
   761 {
   741 	qDebug() <<"calendar: CalenViewManager::handleEditingStarted -->";
       
   742 	
   762 	
   743 	mController.Services().IssueNotificationL(ECalenNotifyEditorClosedFromViewer);
   763 	mController.Services().IssueNotificationL(ECalenNotifyEditorClosedFromViewer);
   744 	
   764 	
   745 	qDebug() <<"calendar: CalenViewManager::handleEditingStarted <--";
       
   746 }
   765 }
   747 
   766 
   748 // ----------------------------------------------------------------------------
   767 // ----------------------------------------------------------------------------
   749 // CalenViewManager::handleDeletingStarted
   768 // CalenViewManager::handleDeletingStarted
   750 //  Slot to handle signal deletingStarted by the agenda event viewer
   769 //  Slot to handle signal deletingStarted by the agenda event viewer
   751 // (other items were commented in a header).
   770 // (other items were commented in a header).
   752 // ----------------------------------------------------------------------------
   771 // ----------------------------------------------------------------------------
   753 //
   772 //
   754 void CalenViewManager::handleDeletingStarted()
   773 void CalenViewManager::handleDeletingStarted()
   755 {
   774 {
   756 	qDebug() <<"calendar: CalenViewManager::handleEditingStarted -->";
       
   757 	
   775 	
   758 	mController.IssueCommandL(ECalenDeleteEntryFromViewer);
   776 	mController.IssueCommandL(ECalenDeleteEntryFromViewer);
   759 	
   777 	
   760 	qDebug() <<"calendar: CalenViewManager::handleEditingStarted <--";
       
   761 }
   778 }
   762 
   779 
   763 // ----------------------------------------------------------------------------
   780 // ----------------------------------------------------------------------------
   764 // CalenViewManager::handleDeletingCompleted
   781 // CalenViewManager::handleDeletingCompleted
   765 //  Slot to handle signal deletingCompleted by the agenda event viewer
   782 //  Slot to handle signal deletingCompleted by the agenda event viewer
   766 // (other items were commented in a header).
   783 // (other items were commented in a header).
   767 // ----------------------------------------------------------------------------
   784 // ----------------------------------------------------------------------------
   768 //
   785 //
   769 void CalenViewManager::handleDeletingCompleted()
   786 void CalenViewManager::handleDeletingCompleted()
   770 {
   787 {
   771 	qDebug() <<"calendar: CalenViewManager::handleEditingStarted -->";
       
   772 	
   788 	
   773 	mController.Services().IssueNotificationL(ECalenNotifyEntryDeleted);
   789 	mController.Services().IssueNotificationL(ECalenNotifyEntryDeleted);
   774 
   790 
   775 	// invalidate captured screenshots as either month view or day view is activated now
   791 	// invalidate captured screenshots as either month view or agenda view is activated now
   776     if (mCalenMonthView) {
   792     if (mCalenMonthView) {
   777     mCalenMonthView->captureScreenshot();
   793     mCalenMonthView->captureScreenshot();
   778     } else if (mCalenDayView) {
   794     } else if (mCalenAgendaView) {
   779     mCalenDayView->captureScreenshot();
   795     	mCalenAgendaView->captureScreenshot();
   780     }
   796     }
   781 
   797 
   782 	
   798 	
   783 	qDebug() <<"calendar: CalenViewManager::handleEditingStarted <--";
       
   784 }
   799 }
   785 
   800 
   786 // ----------------------------------------------------------------------------
   801 // ----------------------------------------------------------------------------
   787 // CalenViewManager::handleInstanceViewCreation
   802 // CalenViewManager::handleInstanceViewCreation
   788 //  Slot to handle completion of instance view creation
   803 //  Slot to handle completion of instance view creation
   800 	// it needs to be refactored and a common solution needs to be put here. So 
   815 	// it needs to be refactored and a common solution needs to be put here. So 
   801 	// that code doesn't break if another view is added tomorow
   816 	// that code doesn't break if another view is added tomorow
   802 	if (mCalenMonthView) {
   817 	if (mCalenMonthView) {
   803 		mCalenMonthView->fetchEntriesAndUpdateModel();
   818 		mCalenMonthView->fetchEntriesAndUpdateModel();
   804 	}
   819 	}
   805 	else if (mCalenDayView) {
   820 	else if (mCalenAgendaView) {
   806 	mCalenDayView->doPopulation();
   821 		mCalenAgendaView->doPopulation();
   807 	}
   822 	}
   808 }
   823 }
   809 
   824 
   810 // ----------------------------------------------------------------------------
   825 // ----------------------------------------------------------------------------
   811 // CalenViewManager::handleDeletingCompleted
   826 // CalenViewManager::handleDeletingCompleted
   816 void CalenViewManager::handleEntryViewCreation(int status)
   831 void CalenViewManager::handleEntryViewCreation(int status)
   817 {
   832 {
   818 	// Nothing Yet
   833 	// Nothing Yet
   819 	Q_UNUSED(status);
   834 	Q_UNUSED(status);
   820 }
   835 }
       
   836 
       
   837 // ----------------------------------------------------------------------------
       
   838 // CalenViewManager::handleDayViewReady
       
   839 // Launches day view when it is added to MainWindow and ready to be displayed
       
   840 // ----------------------------------------------------------------------------
       
   841 //
       
   842 void CalenViewManager::handleDayViewReady() 
       
   843 {
       
   844     // Removes current view
       
   845     // Notice: removing view should be done after new view is set as current to
       
   846     // avoid situation that there is no current view in application
       
   847     removePreviousView();
       
   848     
       
   849     // Sets and activates day view
       
   850     mCurrentViewId = ECalenDayView;
       
   851     activateCurrentView();
       
   852 }
       
   853 
   821 // ----------------------------------------------------------------------------
   854 // ----------------------------------------------------------------------------
   822 // CalenViewManager::launchSettingsView
   855 // CalenViewManager::launchSettingsView
   823 // Launches settings view
   856 // Launches settings view
   824 // (other items were commented in a header).
   857 // (other items were commented in a header).
   825 // ----------------------------------------------------------------------------
   858 // ----------------------------------------------------------------------------
   826 //
   859 //
   827 void CalenViewManager::launchSettingsView()
   860 void CalenViewManager::launchSettingsView()
   828     {
   861 {
   829     mPreviousViewsId = mCurrentViewId ;  
   862     mPreviousViewsId = mCurrentViewId ;  
   830     mCurrentViewId = ECalenShowSettings;
   863     mCurrentViewId = ECalenShowSettings;
   831     mSettingsView->initializeForm();
   864     mSettingsView->initializeForm();
   832     mController.Services().MainWindow().setCurrentView(mSettingsView);
   865     mController.Services().MainWindow().setCurrentView(mSettingsView);
   833     
   866     
   834     // capture cureent view in case app closed/quits from settings view
   867     // capture cureent view in case app closed/quits from settings view
   835     if (mCalenMonthView){
   868     if (mCalenMonthView){
   836     mCalenMonthView->captureScreenshot(true);
   869     mCalenMonthView->captureScreenshot(true);
   837     } else if(mCalenDayView){
   870     } else if(mCalenAgendaView){
   838     mCalenDayView->captureScreenshot(true);
   871     	mCalenAgendaView->captureScreenshot(true);
   839     }
   872     }
   840   	}
   873 }
   841 
   874 
   842 // End of file	--Don't remove this.
   875 // End of file	--Don't remove this.