calendarui/views/src/calenmonthview.cpp
changeset 18 c198609911f9
parent 0 f979ecb2b13e
child 23 fd30d51f876b
equal deleted inserted replaced
0:f979ecb2b13e 18:c198609911f9
     1 /*
     1 /*
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  For Month view of calendar application.
       
    15  *
     8  *
    16 */
     9  * Initial Contributors:
    17 
    10  * Nokia Corporation - initial contribution.
    18 
    11  *
    19 #include <aknnavide.h>
    12  * Contributors:
    20 #include <bldvariant.hrh> // For FeatureIds (lint warns without)
    13  *
    21 #include <eikmenup.h>
    14  * Description:  CalenMonthView implementation.
    22 #include <eikspane.h>       //CEikStatusPane
    15  *
    23 #include <StringLoader.h>
    16  */
    24 #include <aknappui.h>
    17 
    25 #include <featmgr.h>
    18 //system includes
    26 #include <calinstance.h>
    19 #include <QtGui>
    27 #include <calinstanceview.h>
    20 #include <xqsettingsmanager.h>
    28 #include <calcommon.h>
    21 #include <xqsettingskey.h>
    29 #include <caliterator.h>
    22 #include <hbapplication.h>
    30 #include <Calendar.rsg>
    23 #include <hbmainwindow.h>
    31 #include <calencommonui.rsg>
    24 #include <hbmenu.h>
    32 #include <calencommands.hrh>            // Calendar commands
    25 #include <hbaction.h>
    33 #include <calencontext.h>
    26 #include <hbview.h>
    34 #include <CalenStatusPaneUtils.h>
    27 #include <hblabel.h>
    35 #include <calenservices.h>
    28 #include <hbframeitem.h>
    36 #include <caleninstanceid.h>
    29 #include <hbcolorscheme.h>
    37 #include <calenviewutils.h>
    30 #include <agendautil.h>
    38 #include <calcalendarinfo.h>
    31 #include <agendaentry.h>
    39 
    32 
    40 #include "calendarui_debug.h"
    33 //user includes
    41 #include "calenmonthview.h"
    34 #include "calenmonthview.h"
    42 #include "calenmonthcontainer.h"
    35 #include "calenservices.h"
    43 #include <CalenInterimUtils2.h>
    36 #include "calennativeview.h"
    44 #include "calentitlepane.h"
    37 #include "calenview.h"
    45 #include "calensend.h"
    38 #include "calenmonthdata.h"
    46 #include "ToDo.hrh"
    39 #include "calencontext.h"
    47 #include "calendar.hrh"
    40 #include "calenagendautils.h"
    48 #include "CalenUid.h"
    41 #include "CalenUid.h"
    49 
    42 #include "hb_calencommands.hrh" 
    50 // ================= MEMBER FUNCTIONS =========================================
    43 #include "calendateutils.h"
    51 
    44 #include "calenmonthgrid.h"
    52 // ----------------------------------------------------------------------------
    45 #include "calenpreviewpane.h"
    53 // CCalenMonthView::NewLC
    46 #include "calendocloader.h"
    54 // First stage construction
    47 #include "calenthicklinesdrawer.h"
    55 // (other items were commented in a header).
    48 #include "calencommon.h"
    56 // ----------------------------------------------------------------------------
    49 #include "CalendarInternalCRKeys.h"
    57 //
    50 
    58 EXPORT_C CCalenMonthView* CCalenMonthView::NewL( MCalenServices& aServices )
    51 /*!
    59     {
    52  \class CalenMonthView
    60     TRACE_ENTRY_POINT;
    53 
    61 
    54  Class implementing calendar month view
    62     CCalenMonthView* self = new( ELeave ) CCalenMonthView( aServices );
    55  */
    63     CleanupStack::PushL( self );
    56 
    64     self->ConstructL();
    57 /*!
    65     CleanupStack::Pop( self );
    58  Default constructor.
    66 
    59  */
    67     TRACE_EXIT_POINT;
    60 CalenMonthView::CalenMonthView(MCalenServices &services) :
    68     return self;
    61 	CalenNativeView(services), mAgendaUtil(services.agendaInterface()), 
       
    62 	mGoToTodayAction(0)
       
    63 {
       
    64 	mIsWeekNumbersShown = 0;
       
    65 	mOrientation = mServices.MainWindow().orientation();
       
    66 	// Read the date from the context
       
    67 	mDate = mServices.Context().focusDateAndTimeL();
       
    68 	mCurrentDay = mDate;
       
    69 
       
    70 	// Create the settings manager instance and settings key for week number
       
    71 	mSettingsManager = new XQSettingsManager(this);
       
    72 	mWeekNumberCenrepKey
       
    73 	        = new XQSettingsKey(XQSettingsKey::TargetCentralRepository,
       
    74 	                            KCRUidCalendar.iUid, KCalendarWeekViewTitle);
       
    75 
       
    76 	mLocale = HbExtendedLocale::system();
       
    77 	mFirstWeekLabel = NULL;
       
    78 	mIsPrevPaneGesture = false;
       
    79 }
       
    80 
       
    81 /*!
       
    82  Destructor.
       
    83  */
       
    84 CalenMonthView::~CalenMonthView()
       
    85 {
       
    86 }
       
    87 
       
    88 /*!
       
    89  Called by the CalenViewManager after loading the view from the docml.
       
    90  The initializaion/setup of the view is done here. 
       
    91  */
       
    92 void CalenMonthView::setupView(CalenDocLoader *docLoader)
       
    93 {
       
    94 	mDocLoader = docLoader;
       
    95 	mTitleLabel
       
    96 	        = qobject_cast<HbLabel *> (
       
    97 								   mDocLoader->findWidget(CALEN_MONTH_TITLE));
       
    98 	mDayNameWidget
       
    99 	        = qobject_cast<CalenThickLinesDrawer *> (
       
   100 													mDocLoader->findWidget(
       
   101 													CALEN_DAYNAMES_WIDGET));
       
   102 
       
   103 	// Get all the seven day labels
       
   104 	mFirstDayLabel
       
   105 	        = qobject_cast<HbLabel *> (
       
   106 						mDocLoader->findWidget(CALEN_MONTVIEW_FIRST_DAY_LABEL));
       
   107 	mSecondDayLabel
       
   108 	        = qobject_cast<HbLabel *> (
       
   109 					   mDocLoader->findWidget(CALEN_MONTVIEW_SECOND_DAY_LABEL));
       
   110 	mThirdDayLabel
       
   111 	        = qobject_cast<HbLabel *> (
       
   112 					   mDocLoader->findWidget(CALEN_MONTVIEW_THIRD_DAY_LABEL));
       
   113 	mFourthDayLabel
       
   114 	        = qobject_cast<HbLabel *> (
       
   115 					   mDocLoader->findWidget(CALEN_MONTVIEW_FOURTH_DAY_LABEL));
       
   116 	mFifthDayLabel
       
   117 	        = qobject_cast<HbLabel *> (
       
   118 					   mDocLoader->findWidget(CALEN_MONTVIEW_FIFTH_DAY_LABEL));
       
   119 	mSixthDayLabel
       
   120 	        = qobject_cast<HbLabel *> (
       
   121 					   mDocLoader->findWidget(CALEN_MONTVIEW_SIXTH_DAY_LABEL));
       
   122 	mSeventhDayLabel
       
   123 	        = qobject_cast<HbLabel *> (
       
   124 					mDocLoader->findWidget(CALEN_MONTVIEW_SEVENTH_DAY_LABEL));
       
   125 
       
   126 	// Set the short day names to these labels
       
   127 	// TODO: Need to read start of the week from the locale
       
   128 	// and update the labels accortdingly
       
   129 	int startOfDay = mLocale.startOfWeek();
       
   130 	mFirstDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_mo"));
       
   131 	mSecondDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_tu"));
       
   132 	mThirdDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_we"));
       
   133 	mFourthDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_th"));
       
   134 	mFifthDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_fr"));
       
   135 	mSixthDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_sa"));
       
   136 	mSeventhDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_su"));
       
   137 	
       
   138 	// Get the weeknumber widget
       
   139 	mWeekNumberWidget
       
   140 			= qobject_cast<CalenThickLinesDrawer *> (
       
   141 							 mDocLoader->findWidget(CALEN_WEEKNUMBERS_WIDGET));
       
   142 	// Disable the item so that line seperator doesnt gets drawn by default
       
   143 	mWeekNumberWidget->setEnabled(false);
       
   144 
       
   145 	// Get the month grid
       
   146 	mMonthGrid
       
   147 	        = qobject_cast<CalenMonthGrid *> (
       
   148 									mDocLoader->findWidget(CALEN_MONTHGRID));
       
   149 	mCurrPaneParent = qobject_cast<HbWidget *> (
       
   150 			mDocLoader->findWidget(CALEN_CURRPREVIEWPARENT));
       
   151 	// Get current day preview pane widget
       
   152 	mCurrPreviewPane
       
   153 			= static_cast<CalenPreviewPane *> (
       
   154 					docLoader->findWidget(CALEN_CURRPREVIEWPANE));
       
   155 	//mCurrPreviewPane->setParent(mCurrPaneParent);
       
   156 	mCurrPaneParent->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
       
   157 	HbLabel* currPaneNoEntriesLabel = static_cast<HbLabel *> (
       
   158 			docLoader->findWidget(CALEN_NOENTRIES_LABEL_CURR));
       
   159 	mCurrPreviewPane->setView(this);
       
   160 	mCurrPreviewPane->setNoEntriesLabel(currPaneNoEntriesLabel);
       
   161 	
       
   162 	mPrevPaneParent = qobject_cast<HbWidget *> (
       
   163 			mDocLoader->findWidget(CALEN_PREVPREVIEWPARENT));
       
   164 	// Get previous day preview pane widget
       
   165 	mPrevPreviewPane
       
   166 			= static_cast<CalenPreviewPane *> (
       
   167 					docLoader->findWidget(CALEN_PREVPREVIEWPANE));
       
   168 	//mPrevPreviewPane->setParent(mPrevPaneParent);
       
   169 	mPrevPaneParent->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
       
   170 	HbLabel* prevPaneNoEntriesLabel = static_cast<HbLabel *> (
       
   171 			docLoader->findWidget(CALEN_NOENTRIES_LABEL_PREV));
       
   172 	mPrevPreviewPane->setView(this);
       
   173 	mPrevPreviewPane->setNoEntriesLabel(prevPaneNoEntriesLabel);
       
   174 	mPrevPaneParent->setVisible(false);
       
   175 	
       
   176 	mNextPaneParent = qobject_cast<HbWidget *> (
       
   177 			mDocLoader->findWidget(CALEN_NEXTPREVIEWPARENT));
       
   178 	// Get next day preview pane widget
       
   179 	mNextPreviewPane
       
   180 			= static_cast<CalenPreviewPane *> (
       
   181 					docLoader->findWidget(CALEN_NEXTPREVIEWPANE));
       
   182 	//mNextPreviewPane->setParent(mNextPaneParent);
       
   183 	mNextPaneParent->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
       
   184 	HbLabel* nextPaneNoEntriesLabel = static_cast<HbLabel *> (
       
   185 			docLoader->findWidget(CALEN_NOENTRIES_LABEL_NEXT));
       
   186 	mNextPreviewPane->setView(this);
       
   187 	mNextPreviewPane->setNoEntriesLabel(nextPaneNoEntriesLabel);
       
   188 	mNextPaneParent->setVisible(false);
       
   189 	
       
   190 	mMonthGridPlusWeekNumWidget
       
   191 	        = qobject_cast<HbWidget *> (
       
   192 					mDocLoader->findWidget(CALEN_MONTHGRID_WEEKNUMBERS_WIDGET));
       
   193 
       
   194 	mMonthGrid->setView(this);
       
   195 
       
   196 	// Connect to the menu actions
       
   197 	HbAction
       
   198 	        *newEventAction =
       
   199 	                qobject_cast<HbAction *> (
       
   200 						mDocLoader->findObject(CALEN_MONTVIEW_MENU_NEWEVENT));
       
   201 
       
   202 	connect(newEventAction, SIGNAL(triggered()), this, SLOT(createEditor()));
       
   203 
       
   204 	mGoToTodayAction =
       
   205 	                qobject_cast<HbAction *> (
       
   206 							mDocLoader->findObject(CALEN_MONTVIEW_MENU_GOTOTODAY));
       
   207 	connect(mGoToTodayAction, SIGNAL(triggered()), this, SLOT(goToToday()));
       
   208 	
       
   209 	HbAction
       
   210 	        *goToDateAction =
       
   211 	                qobject_cast<HbAction *> (
       
   212 						mDocLoader->findObject(CALEN_MONTVIEW_MENU_GOTODATE));
       
   213 
       
   214 	connect(goToDateAction, SIGNAL(triggered()), this, SLOT(goToDate()));
       
   215 
       
   216 	// TODO: Need to move this to docml
       
   217 	// Set the title to the submenu
       
   218 	HbMenu
       
   219 	        *deleteSubMenu =
       
   220 	                qobject_cast<HbMenu *> (
       
   221 						mDocLoader->findObject(CALEN_MONTVIEW_DELETE_SUBMENU));
       
   222 	deleteSubMenu->setTitle(hbTrId("txt_calendar_opt_delete_entries"));
       
   223 
       
   224 	HbAction
       
   225 	        *beforeDateAction =
       
   226 	                qobject_cast<HbAction *> (
       
   227 						mDocLoader->findObject(CALEN_MONTVIEW_MENU_BEFOREDATE));
       
   228 
       
   229 	connect(beforeDateAction, SIGNAL(triggered()), this,
       
   230 	        SLOT(deleteBeforeDate()));
       
   231 
       
   232 	HbAction
       
   233 	        *allEntriesAction =
       
   234 	                qobject_cast<HbAction *> (
       
   235 						mDocLoader->findObject(CALEN_MONTVIEW_MENU_ALLENTRIES));
       
   236 
       
   237 	connect(allEntriesAction, SIGNAL(triggered()), this,
       
   238 	        SLOT(deleteAllEntries()));
       
   239 
       
   240 	HbAction
       
   241 	        *settingsAction =
       
   242 	                qobject_cast<HbAction *> (
       
   243 						mDocLoader->findObject(CALEN_MONTVIEW_MENU_SETTINGS));
       
   244 
       
   245 	connect(settingsAction, SIGNAL(triggered()), this,
       
   246 	        SLOT(launchSettingsView()));
       
   247 
       
   248 
       
   249 	// Connect to the signal of change orientation.
       
   250 	connect(&(mServices.MainWindow()),
       
   251 	        SIGNAL(orientationChanged(Qt::Orientation)), this,
       
   252 	        SLOT(changeOrientation(Qt::Orientation)));
       
   253 	mIsFirstTimeLoad = true;
       
   254 	
       
   255 	// Add background items to all the widgets
       
   256 	addBackgroundFrame();
       
   257 }
       
   258 
       
   259 /*!
       
   260  Adds the week numbers to the weeknumber widget
       
   261  */
       
   262 void CalenMonthView::addWeekNumbers()
       
   263 {
       
   264 	if (!mFirstWeekLabel) {
       
   265 	// Get all the six week labels
       
   266 	mFirstWeekLabel
       
   267 			= qobject_cast<HbLabel *> (
       
   268 					mDocLoader->findWidget(CALEN_MONTVIEW_FIRST_WEEK_LABEL));
       
   269 	mSecondWeekLabel
       
   270 			= qobject_cast<HbLabel *> (
       
   271 					mDocLoader->findWidget(CALEN_MONTVIEW_SECOND_WEEK_LABEL));
       
   272 	mThirdWeekLabel
       
   273 			= qobject_cast<HbLabel *> (
       
   274 					mDocLoader->findWidget(CALEN_MONTVIEW_THIRD_WEEK_LABEL));
       
   275 	mFourthWeekLabel
       
   276 			= qobject_cast<HbLabel *> (
       
   277 					mDocLoader->findWidget(CALEN_MONTVIEW_FOURTH_WEEK_LABEL));
       
   278 	mFifthWeekLabel
       
   279 			= qobject_cast<HbLabel *> (
       
   280 					mDocLoader->findWidget(CALEN_MONTVIEW_FIFTH_WEEK_LABEL));
       
   281 	mSixthWeekLabel
       
   282 			= qobject_cast<HbLabel *> (
       
   283 					mDocLoader->findWidget(CALEN_MONTVIEW_SIXTH_WEEK_LABEL));
       
   284 	}
       
   285 
       
   286 	// Calculate the week numbers and set them to the week labels
       
   287 	updateWeekNumGridModel();
       
   288 
       
   289 	// Get the day names layout
       
   290 	QGraphicsLinearLayout *dayNamesLayout =
       
   291 	        static_cast<QGraphicsLinearLayout *> (mDayNameWidget->layout());
       
   292 
       
   293 	if (KCalenDaysInWeek == dayNamesLayout->count()) {
       
   294 		// Add one item with text "Wk" in the day name grid
       
   295 		HbLabel *label = new HbLabel(mDayNameWidget);
       
   296 
       
   297 		// Set the attributes same as that of other day names to make it
       
   298 		// look similar to the day names
       
   299 		label->setPlainText(hbTrId("txt_calendar_grid_day_wk"));
       
   300 		label->setFont(mFirstDayLabel->font());
       
   301 		label->setFontSpec(mFirstDayLabel->fontSpec());
       
   302 		label->setAlignment(mFirstDayLabel->alignment());
       
   303 		label->setElideMode(mFirstDayLabel->elideMode());
       
   304 		label->setZValue(mFirstDayLabel->zValue());
       
   305 		label->setPreferredHeight(mFirstDayLabel->preferredHeight());
       
   306 		label->setMinimumHeight(mFirstDayLabel->minimumHeight());
       
   307 		label->setMaximumHeight(mFirstDayLabel->maximumHeight());
       
   308 		
       
   309 		// Add this label into layout
       
   310 		dayNamesLayout->insertItem(0, label);
       
   311 		dayNamesLayout->invalidate();
       
   312 		dayNamesLayout->activate();
       
   313 	}
       
   314 
       
   315 	// Now insert the weekNumber Grid
       
   316 	QGraphicsLinearLayout *layout = static_cast<QGraphicsLinearLayout *> 
       
   317 										(mMonthGridPlusWeekNumWidget->layout());
       
   318 
       
   319 	if (1 == layout->count()) {
       
   320 		layout->insertItem(0, mWeekNumberWidget);
       
   321 		// Enable the item so that line seperator gets drawn
       
   322 		mWeekNumberWidget->setEnabled(true);
       
   323 		layout->invalidate();
       
   324 		layout->activate();
       
   325 	}
       
   326 }
       
   327 
       
   328 /*!
       
   329  Removes the week numbers from the view
       
   330  */
       
   331 void CalenMonthView::removeWeekNumbers()
       
   332 
       
   333 {
       
   334 	// Remove the week number grid if setting is off
       
   335 	QGraphicsLinearLayout *layout = static_cast<QGraphicsLinearLayout *> 
       
   336 									(mMonthGridPlusWeekNumWidget->layout());
       
   337 	if (2 == layout->count()) {
       
   338 		layout->removeItem(mWeekNumberWidget);
       
   339 
       
   340 		// Disable the item as we are removing it from the layout
       
   341 		mWeekNumberWidget->setEnabled(false);
       
   342 		layout->invalidate();
       
   343 		layout->activate();
       
   344 
       
   345 		// Clear the week labels
       
   346 		mFirstWeekLabel->clear();
       
   347 		mSecondWeekLabel->clear();
       
   348 		mThirdWeekLabel->clear();
       
   349 		mFourthWeekLabel->clear();
       
   350 		mFifthWeekLabel->clear();
       
   351 		mSixthWeekLabel->clear();
       
   352 
       
   353 		// Get the day names layout
       
   354 		QGraphicsLinearLayout *dayNamesLayout =
       
   355 		        static_cast<QGraphicsLinearLayout *> (mDayNameWidget->layout());
       
   356 		if (dayNamesLayout->count() == KCalenDaysInWeek + 1) {
       
   357 			// Remove the empty item in the day name grid
       
   358 			QGraphicsLayoutItem *item = dayNamesLayout->itemAt(0);
       
   359 			dayNamesLayout->removeAt(0);
       
   360 			delete item;
       
   361 			dayNamesLayout->invalidate();
       
   362 			dayNamesLayout->activate();
       
   363 		}
       
   364 	}
       
   365 }
       
   366 
       
   367 /*!
       
   368  Sets the background frame for the month view
       
   369  */
       
   370 void CalenMonthView::addBackgroundFrame()
       
   371 {
       
   372     // Set the background items for all the widgets
       
   373     HbFrameItem* frame = NULL;
       
   374     if (mMonthGrid) {
       
   375         // The grid background
       
   376         frame = new HbFrameItem(this);
       
   377         frame->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
       
   378 
       
   379         frame->frameDrawer().setFrameGraphicsName("qtg_fr_cal_monthgrid_bg");
       
   380         mMonthGrid->setBackgroundItem(frame->graphicsItem(), -2);
    69     }
   381     }
    70 
   382     if (mTitleLabel) {
    71 // ----------------------------------------------------------------------------
   383         // The month title
    72 // CCalenMonthView::~CCalenMonthView
   384         frame = new HbFrameItem(this);
    73 // Destructor
   385         frame->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesHorizontal);
    74 // (other items were commented in a header).
   386 
    75 // ----------------------------------------------------------------------------
   387         frame->frameDrawer().setFrameGraphicsName("qtg_fr_cal_monthgrid_title_bg");
    76 //
   388         mTitleLabel->setBackgroundItem(frame->graphicsItem(), -2);
    77 CCalenMonthView::~CCalenMonthView()
       
    78     {
       
    79     TRACE_ENTRY_POINT;
       
    80     TRACE_EXIT_POINT;
       
    81     }
   389     }
    82 
   390   
    83 // ----------------------------------------------------------------------------
   391 }
    84 // CCalenMonthView::CCalenMonthView
   392 
    85 // C++ default constructor can NOT contain any code, that might leave.
   393 /*!
    86 // (other items were commented in a header).
   394  Calculates the week numbers and sets them to the week labels
    87 // ----------------------------------------------------------------------------
   395  */
    88 //
   396 void CalenMonthView::updateWeekNumGridModel()
    89 CCalenMonthView::CCalenMonthView( MCalenServices& aServices )
   397 
    90     : CCalenNativeView( aServices ),
   398 {
    91       iPopulationStep( ENothingDone )
   399 	// Get the visible date
    92     {
   400 	QDateTime firstVisibleDate = mFirstDayOfGrid.addDays(KCalenDaysInWeek
    93     TRACE_ENTRY_POINT;
   401 	        * mNumOfRowsInPrevMonth);
    94     TRACE_EXIT_POINT;
   402 	// Go to the last day so that we get the proper week number for the first
       
   403 	// week of January
       
   404 	mWeekNumbers.clear();
       
   405 	// get the proper week numbers
       
   406 	for (int i = 0; i < KNumOfVisibleRows; i++) {
       
   407 		// Get the week number
       
   408 		QDateTime day = firstVisibleDate.addDays((KCalenDaysInWeek * i));
       
   409 		long weekNumber(day.date().weekNumber());
       
   410 		mWeekNumbers.append(weekNumber);
       
   411 	}
       
   412 	
       
   413 	// Get the week day color from the theme
       
   414 	QColor weekDayColor = HbColorScheme::color("qtc_cal_week_day");
       
   415 
       
   416 	// Update the week labels text
       
   417 	QString text = QString::number(mWeekNumbers.at(0));
       
   418 	mFirstWeekLabel->setPlainText(text);
       
   419 	mFirstWeekLabel->setTextColor(weekDayColor);
       
   420 	text = QString::number(mWeekNumbers.at(1));
       
   421 	mSecondWeekLabel->setPlainText(text);
       
   422 	mSecondWeekLabel->setTextColor(weekDayColor);
       
   423 	text = QString::number(mWeekNumbers.at(2));
       
   424 	mThirdWeekLabel->setPlainText(text);
       
   425 	mThirdWeekLabel->setTextColor(weekDayColor);
       
   426 	text = QString::number(mWeekNumbers.at(3));
       
   427 	mFourthWeekLabel->setPlainText(text);
       
   428 	mFourthWeekLabel->setTextColor(weekDayColor);
       
   429 	text = QString::number(mWeekNumbers.at(4));
       
   430 	mFifthWeekLabel->setPlainText(text);
       
   431 	mFifthWeekLabel->setTextColor(weekDayColor);
       
   432 	text = QString::number(mWeekNumbers.at(5));
       
   433 	mSixthWeekLabel->setPlainText(text);
       
   434 	mSixthWeekLabel->setTextColor(weekDayColor);
       
   435 }
       
   436 
       
   437 /*!
       
   438  Populates the month view with today as focussed item
       
   439  */
       
   440 void CalenMonthView::goToToday()
       
   441 {
       
   442 	QDateTime today = CalenDateUtils::today();
       
   443 	// First check if we are not already
       
   444 	// showing today's month view
       
   445 	if (mDate == today) {
       
   446 		return;
       
   447 	}
       
   448 	
       
   449 	// Set the context and repopulate the view
       
   450 	MCalenContext &context = mServices.Context();
       
   451 	context.setFocusDateAndTimeL(today, KCalenMonthViewUidValue);
       
   452 	
       
   453 	mServices.IssueCommandL(ECalenStartActiveStep);
       
   454 }
       
   455 
       
   456 /*!
       
   457  Populates the view
       
   458  */
       
   459 void CalenMonthView::doPopulation()
       
   460 {
       
   461 	if (!mIsFirstTimeLoad) {
       
   462 		Qt::Orientation orientation = mServices.MainWindow().orientation();
       
   463 		if (mOrientation != orientation) {
       
   464 			mOrientation = orientation;
       
   465 			handleChangeOrientation();
       
   466 		}
       
   467 	}
       
   468 	mIsFirstTimeLoad = false;
       
   469 	// prepare for the population like reading the date frm the context 
       
   470 	// calculating the start of the grid etc.,
       
   471 	prepareForPopulation();
       
   472 
       
   473 	// fetch list of required calendar instances
       
   474 	populateWithInstanceView();
       
   475 
       
   476 	populatePreviewPane(mDate);
       
   477 
       
   478 	// Create the grid items with proper dates
       
   479 	createGrid();
       
   480 
       
   481 	// Complete the population
       
   482 	completePopulation();
       
   483 
       
   484 	// Population is complete, inform it
       
   485 	populationComplete();
       
   486 	
       
   487 	// Start the auto scroll on current preview pane
       
   488 	mCurrPreviewPane->startAutoScroll();
       
   489 }
       
   490 
       
   491 /*!
       
   492  Reads the date from the context and calculates the grid item dates
       
   493  */
       
   494 void CalenMonthView::prepareForPopulation()
       
   495 {
       
   496 	setActiveDay(dateFromContext(mServices.Context()));
       
   497 	setDate();
       
   498 }
       
   499 
       
   500 /*!
       
   501  Reads the date from the context and stores into mDate
       
   502  */
       
   503 QDateTime CalenMonthView::dateFromContext(const MCalenContext &context)
       
   504 {
       
   505 	QDateTime ret;
       
   506 	if (AgendaEntry::TypeTodo == context.instanceId().mType) {
       
   507 		QDateTime today = CalenDateUtils::today();
       
   508 		if (context.focusDateAndTimeL() < today) {
       
   509 			ret = today;
       
   510 		} else {
       
   511 			ret = context.focusDateAndTimeL();
       
   512 		}
       
   513 	} else {
       
   514 		ret = context.focusDateAndTimeL();
       
   515 	}
       
   516 	return ret;
       
   517 }
       
   518 
       
   519 /*!
       
   520  Calculates the necesary parameters of the month view w.r.t mDate
       
   521  */
       
   522 void CalenMonthView::setActiveDay(QDateTime day)
       
   523 {
       
   524 	mDate = day;
       
   525 	// Check if we are population for current day, if yes then disable the
       
   526 	// gototoday action
       
   527 	if ((CalenDateUtils::today().date() == mDate.date()) && mGoToTodayAction) {
       
   528 	    mGoToTodayAction->setVisible(false);
       
   529 	} else if (mGoToTodayAction){
       
   530 	    mGoToTodayAction->setVisible(true);
       
   531 	}
       
   532     
       
   533 	mActiveMonth = mDate;
       
   534 	// Get the first day of the previous month
       
   535 	QDateTime prevMonthDate = mDate.addMonths(-1);
       
   536 	int prevMonth = prevMonthDate.date().month();
       
   537 
       
   538 	// Get the first day of the month
       
   539 	QDate date = prevMonthDate.date();
       
   540 	date.setDate(date.year(), date.month(), 1);
       
   541 	QDateTime firstDayOfPrevMonth(date, day.time());
       
   542 
       
   543 	// TODO: Need to consider the week start frm the locale object
       
   544 	TLocale locale;
       
   545 	int offset(firstDayOfPrevMonth.date().dayOfWeek() - (mLocale.startOfWeek()
       
   546 	        + 1));
       
   547 	if (offset < 0) {
       
   548 		offset += KCalenDaysInWeek;
       
   549 	}
       
   550 
       
   551 	// Substract the offset days
       
   552 	mFirstDayOfGrid = firstDayOfPrevMonth.addDays(-offset);
       
   553 
       
   554 	// Calculate the number of weeks in the previous month that will be hidden
       
   555 	mNumOfRowsInPrevMonth = offset + prevMonthDate.date().daysInMonth();
       
   556 	mNumOfRowsInPrevMonth = (mNumOfRowsInPrevMonth / KCalenDaysInWeek);
       
   557 
       
   558 	// Index to be scrolled is the last day of the visible grid item
       
   559 	mIndexToBeScrolled = ((mNumOfRowsInPrevMonth + KNumOfVisibleRows)
       
   560 	        * KCalenDaysInWeek) - 1;
       
   561 
       
   562 	// Now add the future month days to the count. While doing that, we need to
       
   563 	// calcualte the count till the end of the week in which the month ends
       
   564 	QDateTime futureMonthDate = mDate.addMonths(1);
       
   565 	// Get the first day of the future month
       
   566 	date = futureMonthDate.date();
       
   567 	date.setDate(date.year(), date.month(), 1);
       
   568 	QDateTime firstDayOfFutMonth(date, day.time());
       
   569 	offset = firstDayOfFutMonth.date().dayOfWeek() - (mLocale.startOfWeek() + 1);
       
   570 	if (offset < 0) {
       
   571 		offset += KCalenDaysInWeek;
       
   572 	}
       
   573 	// Substract the firstDayNoInWeek days
       
   574 	QDateTime dateTime = firstDayOfFutMonth.addDays(-offset);
       
   575 
       
   576 	// Need to add 42 days for dateTime so that it fits into the visible grid
       
   577 	mLastDayOfGrid = dateTime.addDays(KNumOfVisibleRows * KCalenDaysInWeek - 1);
       
   578 
       
   579 	// calculate the total numbers of dates that needs to be populated from 
       
   580 	// previous month to future month
       
   581 	mTotalNumOfGridItems = mFirstDayOfGrid.daysTo(mLastDayOfGrid) + 1;
       
   582 
       
   583 	// Calculate the last visible day
       
   584 	int index = (mNumOfRowsInPrevMonth + KNumOfVisibleRows) * KCalenDaysInWeek;
       
   585 	QDateTime lastVisibleDate = mFirstDayOfGrid.addDays(index);
       
   586 	QDateTime dateTimeToCalc = mLastDayOfGrid;
       
   587 	mNumOfRowsInFutureMonth = 0;
       
   588 	while (dateTimeToCalc > lastVisibleDate) {
       
   589 		mNumOfRowsInFutureMonth++;
       
   590 		dateTimeToCalc = dateTimeToCalc.addDays(-KCalenDaysInWeek);
       
   591 	}
       
   592 }
       
   593 
       
   594 /*!
       
   595  Calculates the dates that needs to be set to mMonthDataArray
       
   596  */
       
   597 void CalenMonthView::setDate()
       
   598 {
       
   599 	mMonthDataArray.clear();
       
   600 	// Calculate the actual number of dates to be populated from previous month
       
   601 	// to future month
       
   602 	for (int i(0); i < mTotalNumOfGridItems; ++i) {
       
   603 		QDateTime currentDay = CalenDateUtils::futureOf(mFirstDayOfGrid, i);
       
   604 		CalenMonthData element(currentDay);
       
   605 		mMonthDataArray.append(element);
       
   606 	}
       
   607 	// Update the dates with active flag
       
   608 	updateMonthDataArrayWithActiveDates();
       
   609 }
       
   610 
       
   611 /*!
       
   612  Returns the currDay(Today)
       
   613  */
       
   614 QDateTime CalenMonthView::getCurrentDay()
       
   615 {
       
   616 	return mCurrentDay;
       
   617 }
       
   618 
       
   619 /*!
       
   620  Returns the active day(currently focussed day)
       
   621  */
       
   622 QDateTime CalenMonthView::getActiveDay()
       
   623 {
       
   624 	return mDate;
       
   625 }
       
   626 
       
   627 /*!
       
   628  Returns the array of CalenMonthData items
       
   629  */
       
   630 QList<CalenMonthData> CalenMonthView::monthDataList()
       
   631 {
       
   632 	return mMonthDataArray;
       
   633 }
       
   634 
       
   635 /*!
       
   636  Creates the grid and adds the week numbers depending on the week number setting
       
   637  */
       
   638 void CalenMonthView::createGrid()
       
   639 {
       
   640 	// Update the month grid
       
   641 	mMonthGrid->updateMonthGridModel(mMonthDataArray, mIndexToBeScrolled);
       
   642 
       
   643 	// Read the week number setting from cenrep
       
   644 	QVariant value = mSettingsManager->readItemValue(*mWeekNumberCenrepKey);
       
   645 	mIsWeekNumbersShown = value.toUInt();
       
   646 	if (mIsWeekNumbersShown) {
       
   647 		// Add week numbers to week grid
       
   648 		addWeekNumbers();
       
   649 	} else {
       
   650 		// remove the weeknumbergrid from the layout
       
   651 		removeWeekNumbers();
       
   652 	}
       
   653 }
       
   654 
       
   655 /*!
       
   656  Called when down gesture is performed
       
   657  Caluclates the necessary dates for the new previous month
       
   658  */
       
   659 void CalenMonthView::updateModelWithPrevMonth()
       
   660 {
       
   661 	// Get the new previous month
       
   662 	QDateTime prevMonthDateTime = mActiveMonth.addMonths(-1);
       
   663 	QDateTime dateTime = mFirstDayOfGrid;
       
   664 	if (prevMonthDateTime.date().month() == mFirstDayOfGrid.date().month()) {
       
   665 		//  Month starts right on Monday(Start of the week), 
       
   666 		//hence go back to previous month
       
   667 		dateTime = mFirstDayOfGrid.addMonths(-1);
       
   668 	}
       
   669 
       
   670 	int prevMonth = dateTime.date().month();
       
   671 	QDateTime prevFirstDayOfGrid = mFirstDayOfGrid;
       
   672 	for (int i = 0; i < KNumOfVisibleRows; i++) {
       
   673 		mFirstDayOfGrid = mFirstDayOfGrid.addDays(-KCalenDaysInWeek);
       
   674 		if (mFirstDayOfGrid.date().month() == prevMonth) {
       
   675 			continue;
       
   676 		} else {
       
   677 			// Entered to another month, stop here
       
   678 			break;
       
   679 		}
       
   680 	}
       
   681 	// Readjust the mFirstDayOfGrid
       
   682 	if (mFirstDayOfGrid.addDays(KCalenDaysInWeek - 1).date().month()
       
   683 	        != prevMonth) {
       
   684 		mFirstDayOfGrid = mFirstDayOfGrid.addDays(KCalenDaysInWeek);
       
   685 	}
       
   686 
       
   687 	// Calculate the new days to be added
       
   688 	int countToBeAdded = mFirstDayOfGrid.daysTo(prevFirstDayOfGrid);
       
   689 
       
   690 	// Remove the bottom month entries in mMonthDataArray
       
   691 	int countToBeDeleted = mNumOfRowsInFutureMonth * KCalenDaysInWeek;
       
   692 	int count = mMonthDataArray.count() - 1;
       
   693 	for (int i = 0; i < countToBeDeleted; i++) {
       
   694 		mMonthDataArray.removeAt(count--);
       
   695 	}
       
   696 
       
   697 	// Update the total number of grid items as we will be removing the month
       
   698 	// at the below
       
   699 	mTotalNumOfGridItems -= countToBeDeleted;
       
   700 
       
   701 	// Prepend countToBeAdded new items to mMonthDataArray
       
   702 	for (int i = 0; i < countToBeAdded; i++) {
       
   703 		QDateTime currentDay = mFirstDayOfGrid.addDays(i);
       
   704 		CalenMonthData element(currentDay);
       
   705 		mMonthDataArray.insert(i, element);
       
   706 	}
       
   707 	mTotalNumOfGridItems += countToBeAdded;
       
   708 
       
   709 	// Update the mMonthDataArray with instances if any
       
   710 	populatePrevMonth();
       
   711 
       
   712 	// Update the necessary globals
       
   713 	mActiveMonth = mActiveMonth.addMonths(-1);
       
   714 	mNumOfRowsInPrevMonth = (countToBeAdded / KCalenDaysInWeek);
       
   715 	mLastDayOfGrid = mFirstDayOfGrid.addDays(mTotalNumOfGridItems - 1);
       
   716 	// Calculate the last visible day
       
   717 	int index = (mNumOfRowsInPrevMonth + KNumOfVisibleRows) * KCalenDaysInWeek;
       
   718 	QDateTime lastVisibleDate = mFirstDayOfGrid.addDays(index - 1);
       
   719 	QDateTime date = mLastDayOfGrid;
       
   720 	mNumOfRowsInFutureMonth = 0;
       
   721 	while (date > lastVisibleDate) {
       
   722 		mNumOfRowsInFutureMonth++;
       
   723 		date = date.addDays(-KCalenDaysInWeek);
       
   724 	}
       
   725 	// Update the week Numbers model
       
   726 	if (mIsWeekNumbersShown) {
       
   727 		updateWeekNumGridModel();
       
   728 	}
       
   729 
       
   730 	// Update the dates with active flag
       
   731 	updateMonthDataArrayWithActiveDates();
       
   732 }
       
   733 /*!
       
   734  Called when up gesture is performed
       
   735  */
       
   736 void CalenMonthView::updateModelWithFutureMonth()
       
   737 {
       
   738 	// Get the new future month
       
   739 	QDateTime previousLastDayOfGrid = mLastDayOfGrid;
       
   740 	QDateTime futureMonthDateTime = mActiveMonth.addMonths(2);
       
   741 	QDate date = futureMonthDateTime.date();
       
   742 	date.setDate(date.year(), date.month(), 1);
       
   743 	// Get the first day of the future month
       
   744 	QDateTime firstDayOfFutMonth(date, futureMonthDateTime.time());
       
   745 	TLocale locale;
       
   746 	int offset = firstDayOfFutMonth.date().dayOfWeek() - (mLocale.startOfWeek()
       
   747 	        + 1);
       
   748 	if (offset < 0) {
       
   749 		offset += KCalenDaysInWeek;
       
   750 	}
       
   751 	// Substract the firstDayNoInWeek days
       
   752 	QDateTime dateTime = firstDayOfFutMonth.addDays(-offset);
       
   753 	// Need to add 42 days for dateTime
       
   754 	mLastDayOfGrid = dateTime.addDays(KNumOfVisibleRows * KCalenDaysInWeek - 1);
       
   755 
       
   756 	// Remove the first mNumOfRowsInPrevMonth rows in mMonthDataArray
       
   757 	int countToBeDeleted = mNumOfRowsInPrevMonth * KCalenDaysInWeek;
       
   758 	for (int i = 0; i < countToBeDeleted; i++) {
       
   759 		mMonthDataArray.removeAt(0);
       
   760 	}
       
   761 
       
   762 	// Update the total number of grid items as we will be removing the month
       
   763 	// at the top
       
   764 	mTotalNumOfGridItems -= countToBeDeleted;
       
   765 
       
   766 	// Calcualate the num fo days to be added
       
   767 	int countToBeAdded = previousLastDayOfGrid.daysTo(mLastDayOfGrid);
       
   768 	// Append countToBeAdded new items to mMonthDataArray
       
   769 	for (int i = 1; i <= countToBeAdded; i++) {
       
   770 		QDateTime currentDay = previousLastDayOfGrid.addDays(i);
       
   771 		CalenMonthData element(currentDay);
       
   772 		mMonthDataArray.append(element);
       
   773 	}
       
   774 
       
   775 	// Update the mMonthDataArray with instances if any
       
   776 	populateNextMonth();
       
   777 
       
   778 	// Update the necessary globals
       
   779 	mTotalNumOfGridItems += countToBeAdded;
       
   780 	mActiveMonth = mActiveMonth.addMonths(1);
       
   781 	mNumOfRowsInFutureMonth = (countToBeAdded / KCalenDaysInWeek);
       
   782 	mFirstDayOfGrid = mLastDayOfGrid.addDays(-(mTotalNumOfGridItems - 1));
       
   783 	// Calculate the first visible date
       
   784 	int index = mTotalNumOfGridItems - ((mNumOfRowsInFutureMonth
       
   785 	        + KNumOfVisibleRows) * KCalenDaysInWeek);
       
   786 	QDateTime firstVisibleDate = mFirstDayOfGrid.addDays(index - 1);
       
   787 	QDateTime dateTimeToCalc = mFirstDayOfGrid;
       
   788 	mNumOfRowsInPrevMonth = 0;
       
   789 	while (dateTimeToCalc < firstVisibleDate) {
       
   790 		mNumOfRowsInPrevMonth++;
       
   791 		dateTimeToCalc = dateTimeToCalc.addDays(KCalenDaysInWeek);
       
   792 	}
       
   793 
       
   794 	// Update the week Numbers model
       
   795 	if (mIsWeekNumbersShown) {
       
   796 		updateWeekNumGridModel();
       
   797 	}
       
   798 
       
   799 	// Update the dates with active flag
       
   800 	updateMonthDataArrayWithActiveDates();
       
   801 }
       
   802 
       
   803 /*!
       
   804  Returns the numner of rows in previous month
       
   805  */
       
   806 int CalenMonthView::rowsInPrevMonth()
       
   807 {
       
   808 	return mNumOfRowsInPrevMonth;
       
   809 }
       
   810 
       
   811 /*!
       
   812  Returns the number of rows in future month
       
   813  */
       
   814 int CalenMonthView::rowsInFutMonth()
       
   815 {
       
   816 	return mNumOfRowsInFutureMonth;
       
   817 }
       
   818 
       
   819 /*!
       
   820  Returns current Grid index
       
   821  */
       
   822 int CalenMonthView::getCurrGridIndex()
       
   823 {
       
   824 	return mMonthGrid->getCurrentIndex();
       
   825 }
       
   826 
       
   827 /*!
       
   828  Set the currend Index of the Grid
       
   829  */
       
   830 void CalenMonthView::setCurrGridIndex(int index)
       
   831 {
       
   832 	mIsPrevPaneGesture = true;
       
   833 	mMonthGrid->setCurrentIdex(index);
       
   834 }
       
   835 
       
   836 /*!
       
   837  Sets the active flag to the required dates in the array
       
   838  */
       
   839 void CalenMonthView::updateMonthDataArrayWithActiveDates()
       
   840 {
       
   841 	int activeMonth = mActiveMonth.date().month();
       
   842 	for (int i = 0; i < mMonthDataArray.count(); i++) {
       
   843 		if (mMonthDataArray[i].Day().date().month() == activeMonth) {
       
   844 			// Set the active flag
       
   845 			mMonthDataArray[i].setActive(true);
       
   846 		} else {
       
   847 			// Disable the active flag
       
   848 			mMonthDataArray[i].setActive(false);
       
   849 		}
       
   850 	}
       
   851 }
       
   852 
       
   853 /*!
       
   854  Fetches the calenda entries for a given range
       
   855  */
       
   856 void CalenMonthView::getInstanceList(QList<AgendaEntry> &list,
       
   857                                      QDateTime rangeStart, QDateTime rangeEnd)
       
   858 {
       
   859 	AgendaUtil::FilterFlags filter =
       
   860 	        AgendaUtil::FilterFlags(AgendaUtil::IncludeAnniversaries
       
   861 	                | AgendaUtil::IncludeAppointments
       
   862 	                | AgendaUtil::IncludeEvents
       
   863 	                | AgendaUtil::IncludeReminders
       
   864 	                | AgendaUtil::IncludeIncompletedTodos);
       
   865 	list = mAgendaUtil->fetchEntriesInRange(rangeStart, rangeEnd, filter);
       
   866 }
       
   867 
       
   868 /*!
       
   869  Parses the fetched entries and sets hasEvent attribute for necessary days
       
   870  */
       
   871 void CalenMonthView::populateWithInstanceView()
       
   872 {
       
   873 	const QDateTime today(CalenDateUtils::today());
       
   874 	const QDateTime gridStart(CalenDateUtils::beginningOfDay(mFirstDayOfGrid));
       
   875 
       
   876 	// grid index for "today"
       
   877 	const int todayIndex(gridStart.daysTo(today)); 
       
   878 
       
   879 	QDateTime gridEnd(mLastDayOfGrid.date(), QTime(23, 59, 59, 0));
       
   880 	QList<AgendaEntry> list;
       
   881 
       
   882 	getInstanceList(list, gridStart, gridEnd);
       
   883 
       
   884 	//Parse fetched items
       
   885 	if (list.count()) {
       
   886 		for (int i(0); i < list.count(); i++) {
       
   887 			AgendaEntry entry = list[i];
       
   888 
       
   889 			// Parse  Day Notes, Appointments and Remainders
       
   890 			// Start and end time of Event/Appointment/Remainders has to be 
       
   891 			// indentified before marking the tags
       
   892 			// EEvents/Appointments can span multiple days, 
       
   893 			// while Anniversaries cannot.
       
   894 			if ((entry.type() == AgendaEntry::TypeEvent) || (entry.type()
       
   895 			        == AgendaEntry::TypeAppoinment) || (entry.type()
       
   896 			        == AgendaEntry::TypeReminder)) {
       
   897 				// The start time of the instance
       
   898 				QDateTime startTime = entry.startTime();
       
   899 				// The instance's start index from the grid start           
       
   900 				int startIndex(gridStart.daysTo(startTime));
       
   901 				// The end time of the instance
       
   902 				QDateTime endTime = entry.endTime();
       
   903 
       
   904 				if (CalenAgendaUtils::endsAtStartOfDayL(entry, endTime)) {
       
   905 					// prevent problems with items ending tomorrow at 00:00
       
   906 					QTime time = endTime.time();
       
   907 					time.setHMS(time.hour(), time.minute() - 1, time.second(),
       
   908 					            time.msec());
       
   909 					endTime.setTime(time);
       
   910 
       
   911 					if (endTime <= gridStart) {
       
   912 						// ends at the start of the grid -> not visible
       
   913 						continue; // skip
       
   914 					}
       
   915 				}
       
   916 				// The instance's end index from the grid start             
       
   917 				int endIndex(gridStart.daysTo(endTime));
       
   918 
       
   919 				// Mark the days from start index to end index
       
   920 				for (; startIndex <= endIndex; startIndex++) {
       
   921 					if (startIndex >= 0 && 
       
   922 							startIndex < mMonthDataArray.count()) {
       
   923 						mMonthDataArray[startIndex].SetHasEvents(true);
       
   924 					}
       
   925 				} // Parse Anniversaries
       
   926 			} else if (entry.type() == AgendaEntry::TypeAnniversary) {
       
   927 				QDateTime startTime = entry.startTime();
       
   928 				// The instance's start index from the grid start           
       
   929 				int index(gridStart.daysTo(startTime));
       
   930 				// Mark the particular day
       
   931 				if (index >= 0 && index < mMonthDataArray.count()) {
       
   932 					mMonthDataArray[index].SetHasEvents(true);
       
   933 				} // Parse To DOs
       
   934 			} else if (entry.type() == AgendaEntry::TypeTodo) {
       
   935 				QDateTime startTime = entry.startTime();
       
   936 				;
       
   937 				int index;
       
   938 				// Mark the particular day if the instance's start 
       
   939 				// time is not in the past
       
   940 				if (startTime >= today) {
       
   941 					index = gridStart.daysTo(startTime);
       
   942 				} else {// Mark for today if the instance's 
       
   943 					// start time is in the past
       
   944 					index = todayIndex;
       
   945 				}
       
   946 				if (index >= 0 && index < mMonthDataArray.count()) {
       
   947 					mMonthDataArray[index].SetHasEvents(true);
       
   948 				}
       
   949 			}
       
   950 		}
       
   951 	}
       
   952 	list.clear();
       
   953 }
       
   954 
       
   955 /*!
       
   956  Parses the fetched entries for previous month and 
       
   957  sets hasEvent attribute for necessary days
       
   958  */
       
   959 void CalenMonthView::populatePrevMonth()
       
   960 {
       
   961 	QList<AgendaEntry> list;
       
   962 	const QDateTime gridStart(CalenDateUtils::beginningOfDay(mFirstDayOfGrid));
       
   963 	const QDateTime today(CalenDateUtils::today());
       
   964 
       
   965 	const int todayIndex(gridStart.daysTo(today)); // grid index for "today"
       
   966 	QDateTime end = gridStart.addDays(mNumOfRowsInPrevMonth * KCalenDaysInWeek);
       
   967 	QDateTime gridEnd(end.date(), QTime(23, 59, 59, 0));
       
   968 
       
   969 	getInstanceList(list, gridStart, gridEnd);
       
   970 
       
   971 	//Parse fetched items
       
   972 	if (list.count()) {
       
   973 		for (int i(0); i < list.count(); i++) {
       
   974 			AgendaEntry entry = list[i];
       
   975 
       
   976 			// Parse  Day Notes, Appointments and Remainders
       
   977 			// Start and end time of Event/Appointment/Remainders 
       
   978 			// has to be indentified before marking the tags
       
   979 			// EEvents/Appointments can span multiple days, 
       
   980 			// while Anniversaries cannot.
       
   981 			if ((entry.type() == AgendaEntry::TypeEvent) || (entry.type()
       
   982 			        == AgendaEntry::TypeAppoinment) || (entry.type()
       
   983 			        == AgendaEntry::TypeReminder)) {
       
   984 				// The start time of the instance
       
   985 				QDateTime startTime = entry.startTime();
       
   986 				// The instance's start index from the grid start           
       
   987 				int startIndex(gridStart.daysTo(startTime));
       
   988 				// The end time of the instance
       
   989 				QDateTime endTime = entry.endTime();
       
   990 
       
   991 				if (CalenAgendaUtils::endsAtStartOfDayL(entry, endTime)) {
       
   992 					// prevent problems with items ending tomorrow at 00:00
       
   993 					QTime time = endTime.time();
       
   994 					time.setHMS(time.hour(), time.minute() - 1, time.second(),
       
   995 					            time.msec());
       
   996 					endTime.setTime(time);
       
   997 
       
   998 					if (endTime <= gridStart) {
       
   999 						// ends at the start of the grid -> not visible
       
  1000 						continue; // skip
       
  1001 					}
       
  1002 				}
       
  1003 				// The instance's end index from the grid start             
       
  1004 				int endIndex(gridStart.daysTo(endTime));
       
  1005 
       
  1006 				// Mark the days from start index to end index
       
  1007 				for (; startIndex <= endIndex; startIndex++) {
       
  1008 					if (startIndex >= 0 && 
       
  1009 							startIndex < mMonthDataArray.count()) {
       
  1010 						mMonthDataArray[startIndex].SetHasEvents(true);
       
  1011 					}
       
  1012 				} // Parse Anniversaries
       
  1013 			} else if (entry.type() == AgendaEntry::TypeAnniversary) {
       
  1014 				QDateTime startTime = entry.startTime();
       
  1015 				// The instance's start index from the grid start           
       
  1016 				int index(gridStart.daysTo(startTime));
       
  1017 				// Mark the particular day
       
  1018 				if (index >= 0 && index < mMonthDataArray.count()) {
       
  1019 					mMonthDataArray[index].SetHasEvents(true);
       
  1020 				} // Parse To DOs
       
  1021 			} else if (entry.type() == AgendaEntry::TypeTodo) {
       
  1022 				QDateTime startTime = entry.startTime();
       
  1023 				;
       
  1024 				int index;
       
  1025 				// Mark the particular day if the instance's 
       
  1026 				// start time is not in the past
       
  1027 				if (startTime >= today) {
       
  1028 					index = gridStart.daysTo(startTime);
       
  1029 				} else {// Mark for today if the instance's 
       
  1030 					//start time is in the past
       
  1031 					index = todayIndex;
       
  1032 				}
       
  1033 				if (index >= 0 && index < mMonthDataArray.count()) {
       
  1034 					mMonthDataArray[index].SetHasEvents(true);
       
  1035 				}
       
  1036 			}
       
  1037 		}
       
  1038 	}
       
  1039 	list.clear();
       
  1040 }
       
  1041 
       
  1042 /*!
       
  1043  Parses the fetched entries for future month and 
       
  1044  sets hasEvent attribute for necessary days
       
  1045  */
       
  1046 void CalenMonthView::populateNextMonth()
       
  1047 {
       
  1048 	QList<AgendaEntry> list;
       
  1049 	int actualIndex = mNumOfRowsInFutureMonth * KCalenDaysInWeek;
       
  1050 	const QDateTime gridStart(mLastDayOfGrid.addDays(-actualIndex));
       
  1051 	actualIndex = mMonthDataArray.count() - actualIndex -1;
       
  1052 	
       
  1053 	const QDateTime today(CalenDateUtils::today());
       
  1054 	const int todayIndex(gridStart.daysTo(today)); // grid index for "today"
       
  1055 	QDateTime gridEnd(mLastDayOfGrid.date(), QTime(23, 59, 59, 0));
       
  1056 
       
  1057 	getInstanceList(list, gridStart, gridEnd);
       
  1058 
       
  1059 	//Parse fetched items
       
  1060 	if (list.count()) {
       
  1061 		for (int i(0); i < list.count(); i++) {
       
  1062 			AgendaEntry entry = list[i];
       
  1063 
       
  1064 			// Parse  Day Notes, Appointments and Remainders
       
  1065 			// Start and end time of Event/Appointment/Remainders 
       
  1066 			// has to be indentified before marking the tags
       
  1067 			// EEvents/Appointments can span multiple days, 
       
  1068 			// while Anniversaries cannot.
       
  1069 			if ((entry.type() == AgendaEntry::TypeEvent) || (entry.type()
       
  1070 			        == AgendaEntry::TypeAppoinment) || (entry.type()
       
  1071 			        == AgendaEntry::TypeReminder)) {
       
  1072 				// The start time of the instance
       
  1073 				QDateTime startTime = entry.startTime();
       
  1074 				// The instance's start index from the grid start           
       
  1075 				int startIndex(gridStart.daysTo(startTime));
       
  1076 				// The end time of the instance
       
  1077 				QDateTime endTime = entry.endTime();
       
  1078 
       
  1079 				if (CalenAgendaUtils::endsAtStartOfDayL(entry, endTime)) {
       
  1080 					// prevent problems with items ending tomorrow at 00:00
       
  1081 					QTime time = endTime.time();
       
  1082 					time.setHMS(time.hour(), time.minute() - 1, time.second(),
       
  1083 					            time.msec());
       
  1084 					endTime.setTime(time);
       
  1085 
       
  1086 					if (endTime <= gridStart) {
       
  1087 						// ends at the start of the grid -> not visible
       
  1088 						continue; // skip
       
  1089 					}
       
  1090 				}
       
  1091 				// The instance's end index from the grid start             
       
  1092 				int endIndex(gridStart.daysTo(endTime));
       
  1093 
       
  1094 				// Mark the days from start index to end index
       
  1095 				for (; startIndex <= endIndex; startIndex++) {
       
  1096 					if (startIndex >= 0 && 
       
  1097 							startIndex < mMonthDataArray.count()) {
       
  1098 						mMonthDataArray[actualIndex + startIndex].SetHasEvents(true);
       
  1099 					}
       
  1100 				} // Parse Anniversaries
       
  1101 			} else if (entry.type() == AgendaEntry::TypeAnniversary) {
       
  1102 				QDateTime startTime = entry.startTime();
       
  1103 				// The instance's start index from the grid start           
       
  1104 				int index(gridStart.daysTo(startTime));
       
  1105 				// Mark the particular day
       
  1106 				if (actualIndex +index >= 0 && (actualIndex + index) < mMonthDataArray.count()) {
       
  1107 					mMonthDataArray[actualIndex + index].SetHasEvents(true);
       
  1108 				} // Parse To DOs
       
  1109 			} else if (entry.type() == AgendaEntry::TypeTodo) {
       
  1110 				QDateTime startTime = entry.startTime();
       
  1111 				;
       
  1112 				int index;
       
  1113 				// Mark the particular day if the instance's 
       
  1114 				// start time is not in the past
       
  1115 				if (startTime >= today) {
       
  1116 					index = gridStart.daysTo(startTime);
       
  1117 				} else {// Mark for today if the instance's 
       
  1118 					// start time is in the past
       
  1119 					index = todayIndex;
       
  1120 				}
       
  1121 				if (actualIndex + index >= 0 && (actualIndex + index) < mMonthDataArray.count()) {
       
  1122 					mMonthDataArray[actualIndex + index].SetHasEvents(true);
       
  1123 				}
       
  1124 			}
       
  1125 		}
       
  1126 	}
       
  1127 	list.clear();
       
  1128 }
       
  1129 
       
  1130 /*!
       
  1131  Populates the preview pane
       
  1132  */
       
  1133 void CalenMonthView::populatePreviewPane(QDateTime &dateTime)
       
  1134 {
       
  1135 	mPrevPreviewPane->populateLabel(dateTime.addDays(-1));
       
  1136 	mCurrPreviewPane->populateLabel(dateTime);
       
  1137 	mNextPreviewPane->populateLabel(dateTime.addDays(1));
       
  1138 }
       
  1139 
       
  1140 /*!
       
  1141  Completes the population after setting the view as 
       
  1142  current view to the main window
       
  1143  */
       
  1144 void CalenMonthView::completePopulation()
       
  1145 {
       
  1146 	setDateToLabel();
       
  1147 
       
  1148 	//Set this view as current view
       
  1149 	mServices.MainWindow().setCurrentView(this);
       
  1150 }
       
  1151 
       
  1152 /*!
       
  1153  Launches the day view on tapping of the grid item
       
  1154  */
       
  1155 void CalenMonthView::handleGridItemActivated()
       
  1156 {
       
  1157 	mServices.IssueCommandL(ECalenDayView);
       
  1158 }
       
  1159 
       
  1160 /*!
       
  1161  Handles the long press on a grid item
       
  1162  */
       
  1163 void CalenMonthView::handleGridItemLongPressed(int index, QPointF &coords)
       
  1164 {
       
  1165 	QDateTime newActiveDay = CalenDateUtils::futureOf(mFirstDayOfGrid, index);
       
  1166 
       
  1167 	// set the context
       
  1168 	mServices.Context().setFocusDateL(newActiveDay, KCalenMonthViewUidValue);
       
  1169 
       
  1170 	HbMenu *contextMenu = new HbMenu(this);
       
  1171 
       
  1172 	connect(contextMenu->addAction(hbTrId("txt_common_menu_open")), SIGNAL( triggered() ), this,
       
  1173 	        SLOT( launchDayView()));
       
  1174 	// TODO: Add the text id
       
  1175 	connect(contextMenu->addAction("New Todo"), SIGNAL( triggered() ), this,
       
  1176 	        SLOT( createEditor()));
       
  1177 
       
  1178 	// Show context sensitive menu. 
       
  1179 	// Param const QPointF& coordinate - is a longpress position.
       
  1180 	contextMenu->exec(coords);
       
  1181 }
       
  1182 
       
  1183 /*!
       
  1184  Sets the context w.r.t to the active day
       
  1185  */
       
  1186 void CalenMonthView::setContextForActiveDay(int index)
       
  1187 {
       
  1188 	QDateTime newActiveDay = mFirstDayOfGrid.addDays(index);
       
  1189 	// Set the context
       
  1190 	mServices.Context().setFocusDateL(newActiveDay, KCalenMonthViewUidValue);
       
  1191 	mDate = newActiveDay;
       
  1192 	setDateToLabel();
       
  1193 	
       
  1194 	if(!mIsPrevPaneGesture) {
       
  1195 		populatePreviewPane(mDate);
       
  1196 		// Start the auto scroll on current preview pane
       
  1197 		mCurrPreviewPane->startAutoScroll();
       
  1198 	} else {
       
  1199 		// reset flag
       
  1200 		mIsPrevPaneGesture = false;
       
  1201 	}
       
  1202 	
       
  1203 	// Check if we are population for current day, if yes then disable the
       
  1204     // gototoday action
       
  1205     if ((CalenDateUtils::today() == mDate) && mGoToTodayAction) {
       
  1206         mGoToTodayAction->setVisible(false);
       
  1207     } else if (mGoToTodayAction){
       
  1208         mGoToTodayAction->setVisible(true);
    95     }
  1209     }
    96 
  1210 }
    97 // ----------------------------------------------------------------------------
  1211 
    98 // CCalenMonthView::ConstructL
  1212 /*!
    99 // Symbian OS constructor can leave.
  1213  Slot to launch the event editor
   100 // (other items were commented in a header).
  1214  */
   101 // ----------------------------------------------------------------------------
  1215 void CalenMonthView::createEditor()
   102 //
  1216 {
   103 void CCalenMonthView::ConstructL()
  1217 	mServices.IssueCommandL(ECalenNewMeeting);
   104     {
  1218 }
   105     TRACE_ENTRY_POINT;
  1219 
   106 
  1220 /*!
   107     CommonConstructL( R_CALEN_MONTHVIEW_INFO );
  1221  Slot to launch the agenda view
   108     //iLocalisedViewName = StringLoader::LoadL( R_CALEN_VIEW_MONTH, iCoeEnv );
  1222  */
   109 
  1223 void CalenMonthView::launchDayView()
   110     TRACE_EXIT_POINT;
  1224 {
   111     }
  1225 	mServices.IssueCommandL(ECalenDayView);
   112 
  1226 }
   113 // ----------------------------------------------------------------------------
  1227 
   114 // CCalenMonthView::SetStatusPaneFromActiveContextL
  1228 /*!
   115 // Set active date to Status pane
  1229  Slot to handle the change in orientation
   116 // (other items were commented in a header).
  1230  */
   117 // ----------------------------------------------------------------------------
  1231 void CalenMonthView::changeOrientation(Qt::Orientation orientation)
   118 //
  1232 {
   119 void CCalenMonthView::SetStatusPaneFromActiveContextL()
  1233 	if (this == mServices.MainWindow().currentView()) {
   120     {
  1234 		if (mOrientation != orientation) {
   121     TRACE_ENTRY_POINT;
  1235 			// change the orientation here
   122     
  1236 			mOrientation = orientation;
   123     // title pane
  1237 			handleChangeOrientation();
   124     TBuf<KMaxMonthName> title;
  1238 		}
   125     TTime activeDay = CCalenContainer::DateFromContextL( iServices.Context() );
  1239 	}
   126     TDateTime activeDayTime = activeDay.DateTime();
  1240 }
   127     iSPUtils->MonthNameByActiveTime( title, activeDay );
  1241 
   128     iSPUtils->UnderLineTitleText( EFalse );
  1242 /*!
   129     iSPUtils->SetTitleTextL( title );
  1243  Loads appropriate section from the docml dsepending on the current orientation
   130     
  1244  of the device
   131    
  1245  */
   132     // navi pane
  1246 void CalenMonthView::handleChangeOrientation()
   133     CAknNavigationDecorator* naviLabel = iSPUtils->ShowNaviPaneL( activeDay );
  1247 {
   134     ShowValidScrollButtons( *naviLabel,
  1248 	bool loadSuccess = false;
   135                             activeDay - TTimeIntervalMonths(1),
  1249 	if (mOrientation == Qt::Horizontal) {
   136                             activeDay + TTimeIntervalMonths(1) );
  1250 		mDocLoader->load(CALEN_MONTHVIEW_XML_FILE, CALEN_LANDSCAPE,
   137 
  1251 		                 &loadSuccess);
   138     iSPUtils->RefreshStatusPane();
  1252 
   139     TRACE_EXIT_POINT;
  1253 	} else if (mOrientation == Qt::Vertical) {
   140     }
  1254 		mDocLoader->load(CALEN_MONTHVIEW_XML_FILE, CALEN_PORTRAIT, 
   141 
  1255 													&loadSuccess);
   142 // ----------------------------------------------------------------------------
  1256 	}
   143 // CCalenMonthView::DoActivateImplL
  1257 	
   144 // CCalenNativeView::DoActivateL() calls DoActivateImplL()
  1258 	Q_ASSERT_X(loadSuccess, "calenmonthview.cpp", "Unable to load XML");
   145 // (other items were commented in a header).
  1259 	
   146 // ----------------------------------------------------------------------------
  1260 	// Remove the current pane read from the docml  from the layout 
   147 //
  1261 	// and add actual current pane to the layout
   148 void CCalenMonthView::DoActivateImplL(	const TVwsViewId& /*aPrevViewId*/,
  1262 	QGraphicsLinearLayout* viewLayout = static_cast<QGraphicsLinearLayout *>
   149                                         TUid /*aCustomMessageId*/,
  1263 													(widget()->layout());
   150                                         const TDesC8& /*aCustomMessage*/ )
  1264 	viewLayout->removeAt(1);
   151     {
  1265 	viewLayout->addItem(mCurrPaneParent);
   152     TRACE_ENTRY_POINT;
  1266 	
   153 
  1267 
   154     static_cast<CCalenMonthContainer*>(iContainer)->InitDataForMonthL();
  1268 	// Check the weeknumber setting and update it accordingly
   155     
  1269 	if (mIsWeekNumbersShown) {
   156     TRACE_EXIT_POINT;
  1270 		// Add week numbers to week grid
   157     }
  1271 		addWeekNumbers();
   158 
  1272 	} else {
   159 // ----------------------------------------------------------------------------
  1273 		// remove the weeknumbergrid from the layout
   160 // CCalenMonthView::DoDeactivateImpl
  1274 		removeWeekNumbers();
   161 // CCalenNativeView::DoDeactivateL() calls DoDeactivateImplL()
  1275 	}
   162 // (other items were commented in a header).
  1276 }
   163 // ----------------------------------------------------------------------------
  1277 
   164 //
  1278 /*!
   165 void CCalenMonthView::DoDeactivateImpl()
  1279  Sets the appropriate date to the month title
   166     {
  1280  */
   167     TRACE_ENTRY_POINT;
  1281 void CalenMonthView::setDateToLabel()
   168 
  1282 {
   169     if (!iAvkonAppUi->IsDisplayingMenuOrDialog())
  1283 	// Get the localised string for month name from system locale
   170         {
  1284 	QString monthString = mLocale.monthName(mDate.date().month(), HbExtendedLocale::LongFormat);
   171         iSPUtils->HideNaviPane();
  1285 	// Append a single space
   172         //iNaviContainer->Pop(iNaviLabel);
  1286 	monthString.append(" ");
   173         //delete iNaviLabel;
  1287 	mLocale.setNumberOptions(QLocale::OmitGroupSeparator);
   174         //iNaviLabel = NULL;
  1288 	QString yearString = mLocale.toString(mDate.date().year());
   175         }
  1289 	mTitleLabel->setPlainText(hbTrId("txt_calendar_month_label_title_12").arg(monthString).arg(yearString));
   176 
  1290 	QColor monthTitleColor = HbColorScheme::color("qtc_cal_monthgrid_title");
   177     TRACE_EXIT_POINT;
  1291 	if (monthTitleColor.isValid()) {
   178     }
  1292 	    mTitleLabel->setTextColor(monthTitleColor);
   179 
  1293 	}
   180 // ----------------------------------------------------------------------------
  1294 }
   181 // CCalenMonthView::CreateContainerImplL
  1295 
   182 // making CCalendarContainer. In this class, it is CCalenMonthContainer.
  1296 /*!
   183 // (other items were commented in a header).
  1297  To handle previewpane swipe 
   184 // ----------------------------------------------------------------------------
  1298  */
   185 //
  1299 void CalenMonthView::handlePreviewPaneGesture(bool rightGesture)
   186 CCalenContainer* CCalenMonthView::CreateContainerImplL()
  1300 {
   187     {
  1301 	QGraphicsLinearLayout* viewLayout = static_cast<QGraphicsLinearLayout *>
   188     TRACE_ENTRY_POINT;
  1302 												(widget()->layout());
   189 
  1303 	if(rightGesture) {
   190     TRACE_EXIT_POINT;
  1304 		// Need to bring up the previous day preview pane
   191     return new( ELeave )CCalenMonthContainer( this, iDate, iServices );
  1305 		// Create the effect on mCurrPreviewPane to slide to right side
   192     }
  1306 		mPrevPaneParent->setVisible(true);
   193 
  1307 		if (mOrientation == Qt::Vertical) {
   194 // ----------------------------------------------------------------------------
  1308 			HbEffect::add(mCurrPreviewPane,
   195 // CCalenMonthView::OnLocaleChangedL
  1309 						  ":/fxml/portrait_preview_pane_hide_on_right_gesture",
   196 // Locale or Today was changed when this function is called.
  1310 						  "hide");
   197 // (other items were commented in a header).
  1311 			HbEffect::add(mPrevPreviewPane,
   198 // ----------------------------------------------------------------------------
  1312 						  ":/fxml/portrait_preview_pane_show_on_right_gesture",
   199 //
  1313 						  "show");
   200 void CCalenMonthView::OnLocaleChangedL(TInt aReason)
  1314 		} else {
   201     {
  1315 			HbEffect::add(mCurrPreviewPane,
   202     TRACE_ENTRY_POINT;
  1316 						  ":/fxml/landscape_preview_pane_hide_on_right_gesture",
   203 
  1317 						  "hide");
   204     if (iContainer)
  1318 			HbEffect::add(mPrevPreviewPane,
   205         {
  1319 						  ":/fxml/landscape_preview_pane_show_on_right_gesture",
   206         if (iContainer->IsVisible())
  1320 						  "show");
   207             {
  1321 		}
   208             if (aReason & EChangesLocale)
  1322 		// Start the effects
   209                 {
  1323 		HbEffect::start(mCurrPreviewPane, "hide");
   210                 if (IsContainerFocused())
  1324 		HbEffect::start(mPrevPreviewPane, "show", 
   211                     {
  1325 										this, "handleRightEffectCompleted");
   212                     SetStatusPaneFromActiveContextL();
  1326 		
   213                     }
  1327 		//Remove the mCurrPreviewPane from the layout and add mPrevPreviewPane
   214                 else
  1328 		// to the layout
   215                     {
  1329 		viewLayout->removeAt(1);
   216                     iLocChangeReason = aReason;
  1330 		viewLayout->addItem(mPrevPaneParent);
   217                     }
  1331 	} else {
   218                 }
  1332 		// Need to bring up the previous day preview pane
   219            		if ((aReason & EChangesSystemTime ) || (aReason & EChangesMidnightCrossover ))
  1333 		// Create the effect on mCurrPreviewPane to slide to left side
   220                 {
  1334 		mNextPaneParent->setVisible(true);
   221                 static_cast<CCalenMonthContainer*>(iContainer)->ChangesMidnightCrossover();
  1335 		if (mOrientation == Qt::Vertical) {
   222                 }
  1336 			HbEffect::add(mCurrPreviewPane,
   223             }
  1337 						  ":/fxml/portrait_preview_pane_hide_on_left_gesture",
   224         else
  1338 						  "hide");
   225             { // Not visible
  1339 			HbEffect::add(mNextPreviewPane,
   226             iLocChangeReason = aReason;
  1340 						  ":/fxml/portrait_preview_pane_show_on_left_gesture",
   227             }
  1341 						  "show");
   228         }
  1342 		} else {
   229 
  1343 			HbEffect::add(mCurrPreviewPane,
   230     TRACE_EXIT_POINT;
  1344 						  ":/fxml/landscape_preview_pane_hide_on_left_gesture",
   231     }
  1345 						  "hide");
   232 
  1346 			HbEffect::add(mNextPreviewPane,
   233 // ----------------------------------------------------------------------------
  1347 						  ":/fxml/landscape_preview_pane_show_on_left_gesture",
   234 // CCalenMonthView::RedrawStatusPaneL
  1348 						  "show");
   235 // Redraw status pane when Form is closed
  1349 		}
   236 // (other items were commented in a header).
  1350 		
   237 // ----------------------------------------------------------------------------
  1351 		// Start the effects
   238 //
  1352 		HbEffect::start(mCurrPreviewPane, "hide");
   239 void CCalenMonthView::RedrawStatusPaneL()
  1353 		HbEffect::start(mNextPreviewPane, "show", 
   240     {
  1354 										this, "handleLeftEffectCompleted");
   241     TRACE_ENTRY_POINT;
  1355 		
   242 
  1356 		//Remove the mCurrPreviewPane from the layout and add mNextPreviewPane
   243     SetStatusPaneFromActiveContextL();
  1357 		// to the layout
   244 
  1358 		viewLayout->removeAt(1);
   245     static_cast<CCalenMonthContainer*>(
  1359 		viewLayout->addItem(mNextPaneParent);
   246                 iContainer)->ChangesMidnightCrossover();
  1360 	}
   247 	
  1361 }
   248     static_cast<CCalenMonthContainer*>(
  1362 
   249                 iContainer)->RedrawPreviewPane();
  1363 /*!
   250 	
  1364  Function to handle any locale related changes
   251     TRACE_EXIT_POINT;
  1365  */
   252     }
  1366 void CalenMonthView::onLocaleChanged(int reason)
   253 
  1367 {
   254 // ----------------------------------------------------------------------------
  1368 	Q_UNUSED(reason);
   255 // CCalenMonthView::DynInitMenuPaneL
  1369 }
   256 // Changes MenuPane dynamically
  1370 
   257 // (other items were commented in a header).
  1371 /*!
   258 // ----------------------------------------------------------------------------
  1372  Slot to handle left gesture effects completion
   259 //
  1373  */
   260 void CCalenMonthView::DynInitMenuPaneL(TInt aResourceId,
  1374 void CalenMonthView::handleLeftEffectCompleted(
   261                        CEikMenuPane* aMenuPane)
  1375 										const HbEffect::EffectStatus &status)
   262     {
  1376 {
   263     TRACE_ENTRY_POINT;
  1377 	Q_UNUSED(status);
   264 
  1378 	
   265     TBool isEntry = EFalse;
  1379 	int index = getCurrGridIndex();
   266     static_cast<CCalenMonthContainer*>(iContainer)->HidePopup();
  1380 	index++;
   267 
  1381 	
   268 
  1382 	// Stop the scrolling on current preview pane
   269     CCalenNativeView::DynInitMenuPaneL(aResourceId, aMenuPane);
  1383 	mCurrPreviewPane->stopScrolling();
   270     switch (aResourceId)
  1384 	
   271         {
  1385 	// Swap the preview panes properly
   272         case R_CALENDAR_MONTH_MENUPANE:
  1386 	CalenPreviewPane* pane = mCurrPreviewPane;
   273             {
  1387 	HbWidget* paneParent = mCurrPaneParent;
   274 
  1388 	mCurrPreviewPane = mNextPreviewPane;
   275 #ifdef RD_CALEN_EXTERNAL_CAL
  1389 	mCurrPaneParent = mNextPaneParent;
   276             TBool isit=ExtCalendarAvailableL();
  1390 	mNextPreviewPane = mPrevPreviewPane;
   277             if (!isit)
  1391 	mNextPaneParent = mPrevPaneParent;
   278                 {
  1392 	mPrevPreviewPane = pane;
   279                 ReleaseServiceHandler();
  1393 	mPrevPaneParent = paneParent;
   280                 TInt dummy;
  1394 	
   281                 if (aMenuPane->MenuItemExists(ECalenExtAiwCommandId,dummy))
  1395 	// Set the focus to proper date
   282                     {
  1396 	setCurrGridIndex(index);
   283                     aMenuPane->DeleteMenuItem(ECalenExtAiwCommandId);
  1397 	// Start the auto scroll on current preview pane
   284                     }
  1398 	mCurrPreviewPane->startAutoScroll();
   285                 }
  1399 	mNextPreviewPane->populateLabel(mDate.addDays(1));
   286 #endif //RD_CALEN_EXTERNAL_CAL
  1400 }
   287 
  1401 
   288             if ( ! FeatureManager::FeatureSupported(KFeatureIdHelp) )
  1402 /*!
   289                 {
  1403  Slot to handle right gesture effects completion
   290                 aMenuPane->DeleteMenuItem(EAknCmdHelp);
  1404  */
   291                 }
  1405 void CalenMonthView::handleRightEffectCompleted(
   292             
  1406 										const HbEffect::EffectStatus &status) 	
   293             RPointerArray<CCalCalendarInfo> calendarInfoList;
  1407 {
   294             iServices.GetAllCalendarInfoL(calendarInfoList);
  1408 	Q_UNUSED(status);
   295             CleanupClosePushL(calendarInfoList);                            
  1409 	
   296             
  1410 	int index = getCurrGridIndex();
   297             for(TInt index=0 ; index < calendarInfoList.Count();index++ )
  1411 	index--;
   298                 {
  1412 	
   299                 if(calendarInfoList[index]->Enabled() )
  1413 	// Stop the scrolling on current preview pane
   300                     {
  1414 	mCurrPreviewPane->stopScrolling();
   301                     CCalIter* iterator = CCalIter::NewL(
  1415 		
   302                           iServices.SessionL(calendarInfoList[index]->FileNameL()) );
  1416 	// Swap the preview panes properly
   303                     CleanupStack::PushL( iterator );
  1417 	CalenPreviewPane* pane = mCurrPreviewPane;
   304                     if( iterator->FirstL() != KNullDesC8() )
  1418 	HbWidget* paneParent = mCurrPaneParent;
   305                         {
  1419 	mCurrPreviewPane = mPrevPreviewPane;
   306                         isEntry = ETrue;              
  1420 	mCurrPaneParent = mPrevPaneParent;
   307                         }
  1421 	mPrevPreviewPane = mNextPreviewPane;
   308                     CleanupStack::PopAndDestroy( iterator );
  1422 	mPrevPaneParent = mNextPaneParent;
   309                     }
  1423 	mNextPreviewPane = pane;
   310                  
  1424 	mNextPaneParent = paneParent;
   311                 }
  1425 	
   312             CleanupStack::PopAndDestroy(&calendarInfoList);
  1426 	// Set the focus to proper date
   313 
  1427 	setCurrGridIndex(index);
   314             if( !isEntry )
  1428 	// Start the auto scroll on current preview pane
   315                 {
  1429 	mCurrPreviewPane->startAutoScroll();
   316                 aMenuPane->DeleteMenuItem( ECalenDeleteAllEntries );
  1430 	mPrevPreviewPane->populateLabel(mDate.addDays(-1));
   317                 }
  1431 }
   318             if( !iServices.InterimUtilsL().MRViewersEnabledL( ETrue ) )
  1432 // End of file  --Don't remove this.
   319                 {
       
   320                 aMenuPane->DeleteMenuItem( ECalenNewMeetingRequest );
       
   321                 }
       
   322             // Offer the menu pane to the services for customisation by the
       
   323             // the view manager/plugins
       
   324             iServices.OfferMenuPaneL( aResourceId, aMenuPane );
       
   325             }
       
   326             break;
       
   327 
       
   328         default:
       
   329             break;
       
   330         }
       
   331 
       
   332     TRACE_EXIT_POINT;
       
   333     }
       
   334 
       
   335 // ----------------------------------------------------------------------------
       
   336 // CMonthCalenView::HandleCommandL
       
   337 // Command handling for month view.
       
   338 // (other items were commented in a header).
       
   339 // ----------------------------------------------------------------------------
       
   340 //
       
   341 void CCalenMonthView::HandleCommandL(TInt aCommand)
       
   342     {
       
   343     TRACE_ENTRY_POINT;
       
   344 
       
   345     switch (aCommand)
       
   346         {
       
   347         // if MSK Open was selected then switch into Day view.
       
   348         case EAknSoftkeyOpen:
       
   349             CCalenNativeView::HandleCommandL( ECalenForwardsToDayView );
       
   350             break;
       
   351         // otherwise let CCalenNativeView handle the command.
       
   352         default:
       
   353             CCalenNativeView::HandleCommandL(aCommand);
       
   354             break;
       
   355         }
       
   356 
       
   357     TRACE_EXIT_POINT;
       
   358     }
       
   359 
       
   360 // ----------------------------------------------------------------------------
       
   361 // CCalenMonthView::Id
       
   362 // From CAknView
       
   363 // Return the UID of the month view
       
   364 // (other items were commented in a header)
       
   365 // ----------------------------------------------------------------------------
       
   366 //
       
   367 TUid CCalenMonthView::Id() const
       
   368     {
       
   369     TRACE_ENTRY_POINT;
       
   370 
       
   371     TRACE_EXIT_POINT;
       
   372     return KUidCalenMonthView;
       
   373     }
       
   374 
       
   375 // ----------------------------------------------------------------------------
       
   376 // CCalenMonthView::ClearViewSpecificDataL
       
   377 // Clears any cached data for the specific view, e.g. currently
       
   378 // highlighted row, column, etc.
       
   379 // (other items were commented in a header)
       
   380 // ----------------------------------------------------------------------------
       
   381 //
       
   382 void CCalenMonthView::ClearViewSpecificDataL()
       
   383     {
       
   384     TRACE_ENTRY_POINT;
       
   385 
       
   386     iDate = Time::NullTTime();
       
   387 
       
   388     TRACE_EXIT_POINT;
       
   389     }
       
   390 
       
   391 // ----------------------------------------------------------------------------
       
   392 // CCalenMonthView::IsViewSpecificDataNullL
       
   393 // From CCalenNativeView
       
   394 // Returns ETrue if the view specific data is null, EFalse otherwise.
       
   395 // (other items were commented in a header)
       
   396 // ----------------------------------------------------------------------------
       
   397 //
       
   398 TBool CCalenMonthView::IsViewSpecificDataNullL()
       
   399     {
       
   400     TRACE_ENTRY_POINT;
       
   401     TRACE_EXIT_POINT;
       
   402     return ( iDate == Time::NullTTime() );
       
   403     }
       
   404 
       
   405 // ----------------------------------------------------------------------------
       
   406 // CCalenMonthView::ActiveStepL
       
   407 // From CCalenView
       
   408 // (other items were commented in a header)
       
   409 // ----------------------------------------------------------------------------
       
   410 //
       
   411 CCalenView::TNextPopulationStep CCalenMonthView::ActiveStepL()
       
   412     {
       
   413     TRACE_ENTRY_POINT;
       
   414 
       
   415     CCalenMonthContainer* cnt = static_cast<CCalenMonthContainer*>( iContainer );
       
   416 
       
   417     switch( iPopulationStep )
       
   418         {
       
   419         case ENothingDone:
       
   420             {
       
   421             cnt->PrepareForPopulationL();
       
   422             iPopulationStep = ERequestedInstanceView;
       
   423             
       
   424             CCalenView::TNextPopulationStep nextStep = CCalenView::EDone;
       
   425             
       
   426             // Get the active collection ids.
       
   427             RArray<TInt> colIdArray;
       
   428             CCalenNativeView::GetActiveCollectionidsL( iServices, colIdArray );
       
   429             
       
   430             if(colIdArray.Count() > 0)
       
   431                 {
       
   432                 if( !iServices.InstanceViewL(colIdArray) )
       
   433                     {
       
   434                     TRACE_EXIT_POINT;
       
   435                     nextStep = CCalenView::EWaitForInstanceView;
       
   436                     }
       
   437                 else
       
   438                     {
       
   439                     TRACE_EXIT_POINT;
       
   440                     nextStep = CCalenView::EKeepGoing;
       
   441                     }
       
   442                 }
       
   443             else
       
   444                 {
       
   445                 if( !iServices.InstanceViewL() )
       
   446                     {
       
   447                     TRACE_EXIT_POINT;
       
   448                     nextStep = CCalenView::EWaitForInstanceView;
       
   449                     }
       
   450                 else
       
   451                     {
       
   452                     TRACE_EXIT_POINT;
       
   453                     nextStep = CCalenView::EKeepGoing;
       
   454                     }
       
   455                 }
       
   456             colIdArray.Reset();
       
   457             return nextStep;
       
   458             }               
       
   459             
       
   460         case ERequestedInstanceView:
       
   461             {
       
   462             cnt->PopulateWithInstanceViewL();
       
   463             iPopulationStep = ESetIndicatorNext;
       
   464             TRACE_EXIT_POINT;
       
   465             return CCalenView::EKeepGoing;
       
   466             }
       
   467         case ESetIndicatorNext:
       
   468             {
       
   469             cnt->SetIndicatorL();
       
   470             iPopulationStep = ESetFocusNext;
       
   471             TRACE_EXIT_POINT;
       
   472             return CCalenView::EKeepGoing;
       
   473             }
       
   474         case ESetFocusNext:
       
   475             {
       
   476             cnt->SetFocusL();
       
   477             iPopulationStep = EPopulationDone;
       
   478             TRACE_EXIT_POINT;
       
   479             return CCalenView::EKeepGoing;
       
   480             }
       
   481         case EPopulationDone:  /* fall through... */
       
   482         default:
       
   483             {
       
   484             cnt->CompletePopulationL();
       
   485 
       
   486             TRACE_EXIT_POINT;
       
   487             return CCalenView::EDone;
       
   488             }
       
   489         }
       
   490     }
       
   491 
       
   492 // ----------------------------------------------------------------------------
       
   493 // CCalenMonthView::CancelPopulation
       
   494 // From CCalenView
       
   495 // (other items were commented in a header)
       
   496 // ----------------------------------------------------------------------------
       
   497 //
       
   498 void CCalenMonthView::CancelPopulation()
       
   499     {
       
   500     TRACE_ENTRY_POINT;
       
   501 
       
   502     iPopulationStep = ENothingDone;
       
   503 
       
   504     TRACE_EXIT_POINT;
       
   505     }
       
   506 
       
   507 // ----------------------------------------------------------------------------
       
   508 // CCalenMonthView::CyclePosition
       
   509 // From CCalenView
       
   510 // (other items were commented in a header)
       
   511 // ----------------------------------------------------------------------------
       
   512 //
       
   513 CCalenView::TCyclePosition CCalenMonthView::CyclePosition() const
       
   514     {
       
   515     TRACE_ENTRY_POINT;
       
   516     TRACE_EXIT_POINT;
       
   517     return CCalenView::EReplaceMonthView;
       
   518     }
       
   519 
       
   520 // ----------------------------------------------------------------------------
       
   521 // CCalenMonthView::LocalisedViewNameL
       
   522 // From CCalenView
       
   523 // (other items were commented in a header)
       
   524 // ----------------------------------------------------------------------------
       
   525 //
       
   526 const TDesC& CCalenMonthView::LocalisedViewNameL( CCalenView::TViewName aViewName )
       
   527     {
       
   528     TRACE_ENTRY_POINT;
       
   529     
       
   530     HBufC* ret = NULL;
       
   531 
       
   532     switch ( aViewName )
       
   533         {
       
   534         case CCalenView::EMenuName:
       
   535             if ( !iMenuName )
       
   536                 {
       
   537                 iMenuName = StringLoader::LoadL( R_CALEN_VIEW_MONTH, iCoeEnv );
       
   538                 }
       
   539             ret = iMenuName;
       
   540             break;
       
   541         case CCalenView::ESettingsName:
       
   542             if ( !iSettingsName )
       
   543                 {
       
   544                 iSettingsName = StringLoader::LoadL( R_CALEN_QTN_DEFAULT_MONTH_VIEW,
       
   545                                                      iCoeEnv );
       
   546                 }
       
   547             ret = iSettingsName;
       
   548             break;
       
   549         default:
       
   550             ASSERT( EFalse );
       
   551             break;
       
   552         }
       
   553 
       
   554     TRACE_EXIT_POINT;
       
   555     return *ret;
       
   556     }
       
   557 
       
   558 // ----------------------------------------------------------------------------
       
   559 // CCalenMonthView::ViewIconL
       
   560 // From CCalenView
       
   561 // (other items were commented in a header)
       
   562 // ----------------------------------------------------------------------------
       
   563 //
       
   564 CGulIcon* CCalenMonthView::ViewIconL() const
       
   565     {
       
   566     TRACE_ENTRY_POINT;
       
   567     TRACE_EXIT_POINT;
       
   568     return iServices.GetIconL( MCalenServices::ECalenMonthViewIcon );
       
   569     }
       
   570 
       
   571 // ----------------------------------------------------------------------------
       
   572 // CCalenMonthView::UpdatePreviewPaneL
       
   573 // Updates preview pane/preview popup
       
   574 // (other items were commented in a header)
       
   575 // ----------------------------------------------------------------------------
       
   576 //
       
   577 void CCalenMonthView::UpdatePreviewPaneL()
       
   578     {
       
   579     TRACE_ENTRY_POINT;
       
   580     
       
   581     CCalenMonthContainer* cnt = static_cast<CCalenMonthContainer*>( iContainer );
       
   582     if(cnt)
       
   583         {
       
   584         cnt->RedrawPreviewPane();
       
   585         }
       
   586 
       
   587     TRACE_EXIT_POINT;
       
   588     }
       
   589 
       
   590 // ----------------------------------------------------------------------------
       
   591 // CCalenMonthView::HidePreviewPane
       
   592 // Hides preview pane/preview popup
       
   593 // (other items were commented in a header)
       
   594 // ----------------------------------------------------------------------------
       
   595 //
       
   596 void CCalenMonthView::HidePreviewPane()
       
   597     {
       
   598     TRACE_ENTRY_POINT;
       
   599     
       
   600     CCalenMonthContainer* cnt = static_cast<CCalenMonthContainer*>( iContainer );
       
   601     if(cnt)
       
   602         {
       
   603         cnt->HidePopup();
       
   604         }
       
   605     
       
   606     TRACE_EXIT_POINT;
       
   607     }
       
   608 
       
   609 // End of File