|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Definition file for NotesFavoriteView class. |
|
16 * |
|
17 */ |
|
18 |
|
19 // System includes |
|
20 #include <QDebug> |
|
21 #include <QDateTime> |
|
22 #include <HbListView> |
|
23 #include <HbListWidget> |
|
24 #include <HbAction> |
|
25 #include <HbTextEdit> |
|
26 #include <HbInstance> |
|
27 #include <HbMainWindow> |
|
28 #include <HbMenu> |
|
29 #include <HbDialog> |
|
30 #include <HbLabel> |
|
31 #include <HbAbstractViewItem> |
|
32 #include <HbGroupBox> |
|
33 #include <HbListViewItem> |
|
34 |
|
35 // User includes |
|
36 #include "notesfavoriteview.h" |
|
37 #include "notescommon.h" |
|
38 #include "notesdocloader.h" |
|
39 #include "agendautil.h" |
|
40 #include "notesmodel.h" |
|
41 #include "notessortfilterproxymodel.h" |
|
42 #include "noteseditor.h" |
|
43 |
|
44 /*! |
|
45 \class NotesFavoriteView |
|
46 \brief The main view of the notes application. Responsible for displaying |
|
47 notes and todos. |
|
48 |
|
49 \sa NotesViewManager |
|
50 */ |
|
51 |
|
52 /*! |
|
53 Constructs the NotesFavoriteView object. |
|
54 |
|
55 \param parent The parent of type QGraphicsWidget. |
|
56 */ |
|
57 NotesFavoriteView::NotesFavoriteView(QGraphicsWidget *parent) |
|
58 :HbView(parent), |
|
59 mSelectedItem(0), |
|
60 mDeleteAction(0) |
|
61 { |
|
62 qDebug() << "notes: NotesFavoriteView::NotesFavoriteView -->"; |
|
63 |
|
64 // Nothing yet. |
|
65 |
|
66 qDebug() << "notes: NotesFavoriteView::NotesFavoriteView <--"; |
|
67 } |
|
68 |
|
69 /*! |
|
70 Destructor. |
|
71 */ |
|
72 NotesFavoriteView::~NotesFavoriteView() |
|
73 { |
|
74 qDebug() << "notes: NotesFavoriteView::~NotesFavoriteView -->"; |
|
75 |
|
76 if (mDocLoader) { |
|
77 delete mDocLoader; |
|
78 mDocLoader = 0; |
|
79 } |
|
80 |
|
81 qDebug() << "notes: NotesFavoriteView::~NotesFavoriteView <--"; |
|
82 } |
|
83 |
|
84 /*! |
|
85 Called by the NotesViewManager after loading the view from the docml. |
|
86 The initializaion/setup of the view is done here. |
|
87 |
|
88 \param controller The NotesAppController object. |
|
89 \param docLoader Pointer to NotesDocLoader object. |
|
90 */ |
|
91 void NotesFavoriteView::setupView( |
|
92 NotesAppControllerIf &controllerIf, NotesDocLoader *docLoader) |
|
93 { |
|
94 qDebug() << "notes: NotesMainView::setupView -->"; |
|
95 |
|
96 mDocLoader = docLoader; |
|
97 mAppControllerIf = &controllerIf; |
|
98 mNotesModel = mAppControllerIf->notesModel(); |
|
99 mAgendaUtil = mAppControllerIf->agendaUtil(); |
|
100 |
|
101 mProxyModel = new NotesSortFilterProxyModel(*mAgendaUtil, this); |
|
102 mProxyModel->setDynamicSortFilter(true); |
|
103 mProxyModel->setSourceModel(mNotesModel->sourceModel()); |
|
104 |
|
105 // Apply the filter |
|
106 mProxyModel->setFilterRole(NotesNamespace::FavouriteRole); |
|
107 mProxyModel->setFilterRegExp(QRegExp(QString("favourites"))); |
|
108 |
|
109 NotesSortFilterProxyModel *subModel = |
|
110 new NotesSortFilterProxyModel(*mAgendaUtil, this); |
|
111 subModel->setDynamicSortFilter(true); |
|
112 subModel->setSourceModel(mProxyModel); |
|
113 |
|
114 // Get the list object from the document and update the model. |
|
115 mListView = static_cast<HbListView *> |
|
116 (mDocLoader->findWidget("favoritesListView")); |
|
117 // Update the list view model. |
|
118 mListView->setModel(subModel); |
|
119 // Setup the operations that can be done with a list view. |
|
120 connect( |
|
121 mListView, SIGNAL(released(const QModelIndex &)), |
|
122 this, SLOT(handleItemReleased(const QModelIndex &))); |
|
123 connect( |
|
124 mListView, |
|
125 SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)), |
|
126 this, |
|
127 SLOT(handleItemLongPressed(HbAbstractViewItem *, const QPointF &))); |
|
128 |
|
129 // Get the toolbar/menu actions. |
|
130 mAddNoteAction = static_cast<HbAction *> ( |
|
131 mDocLoader->findObject("newNoteAction")); |
|
132 connect( |
|
133 mAddNoteAction, SIGNAL(triggered()), |
|
134 this, SLOT(createNewNote())); |
|
135 |
|
136 mAllNotesAction = static_cast<HbAction *> ( |
|
137 mDocLoader->findObject("allNotesAction")); |
|
138 connect( |
|
139 mAllNotesAction, SIGNAL(triggered()), |
|
140 this, SLOT(displayAllNotesView())); |
|
141 |
|
142 mViewCollectionAction = static_cast<HbAction *> ( |
|
143 mDocLoader->findObject("displayCollectionsAction")); |
|
144 mViewCollectionAction->setCheckable(true); |
|
145 mViewCollectionAction->setChecked(true); |
|
146 connect( |
|
147 mViewCollectionAction, SIGNAL(changed()), |
|
148 this, SLOT(handleActionStateChanged())); |
|
149 connect( |
|
150 mViewCollectionAction, SIGNAL(triggered()), |
|
151 this, SLOT(displayCollectionView())); |
|
152 |
|
153 // Handles the orientation change for list items |
|
154 HbMainWindow *window = hbInstance->allMainWindows().first(); |
|
155 handleOrientationChanged(window->orientation()); |
|
156 connect( |
|
157 window, SIGNAL(orientationChanged(Qt::Orientation)), |
|
158 this, SLOT(handleOrientationChanged(Qt::Orientation))); |
|
159 |
|
160 qDebug() << "notes: NotesMainView::setupView <--"; |
|
161 } |
|
162 |
|
163 /*! |
|
164 Slot which gets called when `+ New note' action is triggered from the view |
|
165 toolbar. This is responsible for launching the editor to create a new note. |
|
166 */ |
|
167 void NotesFavoriteView::createNewNote() |
|
168 { |
|
169 qDebug() << "notes: NotesFavoriteView::createNewNote -->"; |
|
170 |
|
171 // Here we Display an editor to the use to enter text. |
|
172 mNotesEditor = new NotesEditor(mAgendaUtil, this); |
|
173 connect( |
|
174 mNotesEditor, SIGNAL(editingCompleted(bool)), |
|
175 this, SLOT(handleEditingCompleted(bool))); |
|
176 mNotesEditor->create(NotesEditor::CreateNote); |
|
177 |
|
178 qDebug() << "notes: NotesFavoriteView::createNewNote <--"; |
|
179 } |
|
180 |
|
181 /*! |
|
182 Handles the pressing of a list item in the view. |
|
183 |
|
184 Here we open the editor for viewing/editing. |
|
185 |
|
186 \param index Reference to the QModelIndex representing the view item. |
|
187 \sa HbAbstractViewItem |
|
188 */ |
|
189 void NotesFavoriteView::handleItemReleased(const QModelIndex &index) |
|
190 { |
|
191 qDebug() << "notes: NotesFavoriteView::handleItemReleased -->"; |
|
192 |
|
193 // Sanity check. |
|
194 if (!index.isValid()) { |
|
195 qDebug() << "notes: NotesFavoriteView::handleItemReleased <--"; |
|
196 |
|
197 return; |
|
198 } |
|
199 |
|
200 // First get the id of the note and get the corresponding information from |
|
201 // agendautil. |
|
202 ulong noteId = index.data(NotesNamespace::IdRole).value<qulonglong>(); |
|
203 |
|
204 if (0 >= noteId) { |
|
205 qDebug() << "notes: NotesFavoriteView::handleItemReleased <--"; |
|
206 |
|
207 // Something wrong. |
|
208 return; |
|
209 } |
|
210 |
|
211 // Get the entry details. |
|
212 AgendaEntry entry = mAgendaUtil->fetchById(noteId); |
|
213 |
|
214 if (entry.isNull()) { |
|
215 qDebug() << "notes: NotesFavoriteView::handleItemReleased <--"; |
|
216 |
|
217 // Entry invalid. |
|
218 return; |
|
219 } |
|
220 |
|
221 // Now launch the editor with the obtained info. |
|
222 mNotesEditor = new NotesEditor(mAgendaUtil, this); |
|
223 connect( |
|
224 mNotesEditor, SIGNAL(editingCompleted(bool)), |
|
225 this, SLOT(handleEditingCompleted(bool))); |
|
226 mNotesEditor->edit(entry); |
|
227 |
|
228 qDebug() << "notes: NotesFavoriteView::handleItemReleased <--"; |
|
229 } |
|
230 |
|
231 /*! |
|
232 Displays a list item specific context menu. |
|
233 |
|
234 \param item The HbAbstractViewItem that was long pressed. |
|
235 \param coords The position where mouse was pressed. |
|
236 |
|
237 \sa HbAbstractViewItem, HbListView, HbMenu. |
|
238 */ |
|
239 void NotesFavoriteView::handleItemLongPressed( |
|
240 HbAbstractViewItem *item, const QPointF &coords) |
|
241 { |
|
242 qDebug() << "notes: NotesFavoriteView::handleItemLongPressed -->"; |
|
243 |
|
244 mSelectedItem = item; |
|
245 |
|
246 // Get the entry of the selected item. |
|
247 ulong noteId = item->modelIndex().data( |
|
248 NotesNamespace::IdRole).value<qulonglong>(); |
|
249 AgendaEntry entry = mAgendaUtil->fetchById(noteId); |
|
250 |
|
251 // Display a context specific menu. |
|
252 HbMenu *contextMenu = new HbMenu(); |
|
253 |
|
254 // Add actions to the context menu. |
|
255 mDeleteAction = |
|
256 contextMenu->addAction(hbTrId("txt_common_menu_delete")); |
|
257 connect( |
|
258 mDeleteAction, SIGNAL(triggered()), |
|
259 this, SLOT(deleteNote())); |
|
260 |
|
261 mRemoveFavoriteAction = |
|
262 contextMenu->addAction( |
|
263 hbTrId("txt_notes_menu_remove_from_favorites")); |
|
264 |
|
265 connect( |
|
266 mRemoveFavoriteAction, SIGNAL(triggered()), |
|
267 this, SLOT(markNoteAsNotFavourite())); |
|
268 |
|
269 mMarkTodoAction = |
|
270 contextMenu->addAction( |
|
271 hbTrId("txt_notes_menu_make_it_as_todo_note")); |
|
272 connect( |
|
273 mMarkTodoAction, SIGNAL(triggered()), |
|
274 this, SLOT(markNoteAsTodo())); |
|
275 |
|
276 // Show the menu. |
|
277 contextMenu->exec(coords); |
|
278 |
|
279 qDebug() << "notes: NotesFavoriteView::handleItemLongPressed <--"; |
|
280 } |
|
281 |
|
282 /*! |
|
283 Deletes the note. |
|
284 */ |
|
285 void NotesFavoriteView::deleteNote() |
|
286 { |
|
287 qDebug() << "notes: NotesFavoriteView::deleteNote -->"; |
|
288 |
|
289 Q_ASSERT(mSelectedItem); |
|
290 |
|
291 QModelIndex index = mSelectedItem->modelIndex(); |
|
292 if (!index.isValid()) { |
|
293 qDebug() << "notes: NotesFavoriteView::deleteNote <--"; |
|
294 |
|
295 return; |
|
296 } |
|
297 ulong entryId = |
|
298 index.data(NotesNamespace::IdRole).value<qulonglong>(); |
|
299 if (!entryId) { |
|
300 qDebug() << "notes: NotesFavoriteView::deleteNote <--"; |
|
301 |
|
302 return; |
|
303 } |
|
304 |
|
305 // Delete the given note. |
|
306 mAgendaUtil->deleteEntry(entryId); |
|
307 |
|
308 mSelectedItem = 0; |
|
309 |
|
310 qDebug() << "notes: NotesFavoriteView::deleteNote <--"; |
|
311 } |
|
312 |
|
313 /*! |
|
314 Removes the note from favorites. |
|
315 */ |
|
316 void NotesFavoriteView::markNoteAsNotFavourite() |
|
317 { |
|
318 qDebug() << "notes : NotesFavoriteView::markNoteAsNotFavourite -->"; |
|
319 |
|
320 ulong noteId = mSelectedItem->modelIndex().data( |
|
321 NotesNamespace::IdRole).value<qulonglong>(); |
|
322 AgendaEntry entry = mAgendaUtil->fetchById(noteId); |
|
323 |
|
324 if (entry.favourite()) { |
|
325 entry.setFavourite(0); |
|
326 } |
|
327 mAgendaUtil->updateEntry(entry); |
|
328 |
|
329 qDebug() << "notes : NotesFavoriteView::markNoteAsNotFavourite <--"; |
|
330 } |
|
331 |
|
332 /*! |
|
333 Slot to make a note as to-do. |
|
334 */ |
|
335 void NotesFavoriteView::markNoteAsTodo() |
|
336 { |
|
337 qDebug() << "notes : NotesFavoriteView::markNoteAsTodo -->"; |
|
338 |
|
339 Q_ASSERT(mSelectedItem); |
|
340 |
|
341 QModelIndex index = mSelectedItem->modelIndex(); |
|
342 if (!index.isValid()) { |
|
343 qDebug() << "notes: NotesFavoriteView::markNoteAsTodo <--"; |
|
344 |
|
345 return; |
|
346 } |
|
347 ulong noteId = index.data(NotesNamespace::IdRole).value<qulonglong> (); |
|
348 if (!noteId) { |
|
349 qDebug() << "notes: NotesFavoriteView::markNoteAsTodo <--"; |
|
350 |
|
351 return; |
|
352 } |
|
353 // Get the entry details. |
|
354 AgendaEntry entry = mAgendaUtil->fetchById(noteId); |
|
355 |
|
356 if (entry.isNull()) { |
|
357 qDebug() << "notes: NotesFavoriteView::markNoteAsTodo <--"; |
|
358 |
|
359 // Entry invalid. |
|
360 return; |
|
361 } |
|
362 |
|
363 // Here change the type of modified note and destroy the noteeditor and |
|
364 // construct the to-do editor. |
|
365 entry.setType(AgendaEntry::TypeTodo); |
|
366 |
|
367 QDateTime dueDateTime; |
|
368 dueDateTime.setDate(QDate::currentDate()); |
|
369 dueDateTime.setTime(QTime::fromString("12:00 am", "hh:mm ap")); |
|
370 |
|
371 entry.setStartAndEndTime(dueDateTime, dueDateTime); |
|
372 |
|
373 entry.setSummary(entry.description().left(80)); |
|
374 |
|
375 if (80 > entry.description().length()) { |
|
376 entry.setDescription(""); |
|
377 } |
|
378 |
|
379 // Remove favourite if marked so. |
|
380 entry.setFavourite(0); |
|
381 |
|
382 // Set the status of the to-do. |
|
383 entry.setStatus(AgendaEntry::TodoNeedsAction); |
|
384 |
|
385 // First clone the todoEntry for the new type. |
|
386 mAgendaUtil->cloneEntry(entry, AgendaEntry::TypeTodo); |
|
387 |
|
388 // Delete the old entry. |
|
389 mAgendaUtil->deleteEntry(entry.id()); |
|
390 |
|
391 qDebug() << "notes : NotesFavoriteView::markNoteAsTodo <--"; |
|
392 } |
|
393 |
|
394 /*! |
|
395 Slot to handle the signal editingCompleted by the notes editor. |
|
396 |
|
397 \param status Boolean value indicating whether the note was saved or not. |
|
398 |
|
399 \sa NotesEditor. |
|
400 */ |
|
401 void NotesFavoriteView::handleEditingCompleted(bool status) |
|
402 { |
|
403 qDebug() << "notes: NotesFavoriteView::handleEditingCompleted -->"; |
|
404 |
|
405 Q_UNUSED(status) |
|
406 |
|
407 // Cleanup. |
|
408 mNotesEditor->deleteLater(); |
|
409 |
|
410 qDebug() << "notes: NotesFavoriteView::handleEditingCompleted <--"; |
|
411 } |
|
412 |
|
413 /*! |
|
414 Directs the view manager to display the Collections view. |
|
415 */ |
|
416 void NotesFavoriteView::displayCollectionView() |
|
417 { |
|
418 qDebug() << "notes: NotesFavoriteView::displayCollectionView -->"; |
|
419 |
|
420 // Switch to collections view. |
|
421 mAppControllerIf->switchToView(NotesNamespace::NotesCollectionViewId); |
|
422 |
|
423 qDebug() << "notes: NotesFavoriteView::displayCollectionView <--"; |
|
424 } |
|
425 |
|
426 /*! |
|
427 Directs the view manager to display the All notes view. |
|
428 */ |
|
429 void NotesFavoriteView::displayAllNotesView() |
|
430 { |
|
431 qDebug() << "notes: NotesFavoriteView::displayAllNotesView -->"; |
|
432 |
|
433 // Switch to collections view. |
|
434 mAppControllerIf->switchToView(NotesNamespace::NotesMainViewId); |
|
435 |
|
436 qDebug() << "notes: NotesFavoriteView::displayAllNotesView <--"; |
|
437 } |
|
438 |
|
439 /*! |
|
440 Slot to handle the case when the state of an action has changed. |
|
441 */ |
|
442 void NotesFavoriteView::handleActionStateChanged() |
|
443 { |
|
444 qDebug() << "notes: NotesFavoriteView::handleActionStateChanged -->"; |
|
445 |
|
446 mAllNotesAction->setChecked(true); |
|
447 |
|
448 qDebug() << "notes: NotesFavoriteView::handleActionStateChanged <--"; |
|
449 } |
|
450 |
|
451 /*! |
|
452 Handles the orientation changes.Updates the list |
|
453 item when orientation is changed |
|
454 |
|
455 \param orientation Value of the orientation |
|
456 */ |
|
457 void NotesFavoriteView::handleOrientationChanged(Qt::Orientation orientation) |
|
458 { |
|
459 HbListViewItem *prototype = mListView->listItemPrototype(); |
|
460 |
|
461 if (Qt::Horizontal == orientation) { |
|
462 prototype->setStretchingStyle(HbListViewItem::StretchLandscape); |
|
463 |
|
464 // Set the text in landscape mode |
|
465 mAllNotesAction->setText(hbTrId("txt_notes_button_all")); |
|
466 mViewCollectionAction->setText(hbTrId("txt_notes_button_collections")); |
|
467 mAddNoteAction->setText(hbTrId("txt_notes_button_new_note")); |
|
468 } else { |
|
469 prototype->setStretchingStyle(HbListViewItem::NoStretching); |
|
470 |
|
471 // Set empty text in portriat mode so that only icons are visible. |
|
472 mAllNotesAction->setText(""); |
|
473 mViewCollectionAction->setText(""); |
|
474 mAddNoteAction->setText(""); |
|
475 } |
|
476 } |
|
477 |
|
478 // End of file --Don't remove this. |
|
479 |