calendarui/views/src/calenmonthview.cpp
branchRCL_3
changeset 66 bd7edf625bdd
parent 65 12af337248b1
equal deleted inserted replaced
65:12af337248b1 66:bd7edf625bdd
     1 /*
     1 /*
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2007-2008 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.
     8  *
    15  *
     9  * Initial Contributors:
    16 */
    10  * Nokia Corporation - initial contribution.
    17 
    11  *
    18 
    12  * Contributors:
    19 #include <aknnavide.h>
    13  *
    20 #include <bldvariant.hrh> // For FeatureIds (lint warns without)
    14  * Description:  CalenMonthView implementation.
    21 #include <eikmenup.h>
    15  *
    22 #include <eikspane.h>       //CEikStatusPane
    16  */
    23 #include <StringLoader.h>
    17 
    24 #include <aknappui.h>
    18 //system includes
    25 #include <featmgr.h>
    19 #include <QtGui>
    26 #include <calinstance.h>
    20 #include <xqsettingsmanager.h>
    27 #include <calinstanceview.h>
    21 #include <xqsettingskey.h>
    28 #include <calcommon.h>
    22 #include <hbapplication.h>
    29 #include <caliterator.h>
    23 #include <hbmainwindow.h>
    30 #include <Calendar.rsg>
    24 #include <hbmenu.h>
    31 #include <calencommonui.rsg>
    25 #include <hbaction.h>
    32 #include <calencommands.hrh>            // Calendar commands
    26 #include <hbview.h>
    33 #include <calencontext.h>
    27 #include <hblabel.h>
    34 #include <CalenStatusPaneUtils.h>
    28 #include <hbframeitem.h>
    35 #include <calenservices.h>
    29 #include <hbcolorscheme.h>
    36 #include <caleninstanceid.h>
    30 #include <hbtheme.h>
    37 #include <calenviewutils.h>
    31 #include <agendautil.h>
    38 #include <calcalendarinfo.h>
    32 #include <agendaentry.h>
    39 
    33 #include <hbapplication.h> // hbapplication
    40 #include "calendarui_debug.h"
    34 #include <hbactivitymanager.h> //Activity Manager
       
    35 
       
    36 //user includes
       
    37 #include "calenmonthview.h"
    41 #include "calenmonthview.h"
    38 #include "calenservices.h"
    42 #include "calenmonthcontainer.h"
    39 #include "calennativeview.h"
    43 #include <CalenInterimUtils2.h>
    40 #include "calenview.h"
    44 #include "calentitlepane.h"
    41 #include "calenmonthdata.h"
    45 #include "calensend.h"
    42 #include "calencontext.h"
    46 #include "ToDo.hrh"
    43 #include "calenagendautils.h"
    47 #include "calendar.hrh"
    44 #include "CalenUid.h"
    48 #include "CalenUid.h"
    45 #include "hb_calencommands.hrh" 
    49 
    46 #include "calendateutils.h"
    50 // ================= MEMBER FUNCTIONS =========================================
    47 #include "calenmonthgrid.h"
    51 
    48 #include "calenpreviewpane.h"
    52 // ----------------------------------------------------------------------------
    49 #include "calendocloader.h"
    53 // CCalenMonthView::NewLC
    50 #include "calenthicklinesdrawer.h"
    54 // First stage construction
    51 #include "calencommon.h"
    55 // (other items were commented in a header).
    52 #include "calendarprivatecrkeys.h"
    56 // ----------------------------------------------------------------------------
    53 #include "calenpluginlabel.h"
    57 //
    54 #include "calenconstants.h"
    58 EXPORT_C CCalenMonthView* CCalenMonthView::NewL( MCalenServices& aServices )
    55 #include "OstTraceDefinitions.h"
    59     {
    56 #ifdef OST_TRACE_COMPILER_IN_USE
    60     TRACE_ENTRY_POINT;
    57 #include "calenmonthviewTraces.h"
    61 
    58 #endif
    62     CCalenMonthView* self = new( ELeave ) CCalenMonthView( aServices );
    59 
    63     CleanupStack::PushL( self );
    60 // CONSTANTS
    64     self->ConstructL();
    61 #define WEEKNUMWIDTH 6.41604 // in units, need to update this value if it 
    65     CleanupStack::Pop( self );
    62 								// is changed in the docml
    66 
    63 /*!
    67     TRACE_EXIT_POINT;
    64  \class CalenMonthView
    68     return self;
    65 
    69     }
    66  Class implementing calendar month view
    70 
    67  */
    71 // ----------------------------------------------------------------------------
    68 
    72 // CCalenMonthView::~CCalenMonthView
    69 /*!
    73 // Destructor
    70  Default constructor.
    74 // (other items were commented in a header).
    71  */
    75 // ----------------------------------------------------------------------------
    72 CalenMonthView::CalenMonthView(MCalenServices &services) :
    76 //
    73 	CalenNativeView(services), mAgendaUtil(services.agendaInterface()), 
    77 CCalenMonthView::~CCalenMonthView()
    74 	mGoToTodayAction(0),
    78     {
    75 	mPrevRegionalInfo(0),
    79     TRACE_ENTRY_POINT;
    76 	mCurrRegionalInfo(0),
    80     TRACE_EXIT_POINT;
    77 	mNextRegionalInfo(0),
    81     }
    78 	mIsAboutToQuitEventConnected(false)
    82 
    79 {
    83 // ----------------------------------------------------------------------------
    80     OstTraceFunctionEntry0( CALENMONTHVIEW_CALENMONTHVIEW_ENTRY );
    84 // CCalenMonthView::CCalenMonthView
       
    85 // C++ default constructor can NOT contain any code, that might leave.
       
    86 // (other items were commented in a header).
       
    87 // ----------------------------------------------------------------------------
       
    88 //
       
    89 CCalenMonthView::CCalenMonthView( MCalenServices& aServices )
       
    90     : CCalenNativeView( aServices ),
       
    91       iPopulationStep( ENothingDone )
       
    92     {
       
    93     TRACE_ENTRY_POINT;
       
    94     TRACE_EXIT_POINT;
       
    95     }
       
    96 
       
    97 // ----------------------------------------------------------------------------
       
    98 // CCalenMonthView::ConstructL
       
    99 // Symbian OS constructor can leave.
       
   100 // (other items were commented in a header).
       
   101 // ----------------------------------------------------------------------------
       
   102 //
       
   103 void CCalenMonthView::ConstructL()
       
   104     {
       
   105     TRACE_ENTRY_POINT;
       
   106 
       
   107     CommonConstructL( R_CALEN_MONTHVIEW_INFO );
       
   108     //iLocalisedViewName = StringLoader::LoadL( R_CALEN_VIEW_MONTH, iCoeEnv );
       
   109 
       
   110     TRACE_EXIT_POINT;
       
   111     }
       
   112 
       
   113 // ----------------------------------------------------------------------------
       
   114 // CCalenMonthView::SetStatusPaneFromActiveContextL
       
   115 // Set active date to Status pane
       
   116 // (other items were commented in a header).
       
   117 // ----------------------------------------------------------------------------
       
   118 //
       
   119 void CCalenMonthView::SetStatusPaneFromActiveContextL()
       
   120     {
       
   121     TRACE_ENTRY_POINT;
    81     
   122     
    82 	mIsWeekNumbersShown = 0;
   123     // title pane
    83 	mOrientation = mServices.MainWindow().orientation();
   124     TBuf<KMaxMonthName> title;
    84 	// Read the date from the context
   125     TTime activeDay = CCalenContainer::DateFromContextL( iServices.Context() );
    85 	mDate = mServices.Context().focusDateAndTime();
   126     TDateTime activeDayTime = activeDay.DateTime();
    86 	mCurrentDay = mDate;
   127     iSPUtils->MonthNameByActiveTime( title, activeDay );
    87 
   128     iSPUtils->UnderLineTitleText( EFalse );
    88 	// Create the settings manager instance and settings key for week number
   129     iSPUtils->SetTitleTextL( title );
    89 	mSettingsManager = new XQSettingsManager(this);
   130     
    90 	mWeekNumberCenrepKey
   131    
    91 	        = new XQSettingsKey(XQSettingsKey::TargetCentralRepository,
   132     // navi pane
    92 	                            KCRUidCalendar, KCalendarShowWeekNum);
   133     CAknNavigationDecorator* naviLabel = iSPUtils->ShowNaviPaneL( activeDay );
    93 
   134     ShowValidScrollButtons( *naviLabel,
    94 	mLocale = HbExtendedLocale::system();
   135                             activeDay - TTimeIntervalMonths(1),
    95 	mFirstWeekLabel = NULL;
   136                             activeDay + TTimeIntervalMonths(1) );
    96 	mIsPrevPaneGesture = false;
   137 
    97 	// Get the week day and preview heading color from the theme
   138     iSPUtils->RefreshStatusPane();
    98 	mWeekDaysColor = HbColorScheme::color("qtc_cal_week_day");
   139     TRACE_EXIT_POINT;
       
   140     }
       
   141 
       
   142 // ----------------------------------------------------------------------------
       
   143 // CCalenMonthView::DoActivateImplL
       
   144 // CCalenNativeView::DoActivateL() calls DoActivateImplL()
       
   145 // (other items were commented in a header).
       
   146 // ----------------------------------------------------------------------------
       
   147 //
       
   148 void CCalenMonthView::DoActivateImplL(	const TVwsViewId& /*aPrevViewId*/,
       
   149                                         TUid /*aCustomMessageId*/,
       
   150                                         const TDesC8& /*aCustomMessage*/ )
       
   151     {
       
   152     TRACE_ENTRY_POINT;
       
   153 
       
   154     static_cast<CCalenMonthContainer*>(iContainer)->InitDataForMonthL();
       
   155     
       
   156     TRACE_EXIT_POINT;
       
   157     }
       
   158 
       
   159 // ----------------------------------------------------------------------------
       
   160 // CCalenMonthView::DoDeactivateImpl
       
   161 // CCalenNativeView::DoDeactivateL() calls DoDeactivateImplL()
       
   162 // (other items were commented in a header).
       
   163 // ----------------------------------------------------------------------------
       
   164 //
       
   165 void CCalenMonthView::DoDeactivateImpl()
       
   166     {
       
   167     TRACE_ENTRY_POINT;
       
   168 
       
   169     if (!iAvkonAppUi->IsDisplayingMenuOrDialog())
       
   170         {
       
   171         iSPUtils->HideNaviPane();
       
   172         //iNaviContainer->Pop(iNaviLabel);
       
   173         //delete iNaviLabel;
       
   174         //iNaviLabel = NULL;
       
   175         }
       
   176 
       
   177     TRACE_EXIT_POINT;
       
   178     }
       
   179 
       
   180 // ----------------------------------------------------------------------------
       
   181 // CCalenMonthView::CreateContainerImplL
       
   182 // making CCalendarContainer. In this class, it is CCalenMonthContainer.
       
   183 // (other items were commented in a header).
       
   184 // ----------------------------------------------------------------------------
       
   185 //
       
   186 CCalenContainer* CCalenMonthView::CreateContainerImplL()
       
   187     {
       
   188     TRACE_ENTRY_POINT;
       
   189 
       
   190     TRACE_EXIT_POINT;
       
   191     return new( ELeave )CCalenMonthContainer( this, iDate, iServices );
       
   192     }
       
   193 
       
   194 // ----------------------------------------------------------------------------
       
   195 // CCalenMonthView::OnLocaleChangedL
       
   196 // Locale or Today was changed when this function is called.
       
   197 // (other items were commented in a header).
       
   198 // ----------------------------------------------------------------------------
       
   199 //
       
   200 void CCalenMonthView::OnLocaleChangedL(TInt aReason)
       
   201     {
       
   202     TRACE_ENTRY_POINT;
       
   203 
       
   204     if (iContainer)
       
   205         {
       
   206         if (iContainer->IsVisible())
       
   207             {
       
   208             if (aReason & EChangesLocale)
       
   209                 {
       
   210                 if (IsContainerFocused())
       
   211                     {
       
   212                     SetStatusPaneFromActiveContextL();
       
   213                     }
       
   214                 else
       
   215                     {
       
   216                     iLocChangeReason = aReason;
       
   217                     }
       
   218                 }
       
   219            		if ((aReason & EChangesSystemTime ) || (aReason & EChangesMidnightCrossover ))
       
   220                 {
       
   221                 static_cast<CCalenMonthContainer*>(iContainer)->ChangesMidnightCrossover();
       
   222                 }
       
   223             }
       
   224         else
       
   225             { // Not visible
       
   226             iLocChangeReason = aReason;
       
   227             }
       
   228         }
       
   229 
       
   230     TRACE_EXIT_POINT;
       
   231     }
       
   232 
       
   233 // ----------------------------------------------------------------------------
       
   234 // CCalenMonthView::RedrawStatusPaneL
       
   235 // Redraw status pane when Form is closed
       
   236 // (other items were commented in a header).
       
   237 // ----------------------------------------------------------------------------
       
   238 //
       
   239 void CCalenMonthView::RedrawStatusPaneL()
       
   240     {
       
   241     TRACE_ENTRY_POINT;
       
   242 
       
   243     SetStatusPaneFromActiveContextL();
       
   244 
       
   245     static_cast<CCalenMonthContainer*>(
       
   246                 iContainer)->ChangesMidnightCrossover();
    99 	
   247 	
   100 	mPreviewHeadingColor = HbColorScheme::color("qtc_cal_day_preview_heading");
   248     static_cast<CCalenMonthContainer*>(
       
   249                 iContainer)->RedrawPreviewPane();
   101 	
   250 	
   102     connect(HbTheme::instance(), SIGNAL(changed()),
   251     TRACE_EXIT_POINT;
   103                 this, SLOT(handleThemeChange()));
   252     }
       
   253 
       
   254 // ----------------------------------------------------------------------------
       
   255 // CCalenMonthView::DynInitMenuPaneL
       
   256 // Changes MenuPane dynamically
       
   257 // (other items were commented in a header).
       
   258 // ----------------------------------------------------------------------------
       
   259 //
       
   260 void CCalenMonthView::DynInitMenuPaneL(TInt aResourceId,
       
   261                        CEikMenuPane* aMenuPane)
       
   262     {
       
   263     TRACE_ENTRY_POINT;
       
   264 
       
   265     TBool isEntry = EFalse;
       
   266     static_cast<CCalenMonthContainer*>(iContainer)->HidePopup();
       
   267 
       
   268 
       
   269     CCalenNativeView::DynInitMenuPaneL(aResourceId, aMenuPane);
       
   270     switch (aResourceId)
       
   271         {
       
   272         case R_CALENDAR_MONTH_MENUPANE:
       
   273             {
       
   274 
       
   275 #ifdef RD_CALEN_EXTERNAL_CAL
       
   276             TBool isit=ExtCalendarAvailableL();
       
   277             if (!isit)
       
   278                 {
       
   279                 ReleaseServiceHandler();
       
   280                 TInt dummy;
       
   281                 if (aMenuPane->MenuItemExists(ECalenExtAiwCommandId,dummy))
       
   282                     {
       
   283                     aMenuPane->DeleteMenuItem(ECalenExtAiwCommandId);
       
   284                     }
       
   285                 }
       
   286 #endif //RD_CALEN_EXTERNAL_CAL
       
   287 
       
   288             if ( ! FeatureManager::FeatureSupported(KFeatureIdHelp) )
       
   289                 {
       
   290                 aMenuPane->DeleteMenuItem(EAknCmdHelp);
       
   291                 }
       
   292             
       
   293             RPointerArray<CCalCalendarInfo> calendarInfoList;
       
   294             iServices.GetAllCalendarInfoL(calendarInfoList);
       
   295             CleanupClosePushL(calendarInfoList);                            
       
   296             
       
   297             for(TInt index=0 ; index < calendarInfoList.Count();index++ )
       
   298                 {
       
   299                 if(calendarInfoList[index]->Enabled() )
       
   300                     {
       
   301                     CCalIter* iterator = CCalIter::NewL(
       
   302                           iServices.SessionL(calendarInfoList[index]->FileNameL()) );
       
   303                     CleanupStack::PushL( iterator );
       
   304                     if( iterator->FirstL() != KNullDesC8() )
       
   305                         {
       
   306                         isEntry = ETrue;              
       
   307                         }
       
   308                     CleanupStack::PopAndDestroy( iterator );
       
   309                     }
       
   310                  
       
   311                 }
       
   312             CleanupStack::PopAndDestroy(&calendarInfoList);
       
   313 
       
   314             if( !isEntry )
       
   315                 {
       
   316                 aMenuPane->DeleteMenuItem( ECalenDeleteAllEntries );
       
   317                 }
       
   318             if( !iServices.InterimUtilsL().MRViewersEnabledL( ETrue ) )
       
   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     if(!cnt)
       
   417         {
       
   418         TRACE_EXIT_POINT;
       
   419         iPopulationStep = EPopulationDone;
       
   420         return CCalenView::EDone;
       
   421         }
       
   422         
       
   423     switch( iPopulationStep )
       
   424         {
       
   425         case ENothingDone:
       
   426             {
       
   427             cnt->PrepareForPopulationL();
       
   428             iPopulationStep = ERequestedInstanceView;
       
   429             
       
   430             CCalenView::TNextPopulationStep nextStep = CCalenView::EDone;
       
   431             
       
   432             // Get the active collection ids.
       
   433             RArray<TInt> colIdArray;
       
   434             CCalenNativeView::GetActiveCollectionidsL( iServices, colIdArray );
       
   435             
       
   436             if(colIdArray.Count() > 0)
       
   437                 {
       
   438                 if( !iServices.InstanceViewL(colIdArray) )
       
   439                     {
       
   440                     TRACE_EXIT_POINT;
       
   441                     nextStep = CCalenView::EWaitForInstanceView;
       
   442                     }
       
   443                 else
       
   444                     {
       
   445                     TRACE_EXIT_POINT;
       
   446                     nextStep = CCalenView::EKeepGoing;
       
   447                     }
       
   448                 }
       
   449             else
       
   450                 {
       
   451                 if( !iServices.InstanceViewL() )
       
   452                     {
       
   453                     TRACE_EXIT_POINT;
       
   454                     nextStep = CCalenView::EWaitForInstanceView;
       
   455                     }
       
   456                 else
       
   457                     {
       
   458                     TRACE_EXIT_POINT;
       
   459                     nextStep = CCalenView::EKeepGoing;
       
   460                     }
       
   461                 }
       
   462             colIdArray.Reset();
       
   463             return nextStep;
       
   464             }               
       
   465             
       
   466         case ERequestedInstanceView:
       
   467             {
       
   468             cnt->PopulateWithInstanceViewL();
       
   469             iPopulationStep = ESetIndicatorNext;
       
   470             TRACE_EXIT_POINT;
       
   471             return CCalenView::EKeepGoing;
       
   472             }
       
   473         case ESetIndicatorNext:
       
   474             {
       
   475             cnt->SetIndicatorL();
       
   476             iPopulationStep = ESetFocusNext;
       
   477             TRACE_EXIT_POINT;
       
   478             return CCalenView::EKeepGoing;
       
   479             }
       
   480         case ESetFocusNext:
       
   481             {
       
   482             cnt->SetFocusL();
       
   483             iPopulationStep = EPopulationDone;
       
   484             TRACE_EXIT_POINT;
       
   485             return CCalenView::EKeepGoing;
       
   486             }
       
   487         case EPopulationDone:  /* fall through... */
       
   488         default:
       
   489             {
       
   490             cnt->CompletePopulationL();
       
   491 
       
   492             TRACE_EXIT_POINT;
       
   493             return CCalenView::EDone;
       
   494             }
       
   495         }
       
   496     }
       
   497 
       
   498 // ----------------------------------------------------------------------------
       
   499 // CCalenMonthView::CancelPopulation
       
   500 // From CCalenView
       
   501 // (other items were commented in a header)
       
   502 // ----------------------------------------------------------------------------
       
   503 //
       
   504 void CCalenMonthView::CancelPopulation()
       
   505     {
       
   506     TRACE_ENTRY_POINT;
       
   507 
       
   508     iPopulationStep = ENothingDone;
       
   509 
       
   510     TRACE_EXIT_POINT;
       
   511     }
       
   512 
       
   513 // ----------------------------------------------------------------------------
       
   514 // CCalenMonthView::CyclePosition
       
   515 // From CCalenView
       
   516 // (other items were commented in a header)
       
   517 // ----------------------------------------------------------------------------
       
   518 //
       
   519 CCalenView::TCyclePosition CCalenMonthView::CyclePosition() const
       
   520     {
       
   521     TRACE_ENTRY_POINT;
       
   522     TRACE_EXIT_POINT;
       
   523     return CCalenView::EReplaceMonthView;
       
   524     }
       
   525 
       
   526 // ----------------------------------------------------------------------------
       
   527 // CCalenMonthView::LocalisedViewNameL
       
   528 // From CCalenView
       
   529 // (other items were commented in a header)
       
   530 // ----------------------------------------------------------------------------
       
   531 //
       
   532 const TDesC& CCalenMonthView::LocalisedViewNameL( CCalenView::TViewName aViewName )
       
   533     {
       
   534     TRACE_ENTRY_POINT;
   104     
   535     
   105 	OstTraceFunctionExit0( CALENMONTHVIEW_CALENMONTHVIEW_EXIT );
   536     HBufC* ret = NULL;
   106 }
   537 
   107 
   538     switch ( aViewName )
   108 /*!
   539         {
   109  Destructor.
   540         case CCalenView::EMenuName:
   110  */
   541             if ( !iMenuName )
   111 CalenMonthView::~CalenMonthView()
   542                 {
   112 {
   543                 iMenuName = StringLoader::LoadL( R_CALEN_VIEW_MONTH, iCoeEnv );
   113     OstTraceFunctionEntry0( DUP1_CALENMONTHVIEW_CALENMONTHVIEW_ENTRY );
   544                 }
       
   545             ret = iMenuName;
       
   546             break;
       
   547         case CCalenView::ESettingsName:
       
   548             if ( !iSettingsName )
       
   549                 {
       
   550                 iSettingsName = StringLoader::LoadL( R_CALEN_QTN_DEFAULT_MONTH_VIEW,
       
   551                                                      iCoeEnv );
       
   552                 }
       
   553             ret = iSettingsName;
       
   554             break;
       
   555         default:
       
   556             ASSERT( EFalse );
       
   557             break;
       
   558         }
       
   559 
       
   560     TRACE_EXIT_POINT;
       
   561     return *ret;
       
   562     }
       
   563 
       
   564 // ----------------------------------------------------------------------------
       
   565 // CCalenMonthView::ViewIconL
       
   566 // From CCalenView
       
   567 // (other items were commented in a header)
       
   568 // ----------------------------------------------------------------------------
       
   569 //
       
   570 CGulIcon* CCalenMonthView::ViewIconL() const
       
   571     {
       
   572     TRACE_ENTRY_POINT;
       
   573     TRACE_EXIT_POINT;
       
   574     return iServices.GetIconL( MCalenServices::ECalenMonthViewIcon );
       
   575     }
       
   576 
       
   577 // ----------------------------------------------------------------------------
       
   578 // CCalenMonthView::UpdatePreviewPaneL
       
   579 // Updates preview pane/preview popup
       
   580 // (other items were commented in a header)
       
   581 // ----------------------------------------------------------------------------
       
   582 //
       
   583 void CCalenMonthView::UpdatePreviewPaneL()
       
   584     {
       
   585     TRACE_ENTRY_POINT;
   114     
   586     
   115     OstTraceFunctionExit0( DUP1_CALENMONTHVIEW_CALENMONTHVIEW_EXIT );
   587     CCalenMonthContainer* cnt = static_cast<CCalenMonthContainer*>( iContainer );
   116 }
   588     if(cnt)
   117 
   589         {
   118 /*!
   590         cnt->RedrawPreviewPane();
   119  Called by the CalenViewManager after loading the view from the docml.
   591         }
   120  The initializaion/setup of the view is done here. 
   592 
   121  */
   593     TRACE_EXIT_POINT;
   122 void CalenMonthView::setupView(CalenDocLoader *docLoader)
   594     }
   123 {
   595 
   124     OstTraceFunctionEntry0( CALENMONTHVIEW_SETUPVIEW_ENTRY );
   596 // ----------------------------------------------------------------------------
       
   597 // CCalenMonthView::HidePreviewPane
       
   598 // Hides preview pane/preview popup
       
   599 // (other items were commented in a header)
       
   600 // ----------------------------------------------------------------------------
       
   601 //
       
   602 void CCalenMonthView::HidePreviewPane()
       
   603     {
       
   604     TRACE_ENTRY_POINT;
   125     
   605     
   126 	mDocLoader = docLoader;
   606     CCalenMonthContainer* cnt = static_cast<CCalenMonthContainer*>( iContainer );
   127 	mTitleLabel
   607     if(cnt)
   128 	        = qobject_cast<HbLabel *> (
   608         {
   129 								   mDocLoader->findWidget(CALEN_MONTH_TITLE));
   609         cnt->HidePopup();
   130 	// Set the title text color
   610         }
   131 	QColor monthTitleColor = HbColorScheme::color("qtc_cal_monthgrid_title");
       
   132 	if (mTitleLabel && monthTitleColor.isValid()) {
       
   133 		mTitleLabel->setTextColor(monthTitleColor);
       
   134 	}
       
   135 		
       
   136 	mDayNameWidget
       
   137 	        = qobject_cast<CalenThickLinesDrawer *> (
       
   138 													mDocLoader->findWidget(
       
   139 													CALEN_DAYNAMES_WIDGET));
       
   140 
       
   141 	// Get all the seven day labels
       
   142 	mFirstDayLabel
       
   143 	        = qobject_cast<HbLabel *> (
       
   144 						mDocLoader->findWidget(CALEN_MONTVIEW_FIRST_DAY_LABEL));
       
   145 	mSecondDayLabel
       
   146 	        = qobject_cast<HbLabel *> (
       
   147 					   mDocLoader->findWidget(CALEN_MONTVIEW_SECOND_DAY_LABEL));
       
   148 	mThirdDayLabel
       
   149 	        = qobject_cast<HbLabel *> (
       
   150 					   mDocLoader->findWidget(CALEN_MONTVIEW_THIRD_DAY_LABEL));
       
   151 	mFourthDayLabel
       
   152 	        = qobject_cast<HbLabel *> (
       
   153 					   mDocLoader->findWidget(CALEN_MONTVIEW_FOURTH_DAY_LABEL));
       
   154 	mFifthDayLabel
       
   155 	        = qobject_cast<HbLabel *> (
       
   156 					   mDocLoader->findWidget(CALEN_MONTVIEW_FIFTH_DAY_LABEL));
       
   157 	mSixthDayLabel
       
   158 	        = qobject_cast<HbLabel *> (
       
   159 					   mDocLoader->findWidget(CALEN_MONTVIEW_SIXTH_DAY_LABEL));
       
   160 	mSeventhDayLabel
       
   161 	        = qobject_cast<HbLabel *> (
       
   162 					mDocLoader->findWidget(CALEN_MONTVIEW_SEVENTH_DAY_LABEL));
       
   163 	
       
   164 	// Get the weeknumber widget
       
   165 	mWeekNumberWidget
       
   166 			= qobject_cast<CalenThickLinesDrawer *> (
       
   167 							 mDocLoader->findWidget(CALEN_WEEKNUMBERS_WIDGET));
       
   168 	// Disable the item so that line seperator doesnt gets drawn by default
       
   169 	mWeekNumberWidget->setEnabled(false);
       
   170 
       
   171 	// Get the month grid
       
   172 	mMonthGrid
       
   173 	        = qobject_cast<CalenMonthGrid *> (
       
   174 									mDocLoader->findWidget(CALEN_MONTHGRID));
       
   175 	mCurrPaneParent = qobject_cast<HbWidget *> (
       
   176 			mDocLoader->findWidget(CALEN_CURRPREVIEWPARENT));
       
   177 	// Get current day preview pane widget
       
   178 	mCurrPreviewPane
       
   179 			= static_cast<CalenPreviewPane *> (
       
   180 					docLoader->findWidget(CALEN_CURRPREVIEWPANE));
       
   181 	//mCurrPreviewPane->setParent(mCurrPaneParent);
       
   182 	mCurrPaneParent->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
       
   183 	HbLabel* currPaneNoEntriesLabel = static_cast<HbLabel *> (
       
   184 			docLoader->findWidget(CALEN_NOENTRIES_LABEL_CURR));
       
   185 	mCurrPreviewPane->setView(this);
       
   186 	mCurrPreviewPane->setNoEntriesLabel(currPaneNoEntriesLabel);
       
   187 	
       
   188     connect(
       
   189             HbTheme::instance(), SIGNAL(changed()),
       
   190             mCurrPreviewPane, SLOT(handleThemeChange()));
       
   191 	
       
   192 	mCurrPaneLayoutWidget = qobject_cast<HbWidget*>(docLoader->findWidget(CALEN_CURRPANELAYOUT));
       
   193 	mCurrPaneLayout = static_cast<QGraphicsLinearLayout*>(mCurrPaneLayoutWidget->layout());
       
   194 	
       
   195 	mPrevPaneParent = qobject_cast<HbWidget *> (
       
   196 			mDocLoader->findWidget(CALEN_PREVPREVIEWPARENT));
       
   197 	// Get previous day preview pane widget
       
   198 	mPrevPreviewPane
       
   199 			= static_cast<CalenPreviewPane *> (
       
   200 					docLoader->findWidget(CALEN_PREVPREVIEWPANE));
       
   201 	//mPrevPreviewPane->setParent(mPrevPaneParent);
       
   202 	mPrevPaneParent->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
       
   203 	HbLabel* prevPaneNoEntriesLabel = static_cast<HbLabel *> (
       
   204 			docLoader->findWidget(CALEN_NOENTRIES_LABEL_PREV));
       
   205 	mPrevPreviewPane->setView(this);
       
   206 	mPrevPreviewPane->setNoEntriesLabel(prevPaneNoEntriesLabel);
       
   207     connect(
       
   208             HbTheme::instance(), SIGNAL(changed()),
       
   209             mPrevPreviewPane, SLOT(handleThemeChange()));
       
   210 	mPrevPaneParent->setVisible(false);
       
   211 	
       
   212 	mPrevPaneLayoutWidget = qobject_cast<HbWidget*>(docLoader->findWidget(CALEN_PREVPANELAYOUT));
       
   213 	mPrevPaneLayout = static_cast<QGraphicsLinearLayout*>(mPrevPaneLayoutWidget->layout());
       
   214 	mNextPaneParent = qobject_cast<HbWidget *> (
       
   215 			mDocLoader->findWidget(CALEN_NEXTPREVIEWPARENT));
       
   216 	// Get next day preview pane widget
       
   217 	mNextPreviewPane
       
   218 			= static_cast<CalenPreviewPane *> (
       
   219 					docLoader->findWidget(CALEN_NEXTPREVIEWPANE));
       
   220 	//mNextPreviewPane->setParent(mNextPaneParent);
       
   221 	mNextPaneParent->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
       
   222 	HbLabel* nextPaneNoEntriesLabel = static_cast<HbLabel *> (
       
   223 			docLoader->findWidget(CALEN_NOENTRIES_LABEL_NEXT));
       
   224 	mNextPreviewPane->setView(this);
       
   225 	mNextPreviewPane->setNoEntriesLabel(nextPaneNoEntriesLabel);
       
   226     connect(
       
   227             HbTheme::instance(), SIGNAL(changed()),
       
   228             mNextPreviewPane, SLOT(handleThemeChange()));
       
   229     
   611     
   230 	mNextPaneParent->setVisible(false);
   612     TRACE_EXIT_POINT;
   231 	mNextPaneLayoutWidget = qobject_cast<HbWidget*>(docLoader->findWidget(CALEN_NEXTPANELAYOUT));
   613     }
   232 	mNextPaneLayout = static_cast<QGraphicsLinearLayout*>(mNextPaneLayoutWidget->layout());
   614 
   233 	
   615 // End of File
   234 	mMonthGridPlusWeekNumWidget
       
   235 	        = qobject_cast<HbWidget *> (
       
   236 					mDocLoader->findWidget(CALEN_MONTHGRID_WEEKNUMBERS_WIDGET));
       
   237 
       
   238 	mMonthGrid->setView(this);
       
   239 
       
   240 	
       
   241 	
       
   242 	mIsFirstTimeLoad = true;
       
   243 	// get a pointner to activity manager
       
   244 	HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
       
   245 
       
   246 	// clean up any previous versions of this activity, if any, i.e. activityName, from the activity manager. 
       
   247 	// Ignore return value, first boot would always return False. bool declared 
       
   248 	// only for debugging purpose.
       
   249 	bool ok = activityManager->removeActivity(activityName);
       
   250 
       
   251 	OstTraceFunctionExit0( CALENMONTHVIEW_SETUPVIEW_EXIT );
       
   252 }
       
   253 
       
   254 /*!
       
   255  Constructs the remaining part of the month view that was kept as 
       
   256  part if lazy loading
       
   257  */
       
   258 void CalenMonthView::doLazyLoading()
       
   259 {
       
   260     OstTraceFunctionEntry0( CALENMONTHVIEW_DOLAZYLOADING_ENTRY );
       
   261 	// Add background items to all the widgets
       
   262 	addBackgroundFrame();
       
   263 	
       
   264 	// Construct and add the previous month and next month items to the view
       
   265 	mMonthGrid->updateMonthGridWithInActiveMonths(mMonthDataArray);
       
   266 	
       
   267 	// Check if regional information needs to be shown
       
   268 	// and add it or remove it
       
   269 	showHideRegionalInformation();
       
   270 	
       
   271 	// Connect to the menu actions
       
   272 	HbAction
       
   273 			*newEventAction =
       
   274 					qobject_cast<HbAction *> (
       
   275 						mDocLoader->findObject(CALEN_MONTVIEW_MENU_NEWEVENT));
       
   276 
       
   277 	connect(newEventAction, SIGNAL(triggered()), this, SLOT(createEditor()));
       
   278 
       
   279 	mGoToTodayAction =
       
   280 					qobject_cast<HbAction *> (
       
   281 							mDocLoader->findObject(CALEN_MONTVIEW_MENU_GOTOTODAY));
       
   282 	connect(mGoToTodayAction, SIGNAL(triggered()), this, SLOT(goToToday()));
       
   283 	
       
   284 	HbAction
       
   285 			*goToDateAction =
       
   286 					qobject_cast<HbAction *> (
       
   287 						mDocLoader->findObject(CALEN_MONTVIEW_MENU_GOTODATE));
       
   288 
       
   289 	connect(goToDateAction, SIGNAL(triggered()), this, SLOT(goToDate()));
       
   290 
       
   291 	// TODO: Need to move this to docml
       
   292 	// Set the title to the submenu
       
   293 	mDeleteSubMenu =
       
   294 	                qobject_cast<HbMenu *> (
       
   295 						mDocLoader->findObject(CALEN_MONTVIEW_DELETE_SUBMENU));
       
   296 	mDeleteSubMenu->setTitle(hbTrId("txt_calendar_opt_delete_entries"));
       
   297 
       
   298 	HbAction
       
   299 	        *beforeDateAction =
       
   300 	                qobject_cast<HbAction *> (
       
   301 						mDocLoader->findObject(CALEN_MONTVIEW_MENU_BEFOREDATE));
       
   302 
       
   303 	connect(beforeDateAction, SIGNAL(triggered()), this,
       
   304 	        SLOT(deleteBeforeDate()));
       
   305 
       
   306 	HbAction
       
   307 	        *allEntriesAction =
       
   308 	                qobject_cast<HbAction *> (
       
   309 						mDocLoader->findObject(CALEN_MONTVIEW_MENU_ALLENTRIES));
       
   310 
       
   311 	connect(allEntriesAction, SIGNAL(triggered()), this,
       
   312 	        SLOT(deleteAllEntries()));
       
   313 
       
   314 	HbAction
       
   315 	        *settingsAction =
       
   316 	                qobject_cast<HbAction *> (
       
   317 						mDocLoader->findObject(CALEN_MONTVIEW_MENU_SETTINGS));
       
   318 
       
   319 	connect(settingsAction, SIGNAL(triggered()), this,
       
   320 	        SLOT(launchSettingsView()));
       
   321 
       
   322 
       
   323 	// Connect to the signal of change orientation.
       
   324 	connect(&(mServices.MainWindow()),
       
   325 	        SIGNAL(orientationChanged(Qt::Orientation)), this,
       
   326 	        SLOT(changeOrientation(Qt::Orientation)));
       
   327 	
       
   328 	// Connect to the signal when options menu is shown
       
   329 	// This is required to add/remove dynamically some options
       
   330 	connect(menu(), SIGNAL(aboutToShow ()), this,
       
   331 			SLOT(addRemoveActionsInMenu()));	
       
   332 	//add "show lunar data" action item ,if regional plugin is present
       
   333 	//regional plugin will add the option itself and handles it accordingly
       
   334 	//use this api after adding all action item to the menu
       
   335 	//so that plugin add the "Show lunar data" item as a second last option 
       
   336 	// in all views
       
   337 	mServices.OfferMenu(menu());
       
   338 	
       
   339 	OstTraceFunctionExit0( CALENMONTHVIEW_DOLAZYLOADING_EXIT );
       
   340 }
       
   341 
       
   342 /*!
       
   343  Adds the week numbers to the weeknumber widget
       
   344  */
       
   345 void CalenMonthView::addWeekNumbers()
       
   346 {
       
   347     OstTraceFunctionEntry0( CALENMONTHVIEW_ADDWEEKNUMBERS_ENTRY );
       
   348     
       
   349 	if (!mFirstWeekLabel) {
       
   350 	// Get all the six week labels
       
   351 	mFirstWeekLabel
       
   352 			= qobject_cast<HbLabel *> (
       
   353 					mDocLoader->findWidget(CALEN_MONTVIEW_FIRST_WEEK_LABEL));
       
   354 	mSecondWeekLabel
       
   355 			= qobject_cast<HbLabel *> (
       
   356 					mDocLoader->findWidget(CALEN_MONTVIEW_SECOND_WEEK_LABEL));
       
   357 	mThirdWeekLabel
       
   358 			= qobject_cast<HbLabel *> (
       
   359 					mDocLoader->findWidget(CALEN_MONTVIEW_THIRD_WEEK_LABEL));
       
   360 	mFourthWeekLabel
       
   361 			= qobject_cast<HbLabel *> (
       
   362 					mDocLoader->findWidget(CALEN_MONTVIEW_FOURTH_WEEK_LABEL));
       
   363 	mFifthWeekLabel
       
   364 			= qobject_cast<HbLabel *> (
       
   365 					mDocLoader->findWidget(CALEN_MONTVIEW_FIFTH_WEEK_LABEL));
       
   366 	mSixthWeekLabel
       
   367 			= qobject_cast<HbLabel *> (
       
   368 					mDocLoader->findWidget(CALEN_MONTVIEW_SIXTH_WEEK_LABEL));
       
   369 	}
       
   370 	
       
   371 	// Set the text colors well before instead of setting it again and again
       
   372 	mFirstWeekLabel->setTextColor(mWeekDaysColor);
       
   373 	mSecondWeekLabel->setTextColor(mWeekDaysColor);
       
   374 	mThirdWeekLabel->setTextColor(mWeekDaysColor);
       
   375 	mFourthWeekLabel->setTextColor(mWeekDaysColor);
       
   376 	mFifthWeekLabel->setTextColor(mWeekDaysColor);
       
   377 	mSixthWeekLabel->setTextColor(mWeekDaysColor);
       
   378 	
       
   379 	// Calculate the week numbers and set them to the week labels
       
   380 	updateWeekNumGridModel();
       
   381 
       
   382 	// Get the day names layout
       
   383 	QGraphicsLinearLayout *dayNamesLayout =
       
   384 	        static_cast<QGraphicsLinearLayout *> (mDayNameWidget->layout());
       
   385 
       
   386 	if (KCalenDaysInWeek == dayNamesLayout->count()) {
       
   387 		// Add one empty label in the day name grid
       
   388 		HbLabel *label = new HbLabel(mDayNameWidget);
       
   389 
       
   390 		// Set the attributes same as that of other day names to make it
       
   391 		// look similar to the day names
       
   392 		label->setPlainText("");
       
   393 		label->setFont(mFirstDayLabel->font());
       
   394 		label->setFontSpec(mFirstDayLabel->fontSpec());
       
   395 		label->setAlignment(mFirstDayLabel->alignment());
       
   396 		label->setElideMode(mFirstDayLabel->elideMode());
       
   397 		label->setZValue(mFirstDayLabel->zValue());
       
   398 		// Set the proper width to this empty label so that
       
   399 		// day names are dislayed against the correct columns
       
   400 		HbDeviceProfile deviceProf;
       
   401         qreal unitValue = deviceProf.unitValue();
       
   402         qreal widthInPixels = WEEKNUMWIDTH * unitValue;
       
   403         label->setPreferredWidth(widthInPixels);
       
   404         label->setMinimumWidth(widthInPixels);
       
   405         label->setMaximumWidth(widthInPixels);
       
   406         label->setContentsMargins(0,0,0,0);
       
   407 		
       
   408 		// Add this label into layout
       
   409 		dayNamesLayout->insertItem(0, label);
       
   410 		dayNamesLayout->invalidate();
       
   411 		dayNamesLayout->activate();
       
   412 	}
       
   413 
       
   414 	// Now insert the weekNumber Grid
       
   415 	QGraphicsLinearLayout *layout = static_cast<QGraphicsLinearLayout *> 
       
   416 										(mMonthGridPlusWeekNumWidget->layout());
       
   417 
       
   418 	if (1 == layout->count()) {
       
   419 		layout->insertItem(0, mWeekNumberWidget);
       
   420 		// Enable the item so that line seperator gets drawn
       
   421 		mWeekNumberWidget->setEnabled(true);
       
   422 		layout->invalidate();
       
   423 		layout->activate();
       
   424 	}
       
   425 	
       
   426 	OstTraceFunctionExit0( CALENMONTHVIEW_ADDWEEKNUMBERS_EXIT );
       
   427 }
       
   428 
       
   429 /*!
       
   430  Removes the week numbers from the view
       
   431  */
       
   432 void CalenMonthView::removeWeekNumbers()
       
   433 
       
   434 {
       
   435     OstTraceFunctionEntry0( CALENMONTHVIEW_REMOVEWEEKNUMBERS_ENTRY );
       
   436     
       
   437 	// Remove the week number grid if setting is off
       
   438 	QGraphicsLinearLayout *layout = static_cast<QGraphicsLinearLayout *> 
       
   439 									(mMonthGridPlusWeekNumWidget->layout());
       
   440 	if (2 == layout->count()) {
       
   441 		layout->removeItem(mWeekNumberWidget);
       
   442 
       
   443 		// Disable the item as we are removing it from the layout
       
   444 		mWeekNumberWidget->setEnabled(false);
       
   445 		layout->invalidate();
       
   446 		layout->activate();
       
   447 
       
   448 		// Clear the week labels
       
   449 		mFirstWeekLabel->clear();
       
   450 		mSecondWeekLabel->clear();
       
   451 		mThirdWeekLabel->clear();
       
   452 		mFourthWeekLabel->clear();
       
   453 		mFifthWeekLabel->clear();
       
   454 		mSixthWeekLabel->clear();
       
   455 
       
   456 		// Get the day names layout
       
   457 		QGraphicsLinearLayout *dayNamesLayout =
       
   458 		        static_cast<QGraphicsLinearLayout *> (mDayNameWidget->layout());
       
   459 		if (dayNamesLayout->count() == KCalenDaysInWeek + 1) {
       
   460 			// Remove the empty item in the day name grid
       
   461 			QGraphicsLayoutItem *item = dayNamesLayout->itemAt(0);
       
   462 			dayNamesLayout->removeAt(0);
       
   463 			delete item;
       
   464 			dayNamesLayout->invalidate();
       
   465 			dayNamesLayout->activate();
       
   466 		}
       
   467 	}
       
   468 	
       
   469 	OstTraceFunctionExit0( CALENMONTHVIEW_REMOVEWEEKNUMBERS_EXIT );
       
   470 }
       
   471 
       
   472 /*!
       
   473  Sets the background frame for the month view
       
   474  */
       
   475 void CalenMonthView::addBackgroundFrame()
       
   476 {
       
   477     OstTraceFunctionEntry0( CALENMONTHVIEW_ADDBACKGROUNDFRAME_ENTRY );
       
   478     
       
   479     // Set the background items for all the widgets
       
   480     HbFrameItem* frame = NULL;
       
   481     HbFrameDrawer *drawer = NULL;
       
   482     HbWidget* monthViewExceptPreviewPane = qobject_cast<HbWidget *> (
       
   483 						 mDocLoader->findWidget(CALEN_MONTHVIEW_EXCEPT_PANE));
       
   484     if (monthViewExceptPreviewPane) {
       
   485         drawer = new HbFrameDrawer("qtg_fr_cal_monthgrid_bg", HbFrameDrawer::NinePieces);
       
   486         // The grid background
       
   487         frame = new HbFrameItem(drawer, this);
       
   488         monthViewExceptPreviewPane->setBackgroundItem(frame->graphicsItem(), -2);
       
   489     }
       
   490     if (mTitleLabel) {
       
   491         // The month title
       
   492         drawer = new HbFrameDrawer("qtg_fr_cal_monthgrid_title_bg", HbFrameDrawer::ThreePiecesHorizontal);
       
   493 		if (drawer)
       
   494         	frame = new HbFrameItem(drawer, this);
       
   495 		if(frame)
       
   496 			mTitleLabel->setBackgroundItem(frame->graphicsItem(), -2);
       
   497     }
       
   498     
       
   499     // Set the frame to the preview pane
       
   500     drawer = new HbFrameDrawer("qtg_fr_cal_preview_bg", HbFrameDrawer::NinePieces);
       
   501 	if (drawer)
       
   502 	    frame = new HbFrameItem(drawer, this);
       
   503 	if(frame)
       
   504 	    mPrevPaneLayoutWidget->setBackgroundItem(frame->graphicsItem(), -5);
       
   505     
       
   506     // Set the frame to the preview pane
       
   507     drawer = new HbFrameDrawer("qtg_fr_cal_preview_bg", HbFrameDrawer::NinePieces);
       
   508     if(drawer)
       
   509 	   frame = new HbFrameItem(drawer, this);
       
   510 	if(frame)
       
   511     mCurrPaneLayoutWidget->setBackgroundItem(frame->graphicsItem(), -5);
       
   512     
       
   513     // Set the frame to the preview pane
       
   514     drawer = new HbFrameDrawer("qtg_fr_cal_preview_bg", HbFrameDrawer::NinePieces);
       
   515 	if(drawer)
       
   516            frame = new HbFrameItem(drawer, this);
       
   517 	if(frame)
       
   518 	    mNextPaneLayoutWidget->setBackgroundItem(frame->graphicsItem(), -5);
       
   519 	
       
   520 	OstTraceFunctionExit0( CALENMONTHVIEW_ADDBACKGROUNDFRAME_EXIT );
       
   521 }
       
   522 
       
   523 void CalenMonthView::showHideRegionalInformation()
       
   524 {
       
   525     OstTraceFunctionEntry0( CALENMONTHVIEW_SHOWHIDEREGIONALINFORMATION_ENTRY );
       
   526     
       
   527 	if (pluginEnabled()) {
       
   528 		XQSettingsKey regionalInfo(XQSettingsKey::TargetCentralRepository,
       
   529 									KCRUidCalendar, KCalendarShowRegionalInfo);
       
   530 
       
   531 		int showRegionalInfo = 
       
   532 						mSettingsManager->readItemValue(regionalInfo).toUInt();
       
   533 		if (showRegionalInfo) {
       
   534 
       
   535 			// Add the regional information to the preview panes
       
   536 			if (!mPrevRegionalInfo) {
       
   537 				mPrevRegionalInfo = qobject_cast<CalenPluginLabel *> 
       
   538 				(mDocLoader->findWidget(CALEN_PREVREGIONALINFO));
       
   539 				mPrevRegionalInfo->show();
       
   540 				mPrevPaneLayout->insertItem(0, mPrevRegionalInfo);
       
   541 
       
   542 				HbFrameItem *frameCurr = new HbFrameItem(this);
       
   543 				frameCurr->frameDrawer().setFrameType(
       
   544 										HbFrameDrawer::ThreePiecesHorizontal);
       
   545 				frameCurr->frameDrawer().setFrameGraphicsName(
       
   546 										"qtg_fr_cal_preview_title_bg");
       
   547 				mPrevRegionalInfo->setBackgroundItem(
       
   548 										frameCurr->graphicsItem(), -2);
       
   549 			}
       
   550 			if (!mCurrRegionalInfo) {
       
   551 				mCurrRegionalInfo = qobject_cast<CalenPluginLabel *> 
       
   552 				(mDocLoader->findWidget(CALEN_CURRREGIONALINFO));
       
   553 				mCurrRegionalInfo->show();
       
   554 				mCurrPaneLayout->insertItem(0, mCurrRegionalInfo);
       
   555 
       
   556 				HbFrameItem *frameCurr = new HbFrameItem(this);
       
   557 				frameCurr->frameDrawer().setFrameType(
       
   558 										HbFrameDrawer::ThreePiecesHorizontal);
       
   559 				frameCurr->frameDrawer().setFrameGraphicsName(
       
   560 										"qtg_fr_cal_preview_title_bg");
       
   561 				mCurrRegionalInfo->setBackgroundItem(
       
   562 										frameCurr->graphicsItem(), -2);
       
   563 			}
       
   564 			if (!mNextRegionalInfo) {
       
   565 				mNextRegionalInfo = qobject_cast<CalenPluginLabel *> 
       
   566 				(mDocLoader->findWidget(CALEN_NEXTREGIONALINFO));
       
   567 				mNextRegionalInfo->show();
       
   568 				mNextPaneLayout->insertItem(0, mNextRegionalInfo);
       
   569 
       
   570 				HbFrameItem *frameCurr = new HbFrameItem(this);
       
   571 				frameCurr->frameDrawer().setFrameType(
       
   572 										HbFrameDrawer::ThreePiecesHorizontal);
       
   573 				frameCurr->frameDrawer().setFrameGraphicsName(
       
   574 										"qtg_fr_cal_preview_title_bg");
       
   575 				mNextRegionalInfo->setBackgroundItem(
       
   576 										frameCurr->graphicsItem(), -2);
       
   577 			}
       
   578 			QString *pluginString = pluginText();
       
   579 			mPrevRegionalInfo->setPlainText(*pluginString);
       
   580 			mPrevRegionalInfo->setTextColor(mPreviewHeadingColor);
       
   581 			mCurrRegionalInfo->setPlainText(*pluginString);
       
   582 			mCurrRegionalInfo->setTextColor(mPreviewHeadingColor);
       
   583 			mNextRegionalInfo->setPlainText(*pluginString);
       
   584 			mNextRegionalInfo->setTextColor(mPreviewHeadingColor);
       
   585 		} else {
       
   586 			if (mPrevRegionalInfo) {
       
   587 				mPrevPaneLayout->removeItem(mPrevRegionalInfo);
       
   588 				mPrevRegionalInfo->hide();
       
   589 				mPrevRegionalInfo = NULL;
       
   590 			}
       
   591 			if (mCurrRegionalInfo) {
       
   592 				mCurrPaneLayout->removeItem(mCurrRegionalInfo);
       
   593 				mCurrRegionalInfo->hide();
       
   594 				mCurrRegionalInfo = NULL;
       
   595 			}
       
   596 			if (mNextRegionalInfo) {
       
   597 				mNextPaneLayout->removeItem(mNextRegionalInfo);
       
   598 				mNextRegionalInfo->hide();
       
   599 				mNextRegionalInfo = NULL;
       
   600 			}
       
   601 		}
       
   602 	}
       
   603 	
       
   604 	OstTraceFunctionExit0( CALENMONTHVIEW_SHOWHIDEREGIONALINFORMATION_EXIT );
       
   605 }
       
   606 
       
   607 /*!
       
   608  Handles the context changed notification
       
   609  */
       
   610 void CalenMonthView::onContextChanged()
       
   611 {
       
   612     OstTraceFunctionEntry0( CALENMONTHVIEW_ONCONTEXTCHANGED_ENTRY );
       
   613 	//Update plugin label after setting context
       
   614 	if (mCurrRegionalInfo && mPrevRegionalInfo && mNextPaneLayout
       
   615 	        && pluginEnabled()) {
       
   616 		QString *pluginString = pluginText();
       
   617 		mPrevRegionalInfo->setPlainText(*pluginString);
       
   618 		mCurrRegionalInfo->setPlainText(*pluginString);
       
   619 		mNextRegionalInfo->setPlainText(*pluginString);
       
   620 	}
       
   621 	OstTraceFunctionExit0( CALENMONTHVIEW_ONCONTEXTCHANGED_EXIT );
       
   622 }
       
   623 
       
   624 /*!
       
   625  Calculates the week numbers and sets them to the week labels
       
   626  */
       
   627 void CalenMonthView::updateWeekNumGridModel()
       
   628 
       
   629 {
       
   630     OstTraceFunctionEntry0( CALENMONTHVIEW_UPDATEWEEKNUMGRIDMODEL_ENTRY );
       
   631     
       
   632 	// Get the visible date
       
   633 	QDateTime firstVisibleDate = mFirstDayOfGrid.addDays(KCalenDaysInWeek
       
   634 	        * mNumOfRowsInPrevMonth);
       
   635 	// Go to the last day so that we get the proper week number for the first
       
   636 	// week of January
       
   637 	mWeekNumbers.clear();
       
   638 	// get the proper week numbers
       
   639 	for (int i = 0; i < KNumOfVisibleRows; i++) {
       
   640 		// Get the week number
       
   641 		QDateTime day = firstVisibleDate.addDays((KCalenDaysInWeek * i));
       
   642 		long weekNumber(day.date().weekNumber());
       
   643 		mWeekNumbers.append(weekNumber);
       
   644 	}
       
   645 
       
   646 	// Update the week labels text
       
   647 	QString text = QString::number(mWeekNumbers.at(0));
       
   648 	mFirstWeekLabel->setPlainText(text);
       
   649 	text = QString::number(mWeekNumbers.at(1));
       
   650 	mSecondWeekLabel->setPlainText(text);
       
   651 	text = QString::number(mWeekNumbers.at(2));
       
   652 	mThirdWeekLabel->setPlainText(text);
       
   653 	text = QString::number(mWeekNumbers.at(3));
       
   654 	mFourthWeekLabel->setPlainText(text);
       
   655 	text = QString::number(mWeekNumbers.at(4));
       
   656 	mFifthWeekLabel->setPlainText(text);
       
   657 	text = QString::number(mWeekNumbers.at(5));
       
   658 	mSixthWeekLabel->setPlainText(text);
       
   659 	
       
   660 	OstTraceFunctionExit0( CALENMONTHVIEW_UPDATEWEEKNUMGRIDMODEL_EXIT );
       
   661 }
       
   662 
       
   663 /*!
       
   664  Populates the month view with today as focussed item
       
   665  */
       
   666 void CalenMonthView::goToToday()
       
   667 {
       
   668     OstTraceFunctionEntry0( CALENMONTHVIEW_GOTOTODAY_ENTRY );
       
   669     
       
   670 	QDateTime today = CalenDateUtils::today();
       
   671 	// Set the context and repopulate the view
       
   672     MCalenContext &context = mServices.Context();
       
   673     context.setFocusDateAndTime(today);
       
   674 	    
       
   675 	// First check if we are not alread
       
   676 	// showing today's month view
       
   677 	if (mDate == today) {
       
   678 		OstTraceFunctionExit0( CALENMONTHVIEW_GOTOTODAY_EXIT );
       
   679 		return;
       
   680 	} else if (mActiveMonth.date().year() == today.date().year() && 
       
   681 				mActiveMonth.date().month() == today.date().month()) {
       
   682         mDate = today;
       
   683 		// User is in current month only, so just set the focus to current
       
   684 		// date grid item and refresh the preview pane
       
   685 		int currIndex = mFirstDayOfGrid.daysTo(today);
       
   686 		setCurrGridIndex(currIndex);
       
   687 		// Populate the preview panes
       
   688 		populatePreviewPane(mDate);
       
   689 	} else {	
       
   690         refreshViewOnGoToDate();
       
   691 	}
       
   692 	
       
   693 	OstTraceFunctionExit0( DUP1_CALENMONTHVIEW_GOTOTODAY_EXIT );
       
   694 }
       
   695 
       
   696 /*
       
   697  Slot to handle adding / removing actions frm the menu when menu is about to
       
   698  shown to the user
       
   699  */
       
   700 void CalenMonthView::addRemoveActionsInMenu()
       
   701 {
       
   702     OstTraceFunctionEntry0( CALENMONTHVIEW_ADDREMOVEACTIONSINMENU_ENTRY );
       
   703 	HbAction* menuAction = mDeleteSubMenu->menuAction();
       
   704 	if (menuAction) {
       
   705         if (!mEntriesInDataBase && mAgendaUtil->areNoEntriesInCalendar()) {
       
   706             // hide the delete entries option
       
   707             menuAction->setVisible(false);
       
   708         } else {
       
   709             mEntriesInDataBase = true;
       
   710             // Show the option to delete
       
   711             menuAction->setVisible(true);
       
   712         }
       
   713 	}
       
   714 	
       
   715 	// Check if we are population for current day, if yes then disable the
       
   716 	// gototoday action
       
   717 	if ((CalenDateUtils::today().date() == mDate.date()) && mGoToTodayAction) {
       
   718 		mGoToTodayAction->setVisible(false);
       
   719 	} else if (mGoToTodayAction){
       
   720 		mGoToTodayAction->setVisible(true);
       
   721 	}
       
   722 	OstTraceFunctionExit0( CALENMONTHVIEW_ADDREMOVEACTIONSINMENU_EXIT );
       
   723 }
       
   724 
       
   725 /*!
       
   726  Populates the view
       
   727  */
       
   728 void CalenMonthView::doPopulation()
       
   729 {
       
   730     OstTraceFunctionEntry0( CALENMONTHVIEW_DOPOPULATION_ENTRY );
       
   731     
       
   732  	// Get the layout and add the preview pane layout.
       
   733 	QGraphicsLinearLayout* viewLayout = static_cast<QGraphicsLinearLayout *>
       
   734 														(widget()->layout());
       
   735 	if (viewLayout->count() == 1) {
       
   736 		// Count is 1 implies view has only month grid.
       
   737 		// Add the preview pane at corresponding position.
       
   738 		viewLayout->addItem(mCurrPaneParent);
       
   739 	}
       
   740 	
       
   741 	// prepare for the population like reading the date frm the context 
       
   742 	// calculating the start of the grid etc.,
       
   743 	prepareForPopulation();
       
   744 	
       
   745 	// Populate the view and preview panes only if we are not opening the calendar
       
   746 	if (!mIsFirstTimeLoad) {
       
   747 		// fetch list of required calendar instances
       
   748 		populateWithInstanceView();
       
   749 		// Populate the preview panes
       
   750 		populatePreviewPane(mDate);
       
   751 	}
       
   752 	
       
   753 	
       
   754     //update the day label 
       
   755     //if changes in locale setting
       
   756 	updateDayLabel();
       
   757 	
       
   758 	  // Create the grid items with proper dates
       
   759 	createGrid();
       
   760 	
       
   761 
       
   762 	// Complete the population
       
   763 	completePopulation();
       
   764 
       
   765 	//set Currect Activity to month view
       
   766 	mActivityId = ECalenMonthView;
       
   767 	
       
   768 	// connect to receive a call back on Month View exit. Call back would result in saveActivity 
       
   769 	// to be called in Native View.
       
   770 	if (!mIsAboutToQuitEventConnected) // check if not already connected
       
   771 	    {
       
   772         connect(qobject_cast<HbApplication*>(qApp), SIGNAL(aboutToQuit()), this, SLOT(saveActivity()));
       
   773         mIsAboutToQuitEventConnected = true;
       
   774 	    }
       
   775 	
       
   776 		
       
   777 	// Population is complete, inform it
       
   778 	populationComplete();
       
   779 	
       
   780 	// Handle regional data here if we are not populating the month view for
       
   781 	// the first time
       
   782 	if (!mIsFirstTimeLoad) {
       
   783 		showHideRegionalInformation();
       
   784 	}
       
   785 	// Reset the first time load flag
       
   786 	mIsFirstTimeLoad = false;
       
   787 	
       
   788 	OstTraceFunctionExit0( CALENMONTHVIEW_DOPOPULATION_EXIT );
       
   789 }
       
   790 
       
   791 /*!
       
   792  Reads the date from the context and calculates the grid item dates
       
   793  */
       
   794 void CalenMonthView::prepareForPopulation()
       
   795 {
       
   796     OstTraceFunctionEntry0( CALENMONTHVIEW_PREPAREFORPOPULATION_ENTRY );
       
   797     
       
   798 	setActiveDay(dateFromContext(mServices.Context()));
       
   799 	setDate();
       
   800 	updateMonthDataArrayWithActiveDates();
       
   801 	
       
   802 	OstTraceFunctionExit0( CALENMONTHVIEW_PREPAREFORPOPULATION_EXIT );
       
   803 }
       
   804 
       
   805 /*!
       
   806  Slot to handle gotodate action
       
   807  */
       
   808 void CalenMonthView::refreshViewOnGoToDate()
       
   809 {
       
   810     OstTraceFunctionEntry0( CALENMONTHVIEW_REFRESHVIEWONGOTODATE_ENTRY );
       
   811     
       
   812 	prepareForPopulation();
       
   813 	setDateToLabel();
       
   814 	// fetch list of required calendar instances
       
   815 	populateWithInstanceView();
       
   816 
       
   817 	populatePreviewPane(mDate);
       
   818 	
       
   819 	mMonthGrid->updateMonthGridModel(mMonthDataArray, mIndexToBeScrolled, 
       
   820 	                                 mIsFirstTimeLoad);
       
   821 	// Update the week Numbers model
       
   822 	if (mIsWeekNumbersShown) {
       
   823 		updateWeekNumGridModel();
       
   824 	}
       
   825 	
       
   826 	OstTraceFunctionExit0( CALENMONTHVIEW_REFRESHVIEWONGOTODATE_EXIT );
       
   827 }
       
   828 
       
   829 /*!
       
   830  Reads the date from the context and stores into mDate
       
   831  */
       
   832 QDateTime CalenMonthView::dateFromContext(const MCalenContext &context)
       
   833 {
       
   834     OstTraceFunctionEntry0( CALENMONTHVIEW_DATEFROMCONTEXT_ENTRY );
       
   835 	QDateTime ret;
       
   836 	if (AgendaEntry::TypeTodo == context.instanceId().mType) {
       
   837 		QDateTime today = CalenDateUtils::today();
       
   838 		if (context.focusDateAndTime() < today) {
       
   839 			ret = today;
       
   840 		} else {
       
   841 			ret = context.focusDateAndTime();
       
   842 		}
       
   843 	} else {
       
   844 		ret = context.focusDateAndTime();
       
   845 	}
       
   846 	OstTraceFunctionExit0( CALENMONTHVIEW_DATEFROMCONTEXT_EXIT );
       
   847 	return ret;
       
   848 }
       
   849 
       
   850 /*!
       
   851  Calculates the necesary parameters of the month view w.r.t mDate
       
   852  */
       
   853 void CalenMonthView::setActiveDay(QDateTime day)
       
   854 {
       
   855     OstTraceFunctionEntry0( CALENMONTHVIEW_SETACTIVEDAY_ENTRY );
       
   856     
       
   857 	mDate = day;
       
   858     
       
   859 	mActiveMonth = mDate;
       
   860 	// Get the first day of the previous month
       
   861 	QDateTime prevMonthDate = mDate.addMonths(-1);
       
   862 	int prevMonth = prevMonthDate.date().month();
       
   863 
       
   864 	// Get the first day of the month
       
   865 	QDate date = prevMonthDate.date();
       
   866 	date.setDate(date.year(), date.month(), 1);
       
   867 	QDateTime firstDayOfPrevMonth(date, day.time());
       
   868 
       
   869 	int offset(firstDayOfPrevMonth.date().dayOfWeek() - (mLocale.startOfWeek()
       
   870 	        + 1));
       
   871 	if (offset < 0) {
       
   872 		offset += KCalenDaysInWeek;
       
   873 	}
       
   874 
       
   875 	// Substract the offset days
       
   876 	mFirstDayOfGrid = firstDayOfPrevMonth.addDays(-offset);
       
   877 
       
   878 	// Calculate the number of weeks in the previous month that will be hidden
       
   879 	mNumOfRowsInPrevMonth = offset + prevMonthDate.date().daysInMonth();
       
   880 	mNumOfRowsInPrevMonth = (mNumOfRowsInPrevMonth / KCalenDaysInWeek);
       
   881 
       
   882 	// Index to be scrolled is the last day of the visible grid item
       
   883 	mIndexToBeScrolled = ((mNumOfRowsInPrevMonth + KNumOfVisibleRows)
       
   884 	        * KCalenDaysInWeek) - 1;
       
   885 
       
   886 	// Now add the future month days to the count. While doing that, we need to
       
   887 	// calcualte the count till the end of the week in which the month ends
       
   888 	QDateTime futureMonthDate = mDate.addMonths(1);
       
   889 	// Get the first day of the future month
       
   890 	date = futureMonthDate.date();
       
   891 	date.setDate(date.year(), date.month(), 1);
       
   892 	QDateTime firstDayOfFutMonth(date, day.time());
       
   893 	offset = firstDayOfFutMonth.date().dayOfWeek() - (mLocale.startOfWeek() + 1);
       
   894 	if (offset < 0) {
       
   895 		offset += KCalenDaysInWeek;
       
   896 	}
       
   897 	// Substract the firstDayNoInWeek days
       
   898 	QDateTime dateTime = firstDayOfFutMonth.addDays(-offset);
       
   899 
       
   900 	// Need to add 42 days for dateTime so that it fits into the visible grid
       
   901 	mLastDayOfGrid = dateTime.addDays(KNumOfVisibleRows * KCalenDaysInWeek - 1);
       
   902 
       
   903 	// calculate the total numbers of dates that needs to be populated from 
       
   904 	// previous month to future month
       
   905 	mTotalNumOfGridItems = mFirstDayOfGrid.daysTo(mLastDayOfGrid) + 1;
       
   906 
       
   907 	// Calculate the last visible day
       
   908 	int index = (mNumOfRowsInPrevMonth + KNumOfVisibleRows) * KCalenDaysInWeek;
       
   909 	QDateTime lastVisibleDate = mFirstDayOfGrid.addDays(index - 1);
       
   910 	QDateTime dateTimeToCalc = mLastDayOfGrid;
       
   911 	mNumOfRowsInFutureMonth = 0;
       
   912 	while (dateTimeToCalc > lastVisibleDate) {
       
   913 		mNumOfRowsInFutureMonth++;
       
   914 		dateTimeToCalc = dateTimeToCalc.addDays(-KCalenDaysInWeek);
       
   915 	}
       
   916 	
       
   917 	OstTraceFunctionExit0( CALENMONTHVIEW_SETACTIVEDAY_EXIT );
       
   918 }
       
   919 
       
   920 /*!
       
   921  Calculates the dates that needs to be set to mMonthDataArray
       
   922  */
       
   923 void CalenMonthView::setDate()
       
   924 {
       
   925     OstTraceFunctionEntry0( CALENMONTHVIEW_SETDATE_ENTRY );
       
   926     
       
   927 	mMonthDataArray.clear();
       
   928 	// Calculate the actual number of dates to be populated from previous month
       
   929 	// to future month
       
   930 	for (int i(0); i < mTotalNumOfGridItems; ++i) {
       
   931 		QDateTime currentDay = CalenDateUtils::futureOf(mFirstDayOfGrid, i);
       
   932 		CalenMonthData element(currentDay);
       
   933 		mMonthDataArray.append(element);
       
   934 	}
       
   935 	
       
   936 	OstTraceFunctionExit0( CALENMONTHVIEW_SETDATE_EXIT );
       
   937 }
       
   938 
       
   939 /*!
       
   940  Returns the currDay(Today)
       
   941  */
       
   942 QDateTime CalenMonthView::getCurrentDay()
       
   943 {
       
   944     OstTraceFunctionEntry0( CALENMONTHVIEW_GETCURRENTDAY_ENTRY );
       
   945     
       
   946 	OstTraceFunctionExit0( CALENMONTHVIEW_GETCURRENTDAY_EXIT );
       
   947 	return mCurrentDay;
       
   948 }
       
   949 
       
   950 /*!
       
   951  Returns the active day(currently focussed day)
       
   952  */
       
   953 QDateTime CalenMonthView::getActiveDay()
       
   954 {
       
   955     OstTraceFunctionEntry0( CALENMONTHVIEW_GETACTIVEDAY_ENTRY );
       
   956     
       
   957 	OstTraceFunctionExit0( CALENMONTHVIEW_GETACTIVEDAY_EXIT );
       
   958 	return mDate;
       
   959 }
       
   960 
       
   961 /*!
       
   962  Returns the array of CalenMonthData items
       
   963  */
       
   964 QList<CalenMonthData>& CalenMonthView::monthDataList()
       
   965 {
       
   966     OstTraceFunctionEntry0( CALENMONTHVIEW_MONTHDATALIST_ENTRY );
       
   967     
       
   968 	OstTraceFunctionExit0( CALENMONTHVIEW_MONTHDATALIST_EXIT );
       
   969 	return mMonthDataArray;
       
   970 }
       
   971 
       
   972 /*!
       
   973  Creates the grid and adds the week numbers depending on the week number setting
       
   974  */
       
   975 void CalenMonthView::createGrid()
       
   976 {
       
   977     OstTraceFunctionEntry0( CALENMONTHVIEW_CREATEGRID_ENTRY );
       
   978 	// Update the month grid
       
   979 	mMonthGrid->updateMonthGridModel(mMonthDataArray, mIndexToBeScrolled, 
       
   980 	                                 mIsFirstTimeLoad);
       
   981     // Get start of week from the locale.
       
   982     HbExtendedLocale locale = HbExtendedLocale::system();
       
   983     int startOfWeek = locale.startOfWeek();
       
   984     if(startOfWeek != HbExtendedLocale::Monday)
       
   985         {
       
   986         //if the start of week is other than Monday, don't show the week number
       
   987         mIsWeekNumbersShown = 0;
       
   988         }
       
   989     else
       
   990         {
       
   991         // Read the week number setting from cenrep
       
   992         QVariant value = mSettingsManager->readItemValue(*mWeekNumberCenrepKey);
       
   993         mIsWeekNumbersShown = value.toUInt();
       
   994         }
       
   995 	if (mIsWeekNumbersShown) {
       
   996 		// Add week numbers to week grid
       
   997 		addWeekNumbers();
       
   998 	} else {
       
   999 		// remove the weeknumbergrid from the layout
       
  1000 		removeWeekNumbers();
       
  1001 	}
       
  1002 	OstTraceFunctionExit0( CALENMONTHVIEW_CREATEGRID_EXIT );
       
  1003 }
       
  1004 
       
  1005 /*!
       
  1006  Called when down gesture is performed
       
  1007  Caluclates the necessary dates for the new previous month
       
  1008  */
       
  1009 void CalenMonthView::updateModelWithPrevMonth()
       
  1010 {
       
  1011     OstTraceFunctionEntry0( CALENMONTHVIEW_UPDATEMODELWITHPREVMONTH_ENTRY );
       
  1012     
       
  1013 	// Get the new previous month
       
  1014 	QDateTime prevMonthDateTime = mActiveMonth.addMonths(-1);
       
  1015 	QDateTime dateTime = mFirstDayOfGrid;
       
  1016 	if (prevMonthDateTime.date().month() == mFirstDayOfGrid.date().month()) {
       
  1017 		//  Month starts right on Monday(Start of the week), 
       
  1018 		//hence go back to previous month
       
  1019 		dateTime = mFirstDayOfGrid.addMonths(-1);
       
  1020 	}
       
  1021 
       
  1022 	int prevMonth = dateTime.date().month();
       
  1023 	QDateTime prevFirstDayOfGrid = mFirstDayOfGrid;
       
  1024 	for (int i = 0; i < KNumOfVisibleRows; i++) {
       
  1025 		mFirstDayOfGrid = mFirstDayOfGrid.addDays(-KCalenDaysInWeek);
       
  1026 		if (mFirstDayOfGrid.date().month() == prevMonth) {
       
  1027 			continue;
       
  1028 		} else {
       
  1029 			// Entered to another month, stop here
       
  1030 			break;
       
  1031 		}
       
  1032 	}
       
  1033 	// Readjust the mFirstDayOfGrid
       
  1034 	if (mFirstDayOfGrid.addDays(KCalenDaysInWeek - 1).date().month()
       
  1035 	        != prevMonth) {
       
  1036 		mFirstDayOfGrid = mFirstDayOfGrid.addDays(KCalenDaysInWeek);
       
  1037 	}
       
  1038 
       
  1039 	// Calculate the new days to be added
       
  1040 	int countToBeAdded = mFirstDayOfGrid.daysTo(prevFirstDayOfGrid);
       
  1041 
       
  1042 	// Remove the bottom month entries in mMonthDataArray
       
  1043 	int countToBeDeleted = mNumOfRowsInFutureMonth * KCalenDaysInWeek;
       
  1044 	int count = mMonthDataArray.count() - 1;
       
  1045 	for (int i = 0; i < countToBeDeleted; i++) {
       
  1046 		mMonthDataArray.removeAt(count--);
       
  1047 	}
       
  1048 
       
  1049 	// Update the total number of grid items as we will be removing the month
       
  1050 	// at the below
       
  1051 	mTotalNumOfGridItems -= countToBeDeleted;
       
  1052 
       
  1053 	// Prepend countToBeAdded new items to mMonthDataArray
       
  1054 	for (int i = 0; i < countToBeAdded; i++) {
       
  1055 		QDateTime currentDay = mFirstDayOfGrid.addDays(i);
       
  1056 		CalenMonthData element(currentDay);
       
  1057 		mMonthDataArray.insert(i, element);
       
  1058 	}
       
  1059 	mTotalNumOfGridItems += countToBeAdded;
       
  1060 
       
  1061 	// Update the mMonthDataArray with instances if any
       
  1062 	populatePrevMonth();
       
  1063 
       
  1064 	// Update the necessary globals
       
  1065 	mActiveMonth = mActiveMonth.addMonths(-1);
       
  1066 	mNumOfRowsInPrevMonth = (countToBeAdded / KCalenDaysInWeek);
       
  1067 	mLastDayOfGrid = mFirstDayOfGrid.addDays(mTotalNumOfGridItems - 1);
       
  1068 	// Calculate the last visible day
       
  1069 	int index = (mNumOfRowsInPrevMonth + KNumOfVisibleRows) * KCalenDaysInWeek;
       
  1070 	QDateTime lastVisibleDate = mFirstDayOfGrid.addDays(index - 1);
       
  1071 	QDateTime date = mLastDayOfGrid;
       
  1072 	mNumOfRowsInFutureMonth = 0;
       
  1073 	while (date > lastVisibleDate) {
       
  1074 		mNumOfRowsInFutureMonth++;
       
  1075 		date = date.addDays(-KCalenDaysInWeek);
       
  1076 	}
       
  1077 	// Update the week Numbers model
       
  1078 	if (mIsWeekNumbersShown) {
       
  1079 		updateWeekNumGridModel();
       
  1080 	}
       
  1081 	
       
  1082 	OstTraceFunctionExit0( CALENMONTHVIEW_UPDATEMODELWITHPREVMONTH_EXIT );
       
  1083 }
       
  1084 /*!
       
  1085  Called when up gesture is performed
       
  1086  */
       
  1087 void CalenMonthView::updateModelWithFutureMonth()
       
  1088 {
       
  1089     OstTraceFunctionEntry0( CALENMONTHVIEW_UPDATEMODELWITHFUTUREMONTH_ENTRY );
       
  1090     
       
  1091 	// Get the new future month
       
  1092 	QDateTime previousLastDayOfGrid = mLastDayOfGrid;
       
  1093 	QDateTime futureMonthDateTime = mActiveMonth.addMonths(2);
       
  1094 	QDate date = futureMonthDateTime.date();
       
  1095 	date.setDate(date.year(), date.month(), 1);
       
  1096 	// Get the first day of the future month
       
  1097 	QDateTime firstDayOfFutMonth(date, futureMonthDateTime.time());
       
  1098 
       
  1099 	int offset = firstDayOfFutMonth.date().dayOfWeek() - (mLocale.startOfWeek()
       
  1100 	        + 1);
       
  1101 	if (offset < 0) {
       
  1102 		offset += KCalenDaysInWeek;
       
  1103 	}
       
  1104 	// Substract the firstDayNoInWeek days
       
  1105 	QDateTime dateTime = firstDayOfFutMonth.addDays(-offset);
       
  1106 	// Need to add 42 days for dateTime
       
  1107 	mLastDayOfGrid = dateTime.addDays(KNumOfVisibleRows * KCalenDaysInWeek - 1);
       
  1108 
       
  1109 	// Remove the first mNumOfRowsInPrevMonth rows in mMonthDataArray
       
  1110 	int countToBeDeleted = mNumOfRowsInPrevMonth * KCalenDaysInWeek;
       
  1111 	for (int i = 0; i < countToBeDeleted; i++) {
       
  1112 		mMonthDataArray.removeAt(0);
       
  1113 	}
       
  1114 
       
  1115 	// Update the total number of grid items as we will be removing the month
       
  1116 	// at the top
       
  1117 	mTotalNumOfGridItems -= countToBeDeleted;
       
  1118 
       
  1119 	// Calcualate the num fo days to be added
       
  1120 	int countToBeAdded = previousLastDayOfGrid.daysTo(mLastDayOfGrid);
       
  1121 	// Append countToBeAdded new items to mMonthDataArray
       
  1122 	for (int i = 1; i <= countToBeAdded; i++) {
       
  1123 		QDateTime currentDay = previousLastDayOfGrid.addDays(i);
       
  1124 		CalenMonthData element(currentDay);
       
  1125 		mMonthDataArray.append(element);
       
  1126 	}
       
  1127 
       
  1128 	
       
  1129 
       
  1130 	// Update the necessary globals
       
  1131 	mTotalNumOfGridItems += countToBeAdded;
       
  1132 	mActiveMonth = mActiveMonth.addMonths(1);
       
  1133 	mNumOfRowsInFutureMonth = (countToBeAdded / KCalenDaysInWeek);
       
  1134 	mFirstDayOfGrid = mLastDayOfGrid.addDays(-(mTotalNumOfGridItems - 1));
       
  1135 	// Calculate the first visible date
       
  1136 	int index = mTotalNumOfGridItems - ((mNumOfRowsInFutureMonth
       
  1137 	        + KNumOfVisibleRows) * KCalenDaysInWeek);
       
  1138 	QDateTime firstVisibleDate = mFirstDayOfGrid.addDays(index - 1);
       
  1139 	QDateTime dateTimeToCalc = mFirstDayOfGrid;
       
  1140 	mNumOfRowsInPrevMonth = 0;
       
  1141 	while (dateTimeToCalc < firstVisibleDate) {
       
  1142 		mNumOfRowsInPrevMonth++;
       
  1143 		dateTimeToCalc = dateTimeToCalc.addDays(KCalenDaysInWeek);
       
  1144 	}
       
  1145 
       
  1146 	// Update the week Numbers model
       
  1147 	if (mIsWeekNumbersShown) {
       
  1148 		updateWeekNumGridModel();
       
  1149 	}
       
  1150 	
       
  1151 	// Update the mMonthDataArray with instances if any
       
  1152 	populateNextMonth();
       
  1153 		
       
  1154 	OstTraceFunctionExit0( CALENMONTHVIEW_UPDATEMODELWITHFUTUREMONTH_EXIT );
       
  1155 }
       
  1156 
       
  1157 /*!
       
  1158  Returns the numner of rows in previous month
       
  1159  */
       
  1160 int CalenMonthView::rowsInPrevMonth()
       
  1161 {
       
  1162     OstTraceFunctionEntry0( CALENMONTHVIEW_ROWSINPREVMONTH_ENTRY );
       
  1163     
       
  1164 	OstTraceFunctionExit0( CALENMONTHVIEW_ROWSINPREVMONTH_EXIT );
       
  1165 	return mNumOfRowsInPrevMonth;
       
  1166 }
       
  1167 
       
  1168 /*!
       
  1169  Returns the number of rows in future month
       
  1170  */
       
  1171 int CalenMonthView::rowsInFutMonth()
       
  1172 {
       
  1173     OstTraceFunctionEntry0( CALENMONTHVIEW_ROWSINFUTMONTH_ENTRY );
       
  1174     
       
  1175 	OstTraceFunctionExit0( CALENMONTHVIEW_ROWSINFUTMONTH_EXIT );
       
  1176 	return mNumOfRowsInFutureMonth;
       
  1177 }
       
  1178 
       
  1179 /*!
       
  1180  Returns current Grid index
       
  1181  */
       
  1182 int CalenMonthView::getCurrGridIndex()
       
  1183 {
       
  1184     OstTraceFunctionEntry0( CALENMONTHVIEW_GETCURRGRIDINDEX_ENTRY );
       
  1185     
       
  1186     OstTraceFunctionExit0( CALENMONTHVIEW_GETCURRGRIDINDEX_EXIT );
       
  1187 	return mMonthGrid->getCurrentIndex();
       
  1188 }
       
  1189 
       
  1190 /*!
       
  1191  Set the currend Index of the Grid
       
  1192  */
       
  1193 void CalenMonthView::setCurrGridIndex(int index)
       
  1194 {
       
  1195     OstTraceFunctionEntry0( CALENMONTHVIEW_SETCURRGRIDINDEX_ENTRY );
       
  1196 	mIsPrevPaneGesture = true;
       
  1197 	mMonthGrid->setCurrentIdex(index);
       
  1198 	OstTraceFunctionExit0( CALENMONTHVIEW_SETCURRGRIDINDEX_EXIT );
       
  1199 }
       
  1200 
       
  1201 /*!
       
  1202  Sets the active flag to the required dates in the array
       
  1203  */
       
  1204 void CalenMonthView::updateMonthDataArrayWithActiveDates()
       
  1205 {
       
  1206     OstTraceFunctionEntry0( CALENMONTHVIEW_UPDATEMONTHDATAARRAYWITHACTIVEDATES_ENTRY );
       
  1207     
       
  1208 	int activeMonth = mActiveMonth.date().month();
       
  1209 	int monthDataCount = mMonthDataArray.count();
       
  1210 	for (int i = 0; i < monthDataCount; i++) {
       
  1211 		if (mMonthDataArray[i].Day().date().month() == activeMonth) {
       
  1212 			// Set the active flag
       
  1213 			mMonthDataArray[i].setActive(true);
       
  1214 		} else {
       
  1215 			// Disable the active flag
       
  1216 			mMonthDataArray[i].setActive(false);
       
  1217 		}
       
  1218 	}
       
  1219 	
       
  1220 	OstTraceFunctionExit0( CALENMONTHVIEW_UPDATEMONTHDATAARRAYWITHACTIVEDATES_EXIT );
       
  1221 }
       
  1222 
       
  1223 /*!
       
  1224  Fetches the calenda entries for a given range
       
  1225  */
       
  1226 void CalenMonthView::getInstanceList(QList<QDate> &list,
       
  1227                                      QDateTime rangeStart, QDateTime rangeEnd)
       
  1228 {
       
  1229     OstTraceFunctionEntry0( CALENMONTHVIEW_GETINSTANCELIST_ENTRY );
       
  1230     
       
  1231 	AgendaUtil::FilterFlags filter =
       
  1232 	        AgendaUtil::FilterFlags(AgendaUtil::IncludeAnniversaries
       
  1233 	                | AgendaUtil::IncludeAppointments
       
  1234 	                | AgendaUtil::IncludeEvents
       
  1235 	                | AgendaUtil::IncludeReminders
       
  1236 	                | AgendaUtil::IncludeIncompletedTodos);
       
  1237 	mAgendaUtil->markDatesWithEvents(rangeStart, rangeEnd, filter, list);
       
  1238 	
       
  1239 	OstTraceFunctionExit0( CALENMONTHVIEW_GETINSTANCELIST_EXIT );
       
  1240 }
       
  1241 
       
  1242 /*!
       
  1243  Parses the fetched entries and sets hasEvent attribute for necessary days
       
  1244  */
       
  1245 void CalenMonthView::populateWithInstanceView()
       
  1246 {
       
  1247     OstTraceFunctionEntry0( CALENMONTHVIEW_POPULATEWITHINSTANCEVIEW_ENTRY );
       
  1248     
       
  1249 	const QDateTime today(CalenDateUtils::today());
       
  1250 	const QDateTime gridStart(CalenDateUtils::beginningOfDay(mFirstDayOfGrid));
       
  1251 
       
  1252 	// grid index for "today"
       
  1253 	const int todayIndex(gridStart.daysTo(today)); 
       
  1254 
       
  1255 	QDateTime gridEnd(mLastDayOfGrid.date(), QTime(23, 59, 59, 0));
       
  1256 	
       
  1257 	// Get the list of dates which have events
       
  1258 	QList<QDate> datesWithEvents;
       
  1259 	getInstanceList(datesWithEvents,gridStart,gridEnd);
       
  1260 	
       
  1261 	// Parse thru the list of dates and set the required flags
       
  1262 	int datesEventsCount = datesWithEvents.count();
       
  1263 	for(int i(0); i < datesEventsCount; i++) {
       
  1264 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
       
  1265 		mMonthDataArray[offset].SetHasEvents(true);
       
  1266 	}
       
  1267 	datesWithEvents.clear();
       
  1268 	
       
  1269 	if (datesEventsCount) {
       
  1270         mEntriesInDataBase = true;
       
  1271 	}
       
  1272 	
       
  1273 	OstTraceFunctionExit0( CALENMONTHVIEW_POPULATEWITHINSTANCEVIEW_EXIT );
       
  1274 }
       
  1275 
       
  1276 /*!
       
  1277  Parses the fetched entries for previous month and 
       
  1278  sets hasEvent attribute for necessary days
       
  1279  */
       
  1280 void CalenMonthView::populatePrevMonth()
       
  1281 {
       
  1282     OstTraceFunctionEntry0( CALENMONTHVIEW_POPULATEPREVMONTH_ENTRY );
       
  1283     
       
  1284 	const QDateTime gridStart(CalenDateUtils::beginningOfDay(mFirstDayOfGrid));
       
  1285 	const QDateTime today(CalenDateUtils::today());
       
  1286 
       
  1287 	const int todayIndex(gridStart.daysTo(today)); // grid index for "today"
       
  1288 	QDateTime end = gridStart.addDays(mNumOfRowsInPrevMonth * KCalenDaysInWeek);
       
  1289 	QDateTime gridEnd(end.date(), QTime(23, 59, 59, 0));
       
  1290 
       
  1291 
       
  1292 	// Get the list of dates which have events
       
  1293 	QList<QDate> datesWithEvents;
       
  1294 	getInstanceList(datesWithEvents,gridStart,gridEnd);
       
  1295 	
       
  1296 	// Parse thru the list of dates and set the required flags
       
  1297 	int datesEventsCount = datesWithEvents.count();
       
  1298 	for(int i(0); i < datesEventsCount; i++) {
       
  1299 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
       
  1300 		mMonthDataArray[offset].SetHasEvents(true);
       
  1301 	}
       
  1302 	datesWithEvents.clear();
       
  1303 	
       
  1304 	if (datesEventsCount) {
       
  1305         mEntriesInDataBase = true;
       
  1306     }
       
  1307 	
       
  1308 	OstTraceFunctionExit0( CALENMONTHVIEW_POPULATEPREVMONTH_EXIT );
       
  1309 }
       
  1310 
       
  1311 /*!
       
  1312  Parses the fetched entries for future month and 
       
  1313  sets hasEvent attribute for necessary days
       
  1314  */
       
  1315 void CalenMonthView::populateNextMonth()
       
  1316 {
       
  1317     OstTraceFunctionEntry0( CALENMONTHVIEW_POPULATENEXTMONTH_ENTRY );
       
  1318 	QList<AgendaEntry> list;
       
  1319 	int actualIndex = mNumOfRowsInFutureMonth * KCalenDaysInWeek;
       
  1320 	const QDateTime gridStart(mLastDayOfGrid.addDays(-actualIndex));
       
  1321 	actualIndex = mMonthDataArray.count() - actualIndex -1;
       
  1322 	
       
  1323 	const QDateTime today(CalenDateUtils::today());
       
  1324 	const int todayIndex(gridStart.daysTo(today)); // grid index for "today"
       
  1325 	QDateTime gridEnd(mLastDayOfGrid.date(), QTime(23, 59, 59, 0));
       
  1326 
       
  1327 	// Get the list of dates which have events
       
  1328 	QList<QDate> datesWithEvents;
       
  1329 	getInstanceList(datesWithEvents,gridStart,gridEnd);
       
  1330 	
       
  1331 	// Parse thru the list of dates and set the required flags
       
  1332 	int datesEventsCount = datesWithEvents.count();
       
  1333 	for(int i(0); i < datesEventsCount; i++) {
       
  1334 		int offset = mFirstDayOfGrid.date().daysTo(datesWithEvents.at(i));
       
  1335 		mMonthDataArray[offset].SetHasEvents(true);
       
  1336 	}
       
  1337 	datesWithEvents.clear();
       
  1338 	
       
  1339 	if (datesEventsCount) {
       
  1340         mEntriesInDataBase = true;
       
  1341     }
       
  1342 	OstTraceFunctionExit0( CALENMONTHVIEW_POPULATENEXTMONTH_EXIT );
       
  1343 }
       
  1344 
       
  1345 /*!
       
  1346 	Function that gets called when instacne view is created, so that it can
       
  1347 	query agenda server for any entries
       
  1348  */
       
  1349 void CalenMonthView::fetchEntriesAndUpdateModel()
       
  1350 {
       
  1351     OstTraceFunctionEntry0( CALENMONTHVIEW_FETCHENTRIESANDUPDATEMODEL_ENTRY );
       
  1352     
       
  1353 	// Get to know if entries are there from the agenda server
       
  1354 	populateWithInstanceView();
       
  1355 	// Update the month grid model
       
  1356 	mMonthGrid->updateMonthGridWithEventIndicators(mMonthDataArray);
       
  1357 	// Populate the preview panes
       
  1358 	populatePreviewPane(mDate);
       
  1359 	
       
  1360 	OstTraceFunctionExit0( CALENMONTHVIEW_FETCHENTRIESANDUPDATEMODEL_EXIT );
       
  1361 }
       
  1362 
       
  1363 /*!
       
  1364  Populates the preview pane
       
  1365  */
       
  1366 void CalenMonthView::populatePreviewPane(QDateTime &dateTime)
       
  1367 {
       
  1368     OstTraceFunctionEntry0( CALENMONTHVIEW_POPULATEPREVIEWPANE_ENTRY );
       
  1369     
       
  1370 	mPrevPreviewPane->populateLabel(dateTime.addDays(-1));
       
  1371 	mCurrPreviewPane->populateLabel(dateTime);
       
  1372 	mNextPreviewPane->populateLabel(dateTime.addDays(1));
       
  1373 	
       
  1374 	// Start the auto scroll on current preview pane
       
  1375     mCurrPreviewPane->startAutoScroll();
       
  1376     
       
  1377     OstTraceFunctionExit0( CALENMONTHVIEW_POPULATEPREVIEWPANE_EXIT );
       
  1378 }
       
  1379 
       
  1380 /*!
       
  1381  Completes the population after setting the view as 
       
  1382  current view to the main window
       
  1383  */
       
  1384 void CalenMonthView::completePopulation()
       
  1385 {
       
  1386     OstTraceFunctionEntry0( CALENMONTHVIEW_COMPLETEPOPULATION_ENTRY );
       
  1387     
       
  1388 	setDateToLabel();
       
  1389 	
       
  1390 	OstTraceFunctionExit0( CALENMONTHVIEW_COMPLETEPOPULATION_EXIT );
       
  1391 }
       
  1392 
       
  1393 /*!
       
  1394  Launches the day view on tapping of the grid item
       
  1395  */
       
  1396 void CalenMonthView::handleGridItemActivated()
       
  1397 {
       
  1398     OstTraceFunctionEntry0( CALENMONTHVIEW_HANDLEGRIDITEMACTIVATED_ENTRY );
       
  1399     
       
  1400 	mServices.IssueCommandL(ECalenDayView);
       
  1401 	
       
  1402 	OstTraceFunctionExit0( CALENMONTHVIEW_HANDLEGRIDITEMACTIVATED_EXIT );
       
  1403 }
       
  1404 
       
  1405 /*!
       
  1406  Sets the context w.r.t to the active day
       
  1407  */
       
  1408 void CalenMonthView::setContextForActiveDay(int index)
       
  1409 {
       
  1410     OstTraceFunctionEntry0( CALENMONTHVIEW_SETCONTEXTFORACTIVEDAY_ENTRY );
       
  1411 	QDateTime newActiveDay = mFirstDayOfGrid.addDays(index);
       
  1412 	// Set the context
       
  1413 	mServices.Context().setFocusDate(newActiveDay);
       
  1414 	mDate = newActiveDay;
       
  1415 	setDateToLabel();
       
  1416 	
       
  1417 	if(!mIsPrevPaneGesture) {
       
  1418 		populatePreviewPane(mDate);
       
  1419 	} else {
       
  1420 		// reset flag
       
  1421 		mIsPrevPaneGesture = false;
       
  1422 	}
       
  1423 	
       
  1424 	OstTraceFunctionExit0( CALENMONTHVIEW_SETCONTEXTFORACTIVEDAY_EXIT );
       
  1425 }
       
  1426 
       
  1427 /*!
       
  1428  Slot to launch the event editor
       
  1429  */
       
  1430 void CalenMonthView::createEditor()
       
  1431 {
       
  1432 	OstTraceFunctionEntry0( CALENMONTHVIEW_CREATEEDITOR_ENTRY );
       
  1433 	
       
  1434     captureScreenshot(true);
       
  1435 	mServices.IssueCommandL(ECalenNewMeeting);
       
  1436 	
       
  1437 	OstTraceFunctionExit0( CALENMONTHVIEW_CREATEEDITOR_EXIT );
       
  1438 }
       
  1439 
       
  1440 /*!
       
  1441  Slot to launch the Day view
       
  1442  */
       
  1443 void CalenMonthView::launchDayView()
       
  1444 {
       
  1445     OstTraceFunctionEntry0( CALENMONTHVIEW_LAUNCHDAYVIEW_ENTRY );
       
  1446     
       
  1447 	mServices.IssueCommandL(ECalenDayView);
       
  1448 	// day view launched now, disconnect to get the call backs for saveActivity 
       
  1449 	// on aboutToQuit signal
       
  1450 	disconnectAboutToQuitEvent();
       
  1451 	
       
  1452 	OstTraceFunctionExit0( CALENMONTHVIEW_LAUNCHDAYVIEW_EXIT );
       
  1453 }
       
  1454 
       
  1455 /*!
       
  1456 disconnects for the aboutToQuit events
       
  1457  */
       
  1458 void CalenMonthView::disconnectAboutToQuitEvent()
       
  1459 {
       
  1460 	OstTraceFunctionEntry0( CALENMONTHVIEW_DISCONNECTABOUTTOQUITEVENT_ENTRY );
       
  1461 	
       
  1462 	if (mIsAboutToQuitEventConnected) {
       
  1463 		disconnect(qobject_cast<HbApplication*>(qApp), SIGNAL(aboutToQuit()), this, SLOT(saveActivity()));
       
  1464 		mIsAboutToQuitEventConnected = false;
       
  1465 	}
       
  1466 	
       
  1467 	OstTraceFunctionExit0( CALENMONTHVIEW_DISCONNECTABOUTTOQUITEVENT_EXIT );
       
  1468 }
       
  1469 
       
  1470 /*!
       
  1471  Slot to handle the change in orientation
       
  1472  */
       
  1473 void CalenMonthView::changeOrientation(Qt::Orientation orientation)
       
  1474 {
       
  1475     OstTraceFunctionEntry0( CALENMONTHVIEW_CHANGEORIENTATION_ENTRY );
       
  1476     
       
  1477 		if (mOrientation != orientation) {
       
  1478 			// change the orientation here
       
  1479 			mOrientation = orientation;
       
  1480 			handleChangeOrientation();
       
  1481 		}
       
  1482 		
       
  1483 	OstTraceFunctionExit0( CALENMONTHVIEW_CHANGEORIENTATION_EXIT );
       
  1484 }
       
  1485 
       
  1486 /*!
       
  1487  Slot to handle the change in theme
       
  1488  */
       
  1489 void CalenMonthView::handleThemeChange()
       
  1490 {
       
  1491     OstTraceFunctionEntry0( CALENMONTHVIEW_HANDLETHEMECHANGE_ENTRY );
       
  1492     
       
  1493     // Refresh the month view when the theme change happens
       
  1494     mWeekDaysColor = HbColorScheme::color("qtc_cal_week_day");
       
  1495     QColor monthTitleColor = HbColorScheme::color("qtc_cal_monthgrid_title");
       
  1496     
       
  1497     if (mTitleLabel && monthTitleColor.isValid()) {
       
  1498 		mTitleLabel->setTextColor(monthTitleColor);
       
  1499 	}
       
  1500     
       
  1501     mPreviewHeadingColor = HbColorScheme::color("qtc_cal_day_preview_heading");
       
  1502     
       
  1503     mServices.IssueCommandL(ECalenStartActiveStep);
       
  1504     
       
  1505     OstTraceFunctionExit0( CALENMONTHVIEW_HANDLETHEMECHANGE_EXIT );
       
  1506 }
       
  1507 
       
  1508 /*!
       
  1509  Loads appropriate section from the docml dsepending on the current orientation
       
  1510  of the device
       
  1511  */
       
  1512 void CalenMonthView::handleChangeOrientation()
       
  1513 {
       
  1514     OstTraceFunctionEntry0( CALENMONTHVIEW_HANDLECHANGEORIENTATION_ENTRY );
       
  1515     
       
  1516 	bool loadSuccess = false;
       
  1517 	if (mOrientation == Qt::Horizontal) {
       
  1518 		mDocLoader->load(CALEN_MONTHVIEW_XML_FILE, CALEN_LANDSCAPE,
       
  1519 		                 &loadSuccess);
       
  1520 
       
  1521 	} else if (mOrientation == Qt::Vertical) {
       
  1522 		mDocLoader->load(CALEN_MONTHVIEW_XML_FILE, CALEN_PORTRAIT, 
       
  1523 													&loadSuccess);
       
  1524 	}
       
  1525 	
       
  1526 	Q_ASSERT_X(loadSuccess, "calenmonthview.cpp", "Unable to load XML");
       
  1527 	
       
  1528 	// Remove the current pane read from the docml  from the layout 
       
  1529 	// and add actual current pane to the layout
       
  1530 	QGraphicsLinearLayout* viewLayout = static_cast<QGraphicsLinearLayout *>
       
  1531 													(widget()->layout());
       
  1532 	viewLayout->removeAt(1);
       
  1533 	// Add this item only when orientaion is changed on month view
       
  1534 	// if it is changed in other views, adding the preview pane here was
       
  1535 	// overlapping with the month grid, hence, its been added in dopopulation()
       
  1536 	if (this == mServices.MainWindow().currentView()) {
       
  1537 		viewLayout->addItem(mCurrPaneParent);
       
  1538 	}
       
  1539 	
       
  1540 	OstTraceFunctionExit0( CALENMONTHVIEW_HANDLECHANGEORIENTATION_EXIT );
       
  1541 }
       
  1542 
       
  1543 /*!
       
  1544  Sets the appropriate date to the month title
       
  1545  */
       
  1546 void CalenMonthView::setDateToLabel()
       
  1547 {
       
  1548     OstTraceFunctionEntry0( CALENMONTHVIEW_SETDATETOLABEL_ENTRY );
       
  1549     
       
  1550 	// Get the localised string for month name from system locale
       
  1551 	QString dateString = mLocale.monthName(mDate.date().month(), HbExtendedLocale::LongFormat);
       
  1552 	// Append a single space
       
  1553 	dateString.append(" ");
       
  1554 	mLocale.setNumberOptions(QLocale::OmitGroupSeparator);
       
  1555 	// Append the year string also
       
  1556 	dateString.append(mLocale.toString(mDate.date().year()));
       
  1557 	mTitleLabel->setPlainText(dateString);
       
  1558 	
       
  1559 	OstTraceFunctionExit0( CALENMONTHVIEW_SETDATETOLABEL_EXIT );
       
  1560 }
       
  1561 
       
  1562 /*!
       
  1563  To handle previewpane swipe 
       
  1564  */
       
  1565 void CalenMonthView::handlePreviewPaneGesture(bool rightGesture)
       
  1566 {
       
  1567     OstTraceFunctionEntry0( CALENMONTHVIEW_HANDLEPREVIEWPANEGESTURE_ENTRY );
       
  1568     
       
  1569 	QGraphicsLinearLayout* viewLayout = static_cast<QGraphicsLinearLayout *>
       
  1570 												(widget()->layout());
       
  1571 	
       
  1572 	// Set the effect in progress flags for next and previous panes
       
  1573 	// For current pane, we would have set it in gestureEvent() function
       
  1574 	mPrevPreviewPane->effectStarted();
       
  1575 	mNextPreviewPane->effectStarted();
       
  1576 	
       
  1577 	if(rightGesture) {
       
  1578 		// Need to bring up the previous day preview pane
       
  1579 		// Create the effect on mCurrPreviewPane to slide to right side
       
  1580 		mPrevPaneParent->setVisible(true);
       
  1581 		if (mOrientation == Qt::Vertical) {
       
  1582 			HbEffect::add(mCurrPaneLayoutWidget,
       
  1583 						  ":/fxml/portrait_preview_pane_hide_on_right_gesture",
       
  1584 						  "hide");
       
  1585 			HbEffect::add(mPrevPaneLayoutWidget,
       
  1586 						  ":/fxml/portrait_preview_pane_show_on_right_gesture",
       
  1587 						  "show");
       
  1588 		} else {
       
  1589 			HbEffect::add(mCurrPaneLayoutWidget,
       
  1590 						  ":/fxml/landscape_preview_pane_hide_on_right_gesture",
       
  1591 						  "hide");
       
  1592 			HbEffect::add(mPrevPaneLayoutWidget,
       
  1593 						  ":/fxml/landscape_preview_pane_show_on_right_gesture",
       
  1594 						  "show");
       
  1595 		}
       
  1596 		// Start the effects
       
  1597 		HbEffect::start(mCurrPaneLayoutWidget, "hide");
       
  1598 		HbEffect::start(mPrevPaneLayoutWidget, "show", 
       
  1599 										this, "handleRightEffectCompleted");
       
  1600 		
       
  1601 		//Remove the mCurrPreviewPane from the layout and add mPrevPreviewPane
       
  1602 		// to the layout
       
  1603 		viewLayout->removeAt(1);
       
  1604 		viewLayout->addItem(mPrevPaneParent);
       
  1605 	} else {
       
  1606 		// Need to bring up the previous day preview pane
       
  1607 		// Create the effect on mCurrPreviewPane to slide to left side
       
  1608 		mNextPaneParent->setVisible(true);
       
  1609 		if (mOrientation == Qt::Vertical) {
       
  1610 			HbEffect::add(mCurrPaneLayoutWidget,
       
  1611 						  ":/fxml/portrait_preview_pane_hide_on_left_gesture",
       
  1612 						  "hide");
       
  1613 			HbEffect::add(mNextPaneLayoutWidget,
       
  1614 						  ":/fxml/portrait_preview_pane_show_on_left_gesture",
       
  1615 						  "show");
       
  1616 		} else {
       
  1617 			HbEffect::add(mCurrPaneLayoutWidget,
       
  1618 						  ":/fxml/landscape_preview_pane_hide_on_left_gesture",
       
  1619 						  "hide");
       
  1620 			HbEffect::add(mNextPaneLayoutWidget,
       
  1621 						  ":/fxml/landscape_preview_pane_show_on_left_gesture",
       
  1622 						  "show");
       
  1623 		}
       
  1624 		
       
  1625 		// Start the effects
       
  1626 		HbEffect::start(mCurrPaneLayoutWidget, "hide");
       
  1627 		HbEffect::start(mNextPaneLayoutWidget, "show", 
       
  1628 										this, "handleLeftEffectCompleted");
       
  1629 		
       
  1630 		//Remove the mCurrPreviewPane from the layout and add mNextPreviewPane
       
  1631 		// to the layout
       
  1632 		viewLayout->removeAt(1);
       
  1633 		viewLayout->addItem(mNextPaneParent);
       
  1634 	}
       
  1635 	
       
  1636 	OstTraceFunctionExit0( CALENMONTHVIEW_HANDLEPREVIEWPANEGESTURE_EXIT );
       
  1637 }
       
  1638 
       
  1639 /*!
       
  1640  Returns the first date in the month grid
       
  1641  */
       
  1642 QDateTime CalenMonthView::firstDayOfGrid()
       
  1643 {
       
  1644     OstTraceFunctionEntry0( CALENMONTHVIEW_FIRSTDAYOFGRID_ENTRY );
       
  1645     
       
  1646 	OstTraceFunctionExit0( CALENMONTHVIEW_FIRSTDAYOFGRID_EXIT );
       
  1647 	return mFirstDayOfGrid;
       
  1648 }
       
  1649 
       
  1650 /*!
       
  1651  Function to handle any locale related changes
       
  1652  */
       
  1653 void CalenMonthView::onLocaleChanged(int reason)
       
  1654 {
       
  1655     OstTraceFunctionEntry0( CALENMONTHVIEW_ONLOCALECHANGED_ENTRY );
       
  1656     
       
  1657     if ((reason & EChangesSystemTime) 
       
  1658     		|| (reason & EChangesMidnightCrossover)) {
       
  1659 		mCurrentDay = CalenDateUtils::today();
       
  1660 	}
       
  1661 	OstTraceFunctionExit0( CALENMONTHVIEW_ONLOCALECHANGED_EXIT );
       
  1662 }
       
  1663 
       
  1664 /*!
       
  1665  Slot to handle left gesture effects completion
       
  1666  */
       
  1667 void CalenMonthView::handleLeftEffectCompleted(
       
  1668 										const HbEffect::EffectStatus &status)
       
  1669 {
       
  1670     OstTraceFunctionEntry0( CALENMONTHVIEW_HANDLELEFTEFFECTCOMPLETED_ENTRY );
       
  1671 	Q_UNUSED(status);
       
  1672 	
       
  1673 	int index = getCurrGridIndex();
       
  1674 	index++;
       
  1675 	
       
  1676 	// Stop the scrolling on current preview pane
       
  1677 	mCurrPreviewPane->stopScrolling();
       
  1678 	
       
  1679 	// Swap the preview panes properly
       
  1680 	CalenPreviewPane* pane = mCurrPreviewPane;
       
  1681 	HbWidget* paneParent = mCurrPaneParent;
       
  1682 	HbWidget* paneLayoutWidget = mCurrPaneLayoutWidget;
       
  1683 	mCurrPreviewPane = mNextPreviewPane;
       
  1684 	mCurrPaneParent = mNextPaneParent;
       
  1685 	mCurrPaneLayoutWidget = mNextPaneLayoutWidget;
       
  1686 	mNextPreviewPane = mPrevPreviewPane;
       
  1687 	mNextPaneParent = mPrevPaneParent;
       
  1688 	mNextPaneLayoutWidget = mPrevPaneLayoutWidget;
       
  1689 	mPrevPreviewPane = pane;
       
  1690 	mPrevPaneParent = paneParent;
       
  1691 	mPrevPaneLayoutWidget = paneLayoutWidget;
       
  1692 	
       
  1693 	// Reset the effect in progress flag
       
  1694 	mCurrPreviewPane->effectFinished();
       
  1695     mPrevPreviewPane->effectFinished();
       
  1696     mNextPreviewPane->effectFinished();
       
  1697     
       
  1698 	// Set the focus to proper date
       
  1699 	setCurrGridIndex(index);
       
  1700 	// Start the auto scroll on current preview pane
       
  1701 	mCurrPreviewPane->startAutoScroll();
       
  1702 	mNextPreviewPane->populateLabel(mDate.addDays(1));
       
  1703 	OstTraceFunctionExit0( CALENMONTHVIEW_HANDLELEFTEFFECTCOMPLETED_EXIT );
       
  1704 }
       
  1705 
       
  1706 /*!
       
  1707  Slot to handle right gesture effects completion
       
  1708  */
       
  1709 void CalenMonthView::handleRightEffectCompleted(
       
  1710 										const HbEffect::EffectStatus &status) 	
       
  1711 {
       
  1712     OstTraceFunctionEntry0( CALENMONTHVIEW_HANDLERIGHTEFFECTCOMPLETED_ENTRY );
       
  1713     
       
  1714 	Q_UNUSED(status);
       
  1715 	
       
  1716 	int index = getCurrGridIndex();
       
  1717 	index--;
       
  1718 	
       
  1719 	// Stop the scrolling on current preview pane
       
  1720 	mCurrPreviewPane->stopScrolling();
       
  1721 		
       
  1722 	// Swap the preview panes properly
       
  1723 	CalenPreviewPane* pane = mCurrPreviewPane;
       
  1724 	HbWidget* paneParent = mCurrPaneParent;
       
  1725 	HbWidget* paneLayoutWidget = mCurrPaneLayoutWidget;
       
  1726 	mCurrPreviewPane = mPrevPreviewPane;
       
  1727 	mCurrPaneParent = mPrevPaneParent;
       
  1728 	mCurrPaneLayoutWidget = mPrevPaneLayoutWidget;
       
  1729 	mPrevPreviewPane = mNextPreviewPane;
       
  1730 	mPrevPaneParent = mNextPaneParent;
       
  1731 	mPrevPaneLayoutWidget = mNextPaneLayoutWidget;
       
  1732 	mNextPreviewPane = pane;
       
  1733 	mNextPaneParent = paneParent;
       
  1734 	mNextPaneLayoutWidget = paneLayoutWidget;
       
  1735 	
       
  1736 	// Reset the effect in progress flag
       
  1737 	mCurrPreviewPane->effectFinished();
       
  1738     mNextPreviewPane->effectFinished();
       
  1739     mPrevPreviewPane->effectFinished();
       
  1740     
       
  1741 	// Set the focus to proper date
       
  1742 	setCurrGridIndex(index);
       
  1743 	// Start the auto scroll on current preview pane
       
  1744 	mCurrPreviewPane->startAutoScroll();
       
  1745 	mPrevPreviewPane->populateLabel(mDate.addDays(-1));
       
  1746 	
       
  1747 	OstTraceFunctionExit0( CALENMONTHVIEW_HANDLERIGHTEFFECTCOMPLETED_EXIT );
       
  1748 }
       
  1749 /*!
       
  1750  update the Day labels 
       
  1751  */
       
  1752 void CalenMonthView::updateDayLabel()
       
  1753 {
       
  1754     OstTraceFunctionEntry0( CALENMONTHVIEW_UPDATEDAYLABEL_ENTRY );
       
  1755     
       
  1756     // Set the short day names to these labels  
       
  1757     int startOfWeek = mLocale.startOfWeek();
       
  1758     int weekDayIndex = startOfWeek;
       
  1759     QStringList  weekDayArray ;
       
  1760     weekDayArray <<hbTrId("txt_calendar_grid_day_mo")
       
  1761                            <<hbTrId("txt_calendar_grid_day_tu")
       
  1762                            <<hbTrId("txt_calendar_grid_day_we")
       
  1763                            <<hbTrId("txt_calendar_grid_day_th")
       
  1764                            <<hbTrId("txt_calendar_grid_day_fr")
       
  1765                            <<hbTrId("txt_calendar_grid_day_sa")
       
  1766                            <<hbTrId("txt_calendar_grid_day_su");
       
  1767             
       
  1768     QList<HbLabel*> labels;
       
  1769     // append seven day labels 
       
  1770     labels.append(mFirstDayLabel);
       
  1771     labels.append(mSecondDayLabel);
       
  1772     labels.append(mThirdDayLabel);
       
  1773     labels.append(mFourthDayLabel);
       
  1774     labels.append(mFifthDayLabel);
       
  1775     labels.append(mSixthDayLabel);
       
  1776     labels.append(mSeventhDayLabel);
       
  1777     QGraphicsLinearLayout* layout = static_cast<QGraphicsLinearLayout*> (mDayNameWidget->layout());
       
  1778     for(int i=0;i < KCalenDaysInWeek; i++ )
       
  1779         {
       
  1780         labels.at(i)->setPlainText(weekDayArray[weekDayIndex]);
       
  1781         // Set the stretch factor as 1 so that each label occupies equal space
       
  1782         layout->setStretchFactor(labels.at(i), 1);
       
  1783         if(weekDayIndex == KCalenDaysInWeek - 1 )//Sunday
       
  1784             {
       
  1785             weekDayIndex = 0;//reset to monday
       
  1786             continue;
       
  1787             }
       
  1788         weekDayIndex++;//increase the index for next value
       
  1789         }
       
  1790     labels.clear();
       
  1791     weekDayArray.clear();
       
  1792     
       
  1793     OstTraceFunctionExit0( CALENMONTHVIEW_UPDATEDAYLABEL_EXIT );
       
  1794 }
       
  1795 // End of file  --Don't remove this.