void LastFmUserSettings::addRecentStation( const Station& station ) { MyQSettings s( this ); QList<Station> stations = recentStations(); // remove duplicates for ( int i = 0; i < stations.count(); ++i ) if ( stations[i].url() == station.url() ) stations.removeAt( i-- ); stations.prepend( station ); s.remove( "RecentStations" ); s.beginGroup( "RecentStations" ); int j = stations.count(); while (j--) s.setValue( QString::number( j ), stations[j].url() ); s.endGroup(); s.setValue( "StationNames/" + station.url(), station.name() ); s.sync(); emit userChanged( username() ); emit historyChanged(); }
QList<Station> LastFmUserSettings::recentStations() { MyQSettings s( this ); s.beginGroup( "RecentStations" ); QStringList const keys = s.childKeys(); s.endGroup(); QMap<int, Station> stations; foreach (QString key, keys) { Station station; station.setUrl( s.value( "RecentStations/" + key ).toString() ); station.setName( s.value( "StationNames/" + station.url() ).toString() ); stations[key.toInt()] = station; }