notes/notesui/notesviews/src/notesnoteview.cpp
changeset 23 fd30d51f876b
parent 18 c198609911f9
child 26 a949c2543c15
child 45 b6db4fd4947b
equal deleted inserted replaced
18:c198609911f9 23:fd30d51f876b
    15  * Definition file for NotesNoteView class.
    15  * Definition file for NotesNoteView class.
    16  *
    16  *
    17  */
    17  */
    18 
    18 
    19 // System includes
    19 // System includes
    20 #include <QDebug>
       
    21 #include <QDateTime>
    20 #include <QDateTime>
    22 #include <HbListView>
    21 #include <HbListView>
    23 #include <HbListWidget>
    22 #include <HbListWidget>
    24 #include <HbAction>
    23 #include <HbAction>
    25 #include <HbMenu>
    24 #include <HbMenu>
    54 NotesNoteView::NotesNoteView(QGraphicsWidget *parent)
    53 NotesNoteView::NotesNoteView(QGraphicsWidget *parent)
    55 :HbView(parent),
    54 :HbView(parent),
    56  mSelectedItem(0),
    55  mSelectedItem(0),
    57  mDeleteAction(0)
    56  mDeleteAction(0)
    58  {
    57  {
    59 	qDebug() << "notes: NotesNoteView::NotesNoteView -->";
       
    60 
       
    61 	// Nothing yet.
    58 	// Nothing yet.
    62 
       
    63 	qDebug() << "notes: NotesNoteView::NotesNoteView <--";
       
    64  }
    59  }
    65 
    60 
    66 /*!
    61 /*!
    67 	Destructor.
    62 	Destructor.
    68  */
    63  */
    69 NotesNoteView::~NotesNoteView()
    64 NotesNoteView::~NotesNoteView()
    70 {
    65 {
    71 	qDebug() << "notes: NotesNoteView::~NotesNoteView -->";
       
    72 
       
    73 	if (mDocLoader) {
    66 	if (mDocLoader) {
    74 		delete mDocLoader;
    67 		delete mDocLoader;
    75 		mDocLoader = 0;
    68 		mDocLoader = 0;
    76 	}
    69 	}
    77 
       
    78 	qDebug() << "notes: NotesNoteView::~NotesNoteView <--";
       
    79 }
    70 }
    80 
    71 
    81 /*!
    72 /*!
    82 	Called by the NotesViewManager after loading the view from the docml.
    73 	Called by the NotesViewManager after loading the view from the docml.
    83 	The initializaion/setup of the view is done here.
    74 	The initializaion/setup of the view is done here.
    86 	\param docLoader Pointer to NotesDocLoader object.
    77 	\param docLoader Pointer to NotesDocLoader object.
    87  */
    78  */
    88 void NotesNoteView::setupView(
    79 void NotesNoteView::setupView(
    89 		NotesAppControllerIf &controllerIf, NotesDocLoader *docLoader)
    80 		NotesAppControllerIf &controllerIf, NotesDocLoader *docLoader)
    90 {
    81 {
    91 	qDebug() << "notes: NotesNoteView::setupView -->";
       
    92 
       
    93 	mDocLoader = docLoader;
    82 	mDocLoader = docLoader;
    94 	mAppControllerIf = &controllerIf;
    83 	mAppControllerIf = &controllerIf;
    95 	mNotesModel = mAppControllerIf->notesModel();
    84 	mNotesModel = mAppControllerIf->notesModel();
    96 	mAgendaUtil = mAppControllerIf->agendaUtil();
    85 	mAgendaUtil = mAppControllerIf->agendaUtil();
    97 
    86 
   151 	handleOrientationChanged(window->orientation());
   140 	handleOrientationChanged(window->orientation());
   152 	connect(
   141 	connect(
   153 			window, SIGNAL(orientationChanged(Qt::Orientation)),
   142 			window, SIGNAL(orientationChanged(Qt::Orientation)),
   154 			this, SLOT(handleOrientationChanged(Qt::Orientation)));
   143 			this, SLOT(handleOrientationChanged(Qt::Orientation)));
   155 
   144 
   156 	qDebug() << "notes: NotesNoteView::setupView <--";
   145 	// Set the graphics size for the icons.
       
   146 	HbListViewItem *prototype = mListView->listItemPrototype();
       
   147 	prototype->setGraphicsSize(HbListViewItem::SmallIcon);
   157 }
   148 }
   158 
   149 
   159 /*!
   150 /*!
   160 	Opens the note editor to create a new note.
   151 	Opens the note editor to create a new note.
   161  */
   152  */
   162 void NotesNoteView::createNewNote()
   153 void NotesNoteView::createNewNote()
   163 {
   154 {
   164 	qDebug() << "notes: NotesNoteView::createNewNote -->";
       
   165 
       
   166 	// Here we Display an editor to the use to enter text.
   155 	// Here we Display an editor to the use to enter text.
   167 	mNotesEditor = new NotesEditor(mAgendaUtil, this);
   156 	mNotesEditor = new NotesEditor(mAgendaUtil, this);
   168 	connect(
   157 	connect(
   169 			mNotesEditor, SIGNAL(editingCompleted(bool)),
   158 			mNotesEditor, SIGNAL(editingCompleted(bool)),
   170 			this, SLOT(handleEditingCompleted(bool)));
   159 			this, SLOT(handleEditingCompleted(bool)));
   171 	mNotesEditor->create(NotesEditor::CreateNote);
   160 	mNotesEditor->create(NotesEditor::CreateNote);
   172 
       
   173 	qDebug() << "notes: NotesNoteView::createNewNote <--";
       
   174 }
   161 }
   175 
   162 
   176 /*!
   163 /*!
   177 	Handles the pressing of a list item in the view.
   164 	Handles the pressing of a list item in the view.
   178 
   165 
   181 	\param index Reference to the QModelIndex representing the view item.
   168 	\param index Reference to the QModelIndex representing the view item.
   182 	\sa HbAbstractViewItem
   169 	\sa HbAbstractViewItem
   183  */
   170  */
   184 void NotesNoteView::handleItemReleased(const QModelIndex &index)
   171 void NotesNoteView::handleItemReleased(const QModelIndex &index)
   185 {
   172 {
   186 	qDebug() << "notes: NotesNoteView::handleItemReleased -->";
       
   187 
       
   188 	// Sanity check.
   173 	// Sanity check.
   189 	if (!index.isValid()) {
   174 	if (!index.isValid()) {
   190 		qDebug() << "notes: NotesNoteView::handleItemReleased <--";
       
   191 
       
   192 		return;
   175 		return;
   193 	}
   176 	}
   194 
   177 
   195 	// First get the id of the note and get the corresponding information from
   178 	// First get the id of the note and get the corresponding information from
   196 	// agendautil.
   179 	// agendautil.
   197 	ulong noteId = index.data(NotesNamespace::IdRole).value<qulonglong>();
   180 	ulong noteId = index.data(NotesNamespace::IdRole).value<qulonglong>();
   198 
   181 
   199 	if (0 >= noteId) {
   182 	if (0 >= noteId) {
   200 		qDebug() << "notes: NotesNoteView::handleItemReleased <--";
       
   201 
       
   202 		// Something wrong.
   183 		// Something wrong.
   203 		return;
   184 		return;
   204 	}
   185 	}
   205 
   186 
   206 	// Get the entry details.
   187 	// Get the entry details.
   207 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   188 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   208 
   189 
   209 	if (entry.isNull()) {
   190 	if (entry.isNull()) {
   210 		qDebug() << "notes: NotesNoteView::handleItemReleased <--";
       
   211 
       
   212 		// Entry invalid.
   191 		// Entry invalid.
   213 		return;
   192 		return;
   214 	}
   193 	}
   215 
   194 
   216 	// Now launch the editor with the obtained info.
   195 	// Now launch the editor with the obtained info.
   217 	mNotesEditor = new NotesEditor(mAgendaUtil, this);
   196 	mNotesEditor = new NotesEditor(mAgendaUtil, this);
   218 	connect(
   197 	connect(
   219 			mNotesEditor, SIGNAL(editingCompleted(bool)),
   198 			mNotesEditor, SIGNAL(editingCompleted(bool)),
   220 			this, SLOT(handleEditingCompleted(bool)));
   199 			this, SLOT(handleEditingCompleted(bool)));
   221 	mNotesEditor->edit(entry);
   200 	mNotesEditor->edit(entry);
   222 
       
   223 	qDebug() << "notes: NotesNoteView::handleItemReleased <--";
       
   224 }
   201 }
   225 
   202 
   226 /*!
   203 /*!
   227 	Displays a list item specific context menu.
   204 	Displays a list item specific context menu.
   228 
   205 
   232 	\sa HbAbstractViewItem, HbListView, HbMenu.
   209 	\sa HbAbstractViewItem, HbListView, HbMenu.
   233  */
   210  */
   234 void NotesNoteView::handleItemLongPressed(
   211 void NotesNoteView::handleItemLongPressed(
   235 		HbAbstractViewItem *item, const QPointF &coords)
   212 		HbAbstractViewItem *item, const QPointF &coords)
   236 {
   213 {
   237 	qDebug() << "notes: NotesNoteView::handleItemLongPressed -->";
       
   238 
       
   239 	mSelectedItem = item;
   214 	mSelectedItem = item;
   240 
   215 
   241 	ulong noteId = item->modelIndex().data(
   216 	ulong noteId = item->modelIndex().data(
   242 			NotesNamespace::IdRole).value<qulonglong>();
   217 			NotesNamespace::IdRole).value<qulonglong>();
   243 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   218 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   244 
   219 
   245 	// Display a context specific menu.
   220 	// Display a context specific menu.
   246 	HbMenu *contextMenu = new HbMenu();
   221 	HbMenu *contextMenu = new HbMenu();
   247 
   222 
   248 	// Add actions to the context menu.
   223 	// Add actions to the context menu.
       
   224 	mOpenAction =
       
   225 			contextMenu->addAction(hbTrId("txt_common_menu_open"));
       
   226 	connect(
       
   227 			mOpenAction, SIGNAL(triggered()),
       
   228 			this, SLOT(openNote()));
       
   229 
   249 	mDeleteAction =
   230 	mDeleteAction =
   250 			contextMenu->addAction(hbTrId("txt_common_menu_delete"));
   231 			contextMenu->addAction(hbTrId("txt_common_menu_delete"));
   251 	connect(
   232 	connect(
   252 			mDeleteAction, SIGNAL(triggered()),
   233 			mDeleteAction, SIGNAL(triggered()),
   253 			this, SLOT(deleteNote()));
   234 			this, SLOT(deleteNote()));
   278 				this, SLOT(markNoteAsTodo()));
   259 				this, SLOT(markNoteAsTodo()));
   279 	}
   260 	}
   280 
   261 
   281 	// Show the menu.
   262 	// Show the menu.
   282 	contextMenu->exec(coords);
   263 	contextMenu->exec(coords);
   283 
       
   284 	qDebug() << "notes: NotesNoteView::handleItemLongPressed <--";
       
   285 }
   264 }
   286 
   265 
   287 /*!
   266 /*!
   288 	Slot to delete a selected note.
   267 	Slot to delete a selected note.
   289  */
   268  */
   290 void NotesNoteView::deleteNote()
   269 void NotesNoteView::deleteNote()
   291 {
   270 {
   292 	qDebug() << "notes: NotesNoteView::deleteNote -->";
       
   293 
       
   294 	Q_ASSERT(mSelectedItem);
   271 	Q_ASSERT(mSelectedItem);
   295 
   272 
   296 	QModelIndex index = mSelectedItem->modelIndex();
   273 	QModelIndex index = mSelectedItem->modelIndex();
   297 	if (!index.isValid()) {
   274 	if (!index.isValid()) {
   298 		qDebug() << "notes: NotesNoteView::deleteNote <--";
       
   299 
       
   300 		return;
   275 		return;
   301 	}
   276 	}
   302 	ulong noteId =
   277 	ulong noteId =
   303 			index.data(NotesNamespace::IdRole).value<qulonglong>();
   278 			index.data(NotesNamespace::IdRole).value<qulonglong>();
   304 	if (!noteId) {
   279 	if (!noteId) {
   305 		qDebug() << "notes: NotesNoteView::deleteNote <--";
   280 		return;
   306 
   281 	}
   307 		return;
   282 	// Emitting the signal , deletion would be handle in view manager.
   308 	}
   283 	emit deleteEntry(noteId);
   309 
       
   310 	// Delete the given note.
       
   311 	mAgendaUtil->deleteEntry(noteId);
       
   312 
   284 
   313 	mSelectedItem = 0;
   285 	mSelectedItem = 0;
   314 
       
   315 	qDebug() << "notes: NotesNoteView::deleteNote <--";
       
   316 }
   286 }
   317 
   287 
   318 /*!
   288 /*!
   319     Marks/unmarks the note as favourite.
   289     Marks/unmarks the note as favourite.
   320  */
   290  */
   321 void NotesNoteView::markNoteAsFavourite()
   291 void NotesNoteView::markNoteAsFavourite()
   322 {
   292 {
   323 	qDebug() << "notes : NotesNoteView::markNoteAsFavourite -->";
       
   324 
       
   325 	ulong noteId = mSelectedItem->modelIndex().data(
   293 	ulong noteId = mSelectedItem->modelIndex().data(
   326 			NotesNamespace::IdRole).value<qulonglong>();
   294 			NotesNamespace::IdRole).value<qulonglong>();
   327 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   295 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   328 
   296 
   329 	if (entry.favourite()) {
   297 	if (entry.favourite()) {
   330 		entry.setFavourite(0);
   298 		entry.setFavourite(0);
   331 	} else {
   299 	} else {
   332 		entry.setFavourite(1);
   300 		entry.setFavourite(1);
   333 	}
   301 	}
   334 	mAgendaUtil->updateEntry(entry);
   302 	mAgendaUtil->updateEntry(entry);
   335 
       
   336 	qDebug() << "notes : NotesNoteView::markNoteAsFavourite <--";
       
   337 }
   303 }
   338 
   304 
   339 /*!
   305 /*!
   340     Slot to make a note as to-do.
   306     Slot to make a note as to-do.
   341  */
   307  */
   342 void NotesNoteView::markNoteAsTodo()
   308 void NotesNoteView::markNoteAsTodo()
   343 {
   309 {
   344 	qDebug() << "notes : NotesNoteView::markNoteAsTodo -->";
       
   345 
       
   346 	Q_ASSERT(mSelectedItem);
   310 	Q_ASSERT(mSelectedItem);
   347 
   311 
   348 	QModelIndex index = mSelectedItem->modelIndex();
   312 	QModelIndex index = mSelectedItem->modelIndex();
   349 	if (!index.isValid()) {
   313 	if (!index.isValid()) {
   350 		qDebug() << "notes: NotesNoteView::markNoteAsTodo <--";
       
   351 
       
   352 		return;
   314 		return;
   353 	}
   315 	}
   354 	ulong noteId =
   316 	ulong noteId =
   355 			index.data(NotesNamespace::IdRole).value<qulonglong>();
   317 			index.data(NotesNamespace::IdRole).value<qulonglong>();
   356 	if (!noteId) {
   318 	if (!noteId) {
   357 		qDebug() << "notes: NotesNoteView::markNoteAsTodo <--";
       
   358 
       
   359 		return;
   319 		return;
   360 	}
   320 	}
   361 	// Get the entry details.
   321 	// Get the entry details.
   362 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   322 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   363 
   323 
   364 	if (entry.isNull()) {
   324 	if (entry.isNull()) {
   365 		qDebug() << "notes: NotesNoteView::markNoteAsTodo <--";
       
   366 
       
   367 		// Entry invalid.
   325 		// Entry invalid.
   368 		return;
   326 		return;
   369 	}
   327 	}
   370 
   328 
   371 	// Here change the type of modified note and destroy the noteeditor and
   329 	// Here change the type of modified note and destroy the noteeditor and
   372 	// construct the to-do editor.
   330 	// construct the to-do editor.
   373 	entry.setType(AgendaEntry::TypeTodo);
   331 	entry.setType(AgendaEntry::TypeTodo);
   374 
   332 
   375 	QDateTime dueDateTime;
   333 	QDateTime dueDateTime;
   376 	dueDateTime.setDate(QDate::currentDate());
   334 	QDate currentDate(QDate::currentDate());
       
   335 	dueDateTime.setDate(
       
   336 			QDate(currentDate.year(),currentDate.month(),currentDate.day()+1));
   377 	dueDateTime.setTime(QTime::fromString("12:00 am", "hh:mm ap"));
   337 	dueDateTime.setTime(QTime::fromString("12:00 am", "hh:mm ap"));
   378 
   338 
   379 	entry.setStartAndEndTime(dueDateTime, dueDateTime);
   339 	entry.setStartAndEndTime(dueDateTime, dueDateTime);
   380 
   340 
   381 	entry.setSummary(entry.description().left(80));
   341 	entry.setSummary(entry.description().left(80));
   395 			entry, AgendaEntry::TypeTodo);
   355 			entry, AgendaEntry::TypeTodo);
   396 
   356 
   397 	// Delete the old entry.
   357 	// Delete the old entry.
   398 	mAgendaUtil->deleteEntry(entry.id());
   358 	mAgendaUtil->deleteEntry(entry.id());
   399 
   359 
   400 	qDebug() << "notes : NotesNoteView::markNoteAsTodo <--";
       
   401 }
   360 }
   402 
   361 
   403 /*!
   362 /*!
   404 	Slot to handle the signal editingCompleted by the notes editor.
   363 	Slot to handle the signal editingCompleted by the notes editor.
   405 
   364 
   407 
   366 
   408 	\sa NotesEditor.
   367 	\sa NotesEditor.
   409  */
   368  */
   410 void NotesNoteView::handleEditingCompleted(bool status)
   369 void NotesNoteView::handleEditingCompleted(bool status)
   411 {
   370 {
   412 	qDebug() << "notes: NotesNoteView::handleEditingCompleted -->";
       
   413 
       
   414 	Q_UNUSED(status)
   371 	Q_UNUSED(status)
   415 
   372 
   416 	// Cleanup.
   373 	// Cleanup.
   417 	mNotesEditor->deleteLater();
   374 	mNotesEditor->deleteLater();
   418 
       
   419 	qDebug() << "notes: NotesNoteView::handleEditingCompleted <--";
       
   420 }
   375 }
   421 
   376 
   422 /*!
   377 /*!
   423 	Directs the view manager to display the Collections view.
   378 	Directs the view manager to display the Collections view.
   424  */
   379  */
   425 void NotesNoteView::displayCollectionView()
   380 void NotesNoteView::displayCollectionView()
   426 {
   381 {
   427 	qDebug() << "notes: NotesNoteView::displayCollectionView -->";
       
   428 
       
   429 	// Switch to collections view.
   382 	// Switch to collections view.
   430 	mAppControllerIf->switchToView(NotesNamespace::NotesCollectionViewId);
   383 	mAppControllerIf->switchToView(NotesNamespace::NotesCollectionViewId);
   431 
   384 
   432 	qDebug() << "notes: NotesNoteView::displayCollectionView <--";
       
   433 }
   385 }
   434 
   386 
   435 /*!
   387 /*!
   436 	Directs the view manager to display the All notes view.
   388 	Directs the view manager to display the All notes view.
   437  */
   389  */
   438 void NotesNoteView::displayAllNotesView()
   390 void NotesNoteView::displayAllNotesView()
   439 {
   391 {
   440 	qDebug() << "notes: NotesNoteView::displayAllNotesView -->";
       
   441 
       
   442 	// Switch to collections view.
   392 	// Switch to collections view.
   443 	mAppControllerIf->switchToView(NotesNamespace::NotesMainViewId);
   393 	mAppControllerIf->switchToView(NotesNamespace::NotesMainViewId);
   444 
       
   445 	qDebug() << "notes: NotesNoteView::displayAllNotesView <--";
       
   446 }
   394 }
   447 
   395 
   448 /*!
   396 /*!
   449 	Slot to handle the case when the state of an action has changed.
   397 	Slot to handle the case when the state of an action has changed.
   450  */
   398  */
   451 void NotesNoteView::handleActionStateChanged()
   399 void NotesNoteView::handleActionStateChanged()
   452 {
   400 {
   453 	qDebug() << "notes: NotesNoteView::handleActionStateChanged -->";
       
   454 
       
   455 	mAllNotesAction->setChecked(true);
   401 	mAllNotesAction->setChecked(true);
   456 
       
   457 	qDebug() << "notes: NotesNoteView::handleActionStateChanged <--";
       
   458 }
   402 }
   459 
   403 
   460 /*!
   404 /*!
   461 	Handles the orientation changes.Updates the list
   405 	Handles the orientation changes.Updates the list
   462 	item when orientation is changed
   406 	item when orientation is changed
   467 {
   411 {
   468 	HbListViewItem *prototype = mListView->listItemPrototype();
   412 	HbListViewItem *prototype = mListView->listItemPrototype();
   469 
   413 
   470 	if (Qt::Horizontal == orientation) {
   414 	if (Qt::Horizontal == orientation) {
   471 		prototype->setStretchingStyle(HbListViewItem::StretchLandscape);
   415 		prototype->setStretchingStyle(HbListViewItem::StretchLandscape);
   472 
       
   473 		// Set the text in landscape mode
       
   474 		mAllNotesAction->setText(hbTrId("txt_notes_button_all"));
       
   475 		mViewCollectionAction->setText(hbTrId("txt_notes_button_collections"));
       
   476 		mAddNoteAction->setText(hbTrId("txt_notes_button_new_note"));
       
   477 	} else {
   416 	} else {
   478 		prototype->setStretchingStyle(HbListViewItem::NoStretching);
   417 		prototype->setStretchingStyle(HbListViewItem::NoStretching);
   479 
   418 	}
   480 		// Set empty text in portriat mode so that only icons are visible.
   419 }
   481 		mAllNotesAction->setText("");
   420 
   482 		mViewCollectionAction->setText("");
   421 /*
   483 		mAddNoteAction->setText("");
   422 	Opens the notes editor to edit the note.
   484 	}
   423  */
   485 }
   424 void NotesNoteView::openNote()
   486 
   425 {
       
   426 	ulong noteId = mSelectedItem->modelIndex().data(
       
   427 			NotesNamespace::IdRole).value<qulonglong>();
       
   428 
       
   429 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
       
   430 
       
   431 	// Construct notes editor.
       
   432 	mNotesEditor = new NotesEditor(mAgendaUtil, this);
       
   433 	connect(
       
   434 			mNotesEditor, SIGNAL(editingCompleted(bool)),
       
   435 			this, SLOT(handleEditingCompleted(bool)));
       
   436 
       
   437 	// Launch the notes editor with the obtained info.
       
   438 	mNotesEditor->edit(entry);
       
   439 }
   487 // End of file	--Don't remove this.
   440 // End of file	--Don't remove this.
   488 
   441