Skip to content

Commit

Permalink
Only add callbacks for playlists once
Browse files Browse the repository at this point in the history
This is a somewhat ugly hack to check that the callback functions only
get set once for every playlist.

Setting them more than once seems to result to an infinite recursion
somehow.
  • Loading branch information
Aki Koskinen committed Jul 9, 2012
1 parent a260c02 commit 20f91f9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,23 +887,30 @@ void MainWindow::fillPlaylistModel()
if (pl == m_currentPlaylist) {
currRow = numPlaylists;
}
sp_playlist_add_callbacks(pl, &SpotifyPlaylists::spotifyCallbacks, this);
sp_playlist_add_callbacks(pl, &SpotifyPlaylists::spotifyCallbacks, NULL);
const QModelIndex &index = m_playlistModel->index(0);
m_playlistModel->setData(index, QChar(0x2605) + i18n("Starred tracks"));
m_playlistModel->setData(index, QVariant::fromValue<sp_playlist*>(pl), PlaylistModel::SpotifyNativePlaylistRole);
}

static QList<sp_playlist*> playlistsWithCallbacksSet;

for (int i = 1; i < numPlaylists; ++i) {
sp_playlist *pl = sp_playlistcontainer_playlist(m_pc, i);
if (pl == m_currentPlaylist) {
currRow = i;
}
sp_playlist_add_callbacks(pl, &SpotifyPlaylists::spotifyCallbacks, this);

if (!playlistsWithCallbacksSet.contains(pl)) {
playlistsWithCallbacksSet.append(pl);
sp_playlist_add_callbacks(pl, &SpotifyPlaylists::spotifyCallbacks, NULL);
}

const QModelIndex &index = m_playlistModel->index(i);
m_playlistModel->setData(index, QString::fromUtf8(sp_playlist_name(pl)));
m_playlistModel->setData(index, QVariant::fromValue<sp_playlist*>(pl), PlaylistModel::SpotifyNativePlaylistRole);
}

if (currRow != -1) {
m_playlistView->setCurrentIndex(m_playlistModel->index(currRow, 0));
}
Expand Down

0 comments on commit 20f91f9

Please sign in to comment.