24
|
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 |
// System includes
|
|
19 |
#include <HbStyleLoader>
|
|
20 |
#include <HbPushButton>
|
|
21 |
#include <HbAnchorLayout>
|
|
22 |
#include <HbMessageBox>
|
|
23 |
|
|
24 |
// User includes
|
|
25 |
#include "radiostationitem.h"
|
|
26 |
#include "radiostationcarousel.h"
|
|
27 |
#include "radiouiengine.h"
|
|
28 |
#include "radiofadinglabel.h"
|
|
29 |
#include "radiostationmodel.h"
|
|
30 |
#include "radiologger.h"
|
|
31 |
|
|
32 |
//static const char* FILE_PATH_WIDGETML = ":/layout/radiostationitem.widgetml";
|
|
33 |
//static const char* FILE_PATH_CSS = ":/layout/radiostationitem.css";
|
|
34 |
static const char* GENRE_LABEL = "tv:genre_label";
|
|
35 |
static const char* NAME_LABEL = "tv:name_label";
|
|
36 |
static const char* RADIOTEXT_LABEL = "tv:radiotext_label";
|
|
37 |
static const char* URL_LABEL = "tv:url_label";
|
|
38 |
//static const char* FAVORITE_BUTTON = "favorite_button";
|
|
39 |
|
|
40 |
const char* SEEKING_TEXT = "txt_rad_list_tuning";
|
|
41 |
const char* CONNECT_HEADSET_TEXT = "txt_rad_list_connect_wireless_antenna_headset_with";
|
|
42 |
|
|
43 |
/*!
|
|
44 |
*
|
|
45 |
*/
|
|
46 |
RadioStationItem::RadioStationItem( RadioStationCarousel& carousel ) :
|
|
47 |
HbAbstractViewItem( &carousel ),
|
|
48 |
mCarousel( carousel ),
|
|
49 |
mLayout( 0 ),
|
|
50 |
mNameLabel( 0 ),
|
|
51 |
mIconButton( 0 ),
|
|
52 |
mGenreLabel( 0 ),
|
|
53 |
mRadiotextLabel( 0 ),
|
|
54 |
mUrlLabel( 0 )
|
|
55 |
{
|
|
56 |
setFlag( QGraphicsItem::ItemIsFocusable, true );
|
|
57 |
}
|
|
58 |
|
|
59 |
/*!
|
|
60 |
* From HbAbstractViewItem
|
|
61 |
*
|
|
62 |
*/
|
|
63 |
HbAbstractViewItem* RadioStationItem::createItem()
|
|
64 |
{
|
|
65 |
RadioStationItem* item = new RadioStationItem( *this ); // Calls copy constructor
|
|
66 |
// item->setParent( &mCarousel );
|
|
67 |
// item->setParentItem( &mCarousel );
|
|
68 |
// item->setItemView( itemView() );
|
|
69 |
// item->updateChildItems();
|
|
70 |
return item;
|
|
71 |
}
|
|
72 |
|
|
73 |
/*!
|
|
74 |
* From HbAbstractViewItem
|
|
75 |
*/
|
|
76 |
void RadioStationItem::updateChildItems()
|
|
77 |
{
|
|
78 |
if ( !mLayout )
|
|
79 |
{
|
|
80 |
mIconButton = new HbPushButton( this );
|
|
81 |
QPixmap background( QSize( 50, 50 ) );
|
|
82 |
background.fill( Qt::transparent );
|
|
83 |
mIconButton->setBackground( HbIcon( background ) );
|
|
84 |
mIconButton->setIcon( mCarousel.nonFavoriteIcon() );
|
|
85 |
mIconButton->setMaximumSize( 50, 50 );
|
|
86 |
connectAndTest( mIconButton, SIGNAL(clicked()), this, SLOT(toggleFavorite()));
|
|
87 |
|
|
88 |
mNameLabel = new RadioFadingLabel( this );
|
|
89 |
mNameLabel->setAlignment( Qt::AlignCenter );
|
|
90 |
mNameLabel->setObjectName( NAME_LABEL );
|
|
91 |
HbFontSpec spec = mNameLabel->fontSpec();
|
|
92 |
spec.setRole( HbFontSpec::Primary );
|
|
93 |
mNameLabel->setFontSpec( spec );
|
|
94 |
|
|
95 |
spec.setRole( HbFontSpec::Secondary );
|
|
96 |
|
|
97 |
mGenreLabel = new RadioFadingLabel( this );
|
|
98 |
mGenreLabel->setAlignment( Qt::AlignCenter );
|
|
99 |
mGenreLabel->setObjectName( GENRE_LABEL );
|
|
100 |
mGenreLabel->setTextColor( Qt::white );
|
|
101 |
|
|
102 |
mRadiotextLabel = new RadioFadingLabel( this );
|
|
103 |
mRadiotextLabel->setAlignment( Qt::AlignCenter );
|
|
104 |
mRadiotextLabel->setObjectName( RADIOTEXT_LABEL );
|
|
105 |
mRadiotextLabel->setTextWrapping( Hb::TextWordWrap );
|
|
106 |
// mRadiotextLabel->setFadingEnabled( true ); TODO
|
|
107 |
// mRadiotextLabel->setFontSpec( spec );
|
|
108 |
mRadiotextLabel->setTextColor( Qt::white );
|
|
109 |
|
|
110 |
mUrlLabel = new RadioFadingLabel( this );
|
|
111 |
mUrlLabel->setAlignment( Qt::AlignCenter );
|
|
112 |
mUrlLabel->setObjectName( URL_LABEL );
|
|
113 |
mUrlLabel->setTextColor( Qt::white );
|
|
114 |
|
|
115 |
mLayout = new HbAnchorLayout();
|
|
116 |
|
|
117 |
mLayout->setAnchor( mLayout, Hb::TopEdge, mIconButton, Hb::TopEdge, 20.0 );
|
|
118 |
mLayout->setAnchor( mLayout, Hb::LeftEdge, mIconButton, Hb::LeftEdge, 20.0 );
|
|
119 |
|
|
120 |
mLayout->setAnchor( mIconButton, Hb::CenterVEdge, mGenreLabel, Hb::CenterVEdge, 0.0 );
|
|
121 |
mLayout->setAnchor( mIconButton, Hb::RightEdge, mGenreLabel, Hb::LeftEdge, 20.0 );
|
|
122 |
mLayout->setAnchor( mLayout, Hb::RightEdge, mGenreLabel, Hb::RightEdge, -70.0 );
|
|
123 |
|
|
124 |
mLayout->setAnchor( mGenreLabel, Hb::BottomEdge, mNameLabel, Hb::TopEdge, 0.0 );
|
|
125 |
mLayout->setAnchor( mLayout, Hb::LeftEdge, mNameLabel, Hb::LeftEdge, 10.0 );
|
|
126 |
mLayout->setAnchor( mLayout, Hb::RightEdge, mNameLabel, Hb::RightEdge, -10.0 );
|
|
127 |
|
|
128 |
mLayout->setAnchor( mNameLabel, Hb::BottomEdge, mRadiotextLabel, Hb::TopEdge, 10.0 );
|
|
129 |
mLayout->setAnchor( mLayout, Hb::LeftEdge, mRadiotextLabel, Hb::LeftEdge, 10.0 );
|
|
130 |
mLayout->setAnchor( mLayout, Hb::RightEdge, mRadiotextLabel, Hb::RightEdge, -10.0 );
|
|
131 |
|
|
132 |
mLayout->setAnchor( mRadiotextLabel, Hb::BottomEdge, mUrlLabel, Hb::TopEdge, 10.0 );
|
|
133 |
mLayout->setAnchor( mLayout, Hb::LeftEdge, mUrlLabel, Hb::LeftEdge, 10.0 );
|
|
134 |
mLayout->setAnchor( mLayout, Hb::RightEdge, mUrlLabel, Hb::RightEdge, -10.0 );
|
|
135 |
mLayout->setAnchor( mLayout, Hb::BottomEdge, mUrlLabel, Hb::BottomEdge, -10.0 );
|
|
136 |
|
|
137 |
setLayout( mLayout );
|
|
138 |
}
|
|
139 |
|
|
140 |
update();
|
|
141 |
}
|
|
142 |
|
|
143 |
/*!
|
|
144 |
* Private slot
|
|
145 |
*
|
|
146 |
*/
|
|
147 |
void RadioStationItem::toggleFavorite()
|
|
148 |
{
|
|
149 |
RadioUiEngine* uiEngine = carousel()->uiEngine();
|
|
150 |
if ( uiEngine ) {
|
|
151 |
uiEngine->stationModel().setData( modelIndex(), mFrequency, RadioStationModel::ToggleFavoriteRole );
|
|
152 |
}
|
|
153 |
}
|
|
154 |
|
|
155 |
/*!
|
|
156 |
*
|
|
157 |
*/
|
|
158 |
uint RadioStationItem::frequency() const
|
|
159 |
{
|
|
160 |
return mFrequency;
|
|
161 |
}
|
|
162 |
|
|
163 |
/*!
|
|
164 |
*
|
|
165 |
*/
|
|
166 |
void RadioStationItem::update( const RadioStation* station )
|
|
167 |
{
|
|
168 |
QModelIndex index = modelIndex();
|
|
169 |
if ( !( station && station->isValid() ) && !index.isValid() ) {
|
|
170 |
return;
|
|
171 |
}
|
|
172 |
|
|
173 |
RadioUiEngine* uiEngine = carousel()->uiEngine();
|
|
174 |
if ( !mCarousel.isInScanningMode() && uiEngine ) {
|
|
175 |
RadioStation tempStation = ( station && station->isValid() ) ? *station
|
|
176 |
: index.data( RadioStationModel::RadioStationRole ).value<RadioStation>();
|
|
177 |
|
|
178 |
mNameLabel->setTextWithoutFading( nameOrFrequency( tempStation ) );
|
|
179 |
|
|
180 |
mGenreLabel->setText( uiEngine->genreToString( tempStation.genre(), GenreTarget::Carousel ) );
|
|
181 |
|
|
182 |
if ( !tempStation.radioText().isEmpty() ) {
|
|
183 |
mRadiotextLabel->setText( tempStation.radioText() );
|
|
184 |
} else if ( !tempStation.dynamicPsText().isEmpty() ) {
|
|
185 |
mRadiotextLabel->setText( tempStation.dynamicPsText() );
|
|
186 |
} else {
|
|
187 |
mRadiotextLabel->setText( "" );
|
|
188 |
}
|
|
189 |
|
|
190 |
mUrlLabel->setText( tempStation.url() );
|
|
191 |
|
|
192 |
mFrequency = tempStation.frequency();
|
|
193 |
|
|
194 |
updateFavoriteIcon( tempStation.isFavorite() );
|
|
195 |
}
|
|
196 |
}
|
|
197 |
|
|
198 |
/*!
|
|
199 |
*
|
|
200 |
*/
|
|
201 |
void RadioStationItem::setFrequency( uint frequency )
|
|
202 |
{
|
|
203 |
LOG_FORMAT( "RadioStationItem::setFrequency: %d", frequency );
|
|
204 |
|
|
205 |
mNameLabel->setTextWithoutFading( parseFrequency( frequency ) );
|
|
206 |
mGenreLabel->setTextWithoutFading( "" );
|
|
207 |
mRadiotextLabel->setTextWithoutFading( "" );
|
|
208 |
mUrlLabel->setTextWithoutFading( "" );
|
|
209 |
mFrequency = frequency;
|
|
210 |
updateFavoriteIcon( false );
|
|
211 |
}
|
|
212 |
|
|
213 |
/*!
|
|
214 |
*
|
|
215 |
*/
|
|
216 |
void RadioStationItem::cleanRdsData()
|
|
217 |
{
|
|
218 |
mNameLabel->setTextWithoutFading( "" );
|
|
219 |
mGenreLabel->setTextWithoutFading( "" );
|
|
220 |
mRadiotextLabel->setTextWithoutFading( "" );
|
|
221 |
mUrlLabel->setTextWithoutFading( "" );
|
|
222 |
}
|
|
223 |
|
|
224 |
/*!
|
|
225 |
*
|
|
226 |
*/
|
|
227 |
void RadioStationItem::handleLongPress( const QPointF& /*coords*/ )
|
|
228 |
{
|
|
229 |
QString text = QString( "Selected frequency: %1" ).arg( mFrequency );
|
|
230 |
// HbMessageBox::information( text );
|
|
231 |
}
|
|
232 |
|
|
233 |
/*!
|
|
234 |
*
|
|
235 |
*/
|
|
236 |
void RadioStationItem::updateFavoriteIcon( bool isFavorite )
|
|
237 |
{
|
|
238 |
if ( !mCarousel.isInScanningMode() ) {
|
|
239 |
if ( isFavorite ) {
|
|
240 |
mIconButton->setIcon( mCarousel.favoriteIcon() );
|
|
241 |
} else {
|
|
242 |
mIconButton->setIcon( mCarousel.nonFavoriteIcon() );
|
|
243 |
}
|
|
244 |
} else {
|
|
245 |
mIconButton->setIcon( HbIcon( "" ) );
|
|
246 |
}
|
|
247 |
}
|
|
248 |
|
|
249 |
/*!
|
|
250 |
*
|
|
251 |
*/
|
|
252 |
RadioStationCarousel* RadioStationItem::carousel()
|
|
253 |
{
|
|
254 |
return static_cast<RadioStationCarousel*>( itemView() );
|
|
255 |
}
|
|
256 |
|
|
257 |
/*!
|
|
258 |
*
|
|
259 |
*/
|
|
260 |
QString RadioStationItem::parseFrequency( const uint frequency )
|
|
261 |
{
|
|
262 |
//TODO: Frequency localization temporarily disabled
|
|
263 |
QString loc = "%L1 Mhz";// "txt_rad_list_l1_mhz_big" );
|
|
264 |
return loc.arg( RadioStation::parseFrequency( frequency ) );
|
|
265 |
}
|
|
266 |
|
|
267 |
/*!
|
|
268 |
*
|
|
269 |
*/
|
|
270 |
QString RadioStationItem::nameOrFrequency( const RadioStation& station, uint frequency )
|
|
271 |
{
|
|
272 |
if ( frequency == 0 ) {
|
|
273 |
frequency = station.frequency();
|
|
274 |
}
|
|
275 |
|
|
276 |
QString text = "";
|
|
277 |
if ( station.isValid() && !station.name().isEmpty() ) {
|
|
278 |
text = station.name();
|
|
279 |
} else {
|
|
280 |
text = parseFrequency( frequency );
|
|
281 |
}
|
|
282 |
|
|
283 |
return text;
|
|
284 |
}
|