|
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 "hsscene.h" |
|
20 #include "hsscene_p.h" |
|
21 #include "hsscenedata.h" |
|
22 #include "hspage.h" |
|
23 #include "hspagedata.h" |
|
24 #include "hswidgethost.h" |
|
25 #include "hsdatabase.h" |
|
26 #include "hswallpaper.h" |
|
27 #ifndef Q_OS_SYMBIAN |
|
28 #include "hsipcconnectiondispatcher.h" |
|
29 #endif |
|
30 |
|
31 HsScenePrivate::HsScenePrivate() |
|
32 : mDatabaseId(-1), |
|
33 mIsOnline(true), |
|
34 mWallpaper(0), |
|
35 mActivePage(0), |
|
36 mActiveWidget(0) |
|
37 #ifndef Q_OS_SYMBIAN |
|
38 ,mIpcConnectionDispatcher(0) |
|
39 #endif |
|
40 { |
|
41 mWallpaper = new HsWallpaper; |
|
42 } |
|
43 |
|
44 HsScenePrivate::~HsScenePrivate() |
|
45 { |
|
46 delete mWallpaper; |
|
47 qDeleteAll(mPages); |
|
48 } |
|
49 |
|
50 HsScene::~HsScene() |
|
51 { |
|
52 } |
|
53 |
|
54 int HsScene::databaseId() const |
|
55 { |
|
56 return mD->mDatabaseId; |
|
57 } |
|
58 |
|
59 bool HsScene::load() |
|
60 { |
|
61 HsDatabase *db = HsDatabase::instance(); |
|
62 Q_ASSERT(db); |
|
63 |
|
64 HsSceneData sceneData; |
|
65 if (!db->scene(sceneData)) { |
|
66 return false; |
|
67 } |
|
68 |
|
69 if (sceneData.portraitWallpaper().isEmpty()) { |
|
70 mD->mWallpaper->setImagesById(); |
|
71 } else { |
|
72 mD->mWallpaper->setImagesByPaths( |
|
73 sceneData.landscapeWallpaper(), |
|
74 sceneData.portraitWallpaper()); |
|
75 } |
|
76 |
|
77 QList<HsPageData> pageDatas; |
|
78 if (!db->pages(pageDatas) || pageDatas.empty()) { |
|
79 return false; |
|
80 } |
|
81 |
|
82 HsPage *page = 0; |
|
83 foreach (HsPageData pageData, pageDatas) { |
|
84 page = new HsPage; |
|
85 page->setDatabaseId(pageData.id()); |
|
86 if (page->load()) { |
|
87 mD->mPages << page; |
|
88 } else { |
|
89 qDebug() << "HsScene: Page loading failed."; |
|
90 // TODO |
|
91 } |
|
92 } |
|
93 |
|
94 int defaultPageIndex = sceneData.defaultPage().index(); |
|
95 if(defaultPageIndex > -1){ |
|
96 mD->mActivePage = mD->mPages[defaultPageIndex]; |
|
97 mD->mActivePage->setRemovable(false); |
|
98 } |
|
99 #ifndef Q_OS_SYMBIAN |
|
100 mD->mIpcConnectionDispatcher = new HsIpcConnectionDispatcher("hs_content_publish"); |
|
101 mD->mIpcConnectionDispatcher->setParent(this); |
|
102 return mD->mIpcConnectionDispatcher->start(); |
|
103 #endif |
|
104 } |
|
105 |
|
106 HsWallpaper *HsScene::wallpaper() const |
|
107 { |
|
108 return mD->mWallpaper; |
|
109 } |
|
110 |
|
111 QList<HsPage *> HsScene::pages() const |
|
112 { |
|
113 return mD->mPages; |
|
114 } |
|
115 |
|
116 bool HsScene::addPage(HsPage *page) |
|
117 { |
|
118 if (!page) { |
|
119 return false; |
|
120 } |
|
121 |
|
122 if (mD->mPages.contains(page)) { |
|
123 return true; |
|
124 } |
|
125 |
|
126 HsDatabase *db = HsDatabase::instance(); |
|
127 |
|
128 HsPageData pageData; |
|
129 if (!db->page(page->databaseId(), pageData, false)) { |
|
130 return false; |
|
131 } |
|
132 int index = mD->mPages.count(); |
|
133 if (pageData.index() != index) { |
|
134 pageData.setIndex(index); |
|
135 if (!db->updatePage(pageData, false)) { |
|
136 return false; |
|
137 } |
|
138 } |
|
139 |
|
140 mD->mPages << page; |
|
141 return true; |
|
142 } |
|
143 |
|
144 bool HsScene::removePage(HsPage *page) |
|
145 { |
|
146 if (!page) { |
|
147 return false; |
|
148 } |
|
149 return mD->mPages.removeOne(page); |
|
150 } |
|
151 |
|
152 bool HsScene::setActivePage(HsPage *page) |
|
153 { |
|
154 if (!page) { |
|
155 return false; |
|
156 } |
|
157 |
|
158 if (!mD->mPages.contains(page)) { |
|
159 return false; |
|
160 } |
|
161 |
|
162 mD->mActivePage = page; |
|
163 return true; |
|
164 } |
|
165 |
|
166 bool HsScene::setActivePageIndex(int index) |
|
167 { |
|
168 if (index < 0 || mD->mPages.count() <= index) { |
|
169 return false; |
|
170 } |
|
171 return setActivePage(mD->mPages[index]); |
|
172 } |
|
173 |
|
174 HsPage *HsScene::activePage() const |
|
175 { |
|
176 return mD->mActivePage; |
|
177 } |
|
178 |
|
179 int HsScene::activePageIndex() const |
|
180 { |
|
181 return mD->mPages.indexOf(mD->mActivePage); |
|
182 } |
|
183 |
|
184 void HsScene::setActiveWidget(HsWidgetHost *widget) |
|
185 { |
|
186 mD->mActiveWidget = widget; |
|
187 } |
|
188 |
|
189 HsWidgetHost *HsScene::activeWidget() const |
|
190 { |
|
191 return mD->mActiveWidget; |
|
192 } |
|
193 /*! |
|
194 Toggle application online state. Defaults |
|
195 to true. |
|
196 */ |
|
197 void HsScene::setOnline(bool online) |
|
198 { |
|
199 mD->mIsOnline = online; |
|
200 foreach (HsPage *page, mD->mPages) { |
|
201 page->setOnline(online); |
|
202 } |
|
203 } |
|
204 |
|
205 bool HsScene::isOnline()const |
|
206 { |
|
207 return mD->mIsOnline; |
|
208 } |
|
209 |
|
210 HsScene *HsScene::instance() |
|
211 { |
|
212 if (mInstance.isNull()) { |
|
213 mInstance.reset(new HsScene); |
|
214 } |
|
215 return mInstance.data(); |
|
216 } |
|
217 |
|
218 Qt::Orientation HsScene::orientation() |
|
219 { |
|
220 return hbInstance->orientation(); |
|
221 } |
|
222 |
|
223 HbMainWindow *HsScene::mainWindow() |
|
224 { |
|
225 return hbInstance->allMainWindows().first(); |
|
226 } |
|
227 |
|
228 HsScene::HsScene(QObject *parent) |
|
229 : QObject(parent) |
|
230 { |
|
231 mD.reset(new HsScenePrivate); |
|
232 } |
|
233 |
|
234 QScopedPointer<HsScene> HsScene::mInstance(0); |