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