radioapp/radiowidgets/src/radiostationitem.cpp
changeset 16 f54ebcfc1b80
parent 14 63aabac4416d
child 19 afea38384506
equal deleted inserted replaced
14:63aabac4416d 16:f54ebcfc1b80
    24 #include "radiostationitem.h"
    24 #include "radiostationitem.h"
    25 #include "radiostationcarousel.h"
    25 #include "radiostationcarousel.h"
    26 #include "radiouiengine.h"
    26 #include "radiouiengine.h"
    27 #include "radiofadinglabel.h"
    27 #include "radiofadinglabel.h"
    28 #include "radiostationmodel.h"
    28 #include "radiostationmodel.h"
    29 #include "radiolocalization.h"
       
    30 #include "radiologger.h"
    29 #include "radiologger.h"
    31 
    30 
    32 //static const char* FILE_PATH_WIDGETML   = ":/layout/radiostationitem.widgetml";
    31 //static const char* FILE_PATH_WIDGETML   = ":/layout/radiostationitem.widgetml";
    33 //static const char* FILE_PATH_CSS        = ":/layout/radiostationitem.css";
    32 //static const char* FILE_PATH_CSS        = ":/layout/radiostationitem.css";
    34 //static const char* GENRE_LABEL          = "genre_label";
    33 static const char* GENRE_LABEL            = "tv:genre_label";
    35 //static const char* NAME_LABEL           = "name_label";
    34 static const char* NAME_LABEL             = "tv:name_label";
    36 //static const char* RADIOTEXT_LABEL      = "radiotext_label";
    35 static const char* RADIOTEXT_LABEL        = "tv:radiotext_label";
    37 //static const char* URL_LABEL            = "url_label";
    36 static const char* URL_LABEL              = "tv:url_label";
    38 //static const char* FAVORITE_BUTTON      = "favorite_button";
    37 //static const char* FAVORITE_BUTTON      = "favorite_button";
    39 
    38 
    40 const char* SEEKING_TEXT = "txt_rad_list_tuning";
    39 const char* SEEKING_TEXT = "txt_rad_list_tuning";
    41 const char* CONNECT_HEADSET_TEXT = "txt_rad_list_connect_wireless_antenna_headset_with";
    40 const char* CONNECT_HEADSET_TEXT = "txt_rad_list_connect_wireless_antenna_headset_with";
    42 
    41 
    86         mIconButton->setMaximumSize( 50, 50 );
    85         mIconButton->setMaximumSize( 50, 50 );
    87         connectAndTest( mIconButton, SIGNAL(clicked()), this, SLOT(toggleFavorite()));
    86         connectAndTest( mIconButton, SIGNAL(clicked()), this, SLOT(toggleFavorite()));
    88 
    87 
    89         mNameLabel = new RadioFadingLabel( this );
    88         mNameLabel = new RadioFadingLabel( this );
    90         mNameLabel->setAlignment( Qt::AlignCenter );
    89         mNameLabel->setAlignment( Qt::AlignCenter );
       
    90         mNameLabel->setObjectName( NAME_LABEL );
    91         HbFontSpec spec = mNameLabel->fontSpec();
    91         HbFontSpec spec = mNameLabel->fontSpec();
    92         spec.setRole( HbFontSpec::Primary );
    92         spec.setRole( HbFontSpec::Primary );
    93         mNameLabel->setFontSpec( spec );
    93         mNameLabel->setFontSpec( spec );
    94 
    94 
    95         spec.setRole( HbFontSpec::Secondary );
    95         spec.setRole( HbFontSpec::Secondary );
    96 
    96 
    97         mGenreLabel = new RadioFadingLabel( this );
    97         mGenreLabel = new RadioFadingLabel( this );
    98         mGenreLabel->setAlignment( Qt::AlignCenter );
    98         mGenreLabel->setAlignment( Qt::AlignCenter );
       
    99         mGenreLabel->setObjectName( GENRE_LABEL );
    99         mGenreLabel->setTextColor( Qt::white );
   100         mGenreLabel->setTextColor( Qt::white );
   100 
   101 
   101         mRadiotextLabel = new RadioFadingLabel( this );
   102         mRadiotextLabel = new RadioFadingLabel( this );
   102         mRadiotextLabel->setAlignment( Qt::AlignCenter );
   103         mRadiotextLabel->setAlignment( Qt::AlignCenter );
       
   104         mRadiotextLabel->setObjectName( RADIOTEXT_LABEL );
   103         mRadiotextLabel->setTextWrapping( Hb::TextWordWrap );
   105         mRadiotextLabel->setTextWrapping( Hb::TextWordWrap );
   104 //        mRadiotextLabel->setFadingEnabled( true );    TODO
   106 //        mRadiotextLabel->setFadingEnabled( true );    TODO
   105 //        mRadiotextLabel->setFontSpec( spec );
   107 //        mRadiotextLabel->setFontSpec( spec );
   106         mRadiotextLabel->setTextColor( Qt::white );
   108         mRadiotextLabel->setTextColor( Qt::white );
   107 
   109 
   108         mUrlLabel = new RadioFadingLabel( this );
   110         mUrlLabel = new RadioFadingLabel( this );
   109         mUrlLabel->setAlignment( Qt::AlignCenter );
   111         mUrlLabel->setAlignment( Qt::AlignCenter );
       
   112         mUrlLabel->setObjectName( URL_LABEL );
   110         mUrlLabel->setTextColor( Qt::white );
   113         mUrlLabel->setTextColor( Qt::white );
   111 
   114 
   112         mLayout = new HbAnchorLayout();
   115         mLayout = new HbAnchorLayout();
   113 
   116 
   114         mLayout->setAnchor( mLayout, Hb::TopEdge, mIconButton, Hb::TopEdge, 20.0 );
   117         mLayout->setAnchor( mLayout, Hb::TopEdge, mIconButton, Hb::TopEdge, 20.0 );
   141  * Private slot
   144  * Private slot
   142  *
   145  *
   143  */
   146  */
   144 void RadioStationItem::toggleFavorite()
   147 void RadioStationItem::toggleFavorite()
   145 {
   148 {
   146     carousel()->uiEngine().model().setData( modelIndex(), mFrequency, RadioStationModel::ToggleFavoriteRole );
   149     RadioUiEngine* uiEngine = carousel()->uiEngine();
       
   150     if ( uiEngine ) {
       
   151         uiEngine->model().setData( modelIndex(), mFrequency, RadioStationModel::ToggleFavoriteRole );
       
   152     }
   147 }
   153 }
   148 
   154 
   149 /*!
   155 /*!
   150  *
   156  *
   151  */
   157  */
   162     QModelIndex index = modelIndex();
   168     QModelIndex index = modelIndex();
   163     if ( !( station && station->isValid() ) && !index.isValid() ) {
   169     if ( !( station && station->isValid() ) && !index.isValid() ) {
   164         return;
   170         return;
   165     }
   171     }
   166 
   172 
   167     RadioStation tempStation = ( station && station->isValid() ) ? *station
   173     RadioUiEngine* uiEngine = carousel()->uiEngine();
   168                     : index.data( RadioStationModel::RadioStationRole ).value<RadioStation>();
   174     if ( !mCarousel.isInScanningMode() && uiEngine ) {
   169 
   175         RadioStation tempStation = ( station && station->isValid() ) ? *station
   170     mNameLabel->setTextWithoutFading( RadioUiEngine::nameOrFrequency( tempStation ) );
   176                         : index.data( RadioStationModel::RadioStationRole ).value<RadioStation>();
   171     mGenreLabel->setText( carousel()->uiEngine().genreToString( tempStation.genre() ) );
   177 
   172     if ( !carousel()->isAntennaAttached() ) {
   178         mNameLabel->setTextWithoutFading( nameOrFrequency( tempStation ) );
   173         mRadiotextLabel->setText( hbTrId( CONNECT_HEADSET_TEXT ) );
   179 
   174     } else {
   180         mGenreLabel->setText( uiEngine->genreToString( tempStation.genre(), GenreTarget::Carousel ) );
       
   181 
   175         if ( !tempStation.radioText().isEmpty() ) {
   182         if ( !tempStation.radioText().isEmpty() ) {
   176             mRadiotextLabel->setText( tempStation.radioText() );
   183             mRadiotextLabel->setText( tempStation.radioText() );
   177         } else if ( !tempStation.dynamicPsText().isEmpty() ) {
   184         } else if ( !tempStation.dynamicPsText().isEmpty() ) {
   178             mRadiotextLabel->setText( tempStation.dynamicPsText() );
   185             mRadiotextLabel->setText( tempStation.dynamicPsText() );
   179         } else {
   186         } else {
   180             mRadiotextLabel->setText( "" );
   187             mRadiotextLabel->setText( "" );
   181         }
   188         }
   182     }
   189 
   183 
   190         mUrlLabel->setText( tempStation.url() );
   184     mUrlLabel->setText( tempStation.url() );
   191 
   185 
   192         mFrequency = tempStation.frequency();
   186     mFrequency = tempStation.frequency();
   193 
   187 
   194         updateFavoriteIcon( tempStation.isFavorite() );
   188     updateFavoriteIcon( tempStation.isFavorite() );
   195     }
   189 }
   196 }
   190 
   197 
   191 /*!
   198 /*!
   192  *
   199  *
   193  */
   200  */
   194 void RadioStationItem::setFrequency( uint frequency )
   201 void RadioStationItem::setFrequency( uint frequency )
   195 {
   202 {
   196     LOG_FORMAT( "RadioStationItem::setFrequency: %u", frequency );
   203     LOG_FORMAT( "RadioStationItem::setFrequency: %d", frequency );
   197     mNameLabel->setTextWithoutFading( RadioUiEngine::parseFrequency( frequency ) );
   204 
       
   205     mNameLabel->setTextWithoutFading( parseFrequency( frequency ) );
   198     mGenreLabel->setTextWithoutFading( "" );
   206     mGenreLabel->setTextWithoutFading( "" );
   199     mRadiotextLabel->setTextWithoutFading( carousel()->isAntennaAttached() ? "" : hbTrId( CONNECT_HEADSET_TEXT ) );
   207     mRadiotextLabel->setTextWithoutFading( "" );
   200     mUrlLabel->setTextWithoutFading( "" );
   208     mUrlLabel->setTextWithoutFading( "" );
   201     mFrequency = frequency;
   209     mFrequency = frequency;
   202     updateFavoriteIcon( false );
   210     updateFavoriteIcon( false );
   203 }
   211 }
   204 
   212 
   205 /*!
   213 /*!
   206  *
   214  *
   207  */
   215  */
   208 void RadioStationItem::setSeekingText()
   216 void RadioStationItem::cleanRdsData()
   209 {
   217 {
   210     mNameLabel->setTextWithoutFading( hbTrId( SEEKING_TEXT ) );
   218     mNameLabel->setTextWithoutFading( "" );
   211     mGenreLabel->setTextWithoutFading( "" );
   219     mGenreLabel->setTextWithoutFading( "" );
       
   220     mRadiotextLabel->setTextWithoutFading( "" );
   212     mUrlLabel->setTextWithoutFading( "" );
   221     mUrlLabel->setTextWithoutFading( "" );
   213     mRadiotextLabel->setTextWithoutFading( "" );
       
   214 }
   222 }
   215 
   223 
   216 /*!
   224 /*!
   217  *
   225  *
   218  */
   226  */
   219 void RadioStationItem::updateFavoriteIcon( bool isFavorite )
   227 void RadioStationItem::updateFavoriteIcon( bool isFavorite )
   220 {
   228 {
   221     mIconButton->setIcon( isFavorite ? mCarousel.favoriteIcon() : mCarousel.nonFavoriteIcon() );
   229     if ( !mCarousel.isInScanningMode() ) {
       
   230         mIconButton->setIcon( isFavorite ? mCarousel.favoriteIcon() : mCarousel.nonFavoriteIcon() );
       
   231     } else {
       
   232         mIconButton->setIcon( HbIcon( "" ) );
       
   233     }
   222 }
   234 }
   223 
   235 
   224 /*!
   236 /*!
   225  *
   237  *
   226  */
   238  */
   227 RadioStationCarousel* RadioStationItem::carousel()
   239 RadioStationCarousel* RadioStationItem::carousel()
   228 {
   240 {
   229     return static_cast<RadioStationCarousel*>( itemView() );
   241     return static_cast<RadioStationCarousel*>( itemView() );
   230 }
   242 }
   231 
   243 
       
   244 /*!
       
   245  *
       
   246  */
       
   247 QString RadioStationItem::parseFrequency( const uint frequency )
       
   248 {
       
   249     //TODO: Frequency localization temporarily disabled
       
   250     QString loc = "%L1 Mhz";// "txt_rad_list_l1_mhz_big" );
       
   251     return loc.arg( RadioStation::parseFrequency( frequency ) );
       
   252 }
       
   253 
       
   254 /*!
       
   255  *
       
   256  */
       
   257 QString RadioStationItem::nameOrFrequency( const RadioStation& station, uint frequency )
       
   258 {
       
   259     if ( frequency == 0 ) {
       
   260         frequency = station.frequency();
       
   261     }
       
   262 
       
   263     QString text = "";
       
   264     if ( station.isValid() && !station.name().isEmpty() ) {
       
   265         text = station.name();
       
   266     } else {
       
   267         text = parseFrequency( frequency );
       
   268     }
       
   269 
       
   270     return text;
       
   271 }