diff options
author | RJ Ryan <rryan@mixxx.org> | 2014-04-10 12:53:39 -0400 |
---|---|---|
committer | RJ Ryan <rryan@mixxx.org> | 2014-04-10 12:53:39 -0400 |
commit | a22928e1657f110b153dc7e591ed09a29891038c (patch) | |
tree | 17158ad922800a119e5eeac8c6fde14faa22d422 /src/library/banshee | |
parent | 3512cabceb0ec44de37e842334151b20ea41999a (diff) |
Fix various invalid indices due to calculating "size() - 1" on empty containers.
Diffstat (limited to 'src/library/banshee')
-rw-r--r-- | src/library/banshee/bansheeplaylistmodel.cpp | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/src/library/banshee/bansheeplaylistmodel.cpp b/src/library/banshee/bansheeplaylistmodel.cpp index 32fbaf943c..5c87e864b1 100644 --- a/src/library/banshee/bansheeplaylistmodel.cpp +++ b/src/library/banshee/bansheeplaylistmodel.cpp @@ -131,37 +131,39 @@ void BansheePlaylistModel::setTableModel(int playlistId) { QList<struct BansheeDbConnection::PlaylistEntry> list = m_pConnection->getPlaylistEntries(playlistId); - beginInsertRows(QModelIndex(), 0, list.size() - 1); - - foreach (struct BansheeDbConnection::PlaylistEntry entry, list){ - query.bindValue(":" CLM_VIEW_ORDER, entry.viewOrder + 1); - query.bindValue(":" CLM_ARTIST, entry.pArtist->name); - query.bindValue(":" CLM_TITLE, entry.pTrack->title); - query.bindValue(":" CLM_DURATION, entry.pTrack->duration / 1000); - query.bindValue(":" CLM_URI, entry.pTrack->uri); - query.bindValue(":" CLM_ALBUM, entry.pAlbum->title); - query.bindValue(":" CLM_ALBUM_ARTIST, entry.pAlbumArtist->name); - query.bindValue(":" CLM_YEAR, entry.pTrack->year); - query.bindValue(":" CLM_RATING, entry.pTrack->rating); - query.bindValue(":" CLM_GENRE, entry.pTrack->genre); - query.bindValue(":" CLM_GROUPING, entry.pTrack->grouping); - query.bindValue(":" CLM_TRACKNUMBER, entry.pTrack->tracknumber); - QDateTime timeAdded; - timeAdded.setTime_t(entry.pTrack->dateadded); - query.bindValue(":" CLM_DATEADDED, timeAdded.toString(Qt::ISODate)); - query.bindValue(":" CLM_BPM, entry.pTrack->bpm); - query.bindValue(":" CLM_BITRATE, entry.pTrack->bitrate); - query.bindValue(":" CLM_COMMENT, entry.pTrack->comment); - query.bindValue(":" CLM_PLAYCOUNT, entry.pTrack->playcount); - query.bindValue(":" CLM_COMPOSER, entry.pTrack->composer); - - if (!query.exec()) { - LOG_FAILED_QUERY(query); + if (!list.isEmpty()) { + beginInsertRows(QModelIndex(), 0, list.size() - 1); + + foreach (struct BansheeDbConnection::PlaylistEntry entry, list){ + query.bindValue(":" CLM_VIEW_ORDER, entry.viewOrder + 1); + query.bindValue(":" CLM_ARTIST, entry.pArtist->name); + query.bindValue(":" CLM_TITLE, entry.pTrack->title); + query.bindValue(":" CLM_DURATION, entry.pTrack->duration / 1000); + query.bindValue(":" CLM_URI, entry.pTrack->uri); + query.bindValue(":" CLM_ALBUM, entry.pAlbum->title); + query.bindValue(":" CLM_ALBUM_ARTIST, entry.pAlbumArtist->name); + query.bindValue(":" CLM_YEAR, entry.pTrack->year); + query.bindValue(":" CLM_RATING, entry.pTrack->rating); + query.bindValue(":" CLM_GENRE, entry.pTrack->genre); + query.bindValue(":" CLM_GROUPING, entry.pTrack->grouping); + query.bindValue(":" CLM_TRACKNUMBER, entry.pTrack->tracknumber); + QDateTime timeAdded; + timeAdded.setTime_t(entry.pTrack->dateadded); + query.bindValue(":" CLM_DATEADDED, timeAdded.toString(Qt::ISODate)); + query.bindValue(":" CLM_BPM, entry.pTrack->bpm); + query.bindValue(":" CLM_BITRATE, entry.pTrack->bitrate); + query.bindValue(":" CLM_COMMENT, entry.pTrack->comment); + query.bindValue(":" CLM_PLAYCOUNT, entry.pTrack->playcount); + query.bindValue(":" CLM_COMPOSER, entry.pTrack->composer); + + if (!query.exec()) { + LOG_FAILED_QUERY(query); + } + // qDebug() << "-----" << entry.pTrack->title << query.executedQuery(); } - // qDebug() << "-----" << entry.pTrack->title << query.executedQuery(); - } - endInsertRows(); + endInsertRows(); + } } QStringList tableColumns; |