Move lyrics providers to own thread
This commit is contained in:
@@ -20,8 +20,8 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/settings.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
|
||||
#include "lyricsprovider.h"
|
||||
#include "lyricsproviders.h"
|
||||
@@ -39,7 +40,14 @@
|
||||
|
||||
int LyricsProviders::NextOrderId = 0;
|
||||
|
||||
LyricsProviders::LyricsProviders(QObject *parent) : QObject(parent) {}
|
||||
using std::make_shared;
|
||||
|
||||
LyricsProviders::LyricsProviders(QObject *parent) : QObject(parent), thread_(new QThread(this)), network_(make_shared<NetworkAccessManager>()) {
|
||||
|
||||
network_->moveToThread(thread_);
|
||||
thread_->start();
|
||||
|
||||
}
|
||||
|
||||
LyricsProviders::~LyricsProviders() {
|
||||
|
||||
@@ -47,6 +55,9 @@ LyricsProviders::~LyricsProviders() {
|
||||
delete lyrics_providers_.firstKey();
|
||||
}
|
||||
|
||||
thread_->quit();
|
||||
thread_->wait(1000);
|
||||
|
||||
}
|
||||
|
||||
void LyricsProviders::ReloadSettings() {
|
||||
@@ -96,6 +107,8 @@ LyricsProvider *LyricsProviders::ProviderByName(const QString &name) const {
|
||||
|
||||
void LyricsProviders::AddProvider(LyricsProvider *provider) {
|
||||
|
||||
provider->moveToThread(thread_);
|
||||
|
||||
{
|
||||
QMutexLocker locker(&mutex_);
|
||||
lyrics_providers_.insert(provider, provider->name());
|
||||
|
||||
Reference in New Issue
Block a user