|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbCore module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include "hbapplication.h" |
|
27 #include "hbapplication_p.h" |
|
28 #include "hbsplashscreen_p.h" |
|
29 #include "hbactivitymanager.h" |
|
30 #include <QTime> |
|
31 #include <QUrl> |
|
32 |
|
33 #if defined(Q_OS_SYMBIAN) |
|
34 #include <qwindowsstyle.h> |
|
35 #include <qsymbianevent.h> |
|
36 #endif // Q_OS_SYMBIAN |
|
37 |
|
38 // ### TODO remove this and do it in mainwindow_p once QGestureManager problems are fixed |
|
39 #ifdef HB_GESTURE_FW |
|
40 #include "hbmousepangesturerecognizer_p.h" |
|
41 #include "hbswipegesturerecognizer_p.h" |
|
42 #include "hbtapgesturerecognizer_p.h" |
|
43 #include "hbtapandholdgesturerecognizer_p.h" |
|
44 #endif |
|
45 |
|
46 /*! |
|
47 @stable |
|
48 @hbcore |
|
49 \class HbApplication |
|
50 \brief The HbApplication class is a place for common functionality. |
|
51 |
|
52 HbApplication class is a place for common functionality. |
|
53 |
|
54 In each and every application using LibHb, the application object is |
|
55 always instantiated in main() before creating any GUI controls. Later |
|
56 when the GUI controls have been created and shown, the control is given |
|
57 to the main event loop of the application: |
|
58 |
|
59 \dontinclude graphicsitemdemo/main.cpp |
|
60 \skip int main( |
|
61 \until HbMainWindow |
|
62 \skip show() |
|
63 \until } |
|
64 |
|
65 To support Hb-widgets with QApplication the actual implementation |
|
66 of HbApplication is available in HbInstance. |
|
67 |
|
68 Unless the Hb::NoSplash flag is passed, the HbApplication constructor will |
|
69 try to show a suitable splash screen for the application. On some platforms |
|
70 there will be no splash screens available at all and thus nothing will be |
|
71 shown. |
|
72 |
|
73 Applications that support the 'activities' concept may check the start-up |
|
74 reason like this: |
|
75 |
|
76 \code |
|
77 HbApplication app(argc, argv); |
|
78 if(app.activateReason() == HbApplication::activity) { |
|
79 // start-up case |
|
80 } else if (app.activateReason() == HbApplication::service) { |
|
81 // service lauch |
|
82 } else { |
|
83 // normal launch |
|
84 } |
|
85 |
|
86 MyActivitiesEngine logic; |
|
87 // connect to the application signal |
|
88 QObject::connect(&app, SIGNAL(activate()), &logic, SLOT(openActivity())); |
|
89 \endcode |
|
90 |
|
91 When new activity needs to be activated signal is emited. Application might |
|
92 observe it and start correct handling to return to saved state. Logic should |
|
93 check what is the activity id and data to return to correct state. |
|
94 |
|
95 \sa QApplication |
|
96 */ |
|
97 |
|
98 /*! |
|
99 \fn void HbApplication::activate() |
|
100 |
|
101 This signal is emitted when some activity needs to be shown. |
|
102 */ |
|
103 |
|
104 static int& preInitApp(int &argc) |
|
105 { |
|
106 // This function contains code that needs to be executed before |
|
107 // the QApplication constructor. |
|
108 |
|
109 #if defined(Q_OS_SYMBIAN) |
|
110 // Disable legacy screen furniture. |
|
111 QApplication::setAttribute(Qt::AA_S60DontConstructApplicationPanes); |
|
112 |
|
113 // Temporary solution until Hb specific style is ready. |
|
114 QApplication::setStyle(new QWindowsStyle); |
|
115 #endif //Q_OS_SYMBIAN |
|
116 |
|
117 return argc; |
|
118 } |
|
119 |
|
120 static void initSplash(Hb::ApplicationFlags flags) |
|
121 { |
|
122 if (flags & Hb::NoSplash) { |
|
123 return; |
|
124 } |
|
125 |
|
126 // Show the splash screen (start() also makes sure it is really drawn before |
|
127 // continuing with anything else). |
|
128 |
|
129 HbSplash::Flags splashFlags = HbSplash::Default; |
|
130 if (flags & Hb::SplashFixedVertical) { |
|
131 splashFlags |= HbSplash::FixedVertical; |
|
132 } else if (flags & Hb::SplashFixedHorizontal) { |
|
133 splashFlags |= HbSplash::FixedHorizontal; |
|
134 } |
|
135 |
|
136 #ifdef Q_OS_SYMBIAN |
|
137 QTime t; |
|
138 t.start(); |
|
139 #endif |
|
140 |
|
141 HbSplashScreen::start(splashFlags); |
|
142 |
|
143 #ifdef Q_OS_SYMBIAN |
|
144 qDebug("[hbsplash] %d ms", t.elapsed()); |
|
145 #endif |
|
146 } |
|
147 |
|
148 static void initialize() |
|
149 { |
|
150 // ### TODO remove this and enable HbMainWindowPrivate::initGestures once |
|
151 // the QGestureManager problems are fixed. |
|
152 #ifdef HB_GESTURE_FW |
|
153 QGestureRecognizer::unregisterRecognizer(Qt::TapGesture); |
|
154 QGestureRecognizer::unregisterRecognizer(Qt::TapAndHoldGesture); |
|
155 QGestureRecognizer::unregisterRecognizer(Qt::PanGesture); |
|
156 QGestureRecognizer::unregisterRecognizer(Qt::SwipeGesture); |
|
157 |
|
158 QGestureRecognizer::registerRecognizer(new HbTapGestureRecognizer); |
|
159 QGestureRecognizer::registerRecognizer(new HbTapAndHoldGestureRecognizer); |
|
160 QGestureRecognizer::registerRecognizer(new HbMousePanGestureRecognizer); |
|
161 QGestureRecognizer::registerRecognizer(new HbSwipeGestureRecognizer); |
|
162 #endif |
|
163 } |
|
164 |
|
165 /*! |
|
166 Constructs the application with \a argc and \a argv. |
|
167 */ |
|
168 HbApplication::HbApplication(int &argc, char *argv[], Hb::ApplicationFlags flags) |
|
169 : QApplication(preInitApp(argc), argv) |
|
170 { |
|
171 initSplash(flags); // must be the first thing we do here |
|
172 |
|
173 d_ptr = new HbApplicationPrivate(this); |
|
174 |
|
175 // No expensive operations allowed here, prefer performing such |
|
176 // initialization as part of HbMainWindow's delayed construction instead. |
|
177 |
|
178 initialize(); |
|
179 } |
|
180 |
|
181 #if defined(Q_WS_S60) |
|
182 HbApplication::HbApplication(QApplication::QS60MainApplicationFactory factory, |
|
183 int &argc, char *argv[], Hb::ApplicationFlags flags) |
|
184 : QApplication(factory, preInitApp(argc), argv) |
|
185 { |
|
186 initSplash(flags); // must be the first thing we do here |
|
187 |
|
188 d_ptr = new HbApplicationPrivate(this); |
|
189 |
|
190 // No expensive operations allowed here, prefer performing such |
|
191 // initialization as part of HbMainWindow's delayed construction instead. |
|
192 |
|
193 initialize(); |
|
194 } |
|
195 #endif // Q_WS_S60 |
|
196 |
|
197 /*! |
|
198 Destructor. |
|
199 */ |
|
200 HbApplication::~HbApplication() |
|
201 { |
|
202 hideSplash(); |
|
203 } |
|
204 |
|
205 /*! |
|
206 Hides the splash screen if it is visible. Normally this is done by |
|
207 HbMainWindow but if an application does not create any HbMainWindow |
|
208 instances then there may be a need to hide the splash screen manually. |
|
209 */ |
|
210 void HbApplication::hideSplash() |
|
211 { |
|
212 HbSplashScreen::destroy(); |
|
213 } |
|
214 |
|
215 #if defined(Q_WS_S60) |
|
216 #include <w32std.h> |
|
217 #include <coecntrl.h> |
|
218 #include <QDesktopWidget> |
|
219 #include <QStringList> |
|
220 #include <hbinstance.h> |
|
221 #include <hbinstance_p.h> |
|
222 #include <hbdeviceprofile.h> |
|
223 #include <hbdeviceprofilemanager_p.h> |
|
224 #include <hbs60events.h> |
|
225 #include <hbtextitem_p.h> |
|
226 #include <hbiconitem_p.h> |
|
227 #include <hbtoucharea_p.h> |
|
228 #include "hbgraphicsscene_p.h" |
|
229 |
|
230 #ifdef BUILD_HB_INTERNAL |
|
231 static void forceRefresh() |
|
232 { |
|
233 foreach (HbMainWindow *window, hbInstance->allMainWindows()) { |
|
234 QEvent event(QEvent::WindowActivate); |
|
235 QApplication::sendEvent(window, &event); |
|
236 } |
|
237 } |
|
238 #endif |
|
239 |
|
240 /*! |
|
241 Handles the S60 events. |
|
242 */ |
|
243 bool HbApplication::symbianEventFilter(const QSymbianEvent *event) |
|
244 { |
|
245 if (event->type() != QSymbianEvent::WindowServerEvent) { |
|
246 return QApplication::symbianEventFilter(event); |
|
247 } |
|
248 const TWsEvent *aEvent = event->windowServerEvent(); |
|
249 switch (aEvent->Type()) { |
|
250 // In case of EEventScreenDeviceChanged-event, the current screen |
|
251 // ratio is checked and orientation is set accordingly. |
|
252 case EEventScreenDeviceChanged:{ |
|
253 |
|
254 QList<HbMainWindow*> windows = hbInstance->allMainWindows(); |
|
255 RWindow *win = static_cast<RWindow *>(windows.at(0)->effectiveWinId()->DrawableWindow()); |
|
256 |
|
257 TSize rWinSize; |
|
258 if (win) |
|
259 rWinSize = win->Size(); |
|
260 |
|
261 // fix for emulator / changing modes |
|
262 QSize nSize( (int)rWinSize.iWidth, (int)rWinSize.iHeight ); |
|
263 foreach (HbMainWindow* w, windows) { |
|
264 w->resize(nSize); |
|
265 } |
|
266 |
|
267 |
|
268 } |
|
269 return false; //continue handling in QApplication::s60ProcessEvent |
|
270 case KChangeDirection:{ |
|
271 TUint8* dataptr = aEvent->EventData(); |
|
272 switch(*dataptr){ |
|
273 case 0: |
|
274 HbApplication::setLayoutDirection(Qt::LeftToRight); |
|
275 break; |
|
276 case 1: |
|
277 HbApplication::setLayoutDirection(Qt::RightToLeft); |
|
278 break; |
|
279 default: |
|
280 qWarning("HbApplication::s60EventFilter: Unknown layout direction received"); |
|
281 break; |
|
282 } |
|
283 } |
|
284 return false; |
|
285 case KChangeOrientation:{ |
|
286 TUint8* dataptr = aEvent->EventData(); |
|
287 switch(*dataptr){ |
|
288 case 0: |
|
289 hbInstance->setOrientation(Qt::Vertical); |
|
290 break; |
|
291 case 1: |
|
292 hbInstance->setOrientation(Qt::Horizontal); |
|
293 break; |
|
294 default: |
|
295 qWarning("HbApplication::s60EventFilter: Unknown orientation received"); |
|
296 break; |
|
297 } |
|
298 } |
|
299 return false; |
|
300 case KChangeDeviceProfile:{ |
|
301 TUint8* dataptr = aEvent->EventData(); |
|
302 QStringList names = HbDeviceProfile::profileNames(); |
|
303 if(*dataptr > names.count() - 1){ |
|
304 qWarning("HbApplication::s60EventFilter: Unknown device profile received"); |
|
305 }else{ |
|
306 HbDeviceProfile profile(names.value(*dataptr)); |
|
307 HbDeviceProfileManager::select(profile); |
|
308 HbInstancePrivate::d_ptr()->setOrientation(profile.orientation(),false); |
|
309 } |
|
310 } |
|
311 return false; |
|
312 #ifdef BUILD_HB_INTERNAL |
|
313 case KChangeTouchAreaVis:{ |
|
314 TUint8* dataptr = aEvent->EventData(); |
|
315 HbTouchAreaPrivate::setOutlineDrawing(*dataptr == 1); |
|
316 forceRefresh(); |
|
317 } |
|
318 return false; |
|
319 case KChangeTextItemVis:{ |
|
320 TUint8* dataptr = aEvent->EventData(); |
|
321 HbTextItemPrivate::outlinesEnabled = *dataptr == 1; |
|
322 forceRefresh(); |
|
323 } |
|
324 return false; |
|
325 case KChangeIconItemVis:{ |
|
326 TUint8* dataptr = aEvent->EventData(); |
|
327 HbIconItemPrivate::outlinesEnabled = *dataptr == 1; |
|
328 forceRefresh(); |
|
329 } |
|
330 return false; |
|
331 case KChangeFpsCounterVis:{ |
|
332 TUint8* dataptr = aEvent->EventData(); |
|
333 HbGraphicsScenePrivate::fpsCounterEnabled = *dataptr == 1; |
|
334 forceRefresh(); |
|
335 } |
|
336 return false; |
|
337 #endif |
|
338 default: |
|
339 return QApplication::symbianEventFilter(event); |
|
340 } |
|
341 } |
|
342 |
|
343 #endif // Q_WS_S60 |
|
344 |
|
345 HbApplicationPrivate::HbApplicationPrivate(HbApplication *parent) |
|
346 : QObject(parent), q_ptr(parent), mActivateReason(Hb::ActivationReasonNormal) |
|
347 { |
|
348 mActivityManager = new HbActivityManager(this); |
|
349 connect(mActivityManager, SIGNAL(activityRequested(QString)), this, SLOT(prepareActivityData(QString))); |
|
350 mActivityManager->parseCommandLine(qApp->arguments(), mActivateReason, mActivateId, mActivateParams); |
|
351 } |
|
352 |
|
353 HbApplicationPrivate::~HbApplicationPrivate() |
|
354 { |
|
355 } |
|
356 |
|
357 QVariant HbApplicationPrivate::activateData() |
|
358 { |
|
359 if (!mActivateId.isNull() && !mActivateData.isValid()) { |
|
360 mActivateData = mActivityManager->activityData(mActivateId); |
|
361 } |
|
362 return mActivateData; |
|
363 } |
|
364 |
|
365 void HbApplicationPrivate::prepareActivityData(const QString &activityId) |
|
366 { |
|
367 mActivateReason = Hb::ActivationReasonActivity; |
|
368 mActivateId = activityId; |
|
369 mActivateData = QVariant(); |
|
370 mActivateParams = QVariantHash(); |
|
371 |
|
372 emit q_ptr->activate(); |
|
373 } |
|
374 |
|
375 /*! |
|
376 Returns instance of class responsible for activities handling. |
|
377 */ |
|
378 HbActivityManager *HbApplication::activityManager() |
|
379 { |
|
380 Q_D(HbApplication); |
|
381 return d->mActivityManager; |
|
382 } |
|
383 |
|
384 /*! |
|
385 Returns activation parameters parsed from activation URI. |
|
386 */ |
|
387 QVariantHash HbApplication::activateParams() const |
|
388 { |
|
389 Q_D(const HbApplication); |
|
390 return d->mActivateParams; |
|
391 } |
|
392 |
|
393 /*! |
|
394 Returns activate reason. |
|
395 */ |
|
396 Hb::ActivationReason HbApplication::activateReason() const |
|
397 { |
|
398 Q_D(const HbApplication); |
|
399 return d->mActivateReason; |
|
400 } |
|
401 |
|
402 /*! |
|
403 Last activated activity id. |
|
404 */ |
|
405 QString HbApplication::activateId() const |
|
406 { |
|
407 Q_D(const HbApplication); |
|
408 return d->mActivateId; |
|
409 } |
|
410 |
|
411 /*! |
|
412 Last activated activity data. |
|
413 */ |
|
414 QVariant HbApplication::activateData() |
|
415 { |
|
416 Q_D(HbApplication); |
|
417 return d->activateData(); |
|
418 } |