|
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: Internet Radio home screen widget |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <HbFrameDrawer> |
|
20 #include <HbFrameItem> |
|
21 #include <QGraphicsLinearLayout> |
|
22 |
|
23 // User includes |
|
24 #include "irhswidget.h" |
|
25 #include "irserviceclient.h" |
|
26 #include "irhswidgettitlerow.h" |
|
27 #include "irhswidgetmetadatarow.h" |
|
28 #include "irqlogger.h" |
|
29 |
|
30 // Constants |
|
31 static const int KIrHsWidgetContentsMargin = 0; |
|
32 static const QString KIrHsWidgetBackgroundImage = "qtg_fr_hswidget_normal"; |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 // Constructor |
|
36 IrHsWidget::IrHsWidget(QGraphicsItem* aParent, Qt::WindowFlags aFlags) |
|
37 : HbWidget(aParent, aFlags), |
|
38 mUserActionEnabled(false), |
|
39 mRowLayout(NULL), |
|
40 mTitleRow(NULL), |
|
41 mMetaDataRow(NULL), |
|
42 mServiceClient(NULL), |
|
43 mIrState(IrAppState::Unknown), |
|
44 mIrHsWidgetState(EUnknown) |
|
45 { |
|
46 setupUi(); |
|
47 initHomeSreenWidget(); |
|
48 |
|
49 mServiceClient = IrServiceClient::openInstance(); |
|
50 setupConnection(); |
|
51 } |
|
52 |
|
53 // Destructor |
|
54 IrHsWidget::~IrHsWidget() |
|
55 { |
|
56 if (mServiceClient) |
|
57 { |
|
58 mServiceClient->closeInstance(); |
|
59 } |
|
60 |
|
61 if (mRowLayout->count() == 1) |
|
62 { |
|
63 delete mMetaDataRow; |
|
64 mMetaDataRow = NULL; |
|
65 } |
|
66 } |
|
67 |
|
68 // Initializes the widget. |
|
69 // called by kqti fw when widget is added to home screen |
|
70 void IrHsWidget::onInitialize() |
|
71 { |
|
72 mServiceClient->startMonitoringIrState(); |
|
73 } |
|
74 |
|
75 // Uninitializes the widget. |
|
76 // called by kqti fw when widget is removed from home screen |
|
77 void IrHsWidget::onUninitialize() |
|
78 { |
|
79 } |
|
80 |
|
81 // Called when widget is shown in the home screen |
|
82 void IrHsWidget::onShow() |
|
83 { |
|
84 if (mRowLayout->count() == 2) |
|
85 { |
|
86 mMetaDataRow->startMetaDataMarquee(); |
|
87 } |
|
88 } |
|
89 |
|
90 // Called when widget is hidden from the home screen |
|
91 void IrHsWidget::onHide() |
|
92 { |
|
93 if (mRowLayout->count() == 2) |
|
94 { |
|
95 mMetaDataRow->stopMetaDataMarquee(); |
|
96 } |
|
97 } |
|
98 |
|
99 |
|
100 void IrHsWidget::setupUi() |
|
101 { |
|
102 setContentsMargins( KIrHsWidgetContentsMargin, KIrHsWidgetContentsMargin, |
|
103 KIrHsWidgetContentsMargin, KIrHsWidgetContentsMargin); |
|
104 |
|
105 //Setup layout |
|
106 mRowLayout = new QGraphicsLinearLayout(Qt::Vertical); |
|
107 |
|
108 mRowLayout->setContentsMargins(KIrHsWidgetContentsMargin, KIrHsWidgetContentsMargin, |
|
109 KIrHsWidgetContentsMargin, KIrHsWidgetContentsMargin); |
|
110 mRowLayout->setSpacing(KIrHsWidgetContentsMargin); |
|
111 setLayout(mRowLayout); |
|
112 |
|
113 //background |
|
114 HbFrameDrawer * backgroundFrameDrawer = new HbFrameDrawer(KIrHsWidgetBackgroundImage, HbFrameDrawer::NinePieces); |
|
115 HbFrameItem* backgroundLayoutItem = new HbFrameItem(backgroundFrameDrawer); |
|
116 setBackgroundItem( backgroundLayoutItem ); |
|
117 } |
|
118 |
|
119 void IrHsWidget::initHomeSreenWidget() |
|
120 { |
|
121 mTitleRow = new IrHsWidgetTitleRow(); |
|
122 mMetaDataRow = new IrHsWidgetMetaDataRow(); |
|
123 |
|
124 mRowLayout->addItem(mTitleRow); |
|
125 resizeHomeScreenWidget(); |
|
126 |
|
127 if (mServiceClient->isStationPlayed()) |
|
128 { |
|
129 loadStoppedLayout(); |
|
130 QString stationName; |
|
131 if (mServiceClient->loadStationName(stationName)) |
|
132 { |
|
133 mTitleRow->setStationName(stationName); |
|
134 } |
|
135 |
|
136 if (mServiceClient->loadStationLogoFlag()) |
|
137 { |
|
138 mTitleRow->loadStationLogo(); |
|
139 } |
|
140 } |
|
141 else |
|
142 { |
|
143 loadInitLayout(); |
|
144 } |
|
145 } |
|
146 |
|
147 void IrHsWidget::resizeHomeScreenWidget() |
|
148 { |
|
149 //resize here so homescreen will place widget correctly on screen |
|
150 setPreferredSize( mRowLayout->preferredSize() ); |
|
151 if (parentWidget()) |
|
152 { |
|
153 //to place widget properly after adding to homescreen |
|
154 parentWidget()->resize(preferredSize()); |
|
155 } |
|
156 } |
|
157 |
|
158 void IrHsWidget::setupConnection() |
|
159 { |
|
160 // signal - slot for service event |
|
161 QObject::connect(mServiceClient, SIGNAL(stationNameUpdated(QString)), |
|
162 this, SLOT(handleStationNameUpdated(QString))); |
|
163 QObject::connect(mServiceClient, SIGNAL(stationLogoUpdated(bool)), |
|
164 this, SLOT(handleStationLogoUpdated(bool))); |
|
165 QObject::connect(mServiceClient, SIGNAL(metaDataUpdated(QString)), |
|
166 this, SLOT(handleMetaDataUpdated(QString))); |
|
167 QObject::connect(mServiceClient, SIGNAL(irStateChanged(IrAppState::Type)), |
|
168 this, SLOT(handleIrStateUpdated(IrAppState::Type))); |
|
169 QObject::connect(mServiceClient, SIGNAL(controlFailed()), |
|
170 this, SLOT(handleControlFailed())); |
|
171 |
|
172 enableUserAction(); |
|
173 } |
|
174 |
|
175 // ================ handle user press event =============== |
|
176 void IrHsWidget::handleCommonAreaAction() |
|
177 { |
|
178 switch (mIrState) |
|
179 { |
|
180 case IrAppState::NoRunInit: |
|
181 case IrAppState::NoRunStopped: |
|
182 disableUserAction(); |
|
183 mServiceClient->launchIrNormally(); |
|
184 break; |
|
185 |
|
186 case IrAppState::RunningInit: |
|
187 case IrAppState::RunningStopped: |
|
188 case IrAppState::Playing: |
|
189 case IrAppState::Loading: |
|
190 mServiceClient->bringIrForeground(); |
|
191 break; |
|
192 |
|
193 default: |
|
194 break; |
|
195 } |
|
196 } |
|
197 |
|
198 void IrHsWidget::handleControlAreaAction() |
|
199 { |
|
200 LOG("IrHsWidget::handleControlAreaAction()"); |
|
201 //here, for we will control the application by homescreen, |
|
202 //to avoid repeat actions, we disable all control event here |
|
203 //and enable them when state changed or failed. |
|
204 disableUserAction(); |
|
205 |
|
206 switch (mIrState) |
|
207 { |
|
208 case IrAppState::NoRunStopped: |
|
209 mServiceClient->launchIrNowPlaying(); |
|
210 break; |
|
211 |
|
212 case IrAppState::RunningStopped: |
|
213 mServiceClient->startPlaying(); |
|
214 break; |
|
215 |
|
216 case IrAppState::Playing: |
|
217 mServiceClient->stopPlaying(); |
|
218 break; |
|
219 |
|
220 case IrAppState::Loading: |
|
221 mServiceClient->cancelLoading(); |
|
222 break; |
|
223 |
|
224 default: |
|
225 break; |
|
226 } |
|
227 } |
|
228 |
|
229 |
|
230 void IrHsWidget::handleControlFailed() |
|
231 { |
|
232 LOG("handleControlFailed()"); |
|
233 enableUserAction(); |
|
234 switch (mIrHsWidgetState) |
|
235 { |
|
236 case EInit: // LAF == [logo][go to interneat radio] |
|
237 loadInitLayout(); |
|
238 break; |
|
239 |
|
240 case EPlaying: // LAF == [logo][StationInfo][Play] |
|
241 loadPlayingLayout(); |
|
242 break; |
|
243 |
|
244 case EStopped: // LAF == [logo][StationInfo][Stop] |
|
245 loadStoppedLayout(); |
|
246 break; |
|
247 |
|
248 case ELoading: // LAF == [logo][StationInfo][Loading] |
|
249 loadLoadingLayout(); |
|
250 break; |
|
251 |
|
252 default: |
|
253 break; |
|
254 } |
|
255 } |
|
256 |
|
257 |
|
258 // ======== for service notification ======== |
|
259 void IrHsWidget::handleStationNameUpdated(const QString &aStationName) |
|
260 { |
|
261 mTitleRow->setStationName(aStationName); |
|
262 } |
|
263 |
|
264 void IrHsWidget::handleStationLogoUpdated(bool aLogoAvailable) |
|
265 { |
|
266 if (aLogoAvailable) |
|
267 { |
|
268 mTitleRow->loadStationLogo(); |
|
269 } |
|
270 else |
|
271 { |
|
272 mTitleRow->setDefaultLogo(); |
|
273 } |
|
274 } |
|
275 |
|
276 void IrHsWidget::handleMetaDataUpdated(const QString &aMetaData) |
|
277 { |
|
278 mMetaDataRow->setMetaData(aMetaData); |
|
279 } |
|
280 |
|
281 |
|
282 void IrHsWidget::handleIrStateUpdated(IrAppState::Type aNewState) |
|
283 { |
|
284 LOG("IrHsWidget::handleIrStateUpdated()"); |
|
285 enableUserAction(); |
|
286 if (aNewState == mIrState) |
|
287 { |
|
288 return; |
|
289 } |
|
290 |
|
291 mIrState = aNewState; |
|
292 switch (mIrState) |
|
293 { |
|
294 case IrAppState::NoRunInit: |
|
295 case IrAppState::RunningInit: // LAF == [logo][go to interneat radio] |
|
296 handleHsWidgetStateChange(EInit); |
|
297 break; |
|
298 |
|
299 case IrAppState::NoRunStopped: |
|
300 case IrAppState::RunningStopped: // LAF == [logo][StationInfo][Play] |
|
301 handleHsWidgetStateChange(EStopped); |
|
302 break; |
|
303 |
|
304 case IrAppState::Playing: // LAF == [logo][StationInfo][Stop] |
|
305 handleHsWidgetStateChange(EPlaying); |
|
306 break; |
|
307 |
|
308 case IrAppState::Loading: // LAF == [logo][StationInfo][Loading] |
|
309 handleHsWidgetStateChange(ELoading); |
|
310 break; |
|
311 |
|
312 default: |
|
313 break; |
|
314 } |
|
315 } |
|
316 |
|
317 void IrHsWidget::handleHsWidgetStateChange(IrHsWidgetState aNewState) |
|
318 { |
|
319 if (aNewState == mIrHsWidgetState) |
|
320 { |
|
321 return; |
|
322 } |
|
323 |
|
324 mIrHsWidgetState = aNewState; |
|
325 switch (mIrHsWidgetState) |
|
326 { |
|
327 case EInit: // LAF == [logo][go to interneat radio] |
|
328 loadInitLayout(); |
|
329 break; |
|
330 |
|
331 case EPlaying: // LAF == [logo][StationInfo][Play] |
|
332 loadPlayingLayout(); |
|
333 break; |
|
334 |
|
335 case EStopped: // LAF == [logo][StationInfo][Stop] |
|
336 loadStoppedLayout(); |
|
337 break; |
|
338 |
|
339 case ELoading: // LAF == [logo][StationInfo][Loading] |
|
340 loadLoadingLayout(); |
|
341 break; |
|
342 |
|
343 default: |
|
344 break; |
|
345 } |
|
346 } |
|
347 // LAF == [logo][go to interneat radio] |
|
348 void IrHsWidget::loadInitLayout() |
|
349 { |
|
350 if (mRowLayout->count() == 2) |
|
351 { |
|
352 mRowLayout->removeItem(mMetaDataRow); |
|
353 resizeHomeScreenWidget(); |
|
354 } |
|
355 |
|
356 mTitleRow->setDefaultTitle(); |
|
357 } |
|
358 |
|
359 // LAF == [logo][StationInfo][Play] |
|
360 void IrHsWidget::loadStoppedLayout() |
|
361 { |
|
362 if (mRowLayout->count() == 1) |
|
363 { |
|
364 mRowLayout->addItem(mMetaDataRow); |
|
365 resizeHomeScreenWidget(); |
|
366 } |
|
367 |
|
368 mMetaDataRow->setPlayIcon(); |
|
369 } |
|
370 |
|
371 // LAF == [logo][StationInfo][Stop] |
|
372 void IrHsWidget::loadPlayingLayout() |
|
373 { |
|
374 if (mRowLayout->count() == 1) |
|
375 { |
|
376 mRowLayout->addItem(mMetaDataRow); |
|
377 resizeHomeScreenWidget(); |
|
378 } |
|
379 |
|
380 mMetaDataRow->setStopIcon(); |
|
381 } |
|
382 |
|
383 // LAF == [logo][StationInfo][Loading] |
|
384 void IrHsWidget::loadLoadingLayout() |
|
385 { |
|
386 if (mRowLayout->count() == 1) |
|
387 { |
|
388 mRowLayout->addItem(mMetaDataRow); |
|
389 resizeHomeScreenWidget(); |
|
390 } |
|
391 |
|
392 mMetaDataRow->setLoadingIcon(); |
|
393 } |
|
394 |
|
395 |
|
396 |
|
397 void IrHsWidget::enableUserAction() |
|
398 { |
|
399 if (!mUserActionEnabled) |
|
400 { |
|
401 mUserActionEnabled = true; |
|
402 // signal - slot for user click action |
|
403 QObject::connect(mTitleRow, SIGNAL(titleRowClicked()), |
|
404 this, SLOT(handleCommonAreaAction())); |
|
405 QObject::connect(mMetaDataRow, SIGNAL(metaDataAreaClicked()), |
|
406 this, SLOT(handleCommonAreaAction())); |
|
407 QObject::connect(mMetaDataRow, SIGNAL(controlAreaClicked()), |
|
408 this, SLOT(handleControlAreaAction())); |
|
409 } |
|
410 } |
|
411 |
|
412 void IrHsWidget::disableUserAction() |
|
413 { |
|
414 if (mUserActionEnabled) |
|
415 { |
|
416 mUserActionEnabled = false; |
|
417 // signal - slot for user click action |
|
418 QObject::disconnect(mTitleRow, SIGNAL(titleRowClicked()), |
|
419 this, SLOT(handleCommonAreaAction())); |
|
420 QObject::disconnect(mMetaDataRow, SIGNAL(metaDataAreaClicked()), |
|
421 this, SLOT(handleCommonAreaAction())); |
|
422 QObject::disconnect(mMetaDataRow, SIGNAL(controlAreaClicked()), |
|
423 this, SLOT(handleControlAreaAction())); |
|
424 } |
|
425 } |
|
426 |