44 mBackAction(NULL), |
42 mBackAction(NULL), |
45 mExtensionManager(NULL), |
43 mExtensionManager(NULL), |
46 mMbListModel(NULL), |
44 mMbListModel(NULL), |
47 mServiceViewId(NmUiViewNone), |
45 mServiceViewId(NmUiViewNone), |
48 mForegroundService(false), |
46 mForegroundService(false), |
49 mUtilities(NULL) |
47 mEffects(NULL), |
|
48 mAttaManager(NULL), |
|
49 mSettingsViewLauncher(NULL), |
|
50 mViewReady(false) |
50 { |
51 { |
51 // Create network access manager and cache for application use. |
52 // Create network access manager and cache for application use. |
52 mNetManager = new NmViewerViewNetManager(); |
53 mNetManager = new NmViewerViewNetManager(); |
53 QNetworkDiskCache *cache = new QNetworkDiskCache(); |
54 QNetworkDiskCache *cache = new QNetworkDiskCache(); |
54 cache->setCacheDirectory(NMUI_CACHE_DIR); |
55 cache->setCacheDirectory(QDesktopServices::storageLocation(QDesktopServices::CacheLocation)); |
55 cache->setMaximumCacheSize(nmCacheSize); |
|
56 mNetManager->setCache(cache); |
56 mNetManager->setCache(cache); |
57 |
57 |
58 // TEMPORARY WORKAROUND TO PREVENT PANIC User panic 66, where there is |
58 // TEMPORARY WORKAROUND TO PREVENT PANIC User panic 66, where there is |
59 // a PushL call to cleanup stack without any TRAP. |
59 // a PushL call to cleanup stack without any TRAP. |
60 #ifdef Q_OS_SYMBIAN |
60 #ifdef Q_OS_SYMBIAN |
62 #else |
62 #else |
63 mUiEngine = NmUiEngine::instance(); |
63 mUiEngine = NmUiEngine::instance(); |
64 #endif |
64 #endif |
65 createMainWindow(); |
65 createMainWindow(); |
66 |
66 |
|
67 // attachment manager can be shared between viewer and editor, ownership in application class |
|
68 mAttaManager = new NmAttachmentManager(*mUiEngine); |
|
69 |
67 #ifndef NM_WINS_ENV |
70 #ifndef NM_WINS_ENV |
68 mSendServiceInterface = |
71 mSendServiceInterface = |
69 new NmSendServiceInterface(NmSendServiceName, NULL, *mUiEngine, this); |
72 new NmSendServiceInterface(NmSendServiceName, NULL, *mUiEngine, this); |
70 mSendServiceInterface2 = |
73 mSendServiceInterface2 = |
71 new NmSendServiceInterface(emailInterfaceNameSend, NULL, *mUiEngine, this); |
74 new NmSendServiceInterface(emailFullServiceNameSend, NULL, *mUiEngine, this); |
72 mMailboxServiceInterface = |
75 mMailboxServiceInterface = |
73 new NmMailboxServiceInterface(NULL, *mUiEngine, this); |
76 new NmMailboxServiceInterface(NULL, *mUiEngine, this); |
74 mViewerServiceInterface = |
77 mViewerServiceInterface = |
75 new NmViewerServiceInterface(NULL, this, *mUiEngine); |
78 new NmViewerServiceInterface(NULL, this, *mUiEngine); |
76 #endif |
79 #endif |
77 mUtilities = new NmUtilities(); |
80 |
|
81 mEffects = new NmUiEffects(*mMainWindow); |
78 } |
82 } |
79 |
83 |
80 /*! |
84 /*! |
81 Destructor |
85 Destructor |
82 */ |
86 */ |
132 HbStyleLoader::registerFilePath(":nmviewerheader.css"); |
138 HbStyleLoader::registerFilePath(":nmviewerheader.css"); |
133 |
139 |
134 // Create main window |
140 // Create main window |
135 mMainWindow = new HbMainWindow(); |
141 mMainWindow = new HbMainWindow(); |
136 |
142 |
|
143 // Connect to lazy loading signal |
|
144 QObject::connect(mMainWindow, SIGNAL(viewReady ()), |
|
145 this, SLOT(viewReady())); |
|
146 |
137 // Create extension manager |
147 // Create extension manager |
138 mExtensionManager = new NmUiExtensionManager(); |
148 mExtensionManager = new NmUiExtensionManager(); |
139 |
149 |
140 // Create view stack |
150 // Create view stack |
141 mViewStack = new QStack<NmBaseView*>; |
151 mViewStack = new QStack<NmBaseView*>; |
142 |
152 |
143 // Create back action and connect it to popView() |
153 // Create back action and connect it to popView() |
144 if (mMainWindow) { |
154 if (mMainWindow) { |
145 mBackAction = new HbAction(Hb::BackNaviAction,this); |
155 mBackAction = new HbAction(Hb::BackNaviAction,this); |
146 connect(mBackAction, SIGNAL(triggered()), this, SLOT(popView())); |
156 connect(mBackAction, SIGNAL(triggered()), this, SLOT(popView())); |
147 // Show main window |
157 // Show mainwindow |
148 mMainWindow->show(); |
158 mMainWindow->show(); |
149 } |
159 } |
150 |
160 |
151 // async operation completion related notifications |
161 // async operation completion related notifications |
152 connect( |
162 connect( |
159 // If started as service, there is no need to create views |
169 // If started as service, there is no need to create views |
160 if (!service) { |
170 if (!service) { |
161 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMailboxList); |
171 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMailboxList); |
162 enterNmUiView(startParam); |
172 enterNmUiView(startParam); |
163 } |
173 } |
|
174 |
|
175 // Start to filter main window events to get "end key" event in all possible situations. Using |
|
176 // event() is not enough to catch the event as it is only called if the view widget has the |
|
177 // focus. Note: if key capturing (xqkeycapture.h) is required it is probably best to implement |
|
178 // an own QMainWindow class and do the capturing there, not in the views. |
|
179 mMainWindow->installEventFilter(this); |
|
180 } |
|
181 |
|
182 /*! |
|
183 Slot. React to view ready signal and call |
|
184 current view method. |
|
185 */ |
|
186 void NmApplication::viewReady() |
|
187 { |
|
188 mViewReady = true; |
|
189 if (!mViewStack->isEmpty()) { |
|
190 NmBaseView *currentView = mViewStack->top(); |
|
191 if (currentView){ |
|
192 currentView->viewReady(); |
|
193 } |
|
194 } |
|
195 } |
|
196 |
|
197 /*! |
|
198 Event filter. End key is filtered from the main window and either the view takes case of the |
|
199 or the app is exited by default. |
|
200 */ |
|
201 bool NmApplication::eventFilter(QObject *obj, QEvent *event) |
|
202 { |
|
203 bool consumed = false; |
|
204 |
|
205 if (obj && obj == mMainWindow && event && event->type() == QEvent::KeyPress) { |
|
206 QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); |
|
207 |
|
208 if (keyEvent->key() == Qt::Key_No) { // end key, the "red" key |
|
209 |
|
210 // exit application if no pending operations are on-going |
|
211 } |
|
212 } |
|
213 |
|
214 if (!consumed) { |
|
215 consumed = QObject::eventFilter(obj, event); |
|
216 } |
|
217 |
|
218 return consumed; |
164 } |
219 } |
165 |
220 |
166 /*! |
221 /*! |
167 Push view to view stack |
222 Push view to view stack |
168 */ |
223 */ |
169 void NmApplication::pushView(NmBaseView *view) |
224 void NmApplication::pushView(NmBaseView *newView) |
170 { |
225 { |
171 NMLOG("nmailui: pushView enter"); |
226 NMLOG("nmailui: pushView enter"); |
172 if (view) { |
227 if (newView) { |
173 view->setNavigationAction(mBackAction); |
|
174 NMLOG("nmailui: view exists"); |
228 NMLOG("nmailui: view exists"); |
175 if (!mViewStack->isEmpty()) { |
229 newView->setNavigationAction(mBackAction); |
176 NmBaseView *hideView = mViewStack->top(); |
230 |
177 NMLOG("nmailui: removeView"); |
231 // Store view to be hidden |
178 mMainWindow->removeView(hideView); |
232 NmBaseView *hideView(NULL); |
179 } |
233 if (!mViewStack->isEmpty()) { |
|
234 hideView = mViewStack->top(); |
|
235 } |
|
236 else { |
|
237 // viewReady should be informed immediatelly |
|
238 if (mViewReady) { |
|
239 newView->viewReady(); |
|
240 } |
|
241 } |
|
242 |
|
243 // activate new view |
180 NMLOG("nmailui: addView"); |
244 NMLOG("nmailui: addView"); |
181 mMainWindow->addView(view); |
245 mMainWindow->addView(newView); |
182 mViewStack->push(view); |
246 mViewStack->push(newView); |
183 mActiveViewId=view->nmailViewId(); |
247 mMainWindow->setCurrentView(newView); |
184 |
248 mActiveViewId=newView->nmailViewId(); |
185 //set toolbars orientation |
249 |
186 HbToolBar *tb = view->toolBar(); |
250 // Set toolbars orientation |
|
251 HbToolBar *tb = newView->toolBar(); |
187 if(tb){ |
252 if(tb){ |
188 tb->setOrientation(Qt::Horizontal); |
253 tb->setOrientation(Qt::Horizontal); |
|
254 } |
|
255 |
|
256 // hide old view |
|
257 NMLOG("nmailui: removeView"); |
|
258 if (hideView){ |
|
259 mMainWindow->removeView(hideView); |
189 } |
260 } |
190 |
261 |
191 NMLOG("nmailui: pushView done"); |
262 NMLOG("nmailui: pushView done"); |
192 } |
263 } |
193 } |
264 } |
202 // Get view pointer |
273 // Get view pointer |
203 NmBaseView *view = mViewStack->top(); |
274 NmBaseView *view = mViewStack->top(); |
204 |
275 |
205 // ask view if it's ok to exit |
276 // ask view if it's ok to exit |
206 if (view->okToExitView()) { |
277 if (view->okToExitView()) { |
|
278 NmUiViewId topViewId = view->nmailViewId(); |
|
279 |
|
280 // Prepare for send animation if returing from editor and message has been sent. |
|
281 if (topViewId == NmUiViewMessageEditor && mUiEngine->isSendingMessage()) { |
|
282 mEffects->prepareEffect(NmUiEffects::NmEditorSendMessageAnimation); |
|
283 } |
207 mViewStack->pop(); |
284 mViewStack->pop(); |
208 // Call custom exit function |
285 // Call custom exit function |
209 view->aboutToExitView(); |
286 view->aboutToExitView(); |
210 NmUiViewId topViewId = view->nmailViewId(); |
|
211 // Remove view from stack. |
287 // Remove view from stack. |
212 mMainWindow->removeView(view); |
288 mMainWindow->removeView(view); |
213 |
289 |
214 // if we were in editor and sent a message, pop viewer from stack first |
290 // if we were in editor and sent a message, pop viewer from stack first |
215 // so we can go straight to mail list |
291 // so we can go straight to mail list |
224 |
300 |
225 if (!mViewStack->isEmpty()) { |
301 if (!mViewStack->isEmpty()) { |
226 // Activate next view in stack |
302 // Activate next view in stack |
227 NmBaseView *showView = mViewStack->top(); |
303 NmBaseView *showView = mViewStack->top(); |
228 mMainWindow->addView(showView); |
304 mMainWindow->addView(showView); |
|
305 mMainWindow->setCurrentView(showView); |
229 // Store activated view id |
306 // Store activated view id |
230 mActiveViewId=showView->nmailViewId(); |
307 mActiveViewId=showView->nmailViewId(); |
|
308 // Perform send animation if requested. |
|
309 mEffects->startEffect(NmUiEffects::NmEditorSendMessageAnimation); |
231 } |
310 } |
232 |
311 |
233 delete view; |
312 delete view; |
234 view = NULL; |
313 view = NULL; |
235 |
314 |
290 mForegroundService = mMainWindow->isVisible(); |
369 mForegroundService = mMainWindow->isVisible(); |
291 |
370 |
292 // When the message list is started as a service previous views are removed |
371 // When the message list is started as a service previous views are removed |
293 // from the stack. Open editors are not closed. |
372 // from the stack. Open editors are not closed. |
294 // Also if the view is same than the new one, keep it open (reload the content). |
373 // Also if the view is same than the new one, keep it open (reload the content). |
295 |
374 |
296 // at least one view must remain in the stack |
375 // at least one view must remain in the stack |
297 while (mViewStack->count()>1) { |
376 while (mViewStack->count()>1) { |
298 NmUiViewId topId = mViewStack->top()->nmailViewId(); |
377 NmUiViewId topId = mViewStack->top()->nmailViewId(); |
299 if (topId!=NmUiViewMessageEditor && |
378 if (topId!=NmUiViewMessageEditor && |
300 topId!=NmUiViewMailboxList && |
379 topId!=NmUiViewMailboxList && |
301 topId!=startParam->viewId()) { |
380 topId!=startParam->viewId()) { |
302 popView(); |
381 popView(); |
303 } |
382 } |
304 else { |
383 else { |
305 // Editor or mailbox list in the top. Stop the loop. |
384 // Editor or mailbox list in the top. Stop the loop. |
306 break; |
385 break; |
307 } |
386 } |
308 } |
387 } |
309 } |
388 } |
310 |
389 |
311 // Check whether requested view is already active |
390 // Check whether requested view is already active |
312 // and if so, ask it to reload contents with new start parameter data |
391 // and if so, ask it to reload contents with new start parameter data |
313 // Do not reuse the view if started as service to editor view (ShareUI) |
392 // Do not reuse the view if started as service to editor view (ShareUI) |
314 if (mActiveViewId==startParam->viewId() && |
393 if (mActiveViewId==startParam->viewId() && |
315 (!startParam->service() || mActiveViewId!=NmUiViewMessageEditor)) { |
394 (!startParam->service() || mActiveViewId!=NmUiViewMessageEditor)) { |
327 break; |
406 break; |
328 case NmUiViewMessageList: |
407 case NmUiViewMessageList: |
329 { |
408 { |
330 // Check the topmost view. If it is an editor, do not open |
409 // Check the topmost view. If it is an editor, do not open |
331 // a new mail list view |
410 // a new mail list view |
332 if (startParam->service() && !mViewStack->isEmpty() && |
411 if (startParam->service() && !mViewStack->isEmpty() && |
333 mViewStack->top()->nmailViewId()==NmUiViewMessageEditor) { |
412 mViewStack->top()->nmailViewId()==NmUiViewMessageEditor) { |
334 break; |
413 break; |
335 } |
414 } |
336 NmMessageListModel &messageListModel = mUiEngine->messageListModel( |
415 NmMessageListModel &messageListModel = mUiEngine->messageListModel( |
337 startParam->mailboxId(), startParam->folderId()); |
416 startParam->mailboxId(), startParam->folderId()); |
339 *this, startParam, *mUiEngine, *mMbListModel, messageListModel, |
418 *this, startParam, *mUiEngine, *mMbListModel, messageListModel, |
340 new HbDocumentLoader(mMainWindow)); |
419 new HbDocumentLoader(mMainWindow)); |
341 pushView(msgList); |
420 pushView(msgList); |
342 } |
421 } |
343 break; |
422 break; |
|
423 case NmUiViewMessageSearchList: |
|
424 { |
|
425 // Check the topmost view. If it is an editor, do not open |
|
426 // a new mail search list view. |
|
427 if (startParam->service() && !mViewStack->isEmpty() && |
|
428 mViewStack->top()->nmailViewId() == NmUiViewMessageEditor) { |
|
429 break; |
|
430 } |
|
431 |
|
432 NmMessageListModel &messageListModel = |
|
433 mUiEngine->messageListModel(startParam->mailboxId(), |
|
434 startParam->folderId()); |
|
435 |
|
436 NmMessageSearchListModel &searchListModel = |
|
437 mUiEngine->messageSearchListModel(&messageListModel); |
|
438 |
|
439 NmMessageSearchListView *searchListView = new NmMessageSearchListView( |
|
440 *this, startParam, *mUiEngine, searchListModel, |
|
441 new HbDocumentLoader(mMainWindow)); |
|
442 |
|
443 pushView(searchListView); |
|
444 } |
|
445 break; |
344 case NmUiViewMessageViewer: |
446 case NmUiViewMessageViewer: |
345 pushView(new NmViewerView(*this, startParam, *mUiEngine, mMainWindow)); |
447 pushView(new NmViewerView(*this, startParam, *mUiEngine, |
|
448 mMainWindow, *mAttaManager)); |
346 break; |
449 break; |
347 case NmUiViewMessageEditor: |
450 case NmUiViewMessageEditor: |
348 pushView(new NmEditorView(*this, startParam, *mUiEngine)); |
451 pushView(new NmEditorView(*this, startParam, *mUiEngine)); |
349 break; |
452 break; |
350 default: |
453 default: |
456 /*! |
559 /*! |
457 handles all asynchronous operation's completions at UI level |
560 handles all asynchronous operation's completions at UI level |
458 */ |
561 */ |
459 void NmApplication::handleOperationCompleted(const NmOperationCompletionEvent &event) |
562 void NmApplication::handleOperationCompleted(const NmOperationCompletionEvent &event) |
460 { |
563 { |
461 mUtilities->displayOperationCompletionNote(event); |
564 bool openSettings = NmUtilities::displayOperationCompletionNote(event); |
462 } |
565 if(openSettings) { |
|
566 launchSettings(event.mMailboxId); |
|
567 } |
|
568 } |
|
569 |
|
570 /*! |
|
571 launches settings view of the specified mailbox |
|
572 */ |
|
573 void NmApplication::launchSettings(const NmId &mailboxId) |
|
574 { |
|
575 // create settingslauncher if doesn't exist |
|
576 if(!mSettingsViewLauncher) { |
|
577 mSettingsViewLauncher = new NmSettingsViewLauncher(); |
|
578 } |
|
579 |
|
580 if(mSettingsViewLauncher) { |
|
581 // mailboxname required |
|
582 NmMailboxMetaData *mailboxMetaData = mUiEngine->mailboxById(mailboxId); // no ownership |
|
583 if( mailboxMetaData ) { |
|
584 // launch |
|
585 mSettingsViewLauncher->launchSettingsView(mailboxId, mailboxMetaData->name()); |
|
586 } |
|
587 } |
|
588 } |