calendarui/agendaeventviewer/src/agendaeventview.cpp
changeset 23 fd30d51f876b
parent 18 c198609911f9
child 26 a949c2543c15
child 45 b6db4fd4947b
equal deleted inserted replaced
18:c198609911f9 23:fd30d51f876b
    35 #include <hbi18ndef.h>
    35 #include <hbi18ndef.h>
    36 #include <HbRadioButtonList>
    36 #include <HbRadioButtonList>
    37 #include <HbMessageBox>
    37 #include <HbMessageBox>
    38 #include <HbDialog>
    38 #include <HbDialog>
    39 #include <HbLabel>
    39 #include <HbLabel>
    40 
    40 #include <QFile>
       
    41 #include <QString>
       
    42 #include <QIcon>
       
    43 #include <QPainter>
       
    44 #include <QPixmap>
    41 // User includes
    45 // User includes
    42 #include <agendautil.h>
    46 #include <agendautil.h>
    43 #include <noteseditor.h>
    47 #include <noteseditor.h>
    44 #include <caleneditor.h>
    48 #include <caleneditor.h>
    45 #include "agendaeventview.h"
    49 #include "agendaeventview.h"
    47 #include "agendaeventviewercommon.h"
    51 #include "agendaeventviewercommon.h"
    48 #include "agendaeventviewer_p.h"
    52 #include "agendaeventviewer_p.h"
    49 #include "agendaeventvieweritem.h"
    53 #include "agendaeventvieweritem.h"
    50 #include "calendateutils.h"
    54 #include "calendateutils.h"
    51 
    55 
       
    56 //maptile service 
       
    57 #include <maptileservice.h>
    52 // Constants
    58 // Constants
    53 #define CHARACTER_HYPHEN    "-"
    59 #define CHARACTER_HYPHEN    "-"
    54 #define CHARACTER_SPACE     " "
    60 #define CHARACTER_SPACE     " "
    55 #define CHARACTER_NEW_LINE  "\n"
    61 #define CHARACTER_NEW_LINE  "\n"
       
    62 
       
    63 // This is used to set the maptile image height and width ,
       
    64 //because HbLabel by default not displaying the actual size of image 
       
    65 const int height = 128;
       
    66 const int width =  330;
    56 /*!
    67 /*!
    57 	\class AgendaEventView.
    68 	\class AgendaEventView.
    58 
    69 
    59 	Responsible for viewing viewing agenda entries. This is friend of
    70 	Responsible for viewing viewing agenda entries. This is friend of
    60 	AgendaEventViewerPrivate and it handles all the cases
    71 	AgendaEventViewerPrivate and it handles all the cases
    70 AgendaEventView::AgendaEventView(
    81 AgendaEventView::AgendaEventView(
    71 		AgendaEventViewerPrivate *owner, QObject *parent):
    82 		AgendaEventViewerPrivate *owner, QObject *parent):
    72 		QObject(parent),
    83 		QObject(parent),
    73 		mOwner(owner),
    84 		mOwner(owner),
    74 		mReminderWidgetAdded(true),
    85 		mReminderWidgetAdded(true),
    75 		mMainWindow(NULL)
    86 		mMainWindow(NULL),
       
    87 		mMaptilePath(NULL)
    76 {
    88 {
    77 	qDebug() << "AgendaEventViewer: AgendaEventView::AgendaEventView -->";
    89 	qDebug() << "AgendaEventViewer: AgendaEventView::AgendaEventView -->";
    78 
    90 
    79 	// Load the translator based on locale
    91 	// Load the translator based on locale
    80 	mTranslator = new QTranslator;
    92 	mTranslator = new QTranslator;
   105 			mDocLoader->findWidget(AGENDA_EVENT_VIEWER_DATE_TIME_WIDGET));
   117 			mDocLoader->findWidget(AGENDA_EVENT_VIEWER_DATE_TIME_WIDGET));
   106 
   118 
   107 	mLocationWidget = qobject_cast<AgendaEventViewerItem *> (
   119 	mLocationWidget = qobject_cast<AgendaEventViewerItem *> (
   108 			mDocLoader->findWidget(AGENDA_EVENT_VIEWER_LOCATION_WIDGET));
   120 			mDocLoader->findWidget(AGENDA_EVENT_VIEWER_LOCATION_WIDGET));
   109 	
   121 	
       
   122 	
       
   123 	mMaptileLabel = qobject_cast<HbLabel *> (
       
   124 	                mDocLoader->findWidget(AGENDA_EVENT_VIEWER_MAPTILE_WIDGET));
       
   125 	
       
   126 	
   110 	mReminderWidget = qobject_cast<AgendaEventViewerItem *> (
   127 	mReminderWidget = qobject_cast<AgendaEventViewerItem *> (
   111 			mDocLoader->findWidget(AGENDA_EVENT_VIEWER_REMINDER_WIDGET));
   128 			mDocLoader->findWidget(AGENDA_EVENT_VIEWER_REMINDER_WIDGET));
   112 	
   129 	
   113 	mRepeatWidget = qobject_cast<AgendaEventViewerItem *> (
   130 	mRepeatWidget = qobject_cast<AgendaEventViewerItem *> (
   114 			mDocLoader->findWidget(AGENDA_EVENT_VIEWER_REPEAT_WIDGET));
   131 			mDocLoader->findWidget(AGENDA_EVENT_VIEWER_REPEAT_WIDGET));
   119     HbWidget *scrollAreaWidget = qobject_cast<HbWidget *>(
   136     HbWidget *scrollAreaWidget = qobject_cast<HbWidget *>(
   120                mDocLoader->findWidget(AGENDA_EVENT_VIEWER_SCROLLAREA_CONTENTS));
   137                mDocLoader->findWidget(AGENDA_EVENT_VIEWER_SCROLLAREA_CONTENTS));
   121 
   138 
   122     mLinearLayout = 
   139     mLinearLayout = 
   123     		static_cast<QGraphicsLinearLayout *> (scrollAreaWidget->layout());
   140     		static_cast<QGraphicsLinearLayout *> (scrollAreaWidget->layout());
   124 
   141 	
   125 	qDebug() << "AgendaEventViewer: AgendaEventView::AgendaEventView <--";
   142     MapTileService::AppType appType;
       
   143     appType = MapTileService::AppTypeCalendar;
       
   144     mLocationFeatureEnabled = MapTileService::isLocationFeatureEnabled(appType);
       
   145     
       
   146         
       
   147     qDebug() << "AgendaEventViewer: AgendaEventView::AgendaEventView <--";
   126 	
   148 	
   127 }
   149 }
   128 
   150 
   129 /*!
   151 /*!
   130 	Destructor.
   152 	Destructor.
   230 	// Add agenda entry specific fields to the viewer
   252 	// Add agenda entry specific fields to the viewer
   231 	switch (mAgendaEntry.type()) {
   253 	switch (mAgendaEntry.type()) {
   232 		case AgendaEntry::TypeAppoinment:
   254 		case AgendaEntry::TypeAppoinment:
   233 		case AgendaEntry::TypeEvent:
   255 		case AgendaEntry::TypeEvent:
   234 			addLocationData();
   256 			addLocationData();
       
   257 			addMapTileImage();	
   235 			addReminderData();
   258 			addReminderData();
   236 			addRepeatData();
   259 			addRepeatData();
   237 			break;
   260 			break;
   238 		case AgendaEntry::TypeAnniversary:
   261 		case AgendaEntry::TypeAnniversary:
   239 			break;
   262 			break;
   292 
   315 
   293 	// Load all the actions for event viewer
   316 	// Load all the actions for event viewer
   294 	
   317 	
   295 	if ((action == AgendaEventViewer::ActionEditDelete) || (action
   318 	if ((action == AgendaEventViewer::ActionEditDelete) || (action
   296 	        == AgendaEventViewer::ActionEdit)) {
   319 	        == AgendaEventViewer::ActionEdit)) {
   297 		HbAction *editAction = new HbAction(HbIcon("qtg_mono_edit"), 
   320 		HbAction *editAction = new HbAction();
   298 		                                  hbTrId("txt_calendar_button_edit"));
   321 		editAction->setIcon(HbIcon("qtg_mono_edit"));
   299 		connect(editAction, SIGNAL(triggered()), this, SLOT(edit()));
   322 		connect(editAction, SIGNAL(triggered()), this, SLOT(edit()));
   300 		toolBar->addAction(editAction);
   323 		toolBar->addAction(editAction);
   301 	}
   324 	}
   302 
   325 
   303 	if ((action == AgendaEventViewer::ActionEditDelete) || (action
   326 	if ((action == AgendaEventViewer::ActionEditDelete) || (action
   304 	        == AgendaEventViewer::ActionDelete)) {
   327 	        == AgendaEventViewer::ActionDelete)) {
   305 		HbAction *deleteAction = new HbAction(HbIcon("qtg_mono_delete"), 
   328 		HbAction *deleteAction = new HbAction();
   306 		                                  hbTrId("txt_calendar_button_delete"));
   329 		deleteAction->setIcon(HbIcon("qtg_mono_delete"));
   307 		connect(deleteAction, SIGNAL(triggered()), this,
   330 		connect(deleteAction, SIGNAL(triggered()), this,
   308 		        SLOT(deleteAgendaEntry()));
   331 		        SLOT(deleteAgendaEntry()));
   309 		toolBar->addAction(deleteAction);
   332 		toolBar->addAction(deleteAction);
   310 	}
   333 	}
   311 
   334 
   312 	if (action == AgendaEventViewer::ActionSave) {
   335 	if (action == AgendaEventViewer::ActionSave) {
   313 		HbAction *saveAction = new HbAction(
   336 		HbAction *saveAction = new HbAction();
   314 							hbTrId("txt_calendar_button_save_to_calendar"));
   337 		saveAction->setIcon(HbIcon("qtg_mono_add_to_calendar"));
   315 		connect(saveAction, SIGNAL(triggered()), this, SLOT(saveAgendaEntry()));
   338 		connect(saveAction, SIGNAL(triggered()), this, SLOT(saveAgendaEntry()));
   316 		toolBar->addAction(saveAction);
   339 		toolBar->addAction(saveAction);
   317 	}
   340 	}
   318 
   341 
   319 	qDebug() << "AgendaEventViewer: AgendaEventView::addToolBarItem <--";
   342 	qDebug() << "AgendaEventViewer: AgendaEventView::addToolBarItem <--";
   477 	mLocationWidget->setEventViewerItemData(itemData, Qt::DisplayRole);
   500 	mLocationWidget->setEventViewerItemData(itemData, Qt::DisplayRole);
   478 	qDebug() << "AgendaEventViewer: AgendaEventView::addLocationData <--";
   501 	qDebug() << "AgendaEventViewer: AgendaEventView::addLocationData <--";
   479 }
   502 }
   480 
   503 
   481 /*!
   504 /*!
       
   505     Add maptile image to Event viewer
       
   506  */
       
   507 void AgendaEventView::addMapTileImage()
       
   508 {
       
   509 
       
   510     qDebug() << "AgendaEventViewer: AgendaEventView::addMapTileImage -->";
       
   511     
       
   512     if (!mAgendaEntry.location().isEmpty() && mLocationFeatureEnabled){
       
   513         MapTileService::AddressType addressType;
       
   514         addressType = MapTileService::AddressPlain;
       
   515         int eventId = mAgendaEntry.id();
       
   516         mMaptilePath = MapTileService::getMapTileImage(eventId, addressType);
       
   517         if (!mMaptilePath.isNull())
       
   518         {                        
       
   519             QIcon mapTileIcon(mMaptilePath);
       
   520             QPainter painter;
       
   521             QPixmap baloon(HbIcon("qtg_small_location.svg").pixmap());
       
   522             QPixmap map (mapTileIcon.pixmap(width,height));
       
   523             //Display pin image in the center of maptile image
       
   524             painter.begin( &map );
       
   525             painter.drawPixmap( (width/2)-(baloon.width()/2), 
       
   526                           (height/2)-baloon.height(), baloon );
       
   527             painter.end();
       
   528             mapTileIcon.addPixmap( map );          
       
   529             
       
   530             HbIcon maptile(mapTileIcon);
       
   531             mMaptileLabel->setIcon(maptile);        
       
   532 
       
   533             mMaptileLabel->setPreferredSize(QSizeF(width, height));
       
   534             mMaptileLabel->setMinimumSize(QSizeF(width, height));
       
   535             mMaptileLabel->setMaximumSize(QSizeF(width, height));
       
   536             mMaptileLabel->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,
       
   537                     QSizePolicy::Fixed));            
       
   538 
       
   539         }
       
   540     }
       
   541 
       
   542     qDebug() << "AgendaEventViewer: AgendaEventView::addMapTileImage <--";
       
   543 }
       
   544 /*!
   482 	Add reminder data to Event viewer
   545 	Add reminder data to Event viewer
   483  */
   546  */
   484 void AgendaEventView::addReminderData()
   547 void AgendaEventView::addReminderData()
   485 {
   548 {
   486 	qDebug() << "AgendaEventViewer: AgendaEventView::addReminderData -->";
   549 	qDebug() << "AgendaEventViewer: AgendaEventView::addReminderData -->";
   576 QString AgendaEventView::repeatRule() const
   639 QString AgendaEventView::repeatRule() const
   577 {
   640 {
   578 	qDebug() << "AgendaEventViewer: AgendaEventView::repeatRule -->";
   641 	qDebug() << "AgendaEventViewer: AgendaEventView::repeatRule -->";
   579 	
   642 	
   580 	QString repeatRule;
   643 	QString repeatRule;
   581 	if (mAgendaEntry.repeatRule().type() != AgendaRepeatRule::InvalidRule)
   644 	AgendaRepeatRule agendaRepeatRule = mAgendaEntry.repeatRule();
       
   645 	if (agendaRepeatRule.type() != AgendaRepeatRule::InvalidRule)
   582 	{
   646 	{
   583 		switch (mAgendaEntry.repeatRule().type()) {
   647 		switch (agendaRepeatRule.type()) {
   584 			case AgendaRepeatRule::DailyRule:
   648 			case AgendaRepeatRule::DailyRule:
   585 				repeatRule.append(hbTrId("txt_calendar_dblist_repeats_daily"));
   649 				repeatRule.append(hbTrId("txt_calendar_dblist_repeats_daily"));
   586 			break;
   650 			break;
   587 			case AgendaRepeatRule::WeeklyRule:
   651 			case AgendaRepeatRule::WeeklyRule:
   588 				if (mAgendaEntry.repeatRule().interval() == 2) {
   652 				if (AgendaUtil::isWorkdaysRepeatingEntry(agendaRepeatRule)) {
   589 					repeatRule.append(
   653 					//TODO: Add text id for workdays
       
   654 					repeatRule.append(hbTrId("Workdays"));
       
   655 				} else {
       
   656 					if (agendaRepeatRule.interval() == 2) {
       
   657 						repeatRule.append(
   590 							hbTrId("txt_calendar_dblist_repeats_fortnightly"));
   658 							hbTrId("txt_calendar_dblist_repeats_fortnightly"));
   591 				} else {
   659 					} else {
   592 					repeatRule.append(
   660 						repeatRule.append(
   593 							hbTrId("txt_calendar_dblist_repeats_weekly"));
   661 							hbTrId("txt_calendar_dblist_repeats_weekly"));
       
   662 					}
   594 				}
   663 				}
   595 			break;
   664 			break;
   596 			case AgendaRepeatRule::MonthlyRule:
   665 			case AgendaRepeatRule::MonthlyRule:
   597 				repeatRule.append(
   666 				repeatRule.append(
   598 						hbTrId("txt_calendar_dblist_repeats_monthly"));
   667 						hbTrId("txt_calendar_dblist_repeats_monthly"));
   605 			break;
   674 			break;
   606 		}
   675 		}
   607 		repeatRule.append(CHARACTER_NEW_LINE);
   676 		repeatRule.append(CHARACTER_NEW_LINE);
   608 		HbExtendedLocale systemLocale = HbExtendedLocale::system();
   677 		HbExtendedLocale systemLocale = HbExtendedLocale::system();
   609 		QString untilDateString = systemLocale.format(
   678 		QString untilDateString = systemLocale.format(
   610 				mAgendaEntry.repeatRule().until(), r_qtn_date_usual_with_zero);
   679 				mAgendaEntry.repeatRule().until().date(), 
       
   680 				r_qtn_date_usual_with_zero);
   611 		repeatRule.append(
   681 		repeatRule.append(
   612 			hbTrId("txt_calendar_dblist_repeats_daily_val_until_1").
   682 			hbTrId("txt_calendar_dblist_repeats_daily_val_until_1").
   613 			arg(untilDateString));
   683 			arg(untilDateString));
   614 	}
   684 	}
   615 	qDebug() << "AgendaEventViewer: AgendaEventView::repeatRule <--";
   685 	qDebug() << "AgendaEventViewer: AgendaEventView::repeatRule <--";
   663 	if (mAgendaEntry.location().isEmpty()) { 
   733 	if (mAgendaEntry.location().isEmpty()) { 
   664 		mLocationWidget->hide();
   734 		mLocationWidget->hide();
   665 		mLinearLayout->removeItem(mLocationWidget);
   735 		mLinearLayout->removeItem(mLocationWidget);
   666 	}
   736 	}
   667 	
   737 	
       
   738 	QFile file(mMaptilePath);
       
   739     if ( !mLocationFeatureEnabled || !file.exists()
       
   740             || mAgendaEntry.location().isEmpty()){        
       
   741         //code added to hide and remove maptile image   
       
   742         mMaptileLabel->hide();
       
   743         mLinearLayout->removeItem(mMaptileLabel);
       
   744     }
       
   745         
   668 	if (mAgendaEntry.alarm().isNull()) { 
   746 	if (mAgendaEntry.alarm().isNull()) { 
   669 		if (mAgendaEntry.type() == AgendaEntry::TypeTodo ) {
   747 		if (mAgendaEntry.type() == AgendaEntry::TypeTodo ) {
   670 				if (AgendaEntry::TodoNeedsAction == mAgendaEntry.status()) { 
   748 				if (AgendaEntry::TodoNeedsAction == mAgendaEntry.status()) { 
   671 					mReminderWidget->hide();
   749 					mReminderWidget->hide();
   672 					mLinearLayout->removeItem(mReminderWidget);
   750 					mLinearLayout->removeItem(mReminderWidget);
   758 {
   836 {
   759 	qDebug() << "AgendaEventViewer: AgendaEventView::addAllWidgets -->";
   837 	qDebug() << "AgendaEventViewer: AgendaEventView::addAllWidgets -->";
   760 	
   838 	
   761 	mLinearLayout->addItem(mLocationWidget);
   839 	mLinearLayout->addItem(mLocationWidget);
   762 	mLocationWidget->show();
   840 	mLocationWidget->show();
       
   841 	mLinearLayout->addItem(mMaptileLabel);
       
   842 	mMaptileLabel->show();		
   763 	mLinearLayout->addItem(mReminderWidget);
   843 	mLinearLayout->addItem(mReminderWidget);
   764 	mReminderWidget->show();
   844 	mReminderWidget->show();
   765 	mLinearLayout->addItem(mRepeatWidget);
   845 	mLinearLayout->addItem(mRepeatWidget);
   766 	mRepeatWidget->show();
   846 	mRepeatWidget->show();
   767 	mLinearLayout->addItem(mDescriptionWidget);
   847 	mLinearLayout->addItem(mDescriptionWidget);
   930 		
  1010 		
   931 
  1011 
   932 	} else {
  1012 	} else {
   933 		// Launch the calendar entry editor using calendar editor api
  1013 		// Launch the calendar entry editor using calendar editor api
   934 		mCalenEditor = new CalenEditor(mOwner->mAgendaUtil, this);
  1014 		mCalenEditor = new CalenEditor(mOwner->mAgendaUtil, this);
       
  1015 		connect(mCalenEditor, SIGNAL(dialogClosed()),
       
  1016 		                        this, SLOT(handleCalendarEditorClosed()));
   935 		mCalenEditor->edit(mAgendaEntry, false);
  1017 		mCalenEditor->edit(mAgendaEntry, false);
   936 		connect(mCalenEditor, SIGNAL(dialogClosed()),
  1018 	
   937 						this, SLOT(handleCalendarEditorClosed()));
       
   938 		
  1019 		
   939 	}
  1020 	}
   940 	qDebug() << "AgendaEventViewer: AgendaEventView::edit <--";
  1021 	qDebug() << "AgendaEventViewer: AgendaEventView::edit <--";
   941 }
  1022 }
   942 
  1023 
   999 	disconnect(
  1080 	disconnect(
  1000 			mBackAction, SIGNAL(triggered()),
  1081 			mBackAction, SIGNAL(triggered()),
  1001 			this, SLOT(close()));
  1082 			this, SLOT(close()));
  1002 
  1083 
  1003 	window->removeView(mViewer);
  1084 	window->removeView(mViewer);
  1004 	mOwner->viewingCompleted();
  1085 	mOwner->viewingCompleted(mAgendaEntry.startTime().date());
  1005 
  1086 
  1006 	qDebug() << "AgendaEventViewer: AgendaEventView::close <--";
  1087 	qDebug() << "AgendaEventViewer: AgendaEventView::close <--";
  1007 }
  1088 }
  1008 
  1089 
  1009 /*!
  1090 /*!
  1024 		        != AgendaEntry::TypeTodo) {
  1105 		        != AgendaEntry::TypeTodo) {
  1025 			// if start date of original entry is between start date of updated 
  1106 			// if start date of original entry is between start date of updated 
  1026 			// entry and until date of updated entry then only update time.
  1107 			// entry and until date of updated entry then only update time.
  1027 			if (mOriginalAgendaEntry.startTime().date()
  1108 			if (mOriginalAgendaEntry.startTime().date()
  1028 			        >= updatedEntry.startTime().date()
  1109 			        >= updatedEntry.startTime().date()
  1029 			        || mOriginalAgendaEntry.startTime().date()
  1110 			        && mOriginalAgendaEntry.startTime().date()
  1030 			                <= updatedEntry.repeatRule().until()) {
  1111 			                <= updatedEntry.repeatRule().until().date()) {
  1031 				QDateTime
  1112 				QDateTime
  1032 				        startDateTime(mOriginalAgendaEntry.startTime().date(),
  1113 				        startDateTime(mOriginalAgendaEntry.startTime().date(),
  1033 				                      updatedEntry.startTime().time());
  1114 				                      updatedEntry.startTime().time());
  1034 				QDateTime endDateTime(mOriginalAgendaEntry.endTime().date(),
  1115 				QDateTime endDateTime(mOriginalAgendaEntry.endTime().date(),
  1035 				                      updatedEntry.endTime().time());
  1116 				                      updatedEntry.endTime().time());