|
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: Definition file for class NotesViewManager. |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <qglobal.h> |
|
20 #include <QtGui> |
|
21 #include <HbMainWindow> |
|
22 #include <HbView> |
|
23 #include <HbInstance> |
|
24 #include <HbListView> |
|
25 #include <HbMessageBox> |
|
26 #include <HbAction> |
|
27 #include <hbapplication> // hbapplication |
|
28 #include <hbactivitymanager> // hbactivitymanager |
|
29 |
|
30 // User includes |
|
31 #include "notesviewmanager.h" |
|
32 #include "notesmainview.h" |
|
33 #include "notescollectionview.h" |
|
34 #include "notestodoview.h" |
|
35 #include "notesfavoriteview.h" |
|
36 #include "notesnoteview.h" |
|
37 #include "notesdocloader.h" |
|
38 #include "notescommon.h" |
|
39 #include "notesmodel.h" |
|
40 #include "notessortfilterproxymodel.h" |
|
41 #include <agendautil.h> |
|
42 #include "OstTraceDefinitions.h" |
|
43 #ifdef OST_TRACE_COMPILER_IN_USE |
|
44 #include "notesviewmanagerTraces.h" |
|
45 #endif |
|
46 |
|
47 |
|
48 /*! |
|
49 \class NotesViewManager |
|
50 |
|
51 This is the heart of the notes application. This is responsible for |
|
52 managing the notes views and owning the agenda interface object. |
|
53 This also is the source for the notes list model. |
|
54 */ |
|
55 /*! |
|
56 Constructor. |
|
57 |
|
58 \param controller A reference to the object of NotesAppController. |
|
59 */ |
|
60 NotesViewManager::NotesViewManager( |
|
61 NotesAppControllerIf &controllerIf, QObject *parent) |
|
62 :QObject(parent), |
|
63 mAppControllerIf(controllerIf) |
|
64 { |
|
65 OstTraceFunctionEntry0( NOTESVIEWMANAGER_NOTESVIEWMANAGER_ENTRY ); |
|
66 HbMainWindow *window = hbInstance->allMainWindows().first(); |
|
67 |
|
68 mAgendaUtil = mAppControllerIf.agendaUtil(); |
|
69 |
|
70 // Check the Application Startup reason from Activity Manager |
|
71 int activityReason = qobject_cast<HbApplication*>(qApp)->activateReason(); |
|
72 |
|
73 // Check if application is started from an application |
|
74 if (Hb::ActivationReasonActivity == activityReason) { |
|
75 // Application is started from an activity |
|
76 // extract activity data |
|
77 QVariant data = qobject_cast<HbApplication*>(qApp)->activateData(); |
|
78 // Restore state from activity data |
|
79 QByteArray serializedModel = data.toByteArray(); |
|
80 QDataStream stream(&serializedModel, QIODevice::ReadOnly); |
|
81 int viewId; |
|
82 stream >> viewId; // read stream into an int |
|
83 |
|
84 // Check if viewId is main view. |
|
85 if (NotesNamespace::NotesMainViewId == viewId) { |
|
86 // Load MainView |
|
87 loadNotesMainView(); |
|
88 } else if (NotesNamespace::NotesCollectionViewId == viewId) { |
|
89 // Check if the viewId is collective view |
|
90 //no implementation yet, UI Specs not available |
|
91 } |
|
92 } else { |
|
93 // application started by either service framework or normally |
|
94 // Load the main view at the start up. |
|
95 loadNotesMainView(); |
|
96 } |
|
97 |
|
98 connect( |
|
99 mAgendaUtil, SIGNAL(instanceViewCreationCompleted(int)), |
|
100 this,SLOT(handleInstanceViewCreationCompleted(int))); |
|
101 |
|
102 // Delay loading of other views till main view is loaded. |
|
103 connect( |
|
104 window, SIGNAL(viewReady()), |
|
105 this, SLOT(loadOtherViews())); |
|
106 OstTraceFunctionExit0( NOTESVIEWMANAGER_NOTESVIEWMANAGER_EXIT ); |
|
107 } |
|
108 |
|
109 /*! |
|
110 Destructor. |
|
111 */ |
|
112 NotesViewManager::~NotesViewManager() |
|
113 { |
|
114 OstTraceFunctionEntry0( DUP1_NOTESVIEWMANAGER_NOTESVIEWMANAGER_ENTRY ); |
|
115 // No implementation yet |
|
116 OstTraceFunctionExit0( DUP1_NOTESVIEWMANAGER_NOTESVIEWMANAGER_EXIT ); |
|
117 } |
|
118 |
|
119 /*! |
|
120 Switches to view specified by viewId. |
|
121 |
|
122 \param viewId View Id. |
|
123 */ |
|
124 void NotesViewManager::switchToView(NotesNamespace::NotesViewIds viewId) |
|
125 { |
|
126 OstTraceFunctionEntry0( NOTESVIEWMANAGER_SWITCHTOVIEW_ENTRY ); |
|
127 HbMainWindow *window = hbInstance->allMainWindows().first(); |
|
128 |
|
129 switch (viewId) { |
|
130 case NotesNamespace::NotesMainViewId: |
|
131 { |
|
132 window->removeView(window->currentView()); |
|
133 window->addView(mMainView); |
|
134 window->setCurrentView(mMainView); |
|
135 mMainView->captureScreenShot(false); |
|
136 break; |
|
137 } |
|
138 case NotesNamespace::NotesCollectionViewId: |
|
139 { |
|
140 if (mMainView) { |
|
141 if (mMainView == window->currentView()) { |
|
142 mMainView->captureScreenShot(true); |
|
143 } |
|
144 } |
|
145 window->removeView(window->currentView()); |
|
146 window->addView(mCollectionView); |
|
147 window->setCurrentView(mCollectionView); |
|
148 break; |
|
149 } |
|
150 case NotesNamespace::NotesTodoViewId: |
|
151 { |
|
152 if (mMainView) { |
|
153 if (mMainView == window->currentView()) { |
|
154 mMainView->captureScreenShot(true); |
|
155 } |
|
156 } |
|
157 window->removeView(window->currentView()); |
|
158 window->addView(mTodoView); |
|
159 window->setCurrentView(mTodoView); |
|
160 break; |
|
161 } |
|
162 case NotesNamespace::NotesFavoritesViewId: |
|
163 { |
|
164 if (mMainView) { |
|
165 if (mMainView == window->currentView()) { |
|
166 mMainView->captureScreenShot(true); |
|
167 } |
|
168 } |
|
169 window->removeView(window->currentView()); |
|
170 window->addView(mFavoriteView); |
|
171 window->setCurrentView(mFavoriteView); |
|
172 break; |
|
173 } |
|
174 case NotesNamespace::NotesNoteViewId: |
|
175 { |
|
176 if (mMainView) { |
|
177 if (mMainView == window->currentView()) { |
|
178 mMainView->captureScreenShot(true); |
|
179 } |
|
180 } |
|
181 window->removeView(window->currentView()); |
|
182 window->addView(mNoteView); |
|
183 window->setCurrentView(mNoteView); |
|
184 break; |
|
185 } |
|
186 default: |
|
187 break; |
|
188 } |
|
189 OstTraceFunctionExit0( NOTESVIEWMANAGER_SWITCHTOVIEW_EXIT ); |
|
190 } |
|
191 |
|
192 /*! |
|
193 Loads the notes main view. |
|
194 */ |
|
195 void NotesViewManager::loadNotesMainView() |
|
196 { |
|
197 OstTraceFunctionEntry0( NOTESVIEWMANAGER_LOADNOTESMAINVIEW_ENTRY ); |
|
198 bool loadSuccess; |
|
199 |
|
200 // Construct the document loader instance |
|
201 NotesDocLoader *docLoader = new NotesDocLoader(); |
|
202 |
|
203 // Load the application xml. |
|
204 docLoader->load(NOTES_MAIN_VIEW_XML, &loadSuccess); |
|
205 Q_ASSERT_X( |
|
206 loadSuccess, |
|
207 "notesviewmanager.cpp", |
|
208 "Unable to load the main view app xml"); |
|
209 |
|
210 // Find the main view. |
|
211 mMainView = static_cast<NotesMainView *> ( |
|
212 docLoader->findWidget(NOTES_MAIN_VIEW)); |
|
213 Q_ASSERT_X( |
|
214 mMainView, "notesviewmanager.cpp", "Unable to find the main view."); |
|
215 // Setup the view. |
|
216 mMainView->setupView(mAppControllerIf, docLoader); |
|
217 // Connect to main view signal for entry deletion. |
|
218 connect ( |
|
219 mMainView, SIGNAL(deleteEntry(ulong)), |
|
220 this, SLOT(deleteEntryFromView(ulong))); |
|
221 |
|
222 // Set the main view to the window |
|
223 hbInstance->allMainWindows().first()->addView(mMainView); |
|
224 OstTraceFunctionExit0( NOTESVIEWMANAGER_LOADNOTESMAINVIEW_EXIT ); |
|
225 } |
|
226 |
|
227 /*! |
|
228 Loads the notes collection view. |
|
229 */ |
|
230 void NotesViewManager::loadNotesCollectionView() |
|
231 { |
|
232 OstTraceFunctionEntry0( NOTESVIEWMANAGER_LOADNOTESCOLLECTIONVIEW_ENTRY ); |
|
233 bool loadSuccess; |
|
234 |
|
235 // Construct the document loader instance |
|
236 NotesDocLoader *docLoader = new NotesDocLoader(); |
|
237 |
|
238 // Load the application xml. |
|
239 docLoader->load(NOTES_COLLECTION_VIEW_XML, &loadSuccess); |
|
240 |
|
241 // Find the collection view. |
|
242 mCollectionView = static_cast<NotesCollectionView *> ( |
|
243 docLoader->findWidget(NOTES_COLLECTION_VIEW)); |
|
244 // Setup the view. |
|
245 mCollectionView->setupView(mAppControllerIf, docLoader); |
|
246 OstTraceFunctionExit0( NOTESVIEWMANAGER_LOADNOTESCOLLECTIONVIEW_EXIT ); |
|
247 } |
|
248 |
|
249 /*! |
|
250 Loads the to-do view. |
|
251 */ |
|
252 void NotesViewManager::loadTodoView() |
|
253 { |
|
254 OstTraceFunctionEntry0( NOTESVIEWMANAGER_LOADTODOVIEW_ENTRY ); |
|
255 |
|
256 bool loadSuccess; |
|
257 |
|
258 // Construct the document loader instance |
|
259 NotesDocLoader *docLoader = new NotesDocLoader(); |
|
260 |
|
261 // Load the application xml. |
|
262 docLoader->load(NOTES_TODO_VIEW_XML, &loadSuccess); |
|
263 |
|
264 // Find the to-do view. |
|
265 mTodoView = static_cast<NotesTodoView *> ( |
|
266 docLoader->findWidget(NOTES_TODO_VIEW)); |
|
267 // Setup the view. |
|
268 mTodoView->setupView(mAppControllerIf, docLoader); |
|
269 // Connect to to-do view signal for entry deletion. |
|
270 connect ( |
|
271 mTodoView, SIGNAL(deleteEntry(ulong)), |
|
272 this, SLOT(deleteEntryFromView(ulong))); |
|
273 OstTraceFunctionExit0( NOTESVIEWMANAGER_LOADTODOVIEW_EXIT ); |
|
274 } |
|
275 |
|
276 /*! |
|
277 Loads the favorites view. |
|
278 */ |
|
279 void NotesViewManager::loadFavoritesView() |
|
280 { |
|
281 OstTraceFunctionEntry0( NOTESVIEWMANAGER_LOADFAVORITESVIEW_ENTRY ); |
|
282 bool loadSuccess; |
|
283 |
|
284 // Construct the document loader instance |
|
285 NotesDocLoader *docLoader = new NotesDocLoader(); |
|
286 |
|
287 // Load the application xml. |
|
288 docLoader->load(NOTES_FAVORITES_VIEW_XML, &loadSuccess); |
|
289 |
|
290 // Find the favorites view. |
|
291 mFavoriteView = static_cast<NotesFavoriteView *> ( |
|
292 docLoader->findWidget(NOTES_FAVORITES_VIEW)); |
|
293 // Setup the view. |
|
294 mFavoriteView->setupView(mAppControllerIf, docLoader); |
|
295 |
|
296 // Connect to favourite view signal for entry deletion. |
|
297 connect ( |
|
298 mFavoriteView, SIGNAL(deleteEntry(ulong)), |
|
299 this, SLOT(deleteEntryFromView(ulong))); |
|
300 OstTraceFunctionExit0( NOTESVIEWMANAGER_LOADFAVORITESVIEW_EXIT ); |
|
301 } |
|
302 |
|
303 /*! |
|
304 Loads the recent notes view. |
|
305 */ |
|
306 void NotesViewManager::loadNoteView() |
|
307 { |
|
308 OstTraceFunctionEntry0( NOTESVIEWMANAGER_LOADNOTEVIEW_ENTRY ); |
|
309 bool loadSuccess; |
|
310 |
|
311 // Construct the document loader instance |
|
312 NotesDocLoader *docLoader = new NotesDocLoader(); |
|
313 |
|
314 // Load the application xml. |
|
315 docLoader->load(NOTES_NOTE_VIEW_XML, &loadSuccess); |
|
316 |
|
317 // Find the note view. |
|
318 mNoteView = static_cast<NotesNoteView *> ( |
|
319 docLoader->findWidget(NOTES_NOTE_VIEW)); |
|
320 // Setup the view. |
|
321 mNoteView->setupView(mAppControllerIf, docLoader); |
|
322 |
|
323 connect( |
|
324 mNoteView, SIGNAL(deleteEntry(ulong)), |
|
325 this, SLOT(deleteEntryFromView(ulong))); |
|
326 OstTraceFunctionExit0( NOTESVIEWMANAGER_LOADNOTEVIEW_EXIT ); |
|
327 } |
|
328 |
|
329 /*! |
|
330 Loads other views from the docml file. |
|
331 */ |
|
332 void NotesViewManager::loadOtherViews() |
|
333 { |
|
334 OstTraceFunctionEntry0( NOTESVIEWMANAGER_LOADOTHERVIEWS_ENTRY ); |
|
335 mMainView->setupAfterViewReady(); |
|
336 |
|
337 // Load the collection view. |
|
338 loadNotesCollectionView(); |
|
339 // Load the to-do view. |
|
340 loadTodoView(); |
|
341 // Load the favorites view. |
|
342 loadFavoritesView(); |
|
343 // Load the recent notes view. |
|
344 loadNoteView(); |
|
345 |
|
346 // Disconnect the signal viewReady as all the views are loaded. |
|
347 HbMainWindow *window = hbInstance->allMainWindows().first(); |
|
348 disconnect( |
|
349 window, SIGNAL(viewReady()), |
|
350 this, SLOT(loadOtherViews())); |
|
351 OstTraceFunctionExit0( NOTESVIEWMANAGER_LOADOTHERVIEWS_EXIT ); |
|
352 } |
|
353 |
|
354 /*! |
|
355 Delete the entry. |
|
356 */ |
|
357 void NotesViewManager::deleteEntryFromView(ulong entryId) |
|
358 { |
|
359 OstTraceFunctionEntry0( NOTESVIEWMANAGER_DELETEENTRYFROMVIEW_ENTRY ); |
|
360 mEntryId = entryId; |
|
361 HbMessageBox *confirmationQuery = new HbMessageBox( |
|
362 HbMessageBox::MessageTypeQuestion); |
|
363 confirmationQuery->setDismissPolicy(HbDialog::NoDismiss); |
|
364 confirmationQuery->setTimeout(HbDialog::NoTimeout); |
|
365 confirmationQuery->setIconVisible(true); |
|
366 |
|
367 QString displayText; |
|
368 QString x; |
|
369 AgendaEntry entry = mAgendaUtil->fetchById(entryId); |
|
370 if (AgendaEntry::TypeTodo == entry.type()) { |
|
371 displayText += hbTrId("txt_notes_info_delete_todo_note"); |
|
372 } else { |
|
373 displayText += hbTrId("txt_notes_info_delete_note"); |
|
374 } |
|
375 |
|
376 confirmationQuery->setText(displayText); |
|
377 |
|
378 // Remove the default actions. |
|
379 QList<QAction *> defaultActions = confirmationQuery->actions(); |
|
380 for (int index=0;index<defaultActions.count();index++) { |
|
381 confirmationQuery->removeAction(defaultActions[index]); |
|
382 } |
|
383 defaultActions.clear(); |
|
384 |
|
385 // Add delete and cancel actions |
|
386 mDeleteAction = new HbAction(hbTrId("txt_notes_button_dialog_delete")); |
|
387 mCancelAction = new HbAction(hbTrId("txt_common_button_cancel")); |
|
388 |
|
389 confirmationQuery->addAction(mDeleteAction); |
|
390 confirmationQuery->addAction(mCancelAction); |
|
391 |
|
392 confirmationQuery->open(this, SLOT(selectedAction(HbAction*))); |
|
393 OstTraceFunctionExit0( NOTESVIEWMANAGER_DELETEENTRYFROMVIEW_EXIT ); |
|
394 } |
|
395 |
|
396 /*! |
|
397 Slot to handle the delete action |
|
398 */ |
|
399 void NotesViewManager::selectedAction(HbAction *action) |
|
400 { |
|
401 OstTraceFunctionEntry0( NOTESVIEWMANAGER_SELECTEDACTION_ENTRY ); |
|
402 if (action == mDeleteAction) { |
|
403 // Delete the given note. |
|
404 mAgendaUtil->deleteEntry(mEntryId); |
|
405 } |
|
406 OstTraceFunctionExit0( NOTESVIEWMANAGER_SELECTEDACTION_EXIT ); |
|
407 } |
|
408 |
|
409 /*! |
|
410 Slot to handle instance view creation complete. |
|
411 */ |
|
412 void NotesViewManager::handleInstanceViewCreationCompleted(int status) |
|
413 { |
|
414 OstTraceFunctionEntry0( NOTESVIEWMANAGER_HANDLEINSTANCEVIEWCREATIONCOMPLETED_ENTRY ); |
|
415 Q_UNUSED(status) |
|
416 |
|
417 // Update the title for main view. |
|
418 mMainView->updateTitle(); |
|
419 |
|
420 // Populate collections view. |
|
421 mCollectionView->populateListView(); |
|
422 |
|
423 // Update the title for to-do view. |
|
424 mTodoView->updateTitle(); |
|
425 |
|
426 // Update the plain notes view. |
|
427 mNoteView->updateNoteView(); |
|
428 |
|
429 // Update the favorites view. |
|
430 mFavoriteView->updateFavoriteView(); |
|
431 |
|
432 // Need to emit this signal after the view is fully constructed & populated |
|
433 // with actual data and ready to be used. So entry view & instance view |
|
434 // needs to be created so that a new entry can also be created. Finally |
|
435 // NotesApplication object needs to emit applicationReady Signal. |
|
436 emit appReady(); |
|
437 OstTraceFunctionExit0( NOTESVIEWMANAGER_HANDLEINSTANCEVIEWCREATIONCOMPLETED_EXIT ); |
|
438 } |
|
439 |
|
440 // End of file --Don't remove this. |