|
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 "hswallpaperselectionstate.h" |
|
19 #include "hsspinnerdialog.h" |
|
20 #include "hsscene.h" |
|
21 #include "hspage.h" |
|
22 #include "hswallpaper.h" |
|
23 #include "hsconfiguration.h" |
|
24 |
|
25 #ifdef Q_OS_SYMBIAN |
|
26 #include "hsimagefetcherclient.h" |
|
27 #else |
|
28 #include "xqaiwgetimageclient.h" |
|
29 #endif |
|
30 |
|
31 // Helper macros for connecting state entry and exit actions. |
|
32 #define ENTRY_ACTION(state, action) \ |
|
33 connect(state, SIGNAL(entered()), SLOT(action())); |
|
34 #define EXIT_ACTION(state, action) \ |
|
35 connect(state, SIGNAL(exited()), SLOT(action())); |
|
36 |
|
37 /*! |
|
38 \class HsWallpaperSelectionState |
|
39 \ingroup group_hshomescreenstateplugin |
|
40 \brief |
|
41 */ |
|
42 |
|
43 /*! |
|
44 |
|
45 */ |
|
46 HsWallpaperSelectionState::HsWallpaperSelectionState(QState *parent) |
|
47 : QState(parent), |
|
48 mImageFetcher(0), |
|
49 mWallpaper(0), |
|
50 mWaitDialog(0) |
|
51 { |
|
52 setupStates(); |
|
53 } |
|
54 |
|
55 /*! |
|
56 |
|
57 */ |
|
58 HsWallpaperSelectionState::~HsWallpaperSelectionState() |
|
59 { |
|
60 |
|
61 } |
|
62 |
|
63 /*! |
|
64 |
|
65 */ |
|
66 void HsWallpaperSelectionState::setupStates() |
|
67 { |
|
68 // States |
|
69 |
|
70 QState *state_processing = new QState(this); |
|
71 QState *state_selectingImage = new QState(state_processing); |
|
72 QState *state_assigningImage = new QState(state_processing); |
|
73 QState *state_errorMessage = new QState(this); |
|
74 |
|
75 setInitialState(state_processing); |
|
76 state_processing->setInitialState(state_selectingImage); |
|
77 |
|
78 // Transitions |
|
79 |
|
80 state_selectingImage->addTransition( |
|
81 this, SIGNAL(event_assignImage()), state_assigningImage); |
|
82 |
|
83 state_processing->addTransition( |
|
84 this, SIGNAL(event_error()), state_errorMessage); |
|
85 |
|
86 // Actions |
|
87 |
|
88 ENTRY_ACTION(state_selectingImage, action_selectingImage_start) |
|
89 EXIT_ACTION(state_selectingImage, action_selectingImage_cleanup) |
|
90 |
|
91 ENTRY_ACTION(state_assigningImage, action_assigningImage_showWaitDialog) |
|
92 ENTRY_ACTION(state_assigningImage, action_assigningImage_start) |
|
93 EXIT_ACTION(state_assigningImage, action_assigningImage_cleanup) |
|
94 EXIT_ACTION(state_assigningImage, action_assigningImage_hideWaitDialog) |
|
95 |
|
96 ENTRY_ACTION(state_errorMessage, action_errorMessage_show) |
|
97 } |
|
98 |
|
99 /*! |
|
100 |
|
101 */ |
|
102 void HsWallpaperSelectionState::action_selectingImage_start() |
|
103 { |
|
104 #ifdef Q_OS_SYMBIAN |
|
105 mImageFetcher = new HsImageFetcherClient; |
|
106 #else |
|
107 mImageFetcher = new XQAIWGetImageClient; |
|
108 #endif |
|
109 |
|
110 connect(mImageFetcher, SIGNAL(fetchCompleted(const QString&)), |
|
111 this, SLOT(onFetchCompleted(const QString&))); |
|
112 connect(mImageFetcher, SIGNAL(fetchFailed(int, const QString&)), |
|
113 this, SLOT(onFetchFailed(int, const QString&))); |
|
114 |
|
115 mImageFetcher->fetch(); |
|
116 } |
|
117 |
|
118 /*! |
|
119 |
|
120 */ |
|
121 void HsWallpaperSelectionState::action_selectingImage_cleanup() |
|
122 { |
|
123 mImageFetcher->disconnect(this); |
|
124 mImageFetcher->deleteLater(); |
|
125 mImageFetcher = 0; |
|
126 } |
|
127 |
|
128 /*! |
|
129 |
|
130 */ |
|
131 void HsWallpaperSelectionState::action_assigningImage_showWaitDialog() |
|
132 { |
|
133 mWaitDialog = new HsSpinnerDialog; |
|
134 mWaitDialog->start(); |
|
135 } |
|
136 |
|
137 /*! |
|
138 |
|
139 */ |
|
140 void HsWallpaperSelectionState::action_assigningImage_start() |
|
141 { |
|
142 HsScene *scene = HsScene::instance(); |
|
143 |
|
144 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::SceneWallpaper) { |
|
145 mWallpaper = scene->wallpaper(); |
|
146 } else { |
|
147 mWallpaper = scene->activePage()->wallpaper(); |
|
148 } |
|
149 |
|
150 connect(mWallpaper, SIGNAL(imageSet()), SLOT(onImageSet())); |
|
151 connect(mWallpaper, SIGNAL(imageSetFailed()), SLOT(onImageSetFailed())); |
|
152 |
|
153 mWallpaper->setImage(mImagePath); |
|
154 } |
|
155 |
|
156 /*! |
|
157 |
|
158 */ |
|
159 void HsWallpaperSelectionState::action_assigningImage_cleanup() |
|
160 { |
|
161 mWallpaper->disconnect(this); |
|
162 mWallpaper = 0; |
|
163 } |
|
164 |
|
165 /*! |
|
166 |
|
167 */ |
|
168 void HsWallpaperSelectionState::action_assigningImage_hideWaitDialog() |
|
169 { |
|
170 mWaitDialog->stop(); |
|
171 mWaitDialog = 0; |
|
172 } |
|
173 |
|
174 /*! |
|
175 |
|
176 */ |
|
177 void HsWallpaperSelectionState::action_errorMessage_show() |
|
178 { |
|
179 // TODO: Waiting for UX decision. |
|
180 emit event_waitInput(); |
|
181 } |
|
182 |
|
183 /*! |
|
184 |
|
185 */ |
|
186 void HsWallpaperSelectionState::onFetchCompleted(const QString &imagePath) |
|
187 { |
|
188 mImagePath = imagePath; |
|
189 emit event_assignImage(); |
|
190 } |
|
191 |
|
192 /*! |
|
193 |
|
194 */ |
|
195 void HsWallpaperSelectionState::onFetchFailed(int errorCode, const QString &errorMessage) |
|
196 { |
|
197 Q_UNUSED(errorCode) |
|
198 Q_UNUSED(errorMessage) |
|
199 emit event_error(); |
|
200 } |
|
201 |
|
202 /*! |
|
203 |
|
204 */ |
|
205 void HsWallpaperSelectionState::onImageSet() |
|
206 { |
|
207 emit event_waitInput(); |
|
208 } |
|
209 |
|
210 /*! |
|
211 |
|
212 */ |
|
213 void HsWallpaperSelectionState::onImageSetFailed() |
|
214 { |
|
215 emit event_error(); |
|
216 } |