calendarui/views/src/calenmonthview.cpp
changeset 45 b6db4fd4947b
parent 23 fd30d51f876b
child 51 0b38fc5b94c6
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
    27 #include <hblabel.h>
    27 #include <hblabel.h>
    28 #include <hbframeitem.h>
    28 #include <hbframeitem.h>
    29 #include <hbcolorscheme.h>
    29 #include <hbcolorscheme.h>
    30 #include <agendautil.h>
    30 #include <agendautil.h>
    31 #include <agendaentry.h>
    31 #include <agendaentry.h>
       
    32 #include <hbapplication.h> // hbapplication
       
    33 #include <hbactivitymanager.h> //Activity Manager
    32 
    34 
    33 //user includes
    35 //user includes
    34 #include "calenmonthview.h"
    36 #include "calenmonthview.h"
    35 #include "calenservices.h"
    37 #include "calenservices.h"
    36 #include "calennativeview.h"
    38 #include "calennativeview.h"
    44 #include "calenmonthgrid.h"
    46 #include "calenmonthgrid.h"
    45 #include "calenpreviewpane.h"
    47 #include "calenpreviewpane.h"
    46 #include "calendocloader.h"
    48 #include "calendocloader.h"
    47 #include "calenthicklinesdrawer.h"
    49 #include "calenthicklinesdrawer.h"
    48 #include "calencommon.h"
    50 #include "calencommon.h"
    49 #include "CalendarInternalCRKeys.h"
    51 #include "calendarprivatecrkeys.h"
    50 #include "calenpluginlabel.h"
    52 #include "calenpluginlabel.h"
       
    53 #include "calenconstants.h"
    51 /*!
    54 /*!
    52  \class CalenMonthView
    55  \class CalenMonthView
    53 
    56 
    54  Class implementing calendar month view
    57  Class implementing calendar month view
    55  */
    58  */
    60 CalenMonthView::CalenMonthView(MCalenServices &services) :
    63 CalenMonthView::CalenMonthView(MCalenServices &services) :
    61 	CalenNativeView(services), mAgendaUtil(services.agendaInterface()), 
    64 	CalenNativeView(services), mAgendaUtil(services.agendaInterface()), 
    62 	mGoToTodayAction(0),
    65 	mGoToTodayAction(0),
    63 	mPrevRegionalInfo(0),
    66 	mPrevRegionalInfo(0),
    64 	mCurrRegionalInfo(0),
    67 	mCurrRegionalInfo(0),
    65 	mNextRegionalInfo(0)
    68 	mNextRegionalInfo(0),
       
    69 	mIsAboutToQuitEventConnected(false)
    66 {
    70 {
    67 	mIsWeekNumbersShown = 0;
    71 	mIsWeekNumbersShown = 0;
    68 	mOrientation = mServices.MainWindow().orientation();
    72 	mOrientation = mServices.MainWindow().orientation();
    69 	// Read the date from the context
    73 	// Read the date from the context
    70 	mDate = mServices.Context().focusDateAndTimeL();
    74 	mDate = mServices.Context().focusDateAndTime();
    71 	mCurrentDay = mDate;
    75 	mCurrentDay = mDate;
    72 
    76 
    73 	// Create the settings manager instance and settings key for week number
    77 	// Create the settings manager instance and settings key for week number
    74 	mSettingsManager = new XQSettingsManager(this);
    78 	mSettingsManager = new XQSettingsManager(this);
    75 	mWeekNumberCenrepKey
    79 	mWeekNumberCenrepKey
    76 	        = new XQSettingsKey(XQSettingsKey::TargetCentralRepository,
    80 	        = new XQSettingsKey(XQSettingsKey::TargetCentralRepository,
    77 	                            KCRUidCalendar.iUid, KCalendarWeekViewTitle);
    81 	                            KCRUidCalendar, KCalendarShowWeekNum);
    78 
    82 
    79 	mLocale = HbExtendedLocale::system();
    83 	mLocale = HbExtendedLocale::system();
    80 	mFirstWeekLabel = NULL;
    84 	mFirstWeekLabel = NULL;
    81 	mIsPrevPaneGesture = false;
    85 	mIsPrevPaneGesture = false;
       
    86 	// Get the week day color from the theme
       
    87 	mWeekDaysColor = HbColorScheme::color("qtc_cal_week_day");
    82 }
    88 }
    83 
    89 
    84 /*!
    90 /*!
    85  Destructor.
    91  Destructor.
    86  */
    92  */
    98 	mTitleLabel
   104 	mTitleLabel
    99 	        = qobject_cast<HbLabel *> (
   105 	        = qobject_cast<HbLabel *> (
   100 								   mDocLoader->findWidget(CALEN_MONTH_TITLE));
   106 								   mDocLoader->findWidget(CALEN_MONTH_TITLE));
   101 	// Set the title text color
   107 	// Set the title text color
   102 	QColor monthTitleColor = HbColorScheme::color("qtc_cal_monthgrid_title");
   108 	QColor monthTitleColor = HbColorScheme::color("qtc_cal_monthgrid_title");
   103 	if (monthTitleColor.isValid()) {
   109 	if (mTitleLabel && monthTitleColor.isValid()) {
   104 		mTitleLabel->setTextColor(monthTitleColor);
   110 		mTitleLabel->setTextColor(monthTitleColor);
   105 	}
   111 	}
   106 		
   112 		
   107 	mDayNameWidget
   113 	mDayNameWidget
   108 	        = qobject_cast<CalenThickLinesDrawer *> (
   114 	        = qobject_cast<CalenThickLinesDrawer *> (
   129 	        = qobject_cast<HbLabel *> (
   135 	        = qobject_cast<HbLabel *> (
   130 					   mDocLoader->findWidget(CALEN_MONTVIEW_SIXTH_DAY_LABEL));
   136 					   mDocLoader->findWidget(CALEN_MONTVIEW_SIXTH_DAY_LABEL));
   131 	mSeventhDayLabel
   137 	mSeventhDayLabel
   132 	        = qobject_cast<HbLabel *> (
   138 	        = qobject_cast<HbLabel *> (
   133 					mDocLoader->findWidget(CALEN_MONTVIEW_SEVENTH_DAY_LABEL));
   139 					mDocLoader->findWidget(CALEN_MONTVIEW_SEVENTH_DAY_LABEL));
   134 
       
   135 	// Set the short day names to these labels
       
   136 	// TODO: Need to read start of the week from the locale
       
   137 	// and update the labels accortdingly
       
   138 	int startOfDay = mLocale.startOfWeek();
       
   139 	mFirstDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_mo"));
       
   140 	mSecondDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_tu"));
       
   141 	mThirdDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_we"));
       
   142 	mFourthDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_th"));
       
   143 	mFifthDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_fr"));
       
   144 	mSixthDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_sa"));
       
   145 	mSeventhDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_su"));
       
   146 	
   140 	
   147 	// Get the weeknumber widget
   141 	// Get the weeknumber widget
   148 	mWeekNumberWidget
   142 	mWeekNumberWidget
   149 			= qobject_cast<CalenThickLinesDrawer *> (
   143 			= qobject_cast<CalenThickLinesDrawer *> (
   150 							 mDocLoader->findWidget(CALEN_WEEKNUMBERS_WIDGET));
   144 							 mDocLoader->findWidget(CALEN_WEEKNUMBERS_WIDGET));
   207 	        = qobject_cast<HbWidget *> (
   201 	        = qobject_cast<HbWidget *> (
   208 					mDocLoader->findWidget(CALEN_MONTHGRID_WEEKNUMBERS_WIDGET));
   202 					mDocLoader->findWidget(CALEN_MONTHGRID_WEEKNUMBERS_WIDGET));
   209 
   203 
   210 	mMonthGrid->setView(this);
   204 	mMonthGrid->setView(this);
   211 
   205 
       
   206 	
       
   207 	
       
   208 	mIsFirstTimeLoad = true;
       
   209 	// get a pointner to activity manager
       
   210 	HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
       
   211 
       
   212 	// clean up any previous versions of this activity, if any, i.e. activityName, from the activity manager. 
       
   213 	// Ignore return value, first boot would always return False. bool declared 
       
   214 	// only for debugging purpose.
       
   215 	bool ok = activityManager->removeActivity(activityName);
       
   216 
       
   217 }
       
   218 
       
   219 /*!
       
   220  Constructs the remaining part of the month view that was kept as 
       
   221  part if lazy loading
       
   222  */
       
   223 void CalenMonthView::doLazyLoading()
       
   224 {
       
   225 	// Add background items to all the widgets
       
   226 	addBackgroundFrame();
       
   227 	
       
   228 	// Construct and add the previous month and next month items to the view
       
   229 	mMonthGrid->updateMonthGridWithInActiveMonths(mMonthDataArray);
       
   230 	
       
   231 	// Check if regional information needs to be shown
       
   232 	// and add it or remove it
       
   233 	showHideRegionalInformation();
       
   234 	
   212 	// Connect to the menu actions
   235 	// Connect to the menu actions
   213 	HbAction
   236 	HbAction
   214 	        *newEventAction =
   237 			*newEventAction =
   215 	                qobject_cast<HbAction *> (
   238 					qobject_cast<HbAction *> (
   216 						mDocLoader->findObject(CALEN_MONTVIEW_MENU_NEWEVENT));
   239 						mDocLoader->findObject(CALEN_MONTVIEW_MENU_NEWEVENT));
   217 
   240 
   218 	connect(newEventAction, SIGNAL(triggered()), this, SLOT(createEditor()));
   241 	connect(newEventAction, SIGNAL(triggered()), this, SLOT(createEditor()));
   219 
   242 
   220 	mGoToTodayAction =
   243 	mGoToTodayAction =
   221 	                qobject_cast<HbAction *> (
   244 					qobject_cast<HbAction *> (
   222 							mDocLoader->findObject(CALEN_MONTVIEW_MENU_GOTOTODAY));
   245 							mDocLoader->findObject(CALEN_MONTVIEW_MENU_GOTOTODAY));
   223 	connect(mGoToTodayAction, SIGNAL(triggered()), this, SLOT(goToToday()));
   246 	connect(mGoToTodayAction, SIGNAL(triggered()), this, SLOT(goToToday()));
   224 	
   247 	
   225 	HbAction
   248 	HbAction
   226 	        *goToDateAction =
   249 			*goToDateAction =
   227 	                qobject_cast<HbAction *> (
   250 					qobject_cast<HbAction *> (
   228 						mDocLoader->findObject(CALEN_MONTVIEW_MENU_GOTODATE));
   251 						mDocLoader->findObject(CALEN_MONTVIEW_MENU_GOTODATE));
   229 
   252 
   230 	connect(goToDateAction, SIGNAL(triggered()), this, SLOT(goToDate()));
   253 	connect(goToDateAction, SIGNAL(triggered()), this, SLOT(goToDate()));
   231 
   254 
   232 	// TODO: Need to move this to docml
   255 	// TODO: Need to move this to docml
   267 	        SLOT(changeOrientation(Qt::Orientation)));
   290 	        SLOT(changeOrientation(Qt::Orientation)));
   268 	
   291 	
   269 	// Connect to the signal when options menu is shown
   292 	// Connect to the signal when options menu is shown
   270 	// This is required to add/remove dynamically some options
   293 	// This is required to add/remove dynamically some options
   271 	connect(menu(), SIGNAL(aboutToShow ()), this,
   294 	connect(menu(), SIGNAL(aboutToShow ()), this,
   272 	        SLOT(addRemoveActionsInMenu()));
   295 			SLOT(addRemoveActionsInMenu()));	
   273 	
       
   274 	mIsFirstTimeLoad = true;
       
   275 	
       
   276 	// Add background items to all the widgets
       
   277 	addBackgroundFrame();
       
   278 }
   296 }
   279 
   297 
   280 /*!
   298 /*!
   281  Adds the week numbers to the weeknumber widget
   299  Adds the week numbers to the weeknumber widget
   282  */
   300  */
   301 					mDocLoader->findWidget(CALEN_MONTVIEW_FIFTH_WEEK_LABEL));
   319 					mDocLoader->findWidget(CALEN_MONTVIEW_FIFTH_WEEK_LABEL));
   302 	mSixthWeekLabel
   320 	mSixthWeekLabel
   303 			= qobject_cast<HbLabel *> (
   321 			= qobject_cast<HbLabel *> (
   304 					mDocLoader->findWidget(CALEN_MONTVIEW_SIXTH_WEEK_LABEL));
   322 					mDocLoader->findWidget(CALEN_MONTVIEW_SIXTH_WEEK_LABEL));
   305 	}
   323 	}
   306 
   324 	
       
   325 	// Set the text colors well before instead of setting it again and again
       
   326 	mFirstWeekLabel->setTextColor(mWeekDaysColor);
       
   327 	mSecondWeekLabel->setTextColor(mWeekDaysColor);
       
   328 	mThirdWeekLabel->setTextColor(mWeekDaysColor);
       
   329 	mFourthWeekLabel->setTextColor(mWeekDaysColor);
       
   330 	mFifthWeekLabel->setTextColor(mWeekDaysColor);
       
   331 	mSixthWeekLabel->setTextColor(mWeekDaysColor);
       
   332 	
   307 	// Calculate the week numbers and set them to the week labels
   333 	// Calculate the week numbers and set them to the week labels
   308 	updateWeekNumGridModel();
   334 	updateWeekNumGridModel();
   309 
   335 
   310 	// Get the day names layout
   336 	// Get the day names layout
   311 	QGraphicsLinearLayout *dayNamesLayout =
   337 	QGraphicsLinearLayout *dayNamesLayout =
   390  */
   416  */
   391 void CalenMonthView::addBackgroundFrame()
   417 void CalenMonthView::addBackgroundFrame()
   392 {
   418 {
   393     // Set the background items for all the widgets
   419     // Set the background items for all the widgets
   394     HbFrameItem* frame = NULL;
   420     HbFrameItem* frame = NULL;
       
   421     HbFrameDrawer *drawer = NULL;
   395     HbWidget* monthViewExceptPreviewPane = qobject_cast<HbWidget *> (
   422     HbWidget* monthViewExceptPreviewPane = qobject_cast<HbWidget *> (
   396 						 mDocLoader->findWidget(CALEN_MONTHVIEW_EXCEPT_PANE));
   423 						 mDocLoader->findWidget(CALEN_MONTHVIEW_EXCEPT_PANE));
   397     if (monthViewExceptPreviewPane) {
   424     if (monthViewExceptPreviewPane) {
       
   425         drawer = new HbFrameDrawer("qtg_fr_cal_monthgrid_bg", HbFrameDrawer::NinePieces);
   398         // The grid background
   426         // The grid background
   399         frame = new HbFrameItem(this);
   427         frame = new HbFrameItem(drawer, this);
   400         frame->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
       
   401 
       
   402         frame->frameDrawer().setFrameGraphicsName("qtg_fr_cal_monthgrid_bg");
       
   403         monthViewExceptPreviewPane->setBackgroundItem(frame->graphicsItem(), -2);
   428         monthViewExceptPreviewPane->setBackgroundItem(frame->graphicsItem(), -2);
   404     }
   429     }
   405     if (mTitleLabel) {
   430     if (mTitleLabel) {
   406         // The month title
   431         // The month title
   407         frame = new HbFrameItem(this);
   432         drawer = new HbFrameDrawer("qtg_fr_cal_monthgrid_title_bg", HbFrameDrawer::ThreePiecesHorizontal);
   408         frame->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesHorizontal);
   433 		if (drawer)
   409 
   434         	frame = new HbFrameItem(drawer, this);
   410         frame->frameDrawer().setFrameGraphicsName("qtg_fr_cal_monthgrid_title_bg");
   435 		if(frame)
   411         mTitleLabel->setBackgroundItem(frame->graphicsItem(), -2);
   436 			mTitleLabel->setBackgroundItem(frame->graphicsItem(), -2);
   412     }
   437     }
   413     
   438     
   414     // Set the frame to the preview pane
   439     // Set the frame to the preview pane
   415     frame = new HbFrameItem(this);
   440     drawer = new HbFrameDrawer("qtg_fr_cal_preview_bg", HbFrameDrawer::NinePieces);
   416     frame->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
   441 	if (drawer)
   417 
   442 	    frame = new HbFrameItem(drawer, this);
   418     frame->frameDrawer().setFrameGraphicsName("qtg_fr_cal_preview_bg");
   443 	if(frame)
   419     mPrevPaneLayoutWidget->setBackgroundItem(frame->graphicsItem(), -5);
   444 	    mPrevPaneLayoutWidget->setBackgroundItem(frame->graphicsItem(), -5);
   420     
   445     
   421     // Set the frame to the preview pane
   446     // Set the frame to the preview pane
   422     frame = new HbFrameItem(this);
   447     drawer = new HbFrameDrawer("qtg_fr_cal_preview_bg", HbFrameDrawer::NinePieces);
   423     frame->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
   448     if(drawer)
   424 
   449 	   frame = new HbFrameItem(drawer, this);
   425     frame->frameDrawer().setFrameGraphicsName("qtg_fr_cal_preview_bg");
   450 	if(frame)
   426     mCurrPaneLayoutWidget->setBackgroundItem(frame->graphicsItem(), -5);
   451     mCurrPaneLayoutWidget->setBackgroundItem(frame->graphicsItem(), -5);
   427     
   452     
   428     // Set the frame to the preview pane
   453     // Set the frame to the preview pane
   429     frame = new HbFrameItem(this);
   454     drawer = new HbFrameDrawer("qtg_fr_cal_preview_bg", HbFrameDrawer::NinePieces);
   430     frame->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
   455 	if(drawer)
   431 
   456            frame = new HbFrameItem(drawer, this);
   432     frame->frameDrawer().setFrameGraphicsName("qtg_fr_cal_preview_bg");
   457 	if(frame)
   433     mNextPaneLayoutWidget->setBackgroundItem(frame->graphicsItem(), -5);
   458 	    mNextPaneLayoutWidget->setBackgroundItem(frame->graphicsItem(), -5);
   434 }
   459 }
   435 
   460 
   436 void CalenMonthView::showHideRegionalInformation()
   461 void CalenMonthView::showHideRegionalInformation()
   437 {
   462 {
   438     XQSettingsKey regionalInfo(XQSettingsKey::TargetCentralRepository,
   463 	if (pluginEnabled()) {
   439                                KCRUidCalendar.iUid, KShowRegionalInformation);
   464 		XQSettingsKey regionalInfo(XQSettingsKey::TargetCentralRepository,
   440     
   465 									KCRUidCalendar, KCalendarShowRegionalInfo);
   441     int showRegionalInfo = mSettingsManager->readItemValue(regionalInfo).toUInt();
   466 
   442     if (showRegionalInfo) {
   467 		int showRegionalInfo = 
   443 		
   468 						mSettingsManager->readItemValue(regionalInfo).toUInt();
   444         // Add the regional information to the preview panes
   469 		if (showRegionalInfo) {
   445         if (!mPrevRegionalInfo) {
   470 
   446             mPrevRegionalInfo = new CalenPluginLabel(mServices, this);
   471 			// Add the regional information to the preview panes
   447             mPrevPaneLayout->insertItem(0, mPrevRegionalInfo);
   472 			if (!mPrevRegionalInfo) {
   448 
   473 				mPrevRegionalInfo = qobject_cast<CalenPluginLabel *> 
   449             HbFrameItem *frameCurr = new HbFrameItem(this);
   474 				(mDocLoader->findWidget(CALEN_PREVREGIONALINFO));
   450             frameCurr->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesHorizontal);
   475 				mPrevRegionalInfo->show();
   451             frameCurr->frameDrawer().setFrameGraphicsName("qtg_fr_cal_preview_title_bg");
   476 				mPrevPaneLayout->insertItem(0, mPrevRegionalInfo);
   452             mPrevRegionalInfo->setBackgroundItem(frameCurr->graphicsItem(), -2);
   477 
   453         }
   478 				HbFrameItem *frameCurr = new HbFrameItem(this);
   454         if (!mCurrRegionalInfo) {
   479 				frameCurr->frameDrawer().setFrameType(
   455             mCurrRegionalInfo = new CalenPluginLabel(mServices, this);
   480 										HbFrameDrawer::ThreePiecesHorizontal);
   456             mCurrPaneLayout->insertItem(0, mCurrRegionalInfo);
   481 				frameCurr->frameDrawer().setFrameGraphicsName(
   457             
   482 										"qtg_fr_cal_preview_title_bg");
   458             HbFrameItem *frameCurr = new HbFrameItem(this);
   483 				mPrevRegionalInfo->setBackgroundItem(
   459             frameCurr->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesHorizontal);
   484 										frameCurr->graphicsItem(), -2);
   460             frameCurr->frameDrawer().setFrameGraphicsName("qtg_fr_cal_preview_title_bg");
   485 			}
   461             mCurrRegionalInfo->setBackgroundItem(frameCurr->graphicsItem(), -2);
   486 			if (!mCurrRegionalInfo) {
   462         }
   487 				mCurrRegionalInfo = qobject_cast<CalenPluginLabel *> 
   463         if (!mNextRegionalInfo) {
   488 				(mDocLoader->findWidget(CALEN_CURRREGIONALINFO));
   464             mNextRegionalInfo = new CalenPluginLabel(mServices, this);
   489 				mCurrRegionalInfo->show();
   465             mNextPaneLayout->insertItem(0, mNextRegionalInfo);
   490 				mCurrPaneLayout->insertItem(0, mCurrRegionalInfo);
   466 
   491 
   467             HbFrameItem *frameCurr = new HbFrameItem(this);
   492 				HbFrameItem *frameCurr = new HbFrameItem(this);
   468             frameCurr->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesHorizontal);
   493 				frameCurr->frameDrawer().setFrameType(
   469             frameCurr->frameDrawer().setFrameGraphicsName("qtg_fr_cal_preview_title_bg");
   494 										HbFrameDrawer::ThreePiecesHorizontal);
   470             mNextRegionalInfo->setBackgroundItem(frameCurr->graphicsItem(), -2);
   495 				frameCurr->frameDrawer().setFrameGraphicsName(
   471         }
   496 										"qtg_fr_cal_preview_title_bg");
   472         
   497 				mCurrRegionalInfo->setBackgroundItem(
   473         if (pluginEnabled()) {
   498 										frameCurr->graphicsItem(), -2);
       
   499 			}
       
   500 			if (!mNextRegionalInfo) {
       
   501 				mNextRegionalInfo = qobject_cast<CalenPluginLabel *> 
       
   502 				(mDocLoader->findWidget(CALEN_NEXTREGIONALINFO));
       
   503 				mNextRegionalInfo->show();
       
   504 				mNextPaneLayout->insertItem(0, mNextRegionalInfo);
       
   505 
       
   506 				HbFrameItem *frameCurr = new HbFrameItem(this);
       
   507 				frameCurr->frameDrawer().setFrameType(
       
   508 										HbFrameDrawer::ThreePiecesHorizontal);
       
   509 				frameCurr->frameDrawer().setFrameGraphicsName(
       
   510 										"qtg_fr_cal_preview_title_bg");
       
   511 				mNextRegionalInfo->setBackgroundItem(
       
   512 										frameCurr->graphicsItem(), -2);
       
   513 			}
   474 			QString *pluginString = pluginText();
   514 			QString *pluginString = pluginText();
   475 			mPrevRegionalInfo->setPlainText(*pluginString);
   515 			mPrevRegionalInfo->setPlainText(*pluginString);
   476 			mCurrRegionalInfo->setPlainText(*pluginString);
   516 			mCurrRegionalInfo->setPlainText(*pluginString);
   477 			mNextRegionalInfo->setPlainText(*pluginString);
   517 			mNextRegionalInfo->setPlainText(*pluginString);
       
   518 		} else {
       
   519 			if (mPrevRegionalInfo) {
       
   520 				mPrevPaneLayout->removeItem(mPrevRegionalInfo);
       
   521 				mPrevRegionalInfo->hide();
       
   522 				mPrevRegionalInfo = NULL;
       
   523 			}
       
   524 			if (mCurrRegionalInfo) {
       
   525 				mPrevPaneLayout->removeItem(mCurrRegionalInfo);
       
   526 				mCurrRegionalInfo->hide();
       
   527 				mCurrRegionalInfo = NULL;
       
   528 			}
       
   529 			if (mNextRegionalInfo) {
       
   530 				mPrevPaneLayout->removeItem(mNextRegionalInfo);
       
   531 				mNextRegionalInfo->hide();
       
   532 				mNextRegionalInfo = NULL;
       
   533 			}
   478 		}
   534 		}
   479     } else {
   535 	}
   480         if (mPrevRegionalInfo) {
       
   481             mPrevPaneLayout->removeItem(mPrevRegionalInfo);
       
   482             delete mPrevRegionalInfo;
       
   483             mPrevRegionalInfo = NULL;
       
   484         }
       
   485         if (mCurrRegionalInfo) {
       
   486             mPrevPaneLayout->removeItem(mCurrRegionalInfo);
       
   487             delete mCurrRegionalInfo;
       
   488             mCurrRegionalInfo = NULL;
       
   489         }
       
   490         if (mNextRegionalInfo) {
       
   491             mPrevPaneLayout->removeItem(mNextRegionalInfo);
       
   492             delete mNextRegionalInfo;
       
   493             mNextRegionalInfo = NULL;
       
   494         }
       
   495     }
       
   496 }
   536 }
   497 
   537 
   498 /*!
   538 /*!
   499  Handles the context changed notification
   539  Handles the context changed notification
   500  */
   540  */
   527 		// Get the week number
   567 		// Get the week number
   528 		QDateTime day = firstVisibleDate.addDays((KCalenDaysInWeek * i));
   568 		QDateTime day = firstVisibleDate.addDays((KCalenDaysInWeek * i));
   529 		long weekNumber(day.date().weekNumber());
   569 		long weekNumber(day.date().weekNumber());
   530 		mWeekNumbers.append(weekNumber);
   570 		mWeekNumbers.append(weekNumber);
   531 	}
   571 	}
   532 	
       
   533 	// Get the week day color from the theme
       
   534 	QColor weekDayColor = HbColorScheme::color("qtc_cal_week_day");
       
   535 
   572 
   536 	// Update the week labels text
   573 	// Update the week labels text
   537 	QString text = QString::number(mWeekNumbers.at(0));
   574 	QString text = QString::number(mWeekNumbers.at(0));
   538 	mFirstWeekLabel->setPlainText(text);
   575 	mFirstWeekLabel->setPlainText(text);
   539 	mFirstWeekLabel->setTextColor(weekDayColor);
       
   540 	text = QString::number(mWeekNumbers.at(1));
   576 	text = QString::number(mWeekNumbers.at(1));
   541 	mSecondWeekLabel->setPlainText(text);
   577 	mSecondWeekLabel->setPlainText(text);
   542 	mSecondWeekLabel->setTextColor(weekDayColor);
       
   543 	text = QString::number(mWeekNumbers.at(2));
   578 	text = QString::number(mWeekNumbers.at(2));
   544 	mThirdWeekLabel->setPlainText(text);
   579 	mThirdWeekLabel->setPlainText(text);
   545 	mThirdWeekLabel->setTextColor(weekDayColor);
       
   546 	text = QString::number(mWeekNumbers.at(3));
   580 	text = QString::number(mWeekNumbers.at(3));
   547 	mFourthWeekLabel->setPlainText(text);
   581 	mFourthWeekLabel->setPlainText(text);
   548 	mFourthWeekLabel->setTextColor(weekDayColor);
       
   549 	text = QString::number(mWeekNumbers.at(4));
   582 	text = QString::number(mWeekNumbers.at(4));
   550 	mFifthWeekLabel->setPlainText(text);
   583 	mFifthWeekLabel->setPlainText(text);
   551 	mFifthWeekLabel->setTextColor(weekDayColor);
       
   552 	text = QString::number(mWeekNumbers.at(5));
   584 	text = QString::number(mWeekNumbers.at(5));
   553 	mSixthWeekLabel->setPlainText(text);
   585 	mSixthWeekLabel->setPlainText(text);
   554 	mSixthWeekLabel->setTextColor(weekDayColor);
       
   555 }
   586 }
   556 
   587 
   557 /*!
   588 /*!
   558  Populates the month view with today as focussed item
   589  Populates the month view with today as focussed item
   559  */
   590  */
   560 void CalenMonthView::goToToday()
   591 void CalenMonthView::goToToday()
   561 {
   592 {
   562 	QDateTime today = CalenDateUtils::today();
   593 	QDateTime today = CalenDateUtils::today();
       
   594 	// Set the context and repopulate the view
       
   595     MCalenContext &context = mServices.Context();
       
   596     context.setFocusDateAndTime(today);
       
   597 	    
   563 	// First check if we are not alread
   598 	// First check if we are not alread
   564 	// showing today's month view
   599 	// showing today's month view
   565 	if (mDate == today) {
   600 	if (mDate == today) {
   566 		return;
   601 		return;
   567 	} else if (mActiveMonth.date().year() == today.date().year() && 
   602 	} else if (mActiveMonth.date().year() == today.date().year() && 
   568 				mActiveMonth.date().month() == today.date().month()) {
   603 				mActiveMonth.date().month() == today.date().month()) {
       
   604         mDate = today;
   569 		// User is in current month only, so just set the focus to current
   605 		// User is in current month only, so just set the focus to current
   570 		// date grid item and refresh the preview pane
   606 		// date grid item and refresh the preview pane
   571 		int currIndex = mFirstDayOfGrid.daysTo(today);
   607 		int currIndex = mFirstDayOfGrid.daysTo(today);
   572 		setCurrGridIndex(currIndex);
   608 		setCurrGridIndex(currIndex);
   573 		return;
   609 		// Populate the preview panes
   574 	}
   610 		populatePreviewPane(mDate);
   575 	
   611 	} else {	
   576 	// Set the context and repopulate the view
   612         refreshViewOnGoToDate();
   577 	MCalenContext &context = mServices.Context();
   613 	}
   578 	context.setFocusDateAndTimeL(today, KCalenMonthViewUidValue);
       
   579 	
       
   580 	refreshViewOnGoToDate();
       
   581 }
   614 }
   582 
   615 
   583 /*
   616 /*
   584  Slot to handle adding / removing actions frm the menu when menu is about to
   617  Slot to handle adding / removing actions frm the menu when menu is about to
   585  shown to the user
   618  shown to the user
   608 /*!
   641 /*!
   609  Populates the view
   642  Populates the view
   610  */
   643  */
   611 void CalenMonthView::doPopulation()
   644 void CalenMonthView::doPopulation()
   612 {
   645 {
   613 	if (!mIsFirstTimeLoad) {
   646 
   614 		Qt::Orientation orientation = mServices.MainWindow().orientation();
   647  	// Get the layout and add the preview pane layout.
   615 		if (mOrientation != orientation) {
   648 	QGraphicsLinearLayout* viewLayout = static_cast<QGraphicsLinearLayout *>
   616 			mOrientation = orientation;
   649 														(widget()->layout());
   617 			handleChangeOrientation();
   650 	if (viewLayout->count() == 1) {
   618 		}
   651 		// Count is 1 implies view has only month grid.
   619 	}
   652 		// Add the preview pane at corresponding position.
   620 	mIsFirstTimeLoad = false;
   653 		viewLayout->addItem(mCurrPaneParent);
       
   654 	}
       
   655 	
   621 	// prepare for the population like reading the date frm the context 
   656 	// prepare for the population like reading the date frm the context 
   622 	// calculating the start of the grid etc.,
   657 	// calculating the start of the grid etc.,
   623 	prepareForPopulation();
   658 	prepareForPopulation();
   624 
   659 	
   625 	// fetch list of required calendar instances
   660 	// Populate the view and preview panes only if we are not opening the calendar
   626 	populateWithInstanceView();
   661 	if (!mIsFirstTimeLoad) {
   627 
   662 		// fetch list of required calendar instances
   628 	populatePreviewPane(mDate);
   663 		populateWithInstanceView();
   629 
   664 		// Populate the preview panes
   630 	// Create the grid items with proper dates
   665 		populatePreviewPane(mDate);
       
   666 	}
       
   667 	
       
   668 	
       
   669     //update the day label 
       
   670     //if changes in locale setting
       
   671 	updateDayLabel();
       
   672 	
       
   673 	  // Create the grid items with proper dates
   631 	createGrid();
   674 	createGrid();
   632 	
   675 	
   633 	// Check if regional information needs to be shown
       
   634 	// and add it or remove it
       
   635 	showHideRegionalInformation();
       
   636 
   676 
   637 	// Complete the population
   677 	// Complete the population
   638 	completePopulation();
   678 	completePopulation();
   639 
   679 
       
   680 	//set Currect Activity to month view
       
   681 	mActivityId = ECalenMonthView;
       
   682 	
       
   683 	// connect to receive a call back on Month View exit. Call back would result in saveActivity 
       
   684 	// to be called in Native View.
       
   685 	if (!mIsAboutToQuitEventConnected) // check if not already connected
       
   686 	    {
       
   687         connect(qobject_cast<HbApplication*>(qApp), SIGNAL(aboutToQuit()), this, SLOT(saveActivity()));
       
   688         mIsAboutToQuitEventConnected = true;
       
   689 	    }
       
   690 	
       
   691 		
   640 	// Population is complete, inform it
   692 	// Population is complete, inform it
   641 	populationComplete();
   693 	populationComplete();
   642 	
   694 	
   643 	// Start the auto scroll on current preview pane
   695 	// Handle regional data here if we are not populating the month view for
   644 	mCurrPreviewPane->startAutoScroll();
   696 	// the first time
       
   697 	if (!mIsFirstTimeLoad) {
       
   698 		showHideRegionalInformation();
       
   699 	}
       
   700 	// Reset the first time load flag
       
   701 	mIsFirstTimeLoad = false;
   645 }
   702 }
   646 
   703 
   647 /*!
   704 /*!
   648  Reads the date from the context and calculates the grid item dates
   705  Reads the date from the context and calculates the grid item dates
   649  */
   706  */
   650 void CalenMonthView::prepareForPopulation()
   707 void CalenMonthView::prepareForPopulation()
   651 {
   708 {
   652 	setActiveDay(dateFromContext(mServices.Context()));
   709 	setActiveDay(dateFromContext(mServices.Context()));
   653 	setDate();
   710 	setDate();
       
   711 	updateMonthDataArrayWithActiveDates();
   654 }
   712 }
   655 
   713 
   656 /*!
   714 /*!
   657  Slot to handle gotodate action
   715  Slot to handle gotodate action
   658  */
   716  */
   659 void CalenMonthView::refreshViewOnGoToDate()
   717 void CalenMonthView::refreshViewOnGoToDate()
   660 {
   718 {
   661 	setActiveDay(dateFromContext(mServices.Context()));
   719 	prepareForPopulation();
   662 	setDate();
       
   663 	setDateToLabel();
   720 	setDateToLabel();
   664 	// fetch list of required calendar instances
   721 	// fetch list of required calendar instances
   665 	populateWithInstanceView();
   722 	populateWithInstanceView();
   666 
   723 
   667 	populatePreviewPane(mDate);
   724 	populatePreviewPane(mDate);
   668 	
   725 	
   669 	mMonthGrid->updateMonthGridModel(mMonthDataArray, mIndexToBeScrolled);
   726 	mMonthGrid->updateMonthGridModel(mMonthDataArray, mIndexToBeScrolled, 
   670 	
   727 	                                 mIsFirstTimeLoad);
   671 	// Start the auto scroll on current preview pane
   728 	// Update the week Numbers model
   672 	mCurrPreviewPane->startAutoScroll();
   729 	if (mIsWeekNumbersShown) {
       
   730 		updateWeekNumGridModel();
       
   731 	}
   673 }
   732 }
   674 
   733 
   675 /*!
   734 /*!
   676  Reads the date from the context and stores into mDate
   735  Reads the date from the context and stores into mDate
   677  */
   736  */
   678 QDateTime CalenMonthView::dateFromContext(const MCalenContext &context)
   737 QDateTime CalenMonthView::dateFromContext(const MCalenContext &context)
   679 {
   738 {
   680 	QDateTime ret;
   739 	QDateTime ret;
   681 	if (AgendaEntry::TypeTodo == context.instanceId().mType) {
   740 	if (AgendaEntry::TypeTodo == context.instanceId().mType) {
   682 		QDateTime today = CalenDateUtils::today();
   741 		QDateTime today = CalenDateUtils::today();
   683 		if (context.focusDateAndTimeL() < today) {
   742 		if (context.focusDateAndTime() < today) {
   684 			ret = today;
   743 			ret = today;
   685 		} else {
   744 		} else {
   686 			ret = context.focusDateAndTimeL();
   745 			ret = context.focusDateAndTime();
   687 		}
   746 		}
   688 	} else {
   747 	} else {
   689 		ret = context.focusDateAndTimeL();
   748 		ret = context.focusDateAndTime();
   690 	}
   749 	}
   691 	return ret;
   750 	return ret;
   692 }
   751 }
   693 
   752 
   694 /*!
   753 /*!
   706 	// Get the first day of the month
   765 	// Get the first day of the month
   707 	QDate date = prevMonthDate.date();
   766 	QDate date = prevMonthDate.date();
   708 	date.setDate(date.year(), date.month(), 1);
   767 	date.setDate(date.year(), date.month(), 1);
   709 	QDateTime firstDayOfPrevMonth(date, day.time());
   768 	QDateTime firstDayOfPrevMonth(date, day.time());
   710 
   769 
   711 	// TODO: Need to consider the week start frm the locale object
       
   712 	TLocale locale;
       
   713 	int offset(firstDayOfPrevMonth.date().dayOfWeek() - (mLocale.startOfWeek()
   770 	int offset(firstDayOfPrevMonth.date().dayOfWeek() - (mLocale.startOfWeek()
   714 	        + 1));
   771 	        + 1));
   715 	if (offset < 0) {
   772 	if (offset < 0) {
   716 		offset += KCalenDaysInWeek;
   773 		offset += KCalenDaysInWeek;
   717 	}
   774 	}
   802  Creates the grid and adds the week numbers depending on the week number setting
   859  Creates the grid and adds the week numbers depending on the week number setting
   803  */
   860  */
   804 void CalenMonthView::createGrid()
   861 void CalenMonthView::createGrid()
   805 {
   862 {
   806 	// Update the month grid
   863 	// Update the month grid
   807 	mMonthGrid->updateMonthGridModel(mMonthDataArray, mIndexToBeScrolled);
   864 	mMonthGrid->updateMonthGridModel(mMonthDataArray, mIndexToBeScrolled, 
   808 
   865 	                                 mIsFirstTimeLoad);
   809 	// Read the week number setting from cenrep
   866     // Get start of week from the locale.
   810 	QVariant value = mSettingsManager->readItemValue(*mWeekNumberCenrepKey);
   867     HbExtendedLocale locale = HbExtendedLocale::system();
   811 	mIsWeekNumbersShown = value.toUInt();
   868     int startOfWeek = locale.startOfWeek();
       
   869     if(startOfWeek != HbExtendedLocale::Monday)
       
   870         {
       
   871         //if the start of week is other than Monday, don't show the week number
       
   872         mIsWeekNumbersShown = 0;
       
   873         }
       
   874     else
       
   875         {
       
   876         // Read the week number setting from cenrep
       
   877         QVariant value = mSettingsManager->readItemValue(*mWeekNumberCenrepKey);
       
   878         mIsWeekNumbersShown = value.toUInt();
       
   879         }
   812 	if (mIsWeekNumbersShown) {
   880 	if (mIsWeekNumbersShown) {
   813 		// Add week numbers to week grid
   881 		// Add week numbers to week grid
   814 		addWeekNumbers();
   882 		addWeekNumbers();
   815 	} else {
   883 	} else {
   816 		// remove the weeknumbergrid from the layout
   884 		// remove the weeknumbergrid from the layout
   903 	QDateTime futureMonthDateTime = mActiveMonth.addMonths(2);
   971 	QDateTime futureMonthDateTime = mActiveMonth.addMonths(2);
   904 	QDate date = futureMonthDateTime.date();
   972 	QDate date = futureMonthDateTime.date();
   905 	date.setDate(date.year(), date.month(), 1);
   973 	date.setDate(date.year(), date.month(), 1);
   906 	// Get the first day of the future month
   974 	// Get the first day of the future month
   907 	QDateTime firstDayOfFutMonth(date, futureMonthDateTime.time());
   975 	QDateTime firstDayOfFutMonth(date, futureMonthDateTime.time());
   908 	TLocale locale;
   976 
   909 	int offset = firstDayOfFutMonth.date().dayOfWeek() - (mLocale.startOfWeek()
   977 	int offset = firstDayOfFutMonth.date().dayOfWeek() - (mLocale.startOfWeek()
   910 	        + 1);
   978 	        + 1);
   911 	if (offset < 0) {
   979 	if (offset < 0) {
   912 		offset += KCalenDaysInWeek;
   980 		offset += KCalenDaysInWeek;
   913 	}
   981 	}
  1000  Sets the active flag to the required dates in the array
  1068  Sets the active flag to the required dates in the array
  1001  */
  1069  */
  1002 void CalenMonthView::updateMonthDataArrayWithActiveDates()
  1070 void CalenMonthView::updateMonthDataArrayWithActiveDates()
  1003 {
  1071 {
  1004 	int activeMonth = mActiveMonth.date().month();
  1072 	int activeMonth = mActiveMonth.date().month();
  1005 	for (int i = 0; i < mMonthDataArray.count(); i++) {
  1073 	int monthDataCount = mMonthDataArray.count();
       
  1074 	for (int i = 0; i < monthDataCount; i++) {
  1006 		if (mMonthDataArray[i].Day().date().month() == activeMonth) {
  1075 		if (mMonthDataArray[i].Day().date().month() == activeMonth) {
  1007 			// Set the active flag
  1076 			// Set the active flag
  1008 			mMonthDataArray[i].setActive(true);
  1077 			mMonthDataArray[i].setActive(true);
  1009 		} else {
  1078 		} else {
  1010 			// Disable the active flag
  1079 			// Disable the active flag
  1014 }
  1083 }
  1015 
  1084 
  1016 /*!
  1085 /*!
  1017  Fetches the calenda entries for a given range
  1086  Fetches the calenda entries for a given range
  1018  */
  1087  */
  1019 void CalenMonthView::getInstanceList(QList<AgendaEntry> &list,
  1088 void CalenMonthView::getInstanceList(QList<QDate> &list,
  1020                                      QDateTime rangeStart, QDateTime rangeEnd)
  1089                                      QDateTime rangeStart, QDateTime rangeEnd)
  1021 {
  1090 {
  1022 	AgendaUtil::FilterFlags filter =
  1091 	AgendaUtil::FilterFlags filter =
  1023 	        AgendaUtil::FilterFlags(AgendaUtil::IncludeAnniversaries
  1092 	        AgendaUtil::FilterFlags(AgendaUtil::IncludeAnniversaries
  1024 	                | AgendaUtil::IncludeAppointments
  1093 	                | AgendaUtil::IncludeAppointments
  1025 	                | AgendaUtil::IncludeEvents
  1094 	                | AgendaUtil::IncludeEvents
  1026 	                | AgendaUtil::IncludeReminders
  1095 	                | AgendaUtil::IncludeReminders
  1027 	                | AgendaUtil::IncludeIncompletedTodos);
  1096 	                | AgendaUtil::IncludeIncompletedTodos);
  1028 	list = mAgendaUtil->fetchEntriesInRange(rangeStart, rangeEnd, filter);
  1097 	mAgendaUtil->markDatesWithEvents(rangeStart, rangeEnd, filter, list);
  1029 }
  1098 }
  1030 
  1099 
  1031 /*!
  1100 /*!
  1032  Parses the fetched entries and sets hasEvent attribute for necessary days
  1101  Parses the fetched entries and sets hasEvent attribute for necessary days
  1033  */
  1102  */
  1038 
  1107 
  1039 	// grid index for "today"
  1108 	// grid index for "today"
  1040 	const int todayIndex(gridStart.daysTo(today)); 
  1109 	const int todayIndex(gridStart.daysTo(today)); 
  1041 
  1110 
  1042 	QDateTime gridEnd(mLastDayOfGrid.date(), QTime(23, 59, 59, 0));
  1111 	QDateTime gridEnd(mLastDayOfGrid.date(), QTime(23, 59, 59, 0));
  1043 	QList<AgendaEntry> list;
       
  1044 
       
  1045 	AgendaUtil::FilterFlags filter =
       
  1046 		        AgendaUtil::FilterFlags(AgendaUtil::IncludeAnniversaries
       
  1047 		                | AgendaUtil::IncludeAppointments
       
  1048 		                | AgendaUtil::IncludeEvents
       
  1049 		                | AgendaUtil::IncludeReminders
       
  1050 		                | AgendaUtil::IncludeIncompletedTodos);
       
  1051 	
  1112 	
  1052 	// Get the list of dates which have events
  1113 	// Get the list of dates which have events
  1053 	QList<QDate> datesWithEvents;
  1114 	QList<QDate> datesWithEvents;
  1054 	mAgendaUtil->markDatesWithEvents(gridStart,gridEnd,filter,datesWithEvents);
  1115 	getInstanceList(datesWithEvents,gridStart,gridEnd);
  1055 	
  1116 	
  1056 	// Parse thru the list of dates and set the required flags
  1117 	// Parse thru the list of dates and set the required flags
  1057 	for(int i(0); i < datesWithEvents.count(); i++) {
  1118 	int datesEventsCount = datesWithEvents.count();
       
  1119 	for(int i(0); i < datesEventsCount; i++) {
  1058 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
  1120 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
  1059 		mMonthDataArray[offset].SetHasEvents(true);
  1121 		mMonthDataArray[offset].SetHasEvents(true);
  1060 	}
  1122 	}
  1061 
  1123 
  1062 	datesWithEvents.clear();
  1124 	datesWithEvents.clear();
  1066  Parses the fetched entries for previous month and 
  1128  Parses the fetched entries for previous month and 
  1067  sets hasEvent attribute for necessary days
  1129  sets hasEvent attribute for necessary days
  1068  */
  1130  */
  1069 void CalenMonthView::populatePrevMonth()
  1131 void CalenMonthView::populatePrevMonth()
  1070 {
  1132 {
  1071 	QList<AgendaEntry> list;
       
  1072 	const QDateTime gridStart(CalenDateUtils::beginningOfDay(mFirstDayOfGrid));
  1133 	const QDateTime gridStart(CalenDateUtils::beginningOfDay(mFirstDayOfGrid));
  1073 	const QDateTime today(CalenDateUtils::today());
  1134 	const QDateTime today(CalenDateUtils::today());
  1074 
  1135 
  1075 	const int todayIndex(gridStart.daysTo(today)); // grid index for "today"
  1136 	const int todayIndex(gridStart.daysTo(today)); // grid index for "today"
  1076 	QDateTime end = gridStart.addDays(mNumOfRowsInPrevMonth * KCalenDaysInWeek);
  1137 	QDateTime end = gridStart.addDays(mNumOfRowsInPrevMonth * KCalenDaysInWeek);
  1077 	QDateTime gridEnd(end.date(), QTime(23, 59, 59, 0));
  1138 	QDateTime gridEnd(end.date(), QTime(23, 59, 59, 0));
  1078 
  1139 
  1079 
  1140 
  1080 	AgendaUtil::FilterFlags filter =
       
  1081 		        AgendaUtil::FilterFlags(AgendaUtil::IncludeAnniversaries
       
  1082 		                | AgendaUtil::IncludeAppointments
       
  1083 		                | AgendaUtil::IncludeEvents
       
  1084 		                | AgendaUtil::IncludeReminders
       
  1085 		                | AgendaUtil::IncludeIncompletedTodos);
       
  1086 						
       
  1087 	// Get the list of dates which have events
  1141 	// Get the list of dates which have events
  1088 	QList<QDate> datesWithEvents;
  1142 	QList<QDate> datesWithEvents;
  1089 	mAgendaUtil->markDatesWithEvents(gridStart,gridEnd,filter,datesWithEvents);
  1143 	getInstanceList(datesWithEvents,gridStart,gridEnd);
  1090 	
  1144 	
  1091 	// Parse thru the list of dates and set the required flags
  1145 	// Parse thru the list of dates and set the required flags
  1092 	for(int i(0); i < datesWithEvents.count(); i++) {
  1146 	int datesEventsCount = datesWithEvents.count();
       
  1147 	for(int i(0); i < datesEventsCount; i++) {
  1093 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
  1148 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
  1094 		mMonthDataArray[offset].SetHasEvents(true);
  1149 		mMonthDataArray[offset].SetHasEvents(true);
  1095 	}
  1150 	}
  1096 	
       
  1097 	datesWithEvents.clear();
  1151 	datesWithEvents.clear();
  1098 }
  1152 }
  1099 
  1153 
  1100 /*!
  1154 /*!
  1101  Parses the fetched entries for future month and 
  1155  Parses the fetched entries for future month and 
  1110 	
  1164 	
  1111 	const QDateTime today(CalenDateUtils::today());
  1165 	const QDateTime today(CalenDateUtils::today());
  1112 	const int todayIndex(gridStart.daysTo(today)); // grid index for "today"
  1166 	const int todayIndex(gridStart.daysTo(today)); // grid index for "today"
  1113 	QDateTime gridEnd(mLastDayOfGrid.date(), QTime(23, 59, 59, 0));
  1167 	QDateTime gridEnd(mLastDayOfGrid.date(), QTime(23, 59, 59, 0));
  1114 
  1168 
  1115 
       
  1116 	AgendaUtil::FilterFlags filter =
       
  1117 		        AgendaUtil::FilterFlags(AgendaUtil::IncludeAnniversaries
       
  1118 		                | AgendaUtil::IncludeAppointments
       
  1119 		                | AgendaUtil::IncludeEvents
       
  1120 		                | AgendaUtil::IncludeReminders
       
  1121 		                | AgendaUtil::IncludeIncompletedTodos);
       
  1122 						
       
  1123 	// Get the list of dates which have events
  1169 	// Get the list of dates which have events
  1124 	QList<QDate> datesWithEvents;
  1170 	QList<QDate> datesWithEvents;
  1125 	mAgendaUtil->markDatesWithEvents(gridStart,gridEnd,filter,datesWithEvents);
  1171 	getInstanceList(datesWithEvents,gridStart,gridEnd);
  1126 	
  1172 	
  1127 	// Parse thru the list of dates and set the required flags
  1173 	// Parse thru the list of dates and set the required flags
  1128 	for(int i(0); i < datesWithEvents.count(); i++) {
  1174 	int datesEventsCount = datesWithEvents.count();
       
  1175 	for(int i(0); i < datesEventsCount; i++) {
  1129 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
  1176 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
  1130 		mMonthDataArray[offset].SetHasEvents(true);
  1177 		mMonthDataArray[offset].SetHasEvents(true);
  1131 	}
  1178 	}
  1132 
       
  1133 
       
  1134 	
       
  1135 	datesWithEvents.clear();
  1179 	datesWithEvents.clear();
       
  1180 }
       
  1181 
       
  1182 /*!
       
  1183 	Function that gets called when instacne view is created, so that it can
       
  1184 	query agenda server for any entries
       
  1185  */
       
  1186 void CalenMonthView::fetchEntriesAndUpdateModel()
       
  1187 {
       
  1188 	// Get to know if entries are there from the agenda server
       
  1189 	populateWithInstanceView();
       
  1190 	// Update the month grid model
       
  1191 	mMonthGrid->updateMonthGridWithEventIndicators(mMonthDataArray);
       
  1192 	// Populate the preview panes
       
  1193 	populatePreviewPane(mDate);
  1136 }
  1194 }
  1137 
  1195 
  1138 /*!
  1196 /*!
  1139  Populates the preview pane
  1197  Populates the preview pane
  1140  */
  1198  */
  1141 void CalenMonthView::populatePreviewPane(QDateTime &dateTime)
  1199 void CalenMonthView::populatePreviewPane(QDateTime &dateTime)
  1142 {
  1200 {
  1143 	mPrevPreviewPane->populateLabel(dateTime.addDays(-1));
  1201 	mPrevPreviewPane->populateLabel(dateTime.addDays(-1));
  1144 	mCurrPreviewPane->populateLabel(dateTime);
  1202 	mCurrPreviewPane->populateLabel(dateTime);
  1145 	mNextPreviewPane->populateLabel(dateTime.addDays(1));
  1203 	mNextPreviewPane->populateLabel(dateTime.addDays(1));
       
  1204 	
       
  1205 	// Start the auto scroll on current preview pane
       
  1206     mCurrPreviewPane->startAutoScroll();
  1146 }
  1207 }
  1147 
  1208 
  1148 /*!
  1209 /*!
  1149  Completes the population after setting the view as 
  1210  Completes the population after setting the view as 
  1150  current view to the main window
  1211  current view to the main window
  1161 {
  1222 {
  1162 	mServices.IssueCommandL(ECalenDayView);
  1223 	mServices.IssueCommandL(ECalenDayView);
  1163 }
  1224 }
  1164 
  1225 
  1165 /*!
  1226 /*!
  1166  Handles the long press on a grid item
       
  1167  */
       
  1168 void CalenMonthView::handleGridItemLongPressed(int index, QPointF &coords)
       
  1169 {
       
  1170 	QDateTime newActiveDay = CalenDateUtils::futureOf(mFirstDayOfGrid, index);
       
  1171 
       
  1172 	// set the context
       
  1173 	mServices.Context().setFocusDateL(newActiveDay, KCalenMonthViewUidValue);
       
  1174 
       
  1175 	HbMenu *contextMenu = new HbMenu(this);
       
  1176 
       
  1177 	connect(contextMenu->addAction(hbTrId("txt_common_menu_open")), SIGNAL( triggered() ), this,
       
  1178 	        SLOT( launchDayView()));
       
  1179 	// TODO: Add the text id
       
  1180 	connect(contextMenu->addAction("New Todo"), SIGNAL( triggered() ), this,
       
  1181 	        SLOT( createEditor()));
       
  1182 
       
  1183 	// Show context sensitive menu. 
       
  1184 	// Param const QPointF& coordinate - is a longpress position.
       
  1185 	contextMenu->exec(coords);
       
  1186 }
       
  1187 
       
  1188 /*!
       
  1189  Sets the context w.r.t to the active day
  1227  Sets the context w.r.t to the active day
  1190  */
  1228  */
  1191 void CalenMonthView::setContextForActiveDay(int index)
  1229 void CalenMonthView::setContextForActiveDay(int index)
  1192 {
  1230 {
  1193 	QDateTime newActiveDay = mFirstDayOfGrid.addDays(index);
  1231 	QDateTime newActiveDay = mFirstDayOfGrid.addDays(index);
  1194 	// Set the context
  1232 	// Set the context
  1195 	mServices.Context().setFocusDateL(newActiveDay, KCalenMonthViewUidValue);
  1233 	mServices.Context().setFocusDate(newActiveDay);
  1196 	mDate = newActiveDay;
  1234 	mDate = newActiveDay;
  1197 	setDateToLabel();
  1235 	setDateToLabel();
  1198 	
  1236 	
  1199 	if(!mIsPrevPaneGesture) {
  1237 	if(!mIsPrevPaneGesture) {
  1200 		populatePreviewPane(mDate);
  1238 		populatePreviewPane(mDate);
  1201 		// Start the auto scroll on current preview pane
       
  1202 		mCurrPreviewPane->startAutoScroll();
       
  1203 	} else {
  1239 	} else {
  1204 		// reset flag
  1240 		// reset flag
  1205 		mIsPrevPaneGesture = false;
  1241 		mIsPrevPaneGesture = false;
  1206 	}
  1242 	}
  1207 	
  1243 	
  1214 {
  1250 {
  1215 	mServices.IssueCommandL(ECalenNewMeeting);
  1251 	mServices.IssueCommandL(ECalenNewMeeting);
  1216 }
  1252 }
  1217 
  1253 
  1218 /*!
  1254 /*!
  1219  Slot to launch the agenda view
  1255  Slot to launch the Day view
  1220  */
  1256  */
  1221 void CalenMonthView::launchDayView()
  1257 void CalenMonthView::launchDayView()
  1222 {
  1258 {
  1223 	mServices.IssueCommandL(ECalenDayView);
  1259 	mServices.IssueCommandL(ECalenDayView);
       
  1260 	// day view launched now, disconnect to get the call backs for saveActivity 
       
  1261 	// on aboutToQuit signal
       
  1262 	if (mIsAboutToQuitEventConnected)
       
  1263 	    {
       
  1264         disconnect(qobject_cast<HbApplication*>(qApp), SIGNAL(aboutToQuit()), this, SLOT(saveActivity()));
       
  1265         mIsAboutToQuitEventConnected = false;
       
  1266 	    }
  1224 }
  1267 }
  1225 
  1268 
  1226 /*!
  1269 /*!
  1227  Slot to handle the change in orientation
  1270  Slot to handle the change in orientation
  1228  */
  1271  */
  1229 void CalenMonthView::changeOrientation(Qt::Orientation orientation)
  1272 void CalenMonthView::changeOrientation(Qt::Orientation orientation)
  1230 {
  1273 {
  1231 	if (this == mServices.MainWindow().currentView()) {
       
  1232 		if (mOrientation != orientation) {
  1274 		if (mOrientation != orientation) {
  1233 			// change the orientation here
  1275 			// change the orientation here
  1234 			mOrientation = orientation;
  1276 			mOrientation = orientation;
  1235 			handleChangeOrientation();
  1277 			handleChangeOrientation();
  1236 		}
  1278 		}
  1237 	}
       
  1238 }
  1279 }
  1239 
  1280 
  1240 /*!
  1281 /*!
  1241  Loads appropriate section from the docml dsepending on the current orientation
  1282  Loads appropriate section from the docml dsepending on the current orientation
  1242  of the device
  1283  of the device
  1258 	// Remove the current pane read from the docml  from the layout 
  1299 	// Remove the current pane read from the docml  from the layout 
  1259 	// and add actual current pane to the layout
  1300 	// and add actual current pane to the layout
  1260 	QGraphicsLinearLayout* viewLayout = static_cast<QGraphicsLinearLayout *>
  1301 	QGraphicsLinearLayout* viewLayout = static_cast<QGraphicsLinearLayout *>
  1261 													(widget()->layout());
  1302 													(widget()->layout());
  1262 	viewLayout->removeAt(1);
  1303 	viewLayout->removeAt(1);
  1263 	viewLayout->addItem(mCurrPaneParent);
  1304 	// Add this item only when orientaion is changed on month view
  1264 	
  1305 	// if it is changed in other views, adding the preview pane here was
  1265 
  1306 	// overlapping with the month grid, hence, its been added in dopopulation()
  1266 	// Check the weeknumber setting and update it accordingly
  1307 	if (this == mServices.MainWindow().currentView()) {
  1267 	if (mIsWeekNumbersShown) {
  1308 		viewLayout->addItem(mCurrPaneParent);
  1268 		// Add week numbers to week grid
       
  1269 		addWeekNumbers();
       
  1270 	} else {
       
  1271 		// remove the weeknumbergrid from the layout
       
  1272 		removeWeekNumbers();
       
  1273 	}
  1309 	}
  1274 }
  1310 }
  1275 
  1311 
  1276 /*!
  1312 /*!
  1277  Sets the appropriate date to the month title
  1313  Sets the appropriate date to the month title
  1437 	setCurrGridIndex(index);
  1473 	setCurrGridIndex(index);
  1438 	// Start the auto scroll on current preview pane
  1474 	// Start the auto scroll on current preview pane
  1439 	mCurrPreviewPane->startAutoScroll();
  1475 	mCurrPreviewPane->startAutoScroll();
  1440 	mPrevPreviewPane->populateLabel(mDate.addDays(-1));
  1476 	mPrevPreviewPane->populateLabel(mDate.addDays(-1));
  1441 }
  1477 }
       
  1478 /*!
       
  1479  update the Day labels 
       
  1480  */
       
  1481 void CalenMonthView::updateDayLabel()
       
  1482 {
       
  1483     // Set the short day names to these labels  
       
  1484     int startOfWeek = mLocale.startOfWeek();
       
  1485     int weekDayIndex = startOfWeek;
       
  1486     QStringList  weekDayArray ;
       
  1487     weekDayArray <<hbTrId("txt_calendar_grid_day_mo")
       
  1488                            <<hbTrId("txt_calendar_grid_day_tu")
       
  1489                            <<hbTrId("txt_calendar_grid_day_we")
       
  1490                            <<hbTrId("txt_calendar_grid_day_th")
       
  1491                            <<hbTrId("txt_calendar_grid_day_fr")
       
  1492                            <<hbTrId("txt_calendar_grid_day_sa")
       
  1493                            <<hbTrId("txt_calendar_grid_day_su");
       
  1494             
       
  1495     QList<HbLabel*> labels;
       
  1496     // append seven day labels 
       
  1497     labels.append(mFirstDayLabel);
       
  1498     labels.append(mSecondDayLabel);
       
  1499     labels.append(mThirdDayLabel);
       
  1500     labels.append(mFourthDayLabel);
       
  1501     labels.append(mFifthDayLabel);
       
  1502     labels.append(mSixthDayLabel);
       
  1503     labels.append(mSeventhDayLabel);
       
  1504     for(int i=0;i < KCalenDaysInWeek; i++ )
       
  1505         {
       
  1506         labels.at(i)->setPlainText(weekDayArray[weekDayIndex]);
       
  1507         if(weekDayIndex == KCalenDaysInWeek - 1 )//Sunday
       
  1508             {
       
  1509             weekDayIndex = 0;//reset to monday
       
  1510             continue;
       
  1511             }
       
  1512         weekDayIndex++;//increase the index for next value
       
  1513         }
       
  1514     labels.clear();
       
  1515     weekDayArray.clear();
       
  1516 }
  1442 // End of file  --Don't remove this.
  1517 // End of file  --Don't remove this.