|
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 <HbInstance> |
|
19 #include "hsdomainmodeldatastructures.h" |
|
20 #include "hsscene.h" |
|
21 #include "hspage.h" |
|
22 #include "hswidgethost.h" |
|
23 #include "hswallpaper.h" |
|
24 #include "hsconfiguration.h" |
|
25 |
|
26 HsScene::~HsScene() |
|
27 { |
|
28 delete mWallpaper; |
|
29 qDeleteAll(mPages); |
|
30 } |
|
31 |
|
32 int HsScene::databaseId() const |
|
33 { |
|
34 return mDatabaseId; |
|
35 } |
|
36 |
|
37 bool HsScene::load() |
|
38 { |
|
39 int pageCount = property("pageCount").toInt(); |
|
40 if ( pageCount <= 0 ){ |
|
41 pageCount = 1; |
|
42 } |
|
43 int defaultPageIndex = property("defaultPageIndex").toInt(); |
|
44 |
|
45 mDatabaseId = 1; //Just one scene in the test |
|
46 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::SceneWallpaper) { |
|
47 mWallpaper = new HsSceneWallpaper(this); |
|
48 } |
|
49 |
|
50 for (int i = 0; i < pageCount; ++i) { |
|
51 HsPage *page = new HsPage; |
|
52 page->load(); |
|
53 mPages << page; |
|
54 } |
|
55 |
|
56 if(defaultPageIndex > -1){ |
|
57 mActivePage = mPages[defaultPageIndex]; |
|
58 mActivePage->setRemovable(false); |
|
59 } |
|
60 |
|
61 return true; |
|
62 } |
|
63 |
|
64 HsWallpaper *HsScene::wallpaper() const |
|
65 { |
|
66 return mWallpaper; |
|
67 } |
|
68 |
|
69 QList<HsPage *> HsScene::pages() const |
|
70 { |
|
71 return mPages; |
|
72 } |
|
73 |
|
74 bool HsScene::addPage(HsPage *page) |
|
75 { |
|
76 if (!page) { |
|
77 return false; |
|
78 } |
|
79 |
|
80 if (mPages.contains(page)) { |
|
81 return true; |
|
82 } |
|
83 |
|
84 mPages << page; |
|
85 return true; |
|
86 } |
|
87 |
|
88 bool HsScene::removePage(HsPage *page) |
|
89 { |
|
90 if (!page) { |
|
91 return false; |
|
92 } |
|
93 int index = activePageIndex(); |
|
94 mPages.removeOne(page); |
|
95 if(mPages.isEmpty()) { |
|
96 mActivePage = 0; |
|
97 } |
|
98 if(page == mActivePage){ |
|
99 if(index >= mPages.count()){ |
|
100 index--; |
|
101 } |
|
102 setActivePageIndex(index); |
|
103 } |
|
104 return true; |
|
105 } |
|
106 |
|
107 bool HsScene::setActivePage(HsPage *page) |
|
108 { |
|
109 if (!page) { |
|
110 return false; |
|
111 } |
|
112 |
|
113 if (!mPages.contains(page)) { |
|
114 return false; |
|
115 } |
|
116 |
|
117 if (page == mActivePage) { |
|
118 return true; |
|
119 } |
|
120 |
|
121 mActivePage = page; |
|
122 emit activePageChanged(); |
|
123 |
|
124 foreach (HsPage *p, mPages) { |
|
125 if (p == mActivePage) { |
|
126 p->showWidgets(); |
|
127 } else { |
|
128 p->hideWidgets(); |
|
129 } |
|
130 } |
|
131 |
|
132 return true; |
|
133 } |
|
134 |
|
135 bool HsScene::setActivePageIndex(int index) |
|
136 { |
|
137 if (index < 0 || mPages.count() <= index) { |
|
138 return false; |
|
139 } |
|
140 return setActivePage(mPages[index]); |
|
141 } |
|
142 |
|
143 HsPage *HsScene::activePage() const |
|
144 { |
|
145 return mActivePage; |
|
146 } |
|
147 |
|
148 int HsScene::activePageIndex() const |
|
149 { |
|
150 return mPages.indexOf(mActivePage); |
|
151 } |
|
152 |
|
153 void HsScene::setActiveWidget(HsWidgetHost *widget) |
|
154 { |
|
155 mActiveWidget = widget; |
|
156 } |
|
157 |
|
158 HsWidgetHost *HsScene::activeWidget() const |
|
159 { |
|
160 return mActiveWidget; |
|
161 } |
|
162 |
|
163 void HsScene::setOnline(bool online) |
|
164 { |
|
165 mIsOnline = online; |
|
166 foreach (HsPage *page, mPages) { |
|
167 page->setOnline(online); |
|
168 } |
|
169 } |
|
170 |
|
171 bool HsScene::isOnline()const |
|
172 { |
|
173 return mIsOnline; |
|
174 } |
|
175 |
|
176 /*! |
|
177 Singleton. |
|
178 */ |
|
179 HsScene *HsScene::instance() |
|
180 { |
|
181 if (!mInstance) { |
|
182 mInstance = new HsScene; |
|
183 } |
|
184 return mInstance; |
|
185 } |
|
186 |
|
187 HsScene *HsScene::takeInstance() |
|
188 { |
|
189 HsScene *instance = mInstance; |
|
190 mInstance = 0; |
|
191 return instance; |
|
192 } |
|
193 |
|
194 void HsScene::setInstance(HsScene *instance) |
|
195 { |
|
196 if (mInstance != instance) { |
|
197 delete mInstance; |
|
198 mInstance = instance; |
|
199 } |
|
200 } |
|
201 |
|
202 |
|
203 /*! |
|
204 Listens for application background/foreground changes. |
|
205 */ |
|
206 bool HsScene::eventFilter(QObject *watched, QEvent *event) |
|
207 { |
|
208 switch (event->type()) { |
|
209 case QEvent::ApplicationActivate: |
|
210 mActivePage->showWidgets(); |
|
211 break; |
|
212 case QEvent::ApplicationDeactivate: |
|
213 mActivePage->hideWidgets(); |
|
214 break; |
|
215 default: |
|
216 break; |
|
217 } |
|
218 return QObject::eventFilter(watched, event); |
|
219 } |
|
220 |
|
221 HsScene::HsScene(QObject *parent) |
|
222 : QObject(parent), |
|
223 mDatabaseId(-1), |
|
224 mWallpaper(0), |
|
225 mActivePage(0), |
|
226 mActiveWidget(0), |
|
227 mIsOnline(true) |
|
228 { |
|
229 } |
|
230 |
|
231 /*! |
|
232 Points to the scene instance. |
|
233 */ |
|
234 HsScene *HsScene::mInstance = 0; |