calendarui/views/src/calendayviewwidget.cpp
changeset 49 5de72ea7a065
parent 32 ea672fcb0ea0
equal deleted inserted replaced
37:360d55486d7f 49:5de72ea7a065
    16 */
    16 */
    17 
    17 
    18 // System includes
    18 // System includes
    19 #include <QStandardItemModel>
    19 #include <QStandardItemModel>
    20 #include <QGraphicsSceneEvent>
    20 #include <QGraphicsSceneEvent>
       
    21 #include <QDir>
       
    22 #include <QPluginLoader>
    21 #include <hbi18ndef.h>
    23 #include <hbi18ndef.h>
    22 #include <hbextendedlocale.h>
    24 #include <hbextendedlocale.h>
    23 #include <hbgroupbox.h>
    25 #include <hbgroupbox.h>
    24 #include <hbmenu.h>
    26 #include <hbmenu.h>
    25 #include <hbaction.h>
    27 #include <hbaction.h>
    27 #include <hbstyleloader.h>
    29 #include <hbstyleloader.h>
    28 #include <hbdatetimepicker.h>
    30 #include <hbdatetimepicker.h>
    29 #include <hbdialog.h>
    31 #include <hbdialog.h>
    30 #include <xqsettingsmanager.h>
    32 #include <xqsettingsmanager.h>
    31 #include <agendautil.h>
    33 #include <agendautil.h>
    32 #include <noteseditor.h>
    34 #include <NotesEditorInterface>
    33 
    35 
    34 // User includes
    36 // User includes
    35 #include "calendayviewwidget.h"
    37 #include "calendayviewwidget.h"
    36 #include "calencommon.h"
    38 #include "calencommon.h"
    37 #include "calendayview.h"
    39 #include "calendayview.h"
    66 EXPORT_C CalenDayViewWidget::CalenDayViewWidget(MCalenServices &services,
    68 EXPORT_C CalenDayViewWidget::CalenDayViewWidget(MCalenServices &services,
    67                                        CalenDocLoader *docLoader) :
    69                                        CalenDocLoader *docLoader) :
    68 mServices(services),
    70 mServices(services),
    69 mDocLoader(docLoader),
    71 mDocLoader(docLoader),
    70 mRegionalInfoGroupBox(NULL),
    72 mRegionalInfoGroupBox(NULL),
    71 mLongTapEventFlag(false)
    73 mLongTapEventFlag(false),
       
    74 mNotesPluginLoaded(false)
    72 {
    75 {
    73     // Construct the list view prototype
    76     // Construct the list view prototype
    74     mListViewPrototype = new CalenEventListViewItem(this);
    77     mListViewPrototype = new CalenEventListViewItem(this);
    75     
    78     
    76     // Create the list model
    79     // Create the list model
    88 // Rest of the details are commented in the header
    91 // Rest of the details are commented in the header
    89 // ----------------------------------------------------------------------------
    92 // ----------------------------------------------------------------------------
    90 //    
    93 //    
    91 EXPORT_C CalenDayViewWidget::~CalenDayViewWidget()
    94 EXPORT_C CalenDayViewWidget::~CalenDayViewWidget()
    92 {
    95 {
       
    96 	// Unload notes editor if loaded.
       
    97 	if (mNotesEditorPluginLoader) {
       
    98 		mNotesEditorPluginLoader->unload();
       
    99 		delete mNotesEditorPluginLoader;
       
   100 		mNotesEditorPluginLoader = 0;
       
   101 	}
       
   102 
    93     if (mListViewPrototype) {
   103     if (mListViewPrototype) {
    94         delete mListViewPrototype;
   104         delete mListViewPrototype;
    95         mListViewPrototype = NULL;
   105         mListViewPrototype = NULL;
    96     }
   106     }
    97     if (mListModel) {
   107     if (mListModel) {
   507 
   517 
   508     if (eventStartTime < eventEndTime) {
   518     if (eventStartTime < eventEndTime) {
   509         // Raise the flag to indicate that the list item
   519         // Raise the flag to indicate that the list item
   510         // would wrap to two lines
   520         // would wrap to two lines
   511         twoLines = true;
   521         twoLines = true;
   512         // Append space
       
   513         eventTime.append(" ");
       
   514         // Append '-' to indicate an end time is present
   522         // Append '-' to indicate an end time is present
   515         eventTime.append("-");
   523         eventTime.append("-");
   516     } else {
   524     } else {
   517     	// To align the subject properly if the start and endtime are same
   525     	// To align the subject properly if the start and endtime are same
   518     	eventTime.append("  ");
   526     	eventTime.append("  ");
   563         textData << entry.location();
   571         textData << entry.location();
   564     }
   572     }
   565     // Add the end time to the list item	
   573     // Add the end time to the list item	
   566     if (eventStartTime < eventEndTime) {
   574     if (eventStartTime < eventEndTime) {
   567     	QString endtime = locale.format(eventEndTime, r_qtn_time_usual_with_zero);
   575     	QString endtime = locale.format(eventEndTime, r_qtn_time_usual_with_zero);
       
   576     	endtime.append(" ");
   568     	textData << endtime;
   577     	textData << endtime;
   569     }else {
   578     }else {
   570     	if (entry.location().isEmpty()) {
   579     	textData<<QString("              ");
   571     		textData << QVariant();
       
   572     	}else {
       
   573     		textData << singleSpace;
       
   574     	}
       
   575     }
   580     }
   576     // Get the list model index and set the text and icon data
   581     // Get the list model index and set the text and icon data
   577     QModelIndex listIndex = mListModel->index(index, 0);
   582     QModelIndex listIndex = mListModel->index(index, 0);
   578     mListModel->setData(listIndex, textData, Qt::DisplayRole);
   583     mListModel->setData(listIndex, textData, Qt::DisplayRole);
   579     mListModel->setData(listIndex, iconData, Qt::DecorationRole);
   584     mListModel->setData(listIndex, iconData, Qt::DecorationRole);
   825 // To Show and hide regional plugin label depends upon settings
   830 // To Show and hide regional plugin label depends upon settings
   826 // ----------------------------------------------------------------------------
   831 // ----------------------------------------------------------------------------
   827 //
   832 //
   828 void CalenDayViewWidget::showHideRegionalInformation()
   833 void CalenDayViewWidget::showHideRegionalInformation()
   829 {
   834 {
   830     XQSettingsKey regionalInfo(XQSettingsKey::TargetCentralRepository,
   835 	if (mView->pluginEnabled()) {
   831                                KCRUidCalendar, KCalendarShowRegionalInfo);
   836 		XQSettingsKey regionalInfo(XQSettingsKey::TargetCentralRepository,
   832     
   837 		                           KCRUidCalendar, KCalendarShowRegionalInfo);
   833     int showRegionalInfo = mSettingsManager->readItemValue(regionalInfo).toUInt();
   838 
   834     if (showRegionalInfo) {
   839 		int showRegionalInfo = 
   835 		
   840 						mSettingsManager->readItemValue(regionalInfo).toUInt();
   836         if (!mRegionalInfoGroupBox) {
   841 		if (showRegionalInfo) {
   837         	mRegionalInfoGroupBox = new HbGroupBox();
   842 
   838         	CalenPluginLabel *regionalInfo = new CalenPluginLabel(
   843 			if (!mRegionalInfoGroupBox) {
   839 															mServices, this);
   844 				mRegionalInfoGroupBox = new HbGroupBox();
   840             regionalInfo->setFontSpec(HbFontSpec(HbFontSpec::Primary));
   845 				CalenPluginLabel *regionalInfo = new CalenPluginLabel(
   841             mRegionalInfoGroupBox->setContentWidget(regionalInfo);
   846 						mServices, this);
   842             mRegionalPluginLayout->insertItem(1, mRegionalInfoGroupBox);
   847 				regionalInfo->setFontSpec(HbFontSpec(HbFontSpec::Primary));
   843         }
   848 				mRegionalInfoGroupBox->setContentWidget(regionalInfo);
   844         
   849 				mRegionalPluginLayout->insertItem(1, mRegionalInfoGroupBox);
   845         if (mView->pluginEnabled()) {
   850 			}
   846 			QString *pluginString = mView->pluginText();
   851 			QString *pluginString = mView->pluginText();
   847 			HbLabel *pluginInfoLabel = qobject_cast <HbLabel *> 
   852 			HbLabel *pluginInfoLabel = qobject_cast <HbLabel *> 
   848 									(mRegionalInfoGroupBox->contentWidget());
   853 									(mRegionalInfoGroupBox->contentWidget());
   849 			pluginInfoLabel->setPlainText(*pluginString);
   854 			pluginInfoLabel->setPlainText(*pluginString);
   850 		}
   855 		}
   878 {
   883 {
   879     // Check if the selected index is valid
   884     // Check if the selected index is valid
   880     if (mSelectedIndex < 0 || mSelectedIndex > mInstanceArray.count()) {
   885     if (mSelectedIndex < 0 || mSelectedIndex > mInstanceArray.count()) {
   881         return;
   886         return;
   882     }
   887     }
   883     
   888 
   884     // Get the entry details first
   889 	// Get the entry details first
   885     AgendaEntry entry = mInstanceArray[mSelectedIndex];
   890 	AgendaEntry entry = mInstanceArray[mSelectedIndex];
   886     if (AgendaEntry::TypeTodo == entry.type()) {
   891 	if (AgendaEntry::TypeTodo == entry.type()) {
   887         // Launch the to-do editor
   892 		// Load the notes editor plugin if not loaded.
   888         mNotesEditor = new NotesEditor(mView);
   893 		if (!mNotesPluginLoaded) {
   889         mNotesEditor->edit(entry);
   894 			// Launch the to-do editor using notes editor plugin api
   890         connect(mNotesEditor, SIGNAL(editingCompleted(bool)), this, SLOT(noteEditingCompleted(bool)));
   895 			QDir dir(NOTES_EDITOR_PLUGIN_PATH);
   891     } else {
   896 			QString pluginName = dir.absoluteFilePath(NOTES_EDITOR_PLUGIN_NAME);
   892         // Set the context
   897 
   893         setContextFromHighlight(entry);
   898 			// Create NotesEditor plugin loader object.
   894         // Issue a command to launch the editor to edit this entry
   899 			mNotesEditorPluginLoader = new QPluginLoader(pluginName);
   895         mServices.IssueCommandL(ECalenEditCurrentEntry);
   900 
   896     }
   901 			// Load the plugin
       
   902 			mNotesPluginLoaded = mNotesEditorPluginLoader->load();
       
   903 		}
       
   904 
       
   905 		QObject *plugin = qobject_cast<QObject*> (
       
   906 				mNotesEditorPluginLoader->instance());
       
   907 
       
   908 		NotesEditorInterface* interface =
       
   909 				qobject_cast<NotesEditorInterface*>(plugin);
       
   910 
       
   911 		interface->edit(entry, mServices.agendaInterface());
       
   912 
       
   913 		connect(
       
   914 				interface, SIGNAL(editingCompleted(bool)),
       
   915 				this, SLOT(noteEditingCompleted(bool)));
       
   916 	} else {
       
   917 		// Set the context
       
   918 		setContextFromHighlight(entry);
       
   919 		// Issue a command to launch the editor to edit this entry
       
   920 		mServices.IssueCommandL(ECalenEditCurrentEntry);
       
   921 	}
   897 }
   922 }
   898 
   923 
   899 // ----------------------------------------------------------------------------
   924 // ----------------------------------------------------------------------------
   900 // CalenDayViewWidget::viewEntry
   925 // CalenDayViewWidget::viewEntry
   901 // Rest of the details are commented in the header
   926 // Rest of the details are commented in the header
  1040 // Rest of the details are commented in the header
  1065 // Rest of the details are commented in the header
  1041 // ----------------------------------------------------------------------------
  1066 // ----------------------------------------------------------------------------
  1042 // 
  1067 // 
  1043 void CalenDayViewWidget::noteEditingCompleted(bool status)
  1068 void CalenDayViewWidget::noteEditingCompleted(bool status)
  1044 {
  1069 {
  1045     Q_UNUSED(status);
  1070 	// We need to refresh the list since user
  1046     // Delete the notes editor instance
  1071 	// might have marked the to-do as complete or
  1047     mNotesEditor->deleteLater();
  1072 	// edited it or deleted it. So get the instance
  1048     
  1073 	// list again
  1049     // We need to refresh the list since user
  1074 	if (status) {
  1050     // might have marked the to-do as complete or
  1075 		mServices.IssueCommandL(ECalenStartActiveStep);
  1051     // edited it or deleted it. So get the instance
  1076 	}
  1052     // list again
       
  1053     if (status) {
       
  1054         mServices.IssueCommandL(ECalenStartActiveStep);
       
  1055     }
       
  1056 }
  1077 }
  1057 
  1078 
  1058 // ----------------------------------------------------------------------------
  1079 // ----------------------------------------------------------------------------
  1059 // CalenDayViewWidget::goToToday
  1080 // CalenDayViewWidget::goToToday
  1060 // Rest of the details are commented in the header
  1081 // Rest of the details are commented in the header