1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-31 11:35:24 +01:00

Cancel network requests and outstanding fingerprint operations when cancelling musicbrainz lookups

This commit is contained in:
David Sansome 2011-03-13 12:52:08 +00:00
parent e2cd6d02ee
commit 8690438ad4
6 changed files with 22 additions and 4 deletions

View File

@ -48,10 +48,13 @@ void MusicBrainzClient::Start(int id, const QString& puid) {
}
void MusicBrainzClient::Cancel(int id) {
requests_.remove(requests_.key(id));
QNetworkReply* reply = requests_.key(id);
requests_.remove(reply);
delete reply;
}
void MusicBrainzClient::CancelAll() {
qDeleteAll(requests_.keys());
requests_.clear();
}

View File

@ -61,10 +61,13 @@ void MusicDnsClient::Start(int id, const QString& fingerprint, int duration_msec
}
void MusicDnsClient::Cancel(int id) {
requests_.remove(requests_.key(id));
QNetworkReply* reply = requests_.key(id);
requests_.remove(reply);
delete reply;
}
void MusicDnsClient::CancelAll() {
qDeleteAll(requests_.keys());
requests_.clear();
}

View File

@ -39,6 +39,8 @@ QString TagFetcher::GetFingerprint(const Song& song) {
}
void TagFetcher::StartFetch(const SongList& songs) {
Cancel();
songs_ = songs;
QFuture<QString> future = QtConcurrent::mapped(songs_, GetFingerprint);
@ -52,11 +54,16 @@ void TagFetcher::StartFetch(const SongList& songs) {
}
void TagFetcher::Cancel() {
delete fingerprint_watcher_;
fingerprint_watcher_ = NULL;
if (fingerprint_watcher_) {
fingerprint_watcher_->cancel();
delete fingerprint_watcher_;
fingerprint_watcher_ = NULL;
}
musicdns_client_->CancelAll();
musicbrainz_client_->CancelAll();
songs_.clear();
}
void TagFetcher::FingerprintFound(int index) {

View File

@ -36,6 +36,8 @@ public:
TagFetcher(QObject* parent = 0);
void StartFetch(const SongList& songs);
public slots:
void Cancel();
signals:

View File

@ -66,6 +66,7 @@ EditTagDialog::EditTagDialog(QWidget* parent)
results_dialog_, SLOT(FetchTagProgress(Song,QString)));
connect(results_dialog_, SIGNAL(SongChosen(Song, Song)),
SLOT(FetchTagSongChosen(Song, Song)));
connect(results_dialog_, SIGNAL(finished(int)), tag_fetcher_, SLOT(Cancel()));
ui_->setupUi(this);
ui_->splitter->setSizes(QList<int>() << 200 << width() - 200);

View File

@ -1906,6 +1906,8 @@ void MainWindow::AutoCompleteTags() {
track_selection_dialog_.get(), SLOT(FetchTagProgress(Song,QString)));
connect(track_selection_dialog_.get(), SIGNAL(accepted()),
SLOT(AutoCompleteTagsAccepted()));
connect(track_selection_dialog_.get(), SIGNAL(finished(int)),
tag_fetcher_.get(), SLOT(Cancel()));
}
// Get the selected songs and start fetching tags for them