calendarui/views/src/calenmonthview.cpp
changeset 49 5de72ea7a065
parent 32 ea672fcb0ea0
child 50 579cc610882e
equal deleted inserted replaced
37:360d55486d7f 49:5de72ea7a065
    27 #include <hblabel.h>
    27 #include <hblabel.h>
    28 #include <hbframeitem.h>
    28 #include <hbframeitem.h>
    29 #include <hbcolorscheme.h>
    29 #include <hbcolorscheme.h>
    30 #include <agendautil.h>
    30 #include <agendautil.h>
    31 #include <agendaentry.h>
    31 #include <agendaentry.h>
       
    32 #include <hbapplication.h> // hbapplication
       
    33 #include <hbactivitymanager.h> //Activity Manager
    32 
    34 
    33 //user includes
    35 //user includes
    34 #include "calenmonthview.h"
    36 #include "calenmonthview.h"
    35 #include "calenservices.h"
    37 #include "calenservices.h"
    36 #include "calennativeview.h"
    38 #include "calennativeview.h"
    46 #include "calendocloader.h"
    48 #include "calendocloader.h"
    47 #include "calenthicklinesdrawer.h"
    49 #include "calenthicklinesdrawer.h"
    48 #include "calencommon.h"
    50 #include "calencommon.h"
    49 #include "calendarprivatecrkeys.h"
    51 #include "calendarprivatecrkeys.h"
    50 #include "calenpluginlabel.h"
    52 #include "calenpluginlabel.h"
       
    53 #include "calenconstants.h"
    51 /*!
    54 /*!
    52  \class CalenMonthView
    55  \class CalenMonthView
    53 
    56 
    54  Class implementing calendar month view
    57  Class implementing calendar month view
    55  */
    58  */
    60 CalenMonthView::CalenMonthView(MCalenServices &services) :
    63 CalenMonthView::CalenMonthView(MCalenServices &services) :
    61 	CalenNativeView(services), mAgendaUtil(services.agendaInterface()), 
    64 	CalenNativeView(services), mAgendaUtil(services.agendaInterface()), 
    62 	mGoToTodayAction(0),
    65 	mGoToTodayAction(0),
    63 	mPrevRegionalInfo(0),
    66 	mPrevRegionalInfo(0),
    64 	mCurrRegionalInfo(0),
    67 	mCurrRegionalInfo(0),
    65 	mNextRegionalInfo(0)
    68 	mNextRegionalInfo(0),
       
    69 	mIsAboutToQuitEventConnected(false)
    66 {
    70 {
    67 	mIsWeekNumbersShown = 0;
    71 	mIsWeekNumbersShown = 0;
    68 	mOrientation = mServices.MainWindow().orientation();
    72 	mOrientation = mServices.MainWindow().orientation();
    69 	// Read the date from the context
    73 	// Read the date from the context
    70 	mDate = mServices.Context().focusDateAndTimeL();
    74 	mDate = mServices.Context().focusDateAndTimeL();
   131 	        = qobject_cast<HbLabel *> (
   135 	        = qobject_cast<HbLabel *> (
   132 					   mDocLoader->findWidget(CALEN_MONTVIEW_SIXTH_DAY_LABEL));
   136 					   mDocLoader->findWidget(CALEN_MONTVIEW_SIXTH_DAY_LABEL));
   133 	mSeventhDayLabel
   137 	mSeventhDayLabel
   134 	        = qobject_cast<HbLabel *> (
   138 	        = qobject_cast<HbLabel *> (
   135 					mDocLoader->findWidget(CALEN_MONTVIEW_SEVENTH_DAY_LABEL));
   139 					mDocLoader->findWidget(CALEN_MONTVIEW_SEVENTH_DAY_LABEL));
   136 
       
   137 	// Set the short day names to these labels
       
   138 	// TODO: Need to read start of the week from the locale
       
   139 	// and update the labels accortdingly
       
   140 	int startOfDay = mLocale.startOfWeek();
       
   141 	mFirstDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_mo"));
       
   142 	mSecondDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_tu"));
       
   143 	mThirdDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_we"));
       
   144 	mFourthDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_th"));
       
   145 	mFifthDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_fr"));
       
   146 	mSixthDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_sa"));
       
   147 	mSeventhDayLabel->setPlainText(hbTrId("txt_calendar_grid_day_su"));
       
   148 	
   140 	
   149 	// Get the weeknumber widget
   141 	// Get the weeknumber widget
   150 	mWeekNumberWidget
   142 	mWeekNumberWidget
   151 			= qobject_cast<CalenThickLinesDrawer *> (
   143 			= qobject_cast<CalenThickLinesDrawer *> (
   152 							 mDocLoader->findWidget(CALEN_WEEKNUMBERS_WIDGET));
   144 							 mDocLoader->findWidget(CALEN_WEEKNUMBERS_WIDGET));
   212 	mMonthGrid->setView(this);
   204 	mMonthGrid->setView(this);
   213 
   205 
   214 	
   206 	
   215 	
   207 	
   216 	mIsFirstTimeLoad = true;
   208 	mIsFirstTimeLoad = true;
   217 	
   209 	// get a pointner to activity manager
       
   210 	HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
       
   211 
       
   212 	// clean up any previous versions of this activity, if any, i.e. activityName, from the activity manager. 
       
   213 	// Ignore return value, first boot would always return False. bool declared 
       
   214 	// only for debugging purpose.
       
   215 	bool ok = activityManager->removeActivity(activityName);
       
   216 
   218 }
   217 }
   219 
   218 
   220 /*!
   219 /*!
   221  Constructs the remaining part of the month view that was kept as 
   220  Constructs the remaining part of the month view that was kept as 
   222  part if lazy loading
   221  part if lazy loading
   451     mNextPaneLayoutWidget->setBackgroundItem(frame->graphicsItem(), -5);
   450     mNextPaneLayoutWidget->setBackgroundItem(frame->graphicsItem(), -5);
   452 }
   451 }
   453 
   452 
   454 void CalenMonthView::showHideRegionalInformation()
   453 void CalenMonthView::showHideRegionalInformation()
   455 {
   454 {
   456     XQSettingsKey regionalInfo(XQSettingsKey::TargetCentralRepository,
   455 	if (pluginEnabled()) {
   457                                KCRUidCalendar, KCalendarShowRegionalInfo);
   456 		XQSettingsKey regionalInfo(XQSettingsKey::TargetCentralRepository,
   458     
   457 									KCRUidCalendar, KCalendarShowRegionalInfo);
   459     int showRegionalInfo = mSettingsManager->readItemValue(regionalInfo).toUInt();
   458 
   460     if (showRegionalInfo) {
   459 		int showRegionalInfo = 
   461 		
   460 						mSettingsManager->readItemValue(regionalInfo).toUInt();
   462         // Add the regional information to the preview panes
   461 		if (showRegionalInfo) {
   463         if (!mPrevRegionalInfo) {
   462 
   464             mPrevRegionalInfo = qobject_cast<CalenPluginLabel *> 
   463 			// Add the regional information to the preview panes
   465 							(mDocLoader->findWidget(CALEN_PREVREGIONALINFO));
   464 			if (!mPrevRegionalInfo) {
   466             mPrevRegionalInfo->show();
   465 				mPrevRegionalInfo = qobject_cast<CalenPluginLabel *> 
   467             mPrevPaneLayout->insertItem(0, mPrevRegionalInfo);
   466 				(mDocLoader->findWidget(CALEN_PREVREGIONALINFO));
   468 
   467 				mPrevRegionalInfo->show();
   469             HbFrameItem *frameCurr = new HbFrameItem(this);
   468 				mPrevPaneLayout->insertItem(0, mPrevRegionalInfo);
   470             frameCurr->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesHorizontal);
   469 
   471             frameCurr->frameDrawer().setFrameGraphicsName("qtg_fr_cal_preview_title_bg");
   470 				HbFrameItem *frameCurr = new HbFrameItem(this);
   472             mPrevRegionalInfo->setBackgroundItem(frameCurr->graphicsItem(), -2);
   471 				frameCurr->frameDrawer().setFrameType(
   473         }
   472 										HbFrameDrawer::ThreePiecesHorizontal);
   474         if (!mCurrRegionalInfo) {
   473 				frameCurr->frameDrawer().setFrameGraphicsName(
   475             mCurrRegionalInfo = qobject_cast<CalenPluginLabel *> 
   474 										"qtg_fr_cal_preview_title_bg");
   476 							(mDocLoader->findWidget(CALEN_CURRREGIONALINFO));
   475 				mPrevRegionalInfo->setBackgroundItem(
   477             mCurrRegionalInfo->show();
   476 										frameCurr->graphicsItem(), -2);
   478             mCurrPaneLayout->insertItem(0, mCurrRegionalInfo);
   477 			}
   479             
   478 			if (!mCurrRegionalInfo) {
   480             HbFrameItem *frameCurr = new HbFrameItem(this);
   479 				mCurrRegionalInfo = qobject_cast<CalenPluginLabel *> 
   481             frameCurr->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesHorizontal);
   480 				(mDocLoader->findWidget(CALEN_CURRREGIONALINFO));
   482             frameCurr->frameDrawer().setFrameGraphicsName("qtg_fr_cal_preview_title_bg");
   481 				mCurrRegionalInfo->show();
   483             mCurrRegionalInfo->setBackgroundItem(frameCurr->graphicsItem(), -2);
   482 				mCurrPaneLayout->insertItem(0, mCurrRegionalInfo);
   484         }
   483 
   485         if (!mNextRegionalInfo) {
   484 				HbFrameItem *frameCurr = new HbFrameItem(this);
   486             mNextRegionalInfo = qobject_cast<CalenPluginLabel *> 
   485 				frameCurr->frameDrawer().setFrameType(
   487 							(mDocLoader->findWidget(CALEN_NEXTREGIONALINFO));
   486 										HbFrameDrawer::ThreePiecesHorizontal);
   488             mNextRegionalInfo->show();
   487 				frameCurr->frameDrawer().setFrameGraphicsName(
   489             mNextPaneLayout->insertItem(0, mNextRegionalInfo);
   488 										"qtg_fr_cal_preview_title_bg");
   490 
   489 				mCurrRegionalInfo->setBackgroundItem(
   491             HbFrameItem *frameCurr = new HbFrameItem(this);
   490 										frameCurr->graphicsItem(), -2);
   492             frameCurr->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesHorizontal);
   491 			}
   493             frameCurr->frameDrawer().setFrameGraphicsName("qtg_fr_cal_preview_title_bg");
   492 			if (!mNextRegionalInfo) {
   494             mNextRegionalInfo->setBackgroundItem(frameCurr->graphicsItem(), -2);
   493 				mNextRegionalInfo = qobject_cast<CalenPluginLabel *> 
   495         }
   494 				(mDocLoader->findWidget(CALEN_NEXTREGIONALINFO));
   496         
   495 				mNextRegionalInfo->show();
   497         if (pluginEnabled()) {
   496 				mNextPaneLayout->insertItem(0, mNextRegionalInfo);
       
   497 
       
   498 				HbFrameItem *frameCurr = new HbFrameItem(this);
       
   499 				frameCurr->frameDrawer().setFrameType(
       
   500 										HbFrameDrawer::ThreePiecesHorizontal);
       
   501 				frameCurr->frameDrawer().setFrameGraphicsName(
       
   502 										"qtg_fr_cal_preview_title_bg");
       
   503 				mNextRegionalInfo->setBackgroundItem(
       
   504 										frameCurr->graphicsItem(), -2);
       
   505 			}
   498 			QString *pluginString = pluginText();
   506 			QString *pluginString = pluginText();
   499 			mPrevRegionalInfo->setPlainText(*pluginString);
   507 			mPrevRegionalInfo->setPlainText(*pluginString);
   500 			mCurrRegionalInfo->setPlainText(*pluginString);
   508 			mCurrRegionalInfo->setPlainText(*pluginString);
   501 			mNextRegionalInfo->setPlainText(*pluginString);
   509 			mNextRegionalInfo->setPlainText(*pluginString);
       
   510 		} else {
       
   511 			if (mPrevRegionalInfo) {
       
   512 				mPrevPaneLayout->removeItem(mPrevRegionalInfo);
       
   513 				mPrevRegionalInfo->hide();
       
   514 				mPrevRegionalInfo = NULL;
       
   515 			}
       
   516 			if (mCurrRegionalInfo) {
       
   517 				mPrevPaneLayout->removeItem(mCurrRegionalInfo);
       
   518 				mCurrRegionalInfo->hide();
       
   519 				mCurrRegionalInfo = NULL;
       
   520 			}
       
   521 			if (mNextRegionalInfo) {
       
   522 				mPrevPaneLayout->removeItem(mNextRegionalInfo);
       
   523 				mNextRegionalInfo->hide();
       
   524 				mNextRegionalInfo = NULL;
       
   525 			}
   502 		}
   526 		}
   503     } else {
   527 	}
   504         if (mPrevRegionalInfo) {
       
   505             mPrevPaneLayout->removeItem(mPrevRegionalInfo);
       
   506             mPrevRegionalInfo->hide();
       
   507             mPrevRegionalInfo = NULL;
       
   508         }
       
   509         if (mCurrRegionalInfo) {
       
   510             mPrevPaneLayout->removeItem(mCurrRegionalInfo);
       
   511             mCurrRegionalInfo->hide();
       
   512             mCurrRegionalInfo = NULL;
       
   513         }
       
   514         if (mNextRegionalInfo) {
       
   515             mPrevPaneLayout->removeItem(mNextRegionalInfo);
       
   516             mNextRegionalInfo->hide();
       
   517             mNextRegionalInfo = NULL;
       
   518         }
       
   519     }
       
   520 }
   528 }
   521 
   529 
   522 /*!
   530 /*!
   523  Handles the context changed notification
   531  Handles the context changed notification
   524  */
   532  */
   623 /*!
   631 /*!
   624  Populates the view
   632  Populates the view
   625  */
   633  */
   626 void CalenMonthView::doPopulation()
   634 void CalenMonthView::doPopulation()
   627 {
   635 {
   628 	// Get the layout and add the preview pane layout.
   636 
       
   637  	// Get the layout and add the preview pane layout.
   629 	QGraphicsLinearLayout* viewLayout = static_cast<QGraphicsLinearLayout *>
   638 	QGraphicsLinearLayout* viewLayout = static_cast<QGraphicsLinearLayout *>
   630 														(widget()->layout());
   639 														(widget()->layout());
   631 	if (viewLayout->count() == 1) {
   640 	if (viewLayout->count() == 1) {
   632 		// Count is 1 implies view has only month grid.
   641 		// Count is 1 implies view has only month grid.
   633 		// Add the preview pane at corresponding position.
   642 		// Add the preview pane at corresponding position.
   644 		populateWithInstanceView();
   653 		populateWithInstanceView();
   645 		// Populate the preview panes
   654 		// Populate the preview panes
   646 		populatePreviewPane(mDate);
   655 		populatePreviewPane(mDate);
   647 	}
   656 	}
   648 	
   657 	
   649 	// Create the grid items with proper dates
   658 	
       
   659     //update the day label 
       
   660     //if changes in locale setting
       
   661 	updateDayLabel();
       
   662 	
       
   663 	  // Create the grid items with proper dates
   650 	createGrid();
   664 	createGrid();
   651 	
   665 	
   652 
   666 
   653 	// Complete the population
   667 	// Complete the population
   654 	completePopulation();
   668 	completePopulation();
   655 
   669 
       
   670 	//set Currect Activity to month view
       
   671 	mActivityId = ECalenMonthView;
       
   672 	
       
   673 	// connect to receive a call back on Month View exit. Call back would result in saveActivity 
       
   674 	// to be called in Native View.
       
   675 	if (!mIsAboutToQuitEventConnected) // check if not already connected
       
   676 	    {
       
   677         connect(qobject_cast<HbApplication*>(qApp), SIGNAL(aboutToQuit()), this, SLOT(saveActivity()));
       
   678         mIsAboutToQuitEventConnected = true;
       
   679 	    }
       
   680 	
       
   681 		
   656 	// Population is complete, inform it
   682 	// Population is complete, inform it
   657 	populationComplete();
   683 	populationComplete();
   658 	
   684 	
   659 	// Handle regional data here if we are not populating the month view for
   685 	// Handle regional data here if we are not populating the month view for
   660 	// the first time
   686 	// the first time
   829 void CalenMonthView::createGrid()
   855 void CalenMonthView::createGrid()
   830 {
   856 {
   831 	// Update the month grid
   857 	// Update the month grid
   832 	mMonthGrid->updateMonthGridModel(mMonthDataArray, mIndexToBeScrolled, 
   858 	mMonthGrid->updateMonthGridModel(mMonthDataArray, mIndexToBeScrolled, 
   833 	                                 mIsFirstTimeLoad);
   859 	                                 mIsFirstTimeLoad);
   834 
   860     // Get start of week from the locale.
   835 	// Read the week number setting from cenrep
   861     HbExtendedLocale locale = HbExtendedLocale::system();
   836 	QVariant value = mSettingsManager->readItemValue(*mWeekNumberCenrepKey);
   862     int startOfWeek = locale.startOfWeek();
   837 	mIsWeekNumbersShown = value.toUInt();
   863     if(startOfWeek != HbExtendedLocale::Monday)
       
   864         {
       
   865         //if the start of week is other than Monday, don't show the week number
       
   866         mIsWeekNumbersShown = 0;
       
   867         }
       
   868     else
       
   869         {
       
   870         // Read the week number setting from cenrep
       
   871         QVariant value = mSettingsManager->readItemValue(*mWeekNumberCenrepKey);
       
   872         mIsWeekNumbersShown = value.toUInt();
       
   873         }
   838 	if (mIsWeekNumbersShown) {
   874 	if (mIsWeekNumbersShown) {
   839 		// Add week numbers to week grid
   875 		// Add week numbers to week grid
   840 		addWeekNumbers();
   876 		addWeekNumbers();
   841 	} else {
   877 	} else {
   842 		// remove the weeknumbergrid from the layout
   878 		// remove the weeknumbergrid from the layout
  1209  Slot to launch the agenda view
  1245  Slot to launch the agenda view
  1210  */
  1246  */
  1211 void CalenMonthView::launchDayView()
  1247 void CalenMonthView::launchDayView()
  1212 {
  1248 {
  1213 	mServices.IssueCommandL(ECalenDayView);
  1249 	mServices.IssueCommandL(ECalenDayView);
       
  1250 	// day view launched now, disconnect to get the call backs for saveActivity 
       
  1251 	// on aboutToQuit signal
       
  1252 	if (mIsAboutToQuitEventConnected)
       
  1253 	    {
       
  1254         disconnect(qobject_cast<HbApplication*>(qApp), SIGNAL(aboutToQuit()), this, SLOT(saveActivity()));
       
  1255         mIsAboutToQuitEventConnected = false;
       
  1256 	    }
  1214 }
  1257 }
  1215 
  1258 
  1216 /*!
  1259 /*!
  1217  Slot to handle the change in orientation
  1260  Slot to handle the change in orientation
  1218  */
  1261  */
  1420 	setCurrGridIndex(index);
  1463 	setCurrGridIndex(index);
  1421 	// Start the auto scroll on current preview pane
  1464 	// Start the auto scroll on current preview pane
  1422 	mCurrPreviewPane->startAutoScroll();
  1465 	mCurrPreviewPane->startAutoScroll();
  1423 	mPrevPreviewPane->populateLabel(mDate.addDays(-1));
  1466 	mPrevPreviewPane->populateLabel(mDate.addDays(-1));
  1424 }
  1467 }
       
  1468 /*!
       
  1469  update the Day labels 
       
  1470  */
       
  1471 void CalenMonthView::updateDayLabel()
       
  1472 {
       
  1473     // Set the short day names to these labels  
       
  1474     int startOfWeek = mLocale.startOfWeek();
       
  1475     int weekDayIndex = startOfWeek;
       
  1476     QStringList  weekDayArray ;
       
  1477     weekDayArray <<hbTrId("txt_calendar_grid_day_mo")
       
  1478                            <<hbTrId("txt_calendar_grid_day_tu")
       
  1479                            <<hbTrId("txt_calendar_grid_day_we")
       
  1480                            <<hbTrId("txt_calendar_grid_day_th")
       
  1481                            <<hbTrId("txt_calendar_grid_day_fr")
       
  1482                            <<hbTrId("txt_calendar_grid_day_sa")
       
  1483                            <<hbTrId("txt_calendar_grid_day_su");
       
  1484             
       
  1485     QList<HbLabel*> labels;
       
  1486     // append seven day labels 
       
  1487     labels.append(mFirstDayLabel);
       
  1488     labels.append(mSecondDayLabel);
       
  1489     labels.append(mThirdDayLabel);
       
  1490     labels.append(mFourthDayLabel);
       
  1491     labels.append(mFifthDayLabel);
       
  1492     labels.append(mSixthDayLabel);
       
  1493     labels.append(mSeventhDayLabel);
       
  1494     for(int i=0;i < KCalenDaysInWeek; i++ )
       
  1495         {
       
  1496         labels.at(i)->setPlainText(weekDayArray[weekDayIndex]);
       
  1497         if(weekDayIndex == KCalenDaysInWeek - 1 )//Sunday
       
  1498             {
       
  1499             weekDayIndex = 0;//reset to monday
       
  1500             continue;
       
  1501             }
       
  1502         weekDayIndex++;//increase the index for next value
       
  1503         }
       
  1504     labels.clear();
       
  1505     weekDayArray.clear();
       
  1506 }
  1425 // End of file  --Don't remove this.
  1507 // End of file  --Don't remove this.