From 7520966284969391eefb55502777b83e47e13517 Mon Sep 17 00:00:00 2001 From: Iktwo Sh Date: Tue, 23 Sep 2014 21:50:49 -0700 Subject: [PATCH] Add songs to model only after retrieving their url --- src/musicstreamer.cpp | 15 +++++++-------- src/musicstreamer.h | 1 + 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/musicstreamer.cpp b/src/musicstreamer.cpp index 7fabf4f..0d5854b 100644 --- a/src/musicstreamer.cpp +++ b/src/musicstreamer.cpp @@ -58,11 +58,7 @@ void MusicStreamer::songFound(const QString &title, const QString &artist, const const QString &comment, int kbps, const QString &code, const QString &picture, long long hits) { - beginInsertRows(QModelIndex(), rowCount(), rowCount()); - mSongs.append(new Song(title, artist, length, comment, kbps, code, picture, hits, this)); - endInsertRows(); - - emit songsChanged(); + mTempSongs.append(new Song(title, artist, length, comment, kbps, code, picture, hits, this)); } QObjectList MusicStreamer::songs() @@ -74,12 +70,15 @@ void MusicStreamer::decodedUrl(const QString &code, const QString &url) { // qDebug() << Q_FUNC_INFO << " URL: " << url; int i = 0; - foreach (QObject *item, mSongs) { + foreach (QObject *item, mTempSongs) { Song *song = qobject_cast(item); if (song->code() == code) { song->setUrl(url); - QModelIndex index = createIndex(i, 0); - dataChanged(index, index); + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + mSongs.append(song); + endInsertRows(); + emit songsChanged(); + mTempSongs.removeAt(i); break; } ++i; diff --git a/src/musicstreamer.h b/src/musicstreamer.h index 8978db6..aeacea0 100644 --- a/src/musicstreamer.h +++ b/src/musicstreamer.h @@ -68,6 +68,7 @@ class MusicStreamer : public QAbstractListModel private: Downloader *mDownloader; QObjectList mSongs; + QObjectList mTempSongs; bool mSearching; bool mServerError; QString mLastSearchHasMoreResults;