calendarui/views/src/calenmonthview.cpp
changeset 45 b6db4fd4947b
parent 23 fd30d51f876b
child 51 0b38fc5b94c6
--- a/calendarui/views/src/calenmonthview.cpp	Mon May 03 12:30:32 2010 +0300
+++ b/calendarui/views/src/calenmonthview.cpp	Mon Jun 28 15:22:02 2010 +0530
@@ -29,6 +29,8 @@
 #include <hbcolorscheme.h>
 #include <agendautil.h>
 #include <agendaentry.h>
+#include <hbapplication.h> // hbapplication
+#include <hbactivitymanager.h> //Activity Manager
 
 //user includes
 #include "calenmonthview.h"
@@ -46,8 +48,9 @@
 #include "calendocloader.h"
 #include "calenthicklinesdrawer.h"
 #include "calencommon.h"
-#include "CalendarInternalCRKeys.h"
+#include "calendarprivatecrkeys.h"
 #include "calenpluginlabel.h"
+#include "calenconstants.h"
 /*!
  \class CalenMonthView
 
@@ -62,23 +65,26 @@
 	mGoToTodayAction(0),
 	mPrevRegionalInfo(0),
 	mCurrRegionalInfo(0),
-	mNextRegionalInfo(0)
+	mNextRegionalInfo(0),
+	mIsAboutToQuitEventConnected(false)
 {
 	mIsWeekNumbersShown = 0;
 	mOrientation = mServices.MainWindow().orientation();
 	// Read the date from the context
-	mDate = mServices.Context().focusDateAndTimeL();
+	mDate = mServices.Context().focusDateAndTime();
 	mCurrentDay = mDate;
 
 	// Create the settings manager instance and settings key for week number
 	mSettingsManager = new XQSettingsManager(this);
 	mWeekNumberCenrepKey
 	        = new XQSettingsKey(XQSettingsKey::TargetCentralRepository,
-	                            KCRUidCalendar.iUid, KCalendarWeekViewTitle);
+	                            KCRUidCalendar, KCalendarShowWeekNum);
 
 	mLocale = HbExtendedLocale::system();
 	mFirstWeekLabel = NULL;
 	mIsPrevPaneGesture = false;
+	// Get the week day color from the theme
+	mWeekDaysColor = HbColorScheme::color("qtc_cal_week_day");
 }
 
 /*!
@@ -100,7 +106,7 @@
 								   mDocLoader->findWidget(CALEN_MONTH_TITLE));
 	// Set the title text color
 	QColor monthTitleColor = HbColorScheme::color("qtc_cal_monthgrid_title");
-	if (monthTitleColor.isValid()) {
+	if (mTitleLabel && monthTitleColor.isValid()) {
 		mTitleLabel->setTextColor(monthTitleColor);
 	}
 		
@@ -131,18 +137,6 @@
 	mSeventhDayLabel
 	        = qobject_cast<HbLabel *> (
 					mDocLoader->findWidget(CALEN_MONTVIEW_SEVENTH_DAY_LABEL));
-
-	// Set the short day names to these labels
-	// TODO: Need to read start of the week from the locale
-	// and update the labels accortdingly
-	int startOfDay = mLocale.startOfWeek();
-	mFirstDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_mo"));
-	mSecondDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_tu"));
-	mThirdDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_we"));
-	mFourthDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_th"));
-	mFifthDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_fr"));
-	mSixthDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_sa"));
-	mSeventhDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_su"));
 	
 	// Get the weeknumber widget
 	mWeekNumberWidget
@@ -209,22 +203,51 @@
 
 	mMonthGrid->setView(this);
 
+	
+	
+	mIsFirstTimeLoad = true;
+	// get a pointner to activity manager
+	HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
+
+	// clean up any previous versions of this activity, if any, i.e. activityName, from the activity manager. 
+	// Ignore return value, first boot would always return False. bool declared 
+	// only for debugging purpose.
+	bool ok = activityManager->removeActivity(activityName);
+
+}
+
+/*!
+ Constructs the remaining part of the month view that was kept as 
+ part if lazy loading
+ */
+void CalenMonthView::doLazyLoading()
+{
+	// Add background items to all the widgets
+	addBackgroundFrame();
+	
+	// Construct and add the previous month and next month items to the view
+	mMonthGrid->updateMonthGridWithInActiveMonths(mMonthDataArray);
+	
+	// Check if regional information needs to be shown
+	// and add it or remove it
+	showHideRegionalInformation();
+	
 	// Connect to the menu actions
 	HbAction
-	        *newEventAction =
-	                qobject_cast<HbAction *> (
+			*newEventAction =
+					qobject_cast<HbAction *> (
 						mDocLoader->findObject(CALEN_MONTVIEW_MENU_NEWEVENT));
 
 	connect(newEventAction, SIGNAL(triggered()), this, SLOT(createEditor()));
 
 	mGoToTodayAction =
-	                qobject_cast<HbAction *> (
+					qobject_cast<HbAction *> (
 							mDocLoader->findObject(CALEN_MONTVIEW_MENU_GOTOTODAY));
 	connect(mGoToTodayAction, SIGNAL(triggered()), this, SLOT(goToToday()));
 	
 	HbAction
-	        *goToDateAction =
-	                qobject_cast<HbAction *> (
+			*goToDateAction =
+					qobject_cast<HbAction *> (
 						mDocLoader->findObject(CALEN_MONTVIEW_MENU_GOTODATE));
 
 	connect(goToDateAction, SIGNAL(triggered()), this, SLOT(goToDate()));
@@ -269,12 +292,7 @@
 	// Connect to the signal when options menu is shown
 	// This is required to add/remove dynamically some options
 	connect(menu(), SIGNAL(aboutToShow ()), this,
-	        SLOT(addRemoveActionsInMenu()));
-	
-	mIsFirstTimeLoad = true;
-	
-	// Add background items to all the widgets
-	addBackgroundFrame();
+			SLOT(addRemoveActionsInMenu()));	
 }
 
 /*!
@@ -303,7 +321,15 @@
 			= qobject_cast<HbLabel *> (
 					mDocLoader->findWidget(CALEN_MONTVIEW_SIXTH_WEEK_LABEL));
 	}
-
+	
+	// Set the text colors well before instead of setting it again and again
+	mFirstWeekLabel->setTextColor(mWeekDaysColor);
+	mSecondWeekLabel->setTextColor(mWeekDaysColor);
+	mThirdWeekLabel->setTextColor(mWeekDaysColor);
+	mFourthWeekLabel->setTextColor(mWeekDaysColor);
+	mFifthWeekLabel->setTextColor(mWeekDaysColor);
+	mSixthWeekLabel->setTextColor(mWeekDaysColor);
+	
 	// Calculate the week numbers and set them to the week labels
 	updateWeekNumGridModel();
 
@@ -392,107 +418,121 @@
 {
     // Set the background items for all the widgets
     HbFrameItem* frame = NULL;
+    HbFrameDrawer *drawer = NULL;
     HbWidget* monthViewExceptPreviewPane = qobject_cast<HbWidget *> (
 						 mDocLoader->findWidget(CALEN_MONTHVIEW_EXCEPT_PANE));
     if (monthViewExceptPreviewPane) {
+        drawer = new HbFrameDrawer("qtg_fr_cal_monthgrid_bg", HbFrameDrawer::NinePieces);
         // The grid background
-        frame = new HbFrameItem(this);
-        frame->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
-
-        frame->frameDrawer().setFrameGraphicsName("qtg_fr_cal_monthgrid_bg");
+        frame = new HbFrameItem(drawer, this);
         monthViewExceptPreviewPane->setBackgroundItem(frame->graphicsItem(), -2);
     }
     if (mTitleLabel) {
         // The month title
-        frame = new HbFrameItem(this);
-        frame->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesHorizontal);
-
-        frame->frameDrawer().setFrameGraphicsName("qtg_fr_cal_monthgrid_title_bg");
-        mTitleLabel->setBackgroundItem(frame->graphicsItem(), -2);
+        drawer = new HbFrameDrawer("qtg_fr_cal_monthgrid_title_bg", HbFrameDrawer::ThreePiecesHorizontal);
+		if (drawer)
+        	frame = new HbFrameItem(drawer, this);
+		if(frame)
+			mTitleLabel->setBackgroundItem(frame->graphicsItem(), -2);
     }
     
     // Set the frame to the preview pane
-    frame = new HbFrameItem(this);
-    frame->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
-
-    frame->frameDrawer().setFrameGraphicsName("qtg_fr_cal_preview_bg");
-    mPrevPaneLayoutWidget->setBackgroundItem(frame->graphicsItem(), -5);
+    drawer = new HbFrameDrawer("qtg_fr_cal_preview_bg", HbFrameDrawer::NinePieces);
+	if (drawer)
+	    frame = new HbFrameItem(drawer, this);
+	if(frame)
+	    mPrevPaneLayoutWidget->setBackgroundItem(frame->graphicsItem(), -5);
     
     // Set the frame to the preview pane
-    frame = new HbFrameItem(this);
-    frame->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
-
-    frame->frameDrawer().setFrameGraphicsName("qtg_fr_cal_preview_bg");
+    drawer = new HbFrameDrawer("qtg_fr_cal_preview_bg", HbFrameDrawer::NinePieces);
+    if(drawer)
+	   frame = new HbFrameItem(drawer, this);
+	if(frame)
     mCurrPaneLayoutWidget->setBackgroundItem(frame->graphicsItem(), -5);
     
     // Set the frame to the preview pane
-    frame = new HbFrameItem(this);
-    frame->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
-
-    frame->frameDrawer().setFrameGraphicsName("qtg_fr_cal_preview_bg");
-    mNextPaneLayoutWidget->setBackgroundItem(frame->graphicsItem(), -5);
+    drawer = new HbFrameDrawer("qtg_fr_cal_preview_bg", HbFrameDrawer::NinePieces);
+	if(drawer)
+           frame = new HbFrameItem(drawer, this);
+	if(frame)
+	    mNextPaneLayoutWidget->setBackgroundItem(frame->graphicsItem(), -5);
 }
 
 void CalenMonthView::showHideRegionalInformation()
 {
-    XQSettingsKey regionalInfo(XQSettingsKey::TargetCentralRepository,
-                               KCRUidCalendar.iUid, KShowRegionalInformation);
-    
-    int showRegionalInfo = mSettingsManager->readItemValue(regionalInfo).toUInt();
-    if (showRegionalInfo) {
-		
-        // Add the regional information to the preview panes
-        if (!mPrevRegionalInfo) {
-            mPrevRegionalInfo = new CalenPluginLabel(mServices, this);
-            mPrevPaneLayout->insertItem(0, mPrevRegionalInfo);
+	if (pluginEnabled()) {
+		XQSettingsKey regionalInfo(XQSettingsKey::TargetCentralRepository,
+									KCRUidCalendar, KCalendarShowRegionalInfo);
+
+		int showRegionalInfo = 
+						mSettingsManager->readItemValue(regionalInfo).toUInt();
+		if (showRegionalInfo) {
+
+			// Add the regional information to the preview panes
+			if (!mPrevRegionalInfo) {
+				mPrevRegionalInfo = qobject_cast<CalenPluginLabel *> 
+				(mDocLoader->findWidget(CALEN_PREVREGIONALINFO));
+				mPrevRegionalInfo->show();
+				mPrevPaneLayout->insertItem(0, mPrevRegionalInfo);
 
-            HbFrameItem *frameCurr = new HbFrameItem(this);
-            frameCurr->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesHorizontal);
-            frameCurr->frameDrawer().setFrameGraphicsName("qtg_fr_cal_preview_title_bg");
-            mPrevRegionalInfo->setBackgroundItem(frameCurr->graphicsItem(), -2);
-        }
-        if (!mCurrRegionalInfo) {
-            mCurrRegionalInfo = new CalenPluginLabel(mServices, this);
-            mCurrPaneLayout->insertItem(0, mCurrRegionalInfo);
-            
-            HbFrameItem *frameCurr = new HbFrameItem(this);
-            frameCurr->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesHorizontal);
-            frameCurr->frameDrawer().setFrameGraphicsName("qtg_fr_cal_preview_title_bg");
-            mCurrRegionalInfo->setBackgroundItem(frameCurr->graphicsItem(), -2);
-        }
-        if (!mNextRegionalInfo) {
-            mNextRegionalInfo = new CalenPluginLabel(mServices, this);
-            mNextPaneLayout->insertItem(0, mNextRegionalInfo);
+				HbFrameItem *frameCurr = new HbFrameItem(this);
+				frameCurr->frameDrawer().setFrameType(
+										HbFrameDrawer::ThreePiecesHorizontal);
+				frameCurr->frameDrawer().setFrameGraphicsName(
+										"qtg_fr_cal_preview_title_bg");
+				mPrevRegionalInfo->setBackgroundItem(
+										frameCurr->graphicsItem(), -2);
+			}
+			if (!mCurrRegionalInfo) {
+				mCurrRegionalInfo = qobject_cast<CalenPluginLabel *> 
+				(mDocLoader->findWidget(CALEN_CURRREGIONALINFO));
+				mCurrRegionalInfo->show();
+				mCurrPaneLayout->insertItem(0, mCurrRegionalInfo);
 
-            HbFrameItem *frameCurr = new HbFrameItem(this);
-            frameCurr->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesHorizontal);
-            frameCurr->frameDrawer().setFrameGraphicsName("qtg_fr_cal_preview_title_bg");
-            mNextRegionalInfo->setBackgroundItem(frameCurr->graphicsItem(), -2);
-        }
-        
-        if (pluginEnabled()) {
+				HbFrameItem *frameCurr = new HbFrameItem(this);
+				frameCurr->frameDrawer().setFrameType(
+										HbFrameDrawer::ThreePiecesHorizontal);
+				frameCurr->frameDrawer().setFrameGraphicsName(
+										"qtg_fr_cal_preview_title_bg");
+				mCurrRegionalInfo->setBackgroundItem(
+										frameCurr->graphicsItem(), -2);
+			}
+			if (!mNextRegionalInfo) {
+				mNextRegionalInfo = qobject_cast<CalenPluginLabel *> 
+				(mDocLoader->findWidget(CALEN_NEXTREGIONALINFO));
+				mNextRegionalInfo->show();
+				mNextPaneLayout->insertItem(0, mNextRegionalInfo);
+
+				HbFrameItem *frameCurr = new HbFrameItem(this);
+				frameCurr->frameDrawer().setFrameType(
+										HbFrameDrawer::ThreePiecesHorizontal);
+				frameCurr->frameDrawer().setFrameGraphicsName(
+										"qtg_fr_cal_preview_title_bg");
+				mNextRegionalInfo->setBackgroundItem(
+										frameCurr->graphicsItem(), -2);
+			}
 			QString *pluginString = pluginText();
 			mPrevRegionalInfo->setPlainText(*pluginString);
 			mCurrRegionalInfo->setPlainText(*pluginString);
 			mNextRegionalInfo->setPlainText(*pluginString);
+		} else {
+			if (mPrevRegionalInfo) {
+				mPrevPaneLayout->removeItem(mPrevRegionalInfo);
+				mPrevRegionalInfo->hide();
+				mPrevRegionalInfo = NULL;
+			}
+			if (mCurrRegionalInfo) {
+				mPrevPaneLayout->removeItem(mCurrRegionalInfo);
+				mCurrRegionalInfo->hide();
+				mCurrRegionalInfo = NULL;
+			}
+			if (mNextRegionalInfo) {
+				mPrevPaneLayout->removeItem(mNextRegionalInfo);
+				mNextRegionalInfo->hide();
+				mNextRegionalInfo = NULL;
+			}
 		}
-    } else {
-        if (mPrevRegionalInfo) {
-            mPrevPaneLayout->removeItem(mPrevRegionalInfo);
-            delete mPrevRegionalInfo;
-            mPrevRegionalInfo = NULL;
-        }
-        if (mCurrRegionalInfo) {
-            mPrevPaneLayout->removeItem(mCurrRegionalInfo);
-            delete mCurrRegionalInfo;
-            mCurrRegionalInfo = NULL;
-        }
-        if (mNextRegionalInfo) {
-            mPrevPaneLayout->removeItem(mNextRegionalInfo);
-            delete mNextRegionalInfo;
-            mNextRegionalInfo = NULL;
-        }
-    }
+	}
 }
 
 /*!
@@ -529,29 +569,20 @@
 		long weekNumber(day.date().weekNumber());
 		mWeekNumbers.append(weekNumber);
 	}
-	
-	// Get the week day color from the theme
-	QColor weekDayColor = HbColorScheme::color("qtc_cal_week_day");
 
 	// Update the week labels text
 	QString text = QString::number(mWeekNumbers.at(0));
 	mFirstWeekLabel->setPlainText(text);
-	mFirstWeekLabel->setTextColor(weekDayColor);
 	text = QString::number(mWeekNumbers.at(1));
 	mSecondWeekLabel->setPlainText(text);
-	mSecondWeekLabel->setTextColor(weekDayColor);
 	text = QString::number(mWeekNumbers.at(2));
 	mThirdWeekLabel->setPlainText(text);
-	mThirdWeekLabel->setTextColor(weekDayColor);
 	text = QString::number(mWeekNumbers.at(3));
 	mFourthWeekLabel->setPlainText(text);
-	mFourthWeekLabel->setTextColor(weekDayColor);
 	text = QString::number(mWeekNumbers.at(4));
 	mFifthWeekLabel->setPlainText(text);
-	mFifthWeekLabel->setTextColor(weekDayColor);
 	text = QString::number(mWeekNumbers.at(5));
 	mSixthWeekLabel->setPlainText(text);
-	mSixthWeekLabel->setTextColor(weekDayColor);
 }
 
 /*!
@@ -560,24 +591,26 @@
 void CalenMonthView::goToToday()
 {
 	QDateTime today = CalenDateUtils::today();
+	// Set the context and repopulate the view
+    MCalenContext &context = mServices.Context();
+    context.setFocusDateAndTime(today);
+	    
 	// First check if we are not alread
 	// showing today's month view
 	if (mDate == today) {
 		return;
 	} else if (mActiveMonth.date().year() == today.date().year() && 
 				mActiveMonth.date().month() == today.date().month()) {
+        mDate = today;
 		// User is in current month only, so just set the focus to current
 		// date grid item and refresh the preview pane
 		int currIndex = mFirstDayOfGrid.daysTo(today);
 		setCurrGridIndex(currIndex);
-		return;
+		// Populate the preview panes
+		populatePreviewPane(mDate);
+	} else {	
+        refreshViewOnGoToDate();
 	}
-	
-	// Set the context and repopulate the view
-	MCalenContext &context = mServices.Context();
-	context.setFocusDateAndTimeL(today, KCalenMonthViewUidValue);
-	
-	refreshViewOnGoToDate();
 }
 
 /*
@@ -610,38 +643,62 @@
  */
 void CalenMonthView::doPopulation()
 {
-	if (!mIsFirstTimeLoad) {
-		Qt::Orientation orientation = mServices.MainWindow().orientation();
-		if (mOrientation != orientation) {
-			mOrientation = orientation;
-			handleChangeOrientation();
-		}
+
+ 	// Get the layout and add the preview pane layout.
+	QGraphicsLinearLayout* viewLayout = static_cast<QGraphicsLinearLayout *>
+														(widget()->layout());
+	if (viewLayout->count() == 1) {
+		// Count is 1 implies view has only month grid.
+		// Add the preview pane at corresponding position.
+		viewLayout->addItem(mCurrPaneParent);
 	}
-	mIsFirstTimeLoad = false;
+	
 	// prepare for the population like reading the date frm the context 
 	// calculating the start of the grid etc.,
 	prepareForPopulation();
-
-	// fetch list of required calendar instances
-	populateWithInstanceView();
-
-	populatePreviewPane(mDate);
-
-	// Create the grid items with proper dates
+	
+	// Populate the view and preview panes only if we are not opening the calendar
+	if (!mIsFirstTimeLoad) {
+		// fetch list of required calendar instances
+		populateWithInstanceView();
+		// Populate the preview panes
+		populatePreviewPane(mDate);
+	}
+	
+	
+    //update the day label 
+    //if changes in locale setting
+	updateDayLabel();
+	
+	  // Create the grid items with proper dates
 	createGrid();
 	
-	// Check if regional information needs to be shown
-	// and add it or remove it
-	showHideRegionalInformation();
 
 	// Complete the population
 	completePopulation();
 
+	//set Currect Activity to month view
+	mActivityId = ECalenMonthView;
+	
+	// connect to receive a call back on Month View exit. Call back would result in saveActivity 
+	// to be called in Native View.
+	if (!mIsAboutToQuitEventConnected) // check if not already connected
+	    {
+        connect(qobject_cast<HbApplication*>(qApp), SIGNAL(aboutToQuit()), this, SLOT(saveActivity()));
+        mIsAboutToQuitEventConnected = true;
+	    }
+	
+		
 	// Population is complete, inform it
 	populationComplete();
 	
-	// Start the auto scroll on current preview pane
-	mCurrPreviewPane->startAutoScroll();
+	// Handle regional data here if we are not populating the month view for
+	// the first time
+	if (!mIsFirstTimeLoad) {
+		showHideRegionalInformation();
+	}
+	// Reset the first time load flag
+	mIsFirstTimeLoad = false;
 }
 
 /*!
@@ -651,6 +708,7 @@
 {
 	setActiveDay(dateFromContext(mServices.Context()));
 	setDate();
+	updateMonthDataArrayWithActiveDates();
 }
 
 /*!
@@ -658,18 +716,19 @@
  */
 void CalenMonthView::refreshViewOnGoToDate()
 {
-	setActiveDay(dateFromContext(mServices.Context()));
-	setDate();
+	prepareForPopulation();
 	setDateToLabel();
 	// fetch list of required calendar instances
 	populateWithInstanceView();
 
 	populatePreviewPane(mDate);
 	
-	mMonthGrid->updateMonthGridModel(mMonthDataArray, mIndexToBeScrolled);
-	
-	// Start the auto scroll on current preview pane
-	mCurrPreviewPane->startAutoScroll();
+	mMonthGrid->updateMonthGridModel(mMonthDataArray, mIndexToBeScrolled, 
+	                                 mIsFirstTimeLoad);
+	// Update the week Numbers model
+	if (mIsWeekNumbersShown) {
+		updateWeekNumGridModel();
+	}
 }
 
 /*!
@@ -680,13 +739,13 @@
 	QDateTime ret;
 	if (AgendaEntry::TypeTodo == context.instanceId().mType) {
 		QDateTime today = CalenDateUtils::today();
-		if (context.focusDateAndTimeL() < today) {
+		if (context.focusDateAndTime() < today) {
 			ret = today;
 		} else {
-			ret = context.focusDateAndTimeL();
+			ret = context.focusDateAndTime();
 		}
 	} else {
-		ret = context.focusDateAndTimeL();
+		ret = context.focusDateAndTime();
 	}
 	return ret;
 }
@@ -708,8 +767,6 @@
 	date.setDate(date.year(), date.month(), 1);
 	QDateTime firstDayOfPrevMonth(date, day.time());
 
-	// TODO: Need to consider the week start frm the locale object
-	TLocale locale;
 	int offset(firstDayOfPrevMonth.date().dayOfWeek() - (mLocale.startOfWeek()
 	        + 1));
 	if (offset < 0) {
@@ -804,11 +861,22 @@
 void CalenMonthView::createGrid()
 {
 	// Update the month grid
-	mMonthGrid->updateMonthGridModel(mMonthDataArray, mIndexToBeScrolled);
-
-	// Read the week number setting from cenrep
-	QVariant value = mSettingsManager->readItemValue(*mWeekNumberCenrepKey);
-	mIsWeekNumbersShown = value.toUInt();
+	mMonthGrid->updateMonthGridModel(mMonthDataArray, mIndexToBeScrolled, 
+	                                 mIsFirstTimeLoad);
+    // Get start of week from the locale.
+    HbExtendedLocale locale = HbExtendedLocale::system();
+    int startOfWeek = locale.startOfWeek();
+    if(startOfWeek != HbExtendedLocale::Monday)
+        {
+        //if the start of week is other than Monday, don't show the week number
+        mIsWeekNumbersShown = 0;
+        }
+    else
+        {
+        // Read the week number setting from cenrep
+        QVariant value = mSettingsManager->readItemValue(*mWeekNumberCenrepKey);
+        mIsWeekNumbersShown = value.toUInt();
+        }
 	if (mIsWeekNumbersShown) {
 		// Add week numbers to week grid
 		addWeekNumbers();
@@ -905,7 +973,7 @@
 	date.setDate(date.year(), date.month(), 1);
 	// Get the first day of the future month
 	QDateTime firstDayOfFutMonth(date, futureMonthDateTime.time());
-	TLocale locale;
+
 	int offset = firstDayOfFutMonth.date().dayOfWeek() - (mLocale.startOfWeek()
 	        + 1);
 	if (offset < 0) {
@@ -1002,7 +1070,8 @@
 void CalenMonthView::updateMonthDataArrayWithActiveDates()
 {
 	int activeMonth = mActiveMonth.date().month();
-	for (int i = 0; i < mMonthDataArray.count(); i++) {
+	int monthDataCount = mMonthDataArray.count();
+	for (int i = 0; i < monthDataCount; i++) {
 		if (mMonthDataArray[i].Day().date().month() == activeMonth) {
 			// Set the active flag
 			mMonthDataArray[i].setActive(true);
@@ -1016,7 +1085,7 @@
 /*!
  Fetches the calenda entries for a given range
  */
-void CalenMonthView::getInstanceList(QList<AgendaEntry> &list,
+void CalenMonthView::getInstanceList(QList<QDate> &list,
                                      QDateTime rangeStart, QDateTime rangeEnd)
 {
 	AgendaUtil::FilterFlags filter =
@@ -1025,7 +1094,7 @@
 	                | AgendaUtil::IncludeEvents
 	                | AgendaUtil::IncludeReminders
 	                | AgendaUtil::IncludeIncompletedTodos);
-	list = mAgendaUtil->fetchEntriesInRange(rangeStart, rangeEnd, filter);
+	mAgendaUtil->markDatesWithEvents(rangeStart, rangeEnd, filter, list);
 }
 
 /*!
@@ -1040,21 +1109,14 @@
 	const int todayIndex(gridStart.daysTo(today)); 
 
 	QDateTime gridEnd(mLastDayOfGrid.date(), QTime(23, 59, 59, 0));
-	QList<AgendaEntry> list;
-
-	AgendaUtil::FilterFlags filter =
-		        AgendaUtil::FilterFlags(AgendaUtil::IncludeAnniversaries
-		                | AgendaUtil::IncludeAppointments
-		                | AgendaUtil::IncludeEvents
-		                | AgendaUtil::IncludeReminders
-		                | AgendaUtil::IncludeIncompletedTodos);
 	
 	// Get the list of dates which have events
 	QList<QDate> datesWithEvents;
-	mAgendaUtil->markDatesWithEvents(gridStart,gridEnd,filter,datesWithEvents);
+	getInstanceList(datesWithEvents,gridStart,gridEnd);
 	
 	// Parse thru the list of dates and set the required flags
-	for(int i(0); i < datesWithEvents.count(); i++) {
+	int datesEventsCount = datesWithEvents.count();
+	for(int i(0); i < datesEventsCount; i++) {
 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
 		mMonthDataArray[offset].SetHasEvents(true);
 	}
@@ -1068,7 +1130,6 @@
  */
 void CalenMonthView::populatePrevMonth()
 {
-	QList<AgendaEntry> list;
 	const QDateTime gridStart(CalenDateUtils::beginningOfDay(mFirstDayOfGrid));
 	const QDateTime today(CalenDateUtils::today());
 
@@ -1077,23 +1138,16 @@
 	QDateTime gridEnd(end.date(), QTime(23, 59, 59, 0));
 
 
-	AgendaUtil::FilterFlags filter =
-		        AgendaUtil::FilterFlags(AgendaUtil::IncludeAnniversaries
-		                | AgendaUtil::IncludeAppointments
-		                | AgendaUtil::IncludeEvents
-		                | AgendaUtil::IncludeReminders
-		                | AgendaUtil::IncludeIncompletedTodos);
-						
 	// Get the list of dates which have events
 	QList<QDate> datesWithEvents;
-	mAgendaUtil->markDatesWithEvents(gridStart,gridEnd,filter,datesWithEvents);
+	getInstanceList(datesWithEvents,gridStart,gridEnd);
 	
 	// Parse thru the list of dates and set the required flags
-	for(int i(0); i < datesWithEvents.count(); i++) {
+	int datesEventsCount = datesWithEvents.count();
+	for(int i(0); i < datesEventsCount; i++) {
 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
 		mMonthDataArray[offset].SetHasEvents(true);
 	}
-	
 	datesWithEvents.clear();
 }
 
@@ -1112,27 +1166,31 @@
 	const int todayIndex(gridStart.daysTo(today)); // grid index for "today"
 	QDateTime gridEnd(mLastDayOfGrid.date(), QTime(23, 59, 59, 0));
 
-
-	AgendaUtil::FilterFlags filter =
-		        AgendaUtil::FilterFlags(AgendaUtil::IncludeAnniversaries
-		                | AgendaUtil::IncludeAppointments
-		                | AgendaUtil::IncludeEvents
-		                | AgendaUtil::IncludeReminders
-		                | AgendaUtil::IncludeIncompletedTodos);
-						
 	// Get the list of dates which have events
 	QList<QDate> datesWithEvents;
-	mAgendaUtil->markDatesWithEvents(gridStart,gridEnd,filter,datesWithEvents);
+	getInstanceList(datesWithEvents,gridStart,gridEnd);
 	
 	// Parse thru the list of dates and set the required flags
-	for(int i(0); i < datesWithEvents.count(); i++) {
+	int datesEventsCount = datesWithEvents.count();
+	for(int i(0); i < datesEventsCount; i++) {
 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
 		mMonthDataArray[offset].SetHasEvents(true);
 	}
-
+	datesWithEvents.clear();
+}
 
-	
-	datesWithEvents.clear();
+/*!
+	Function that gets called when instacne view is created, so that it can
+	query agenda server for any entries
+ */
+void CalenMonthView::fetchEntriesAndUpdateModel()
+{
+	// Get to know if entries are there from the agenda server
+	populateWithInstanceView();
+	// Update the month grid model
+	mMonthGrid->updateMonthGridWithEventIndicators(mMonthDataArray);
+	// Populate the preview panes
+	populatePreviewPane(mDate);
 }
 
 /*!
@@ -1143,6 +1201,9 @@
 	mPrevPreviewPane->populateLabel(dateTime.addDays(-1));
 	mCurrPreviewPane->populateLabel(dateTime);
 	mNextPreviewPane->populateLabel(dateTime.addDays(1));
+	
+	// Start the auto scroll on current preview pane
+    mCurrPreviewPane->startAutoScroll();
 }
 
 /*!
@@ -1163,43 +1224,18 @@
 }
 
 /*!
- Handles the long press on a grid item
- */
-void CalenMonthView::handleGridItemLongPressed(int index, QPointF &coords)
-{
-	QDateTime newActiveDay = CalenDateUtils::futureOf(mFirstDayOfGrid, index);
-
-	// set the context
-	mServices.Context().setFocusDateL(newActiveDay, KCalenMonthViewUidValue);
-
-	HbMenu *contextMenu = new HbMenu(this);
-
-	connect(contextMenu->addAction(hbTrId("txt_common_menu_open")), SIGNAL( triggered() ), this,
-	        SLOT( launchDayView()));
-	// TODO: Add the text id
-	connect(contextMenu->addAction("New Todo"), SIGNAL( triggered() ), this,
-	        SLOT( createEditor()));
-
-	// Show context sensitive menu. 
-	// Param const QPointF& coordinate - is a longpress position.
-	contextMenu->exec(coords);
-}
-
-/*!
  Sets the context w.r.t to the active day
  */
 void CalenMonthView::setContextForActiveDay(int index)
 {
 	QDateTime newActiveDay = mFirstDayOfGrid.addDays(index);
 	// Set the context
-	mServices.Context().setFocusDateL(newActiveDay, KCalenMonthViewUidValue);
+	mServices.Context().setFocusDate(newActiveDay);
 	mDate = newActiveDay;
 	setDateToLabel();
 	
 	if(!mIsPrevPaneGesture) {
 		populatePreviewPane(mDate);
-		// Start the auto scroll on current preview pane
-		mCurrPreviewPane->startAutoScroll();
 	} else {
 		// reset flag
 		mIsPrevPaneGesture = false;
@@ -1216,11 +1252,18 @@
 }
 
 /*!
- Slot to launch the agenda view
+ Slot to launch the Day view
  */
 void CalenMonthView::launchDayView()
 {
 	mServices.IssueCommandL(ECalenDayView);
+	// day view launched now, disconnect to get the call backs for saveActivity 
+	// on aboutToQuit signal
+	if (mIsAboutToQuitEventConnected)
+	    {
+        disconnect(qobject_cast<HbApplication*>(qApp), SIGNAL(aboutToQuit()), this, SLOT(saveActivity()));
+        mIsAboutToQuitEventConnected = false;
+	    }
 }
 
 /*!
@@ -1228,13 +1271,11 @@
  */
 void CalenMonthView::changeOrientation(Qt::Orientation orientation)
 {
-	if (this == mServices.MainWindow().currentView()) {
 		if (mOrientation != orientation) {
 			// change the orientation here
 			mOrientation = orientation;
 			handleChangeOrientation();
 		}
-	}
 }
 
 /*!
@@ -1260,16 +1301,11 @@
 	QGraphicsLinearLayout* viewLayout = static_cast<QGraphicsLinearLayout *>
 													(widget()->layout());
 	viewLayout->removeAt(1);
-	viewLayout->addItem(mCurrPaneParent);
-	
-
-	// Check the weeknumber setting and update it accordingly
-	if (mIsWeekNumbersShown) {
-		// Add week numbers to week grid
-		addWeekNumbers();
-	} else {
-		// remove the weeknumbergrid from the layout
-		removeWeekNumbers();
+	// Add this item only when orientaion is changed on month view
+	// if it is changed in other views, adding the preview pane here was
+	// overlapping with the month grid, hence, its been added in dopopulation()
+	if (this == mServices.MainWindow().currentView()) {
+		viewLayout->addItem(mCurrPaneParent);
 	}
 }
 
@@ -1439,4 +1475,43 @@
 	mCurrPreviewPane->startAutoScroll();
 	mPrevPreviewPane->populateLabel(mDate.addDays(-1));
 }
+/*!
+ update the Day labels 
+ */
+void CalenMonthView::updateDayLabel()
+{
+    // Set the short day names to these labels  
+    int startOfWeek = mLocale.startOfWeek();
+    int weekDayIndex = startOfWeek;
+    QStringList  weekDayArray ;
+    weekDayArray <<hbTrId("txt_calendar_grid_day_mo")
+                           <<hbTrId("txt_calendar_grid_day_tu")
+                           <<hbTrId("txt_calendar_grid_day_we")
+                           <<hbTrId("txt_calendar_grid_day_th")
+                           <<hbTrId("txt_calendar_grid_day_fr")
+                           <<hbTrId("txt_calendar_grid_day_sa")
+                           <<hbTrId("txt_calendar_grid_day_su");
+            
+    QList<HbLabel*> labels;
+    // append seven day labels 
+    labels.append(mFirstDayLabel);
+    labels.append(mSecondDayLabel);
+    labels.append(mThirdDayLabel);
+    labels.append(mFourthDayLabel);
+    labels.append(mFifthDayLabel);
+    labels.append(mSixthDayLabel);
+    labels.append(mSeventhDayLabel);
+    for(int i=0;i < KCalenDaysInWeek; i++ )
+        {
+        labels.at(i)->setPlainText(weekDayArray[weekDayIndex]);
+        if(weekDayIndex == KCalenDaysInWeek - 1 )//Sunday
+            {
+            weekDayIndex = 0;//reset to monday
+            continue;
+            }
+        weekDayIndex++;//increase the index for next value
+        }
+    labels.clear();
+    weekDayArray.clear();
+}
 // End of file  --Don't remove this.