|
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: Default implementation of the home screen runtime. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QState> |
|
19 #include <QFinalState> |
|
20 #include <QSignalTransition> |
|
21 #include <QKeyEventTransition> |
|
22 |
|
23 #include <qvaluespacepublisher.h> |
|
24 #include <qservicemanager.h> |
|
25 #include <qservicefilter.h> |
|
26 #include <qserviceinterfacedescriptor.h> |
|
27 |
|
28 #include <HbInstance> |
|
29 |
|
30 #include "homescreendomainpskeys.h" |
|
31 #include "hsdefaultruntime.h" |
|
32 #include "hscontentservice.h" |
|
33 #include "hsshortcutservice.h" |
|
34 #include "hsmenueventtransition.h" |
|
35 #include "hswidgetpositioningonorientationchange.h" |
|
36 #include "hswidgetpositioningonwidgetadd.h" |
|
37 #include "hstest_global.h" |
|
38 |
|
39 QTM_USE_NAMESPACE |
|
40 |
|
41 #ifdef S60APP_KEY |
|
42 int applicationKey = Qt::Key_Launch0; |
|
43 #else |
|
44 int applicationKey = Qt::Key_Any; |
|
45 #endif |
|
46 |
|
47 /*! |
|
48 \class HsDefaultRuntime |
|
49 \ingroup group_hsdefaultruntimeplugin |
|
50 \brief Default implementation of the home screen runtime. |
|
51 Creates an execution context (EC) and populates it with |
|
52 runtime services. States are loaded from state plugins. |
|
53 Each state is given an access to the EC. States |
|
54 are added to a state machine. Finally, the state machine |
|
55 is started. |
|
56 */ |
|
57 |
|
58 /*! |
|
59 Constructs runtime with \a parent as the parent object. |
|
60 */ |
|
61 HsDefaultRuntime::HsDefaultRuntime(QObject *parent) |
|
62 : QStateMachine(parent), |
|
63 mContentService(0), |
|
64 mHomeScreenActive(false), |
|
65 mIdleStateActive(false) |
|
66 { |
|
67 HSTEST_FUNC_ENTRY("HS::HsDefaultRuntime::HsDefaultRuntime"); |
|
68 |
|
69 HsWidgetPositioningOnOrientationChange::setInstance( |
|
70 new HsAdvancedWidgetPositioningOnOrientationChange); |
|
71 |
|
72 HsWidgetPositioningOnWidgetAdd::setInstance( |
|
73 new HsAnchorPointInBottomRight); |
|
74 |
|
75 createContentServiceParts(); |
|
76 createStates(); |
|
77 assignServices(); |
|
78 |
|
79 QCoreApplication::instance()->installEventFilter(this); |
|
80 HSTEST_FUNC_EXIT("HS::HsDefaultRuntime::HsDefaultRuntime"); |
|
81 } |
|
82 |
|
83 /*! |
|
84 Destructor. |
|
85 */ |
|
86 HsDefaultRuntime::~HsDefaultRuntime() |
|
87 { |
|
88 HsWidgetPositioningOnOrientationChange::setInstance(0); |
|
89 } |
|
90 |
|
91 /*! |
|
92 \fn void HsDefaultRuntime::stopStateMachine() |
|
93 Emission of this signal initiates a transition to the final state. |
|
94 */ |
|
95 |
|
96 /*! |
|
97 \copydoc QObject::eventFilter(QObject *watched, QEvent *event) |
|
98 */ |
|
99 bool HsDefaultRuntime::eventFilter(QObject *watched, QEvent *event) |
|
100 { |
|
101 Q_UNUSED(watched); |
|
102 |
|
103 switch (event->type()) { |
|
104 case QEvent::ApplicationActivate: |
|
105 { |
|
106 qDebug() << "HsDefaultRuntime::eventFilter: QEvent::ApplicationActivate"; |
|
107 mHomeScreenActive = true; |
|
108 updatePSKeys(); |
|
109 } |
|
110 break; |
|
111 case QEvent::ApplicationDeactivate: |
|
112 { |
|
113 qDebug() << "HsDefaultRuntime::eventFilter: QEvent::ApplicationDeactivate"; |
|
114 mHomeScreenActive = false; |
|
115 updatePSKeys(); |
|
116 } |
|
117 break; |
|
118 } |
|
119 |
|
120 return QStateMachine::eventFilter(watched, event); |
|
121 } |
|
122 |
|
123 /*! |
|
124 Creates content service parts. |
|
125 */ |
|
126 void HsDefaultRuntime::createContentServiceParts() |
|
127 { |
|
128 HSTEST_FUNC_ENTRY("HS::HsDefaultRuntime::createContentServiceParts"); |
|
129 |
|
130 mContentService = new HsContentService(this); |
|
131 |
|
132 HSTEST_FUNC_EXIT("HS::HsDefaultRuntime::createContentServiceParts"); |
|
133 } |
|
134 |
|
135 /*! |
|
136 Creates states. |
|
137 */ |
|
138 void HsDefaultRuntime::createStates() |
|
139 { |
|
140 HSTEST_FUNC_ENTRY("HS::HsDefaultRuntime::createStates"); |
|
141 |
|
142 QFinalState *finalState = new QFinalState(); |
|
143 addState(finalState); |
|
144 |
|
145 QState *guiRootState = new QState(); |
|
146 addState(guiRootState); |
|
147 |
|
148 guiRootState->addTransition(this, SIGNAL(event_exit()), finalState); |
|
149 |
|
150 // Workaround to QtSF bug. Create in stack after the bug is fixed. |
|
151 QServiceManager *manager = new QServiceManager(this); |
|
152 QServiceFilter filter; |
|
153 |
|
154 filter.setInterface("com.nokia.homescreen.state.HsLoadSceneState"); |
|
155 QList<QServiceInterfaceDescriptor> interfaces = manager->findInterfaces(filter); |
|
156 QObject *loadSceneStateObj = manager->loadInterface(interfaces.first().interfaceName()); |
|
157 QState *loadSceneState = qobject_cast<QState *>(loadSceneStateObj); |
|
158 loadSceneState->setParent(guiRootState); |
|
159 loadSceneState->setObjectName(interfaces.first().interfaceName()); |
|
160 |
|
161 filter.setInterface("com.nokia.homescreen.state.HsIdleState"); |
|
162 interfaces = manager->findInterfaces(filter); |
|
163 QObject *idleStateObj = manager->loadInterface(interfaces.first().interfaceName()); |
|
164 QState *idleState = qobject_cast<QState *>(idleStateObj); |
|
165 idleState->setParent(guiRootState); |
|
166 idleState->setObjectName(interfaces.first().interfaceName()); |
|
167 connect(idleState, SIGNAL(entered()), SLOT(onIdleStateEntered())); |
|
168 connect(idleState, SIGNAL(exited()), SLOT(onIdleStateExited())); |
|
169 |
|
170 loadSceneState->addTransition( |
|
171 loadSceneState, SIGNAL(event_idle()), idleState); |
|
172 |
|
173 //menu state |
|
174 QState *menuParallelState = new QState( |
|
175 QState::ParallelStates, guiRootState); |
|
176 QState *menuRootState = new QState(menuParallelState); |
|
177 |
|
178 filter.setInterface("com.nokia.homescreen.state.HsAppLibraryState"); |
|
179 interfaces = manager->findInterfaces(filter); |
|
180 QObject *appLibraryStateObj = manager->loadInterface(interfaces.first().interfaceName()); |
|
181 QState *appLibraryState = qobject_cast<QState *>(appLibraryStateObj); |
|
182 appLibraryState->setParent(menuRootState); |
|
183 appLibraryState->setObjectName(interfaces.first().interfaceName()); |
|
184 menuRootState->setInitialState(appLibraryState); |
|
185 |
|
186 filter.setInterface("com.nokia.homescreen.state.HsMenuWorkerState"); |
|
187 interfaces = manager->findInterfaces(filter); |
|
188 QObject *menuWorkerStateObj = manager->loadInterface(interfaces.first().interfaceName()); |
|
189 QState *menuWorkerState = qobject_cast<QState *>(menuWorkerStateObj); |
|
190 menuWorkerState->setParent(menuParallelState); |
|
191 menuWorkerState->setObjectName(interfaces.first().interfaceName()); |
|
192 |
|
193 // root state transitions |
|
194 idleState->addTransition(idleState, SIGNAL(event_applicationLibrary()), menuRootState); |
|
195 appLibraryState->addTransition( |
|
196 appLibraryState, SIGNAL(toHomescreenState()), idleState); |
|
197 // opening shortcut to Application Library |
|
198 HsMenuEventTransition *idleToAppLibTransition = |
|
199 new HsMenuEventTransition(HsMenuEvent::OpenApplicationLibrary, |
|
200 idleState, appLibraryState); |
|
201 idleState->addTransition(idleToAppLibTransition); |
|
202 |
|
203 HsMenuEventTransition *appLibToIdleTransition = |
|
204 new HsMenuEventTransition( |
|
205 HsMenuEvent::OpenHomeScreen, appLibraryState, idleState); |
|
206 appLibraryState->addTransition(appLibToIdleTransition); |
|
207 |
|
208 HbMainWindow *window = hbInstance->allMainWindows().at(0); |
|
209 |
|
210 // key driven transition from idle to menu |
|
211 QKeyEventTransition *idleToMenuRootTransition = |
|
212 new QKeyEventTransition( |
|
213 window, QEvent::KeyRelease, applicationKey, idleState); |
|
214 idleToMenuRootTransition->setTargetState(menuRootState); |
|
215 idleState->addTransition(idleToMenuRootTransition); |
|
216 // key driven transition from menu to idle |
|
217 QKeyEventTransition *menuToIdleTransition = |
|
218 new QKeyEventTransition( |
|
219 window, QEvent::KeyRelease, applicationKey, idleState); |
|
220 menuToIdleTransition->setTargetState(idleState); |
|
221 menuRootState->addTransition(menuToIdleTransition); |
|
222 |
|
223 // transitions to child states |
|
224 // opening shortcut to a colleciton |
|
225 QList<QState *> collectionStates = |
|
226 appLibraryState-> |
|
227 findChildren<QState *> |
|
228 ("homescreen.nokia.com/state/applibrarystate/collectionstate"); |
|
229 qDebug( |
|
230 "Found %d \"collectionstate\" children for Application Library State", |
|
231 collectionStates.count()); |
|
232 if (collectionStates.count()) { |
|
233 HsMenuEventTransition *idleToCollectionTransition = |
|
234 new HsMenuEventTransition(HsMenuEvent::OpenCollection, |
|
235 idleState, collectionStates[0]); |
|
236 idleState->addTransition(idleToCollectionTransition); |
|
237 } |
|
238 |
|
239 guiRootState->setInitialState(loadSceneState); |
|
240 setInitialState(guiRootState); |
|
241 |
|
242 HSTEST_FUNC_EXIT("HS::HsDefaultRuntime::createStates"); |
|
243 } |
|
244 |
|
245 /*! |
|
246 Assigns services to states based on value of property HS_SERVICES_REGISTRATION_KEY. |
|
247 */ |
|
248 void HsDefaultRuntime::assignServices() |
|
249 { |
|
250 HSTEST_FUNC_ENTRY("HS::HsDefaultRuntime::assignServices"); |
|
251 |
|
252 QList<QState*> children = findChildren<QState*>(); |
|
253 foreach (QState *state, children) { |
|
254 QList<QVariant> services = state->property(HS_SERVICES_REGISTRATION_KEY).toList(); |
|
255 foreach (const QVariant &service, services) { |
|
256 QString name = service.toString(); |
|
257 qDebug() << "Assign service:" << name << "\n to " << state->objectName(); |
|
258 if (name == CONTENT_SERVICE_KEY) { |
|
259 state->setProperty(name.toAscii().data(), qVariantFromValue(mContentService)); |
|
260 } else if (name == SHORTCUT_SERVICE_KEY) { |
|
261 state->setProperty(name.toAscii().data(), |
|
262 qVariantFromValue(HsShortcutService::instance(this))); |
|
263 } else { |
|
264 qWarning() << "WARNING: Service " << name << " is unknown"; |
|
265 } |
|
266 } |
|
267 } |
|
268 |
|
269 HSTEST_FUNC_EXIT("HS::HsDefaultRuntime::assignServices"); |
|
270 } |
|
271 |
|
272 /*! |
|
273 |
|
274 */ |
|
275 void HsDefaultRuntime::updatePSKeys() |
|
276 { |
|
277 QValueSpacePublisher publisher(HsStatePSKeyPath); |
|
278 |
|
279 if (mHomeScreenActive && mIdleStateActive){ |
|
280 qDebug() << "HsDefaultRuntime::updatePSKeys: EHomeScreenIdleState"; |
|
281 publisher.setValue(HsStatePSKeySubPath, EHomeScreenIdleState); |
|
282 } |
|
283 else{ |
|
284 qDebug() << "HsDefaultRuntime::updatePSKeys: EHomeScreenInactive"; |
|
285 publisher.setValue(HsStatePSKeySubPath, EHomeScreenInactive); |
|
286 } |
|
287 } |
|
288 |
|
289 /*! |
|
290 |
|
291 */ |
|
292 void HsDefaultRuntime::onIdleStateEntered() |
|
293 { |
|
294 mIdleStateActive = true; |
|
295 updatePSKeys(); |
|
296 } |
|
297 |
|
298 /*! |
|
299 |
|
300 */ |
|
301 void HsDefaultRuntime::onIdleStateExited() |
|
302 { |
|
303 mIdleStateActive = false; |
|
304 updatePSKeys(); |
|
305 } |