notes/notesui/notesviews/src/notesfavoriteview.cpp
changeset 45 b6db4fd4947b
parent 23 fd30d51f876b
child 55 2c54b51f39c4
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
    28 #include <HbDialog>
    28 #include <HbDialog>
    29 #include <HbLabel>
    29 #include <HbLabel>
    30 #include <HbAbstractViewItem>
    30 #include <HbAbstractViewItem>
    31 #include <HbGroupBox>
    31 #include <HbGroupBox>
    32 #include <HbListViewItem>
    32 #include <HbListViewItem>
       
    33 #include <HbNotificationDialog>
    33 
    34 
    34 // User includes
    35 // User includes
    35 #include "notesfavoriteview.h"
    36 #include "notesfavoriteview.h"
    36 #include "notescommon.h"
    37 #include "notescommon.h"
    37 #include "notesdocloader.h"
    38 #include "notesdocloader.h"
    54 	\param parent The parent of type QGraphicsWidget.
    55 	\param parent The parent of type QGraphicsWidget.
    55  */
    56  */
    56 NotesFavoriteView::NotesFavoriteView(QGraphicsWidget *parent)
    57 NotesFavoriteView::NotesFavoriteView(QGraphicsWidget *parent)
    57 :HbView(parent),
    58 :HbView(parent),
    58  mSelectedItem(0),
    59  mSelectedItem(0),
    59  mDeleteAction(0)
    60  mDeleteAction(0),
       
    61  mIsLongTop(false)
    60 {
    62 {
    61 	// Nothing yet.
    63 	// Nothing yet.
    62 }
    64 }
    63 
    65 
    64 /*!
    66 /*!
   114 			mListView,
   116 			mListView,
   115 			SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)),
   117 			SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)),
   116 			this,
   118 			this,
   117 			SLOT(handleItemLongPressed(HbAbstractViewItem *, const QPointF &)));
   119 			SLOT(handleItemLongPressed(HbAbstractViewItem *, const QPointF &)));
   118 
   120 
       
   121 	// Get the empty list label.
       
   122 	mEmptyListLabel = static_cast<HbLabel *> (
       
   123 			mDocLoader->findWidget("emptyListLabel"));
       
   124 	
   119 	// Get the toolbar/menu actions.
   125 	// Get the toolbar/menu actions.
   120 	mAddNoteAction = static_cast<HbAction *> (
   126 	mAddNoteAction = static_cast<HbAction *> (
   121 			mDocLoader->findObject("newNoteAction"));
   127 			mDocLoader->findObject("newNoteAction"));
   122 	connect(
   128 	connect(
   123 			mAddNoteAction, SIGNAL(triggered()),
   129 			mAddNoteAction, SIGNAL(triggered()),
   129 			mAllNotesAction, SIGNAL(triggered()),
   135 			mAllNotesAction, SIGNAL(triggered()),
   130 			this, SLOT(displayAllNotesView()));
   136 			this, SLOT(displayAllNotesView()));
   131 
   137 
   132 	mViewCollectionAction = static_cast<HbAction *> (
   138 	mViewCollectionAction = static_cast<HbAction *> (
   133 			mDocLoader->findObject("displayCollectionsAction"));
   139 			mDocLoader->findObject("displayCollectionsAction"));
   134 	mViewCollectionAction->setCheckable(true);
   140 
   135 	mViewCollectionAction->setChecked(true);
       
   136 	connect(
   141 	connect(
   137 			mViewCollectionAction, SIGNAL(changed()),
   142 			mViewCollectionAction, SIGNAL(changed()),
   138 			this, SLOT(handleActionStateChanged()));
   143 			this, SLOT(handleActionStateChanged()));
   139 	connect(
   144 	connect(
   140 			mViewCollectionAction, SIGNAL(triggered()),
   145 			mViewCollectionAction, SIGNAL(triggered()),
   145 	handleOrientationChanged(window->orientation());
   150 	handleOrientationChanged(window->orientation());
   146 	connect(
   151 	connect(
   147 			window, SIGNAL(orientationChanged(Qt::Orientation)),
   152 			window, SIGNAL(orientationChanged(Qt::Orientation)),
   148 			this, SLOT(handleOrientationChanged(Qt::Orientation)));
   153 			this, SLOT(handleOrientationChanged(Qt::Orientation)));
   149 
   154 
       
   155 	connect(
       
   156 			mAgendaUtil, SIGNAL(entryAdded(ulong)),
       
   157 			this,SLOT(updateView(ulong)));
       
   158 	connect(
       
   159 			mAgendaUtil, SIGNAL(entryDeleted(ulong)),
       
   160 			this,SLOT(updateView(ulong)));
       
   161 	connect(
       
   162 			mAgendaUtil, SIGNAL(entryUpdated(ulong)),
       
   163 			this, SLOT(updateView(ulong)));
       
   164 	
   150 	// Set the graphics size for the icons.
   165 	// Set the graphics size for the icons.
   151 	HbListViewItem *prototype = mListView->listItemPrototype();
   166 	HbListViewItem *prototype = mListView->listItemPrototype();
   152 	prototype->setGraphicsSize(HbListViewItem::SmallIcon);
   167 	prototype->setGraphicsSize(HbListViewItem::SmallIcon);
   153 }
   168 }
   154 
   169 
       
   170 /*
       
   171 	Updates the favorite view either to show notes or emptyListLabel.
       
   172  */
       
   173 void NotesFavoriteView::updateFavoriteView()
       
   174 {
       
   175 	updateView();
       
   176 }
       
   177 
   155 /*!
   178 /*!
   156 	Slot which gets called when `+ New note' action is triggered from the view
   179 	Slot which gets called when `+ New note' action is triggered from the view
   157 	toolbar. This is responsible for launching the editor to create a new note.
   180 	toolbar. This is responsible for launching the editor to create a new note.
   158  */
   181  */
   159 void NotesFavoriteView::createNewNote()
   182 void NotesFavoriteView::createNewNote()
   174 	\param index Reference to the QModelIndex representing the view item.
   197 	\param index Reference to the QModelIndex representing the view item.
   175 	\sa HbAbstractViewItem
   198 	\sa HbAbstractViewItem
   176  */
   199  */
   177 void NotesFavoriteView::handleItemReleased(const QModelIndex &index)
   200 void NotesFavoriteView::handleItemReleased(const QModelIndex &index)
   178 {
   201 {
   179 	// Sanity check.
   202 	if (!mIsLongTop) {
   180 	if (!index.isValid()) {
   203 		// Sanity check.
   181 		return;
   204 		if (!index.isValid()) {
   182 	}
   205 			return;
   183 
   206 		}
   184 	// First get the id of the note and get the corresponding information from
   207 
   185 	// agendautil.
   208 		// First get the id of the note and get the corresponding information from
   186 	ulong noteId = index.data(NotesNamespace::IdRole).value<qulonglong>();
   209 		// agendautil.
   187 
   210 		ulong noteId = index.data(NotesNamespace::IdRole).value<qulonglong>();
   188 	if (0 >= noteId) {
   211 
   189 		// Something wrong.
   212 		if (0 >= noteId) {
   190 		return;
   213 			// Something wrong.
   191 	}
   214 			return;
   192 
   215 		}
   193 	// Get the entry details.
   216 
   194 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   217 		// Get the entry details.
   195 
   218 		AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   196 	if (entry.isNull()) {
   219 
   197 
   220 		if (entry.isNull()) {
   198 		// Entry invalid.
   221 
   199 		return;
   222 			// Entry invalid.
   200 	}
   223 			return;
   201 
   224 		}
   202 	// Now launch the editor with the obtained info.
   225 
   203 	mNotesEditor = new NotesEditor(mAgendaUtil, this);
   226 		// Now launch the editor with the obtained info.
   204 	connect(
   227 		mNotesEditor = new NotesEditor(mAgendaUtil, this);
   205 			mNotesEditor, SIGNAL(editingCompleted(bool)),
   228 		connect(
   206 			this, SLOT(handleEditingCompleted(bool)));
   229 				mNotesEditor, SIGNAL(editingCompleted(bool)),
   207 	mNotesEditor->edit(entry);
   230 				this, SLOT(handleEditingCompleted(bool)));
       
   231 		mNotesEditor->edit(entry);
       
   232 	}
   208 }
   233 }
   209 
   234 
   210 /*!
   235 /*!
   211 	Displays a list item specific context menu.
   236 	Displays a list item specific context menu.
   212 
   237 
   217  */
   242  */
   218 void NotesFavoriteView::handleItemLongPressed(
   243 void NotesFavoriteView::handleItemLongPressed(
   219 		HbAbstractViewItem *item, const QPointF &coords)
   244 		HbAbstractViewItem *item, const QPointF &coords)
   220 {
   245 {
   221 	mSelectedItem = item;
   246 	mSelectedItem = item;
       
   247 	mIsLongTop = true;
   222 
   248 
   223 	// Get the entry of the selected item.
   249 	// Get the entry of the selected item.
   224 	ulong noteId = item->modelIndex().data(
   250 	ulong noteId = item->modelIndex().data(
   225 			NotesNamespace::IdRole).value<qulonglong>();
   251 			NotesNamespace::IdRole).value<qulonglong>();
   226 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   252 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   227 
   253 
   228 	// Display a context specific menu.
   254 	// Display a context specific menu.
   229 	HbMenu *contextMenu = new HbMenu();
   255 	HbMenu *contextMenu = new HbMenu();
       
   256 	connect(
       
   257 			contextMenu,SIGNAL(aboutToClose()),
       
   258 			this, SLOT(handleMenuClosed()));
   230 
   259 
   231 	// Add actions to the context menu.
   260 	// Add actions to the context menu.
   232 	mOpenAction =
   261 	mOpenAction =
   233 			contextMenu->addAction(hbTrId("txt_common_menu_open"));
   262 			contextMenu->addAction(hbTrId("txt_common_menu_open"));
   234 	connect(
       
   235 			mOpenAction, SIGNAL(triggered()),
       
   236 			this, SLOT(openNote()));
       
   237 
   263 
   238 	mDeleteAction =
   264 	mDeleteAction =
   239 			contextMenu->addAction(hbTrId("txt_common_menu_delete"));
   265 			contextMenu->addAction(hbTrId("txt_common_menu_delete"));
   240 	connect(
       
   241 			mDeleteAction, SIGNAL(triggered()),
       
   242 			this, SLOT(deleteNote()));
       
   243 
   266 
   244 	mRemoveFavoriteAction =
   267 	mRemoveFavoriteAction =
   245 			contextMenu->addAction(
   268 			contextMenu->addAction(
   246 					hbTrId("txt_notes_menu_remove_from_favorites"));
   269 					hbTrId("txt_notes_menu_remove_from_favorites"));
   247 
   270 
   248 	connect(
       
   249 			mRemoveFavoriteAction, SIGNAL(triggered()),
       
   250 			this, SLOT(markNoteAsNotFavourite()));
       
   251 
       
   252 	mMarkTodoAction =
   271 	mMarkTodoAction =
   253 			contextMenu->addAction(
   272 			contextMenu->addAction(
   254 					hbTrId("txt_notes_menu_make_it_as_todo_note"));
   273 					hbTrId("txt_notes_menu_make_it_as_todo_note"));
   255 	connect(
       
   256 			mMarkTodoAction, SIGNAL(triggered()),
       
   257 			this, SLOT(markNoteAsTodo()));
       
   258 
   274 
   259 	// Show the menu.
   275 	// Show the menu.
   260 	contextMenu->exec(coords);
   276 	contextMenu->open(this, SLOT(selectedMenuAction(HbAction*)));
       
   277 	contextMenu->setPreferredPos(coords);
   261 }
   278 }
   262 
   279 
   263 /*!
   280 /*!
   264 	Deletes the note.
   281 	Deletes the note.
   265  */
   282  */
   350 	// First clone the todoEntry for the new type.
   367 	// First clone the todoEntry for the new type.
   351 	mAgendaUtil->cloneEntry(entry, AgendaEntry::TypeTodo);
   368 	mAgendaUtil->cloneEntry(entry, AgendaEntry::TypeTodo);
   352 
   369 
   353 	// Delete the old entry.
   370 	// Delete the old entry.
   354 	mAgendaUtil->deleteEntry(entry.id());
   371 	mAgendaUtil->deleteEntry(entry.id());
       
   372 
       
   373 	// Show the soft notification.
       
   374 	HbNotificationDialog *notificationDialog = new HbNotificationDialog();
       
   375 	notificationDialog->setTimeout(
       
   376 			HbNotificationDialog::ConfirmationNoteTimeout);
       
   377 	notificationDialog->setTitle(
       
   378 			hbTrId("txt_notes_dpopinfo_note_moved_to_todos"));
       
   379 	notificationDialog->show();
   355 }
   380 }
   356 
   381 
   357 /*!
   382 /*!
   358 	Slot to handle the signal editingCompleted by the notes editor.
   383 	Slot to handle the signal editingCompleted by the notes editor.
   359 
   384 
   428 			this, SLOT(handleEditingCompleted(bool)));
   453 			this, SLOT(handleEditingCompleted(bool)));
   429 
   454 
   430 	// Launch the notes editor with the obtained info.
   455 	// Launch the notes editor with the obtained info.
   431 	mNotesEditor->edit(entry);
   456 	mNotesEditor->edit(entry);
   432 }
   457 }
       
   458 
       
   459 /*
       
   460 	Slot to handle the context menu actions.
       
   461  */
       
   462 void NotesFavoriteView::selectedMenuAction(HbAction *action)
       
   463 {
       
   464 	if(action == mOpenAction) {
       
   465 		openNote();
       
   466 	} else if (action == mDeleteAction) {
       
   467 		deleteNote();
       
   468 	} else if (action ==mRemoveFavoriteAction){
       
   469 		markNoteAsNotFavourite();
       
   470 	} else if (action == mMarkTodoAction) {
       
   471 		markNoteAsTodo();
       
   472 	}
       
   473 }
       
   474 
       
   475 /*!
       
   476 	Slot to handle the context menu closed.
       
   477  */
       
   478 void NotesFavoriteView::handleMenuClosed()
       
   479 {
       
   480 	mIsLongTop = false;
       
   481 }
       
   482 
       
   483 /*!
       
   484 	Handles the visibility of empty list label.
       
   485  */
       
   486 void NotesFavoriteView::updateView(ulong id)
       
   487 {
       
   488 	Q_UNUSED(id)
       
   489 
       
   490 	// Get the numbers of favorite notes.
       
   491 	if (0 >= mListView->model()->rowCount()) {
       
   492 		mEmptyListLabel->show();
       
   493 		mListView->hide();
       
   494 	} else {
       
   495 		mEmptyListLabel->hide();
       
   496 		mListView->show();
       
   497 	}
       
   498 }
       
   499 
   433 // End of file	--Don't remove this.
   500 // End of file	--Don't remove this.
   434 
   501