Safely close database connections and delete backends

Also fix NewClosure leak caused by disconnected object signals
This commit is contained in:
Jonas Kvinge
2019-07-24 19:16:51 +02:00
parent bd78e8c275
commit b5eb13449b
47 changed files with 490 additions and 53 deletions

View File

@@ -40,6 +40,7 @@ class InternetService : public QObject {
InternetService(Song::Source source, const QString &name, const QString &url_scheme, Application *app, QObject *parent = nullptr);
virtual ~InternetService() {}
virtual void Exit() {}
virtual Song::Source source() const { return source_; }
virtual QString name() const { return name_; }
@@ -75,6 +76,7 @@ class InternetService : public QObject {
virtual void ResetSongsRequest() {}
signals:
void ExitFinished();
void Login();
void Logout();
void Login(const QString &api_token, const QString &username, const QString &password);

View File

@@ -72,3 +72,22 @@ void InternetServices::ReloadSettings() {
service->ReloadSettings();
}
}
void InternetServices::Exit() {
for (InternetService *service : services_.values()) {
wait_for_exit_ << service;
connect(service, SIGNAL(ExitFinished()), this, SLOT(ExitReceived()));
service->Exit();
}
}
void InternetServices::ExitReceived() {
InternetService *service = qobject_cast<InternetService*>(sender());
wait_for_exit_.removeAll(service);
if (wait_for_exit_.isEmpty()) emit ExitFinished();
}

View File

@@ -47,9 +47,17 @@ class InternetServices : public QObject {
void AddService(InternetService *service);
void RemoveService(InternetService *service);
void ReloadSettings();
void Exit();
signals:
void ExitFinished();
private slots:
void ExitReceived();
private:
QMap<Song::Source, InternetService*> services_;
QList<InternetService*> wait_for_exit_;
};