diff -r 6df133bd92e1 -r 075425b8d9a4 radioapp/radiouiengine/src/radiostationmodel.cpp --- a/radioapp/radiouiengine/src/radiostationmodel.cpp Fri Jun 04 10:21:36 2010 +0100 +++ b/radioapp/radiouiengine/src/radiostationmodel.cpp Fri Jun 11 13:38:32 2010 +0300 @@ -18,6 +18,7 @@ // System includes #include +// User includes #include "radiostationmodel.h" #include "radiostationmodel_p.h" #include "radiopresetstorage.h" @@ -112,7 +113,7 @@ } return firstLine; - } else if ( role == RadioStationModel::RadioStationRole ) { + } else if ( role == RadioRole::RadioStationRole ) { QVariant variant; variant.setValue( stationAt( index.row() ) ); return variant; @@ -129,6 +130,10 @@ list.append( d->mNowPlayingIcon ); } return list; + } else if ( role == RadioRole::IsFavoriteRole ) { + QVariant variant; + variant.setValue( stationAt( index.row() ).isFavorite() ); + return variant; } return QVariant(); @@ -141,7 +146,7 @@ { Q_UNUSED( index ); - if ( role == RadioStationModel::ToggleFavoriteRole ) { + if ( role == RadioRole::ToggleFavoriteRole ) { const uint frequency = value.toUInt(); RadioStation station; if ( findFrequency( frequency, station ) ) { @@ -164,17 +169,12 @@ Q_D( RadioStationModel ); d->mPresetStorage = storage; d->mWrapper = wrapper; - const int presetCount = d->mPresetStorage->presetCount(); + int index = d->mPresetStorage->firstPreset(); - LOG_FORMAT( "RadioStationModelPrivate::initialize: presetCount: %d, firstIndex: %d", presetCount, index ); + LOG_FORMAT( "RadioStationModelPrivate::initialize: presetCount: %d, firstIndex: %d", + d->mPresetStorage->presetCount(), index ); -#ifdef COMPILE_WITH_NEW_PRESET_UTILITY while ( index >= 0 ) { -#else - index = 0; - while ( index < presetCount ) { -#endif // COMPILE_WITH_NEW_PRESET_UTILITY - RadioStation station; station.detach(); @@ -187,9 +187,7 @@ } } -#ifdef COMPILE_WITH_NEW_PRESET_UTILITY index = d->mPresetStorage->nextPreset( index ); -#endif } d->setCurrentStation( d->mWrapper->currentFrequency() ); @@ -233,7 +231,7 @@ // Get the value from the keys list instead of directly accessing the values list // because QMap may have added a default-constructed value to the values list Q_D( const RadioStationModel ); - if ( index < d->mStations.keys().count() ) { + if ( index >= 0 && index < d->mStations.keys().count() ) { uint frequency = d->mStations.keys().at( index ); return d->mStations.value( frequency ); } @@ -243,9 +241,9 @@ /*! * Finds a station by frequency */ -bool RadioStationModel::findFrequency( uint frequency, RadioStation& station ) +bool RadioStationModel::findFrequency( uint frequency, RadioStation& station ) const { - Q_D( RadioStationModel ); + Q_D( const RadioStationModel ); if ( d->mStations.contains( frequency ) ) { station = d->mStations.value( frequency ); return true; @@ -293,6 +291,10 @@ const bool findNext = mode == StationSkip::Next || mode == StationSkip::NextFavorite; QList list = findFavorite ? d->favorites() : d->mStations.values(); + if ( list.isEmpty() ) { + return RadioStation(); + } + // Find the previous and next station from current frequency RadioStation previous; RadioStation next; @@ -320,6 +322,15 @@ } /*! + * Checks if the model contains the given frequency + */ +bool RadioStationModel::contains( const uint frequency ) const +{ + RadioStation unused; + return findFrequency( frequency, unused ); +} + +/*! * Removes a station by frequency */ void RadioStationModel::removeByFrequency( uint frequency ) @@ -361,7 +372,7 @@ // Copy the station to a temporary variable that can be used as signal parameter RadioStation tempStation = station; - const int row = modelIndexFromFrequency( tempStation.frequency() ).row(); + const int row = indexFromFrequency( tempStation.frequency() ); beginRemoveRows( QModelIndex(), row, row ); d->mPresetStorage->deletePreset( tempStation.presetIndex() ); @@ -414,8 +425,6 @@ } } } - - reset(); // TODO: Remove. this is a workaround to HbGridView update problem } /*! @@ -615,13 +624,13 @@ /*! * Returns the model index corresponding to the given frequency */ -QModelIndex RadioStationModel::modelIndexFromFrequency( uint frequency ) +int RadioStationModel::indexFromFrequency( uint frequency ) { RadioStation station; if ( findFrequency( frequency, station ) ) { - return index( findPresetIndex( station.presetIndex() ), 0 ); + return findPresetIndex( station.presetIndex() ); } - return QModelIndex(); + return -1; } /*!