|
1 /* |
|
2 * Copyright (c) 2010 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 <QDir> |
|
19 #include <QFile> |
|
20 #include <QVariantHash> |
|
21 #include <QGraphicsLinearLayout> |
|
22 |
|
23 #include <HbMainWindow> |
|
24 #include <HbIconItem> |
|
25 |
|
26 #include "hswallpaper.h" |
|
27 #include "hsscene.h" |
|
28 #include "hspage.h" |
|
29 #include "hswallpaperloader.h" |
|
30 #include "hsconfiguration.h" |
|
31 #include "hsgui.h" |
|
32 |
|
33 /*! |
|
34 |
|
35 */ |
|
36 |
|
37 /*! |
|
38 |
|
39 */ |
|
40 HsWallpaper::HsWallpaper(QGraphicsItem *parent) |
|
41 : HbWidget(parent), |
|
42 mIsDefaultImage(false), |
|
43 mIconItem(0) |
|
44 { |
|
45 setFlag(ItemHasNoContents); |
|
46 setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored); |
|
47 |
|
48 mIconItem = new HbIconItem(); |
|
49 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout; |
|
50 layout->setContentsMargins(0, 0, 0, 0); |
|
51 layout->addItem(mIconItem); |
|
52 setLayout(layout); |
|
53 |
|
54 connect(HsGui::instance(), |
|
55 SIGNAL(orientationChanged(Qt::Orientation)), |
|
56 SLOT(updateIconItem(Qt::Orientation))); |
|
57 } |
|
58 |
|
59 /*! |
|
60 |
|
61 */ |
|
62 HsWallpaper::~HsWallpaper() |
|
63 { |
|
64 } |
|
65 |
|
66 /*! |
|
67 |
|
68 */ |
|
69 void HsWallpaper::setImage(const QString &path) |
|
70 { |
|
71 Q_UNUSED(path); |
|
72 emit imageSet(); |
|
73 } |
|
74 |
|
75 void HsWallpaper::setImages(const QString &portraitFileName, const QString &landscapeFileName) |
|
76 { |
|
77 Q_UNUSED(portraitFileName) |
|
78 Q_UNUSED(landscapeFileName) |
|
79 emit imageSet(); |
|
80 } |
|
81 |
|
82 /*! |
|
83 |
|
84 */ |
|
85 void HsWallpaper::setDefaultImage() |
|
86 { |
|
87 if (mIsDefaultImage) { |
|
88 return; |
|
89 } |
|
90 |
|
91 mIsDefaultImage = true; |
|
92 mLandscapeImagePath = QString(); |
|
93 mPortraitImagePath = QString(); |
|
94 |
|
95 updateIconItem(HsGui::instance()->orientation()); |
|
96 } |
|
97 |
|
98 /*! |
|
99 |
|
100 */ |
|
101 void HsWallpaper::remove() |
|
102 { |
|
103 if (mIsDefaultImage) { |
|
104 mIsDefaultImage = false; |
|
105 } else { |
|
106 QFile::remove(mPortraitImagePath); |
|
107 QFile::remove(mLandscapeImagePath); |
|
108 } |
|
109 mPortraitImagePath.clear(); |
|
110 mLandscapeImagePath.clear(); |
|
111 } |
|
112 |
|
113 /*! |
|
114 |
|
115 */ |
|
116 bool HsWallpaper::setExistingImage() |
|
117 { |
|
118 QDir dir(wallpaperDirectory()); |
|
119 QStringList filters; |
|
120 filters << QString("%1_portrait.*").arg(mId); |
|
121 filters << QString("%1_landscape.*").arg(mId); |
|
122 QFileInfoList infos = dir.entryInfoList( |
|
123 filters, QDir::Files, QDir::Name | QDir::IgnoreCase); |
|
124 |
|
125 Q_ASSERT(infos.isEmpty() || infos.count() == 2); |
|
126 |
|
127 if (infos.isEmpty()) { |
|
128 return false; |
|
129 } |
|
130 |
|
131 mIsDefaultImage = false; |
|
132 mLandscapeImagePath = infos.first().absoluteFilePath(); |
|
133 mPortraitImagePath = infos.last().absoluteFilePath(); |
|
134 |
|
135 updateIconItem(HsGui::instance()->orientation()); |
|
136 return true; |
|
137 } |
|
138 |
|
139 QString HsWallpaper::rootDirectory() const |
|
140 { |
|
141 #ifdef Q_OS_SYMBIAN |
|
142 QString directory("c:/private/20022f35/wallpapers/"); |
|
143 #else |
|
144 QString directory(QDir::currentPath() + "/private/20022f35/wallpapers/"); |
|
145 #endif |
|
146 |
|
147 #ifdef HSDOMAINMODEL_TEST |
|
148 directory = QDir::currentPath() + "/wallpapers/"; |
|
149 #endif |
|
150 return directory; |
|
151 } |
|
152 |
|
153 /*! |
|
154 |
|
155 */ |
|
156 void HsWallpaper::onLoaderFinished() |
|
157 { |
|
158 if (mIsDefaultImage) { |
|
159 mIsDefaultImage = false; |
|
160 } else { |
|
161 QFile::remove(mPortraitImagePath); |
|
162 QFile::remove(mLandscapeImagePath); |
|
163 } |
|
164 foreach (QString path, mLoader->targets().keys()) { |
|
165 QString newName = path; newName.remove("temp"); |
|
166 QFile::rename(path, newName); |
|
167 } |
|
168 setExistingImage(); |
|
169 emit imageSet(); |
|
170 } |
|
171 |
|
172 /*! |
|
173 |
|
174 */ |
|
175 void HsWallpaper::onLoaderFailed() |
|
176 { |
|
177 foreach (QString path, mLoader->targets().keys()) { |
|
178 QFile::remove(path); |
|
179 } |
|
180 emit imageSetFailed(); |
|
181 } |
|
182 |
|
183 /*! |
|
184 |
|
185 */ |
|
186 void HsWallpaper::updateIconItem(Qt::Orientation orientation) |
|
187 { |
|
188 if (orientation == Qt::Vertical) { |
|
189 mIconItem->setIcon(HbIcon(QIcon(mPortraitImagePath))); |
|
190 } else { |
|
191 mIconItem->setIcon(HbIcon(QIcon(mLandscapeImagePath))); |
|
192 } |
|
193 } |
|
194 |
|
195 /*! |
|
196 |
|
197 */ |
|
198 HsSceneWallpaper::HsSceneWallpaper(HsScene *scene, QGraphicsItem *parent) |
|
199 : HsWallpaper(parent), |
|
200 mScene(0) |
|
201 { |
|
202 setScene(scene); |
|
203 } |
|
204 |
|
205 /*! |
|
206 |
|
207 */ |
|
208 HsSceneWallpaper::~HsSceneWallpaper() |
|
209 { |
|
210 } |
|
211 |
|
212 /*! |
|
213 |
|
214 */ |
|
215 void HsSceneWallpaper::setScene(HsScene *scene) |
|
216 { |
|
217 Q_UNUSED(scene); |
|
218 } |
|
219 |
|
220 /*! |
|
221 |
|
222 */ |
|
223 QString HsSceneWallpaper::wallpaperDirectory() const |
|
224 { |
|
225 return QDir::toNativeSeparators(rootDirectory() + "scene/"); |
|
226 } |
|
227 |
|
228 /*! |
|
229 |
|
230 */ |
|
231 QVariantHash HsSceneWallpaper::createTargets(const QString &sourcePath) |
|
232 { |
|
233 QVariantHash targets; |
|
234 |
|
235 QString path = wallpaperDirectory() |
|
236 + QString("temp%1_").arg(mId) |
|
237 + QString("%1.") |
|
238 + QFileInfo(sourcePath).suffix(); |
|
239 |
|
240 targets.insert(path.arg("portrait"), QSize((2 * 360) + HSCONFIGURATION_GET(bounceEffect), 640)); |
|
241 targets.insert(path.arg("landscape"), QSize((2 * 640) + HSCONFIGURATION_GET(bounceEffect), 360)); |
|
242 return targets; |
|
243 } |
|
244 |
|
245 /*! |
|
246 PAGE |
|
247 */ |
|
248 HsPageWallpaper::HsPageWallpaper(HsPage *page, QGraphicsItem *parent) |
|
249 : HsWallpaper(parent), |
|
250 mPage(0) |
|
251 { |
|
252 setPage(page); |
|
253 } |
|
254 |
|
255 /*! |
|
256 |
|
257 */ |
|
258 HsPageWallpaper::~HsPageWallpaper() |
|
259 { |
|
260 } |
|
261 |
|
262 /*! |
|
263 |
|
264 */ |
|
265 void HsPageWallpaper::setPage(HsPage *page) |
|
266 { |
|
267 if (!page) { |
|
268 return; |
|
269 } |
|
270 |
|
271 mPage = page; |
|
272 mId = page->databaseId(); |
|
273 if (!setExistingImage()) { |
|
274 setDefaultImage(); |
|
275 } |
|
276 } |
|
277 |
|
278 /*! |
|
279 |
|
280 */ |
|
281 QString HsPageWallpaper::wallpaperDirectory() const |
|
282 { |
|
283 return QDir::toNativeSeparators(rootDirectory() + "page/"); |
|
284 } |
|
285 |
|
286 /*! |
|
287 |
|
288 */ |
|
289 QVariantHash HsPageWallpaper::createTargets(const QString &sourcePath) |
|
290 { |
|
291 QVariantHash targets; |
|
292 |
|
293 QString path = wallpaperDirectory() |
|
294 + QString("temp%1_").arg(mId) |
|
295 + QString("%1.") |
|
296 + QFileInfo(sourcePath).suffix(); |
|
297 |
|
298 targets.insert(path.arg("portrait"), QSize(360, 640)); |
|
299 targets.insert(path.arg("landscape"), QSize(640, 360)); |
|
300 return targets; |
|
301 } |
|
302 |