|
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 <HbLabel> |
|
20 #include <HbDocumentLoader> |
|
21 #include <HbFrameDrawer> |
|
22 #include <HbFrameItem> |
|
23 #include <HbIconAnimationManager> |
|
24 #include <HbIconAnimationDefinition> |
|
25 #include <HbColorScheme> |
|
26 #include <HbStyleLoader> |
|
27 #include <QGraphicsLinearLayout> |
|
28 #include <QSettings> |
|
29 #include <QPixmap> |
|
30 |
|
31 // User includes |
|
32 #include "irhswidget.h" |
|
33 #include "irserviceclient.h" |
|
34 |
|
35 // Defines |
|
36 static const QString KIrHsWidgetDocml = ":/resource/irhswidget.docml"; |
|
37 static const QString KIrHsWidget = "irhswidget"; |
|
38 static const QString KLogoLabel = "logoLabel"; |
|
39 static const QString KGoToIrLabel = "goToIrLabel"; |
|
40 static const QString KControlLabel = "controlLabel"; |
|
41 static const QString KFirstRowLabel = "firstRowLabel"; |
|
42 static const QString KSecondRowLabel = "secondRowLabel"; |
|
43 static const QString KInfoControlArea = "info_control_area"; |
|
44 static const QString KCentrolArea = "infoLayout"; |
|
45 |
|
46 static const QString KDefaultStationLogo = "qtg_large_internet_radio"; |
|
47 static const QString KPlayButtonIcon = "qtg_mono_play"; |
|
48 static const QString KStopButtonIcon = "qtg_mono_stop"; |
|
49 |
|
50 static const QString KFrameGraphicsName = "qtg_fr_hswidget_normal"; |
|
51 static const QString KStationNameColor = "qtc_hs_list_item_title"; |
|
52 static const QString KMetaDataColor = "qtc_hs_list_item_content"; |
|
53 |
|
54 static const QString KLoadingAnimationPrefix = "qtg_anim_loading_"; |
|
55 static const QString KLoadingIconName = "LoadingAnimation"; |
|
56 |
|
57 const int KIrHsWidgetLogoSize = 50; // hs widget logo size |
|
58 |
|
59 // ======== MEMBER FUNCTIONS ======== |
|
60 // Constructor |
|
61 IrHsWidget::IrHsWidget(QGraphicsItem* aParent, Qt::WindowFlags aFlags) |
|
62 : HbWidget(aParent, aFlags), |
|
63 mLogoLabel(NULL), |
|
64 mControlLabel(NULL), |
|
65 mGoToIrLabel(NULL), |
|
66 mStationNameLabel(NULL), |
|
67 mMetadataLabel(NULL), |
|
68 mInfoControlArea(NULL), |
|
69 mCentralArea(NULL), |
|
70 mServiceClient(NULL), |
|
71 mIrState(IrAppState::Unknown), |
|
72 mIrHsWidgetState(EUnknown) |
|
73 { |
|
74 setupUi(); |
|
75 initHomeSreenWidget(); |
|
76 |
|
77 mServiceClient = new IrServiceClient(this); |
|
78 setupConnection(); |
|
79 } |
|
80 |
|
81 // Destructor |
|
82 IrHsWidget::~IrHsWidget() |
|
83 { |
|
84 } |
|
85 |
|
86 // Initializes the widget. |
|
87 // called by kqti fw when widget is added to home screen |
|
88 void IrHsWidget::onInitialize() |
|
89 { |
|
90 mServiceClient->startMonitoringIrState(); |
|
91 } |
|
92 |
|
93 // Uninitializes the widget. |
|
94 // called by kqti fw when widget is removed from home screen |
|
95 void IrHsWidget::onUninitialize() |
|
96 { |
|
97 } |
|
98 |
|
99 // Called when widget is shown in the home screen |
|
100 void IrHsWidget::onShow() |
|
101 { |
|
102 } |
|
103 |
|
104 // Called when widget is hidden from the home screen |
|
105 void IrHsWidget::onHide() |
|
106 { |
|
107 } |
|
108 |
|
109 |
|
110 void IrHsWidget::setupUi() |
|
111 { |
|
112 HbDocumentLoader *uiLoader = new HbDocumentLoader(); |
|
113 uiLoader->reset(); |
|
114 |
|
115 bool loaded = false; |
|
116 uiLoader->load(KIrHsWidgetDocml, &loaded); |
|
117 |
|
118 if (loaded) |
|
119 { |
|
120 HbWidget *irHsWidget = qobject_cast<HbWidget *>(uiLoader->findWidget(KIrHsWidget)); |
|
121 HbFrameDrawer *irHsWidgetDrawer = new HbFrameDrawer(KFrameGraphicsName, HbFrameDrawer::NinePieces); |
|
122 HbFrameItem *irHsWidgetBgItem = new HbFrameItem(irHsWidgetDrawer, irHsWidget); |
|
123 irHsWidgetBgItem->setPreferredSize(irHsWidget->preferredSize()); |
|
124 |
|
125 QGraphicsLinearLayout *irHsWidgetLayout = new QGraphicsLinearLayout(Qt::Vertical, this); |
|
126 irHsWidgetLayout->addItem(irHsWidget); |
|
127 setLayout(irHsWidgetLayout); |
|
128 |
|
129 mGoToIrLabel = qobject_cast<HbLabel *>(uiLoader->findWidget(KGoToIrLabel)); |
|
130 mLogoLabel = qobject_cast<HbLabel *>(uiLoader->findWidget(KLogoLabel)); |
|
131 mControlLabel = qobject_cast<HbLabel *>(uiLoader->findWidget(KControlLabel)); |
|
132 mInfoControlArea = qobject_cast<HbWidget *>(uiLoader->findWidget(KInfoControlArea)); |
|
133 mCentralArea = qobject_cast<HbWidget *>(uiLoader->findWidget(KCentrolArea)); |
|
134 |
|
135 // make system's hs backgourd item under logo |
|
136 irHsWidgetBgItem->stackBefore(mLogoLabel); |
|
137 |
|
138 // set font for station name line |
|
139 mStationNameLabel = qobject_cast<HbLabel *>(uiLoader->findWidget(KFirstRowLabel)); |
|
140 mStationNameLabel->setTextColor(HbColorScheme::color(KStationNameColor)); |
|
141 |
|
142 // set font for meta data line |
|
143 mMetadataLabel = qobject_cast<HbLabel *>(uiLoader->findWidget(KSecondRowLabel)); |
|
144 mMetadataLabel->setTextColor(HbColorScheme::color(KMetaDataColor)); |
|
145 |
|
146 // Create animation. |
|
147 HbIconAnimationManager *animationManager = HbIconAnimationManager::global(); |
|
148 HbIconAnimationDefinition animationDefinition; |
|
149 HbIconAnimationDefinition::AnimationFrame animationFrame; |
|
150 QList<HbIconAnimationDefinition::AnimationFrame> animationFrameList; |
|
151 |
|
152 QString animationFrameIconName; |
|
153 for (int i = 1; i < 11; i++) |
|
154 { |
|
155 animationFrame.duration = 100; |
|
156 animationFrameIconName.clear(); |
|
157 animationFrameIconName.append(KLoadingAnimationPrefix); |
|
158 animationFrameIconName.append(animationFrameIconName.number(i)); |
|
159 animationFrame.iconName = animationFrameIconName; |
|
160 animationFrameList.append(animationFrame); |
|
161 } |
|
162 animationDefinition.setPlayMode(HbIconAnimationDefinition::Loop); |
|
163 animationDefinition.setFrameList(animationFrameList); |
|
164 animationManager->addDefinition(KLoadingIconName, animationDefinition); |
|
165 |
|
166 // Construct an icon using the animation definition. |
|
167 mLoadingIcon.setIconName(KLoadingIconName); |
|
168 |
|
169 // install event filter to widget |
|
170 mGoToIrLabel->installEventFilter(this); |
|
171 mControlLabel->installEventFilter(this); |
|
172 mLogoLabel->installEventFilter(this); |
|
173 mCentralArea->installEventFilter(this); |
|
174 } |
|
175 |
|
176 delete uiLoader; |
|
177 } |
|
178 |
|
179 void IrHsWidget::initHomeSreenWidget() |
|
180 { |
|
181 if (mServiceClient->isStationPlayed()) |
|
182 { |
|
183 loadStoppedLayout(); |
|
184 QString stationName; |
|
185 if (mServiceClient->loadStationName(stationName)) |
|
186 { |
|
187 mStationNameLabel->setPlainText(stationName); |
|
188 } |
|
189 |
|
190 if (mServiceClient->loadStationLogoFlag()) |
|
191 { |
|
192 loadStationLogo(); |
|
193 } |
|
194 } |
|
195 else |
|
196 { |
|
197 loadInitLayout(); |
|
198 } |
|
199 } |
|
200 |
|
201 void IrHsWidget::setupConnection() |
|
202 { |
|
203 // signal - slot for service event |
|
204 QObject::connect(mServiceClient, SIGNAL(stationNameUpdated(QString)), |
|
205 this, SLOT(handleStationNameUpdated(QString))); |
|
206 QObject::connect(mServiceClient, SIGNAL(stationLogoUpdated(bool)), |
|
207 this, SLOT(handleStationLogoUpdated(bool))); |
|
208 QObject::connect(mServiceClient, SIGNAL(metaDataUpdated(QString)), |
|
209 this, SLOT(handleMetaDataUpdated(QString))); |
|
210 QObject::connect(mServiceClient, SIGNAL(irStateChanged(IrAppState::Type)), |
|
211 this, SLOT(handleIrStateUpdated(IrAppState::Type))); |
|
212 QObject::connect(mServiceClient, SIGNAL(controlFailed()), |
|
213 this, SLOT(handleControlFailed())); |
|
214 } |
|
215 |
|
216 bool IrHsWidget::eventFilter(QObject *aObject, QEvent *aEvent) |
|
217 { |
|
218 bool eventWasConsumed = false; |
|
219 QString objectName = aObject->objectName(); |
|
220 QEvent::Type eventType = aEvent->type(); |
|
221 |
|
222 if (KGoToIrLabel == objectName) |
|
223 { |
|
224 if (QEvent::GraphicsSceneMousePress == eventType) |
|
225 { |
|
226 eventWasConsumed = true; |
|
227 handleGoToIrAreaAction(); |
|
228 } |
|
229 } |
|
230 else if (KLogoLabel == objectName) |
|
231 { |
|
232 if (QEvent::GraphicsSceneMousePress == eventType) |
|
233 { |
|
234 eventWasConsumed = true; |
|
235 handleLogoAreaAction(); |
|
236 } |
|
237 } |
|
238 else if (KControlLabel == objectName) |
|
239 { |
|
240 if (QEvent::GraphicsSceneMousePress == eventType) |
|
241 { |
|
242 eventWasConsumed = true; |
|
243 handleControlAreaAction(); |
|
244 } |
|
245 } |
|
246 else if (KCentrolArea == objectName) |
|
247 { |
|
248 if (QEvent::GraphicsSceneMousePress == eventType) |
|
249 { |
|
250 eventWasConsumed = true; |
|
251 handleCentralAreaAction(); |
|
252 } |
|
253 } |
|
254 |
|
255 return eventWasConsumed; |
|
256 } |
|
257 |
|
258 // ================ handle user press event =============== |
|
259 void IrHsWidget::handleLogoAreaAction() |
|
260 { |
|
261 switch (mIrState) |
|
262 { |
|
263 case IrAppState::NoRunInit: |
|
264 case IrAppState::NoRunStopped: |
|
265 mServiceClient->launchIrNormally(); |
|
266 break; |
|
267 |
|
268 case IrAppState::RunningInit: |
|
269 case IrAppState::RunningStopped: |
|
270 case IrAppState::Playing: |
|
271 case IrAppState::Loading: |
|
272 mServiceClient->bringIrForeground(); |
|
273 break; |
|
274 |
|
275 default: |
|
276 break; |
|
277 } |
|
278 } |
|
279 |
|
280 void IrHsWidget::handleControlAreaAction() |
|
281 { |
|
282 switch (mIrState) |
|
283 { |
|
284 case IrAppState::NoRunStopped: |
|
285 mServiceClient->launchIrNowPlaying(); |
|
286 loadLoadingLayout(); |
|
287 break; |
|
288 |
|
289 case IrAppState::RunningStopped: |
|
290 mServiceClient->startPlaying(); |
|
291 loadLoadingLayout(); |
|
292 break; |
|
293 |
|
294 case IrAppState::Playing: |
|
295 mServiceClient->stopPlaying(); |
|
296 loadStoppedLayout(); |
|
297 break; |
|
298 |
|
299 case IrAppState::Loading: |
|
300 mServiceClient->cancelLoading(); |
|
301 loadStoppedLayout(); |
|
302 break; |
|
303 |
|
304 default: |
|
305 break; |
|
306 } |
|
307 } |
|
308 |
|
309 void IrHsWidget::handleGoToIrAreaAction() |
|
310 { |
|
311 handleLogoAreaAction(); |
|
312 } |
|
313 |
|
314 void IrHsWidget::handleCentralAreaAction() |
|
315 { |
|
316 handleLogoAreaAction(); |
|
317 } |
|
318 |
|
319 void IrHsWidget::handleControlFailed() |
|
320 { |
|
321 switch (mIrHsWidgetState) |
|
322 { |
|
323 case EInit: // LAF == [logo][go to interneat radio] |
|
324 loadInitLayout(); |
|
325 break; |
|
326 |
|
327 case EPlaying: // LAF == [logo][StationInfo][Play] |
|
328 loadPlayingLayout(); |
|
329 break; |
|
330 |
|
331 case EStopped: // LAF == [logo][StationInfo][Stop] |
|
332 loadStoppedLayout(); |
|
333 break; |
|
334 |
|
335 case ELoading: // LAF == [logo][StationInfo][Loading] |
|
336 loadLoadingLayout(); |
|
337 break; |
|
338 |
|
339 default: |
|
340 break; |
|
341 } |
|
342 } |
|
343 |
|
344 |
|
345 // ======== for service notification ======== |
|
346 void IrHsWidget::handleStationNameUpdated(const QString &aStationName) |
|
347 { |
|
348 if (mStationNameLabel->plainText() != aStationName) |
|
349 { |
|
350 mStationNameLabel->setPlainText(aStationName); |
|
351 } |
|
352 } |
|
353 |
|
354 void IrHsWidget::handleStationLogoUpdated(bool aLogoAvailable) |
|
355 { |
|
356 if (aLogoAvailable) |
|
357 { |
|
358 loadStationLogo(); |
|
359 } |
|
360 else |
|
361 { |
|
362 mLogoLabel->setIcon(KDefaultStationLogo); |
|
363 } |
|
364 } |
|
365 |
|
366 void IrHsWidget::handleMetaDataUpdated(const QString &aMetaData) |
|
367 { |
|
368 if (mMetadataLabel->plainText() != aMetaData) |
|
369 { |
|
370 mMetadataLabel->setPlainText(aMetaData); |
|
371 } |
|
372 } |
|
373 |
|
374 |
|
375 void IrHsWidget::handleIrStateUpdated(IrAppState::Type aNewState) |
|
376 { |
|
377 if (aNewState == mIrState) |
|
378 { |
|
379 return; |
|
380 } |
|
381 |
|
382 mIrState = aNewState; |
|
383 switch (mIrState) |
|
384 { |
|
385 case IrAppState::NoRunInit: |
|
386 case IrAppState::RunningInit: // LAF == [logo][go to interneat radio] |
|
387 handleHsWidgetStateChange(EInit); |
|
388 break; |
|
389 |
|
390 case IrAppState::NoRunStopped: |
|
391 case IrAppState::RunningStopped: // LAF == [logo][StationInfo][Play] |
|
392 handleHsWidgetStateChange(EStopped); |
|
393 break; |
|
394 |
|
395 case IrAppState::Playing: // LAF == [logo][StationInfo][Stop] |
|
396 handleHsWidgetStateChange(EPlaying); |
|
397 break; |
|
398 |
|
399 case IrAppState::Loading: // LAF == [logo][StationInfo][Loading] |
|
400 handleHsWidgetStateChange(ELoading); |
|
401 break; |
|
402 |
|
403 default: |
|
404 break; |
|
405 } |
|
406 } |
|
407 |
|
408 void IrHsWidget::handleHsWidgetStateChange(IrHsWidgetState aNewState) |
|
409 { |
|
410 if (aNewState == mIrHsWidgetState) |
|
411 { |
|
412 return; |
|
413 } |
|
414 |
|
415 mIrHsWidgetState = aNewState; |
|
416 switch (mIrHsWidgetState) |
|
417 { |
|
418 case EInit: // LAF == [logo][go to interneat radio] |
|
419 loadInitLayout(); |
|
420 break; |
|
421 |
|
422 case EPlaying: // LAF == [logo][StationInfo][Play] |
|
423 loadPlayingLayout(); |
|
424 break; |
|
425 |
|
426 case EStopped: // LAF == [logo][StationInfo][Stop] |
|
427 loadStoppedLayout(); |
|
428 break; |
|
429 |
|
430 case ELoading: // LAF == [logo][StationInfo][Loading] |
|
431 loadLoadingLayout(); |
|
432 break; |
|
433 |
|
434 default: |
|
435 break; |
|
436 } |
|
437 } |
|
438 // LAF == [logo][go to interneat radio] |
|
439 void IrHsWidget::loadInitLayout() |
|
440 { |
|
441 mInfoControlArea->hide(); |
|
442 mGoToIrLabel->show(); |
|
443 } |
|
444 |
|
445 // LAF == [logo][StationInfo][Play] |
|
446 void IrHsWidget::loadStoppedLayout() |
|
447 { |
|
448 mGoToIrLabel->hide(); |
|
449 mInfoControlArea->show(); |
|
450 mMetadataLabel->setPlainText(QString("")); |
|
451 mControlLabel->setIcon(KPlayButtonIcon); |
|
452 } |
|
453 |
|
454 // LAF == [logo][StationInfo][Stop] |
|
455 void IrHsWidget::loadPlayingLayout() |
|
456 { |
|
457 mGoToIrLabel->hide(); |
|
458 mInfoControlArea->show(); |
|
459 mControlLabel->setIcon(KStopButtonIcon); |
|
460 } |
|
461 |
|
462 // LAF == [logo][StationInfo][Loading] |
|
463 void IrHsWidget::loadLoadingLayout() |
|
464 { |
|
465 mGoToIrLabel->hide(); |
|
466 mInfoControlArea->show(); |
|
467 mMetadataLabel->setPlainText(QString("")); |
|
468 mControlLabel->setIcon(mLoadingIcon); |
|
469 } |
|
470 |
|
471 void IrHsWidget::loadStationLogo() |
|
472 { |
|
473 QSettings settings(KIrSettingOrganization, KIrSettingApplicaton); |
|
474 if (settings.value(KIrSettingStationLogo).canConvert<QPixmap>()) |
|
475 { |
|
476 QPixmap logoPixmap = settings.value(KIrSettingStationLogo).value<QPixmap>(); |
|
477 QPixmap newLogoPixmap = |
|
478 logoPixmap.scaled(QSize(KIrHsWidgetLogoSize,KIrHsWidgetLogoSize),Qt::KeepAspectRatio); |
|
479 QIcon logoQIcon(newLogoPixmap); |
|
480 HbIcon logoHbIcon(logoQIcon); |
|
481 mLogoLabel->setIcon(logoHbIcon); |
|
482 } |
|
483 } |
|
484 |