95 new NotesSortFilterProxyModel(*mAgendaUtil, this); |
98 new NotesSortFilterProxyModel(*mAgendaUtil, this); |
96 subModel->setDynamicSortFilter(true); |
99 subModel->setDynamicSortFilter(true); |
97 subModel->setSourceModel(mProxyModel); |
100 subModel->setSourceModel(mProxyModel); |
98 |
101 |
99 // Get the list object from the document and update the model. |
102 // Get the list object from the document and update the model. |
100 mListView = static_cast<HbListView *> |
103 mListView = static_cast<HbListView *> ( |
101 (mDocLoader->findWidget("noteListView")); |
104 mDocLoader->findWidget("noteListView")); |
|
105 |
102 // Update the list view model. |
106 // Update the list view model. |
103 mListView->setModel(subModel); |
107 mListView->setModel(subModel); |
104 // Setup the operations that can be done with a list view. |
108 // Setup the operations that can be done with a list view. |
105 connect( |
109 connect( |
106 mListView, SIGNAL(released(const QModelIndex &)), |
110 mListView, SIGNAL(released(const QModelIndex &)), |
109 mListView, |
113 mListView, |
110 SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)), |
114 SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)), |
111 this, |
115 this, |
112 SLOT(handleItemLongPressed(HbAbstractViewItem *, const QPointF &))); |
116 SLOT(handleItemLongPressed(HbAbstractViewItem *, const QPointF &))); |
113 |
117 |
|
118 // Get the empty list label. |
|
119 mEmptyListLabel = static_cast<HbLabel *> ( |
|
120 mDocLoader->findWidget("emptyListLabel")); |
|
121 |
114 // Get the toolbar/menu actions. |
122 // Get the toolbar/menu actions. |
115 mAddNoteAction = static_cast<HbAction *> ( |
123 mAddNoteAction = static_cast<HbAction *> ( |
116 mDocLoader->findObject("newNoteAction")); |
124 mDocLoader->findObject("newNoteAction")); |
117 connect( |
125 connect( |
118 mAddNoteAction, SIGNAL(triggered()), |
126 mAddNoteAction, SIGNAL(triggered()), |
124 mAllNotesAction, SIGNAL(triggered()), |
132 mAllNotesAction, SIGNAL(triggered()), |
125 this, SLOT(displayAllNotesView())); |
133 this, SLOT(displayAllNotesView())); |
126 |
134 |
127 mViewCollectionAction = static_cast<HbAction *> ( |
135 mViewCollectionAction = static_cast<HbAction *> ( |
128 mDocLoader->findObject("displayCollectionsAction")); |
136 mDocLoader->findObject("displayCollectionsAction")); |
129 mViewCollectionAction->setCheckable(true); |
137 |
130 mViewCollectionAction->setChecked(true); |
|
131 connect( |
138 connect( |
132 mViewCollectionAction, SIGNAL(changed()), |
139 mViewCollectionAction, SIGNAL(changed()), |
133 this, SLOT(handleActionStateChanged())); |
140 this, SLOT(handleActionStateChanged())); |
134 connect( |
141 connect( |
135 mViewCollectionAction, SIGNAL(triggered()), |
142 mViewCollectionAction, SIGNAL(triggered()), |
140 handleOrientationChanged(window->orientation()); |
147 handleOrientationChanged(window->orientation()); |
141 connect( |
148 connect( |
142 window, SIGNAL(orientationChanged(Qt::Orientation)), |
149 window, SIGNAL(orientationChanged(Qt::Orientation)), |
143 this, SLOT(handleOrientationChanged(Qt::Orientation))); |
150 this, SLOT(handleOrientationChanged(Qt::Orientation))); |
144 |
151 |
|
152 |
|
153 connect( |
|
154 mAgendaUtil, SIGNAL(entryAdded(ulong)), |
|
155 this,SLOT(updateView(ulong))); |
|
156 connect( |
|
157 mAgendaUtil, SIGNAL(entryDeleted(ulong)), |
|
158 this,SLOT(updateView(ulong))); |
|
159 connect( |
|
160 mAgendaUtil, SIGNAL(entryUpdated(ulong)), |
|
161 this, SLOT(updateView(ulong))); |
|
162 |
|
163 |
145 // Set the graphics size for the icons. |
164 // Set the graphics size for the icons. |
146 HbListViewItem *prototype = mListView->listItemPrototype(); |
165 HbListViewItem *prototype = mListView->listItemPrototype(); |
147 prototype->setGraphicsSize(HbListViewItem::SmallIcon); |
166 prototype->setGraphicsSize(HbListViewItem::SmallIcon); |
148 } |
167 } |
149 |
168 |
|
169 /* |
|
170 Updates the note view either to show notes or emptyListLabel. |
|
171 */ |
|
172 void NotesNoteView::updateNoteView() |
|
173 { |
|
174 updateView(); |
|
175 } |
|
176 |
150 /*! |
177 /*! |
151 Opens the note editor to create a new note. |
178 Opens the note editor to create a new note. |
152 */ |
179 */ |
153 void NotesNoteView::createNewNote() |
180 void NotesNoteView::createNewNote() |
154 { |
181 { |
168 \param index Reference to the QModelIndex representing the view item. |
195 \param index Reference to the QModelIndex representing the view item. |
169 \sa HbAbstractViewItem |
196 \sa HbAbstractViewItem |
170 */ |
197 */ |
171 void NotesNoteView::handleItemReleased(const QModelIndex &index) |
198 void NotesNoteView::handleItemReleased(const QModelIndex &index) |
172 { |
199 { |
173 // Sanity check. |
200 if(!mIsLongTop) { |
174 if (!index.isValid()) { |
201 // Sanity check. |
175 return; |
202 if (!index.isValid()) { |
176 } |
203 return; |
177 |
204 } |
178 // First get the id of the note and get the corresponding information from |
205 |
179 // agendautil. |
206 // First get the id of the note and get the corresponding information from |
180 ulong noteId = index.data(NotesNamespace::IdRole).value<qulonglong>(); |
207 // agendautil. |
181 |
208 ulong noteId = index.data(NotesNamespace::IdRole).value<qulonglong>(); |
182 if (0 >= noteId) { |
209 |
183 // Something wrong. |
210 if (0 >= noteId) { |
184 return; |
211 // Something wrong. |
185 } |
212 return; |
186 |
213 } |
187 // Get the entry details. |
214 |
188 AgendaEntry entry = mAgendaUtil->fetchById(noteId); |
215 // Get the entry details. |
189 |
216 AgendaEntry entry = mAgendaUtil->fetchById(noteId); |
190 if (entry.isNull()) { |
217 |
191 // Entry invalid. |
218 if (entry.isNull()) { |
192 return; |
219 // Entry invalid. |
193 } |
220 return; |
194 |
221 } |
195 // Now launch the editor with the obtained info. |
222 |
196 mNotesEditor = new NotesEditor(mAgendaUtil, this); |
223 // Now launch the editor with the obtained info. |
197 connect( |
224 mNotesEditor = new NotesEditor(mAgendaUtil, this); |
198 mNotesEditor, SIGNAL(editingCompleted(bool)), |
225 connect( |
199 this, SLOT(handleEditingCompleted(bool))); |
226 mNotesEditor, SIGNAL(editingCompleted(bool)), |
200 mNotesEditor->edit(entry); |
227 this, SLOT(handleEditingCompleted(bool))); |
|
228 mNotesEditor->edit(entry); |
|
229 } |
201 } |
230 } |
202 |
231 |
203 /*! |
232 /*! |
204 Displays a list item specific context menu. |
233 Displays a list item specific context menu. |
205 |
234 |
210 */ |
239 */ |
211 void NotesNoteView::handleItemLongPressed( |
240 void NotesNoteView::handleItemLongPressed( |
212 HbAbstractViewItem *item, const QPointF &coords) |
241 HbAbstractViewItem *item, const QPointF &coords) |
213 { |
242 { |
214 mSelectedItem = item; |
243 mSelectedItem = item; |
|
244 mIsLongTop = true; |
215 |
245 |
216 ulong noteId = item->modelIndex().data( |
246 ulong noteId = item->modelIndex().data( |
217 NotesNamespace::IdRole).value<qulonglong>(); |
247 NotesNamespace::IdRole).value<qulonglong>(); |
218 AgendaEntry entry = mAgendaUtil->fetchById(noteId); |
248 AgendaEntry entry = mAgendaUtil->fetchById(noteId); |
219 |
249 |
220 // Display a context specific menu. |
250 // Display a context specific menu. |
221 HbMenu *contextMenu = new HbMenu(); |
251 HbMenu *contextMenu = new HbMenu(); |
|
252 connect( |
|
253 contextMenu,SIGNAL(aboutToClose()), |
|
254 this, SLOT(handleMenuClosed())); |
222 |
255 |
223 // Add actions to the context menu. |
256 // Add actions to the context menu. |
224 mOpenAction = |
257 mOpenAction = |
225 contextMenu->addAction(hbTrId("txt_common_menu_open")); |
258 contextMenu->addAction(hbTrId("txt_common_menu_open")); |
226 connect( |
|
227 mOpenAction, SIGNAL(triggered()), |
|
228 this, SLOT(openNote())); |
|
229 |
259 |
230 mDeleteAction = |
260 mDeleteAction = |
231 contextMenu->addAction(hbTrId("txt_common_menu_delete")); |
261 contextMenu->addAction(hbTrId("txt_common_menu_delete")); |
232 connect( |
|
233 mDeleteAction, SIGNAL(triggered()), |
|
234 this, SLOT(deleteNote())); |
|
235 |
262 |
236 if (AgendaEntry::TypeNote == entry.type()) { |
263 if (AgendaEntry::TypeNote == entry.type()) { |
237 if (entry.favourite()) { |
264 if (entry.favourite()) { |
238 mMakeFavouriteAction = |
265 mMakeFavouriteAction = contextMenu->addAction( |
239 contextMenu->addAction( |
|
240 hbTrId("txt_notes_menu_remove_from_favorites")); |
266 hbTrId("txt_notes_menu_remove_from_favorites")); |
241 |
|
242 connect( |
|
243 mMakeFavouriteAction, SIGNAL(triggered()), |
|
244 this, SLOT(markNoteAsFavourite())); |
|
245 |
|
246 } else { |
267 } else { |
247 mMakeFavouriteAction = |
268 mMakeFavouriteAction = contextMenu->addAction( |
248 contextMenu->addAction( |
|
249 hbTrId("txt_notes_menu_mark_as_favorite")); |
269 hbTrId("txt_notes_menu_mark_as_favorite")); |
250 |
|
251 connect( |
|
252 mMakeFavouriteAction, SIGNAL(triggered()), |
|
253 this, SLOT(markNoteAsFavourite())); |
|
254 } |
270 } |
255 mMarkTodoAction = contextMenu->addAction( |
271 mMarkTodoAction = contextMenu->addAction( |
256 hbTrId("txt_notes_menu_make_it_as_todo_note")); |
272 hbTrId("txt_notes_menu_make_it_as_todo_note")); |
257 connect( |
|
258 mMarkTodoAction, SIGNAL(triggered()), |
|
259 this, SLOT(markNoteAsTodo())); |
|
260 } |
273 } |
261 |
274 |
262 // Show the menu. |
275 // Show the menu. |
263 contextMenu->exec(coords); |
276 contextMenu->open(this, SLOT(selectedMenuAction(HbAction*))); |
|
277 contextMenu->setPreferredPos(coords); |
264 } |
278 } |
265 |
279 |
266 /*! |
280 /*! |
267 Slot to delete a selected note. |
281 Slot to delete a selected note. |
268 */ |
282 */ |
355 entry, AgendaEntry::TypeTodo); |
369 entry, AgendaEntry::TypeTodo); |
356 |
370 |
357 // Delete the old entry. |
371 // Delete the old entry. |
358 mAgendaUtil->deleteEntry(entry.id()); |
372 mAgendaUtil->deleteEntry(entry.id()); |
359 |
373 |
|
374 // Show the soft notification. |
|
375 HbNotificationDialog *notificationDialog = new HbNotificationDialog(); |
|
376 notificationDialog->setTimeout( |
|
377 HbNotificationDialog::ConfirmationNoteTimeout); |
|
378 notificationDialog->setTitle( |
|
379 hbTrId("txt_notes_dpopinfo_note_moved_to_todos")); |
|
380 notificationDialog->show(); |
360 } |
381 } |
361 |
382 |
362 /*! |
383 /*! |
363 Slot to handle the signal editingCompleted by the notes editor. |
384 Slot to handle the signal editingCompleted by the notes editor. |
364 |
385 |
435 this, SLOT(handleEditingCompleted(bool))); |
456 this, SLOT(handleEditingCompleted(bool))); |
436 |
457 |
437 // Launch the notes editor with the obtained info. |
458 // Launch the notes editor with the obtained info. |
438 mNotesEditor->edit(entry); |
459 mNotesEditor->edit(entry); |
439 } |
460 } |
|
461 |
|
462 /*! |
|
463 Slot to handle context menu actions. |
|
464 */ |
|
465 void NotesNoteView::selectedMenuAction(HbAction *action) |
|
466 { |
|
467 if (action == mOpenAction) { |
|
468 openNote(); |
|
469 } else if (action == mDeleteAction) { |
|
470 deleteNote(); |
|
471 } else if (action == mMakeFavouriteAction) { |
|
472 markNoteAsFavourite(); |
|
473 } else if (action == mMarkTodoAction) { |
|
474 markNoteAsTodo(); |
|
475 } |
|
476 } |
|
477 |
|
478 /*! |
|
479 Slot to handle the context menu closed. |
|
480 */ |
|
481 void NotesNoteView::handleMenuClosed() |
|
482 { |
|
483 mIsLongTop = false; |
|
484 } |
|
485 |
|
486 /*! |
|
487 Handles the visibility of empty list label. |
|
488 */ |
|
489 void NotesNoteView::updateView(ulong id) |
|
490 { |
|
491 Q_UNUSED(id) |
|
492 |
|
493 // Get the numbers of notes. |
|
494 if (0 >= mListView->model()->rowCount()) { |
|
495 mEmptyListLabel->show(); |
|
496 mListView->hide(); |
|
497 } else { |
|
498 mEmptyListLabel->hide(); |
|
499 mListView->show(); |
|
500 } |
|
501 } |
|
502 |
440 // End of file --Don't remove this. |
503 // End of file --Don't remove this. |
441 |
504 |