icecast: free backend on exit
Use a shared pointer since the model and search provider both hold pointers to the backend object. Also removed unused accessor method.
This commit is contained in:
parent
8f56fbb83b
commit
879dfa3d79
|
@ -16,11 +16,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "icecastsearchprovider.h"
|
#include "icecastsearchprovider.h"
|
||||||
|
|
||||||
#include "internet/icecast/icecastbackend.h"
|
#include "internet/icecast/icecastbackend.h"
|
||||||
#include "ui/iconloader.h"
|
#include "ui/iconloader.h"
|
||||||
|
|
||||||
IcecastSearchProvider::IcecastSearchProvider(IcecastBackend* backend,
|
IcecastSearchProvider::IcecastSearchProvider(
|
||||||
Application* app, QObject* parent)
|
std::shared_ptr<IcecastBackend> backend, Application* app, QObject* parent)
|
||||||
: BlockingSearchProvider(app, parent), backend_(backend) {
|
: BlockingSearchProvider(app, parent), backend_(backend) {
|
||||||
Init("Icecast", "icecast", IconLoader::Load("icon_radio", IconLoader::Lastfm),
|
Init("Icecast", "icecast", IconLoader::Load("icon_radio", IconLoader::Lastfm),
|
||||||
DisabledByDefault);
|
DisabledByDefault);
|
||||||
|
|
|
@ -18,19 +18,21 @@
|
||||||
#ifndef ICECASTSEARCHPROVIDER_H
|
#ifndef ICECASTSEARCHPROVIDER_H
|
||||||
#define ICECASTSEARCHPROVIDER_H
|
#define ICECASTSEARCHPROVIDER_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "searchprovider.h"
|
#include "searchprovider.h"
|
||||||
|
|
||||||
class IcecastBackend;
|
class IcecastBackend;
|
||||||
|
|
||||||
class IcecastSearchProvider : public BlockingSearchProvider {
|
class IcecastSearchProvider : public BlockingSearchProvider {
|
||||||
public:
|
public:
|
||||||
IcecastSearchProvider(IcecastBackend* backend, Application* app,
|
IcecastSearchProvider(std::shared_ptr<IcecastBackend> backend,
|
||||||
QObject* parent);
|
Application* app, QObject* parent);
|
||||||
|
|
||||||
ResultList Search(int id, const QString& query);
|
ResultList Search(int id, const QString& query);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IcecastBackend* backend_;
|
std::shared_ptr<IcecastBackend> backend_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ICECASTSEARCHPROVIDER_H
|
#endif // ICECASTSEARCHPROVIDER_H
|
||||||
|
|
|
@ -23,7 +23,8 @@
|
||||||
#include "playlist/songmimedata.h"
|
#include "playlist/songmimedata.h"
|
||||||
#include "ui/iconloader.h"
|
#include "ui/iconloader.h"
|
||||||
|
|
||||||
IcecastModel::IcecastModel(IcecastBackend* backend, QObject* parent)
|
IcecastModel::IcecastModel(std::shared_ptr<IcecastBackend> backend,
|
||||||
|
QObject* parent)
|
||||||
: SimpleTreeModel<IcecastItem>(new IcecastItem(this), parent),
|
: SimpleTreeModel<IcecastItem>(new IcecastItem(this), parent),
|
||||||
backend_(backend),
|
backend_(backend),
|
||||||
sort_mode_(SortMode_GenreByPopularity),
|
sort_mode_(SortMode_GenreByPopularity),
|
||||||
|
@ -35,7 +36,7 @@ IcecastModel::IcecastModel(IcecastBackend* backend, QObject* parent)
|
||||||
IcecastModel::~IcecastModel() { delete root_; }
|
IcecastModel::~IcecastModel() { delete root_; }
|
||||||
|
|
||||||
void IcecastModel::Init() {
|
void IcecastModel::Init() {
|
||||||
connect(backend_, SIGNAL(DatabaseReset()), SLOT(Reset()));
|
connect(backend_.get(), SIGNAL(DatabaseReset()), SLOT(Reset()));
|
||||||
|
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,12 @@
|
||||||
#ifndef INTERNET_ICECAST_ICECASTMODEL_H_
|
#ifndef INTERNET_ICECAST_ICECASTMODEL_H_
|
||||||
#define INTERNET_ICECAST_ICECASTMODEL_H_
|
#define INTERNET_ICECAST_ICECASTMODEL_H_
|
||||||
|
|
||||||
#include "icecastitem.h"
|
|
||||||
#include "core/simpletreemodel.h"
|
|
||||||
#include "library/librarymodel.h"
|
|
||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "core/simpletreemodel.h"
|
||||||
|
#include "icecastitem.h"
|
||||||
|
#include "library/librarymodel.h"
|
||||||
|
|
||||||
class IcecastBackend;
|
class IcecastBackend;
|
||||||
|
|
||||||
|
@ -32,7 +33,8 @@ class IcecastModel : public SimpleTreeModel<IcecastItem> {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit IcecastModel(IcecastBackend* backend, QObject* parent = nullptr);
|
explicit IcecastModel(std::shared_ptr<IcecastBackend> backend,
|
||||||
|
QObject* parent = nullptr);
|
||||||
~IcecastModel();
|
~IcecastModel();
|
||||||
|
|
||||||
// These values get saved in QSettings - don't change them
|
// These values get saved in QSettings - don't change them
|
||||||
|
@ -46,8 +48,6 @@ class IcecastModel : public SimpleTreeModel<IcecastItem> {
|
||||||
Role_IsDivider = LibraryModel::Role_IsDivider,
|
Role_IsDivider = LibraryModel::Role_IsDivider,
|
||||||
};
|
};
|
||||||
|
|
||||||
IcecastBackend* backend() const { return backend_; }
|
|
||||||
|
|
||||||
Song GetSong(const QModelIndex& index) const;
|
Song GetSong(const QModelIndex& index) const;
|
||||||
|
|
||||||
// QAbstractItemModel
|
// QAbstractItemModel
|
||||||
|
@ -76,7 +76,7 @@ class IcecastModel : public SimpleTreeModel<IcecastItem> {
|
||||||
static QString DividerDisplayText(const QChar& key);
|
static QString DividerDisplayText(const QChar& key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IcecastBackend* backend_;
|
std::shared_ptr<IcecastBackend> backend_;
|
||||||
|
|
||||||
QString filter_;
|
QString filter_;
|
||||||
SortMode sort_mode_;
|
SortMode sort_mode_;
|
||||||
|
|
|
@ -57,10 +57,9 @@ IcecastService::IcecastService(Application* app, InternetModel* parent)
|
||||||
: InternetService(kServiceName, app, parent, parent),
|
: InternetService(kServiceName, app, parent, parent),
|
||||||
network_(new NetworkAccessManager(this)),
|
network_(new NetworkAccessManager(this)),
|
||||||
context_menu_(nullptr),
|
context_menu_(nullptr),
|
||||||
backend_(nullptr),
|
backend_(new IcecastBackend),
|
||||||
model_(nullptr),
|
model_(nullptr),
|
||||||
filter_(new IcecastFilterWidget(0)) {
|
filter_(new IcecastFilterWidget(0)) {
|
||||||
backend_ = new IcecastBackend;
|
|
||||||
backend_->moveToThread(app_->database()->thread());
|
backend_->moveToThread(app_->database()->thread());
|
||||||
backend_->Init(app_->database());
|
backend_->Init(app_->database());
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include "internet/core/internetservice.h"
|
#include "internet/core/internetservice.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
|
|
||||||
#include "icecastbackend.h"
|
#include "icecastbackend.h"
|
||||||
|
@ -75,7 +76,7 @@ class IcecastService : public InternetService {
|
||||||
NetworkAccessManager* network_;
|
NetworkAccessManager* network_;
|
||||||
QMenu* context_menu_;
|
QMenu* context_menu_;
|
||||||
|
|
||||||
IcecastBackend* backend_;
|
std::shared_ptr<IcecastBackend> backend_;
|
||||||
IcecastModel* model_;
|
IcecastModel* model_;
|
||||||
IcecastFilterWidget* filter_;
|
IcecastFilterWidget* filter_;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue