Stop adding new songs if we cancelled the seafile indexing

This commit is contained in:
Chocobozzz 2015-02-20 20:13:47 +01:00
parent ec60d1174c
commit 4b1a6651b1
5 changed files with 37 additions and 4 deletions

View File

@ -68,8 +68,8 @@ CloudFileService::CloudFileService(Application* app, InternetModel* parent,
library_sort_model_->setSortLocaleAware(true);
library_sort_model_->sort(0);
app->global_search()->AddProvider(new CloudFileSearchProvider(
library_backend_, service_id, icon_, this));
app->global_search()->AddProvider(
new CloudFileSearchProvider(library_backend_, service_id, icon_, this));
}
QStandardItem* CloudFileService::CreateRootItem() {
@ -160,6 +160,8 @@ void CloudFileService::MaybeAddFileToDatabase(const Song& metadata,
TagReaderClient::ReplyType* reply = app_->tag_reader_client()->ReadCloudFile(
download_url, metadata.title(), metadata.filesize(), mime_type,
authorisation);
pending_tagreader_replies_.append(reply);
NewClosure(reply, SIGNAL(Finished(bool)), this,
SLOT(ReadTagsFinished(TagReaderClient::ReplyType*, Song)), reply,
metadata);
@ -167,8 +169,17 @@ void CloudFileService::MaybeAddFileToDatabase(const Song& metadata,
void CloudFileService::ReadTagsFinished(TagReaderClient::ReplyType* reply,
const Song& metadata) {
int index_reply;
reply->deleteLater();
if ((index_reply = pending_tagreader_replies_.indexOf(reply)) == -1) {
qLog(Debug) << "Ignore the reply";
return;
}
pending_tagreader_replies_.removeAt(index_reply);
indexing_task_progress_++;
if (indexing_task_progress_ == indexing_task_max_) {
task_manager_->SetTaskFinished(indexing_task_id_);
@ -219,3 +230,12 @@ QString CloudFileService::GuessMimeTypeForFile(const QString& filename) const {
}
return QString::null;
}
void CloudFileService::AbortReadTagsReplies() {
qLog(Debug) << "Aborting the read tags replies";
pending_tagreader_replies_.clear();
task_manager_->SetTaskFinished(indexing_task_id_);
indexing_task_id_ = -1;
emit AllIndexingTasksFinished();
}

View File

@ -52,7 +52,7 @@ class CloudFileService : public InternetService {
virtual bool has_credentials() const = 0;
bool is_indexing() const { return indexing_task_id_ != -1; }
signals:
signals:
void AllIndexingTasksFinished();
public slots:
@ -67,6 +67,7 @@ class CloudFileService : public InternetService {
const QString& authorisation);
virtual bool IsSupportedMimeType(const QString& mime_type) const;
QString GuessMimeTypeForFile(const QString& filename) const;
void AbortReadTagsReplies();
protected slots:
void ShowCoverManager();
@ -86,6 +87,7 @@ class CloudFileService : public InternetService {
std::unique_ptr<AlbumCoverManager> cover_manager_;
PlaylistManager* playlist_manager_;
TaskManager* task_manager_;
QList<TagReaderClient::ReplyType*> pending_tagreader_replies_;
private:
QIcon icon_;

View File

@ -55,7 +55,8 @@ SeafileService::SeafileService(Application* app, InternetModel* parent)
SettingsDialog::Page_Seafile),
indexing_task_id_(-1),
indexing_task_max_(0),
indexing_task_progress_(0) {
indexing_task_progress_(0),
changing_libary_(false) {
QSettings s;
s.beginGroup(kSettingsGroup);
access_token_ = s.value("access_token").toString();
@ -179,14 +180,19 @@ void SeafileService::GetLibrariesFinished(QNetworkReply* reply) {
}
void SeafileService::ChangeLibrary(const QString& new_library) {
if (new_library == library_updated_ || changing_libary_) return;
if (indexing_task_id_ != -1) {
qLog(Debug) << "Want to change the Seafile library, but Clementine waits "
"the previous indexing...";
changing_libary_ = true;
NewClosure(this, SIGNAL(UpdatingLibrariesFinishedSignal()), this,
SLOT(ChangeLibrary(QString)), new_library);
return;
}
AbortReadTagsReplies();
qLog(Debug) << "Change the Seafile library";
// Every other libraries have to be destroyed from the tree
@ -198,6 +204,7 @@ void SeafileService::ChangeLibrary(const QString& new_library) {
}
}
changing_libary_ = false;
UpdateLibraries();
}

View File

@ -155,6 +155,8 @@ signals:
int indexing_task_id_;
int indexing_task_max_;
int indexing_task_progress_;
bool changing_libary_;
};
#endif // INTERNET_SEAFILE_SEAFILESERVICE_H_

View File

@ -134,6 +134,8 @@ void SeafileSettingsPage::Login() {
}
void SeafileSettingsPage::Logout() {
// Forget the songs added
service_->ChangeLibrary("none");
service_->ForgetCredentials();
// We choose to keep the server