notes/notesui/notesviews/src/notestodoview.cpp
changeset 45 b6db4fd4947b
parent 23 fd30d51f876b
child 55 2c54b51f39c4
--- a/notes/notesui/notesviews/src/notestodoview.cpp	Mon May 03 12:30:32 2010 +0300
+++ b/notes/notesui/notesviews/src/notestodoview.cpp	Mon Jun 28 15:22:02 2010 +0530
@@ -57,7 +57,8 @@
 NotesTodoView::NotesTodoView(QGraphicsWidget *parent)
 :HbView(parent),
  mSelectedItem(0),
- mDeleteAction(0)
+ mDeleteAction(0),
+ mIsLongTop(false)
 {
 	// Nothing yet.
 }
@@ -114,7 +115,11 @@
 			SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)),
 			this,
 			SLOT(handleItemLongPressed(HbAbstractViewItem *, const QPointF &)));
-
+	
+	// Get the empty list string.
+	mEmptyListLabel = static_cast<HbLabel *> (
+			mDocLoader->findWidget("emptyListLabel"));
+	
 	// Get the toolbar/menu actions.
 	mAddTodoAction = static_cast<HbAction *> (
 			mDocLoader->findObject("newTodoAction"));
@@ -130,8 +135,7 @@
 
 	mViewCollectionAction = static_cast<HbAction *> (
 			mDocLoader->findObject("displayCollectionsAction"));
-	mViewCollectionAction->setCheckable(true);
-	mViewCollectionAction->setChecked(true);
+	
 	connect(
 			mViewCollectionAction, SIGNAL(changed()),
 			this, SLOT(handleActionStateChanged()));
@@ -149,9 +153,6 @@
 	mSubTitle = static_cast<HbGroupBox *>(
 			mDocLoader->findWidget("subtitleGroupBox"));
 
-	// Update sub heading text for to-do collections view.
-	updateSubTitle();
-
 	connect(
 			mAgendaUtil, SIGNAL(entryAdded(ulong)),
 			this,SLOT(updateSubTitle(ulong)));
@@ -167,6 +168,14 @@
 	prototype->setGraphicsSize(HbListViewItem::SmallIcon);
 }
 
+/*
+	Updates the title text for the first launch
+ */
+void NotesTodoView::updateTitle()
+{
+	updateSubTitle();
+}
+
 /*!
 	Opens the to-do editor to create a new to-do.
  */
@@ -190,28 +199,30 @@
  */
 void NotesTodoView::handleItemReleased(const QModelIndex &index)
 {
-	// Sanity check.
-	if (!index.isValid()) {
-		return;
-	}
+	if(!mIsLongTop) {
+		// Sanity check.
+		if (!index.isValid()) {
+			return;
+		}
 
-	// First get the id of the to-do and get the corresponding information from
-	// agendautil.
-	ulong toDoId = index.data(NotesNamespace::IdRole).value<qulonglong>();
+		// First get the id of the to-do and get the corresponding information from
+		// agendautil.
+		ulong toDoId = index.data(NotesNamespace::IdRole).value<qulonglong>();
 
-	if (0 >= toDoId) {
-		// Something wrong.
-		return;
-	}
+		if (0 >= toDoId) {
+			// Something wrong.
+			return;
+		}
 
-	// Construct agenda event viewer.
-	mAgendaEventViewer = new AgendaEventViewer(mAgendaUtil, this);
+		// Construct agenda event viewer.
+		mAgendaEventViewer = new AgendaEventViewer(mAgendaUtil, this);
 
-	connect(
-			mAgendaEventViewer, SIGNAL(viewingCompleted(const QDate)),
-			this, SLOT(handleViewingCompleted()));
-	// Launch agenda event viewer
-	mAgendaEventViewer->view(toDoId, AgendaEventViewer::ActionEditDelete);
+		connect(
+				mAgendaEventViewer, SIGNAL(viewingCompleted(const QDate)),
+				this, SLOT(handleViewingCompleted()));
+		// Launch agenda event viewer
+		mAgendaEventViewer->view(toDoId, AgendaEventViewer::ActionEditDelete);
+	}
 }
 
 /*!
@@ -226,6 +237,7 @@
 		HbAbstractViewItem *item, const QPointF &coords)
 {
 	mSelectedItem = item;
+	mIsLongTop = true;
 
 	// Get the entry of the selected item.
 	ulong noteId = item->modelIndex().data(
@@ -234,46 +246,34 @@
 
 	// Display a context specific menu.
 	HbMenu *contextMenu = new HbMenu();
+	connect(
+			contextMenu,SIGNAL(aboutToClose()),
+			this, SLOT(handleMenuClosed()));
 
 	// Add actions to the context menu.
 	mOpenAction =
 			contextMenu->addAction(hbTrId("txt_common_menu_open"));
-	connect(
-			mOpenAction, SIGNAL(triggered()),
-			this, SLOT(openTodo()));
 
 	mEditAction = contextMenu->addAction(
 			hbTrId("txt_common_menu_edit"));
-	connect(
-			mEditAction, SIGNAL(triggered()),
-			this, SLOT(editTodo()));
 
 	mDeleteAction = contextMenu->addAction(
 			hbTrId("txt_common_menu_delete"));
-	connect(
-			mDeleteAction, SIGNAL(triggered()),
-			this, SLOT(deleteTodo()));
 
 	if (AgendaEntry::TypeTodo == entry.type()) {
 		if (AgendaEntry::TodoNeedsAction == entry.status()) {
 			mTodoStatusAction = contextMenu->addAction(
 					hbTrId("txt_notes_menu_mark_as_done"));
-			connect(
-					mTodoStatusAction , SIGNAL(triggered()),
-					this, SLOT(markTodoStatus()));
-
 		} else if (AgendaEntry::TodoCompleted == entry.status()) {
 			mTodoStatusAction =
 					contextMenu->addAction(
 							hbTrId("txt_notes_menu_mark_as_not_done"));
-			connect(
-					mTodoStatusAction , SIGNAL(triggered()),
-					this, SLOT(markTodoStatus()));
 		}
 	}
 
 	// Show the menu.
-	contextMenu->exec(coords);
+	contextMenu->open(this, SLOT(selectedMenuAction(HbAction*)));
+	contextMenu->setPreferredPos(coords);
 }
 
 /*!
@@ -442,6 +442,14 @@
 		AgendaUtil::IncludeIncompletedTodos);
 	mSubTitle->setHeading(
 			hbTrId("txt_notes_subhead_todos_ln_pending",entries.count()));
+	
+	if (0 >= entries.count()) {
+		mEmptyListLabel->show();
+		mListView->hide();
+	} else {
+		mEmptyListLabel->hide();
+		mListView->show();
+	}
 }
 
 /*
@@ -465,4 +473,28 @@
 			entry, AgendaEventViewer::ActionEditDelete);
 }
 
+/*
+	Slot to handle the context menu actions.
+ */
+void NotesTodoView::selectedMenuAction(HbAction *action)
+{
+	if (action == mOpenAction) {
+		openTodo();
+	} else if (action == mEditAction) {
+		editTodo();
+	} else if (action == mDeleteAction) {
+		deleteTodo();
+	} else if (action == mTodoStatusAction) {
+		markTodoStatus();
+	}
+}
+
+
+/*!
+	Slot to handle the context menu closed.
+ */
+void NotesTodoView::handleMenuClosed()
+{
+	mIsLongTop = false;
+}
 // End of file	--Don't remove this.