|
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: Menu Application Library state. |
|
15 * |
|
16 */ |
|
17 #include <qsignaltransition.h> |
|
18 #include <qhistorystate.h> |
|
19 |
|
20 #include <hbmainwindow.h> |
|
21 #include <hbview.h> |
|
22 #include <hbaction.h> |
|
23 #include <hbtoolbar.h> |
|
24 #include <hbinstance.h> |
|
25 #include <hblistview.h> |
|
26 #include <hbsearchpanel.h> |
|
27 #include <hsmenueventtransition.h> |
|
28 |
|
29 #include "hstest_global.h" |
|
30 #include "hsapplibrarystate.h" |
|
31 #include "hsallappsstate.h" |
|
32 #include "hsallcollectionsstate.h" |
|
33 #include "hscollectionstate.h" |
|
34 #include "hsovistorehandler.h" |
|
35 #include "hsmenuview.h" |
|
36 #include "hsmenumodetransition.h" |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 HsAppLibraryState::HsAppLibraryState(QState *parent) : |
|
42 QState(parent), mSecondarySoftkeyAction(0), mAllAppsState(0), |
|
43 mHistoryTransaction(0), mAllCollectionsState(0), mCollectionState(0), |
|
44 mMenuView(HbInstance::instance()->allMainWindows().value(0)) |
|
45 { |
|
46 construct(); |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 HsAppLibraryState::~HsAppLibraryState() |
|
53 { |
|
54 HbMainWindow *const hbW = |
|
55 HbInstance::instance()->allMainWindows().value(0); |
|
56 |
|
57 if (hbW) { |
|
58 hbW->removeView(mMenuView.view()); |
|
59 hbW->removeSoftKeyAction(Hb::SecondarySoftKey, |
|
60 mSecondarySoftkeyAction); |
|
61 } |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 void HsAppLibraryState::construct() |
|
68 { |
|
69 HSMENUTEST_FUNC_ENTRY("HsAppLibraryState::construct"); |
|
70 setObjectName("homescreen.nokia.com/state/applibrarystate"); |
|
71 |
|
72 mSecondarySoftkeyAction = new HbAction(Hb::BackAction, this); |
|
73 connect(mSecondarySoftkeyAction, SIGNAL(triggered()), |
|
74 SIGNAL(toHomescreenState())); |
|
75 |
|
76 mAllAppsState = new HsAllAppsState(mMenuView, this); |
|
77 connect(this, SIGNAL(entered()),mAllAppsState, SLOT(scrollToBeginning())); |
|
78 |
|
79 mAllCollectionsState = new HsAllCollectionsState(mMenuView, this); |
|
80 connect(this, SIGNAL(entered()), |
|
81 mAllCollectionsState, SLOT(scrollToBeginning())); |
|
82 |
|
83 QState *initialState = new QState(this); |
|
84 setInitialState(initialState); |
|
85 |
|
86 mHistoryTransaction = new HsMenuModeTransition( |
|
87 mMenuView, NormalHsMenuMode, mAllAppsState); |
|
88 initialState->addTransition(mHistoryTransaction); |
|
89 initialState->addTransition(new HsMenuModeTransition( |
|
90 mMenuView, AddHsMenuMode, mAllAppsState)); |
|
91 |
|
92 mCollectionState = new HsCollectionState(mMenuView, this); |
|
93 connect(mCollectionState, SIGNAL(entered()),SLOT(clearToolbarLatch())); |
|
94 |
|
95 HsMenuEventTransition *eventTransition = |
|
96 new HsMenuEventTransition(HsMenuEvent::OpenCollection, |
|
97 mAllCollectionsState, mCollectionState); |
|
98 mAllCollectionsState->addTransition(eventTransition); |
|
99 |
|
100 HsMenuEventTransition *collectionDeletedTransition = |
|
101 new HsMenuEventTransition(HsMenuEvent::CollectionDeleted, |
|
102 mCollectionState, mAllCollectionsState); |
|
103 mCollectionState->addTransition(collectionDeletedTransition); |
|
104 |
|
105 //transition for returning from collection |
|
106 HsMenuEventTransition *collectionToAppLibTransition = |
|
107 new HsMenuEventTransition(HsMenuEvent::OpenApplicationLibrary, |
|
108 mCollectionState, mAllCollectionsState); |
|
109 mCollectionState->addTransition(collectionToAppLibTransition); |
|
110 |
|
111 constructToolbar(); |
|
112 |
|
113 connect(this, SIGNAL(entered()),SLOT(stateEntered())); |
|
114 connect(this, SIGNAL(exited()),SLOT(stateExited())); |
|
115 connect(mAllCollectionsState, SIGNAL(sortOrderChanged(HsSortAttribute)), |
|
116 mAllAppsState, SLOT(collectionsSortOrder(HsSortAttribute))); |
|
117 connect(mAllCollectionsState, SIGNAL(sortOrderChanged(HsSortAttribute)), |
|
118 mCollectionState, SLOT(collectionsSortOrder(HsSortAttribute))); |
|
119 |
|
120 connect(mAllAppsState, SIGNAL(entered()), |
|
121 this, SLOT(allAppsStateEntered())); |
|
122 connect(mAllCollectionsState, SIGNAL(entered()), |
|
123 this, SLOT(allCollectionsStateEntered())); |
|
124 |
|
125 HSMENUTEST_FUNC_EXIT("HsAppLibraryState::construct"); |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 void HsAppLibraryState::onEntry(QEvent *event) |
|
132 { |
|
133 qDebug("HsCollectionState::onEntry()"); |
|
134 HSMENUTEST_FUNC_ENTRY("HsAppLibraryState::onEntry"); |
|
135 QState::onEntry(event); |
|
136 |
|
137 if (event->type() == HsMenuEvent::eventType()) { |
|
138 HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event); |
|
139 QVariantMap data = menuEvent->data(); |
|
140 mMenuView.setHsMenuMode( |
|
141 static_cast<HsMenuMode>(data.value(menuModeType()).toInt())); |
|
142 } else { |
|
143 mMenuView.setHsMenuMode(NormalHsMenuMode); |
|
144 } |
|
145 |
|
146 HSMENUTEST_FUNC_EXIT("HsAppLibraryState::onEntry"); |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 void HsAppLibraryState::stateEntered() |
|
153 { |
|
154 HSTEST_FUNC_ENTRY("AppLibraryState::stateEntered"); |
|
155 HbMainWindow *hbW = HbInstance::instance()->allMainWindows().value(0); |
|
156 if (!hbW->views().contains(mMenuView.view())) { |
|
157 hbW->addView(mMenuView.view()); |
|
158 } |
|
159 hbW->addSoftKeyAction(Hb::SecondarySoftKey, mSecondarySoftkeyAction); |
|
160 hbW->setCurrentView(mMenuView.view()); |
|
161 HSTEST_FUNC_EXIT("AppLibraryState::stateEntered"); |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 void HsAppLibraryState::stateExited() |
|
168 { |
|
169 HSTEST_FUNC_ENTRY("AppLibraryState::stateExited"); |
|
170 HbMainWindow *hbW = HbInstance::instance()->allMainWindows().value(0); |
|
171 |
|
172 //when exiting the pointer can be NULL |
|
173 if (hbW) { |
|
174 hbW->removeSoftKeyAction(Hb::SecondarySoftKey, |
|
175 mSecondarySoftkeyAction); |
|
176 } |
|
177 HSTEST_FUNC_EXIT("AppLibraryState::stateExited"); |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // --------------------------------------------------------------------------- |
|
182 // |
|
183 void HsAppLibraryState::constructToolbar() |
|
184 { |
|
185 HSMENUTEST_FUNC_ENTRY("HsAppLibraryState::constructToolbar"); |
|
186 |
|
187 HsOviStoreHandler *const oviStoreHandler = new HsOviStoreHandler(this); |
|
188 |
|
189 HbAction *const oviStoreAction(mMenuView.oviStoreAction()); |
|
190 |
|
191 oviStoreAction->setIcon(HbIcon(oviStoreHandler->icon())); |
|
192 connect(mMenuView.oviStoreAction(), SIGNAL(triggered()), |
|
193 oviStoreHandler, SLOT(action())); |
|
194 |
|
195 HbAction *const allCollectionsAction(mMenuView.allCollectionsAction()); |
|
196 |
|
197 mAllAppsState->addTransition(allCollectionsAction, SIGNAL(triggered()), |
|
198 mAllCollectionsState); |
|
199 mCollectionState->addTransition(allCollectionsAction, |
|
200 SIGNAL(triggered()), mAllCollectionsState); |
|
201 |
|
202 HbAction *const allAppsAction(mMenuView.allAppsAction()); |
|
203 |
|
204 mAllCollectionsState->addTransition(allAppsAction, |
|
205 SIGNAL(triggered()), mAllAppsState); |
|
206 mCollectionState->addTransition(allAppsAction, SIGNAL(triggered()), |
|
207 mAllAppsState); |
|
208 |
|
209 mAllAppsState->assignProperty( |
|
210 allAppsAction, "checked", true); |
|
211 mAllCollectionsState->assignProperty( |
|
212 allCollectionsAction, "checked", true); |
|
213 HSMENUTEST_FUNC_EXIT("HsAppLibraryState::constructToolbar"); |
|
214 } |
|
215 |
|
216 // --------------------------------------------------------------------------- |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 void HsAppLibraryState::clearToolbarLatch() |
|
220 { |
|
221 HSMENUTEST_FUNC_ENTRY("HsAppLibraryState::clearToolbarLatch"); |
|
222 QAction *const checkedAction = |
|
223 mMenuView.toolBarActionGroup()->checkedAction(); |
|
224 |
|
225 if (checkedAction != NULL) { |
|
226 checkedAction->setChecked(false); |
|
227 } |
|
228 HSMENUTEST_FUNC_EXIT("HsAppLibraryState::clearToolbarLatch"); |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 void HsAppLibraryState::allAppsStateEntered() |
|
235 { |
|
236 if (mMenuView.getHsMenuMode() == NormalHsMenuMode) { |
|
237 mHistoryTransaction->setTargetState(mAllAppsState); |
|
238 } |
|
239 } |
|
240 |
|
241 // --------------------------------------------------------------------------- |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 void HsAppLibraryState::allCollectionsStateEntered() |
|
245 { |
|
246 if (mMenuView.getHsMenuMode() == NormalHsMenuMode) { |
|
247 mHistoryTransaction->setTargetState(mAllCollectionsState); |
|
248 } |
|
249 } |