|
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 * |
|
16 */ |
|
17 |
|
18 #include "nmuiheaders.h" |
|
19 #ifdef Q_OS_SYMBIAN |
|
20 #include <e32base.h> |
|
21 #else |
|
22 #define NM_WINS_ENV |
|
23 #endif |
|
24 |
|
25 static const qreal nmCacheSize = 2097152; |
|
26 |
|
27 /*! |
|
28 \class NmApplication |
|
29 \brief Application class, creates main window and handles view switching |
|
30 */ |
|
31 |
|
32 /*! |
|
33 Constructor |
|
34 */ |
|
35 NmApplication::NmApplication(QObject *parent) |
|
36 :QObject(parent), |
|
37 mMainWindow(NULL), |
|
38 mViewStack(NULL), |
|
39 mActiveViewId(NmUiViewNone), |
|
40 mUiEngine(NULL), |
|
41 mBackAction(NULL), |
|
42 mExtensionManager(NULL), |
|
43 mMbListModel(NULL), |
|
44 mServiceViewId(NmUiViewNone) |
|
45 { |
|
46 // Create network access manager and cache for application use. |
|
47 mNetManager = new NmViewerViewNetManager(); |
|
48 QNetworkDiskCache *cache = new QNetworkDiskCache(); |
|
49 cache->setMaximumCacheSize(nmCacheSize); |
|
50 mNetManager->setCache(cache); |
|
51 |
|
52 // TEMPORARY WORKAROUND TO PREVENT PANIC User panic 66, where there is |
|
53 // a PushL call to cleanup stack without any TRAP. |
|
54 #ifdef Q_OS_SYMBIAN |
|
55 TRAP_IGNORE(mUiEngine = NmUiEngine::instance()); |
|
56 #else |
|
57 mUiEngine = NmUiEngine::instance(); |
|
58 #endif |
|
59 createMainWindow(); |
|
60 |
|
61 #ifndef NM_WINS_ENV |
|
62 mSendServiceInterface = |
|
63 new NmSendServiceInterface(NULL, *mUiEngine, this); |
|
64 mMailboxServiceInterface = |
|
65 new NmMailboxServiceInterface(NULL, *mUiEngine, this); |
|
66 mViewerServiceInterface = |
|
67 new NmViewerServiceInterface(NULL, this, *mUiEngine); |
|
68 #endif |
|
69 } |
|
70 |
|
71 /*! |
|
72 Destructor |
|
73 */ |
|
74 NmApplication::~NmApplication() |
|
75 { |
|
76 #ifndef NM_WINS_ENV |
|
77 delete mSendServiceInterface; |
|
78 delete mMailboxServiceInterface; |
|
79 delete mViewerServiceInterface; |
|
80 #endif |
|
81 |
|
82 resetViewStack(); |
|
83 delete mViewStack; |
|
84 NmIcons::freeIcons(); |
|
85 NmUiEngine::releaseInstance(mUiEngine); |
|
86 mUiEngine = NULL; |
|
87 delete mBackAction; |
|
88 delete mExtensionManager; |
|
89 if (mNetManager){ |
|
90 if (mNetManager->cache()){ |
|
91 mNetManager->cache()->clear(); |
|
92 } |
|
93 delete mNetManager; |
|
94 mNetManager=NULL; |
|
95 } |
|
96 } |
|
97 |
|
98 /*! |
|
99 Main application window creation |
|
100 */ |
|
101 void NmApplication::createMainWindow() |
|
102 { |
|
103 NMLOG("nmailui: createMainWindow enter"); |
|
104 |
|
105 #ifndef NM_WINS_ENV |
|
106 bool service = XQServiceUtil::isService(); |
|
107 if (service && !XQServiceUtil::isEmbedded()) { |
|
108 // If started as service, keep it hidden until everything is initialised |
|
109 // In embedded mode, the client app should not get hidden |
|
110 XQServiceUtil::toBackground(true); |
|
111 } |
|
112 #else |
|
113 bool service = false; |
|
114 #endif |
|
115 |
|
116 // Register custom widget files |
|
117 HbStyleLoader::registerFilePath(":nmmessagelistviewitem.widgetml"); |
|
118 HbStyleLoader::registerFilePath(":nmmessagelistviewitem.css"); |
|
119 HbStyleLoader::registerFilePath(":nmviewerheader.widgetml"); |
|
120 HbStyleLoader::registerFilePath(":nmviewerheader.css"); |
|
121 |
|
122 // Create main window |
|
123 mMainWindow = new HbMainWindow(); |
|
124 mMainWindow->show(); |
|
125 |
|
126 // Create extension manager |
|
127 mExtensionManager = new NmUiExtensionManager(); |
|
128 |
|
129 // Create view stack |
|
130 mViewStack = new QStack<NmBaseView*>; |
|
131 |
|
132 // Create back action and connect it to popView() |
|
133 if (mMainWindow) { |
|
134 mBackAction = new HbAction(Hb::BackNaviAction,this); |
|
135 connect(mBackAction, SIGNAL(triggered()), this, SLOT(popView())); |
|
136 } |
|
137 |
|
138 mMbListModel = &mUiEngine->mailboxListModel(); |
|
139 |
|
140 // Start application to mailbox view |
|
141 // If started as service, there is no need to create views |
|
142 if (!service) { |
|
143 NmUiStartParam *startParam = new NmUiStartParam(NmUiViewMailboxList); |
|
144 enterNmUiView(startParam); |
|
145 } |
|
146 } |
|
147 |
|
148 /*! |
|
149 Push view to view stack |
|
150 */ |
|
151 void NmApplication::pushView(NmBaseView *view) |
|
152 { |
|
153 NMLOG("nmailui: pushView enter"); |
|
154 if (view) { |
|
155 view->setNavigationAction(mBackAction); |
|
156 NMLOG("nmailui: view exists"); |
|
157 if (!mViewStack->isEmpty()) { |
|
158 NmBaseView *hideView = mViewStack->top(); |
|
159 NMLOG("nmailui: removeView"); |
|
160 mMainWindow->removeView(hideView); |
|
161 } |
|
162 NMLOG("nmailui: addView"); |
|
163 mMainWindow->addView(view); |
|
164 mViewStack->push(view); |
|
165 mActiveViewId=view->nmailViewId(); |
|
166 |
|
167 //set toolbars orientation |
|
168 HbToolBar *tb = view->toolBar(); |
|
169 if(tb){ |
|
170 tb->setOrientation(Qt::Horizontal); |
|
171 } |
|
172 |
|
173 NMLOG("nmailui: pushView done"); |
|
174 } |
|
175 } |
|
176 |
|
177 /*! |
|
178 Pop view from view stack. View object is deleted. |
|
179 */ |
|
180 void NmApplication::popView() |
|
181 { |
|
182 NMLOG("nmailui: popView enter"); |
|
183 if (mViewStack->size() > 0) { |
|
184 // Get view pointer |
|
185 NmBaseView *view = mViewStack->top(); |
|
186 |
|
187 // ask view if it's ok to exit |
|
188 if (view->okToExitView()) { |
|
189 mViewStack->pop(); |
|
190 // Call custom exit function |
|
191 view->aboutToExitView(); |
|
192 NmUiViewId topViewId = view->nmailViewId(); |
|
193 // Remove view from stack. |
|
194 mMainWindow->removeView(view); |
|
195 |
|
196 if (!mViewStack->isEmpty()) { |
|
197 // Activate next view in stack |
|
198 NmBaseView *showView = mViewStack->top(); |
|
199 mMainWindow->addView(showView); |
|
200 // Store activated view id |
|
201 mActiveViewId=showView->nmailViewId(); |
|
202 } |
|
203 |
|
204 delete view; |
|
205 view = NULL; |
|
206 |
|
207 #ifndef NM_WINS_ENV |
|
208 // If view was started as service, move the app now to the background |
|
209 if (mServiceViewId == topViewId) { |
|
210 mServiceViewId = NmUiViewNone; |
|
211 |
|
212 // if started as embedded, do not hide the app |
|
213 if (!XQServiceUtil::isEmbedded()) { |
|
214 XQServiceUtil::toBackground(true); |
|
215 } |
|
216 } |
|
217 #endif |
|
218 } |
|
219 } |
|
220 |
|
221 // If the view stack is now empty quit the app |
|
222 // This happens also when the app has been started as a service |
|
223 if (mViewStack->size()==0) { |
|
224 exitApplication(); |
|
225 } |
|
226 } |
|
227 |
|
228 /*! |
|
229 Reset view stack. Remove and destroy view objects. |
|
230 */ |
|
231 void NmApplication::resetViewStack() |
|
232 { |
|
233 NMLOG("nmailui: resetViewStack enter"); |
|
234 if (mViewStack && !mViewStack->isEmpty()) { |
|
235 int viewCount = mViewStack->count(); |
|
236 // Pop and destroy all views |
|
237 for (int i=0;i<viewCount;i++) { |
|
238 NmBaseView *view = mViewStack->pop(); |
|
239 mMainWindow->removeView(view); |
|
240 delete view; |
|
241 } |
|
242 mActiveViewId=NmUiViewNone; |
|
243 } |
|
244 } |
|
245 |
|
246 /*! |
|
247 Function activates view based on viewId parameter. |
|
248 If requested view is already open, it is requested to reload. |
|
249 Otherwise view object is created and pushed to view stack |
|
250 */ |
|
251 void NmApplication::enterNmUiView(NmUiStartParam* startParam) |
|
252 { |
|
253 // Check the validity of start parameter object |
|
254 if (startParam) { |
|
255 |
|
256 // Check whether requested view is already active |
|
257 // and if so, ask it to reload contents with new start parameter data |
|
258 // Do not reuse the view if started as service (ShareUI or Launch API) |
|
259 if (mActiveViewId==startParam->viewId() && !startParam->service()) { |
|
260 mViewStack->top()->reloadViewContents(startParam); |
|
261 } |
|
262 else { |
|
263 switch (startParam->viewId()) { |
|
264 case NmUiViewMailboxList: |
|
265 { |
|
266 NmMailboxListView *mbListView = new NmMailboxListView( |
|
267 *this, startParam, *mUiEngine, |
|
268 *mMbListModel, new HbDocumentLoader(mMainWindow)); |
|
269 pushView(mbListView); |
|
270 } |
|
271 break; |
|
272 case NmUiViewMessageList: |
|
273 { |
|
274 NmMessageListModel &messageListModel = mUiEngine->messageListModel( |
|
275 startParam->mailboxId(), startParam->folderId()); |
|
276 NmMessageListView *msgList =new NmMessageListView( |
|
277 *this, startParam, *mUiEngine, *mMbListModel, messageListModel, |
|
278 new HbDocumentLoader(mMainWindow)); |
|
279 pushView(msgList); |
|
280 } |
|
281 break; |
|
282 case NmUiViewMessageViewer: |
|
283 pushView(new NmViewerView(*this, startParam, *mUiEngine, mMainWindow)); |
|
284 break; |
|
285 case NmUiViewMessageEditor: |
|
286 pushView(new NmEditorView(*this, startParam, *mUiEngine)); |
|
287 break; |
|
288 default: |
|
289 // Reset view stack and exit application |
|
290 delete startParam; |
|
291 resetViewStack(); |
|
292 break; |
|
293 } |
|
294 |
|
295 if (startParam->service()) { |
|
296 // Store the view id that was launched as service |
|
297 mServiceViewId = mActiveViewId; |
|
298 } |
|
299 } |
|
300 } |
|
301 } |
|
302 |
|
303 /*! |
|
304 Function can be used from views to exit the application |
|
305 View stack is cleared. Views can connect exit menu |
|
306 selection to this slot. |
|
307 */ |
|
308 void NmApplication::exitApplication() |
|
309 { |
|
310 NMLOG("NmApplication::exitApplication"); |
|
311 #ifndef NM_WINS_ENV |
|
312 delete mSendServiceInterface; |
|
313 mSendServiceInterface = NULL; |
|
314 delete mMailboxServiceInterface; |
|
315 mMailboxServiceInterface = NULL; |
|
316 delete mViewerServiceInterface; |
|
317 mViewerServiceInterface = NULL; |
|
318 #endif |
|
319 resetViewStack(); |
|
320 // Do housekeeping if needed. |
|
321 qApp->quit(); |
|
322 } |
|
323 |
|
324 /*! |
|
325 Exit the application in the next event loop |
|
326 */ |
|
327 void NmApplication::delayedExitApplication() |
|
328 { |
|
329 NMLOG("NmApplication::delayedExitApplication"); |
|
330 // Exit the application in the next event loop |
|
331 QTimer::singleShot(0, this, SLOT(exitApplication())); |
|
332 } |
|
333 |
|
334 /*! |
|
335 Getter for main window instance. |
|
336 */ |
|
337 HbMainWindow* NmApplication::mainWindow() |
|
338 { |
|
339 return mMainWindow; |
|
340 } |
|
341 |
|
342 /*! |
|
343 Getter for main UI extension manager |
|
344 */ |
|
345 NmUiExtensionManager& NmApplication::extManager() |
|
346 { |
|
347 return *mExtensionManager; |
|
348 } |
|
349 |
|
350 /*! |
|
351 Getter for network access manager |
|
352 */ |
|
353 NmViewerViewNetManager* NmApplication::networkAccessManager() |
|
354 { |
|
355 return mNetManager; |
|
356 } |
|
357 |
|
358 /*! |
|
359 screen size. Function returns curtent screen size |
|
360 */ |
|
361 QSize NmApplication::screenSize() |
|
362 { |
|
363 QSize ret(0,0); |
|
364 if (mMainWindow){ |
|
365 HbDeviceProfile currentP = HbDeviceProfile::current(); |
|
366 HbDeviceProfile altP(currentP.alternateProfileName()); |
|
367 QSize curPSize = currentP.logicalSize(); |
|
368 QSize altPSize = altP.logicalSize(); |
|
369 if (mMainWindow->orientation()==Qt::Horizontal){ |
|
370 // Get wide profile size in landscape |
|
371 if (curPSize.width()>altPSize.width()){ |
|
372 ret = curPSize; |
|
373 } |
|
374 else{ |
|
375 ret = altPSize; |
|
376 } |
|
377 } |
|
378 else { |
|
379 // Get narrow profile size in portrait |
|
380 if (curPSize.width()<altPSize.width()){ |
|
381 ret = curPSize; |
|
382 } |
|
383 else{ |
|
384 ret = altPSize; |
|
385 } |
|
386 } |
|
387 } |
|
388 return ret; |
|
389 } |