28 #include <HbLabel> |
28 #include <HbLabel> |
29 #include <HbAbstractViewItem> |
29 #include <HbAbstractViewItem> |
30 #include <HbAbstractItemView> |
30 #include <HbAbstractItemView> |
31 #include <HbGroupBox> |
31 #include <HbGroupBox> |
32 #include <HbListViewItem> |
32 #include <HbListViewItem> |
|
33 #include <hbapplication> // hbapplication |
|
34 #include <hbactivitymanager> // hbactivitymanager |
33 |
35 |
34 // User includes |
36 // User includes |
35 #include "agendaeventviewer.h" |
37 #include "agendaeventviewer.h" |
36 #include "notesmainview.h" |
38 #include "notesmainview.h" |
37 #include "notescommon.h" |
39 #include "notescommon.h" |
38 #include "notesdocloader.h" |
40 #include "notesdocloader.h" |
39 #include "agendautil.h" |
41 #include "agendautil.h" |
40 #include "notesmodel.h" |
42 #include "notesmodel.h" |
41 #include "notessortfilterproxymodel.h" |
43 #include "notessortfilterproxymodel.h" |
42 #include "noteseditor.h" |
44 #include "noteseditor.h" |
|
45 #include "notescommon.h" // NotesNamespace |
43 |
46 |
44 /*! |
47 /*! |
45 \class NotesMainView |
48 \class NotesMainView |
46 \brief The main view of the notes application. Responsible for displaying |
49 \brief The main view of the notes application. Responsible for displaying |
47 notes and todos. |
50 notes and todos. |
119 SLOT(handleItemLongPressed(HbAbstractViewItem *, const QPointF &))); |
124 SLOT(handleItemLongPressed(HbAbstractViewItem *, const QPointF &))); |
120 connect( |
125 connect( |
121 mNotesModel, SIGNAL(rowAdded(QModelIndex)), |
126 mNotesModel, SIGNAL(rowAdded(QModelIndex)), |
122 this, SLOT(scrollTo(QModelIndex))); |
127 this, SLOT(scrollTo(QModelIndex))); |
123 |
128 |
|
129 // Get the empty list label. |
|
130 mEmptyListLabel = static_cast<HbLabel *> ( |
|
131 mDocLoader->findWidget("emptyListLabel")); |
|
132 mEmptyListLabel->hide(); |
|
133 |
124 // Get the view heading label |
134 // Get the view heading label |
125 mViewHeading = static_cast<HbLabel *> ( |
135 mSubTitle = static_cast<HbGroupBox *>( |
126 mDocLoader->findWidget("viewHeading")); |
136 mDocLoader->findWidget("viewHeading")); |
127 |
137 |
|
138 // Handles the orientation change for list items |
|
139 HbMainWindow *window = hbInstance->allMainWindows().first(); |
|
140 handleOrientationChanged(window->orientation()); |
|
141 connect( |
|
142 window, SIGNAL(orientationChanged(Qt::Orientation)), |
|
143 this, SLOT(handleOrientationChanged(Qt::Orientation))); |
|
144 |
|
145 // Set the graphics size for the icons. |
|
146 HbListViewItem *prototype = mListView->listItemPrototype(); |
|
147 prototype->setGraphicsSize(HbListViewItem::SmallIcon); |
|
148 |
|
149 // Get a pointer to activity Manager |
|
150 HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager(); |
|
151 |
|
152 // clean up any previous versions of this activity from the activity manager. |
|
153 // ignore return value as the first boot would always return a false |
|
154 // bool declared on for debugging purpose |
|
155 bool ok = activityManager->removeActivity(notes); |
|
156 |
|
157 // connect main view for the first time to recieve aboutToQuit signal |
|
158 connect(qobject_cast<HbApplication*>(qApp), SIGNAL(aboutToQuit()), this, SLOT(saveActivity())); |
|
159 |
|
160 } |
|
161 |
|
162 void NotesMainView::setupAfterViewReady() |
|
163 { |
128 // Get the toolbar/menu actions. |
164 // Get the toolbar/menu actions. |
129 mAddNoteAction = static_cast<HbAction *> ( |
165 mAddNoteAction = static_cast<HbAction *> ( |
130 mDocLoader->findObject("newNoteAction")); |
166 mDocLoader->findObject("newNoteAction")); |
131 Q_ASSERT_X( |
167 Q_ASSERT_X( |
132 mAddNoteAction, |
168 mAddNoteAction, |
157 |
193 |
158 connect( |
194 connect( |
159 mViewCollectionAction, SIGNAL(triggered()), |
195 mViewCollectionAction, SIGNAL(triggered()), |
160 this, SLOT(displayCollectionView())); |
196 this, SLOT(displayCollectionView())); |
161 |
197 |
162 mSubTitle = static_cast<HbGroupBox *>( |
|
163 mDocLoader->findWidget("viewHeading")); |
|
164 |
|
165 // Handles the orientation change for list items |
|
166 HbMainWindow *window = hbInstance->allMainWindows().first(); |
|
167 handleOrientationChanged(window->orientation()); |
|
168 connect( |
|
169 window, SIGNAL(orientationChanged(Qt::Orientation)), |
|
170 this, SLOT(handleOrientationChanged(Qt::Orientation))); |
|
171 |
|
172 // Update sub heading text for main view. |
|
173 updateSubTitle(); |
|
174 |
|
175 connect( |
198 connect( |
176 mAgendaUtil, SIGNAL(entryAdded(ulong)), |
199 mAgendaUtil, SIGNAL(entryAdded(ulong)), |
177 this,SLOT(updateSubTitle(ulong))); |
200 this,SLOT(updateSubTitle(ulong))); |
178 connect( |
201 connect( |
179 mAgendaUtil, SIGNAL(entryDeleted(ulong)), |
202 mAgendaUtil, SIGNAL(entryDeleted(ulong)), |
180 this,SLOT(updateSubTitle(ulong))); |
203 this,SLOT(updateSubTitle(ulong))); |
181 connect( |
204 connect( |
182 mAgendaUtil, SIGNAL(entryUpdated(ulong)), |
205 mAgendaUtil, SIGNAL(entryUpdated(ulong)), |
183 this, SLOT(updateSubTitle(ulong))); |
206 this, SLOT(updateSubTitle(ulong))); |
184 |
207 } |
185 // Set the graphics size for the icons. |
208 |
186 HbListViewItem *prototype = mListView->listItemPrototype(); |
209 /* |
187 prototype->setGraphicsSize(HbListViewItem::SmallIcon); |
210 Updates the title text for the first launch |
|
211 */ |
|
212 void NotesMainView::updateTitle() |
|
213 { |
|
214 updateSubTitle(); |
188 } |
215 } |
189 |
216 |
190 /*! |
217 /*! |
191 Slot which gets called when `+ New note' action is triggered from the view |
218 Slot which gets called when `+ New note' action is triggered from the view |
192 toolbar. This is responsible for launching the editor to create a new note. |
219 toolbar. This is responsible for launching the editor to create a new note. |
210 \param index Reference to the QModelIndex representing the view item. |
240 \param index Reference to the QModelIndex representing the view item. |
211 \sa HbAbstractViewItem |
241 \sa HbAbstractViewItem |
212 */ |
242 */ |
213 void NotesMainView::handleItemReleased(const QModelIndex &index) |
243 void NotesMainView::handleItemReleased(const QModelIndex &index) |
214 { |
244 { |
215 // Sanity check. |
245 if(!mIsLongTop) { |
216 if (!index.isValid()) { |
246 // Sanity check. |
217 return; |
247 if (!index.isValid()) { |
218 } |
248 return; |
219 |
249 } |
220 // First get the id of the note and get the corresponding information from |
250 |
221 // agendautil. |
251 // First get the id of the note and get the corresponding information from |
222 ulong noteId = index.data(NotesNamespace::IdRole).value<qulonglong>(); |
252 // agendautil. |
223 |
253 ulong noteId = index.data(NotesNamespace::IdRole).value<qulonglong>(); |
224 if (0 >= noteId) { |
254 |
225 // Something wrong. |
255 if (0 >= noteId) { |
226 return; |
256 // Something wrong. |
227 } |
257 return; |
228 |
258 } |
229 // Get the entry details. |
259 |
230 AgendaEntry entry = mAgendaUtil->fetchById(noteId); |
260 // Get the entry details. |
231 if (entry.isNull()) { |
261 AgendaEntry entry = mAgendaUtil->fetchById(noteId); |
232 // Entry invalid. |
262 if (entry.isNull()) { |
233 return; |
263 // Entry invalid. |
234 } |
264 return; |
235 |
265 } |
236 if(AgendaEntry::TypeTodo == entry.type()) { |
266 |
237 // Construct agenda event viewer. |
267 if(AgendaEntry::TypeTodo == entry.type()) { |
238 mAgendaEventViewer = new AgendaEventViewer(mAgendaUtil, this); |
268 // Construct agenda event viewer. |
239 |
269 mAgendaEventViewer = new AgendaEventViewer(mAgendaUtil, this); |
240 connect( |
270 |
241 mAgendaEventViewer, SIGNAL(viewingCompleted(const QDate)), |
271 connect( |
242 this, SLOT(handleViewingCompleted())); |
272 mAgendaEventViewer, SIGNAL(viewingCompleted(const QDate)), |
243 // Launch agenda event viewer |
273 this, SLOT(handleViewingCompleted())); |
244 mAgendaEventViewer->view( |
274 // Launch agenda event viewer |
245 entry, AgendaEventViewer::ActionEditDelete); |
275 mAgendaEventViewer->view( |
246 }else if(AgendaEntry::TypeNote == entry.type()) { |
276 entry, AgendaEventViewer::ActionEditDelete); |
247 // Construct notes editor. |
277 }else if(AgendaEntry::TypeNote == entry.type()) { |
248 mNotesEditor = new NotesEditor(mAgendaUtil, this); |
278 // Construct notes editor. |
249 connect( |
279 mNotesEditor = new NotesEditor(mAgendaUtil, this); |
250 mNotesEditor, SIGNAL(editingCompleted(bool)), |
280 connect( |
251 this, SLOT(handleEditingCompleted(bool))); |
281 mNotesEditor, SIGNAL(editingCompleted(bool)), |
252 |
282 this, SLOT(handleEditingCompleted(bool))); |
253 // Launch the notes editor with the obtained info. |
283 |
254 mNotesEditor->edit(entry); |
284 // Launch the notes editor with the obtained info. |
|
285 mNotesEditor->edit(entry); |
|
286 } |
|
287 // capture screenshot for future use, if application |
|
288 // is exited/Quit from eventViewer/notesEditor |
|
289 captureScreenShot(true); |
255 } |
290 } |
256 } |
291 } |
257 |
292 |
258 /*! |
293 /*! |
259 Displays a list item specific context menu. |
294 Displays a list item specific context menu. |
264 \sa HbAbstractViewItem, HbListView, HbMenu. |
299 \sa HbAbstractViewItem, HbListView, HbMenu. |
265 */ |
300 */ |
266 void NotesMainView::handleItemLongPressed( |
301 void NotesMainView::handleItemLongPressed( |
267 HbAbstractViewItem *item, const QPointF &coords) |
302 HbAbstractViewItem *item, const QPointF &coords) |
268 { |
303 { |
|
304 mIsLongTop = true; |
269 mSelectedItem = item; |
305 mSelectedItem = item; |
270 |
306 |
271 ulong noteId = item->modelIndex().data( |
307 ulong noteId = item->modelIndex().data( |
272 NotesNamespace::IdRole).value<qulonglong>(); |
308 NotesNamespace::IdRole).value<qulonglong>(); |
273 AgendaEntry entry = mAgendaUtil->fetchById(noteId); |
309 AgendaEntry entry = mAgendaUtil->fetchById(noteId); |
274 |
310 |
275 // Display a context specific menu. |
311 // Display a context specific menu. |
276 HbMenu *contextMenu = new HbMenu(); |
312 HbMenu *contextMenu = new HbMenu(); |
|
313 connect( |
|
314 contextMenu,SIGNAL(aboutToClose()), |
|
315 this, SLOT(handleMenuClosed())); |
|
316 |
277 mOpenAction = |
317 mOpenAction = |
278 contextMenu->addAction(hbTrId("txt_common_menu_open")); |
318 contextMenu->addAction(hbTrId("txt_common_menu_open")); |
279 connect( |
|
280 mOpenAction, SIGNAL(triggered()), |
|
281 this, SLOT(openNote())); |
|
282 |
319 |
283 // Add actions to the context menu. |
320 // Add actions to the context menu. |
284 if (AgendaEntry::TypeTodo == entry.type()) { |
321 if (AgendaEntry::TypeTodo == entry.type()) { |
285 mEditTodoAction = |
322 mEditTodoAction = |
286 contextMenu->addAction(hbTrId("txt_common_menu_edit")); |
323 contextMenu->addAction(hbTrId("txt_common_menu_edit")); |
287 connect( |
|
288 mEditTodoAction, SIGNAL(triggered()), |
|
289 this, SLOT(editTodo())); |
|
290 } |
324 } |
291 |
325 |
292 mDeleteAction = |
326 mDeleteAction = |
293 contextMenu->addAction(hbTrId("txt_common_menu_delete")); |
327 contextMenu->addAction(hbTrId("txt_common_menu_delete")); |
294 connect( |
|
295 mDeleteAction, SIGNAL(triggered()), |
|
296 this, SLOT(deleteNote())); |
|
297 |
328 |
298 if (AgendaEntry::TypeNote == entry.type()) { |
329 if (AgendaEntry::TypeNote == entry.type()) { |
299 if (entry.favourite()) { |
330 if (entry.favourite()) { |
300 mMakeFavouriteAction = contextMenu->addAction( |
331 mMakeFavouriteAction = contextMenu->addAction( |
301 hbTrId("txt_notes_menu_remove_from_favorites")); |
332 hbTrId("txt_notes_menu_remove_from_favorites")); |
302 |
|
303 connect( |
|
304 mMakeFavouriteAction, SIGNAL(triggered()), |
|
305 this, SLOT(markNoteAsFavourite())); |
|
306 |
|
307 } else { |
333 } else { |
308 mMakeFavouriteAction = contextMenu->addAction( |
334 mMakeFavouriteAction = contextMenu->addAction( |
309 hbTrId("txt_notes_menu_mark_as_favorite")); |
335 hbTrId("txt_notes_menu_mark_as_favorite")); |
310 |
|
311 connect( |
|
312 mMakeFavouriteAction, SIGNAL(triggered()), |
|
313 this, SLOT(markNoteAsFavourite())); |
|
314 } |
336 } |
315 |
337 |
316 mMarkTodoAction = |
338 mMarkTodoAction = |
317 contextMenu->addAction( |
339 contextMenu->addAction( |
318 hbTrId("txt_notes_menu_make_it_as_todo_note")); |
340 hbTrId("txt_notes_menu_make_it_as_todo_note")); |
319 connect( |
|
320 mMarkTodoAction, SIGNAL(triggered()), |
|
321 this, SLOT(markNoteAsTodo())); |
|
322 |
341 |
323 } else if (AgendaEntry::TypeTodo == entry.type()) { |
342 } else if (AgendaEntry::TypeTodo == entry.type()) { |
324 if (AgendaEntry::TodoNeedsAction == entry.status()) { |
343 if (AgendaEntry::TodoNeedsAction == entry.status()) { |
325 mTodoStatusAction = contextMenu->addAction( |
344 mTodoStatusAction = contextMenu->addAction( |
326 hbTrId("txt_notes_menu_mark_as_done")); |
345 hbTrId("txt_notes_menu_mark_as_done")); |
327 |
|
328 connect( |
|
329 mTodoStatusAction , SIGNAL(triggered()), |
|
330 this, SLOT(markTodoStatus())); |
|
331 |
|
332 } else if (AgendaEntry::TodoCompleted == entry.status()) { |
346 } else if (AgendaEntry::TodoCompleted == entry.status()) { |
333 mTodoStatusAction = contextMenu->addAction( |
347 mTodoStatusAction = contextMenu->addAction( |
334 hbTrId("txt_notes_menu_mark_as_not_done")); |
348 hbTrId("txt_notes_menu_mark_as_not_done")); |
335 |
|
336 connect( |
|
337 mTodoStatusAction , SIGNAL(triggered()), |
|
338 this, SLOT(markTodoStatus())); |
|
339 } |
349 } |
340 } |
350 } |
341 |
351 |
342 // Show the menu. |
352 // Show the menu. |
343 contextMenu->exec(coords); |
353 contextMenu->open(this, SLOT(selectedMenuAction(HbAction*))); |
344 |
354 contextMenu->setPreferredPos(coords); |
345 } |
355 } |
346 |
356 |
347 /*! |
357 /*! |
348 Slot to delete a selected note. |
358 Slot to delete a selected note. |
349 */ |
359 */ |
616 this, SLOT(handleViewingCompleted(bool))); |
639 this, SLOT(handleViewingCompleted(bool))); |
617 // Launch agenda event viewer |
640 // Launch agenda event viewer |
618 mAgendaEventViewer->view( |
641 mAgendaEventViewer->view( |
619 entry, AgendaEventViewer::ActionEditDelete); |
642 entry, AgendaEventViewer::ActionEditDelete); |
620 } |
643 } |
621 } |
644 // capture screenshot for future use, if application |
|
645 // is exited/Quit from notesEditor/eventViewer |
|
646 captureScreenShot(true); |
|
647 } |
|
648 |
|
649 /*! |
|
650 Slot to handle the selected context menu actions |
|
651 */ |
|
652 void NotesMainView::selectedMenuAction(HbAction *action) |
|
653 { |
|
654 if (action == mOpenAction) { |
|
655 openNote(); |
|
656 } else if (action == mEditTodoAction) { |
|
657 editTodo(); |
|
658 } else if (action == mDeleteAction) { |
|
659 deleteNote(); |
|
660 } else if (action == mMakeFavouriteAction) { |
|
661 markNoteAsFavourite(); |
|
662 } else if (action == mMarkTodoAction) { |
|
663 markNoteAsTodo(); |
|
664 } else if (action == mTodoStatusAction) { |
|
665 markTodoStatus(); |
|
666 } |
|
667 } |
|
668 |
|
669 /*! |
|
670 Slot to handle the context menu closed. |
|
671 */ |
|
672 void NotesMainView::handleMenuClosed() |
|
673 { |
|
674 mIsLongTop = false; |
|
675 } |
|
676 |
|
677 /*! |
|
678 CaptureScreenShot captures screen shot |
|
679 \param captureScreenShot bool to indicate if screenshot needs to be captured |
|
680 */ |
|
681 void NotesMainView::captureScreenShot(bool captureScreenShot) |
|
682 { |
|
683 if (captureScreenShot) // check if screen shot needs to be captured |
|
684 { |
|
685 mScreenShot.clear(); |
|
686 mScreenShot.insert("screenshot", QPixmap::grabWidget(mainWindow(), mainWindow()->rect())); |
|
687 } |
|
688 mIsScreenShotCapruted = captureScreenShot; // set mIsScreenShotCapruted set validity of screenshot |
|
689 } |
|
690 |
|
691 /*! |
|
692 saveActivity saves main view as an activity |
|
693 */ |
|
694 void NotesMainView::saveActivity() |
|
695 { |
|
696 // Get a pointer to activity Manager |
|
697 HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager(); |
|
698 |
|
699 if (!mIsScreenShotCapruted) // check if a valid screenshot is already captured |
|
700 { |
|
701 mScreenShot.clear(); |
|
702 mScreenShot.insert("screenshot", QPixmap::grabWidget(mainWindow(), mainWindow()->rect())); |
|
703 } |
|
704 |
|
705 // save any data necessary to save the state |
|
706 QByteArray serializedActivity; |
|
707 QDataStream stream(&serializedActivity, QIODevice::WriteOnly | QIODevice::Append); |
|
708 stream << NotesNamespace::NotesMainViewId; |
|
709 |
|
710 // add the activity to the activity manager |
|
711 bool ok = activityManager->addActivity(notes, serializedActivity, mScreenShot); |
|
712 if ( !ok ) |
|
713 { |
|
714 qFatal("Add failed" ); |
|
715 } |
|
716 } |
622 // End of file --Don't remove this. |
717 // End of file --Don't remove this. |