34
|
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: FM Radio home screen widget
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// System includes
|
|
19 |
#include <HbPushButton>
|
|
20 |
#include <HbLabel>
|
|
21 |
#include <HbDocumentLoader>
|
|
22 |
#include <HbFrameDrawer>
|
|
23 |
#include <HbIcon>
|
|
24 |
#include <HbIconAnimationManager>
|
|
25 |
#include <HbIconAnimationDefinition>
|
|
26 |
#include <HbColorScheme>
|
|
27 |
#include <HbDeviceMessageBox>
|
|
28 |
#include <QGraphicsLinearLayout>
|
|
29 |
#include <QGraphicsItem>
|
|
30 |
#include <QDesktopServices>
|
|
31 |
#include <QSignalMapper>
|
|
32 |
|
|
33 |
// User includes
|
|
34 |
#include "radiohswidget.h"
|
|
35 |
#include "radiohswidgetprofilereader.h"
|
|
36 |
#include "radiohswidgetradioserviceclient.h"
|
|
37 |
#include "radioservicedef.h"
|
|
38 |
#include "radio_global.h"
|
|
39 |
#include "radiologger.h"
|
|
40 |
|
|
41 |
// Constants
|
|
42 |
/** Path to docml file */
|
|
43 |
const QString DOCML(":/ui/resource/fmradiohswidget.docml");
|
|
44 |
|
|
45 |
/** DOCML object name for mainLayout */
|
|
46 |
const QString DOCML_OBJECT_NAME_MAIN_LAYOUT("mainLayout");
|
|
47 |
/** DOCML object name for contentLayout */
|
|
48 |
const QString DOCML_OBJECT_NAME_CONTENT_LAYOUT("contentLayout");
|
|
49 |
/** DOCML object name for tunerBackgroundPushButton */
|
|
50 |
const QString DOCML_OBJECT_NAME_TUNER_BACKGROUND_BUTTON(
|
|
51 |
"tunerBackgroundPushButton");
|
|
52 |
/** DOCML object name for tunerStackedLayout */
|
|
53 |
const QString DOCML_OBJECT_NAME_TUNER_STACKED_LAYOUT("tunerStackedLayout");
|
|
54 |
/** DOCML object name for tunerInformationStackedLayout */
|
|
55 |
const QString DOCML_OBJECT_NAME_TUNER_INFORMATION_STACKED_LAYOUT(
|
|
56 |
"tunerInformationStackedLayout");
|
|
57 |
/** DOCML object name for controlButtons */
|
|
58 |
const QString DOCML_OBJECT_NAME_CONTROL_BUTTONS_LAYOUT("controlButtons");
|
|
59 |
/** DOCML object name for powerToggleButton */
|
|
60 |
const QString DOCML_OBJECT_NAME_POWER_BUTTON("powerButton");
|
|
61 |
/** DOCML object name for previousPushButton */
|
|
62 |
const QString DOCML_OBJECT_NAME_PREVIOUS_BUTTON("previousPushButton");
|
|
63 |
/** DOCML object name for nextPushButton */
|
|
64 |
const QString DOCML_OBJECT_NAME_NEXT_BUTTON("nextPushButton");
|
|
65 |
/** DOCML object name for twoRowsLayout */
|
|
66 |
const QString DOCML_OBJECT_NAME_TWO_ROWS_LAYOUT("twoRowsLayout");
|
|
67 |
/** DOCML object name for firstRowLabel */
|
|
68 |
const QString DOCML_OBJECT_NAME_FIRST_ROW_LABEL("firstRowLabel");
|
|
69 |
/** DOCML object name for secondRowLabel */
|
|
70 |
const QString DOCML_OBJECT_NAME_SECOND_ROW_LABEL("secondRowLabel");
|
|
71 |
/** DOCML object name for lonelyRowLabel */
|
|
72 |
const QString DOCML_OBJECT_NAME_LONELY_ROW_LABEL("lonelyRowLabel");
|
|
73 |
/** DOCML object name for animationIcon */
|
|
74 |
const QString DOCML_OBJECT_NAME_ANIMATION_ICON("animationIcon");
|
|
75 |
|
|
76 |
/** Unknown favorite station count. */
|
|
77 |
const int FAVORITE_STATION_COUNT_UNDEFINED(-1);
|
|
78 |
/** One favorite station set. */
|
|
79 |
const int FAVORITE_STATION_COUNT_ONE(1);
|
|
80 |
/** Favorite station count lower boundary including this number. */
|
|
81 |
const int FAVORITE_STATION_COUNT_LOWER_BOUNDARY(0);
|
|
82 |
/** Favorite station count upper boundary including this number. */
|
|
83 |
const int FAVORITE_STATION_COUNT_UPPER_BOUNDARY(100);
|
|
84 |
|
|
85 |
// Graphics identifiers for different push button states
|
|
86 |
const QString CONTROL_BUTTON_GRAPHICS_NORMAL ("qtg_fr_hsbutton_normal");
|
|
87 |
const QString CONTROL_BUTTON_GRAPHICS_PRESSED ("qtg_fr_hsbutton_pressed");
|
|
88 |
const QString CONTROL_BUTTON_GRAPHICS_DISABLED("qtg_fr_hsbutton_disabled");
|
|
89 |
const QString CONTROL_BUTTON_GRAPHICS_LATCHED ("qtg_fr_hsbutton_latched");
|
|
90 |
|
|
91 |
// Push button icon colors for each of the states (normal, pressed, disabled
|
|
92 |
// and latched)
|
|
93 |
const QString CONTROL_BUTTON_ICON_COLOR_NORMAL ("qtc_button_normal");
|
|
94 |
const QString CONTROL_BUTTON_ICON_COLOR_PRESSED ("qtc_button_pressed");
|
|
95 |
const QString CONTROL_BUTTON_ICON_COLOR_DISABLED("qtc_button_disabled");
|
|
96 |
const QString CONTROL_BUTTON_ICON_COLOR_LATCHED ("qtc_button_latched");
|
|
97 |
|
|
98 |
// File name suffix lists for push buttons
|
|
99 |
const QStringList POWER_BUTTON_SUFFIX(
|
|
100 |
(QStringList() << "_l" << "_c" << "_cr"));
|
|
101 |
const QStringList PREVIOUS_BUTTON_SUFFIX(
|
|
102 |
(QStringList() << "_cl" << "_c" << "_cr"));
|
|
103 |
const QStringList NEXT_BUTTON_SUFFIX(
|
|
104 |
(QStringList() << "_cl" << "_c" << "_r"));
|
|
105 |
|
|
106 |
/** Icon for power button off. */
|
|
107 |
const QString POWER_BUTTON_ICON_OFF("qtg_mono_power");
|
|
108 |
/** Icon for power button on. */
|
|
109 |
const QString POWER_BUTTON_ICON_ON ("qtg_mono_power");
|
|
110 |
|
|
111 |
// Tuner background button graphics for different states.
|
|
112 |
const QString TUNER_BUTTON_NORMAL_OFF("qtg_fr_tuner");
|
|
113 |
const QString TUNER_BUTTON_NORMAL_ON("qtg_fr_tuner");
|
|
114 |
const QString TUNER_BUTTON_NORMAL_PRESSED("qtg_fr_hsitems2_pressed");
|
|
115 |
|
|
116 |
/*!
|
|
117 |
\class RadioHsWidget
|
|
118 |
\brief Implementation of FM Radio home screen widget.
|
|
119 |
|
|
120 |
RadioHsWidget implements needed functions for the FM Radio home screen
|
|
121 |
widget.
|
|
122 |
*/
|
|
123 |
|
|
124 |
// ======== MEMBER FUNCTIONS ========
|
|
125 |
|
|
126 |
/*!
|
|
127 |
Constructs a widget which is a child of \a parent, with widget flags set
|
|
128 |
to \a flags.
|
|
129 |
|
|
130 |
Constructor should be empty and all the actual construction should be
|
|
131 |
done in onInitialize().
|
|
132 |
*/
|
|
133 |
RadioHsWidget::RadioHsWidget(QGraphicsItem* parent, Qt::WindowFlags flags)
|
|
134 |
: HbWidget(parent, flags),
|
|
135 |
mInformationAreaBackgroundButton(NULL),
|
|
136 |
mPowerButton(NULL),
|
|
137 |
mPreviousButton(NULL),
|
|
138 |
mNextButton(NULL),
|
|
139 |
mInformationAreaTwoRowsLayout(NULL),
|
|
140 |
mInformationLonelyRowLabel(NULL),
|
|
141 |
mInformationFirstRowLabel(NULL),
|
|
142 |
mInformationSecondRowLabel(NULL),
|
|
143 |
mAnimationIcon(NULL),
|
|
144 |
mFmRadioState(FmRadio::StateUndefined),
|
|
145 |
mFavoriteStationCount(FAVORITE_STATION_COUNT_UNDEFINED),
|
|
146 |
mCurrentStationIsFavorite(false),
|
|
147 |
mProfileMonitor(NULL),
|
|
148 |
mRadioServiceClient(NULL)
|
|
149 |
{
|
|
150 |
LOG_METHOD;
|
|
151 |
}
|
|
152 |
|
|
153 |
/*!
|
|
154 |
Destructor
|
|
155 |
*/
|
|
156 |
RadioHsWidget::~RadioHsWidget()
|
|
157 |
{
|
|
158 |
LOG_METHOD;
|
|
159 |
}
|
|
160 |
|
|
161 |
/*!
|
|
162 |
Handles changes in FM Radio information.
|
|
163 |
|
|
164 |
\param informationType Type of changed information.
|
|
165 |
\param information Actual information.
|
|
166 |
*/
|
|
167 |
void RadioHsWidget::handleRadioInformationChange(const int informationType,
|
|
168 |
const QVariant &information)
|
|
169 |
{
|
|
170 |
LOG_METHOD;
|
|
171 |
switch (informationType) {
|
|
172 |
|
|
173 |
case RadioServiceNotification::FavoriteCount:
|
|
174 |
LOG("FavoriteCount");
|
|
175 |
if (information.canConvert(QVariant::Int) &&
|
|
176 |
information.toInt() >= FAVORITE_STATION_COUNT_LOWER_BOUNDARY &&
|
|
177 |
information.toInt() <= FAVORITE_STATION_COUNT_UPPER_BOUNDARY) {
|
|
178 |
mFavoriteStationCount = information.toInt();
|
|
179 |
// If there are favorite stations, enable the next/previous
|
|
180 |
// buttons.
|
|
181 |
LOG_FORMAT("mFavoriteStationCount: %d", mFavoriteStationCount);
|
|
182 |
// Enable or disable buttons only if favoriteCount differs
|
|
183 |
// from 1. CurrentIsFavorite case handles situation when there
|
|
184 |
// is only one favorite station.
|
|
185 |
if (mFavoriteStationCount != FAVORITE_STATION_COUNT_ONE) {
|
|
186 |
enableStationButtons();
|
|
187 |
}
|
|
188 |
} else {
|
|
189 |
mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
|
|
190 |
}
|
|
191 |
break;
|
|
192 |
|
|
193 |
case RadioServiceNotification::CurrentIsFavorite:
|
|
194 |
LOG("CurrentIsFavorite");
|
|
195 |
if (information.canConvert(QVariant::Bool)) {
|
|
196 |
mCurrentStationIsFavorite = information.toBool();
|
|
197 |
LOG_FORMAT("currentIsFavorite: %d", mCurrentStationIsFavorite);
|
|
198 |
// If current station is favorite disable next/prev buttons.
|
|
199 |
// Radio sends this information only when there is only one
|
|
200 |
// favorite station set.
|
|
201 |
enableStationButtons();
|
|
202 |
}
|
|
203 |
break;
|
|
204 |
|
|
205 |
case RadioServiceNotification::RadioStatus:
|
|
206 |
LOG("RadioStatus");
|
|
207 |
if (information.canConvert(QVariant::Int)) {
|
|
208 |
const int status = information.toInt();
|
|
209 |
switch (status) {
|
|
210 |
case RadioStatus::Playing:
|
|
211 |
LOG("Playing");
|
36
|
212 |
handleRadioStateChange(FmRadio::StateRunning);
|
34
|
213 |
break;
|
|
214 |
case RadioStatus::Muted:
|
|
215 |
LOG("Muted");
|
|
216 |
break;
|
|
217 |
case RadioStatus::Seeking:
|
|
218 |
LEVEL2(LOG("Seeking"));
|
|
219 |
handleRadioStateChange(FmRadio::StateSeeking);
|
|
220 |
break;
|
|
221 |
case RadioStatus::NoAntenna:
|
|
222 |
LEVEL2(LOG("NoAntenna"));
|
|
223 |
handleRadioStateChange(FmRadio::StateAntennaNotConnected);
|
|
224 |
break;
|
|
225 |
case RadioStatus::PoweringOff:
|
|
226 |
LEVEL2(LOG("PoweringOff"));
|
|
227 |
handleRadioStateChange(FmRadio::StateClosing);
|
|
228 |
break;
|
|
229 |
default:
|
|
230 |
LOG("default case at case RadioStatus");
|
|
231 |
break;
|
|
232 |
}
|
|
233 |
}
|
|
234 |
break;
|
|
235 |
|
|
236 |
case RadioServiceNotification::Frequency:
|
|
237 |
LOG("Frequency");
|
|
238 |
// TODO: Should information.toString() be checked for too many characters? What's the limit?
|
|
239 |
if (information.canConvert(QVariant::String)) {
|
|
240 |
LOG_FORMAT("frequency: %s", GETSTRING(information.toString()));
|
|
241 |
// TODO: Remove comment when localisation is working on device.
|
|
242 |
//frequencyString = hbTrId("txt_fmradiohswidget_rad_list_l1_mhz").arg(freqString);
|
|
243 |
bool frequencyCleared = false;
|
36
|
244 |
|
|
245 |
if (mRadioInformation.contains(Frequency)) {
|
|
246 |
// Clear all infromation.
|
34
|
247 |
clearRadioInformation();
|
|
248 |
frequencyCleared = true;
|
|
249 |
}
|
|
250 |
// If widget do not have any frquency information, update it.
|
|
251 |
bool frequencyUpdated = updateRadioInformation(Frequency,
|
|
252 |
information.toString());
|
|
253 |
if (frequencyCleared || frequencyUpdated) {
|
|
254 |
// Information changed, update the UI.
|
|
255 |
changeInRadioInformation();
|
36
|
256 |
mFmRadioState = FmRadio::StateRunning;
|
34
|
257 |
}
|
|
258 |
}
|
|
259 |
break;
|
|
260 |
|
|
261 |
case RadioServiceNotification::Name:
|
|
262 |
LOG("Name");
|
|
263 |
handleSimilarRadioInformation(StationName, information);
|
|
264 |
break;
|
|
265 |
|
|
266 |
case RadioServiceNotification::Genre:
|
|
267 |
LOG("Genre");
|
|
268 |
handleSimilarRadioInformation(Pty, information);
|
|
269 |
break;
|
|
270 |
|
|
271 |
case RadioServiceNotification::RadioText:
|
|
272 |
LOG("RadioText");
|
|
273 |
handleSimilarRadioInformation(RadioText, information);
|
|
274 |
break;
|
|
275 |
|
|
276 |
case RadioServiceNotification::DynamicPS:
|
|
277 |
LOG("DynamicPS");
|
|
278 |
handleSimilarRadioInformation(DynamicPsName, information);
|
|
279 |
break;
|
|
280 |
|
|
281 |
default:
|
|
282 |
LOG("default case at notificationId");
|
|
283 |
break;
|
|
284 |
}
|
|
285 |
}
|
|
286 |
|
|
287 |
/*!
|
|
288 |
Handles changes in FM Radio state.
|
|
289 |
|
|
290 |
\param value New state of the radio application.
|
|
291 |
*/
|
|
292 |
void RadioHsWidget::handleRadioStateChange(const QVariant &value)
|
|
293 |
{
|
|
294 |
LOG_METHOD;
|
|
295 |
int state;
|
|
296 |
if (value.canConvert(QVariant::Int)) {
|
|
297 |
state = value.toInt();
|
|
298 |
} else {
|
|
299 |
return;
|
|
300 |
}
|
|
301 |
|
|
302 |
if (state == mFmRadioState) {
|
|
303 |
// State did not change, so return.
|
|
304 |
return;
|
|
305 |
}
|
|
306 |
|
|
307 |
switch (state) {
|
|
308 |
case FmRadio::StateUndefined:
|
|
309 |
LOG("FmRadio::StateUndefined");
|
|
310 |
// Something went wrong. Widget should not be in this state after onInitialize().
|
|
311 |
mFmRadioState = FmRadio::StateUndefined;
|
|
312 |
break;
|
|
313 |
case FmRadio::StateNotRunning:
|
|
314 |
LOG("FmRadio::StateNotRunning");
|
|
315 |
mFmRadioState = FmRadio::StateNotRunning;
|
|
316 |
mRadioServiceClient->stopMonitoring();
|
|
317 |
changePowerButtonOn(false);
|
|
318 |
mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
|
|
319 |
mCurrentStationIsFavorite = false;
|
|
320 |
enableStationButtons();
|
|
321 |
clearRadioInformation();
|
|
322 |
mInformationFirstRowLabel->setPlainText("");
|
|
323 |
mInformationSecondRowLabel->setPlainText("");
|
|
324 |
mInformationLonelyRowLabel->setPlainText(hbTrId("txt_fmradiohswidget_rad_list_fm_radio"));
|
|
325 |
changeInformationAreaLayout(OneRow);
|
|
326 |
break;
|
|
327 |
case FmRadio::StateStarting:
|
|
328 |
LOG("FmRadio::StateStarting");
|
|
329 |
mFmRadioState = FmRadio::StateStarting;
|
|
330 |
changePowerButtonOn(true);
|
|
331 |
mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
|
|
332 |
mCurrentStationIsFavorite = false;
|
|
333 |
enableStationButtons();
|
|
334 |
changeInformationAreaLayout(Animation);
|
|
335 |
break;
|
|
336 |
case FmRadio::StateRunning:
|
|
337 |
LOG("FmRadio::StateRunning");
|
|
338 |
mFmRadioState = FmRadio::StateRunning;
|
|
339 |
// Stop timer if it is running because radio is now running.
|
|
340 |
mRadioServiceClient->startMonitoring(
|
|
341 |
FmRadio::VisibiltyDoNotChange);
|
36
|
342 |
changeInRadioInformation();
|
34
|
343 |
changePowerButtonOn(true);
|
|
344 |
enableStationButtons();
|
|
345 |
changeInformationAreaLayout(OneRow);
|
|
346 |
break;
|
|
347 |
case FmRadio::StateSeeking:
|
|
348 |
LOG("FmRadio::StateSeeking");
|
|
349 |
mFmRadioState = FmRadio::StateSeeking;
|
|
350 |
mCurrentStationIsFavorite = false;
|
|
351 |
enableStationButtons();
|
|
352 |
changeInformationAreaLayout(Animation);
|
|
353 |
break;
|
|
354 |
case FmRadio::StateAntennaNotConnected:
|
|
355 |
LOG("FmRadio::StateAntennaNotConnected");
|
|
356 |
mFmRadioState = FmRadio::StateAntennaNotConnected;
|
|
357 |
mCurrentStationIsFavorite = false;
|
|
358 |
enableStationButtons();
|
|
359 |
mInformationFirstRowLabel->setPlainText("");
|
|
360 |
mInformationSecondRowLabel->setPlainText("");
|
|
361 |
mInformationLonelyRowLabel->setPlainText(hbTrId(
|
|
362 |
"txt_fmradiohswidget_rad_info_connect_wired_headset"));
|
|
363 |
changeInformationAreaLayout(OneRow);
|
|
364 |
break;
|
|
365 |
case FmRadio::StateClosing:
|
|
366 |
LOG("FmRadio::StateClosing");
|
|
367 |
mFmRadioState = FmRadio::StateClosing;
|
|
368 |
changePowerButtonOn(false);
|
|
369 |
mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
|
|
370 |
mCurrentStationIsFavorite = false;
|
|
371 |
enableStationButtons();
|
|
372 |
clearRadioInformation();
|
|
373 |
mInformationFirstRowLabel->setPlainText("");
|
|
374 |
mInformationSecondRowLabel->setPlainText("");
|
|
375 |
mInformationLonelyRowLabel->setPlainText(hbTrId(
|
|
376 |
"txt_fmradiohswidget_rad_list_fm_radio"));
|
|
377 |
changeInformationAreaLayout(OneRow);
|
|
378 |
break;
|
|
379 |
default:
|
|
380 |
LOG_FORMAT("default case at state. State: %d", state);
|
|
381 |
break;
|
|
382 |
}
|
|
383 |
}
|
|
384 |
|
|
385 |
/*!
|
|
386 |
Called when widget is initialized. Constructs objects and connects them.
|
|
387 |
*/
|
|
388 |
void RadioHsWidget::onInitialize()
|
|
389 |
{
|
|
390 |
LOG_METHOD_ENTER;
|
|
391 |
mProfileMonitor = new RadioHsWidgetProfileReader(this);
|
|
392 |
mRadioServiceClient = new RadioHsWidgetRadioServiceClient(this);
|
|
393 |
|
|
394 |
load(DOCML);
|
|
395 |
|
|
396 |
// Use signal mapper to indicate button identifiers to button event
|
|
397 |
// slots.
|
|
398 |
QSignalMapper* signalMapperPressed = new QSignalMapper(this);
|
|
399 |
signalMapperPressed->setMapping(mPowerButton, Power);
|
|
400 |
signalMapperPressed->setMapping(mPreviousButton, Previous);
|
|
401 |
signalMapperPressed->setMapping(mNextButton, Next);
|
|
402 |
|
|
403 |
// Need to use different signal mapper for pressed and released events,
|
|
404 |
// both have same mappings but they are mapped to different slots.
|
|
405 |
QSignalMapper* signalMapperReleased = new QSignalMapper(this);
|
|
406 |
signalMapperReleased->setMapping(mPowerButton, Power);
|
|
407 |
signalMapperReleased->setMapping(mPreviousButton, Previous);
|
|
408 |
signalMapperReleased->setMapping(mNextButton, Next);
|
|
409 |
|
|
410 |
// Connect button events to signal maps.
|
|
411 |
Radio::connect(mPowerButton, SIGNAL(pressed()), signalMapperPressed, SLOT (map()));
|
|
412 |
Radio::connect(mPowerButton, SIGNAL(released()), signalMapperReleased, SLOT (map()));
|
|
413 |
Radio::connect(mPreviousButton, SIGNAL(pressed()), signalMapperPressed, SLOT (map()));
|
|
414 |
Radio::connect(mPreviousButton, SIGNAL(released()), signalMapperReleased, SLOT (map()));
|
|
415 |
Radio::connect(mNextButton, SIGNAL(pressed()), signalMapperPressed, SLOT (map()));
|
|
416 |
Radio::connect(mNextButton, SIGNAL(released()), signalMapperReleased, SLOT (map()));
|
|
417 |
|
|
418 |
// Connect mapper signals to self implemented slots.
|
|
419 |
Radio::connect(signalMapperPressed, SIGNAL(mapped(int)), this, SLOT(changeButtonToPressed(int)));
|
|
420 |
Radio::connect(signalMapperReleased, SIGNAL(mapped(int)), this, SLOT(changeButtonToReleased(int)));
|
|
421 |
|
|
422 |
mProfileMonitor->startMonitoringRadioRunningStatus();
|
|
423 |
}
|
|
424 |
|
|
425 |
/*!
|
|
426 |
Called when widget is shown in the home screen
|
|
427 |
*/
|
|
428 |
void RadioHsWidget::onShow()
|
|
429 |
{
|
|
430 |
LOG_METHOD_ENTER;
|
|
431 |
}
|
|
432 |
|
|
433 |
/*!
|
|
434 |
Called when widget is hidden from the home screen
|
|
435 |
*/
|
|
436 |
void RadioHsWidget::onHide()
|
|
437 |
{
|
|
438 |
LOG_METHOD_ENTER;
|
|
439 |
}
|
|
440 |
|
|
441 |
/*!
|
|
442 |
Emited from HbPushButton:pressed() signal, changes the button layout to
|
|
443 |
pressed state.
|
|
444 |
|
|
445 |
\param hsButtonIdentifier Identifies the button which was pressed.
|
|
446 |
*/
|
|
447 |
void RadioHsWidget::changeButtonToPressed(int hsButtonIdentifier)
|
|
448 |
{
|
|
449 |
LEVEL2(LOG_METHOD);
|
|
450 |
buttonEvent(static_cast<ControlButtonIdentifier>(hsButtonIdentifier), Pressed);
|
|
451 |
}
|
|
452 |
|
|
453 |
/*!
|
|
454 |
Emited from HbPushButton:released() signal, changes the button layout to
|
|
455 |
normal state.
|
|
456 |
|
|
457 |
\param hsButtonIdentifier Identifies the button which was released.
|
|
458 |
*/
|
|
459 |
void RadioHsWidget::changeButtonToReleased(int hsButtonIdentifier)
|
|
460 |
{
|
|
461 |
LEVEL2(LOG_METHOD);
|
|
462 |
buttonEvent(static_cast<ControlButtonIdentifier>(hsButtonIdentifier), Normal);
|
|
463 |
}
|
|
464 |
|
|
465 |
/*!
|
|
466 |
Slot for closing FM Radio application from power button.
|
|
467 |
*/
|
|
468 |
void RadioHsWidget::closeRadio()
|
|
469 |
{
|
|
470 |
LOG_SLOT_CALLER;
|
|
471 |
mRadioServiceClient->commandFmRadio(RadioServiceCommand::PowerOff);
|
|
472 |
}
|
|
473 |
|
|
474 |
/*!
|
|
475 |
Slot for previous button clicked.
|
|
476 |
*/
|
|
477 |
void RadioHsWidget::changeToPreviousStation()
|
|
478 |
{
|
|
479 |
LOG_SLOT_CALLER;
|
|
480 |
clearRadioInformation();
|
|
481 |
mRadioServiceClient->commandFmRadio(RadioServiceCommand::Previous);
|
|
482 |
}
|
|
483 |
|
|
484 |
/*!
|
|
485 |
Slot for next button clicked.
|
|
486 |
*/
|
|
487 |
void RadioHsWidget::changeToNextStation()
|
|
488 |
{
|
|
489 |
LOG_SLOT_CALLER;
|
|
490 |
clearRadioInformation();
|
|
491 |
mRadioServiceClient->commandFmRadio(RadioServiceCommand::Next);
|
|
492 |
|
|
493 |
}
|
|
494 |
|
|
495 |
/*!
|
|
496 |
Slot for bringing the radio application to foreground.
|
|
497 |
*/
|
|
498 |
void RadioHsWidget::changeRadioToForeground()
|
|
499 |
{
|
|
500 |
LOG_SLOT_CALLER;
|
|
501 |
// If radio is not running start it to foreground by monitor request.
|
|
502 |
if (mFmRadioState == FmRadio::StateNotRunning) {
|
|
503 |
bool okToStartRadio = radioStartPermission();
|
|
504 |
if (okToStartRadio) {
|
|
505 |
handleRadioStateChange(FmRadio::StateStarting);
|
|
506 |
mRadioServiceClient->startMonitoring(
|
|
507 |
FmRadio::VisibiltyToForeground);
|
|
508 |
}
|
|
509 |
}
|
|
510 |
else {
|
|
511 |
if (mFmRadioState == FmRadio::StateClosing) {
|
|
512 |
// Radio is closing but user wants to power it up again.
|
|
513 |
mRadioServiceClient->commandFmRadio(RadioServiceCommand::PowerOn);
|
|
514 |
// Stop and start monitoring to get refresh.
|
|
515 |
mRadioServiceClient->stopMonitoring();
|
|
516 |
mRadioServiceClient->startMonitoring(
|
|
517 |
FmRadio::VisibiltyToBackground);
|
|
518 |
handleRadioStateChange(FmRadio::StateRunning);
|
|
519 |
}
|
|
520 |
// If radio is running, bring it to the foreground.
|
|
521 |
mRadioServiceClient->commandFmRadio(RadioServiceCommand::Foreground);
|
|
522 |
}
|
|
523 |
}
|
|
524 |
|
|
525 |
/*!
|
|
526 |
Slot for putting the radio application to the background.
|
|
527 |
*/
|
|
528 |
void RadioHsWidget::changeRadioToBackground()
|
|
529 |
{
|
|
530 |
LOG_SLOT_CALLER;
|
|
531 |
// If radio is not running start it to background by monitor request.
|
|
532 |
if (mFmRadioState == FmRadio::StateNotRunning) {
|
|
533 |
bool okToStartRadio = radioStartPermission();
|
|
534 |
if (okToStartRadio) {
|
|
535 |
handleRadioStateChange(FmRadio::StateStarting);
|
|
536 |
mRadioServiceClient->startMonitoring(
|
|
537 |
FmRadio::VisibiltyToBackground);
|
|
538 |
}
|
|
539 |
}
|
|
540 |
else if (mFmRadioState == FmRadio::StateStarting) {
|
|
541 |
// Do nothing if radio is starting.
|
|
542 |
}
|
|
543 |
else if (mFmRadioState == FmRadio::StateClosing) {
|
|
544 |
// Radio is closing but user wants to power it up again.
|
|
545 |
mRadioServiceClient->commandFmRadio(RadioServiceCommand::PowerOn);
|
|
546 |
// Stop and start monitoring to get refresh.
|
|
547 |
mRadioServiceClient->stopMonitoring();
|
|
548 |
mRadioServiceClient->startMonitoring(
|
|
549 |
FmRadio::VisibiltyToBackground);
|
|
550 |
handleRadioStateChange(FmRadio::StateRunning);
|
|
551 |
}
|
|
552 |
else {
|
|
553 |
// If radio is running, put it to the background.
|
|
554 |
// This is little bit useless because the radio is in background if
|
|
555 |
// user is able to click the widget.
|
|
556 |
mRadioServiceClient->commandFmRadio(RadioServiceCommand::Background);
|
|
557 |
}
|
|
558 |
}
|
|
559 |
|
|
560 |
/*!
|
|
561 |
Powering off or on the radio.
|
|
562 |
*/
|
|
563 |
void RadioHsWidget::toggleRadioPower()
|
|
564 |
{
|
|
565 |
LOG_SLOT_CALLER;
|
|
566 |
// If radio is not running start it to background by monitor request.
|
|
567 |
if (mFmRadioState == FmRadio::StateNotRunning || mFmRadioState == FmRadio::StateClosing) {
|
|
568 |
LEVEL2(LOG("Power on"));
|
|
569 |
// Start radio
|
|
570 |
changeRadioToBackground();
|
|
571 |
} else {
|
|
572 |
LEVEL2(LOG("Power off"));
|
|
573 |
// Close radio
|
|
574 |
closeRadio();
|
|
575 |
}
|
|
576 |
}
|
|
577 |
|
|
578 |
/*!
|
|
579 |
Loads docml file.
|
|
580 |
|
|
581 |
\param docml Docml filename to be loaded.
|
|
582 |
*/
|
|
583 |
void RadioHsWidget::load(const QString &docml)
|
|
584 |
{
|
|
585 |
LOG_METHOD_ENTER;
|
|
586 |
|
|
587 |
QScopedPointer<HbDocumentLoader> documentLoader(new HbDocumentLoader());
|
|
588 |
bool loaded = false;
|
|
589 |
documentLoader->load(docml, &loaded);
|
|
590 |
if (loaded) {
|
|
591 |
// Find mainLayout
|
|
592 |
HbWidget *mainLayout = qobject_cast<HbWidget*> (
|
|
593 |
documentLoader->findWidget(DOCML_OBJECT_NAME_MAIN_LAYOUT));
|
|
594 |
|
|
595 |
if (mainLayout) {
|
|
596 |
QGraphicsLinearLayout *widgetLayout = new QGraphicsLinearLayout(
|
|
597 |
Qt::Vertical, this);
|
|
598 |
widgetLayout->addItem(mainLayout);
|
|
599 |
setLayout(widgetLayout);
|
|
600 |
}
|
|
601 |
|
|
602 |
// Find contentLayout
|
|
603 |
HbWidget *contentLayout = qobject_cast<HbWidget*> (
|
|
604 |
documentLoader->findWidget(DOCML_OBJECT_NAME_CONTENT_LAYOUT));
|
|
605 |
if (contentLayout) {
|
|
606 |
|
|
607 |
// Find stacked layout for tuner area.
|
|
608 |
HbWidget *tunerStackedLayout = qobject_cast<HbWidget*> (
|
|
609 |
documentLoader->findWidget(
|
|
610 |
DOCML_OBJECT_NAME_TUNER_STACKED_LAYOUT));
|
|
611 |
if (tunerStackedLayout) {
|
|
612 |
|
|
613 |
// Find stacked layout for information area.
|
|
614 |
HbWidget *tunerInformationStackedLayout = qobject_cast<
|
|
615 |
HbWidget*> (documentLoader->findWidget(
|
|
616 |
DOCML_OBJECT_NAME_TUNER_INFORMATION_STACKED_LAYOUT));
|
|
617 |
if (tunerInformationStackedLayout) {
|
|
618 |
}
|
|
619 |
|
|
620 |
// Find lonely label
|
|
621 |
mInformationLonelyRowLabel = qobject_cast<HbLabel *> (
|
|
622 |
documentLoader->findWidget(
|
|
623 |
DOCML_OBJECT_NAME_LONELY_ROW_LABEL));
|
|
624 |
if (mInformationLonelyRowLabel) {
|
|
625 |
// TODO: Set the color in docml when application designer supports it.
|
|
626 |
QColor color = HbColorScheme::color(
|
|
627 |
"qtc_radio_tuner_normal");
|
|
628 |
mInformationLonelyRowLabel->setTextColor(color);
|
|
629 |
}
|
|
630 |
|
|
631 |
// Find layout for two rows
|
|
632 |
mInformationAreaTwoRowsLayout = qobject_cast<
|
|
633 |
QGraphicsWidget *> (documentLoader->findObject(
|
|
634 |
DOCML_OBJECT_NAME_TWO_ROWS_LAYOUT));
|
|
635 |
if (mInformationAreaTwoRowsLayout) {
|
|
636 |
// Find first row
|
|
637 |
mInformationFirstRowLabel = qobject_cast<HbLabel *> (
|
|
638 |
documentLoader->findWidget(
|
|
639 |
DOCML_OBJECT_NAME_FIRST_ROW_LABEL));
|
|
640 |
if (mInformationFirstRowLabel) {
|
|
641 |
// TODO: Set the color in docml when application designer supports it.
|
|
642 |
QColor color = HbColorScheme::color(
|
|
643 |
"qtc_radio_tuner_normal");
|
|
644 |
mInformationFirstRowLabel->setTextColor(color);
|
|
645 |
}
|
|
646 |
|
|
647 |
// Find second row
|
|
648 |
mInformationSecondRowLabel = qobject_cast<HbLabel *> (
|
|
649 |
documentLoader->findWidget(
|
|
650 |
DOCML_OBJECT_NAME_SECOND_ROW_LABEL));
|
|
651 |
if (mInformationSecondRowLabel) {
|
|
652 |
// TODO: Set the color in docml when application designer supports it.
|
|
653 |
QColor color = HbColorScheme::color(
|
|
654 |
"qtc_radio_tuner_normal");
|
|
655 |
mInformationSecondRowLabel->setTextColor(color);
|
|
656 |
}
|
|
657 |
}
|
|
658 |
|
|
659 |
mAnimationIcon = qobject_cast<HbLabel *> (
|
|
660 |
documentLoader->findWidget(
|
|
661 |
DOCML_OBJECT_NAME_ANIMATION_ICON));
|
|
662 |
if (mAnimationIcon) {
|
|
663 |
// Use animation manager to access anim loading animation.
|
|
664 |
HbIconAnimationManager *animationManager =
|
|
665 |
HbIconAnimationManager::global();
|
|
666 |
// TODO: Axml extension can be removed after wk24 release.
|
|
667 |
animationManager->addDefinitionFile(QLatin1String(
|
|
668 |
"qtg_anim_loading.axml"));
|
|
669 |
mAnimationIcon->setIcon(HbIcon("qtg_anim_loading"));
|
|
670 |
}
|
|
671 |
}
|
|
672 |
|
|
673 |
// Find push button for tuner area.
|
|
674 |
mInformationAreaBackgroundButton = qobject_cast<HbPushButton*> (
|
|
675 |
documentLoader->findWidget(
|
|
676 |
DOCML_OBJECT_NAME_TUNER_BACKGROUND_BUTTON));
|
|
677 |
if (mInformationAreaBackgroundButton) {
|
|
678 |
// Use the frame background.
|
|
679 |
HbFrameDrawer *tunerBackgroundButtonFrameDrawer =
|
|
680 |
new HbFrameDrawer("qtg_fr_tuner",
|
|
681 |
HbFrameDrawer::ThreePiecesHorizontal);
|
|
682 |
tunerBackgroundButtonFrameDrawer->setFillWholeRect(true);
|
|
683 |
mInformationAreaBackgroundButton->setFrameBackground(
|
|
684 |
tunerBackgroundButtonFrameDrawer);
|
|
685 |
// Connect the button's clicked signal.
|
|
686 |
Radio::connect(mInformationAreaBackgroundButton,
|
|
687 |
SIGNAL(clicked()), this, SLOT(changeRadioToForeground()));
|
|
688 |
}
|
|
689 |
|
|
690 |
// Find layout for control buttons.
|
|
691 |
HbWidget *controlButtonsLayout = qobject_cast<HbWidget*> (
|
|
692 |
documentLoader->findWidget(
|
|
693 |
DOCML_OBJECT_NAME_CONTROL_BUTTONS_LAYOUT));
|
|
694 |
if (controlButtonsLayout) {
|
|
695 |
|
|
696 |
// Find power button.
|
|
697 |
mPowerButton
|
|
698 |
= qobject_cast<HbPushButton *> (
|
|
699 |
documentLoader->findWidget(
|
|
700 |
DOCML_OBJECT_NAME_POWER_BUTTON));
|
|
701 |
if (mPowerButton) {
|
|
702 |
defineButton(*mPowerButton,
|
|
703 |
CONTROL_BUTTON_GRAPHICS_NORMAL, POWER_BUTTON_SUFFIX,
|
|
704 |
POWER_BUTTON_ICON_ON,
|
|
705 |
CONTROL_BUTTON_ICON_COLOR_NORMAL);
|
|
706 |
// Connect the button's clicked signal.
|
44
|
707 |
Radio::connect(mPowerButton, SIGNAL(clicked()),
|
|
708 |
this, SLOT(toggleRadioPower()));
|
34
|
709 |
}
|
|
710 |
|
|
711 |
// Find previous button.
|
|
712 |
mPreviousButton = qobject_cast<HbPushButton *> (
|
|
713 |
documentLoader->findWidget(
|
|
714 |
DOCML_OBJECT_NAME_PREVIOUS_BUTTON));
|
|
715 |
if (mPreviousButton) {
|
|
716 |
defineButton(*mPreviousButton,
|
|
717 |
CONTROL_BUTTON_GRAPHICS_DISABLED,
|
|
718 |
PREVIOUS_BUTTON_SUFFIX, NULL,
|
|
719 |
CONTROL_BUTTON_ICON_COLOR_DISABLED);
|
|
720 |
// Connect the button's clicked signal.
|
44
|
721 |
Radio::connect(mPreviousButton, SIGNAL(clicked()),
|
|
722 |
this, SLOT(changeToPreviousStation()));
|
34
|
723 |
}
|
|
724 |
|
|
725 |
// Find next button.
|
|
726 |
mNextButton
|
|
727 |
= qobject_cast<HbPushButton *> (
|
|
728 |
documentLoader->findWidget(
|
|
729 |
DOCML_OBJECT_NAME_NEXT_BUTTON));
|
|
730 |
if (mNextButton) {
|
|
731 |
defineButton(*mNextButton,
|
|
732 |
CONTROL_BUTTON_GRAPHICS_DISABLED, NEXT_BUTTON_SUFFIX,
|
|
733 |
NULL, CONTROL_BUTTON_ICON_COLOR_DISABLED);
|
|
734 |
// Connect the button's clicked signal.
|
44
|
735 |
Radio::connect(mNextButton, SIGNAL(clicked()),
|
|
736 |
this, SLOT(changeToNextStation()));
|
34
|
737 |
}
|
|
738 |
}
|
|
739 |
}
|
|
740 |
}
|
|
741 |
else {
|
|
742 |
// Docml was not succesfully loaded. UI cannot be displayed.
|
|
743 |
// Emit error to home screen framework, which removes the widget.
|
|
744 |
emit error();
|
|
745 |
}
|
|
746 |
}
|
|
747 |
|
|
748 |
/*!
|
|
749 |
Groups handling of similar kind of radio information (textual) to one
|
|
750 |
function.
|
|
751 |
|
|
752 |
\param informationType Type of changed information.
|
|
753 |
\param information Actual textual information.
|
|
754 |
*/
|
|
755 |
void RadioHsWidget::handleSimilarRadioInformation(
|
|
756 |
const FmRadioInformationType informationType, const QVariant &information)
|
|
757 |
{
|
|
758 |
LOG_METHOD_ENTER;
|
|
759 |
// TODO: Should information.toString() be checked for too many characters? What's the limit?
|
|
760 |
if (information.canConvert(QVariant::String) && updateRadioInformation(
|
|
761 |
informationType, information.toString())) {
|
|
762 |
LOG_FORMAT("informationType: %d, information: %s", informationType, GETSTRING(information.toString()));
|
|
763 |
changeInRadioInformation();
|
|
764 |
}
|
|
765 |
}
|
|
766 |
|
|
767 |
/*!
|
|
768 |
Check if the the radio information is changed. If it is changed, it is
|
|
769 |
also updated.
|
|
770 |
|
|
771 |
\param informationType Type of the information.
|
|
772 |
\param information Information text.
|
|
773 |
|
|
774 |
\returns Returns \c true, if information is updated. Returns \c false otherwise.
|
|
775 |
*/
|
|
776 |
bool RadioHsWidget::updateRadioInformation(const FmRadioInformationType informationType,
|
|
777 |
const QString &information)
|
|
778 |
{
|
|
779 |
LOG_METHOD_RET("%d");
|
|
780 |
// If hash contains this type of information.
|
|
781 |
if (mRadioInformation.contains(informationType)) {
|
|
782 |
// If new information is empty.
|
|
783 |
if (information.isEmpty()) {
|
|
784 |
// Remove old information from the hash.
|
|
785 |
LEVEL2(LOG_FORMAT("informationType: %s removed", GETSTRING(informationType)));
|
|
786 |
mRadioInformation.remove(informationType);
|
|
787 |
// Return true to indicate the change.
|
|
788 |
return true;
|
|
789 |
}
|
|
790 |
// If new information differs from the old one.
|
|
791 |
if (mRadioInformation[informationType].compare(information) != 0) {
|
|
792 |
// Update the information.
|
|
793 |
LEVEL2(LOG_FORMAT("informationType: %s = %s", GETSTRING(informationType), GETSTRING(information)));
|
|
794 |
mRadioInformation[informationType] = information;
|
|
795 |
// And return true to indicate the change.
|
|
796 |
return true;
|
|
797 |
}
|
|
798 |
} else { // Hash do not contain this type of information.
|
|
799 |
// If new information is not empty.
|
|
800 |
if (!information.isEmpty()) {
|
|
801 |
// Add it to the hash.
|
|
802 |
LEVEL2(LOG_FORMAT("informationType: %s = %s", GETSTRING(informationType), GETSTRING(information)));
|
|
803 |
mRadioInformation[informationType] = information;
|
|
804 |
// Return true to indicate the change.
|
|
805 |
return true;
|
|
806 |
}
|
|
807 |
}
|
|
808 |
// Return false to indicate that nothing changed.
|
|
809 |
return false;
|
|
810 |
}
|
|
811 |
|
|
812 |
/*!
|
|
813 |
Formatting radio information texts after a change.
|
|
814 |
*/
|
|
815 |
void RadioHsWidget::changeInRadioInformation()
|
|
816 |
{
|
|
817 |
LOG_METHOD_ENTER;
|
|
818 |
// Clear the rows.
|
|
819 |
mRadioInformationFirstRow.clear();
|
|
820 |
mRadioInformationSecondRow.clear();
|
|
821 |
|
|
822 |
// First row contains station name.
|
|
823 |
if (mRadioInformation.contains(StationName)) {
|
|
824 |
mRadioInformationFirstRow.append(mRadioInformation.value(StationName));
|
|
825 |
}
|
|
826 |
else if (mRadioInformation.contains(Frequency)) {
|
|
827 |
// Or frequency.
|
|
828 |
mRadioInformationFirstRow.append(mRadioInformation.value(Frequency));
|
|
829 |
} LEVEL2(LOG_FORMAT("mRadioInformationFirstRow: %s", GETSTRING(mRadioInformationFirstRow)));
|
|
830 |
|
|
831 |
// Second row of information contains radio text.
|
|
832 |
if (mRadioInformation.contains(RadioText)) {
|
|
833 |
mRadioInformationSecondRow.append(mRadioInformation.value(RadioText));
|
|
834 |
}
|
|
835 |
else if (mRadioInformation.contains(DynamicPsName)) {
|
|
836 |
// Or Dynamic PS name.
|
|
837 |
mRadioInformationSecondRow.append(mRadioInformation.value(DynamicPsName));
|
|
838 |
}
|
|
839 |
else if (mRadioInformation.contains(Pty)) {
|
|
840 |
// Or PTY.
|
|
841 |
mRadioInformationSecondRow.append(mRadioInformation.value(Pty));
|
|
842 |
}
|
|
843 |
LEVEL2(LOG_FORMAT("mRadioInformationSecondRow: %s", GETSTRING(mRadioInformationSecondRow)));
|
|
844 |
|
|
845 |
// If second row is empty.
|
|
846 |
if (mRadioInformationSecondRow.isEmpty()) {
|
|
847 |
// Show only the lonely row.
|
|
848 |
mInformationLonelyRowLabel->setPlainText(mRadioInformationFirstRow);
|
|
849 |
changeInformationAreaLayout(OneRow);
|
|
850 |
}
|
|
851 |
else {
|
|
852 |
// Else display both rows.
|
|
853 |
mInformationFirstRowLabel->setPlainText(mRadioInformationFirstRow);
|
|
854 |
mInformationSecondRowLabel->setPlainText(mRadioInformationSecondRow);
|
|
855 |
changeInformationAreaLayout(TwoRows);
|
|
856 |
}
|
|
857 |
}
|
|
858 |
|
|
859 |
/*!
|
|
860 |
Clears the radio station information. For example, when the station is
|
|
861 |
changed, old information should be cleared.
|
|
862 |
*/
|
|
863 |
void RadioHsWidget::clearRadioInformation()
|
|
864 |
{
|
|
865 |
LOG_METHOD_ENTER;
|
|
866 |
mRadioInformation.clear();
|
|
867 |
}
|
|
868 |
|
|
869 |
/*!
|
|
870 |
Changes visible widgets of information area stacked layout.
|
|
871 |
|
|
872 |
\param layout The layout to switch visible.
|
|
873 |
*/
|
|
874 |
void RadioHsWidget::changeInformationAreaLayout(const InformationAreaLayout layout)
|
|
875 |
{
|
|
876 |
LOG_METHOD_ENTER;
|
|
877 |
mInformationLonelyRowLabel->setVisible(layout == OneRow);
|
|
878 |
mInformationAreaTwoRowsLayout->setVisible(layout == TwoRows);
|
|
879 |
mAnimationIcon->setVisible(layout == Animation);
|
|
880 |
}
|
|
881 |
|
|
882 |
/*!
|
|
883 |
Changes state of power button.
|
|
884 |
|
|
885 |
\param isPowerOn \c true the power is on and \c false the power is off.
|
|
886 |
*/
|
|
887 |
void RadioHsWidget::changePowerButtonOn(const bool isPowerOn)
|
|
888 |
{
|
|
889 |
LEVEL2(LOG_METHOD);
|
|
890 |
if (isPowerOn) {
|
|
891 |
LEVEL2(LOG("Power on"));
|
|
892 |
// TODO: Temporarily set the text to clarify the action it performs.
|
|
893 |
// Remove when graphics displays the difference.
|
|
894 |
mPowerButton->setText("Off");
|
|
895 |
buttonEvent(Power, Latched);
|
|
896 |
} else {
|
|
897 |
LEVEL2(LOG("Power off"));
|
|
898 |
// TODO: Temporarily set the text to clarify the action it performs.
|
|
899 |
// Remove when graphics displays the difference.
|
|
900 |
mPowerButton->setText("On");
|
|
901 |
buttonEvent(Power, Normal);
|
|
902 |
}
|
|
903 |
}
|
|
904 |
|
|
905 |
/*!
|
|
906 |
Changes enabled state of station buttons.
|
|
907 |
*/
|
|
908 |
void RadioHsWidget::enableStationButtons()
|
|
909 |
{
|
|
910 |
LEVEL2(LOG_METHOD_ENTER);
|
36
|
911 |
LOG_FORMAT("RadioHsWidget::enableStationButtons count: %d", mFavoriteStationCount);
|
|
912 |
if (mFmRadioState == FmRadio::StateAntennaNotConnected){
|
|
913 |
changeButtonToDisabled(Next);
|
|
914 |
changeButtonToDisabled(Previous);
|
|
915 |
}
|
|
916 |
else if ((mFavoriteStationCount > 1) || (mFavoriteStationCount == 1
|
34
|
917 |
&& !mCurrentStationIsFavorite)) {
|
|
918 |
changeButtonToEnabled(Next);
|
|
919 |
changeButtonToEnabled(Previous);
|
|
920 |
}
|
|
921 |
else if ((mFavoriteStationCount == 1 && mCurrentStationIsFavorite)
|
|
922 |
|| (mFavoriteStationCount < 1)) {
|
|
923 |
changeButtonToDisabled(Next);
|
|
924 |
changeButtonToDisabled(Previous);
|
|
925 |
}
|
|
926 |
}
|
|
927 |
|
|
928 |
/*!
|
|
929 |
Makes homescreen specific push button based on parameters.
|
|
930 |
|
|
931 |
\param target Target push button to modify. Must not be NULL.
|
|
932 |
\param graphicsId Defines the target button background graphics.
|
|
933 |
\param suffix Defines the suffix for the target button background graphics.
|
|
934 |
\param icon Defines the icon for the target button.
|
|
935 |
\param iconColor Defines the icon color for the target button.
|
|
936 |
*/
|
|
937 |
void RadioHsWidget::defineButton(HbPushButton &target, const QString &graphicsId,
|
|
938 |
const QStringList &suffix, const QString &icon, const QString &iconColor)
|
|
939 |
{
|
|
940 |
LEVEL2(LOG_METHOD);
|
|
941 |
HbFrameDrawer* drawer = NULL;
|
|
942 |
|
|
943 |
// First check if the drawer is already created for this push button
|
|
944 |
if (!target.frameBackground()) {
|
|
945 |
LEVEL2(LOG("Creating new frame background."));
|
|
946 |
// Nope, create one now
|
|
947 |
drawer = new HbFrameDrawer(graphicsId,
|
|
948 |
HbFrameDrawer::ThreePiecesHorizontal);
|
|
949 |
target.setFrameBackground(drawer);
|
|
950 |
}
|
|
951 |
else {
|
|
952 |
// Frame drawer already created, only need to update frame graphics
|
|
953 |
drawer = target.frameBackground();
|
|
954 |
drawer->setFrameGraphicsName(graphicsId);
|
|
955 |
}
|
|
956 |
|
|
957 |
// Set file name suffix list, so that drawer can load correct 3-piece graphic files
|
|
958 |
drawer->setFileNameSuffixList(suffix);
|
|
959 |
|
|
960 |
// Set the icon, if it is not NULL
|
|
961 |
if (!icon.isNull()) {
|
|
962 |
target.setIcon(HbIcon(icon));
|
|
963 |
}
|
|
964 |
|
|
965 |
// Update also the icon color
|
|
966 |
QColor color = HbColorScheme::color(iconColor);
|
|
967 |
target.icon().setColor(color);
|
|
968 |
|
|
969 |
// Lastly, check if the buttton is disabled
|
|
970 |
if (iconColor == CONTROL_BUTTON_ICON_COLOR_DISABLED) {
|
|
971 |
target.setEnabled(false);
|
|
972 |
}
|
|
973 |
else {
|
|
974 |
target.setEnabled(true);
|
|
975 |
}
|
|
976 |
}
|
|
977 |
|
|
978 |
/*!
|
|
979 |
Prepares the information needed for displaying the button correctly
|
|
980 |
reflecting its state.
|
|
981 |
|
|
982 |
\param buttonId Identifies the button.
|
|
983 |
\param state Tells in what state the button is.
|
|
984 |
*/
|
|
985 |
void RadioHsWidget::buttonEvent(ControlButtonIdentifier buttonId,
|
|
986 |
const ControlButtonState state)
|
|
987 |
{
|
|
988 |
LEVEL2(LOG_METHOD);
|
|
989 |
HbPushButton* target = NULL;
|
|
990 |
QStringList suffix;
|
|
991 |
QString icon;
|
|
992 |
|
|
993 |
switch (buttonId) {
|
|
994 |
case Power:
|
|
995 |
LEVEL2(LOG("Power"));
|
|
996 |
target = mPowerButton;
|
|
997 |
icon = POWER_BUTTON_ICON_ON;
|
|
998 |
suffix = POWER_BUTTON_SUFFIX;
|
|
999 |
break;
|
|
1000 |
case Previous:
|
|
1001 |
LEVEL2(LOG("Previous"));
|
|
1002 |
target = mPreviousButton;
|
|
1003 |
suffix = PREVIOUS_BUTTON_SUFFIX;
|
|
1004 |
break;
|
|
1005 |
case Next:
|
|
1006 |
LEVEL2(LOG("Next"));
|
|
1007 |
target = mNextButton;
|
|
1008 |
suffix = NEXT_BUTTON_SUFFIX;
|
|
1009 |
break;
|
|
1010 |
default:
|
|
1011 |
LOG("default case at buttonId");
|
|
1012 |
break;
|
|
1013 |
}
|
|
1014 |
|
|
1015 |
QString buttonBackgroundGraphics;
|
|
1016 |
QString buttonIconColors;
|
|
1017 |
switch (state) {
|
|
1018 |
case Normal:
|
|
1019 |
LEVEL2(LOG("Normal"));
|
|
1020 |
target->setProperty("state", "normal");
|
|
1021 |
buttonBackgroundGraphics = CONTROL_BUTTON_GRAPHICS_NORMAL;
|
|
1022 |
buttonIconColors = CONTROL_BUTTON_ICON_COLOR_NORMAL;
|
|
1023 |
break;
|
|
1024 |
case Pressed:
|
|
1025 |
LEVEL2(LOG("Pressed"));
|
|
1026 |
target->setProperty("state", "pressed");
|
|
1027 |
buttonBackgroundGraphics = CONTROL_BUTTON_GRAPHICS_PRESSED;
|
|
1028 |
buttonIconColors = CONTROL_BUTTON_ICON_COLOR_PRESSED;
|
|
1029 |
break;
|
|
1030 |
case Disabled:
|
|
1031 |
LEVEL2(LOG("Disabled"));
|
|
1032 |
target->setProperty("state", "disabled");
|
|
1033 |
buttonBackgroundGraphics = CONTROL_BUTTON_GRAPHICS_DISABLED;
|
|
1034 |
buttonIconColors = CONTROL_BUTTON_ICON_COLOR_DISABLED;
|
|
1035 |
break;
|
|
1036 |
case Latched:
|
|
1037 |
LEVEL2(LOG("Latched"));
|
|
1038 |
target->setProperty("state", "latched");
|
|
1039 |
buttonBackgroundGraphics = CONTROL_BUTTON_GRAPHICS_LATCHED;
|
|
1040 |
buttonIconColors = CONTROL_BUTTON_ICON_COLOR_LATCHED;
|
|
1041 |
break;
|
|
1042 |
default:
|
|
1043 |
LOG("default case at button state");
|
|
1044 |
break;
|
|
1045 |
}
|
|
1046 |
|
|
1047 |
RadioHsWidget::defineButton(*target, buttonBackgroundGraphics,
|
|
1048 |
suffix, icon, buttonIconColors);
|
|
1049 |
}
|
|
1050 |
|
|
1051 |
/*!
|
|
1052 |
Disables specified push button.
|
|
1053 |
|
|
1054 |
\param hsButtonIdentifier Which button is to be disabled.
|
|
1055 |
*/
|
|
1056 |
void RadioHsWidget::changeButtonToDisabled(int hsButtonIdentifier)
|
|
1057 |
{
|
|
1058 |
LEVEL2(LOG_METHOD_ENTER);
|
|
1059 |
buttonEvent(static_cast<ControlButtonIdentifier>(hsButtonIdentifier), Disabled);
|
|
1060 |
}
|
|
1061 |
|
|
1062 |
/*!
|
|
1063 |
Enabled specified push button.
|
|
1064 |
|
|
1065 |
\param hsButtonIdentifier Which button is to be enabled.
|
|
1066 |
*/
|
|
1067 |
void RadioHsWidget::changeButtonToEnabled(int hsButtonIdentifier)
|
|
1068 |
{
|
|
1069 |
LEVEL2(LOG_METHOD_ENTER);
|
|
1070 |
changeButtonToReleased(hsButtonIdentifier);
|
|
1071 |
}
|
|
1072 |
|
|
1073 |
/*!
|
|
1074 |
Checks the profile of the device. If profile is offline, user is asked a
|
|
1075 |
permission to start the radio in offline profile. Dialog is shown on
|
|
1076 |
behalf of the radio asking the permission.
|
|
1077 |
|
|
1078 |
\returns \c true if radio can be started, \c false if device is in
|
|
1079 |
offline profile and user didn't gave permission to start the radio.
|
|
1080 |
*/
|
|
1081 |
bool RadioHsWidget::radioStartPermission()
|
|
1082 |
{
|
|
1083 |
LOG_METHOD_ENTER;
|
|
1084 |
// This is true by default because we might not be in offline profile and
|
|
1085 |
// starting the radio is allowed in other profiles without asking a
|
|
1086 |
// permission.
|
|
1087 |
bool radioStartPermssion = true;
|
38
|
1088 |
if (mProfileMonitor->isInOfflineMode()) {
|
34
|
1089 |
// Device is in offline profile, ask the user for permission to start
|
|
1090 |
HbDeviceMessageBox box(hbTrId(
|
|
1091 |
"txt_fmradiohswidget_rad_info_activate_radio_in_offline_mode_hs"),
|
|
1092 |
HbMessageBox::MessageTypeQuestion);
|
|
1093 |
box.setTimeout(HbPopup::NoTimeout);
|
|
1094 |
box.exec();
|
|
1095 |
// radioStartPermssion is now true or false, depending what the user
|
|
1096 |
// selected. If user didn't gave permission, then radio is not
|
|
1097 |
// started.
|
|
1098 |
radioStartPermssion = box.isAcceptAction(box.triggeredAction());
|
|
1099 |
}
|
|
1100 |
return radioStartPermssion;
|
|
1101 |
}
|