@@ -23,13 +23,14 @@
|
||||
#include <QMutexLocker>
|
||||
#include <QSqlDatabase>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/database.h"
|
||||
#include "core/sqlquery.h"
|
||||
#include "core/song.h"
|
||||
#include "radiobackend.h"
|
||||
#include "radiochannel.h"
|
||||
|
||||
RadioBackend::RadioBackend(Database *db, QObject *parent)
|
||||
RadioBackend::RadioBackend(SharedPtr<Database> db, QObject *parent)
|
||||
: QObject(parent),
|
||||
db_(db),
|
||||
original_thread_(thread()) {}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "radiochannel.h"
|
||||
|
||||
class QThread;
|
||||
@@ -31,7 +32,7 @@ class RadioBackend : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RadioBackend(Database *db, QObject *parent = nullptr);
|
||||
explicit RadioBackend(SharedPtr<Database> db, QObject *parent = nullptr);
|
||||
|
||||
void Close();
|
||||
void ExitAsync();
|
||||
@@ -53,7 +54,7 @@ class RadioBackend : public QObject {
|
||||
void Exit();
|
||||
|
||||
private:
|
||||
Database *db_;
|
||||
SharedPtr<Database> db_;
|
||||
QThread *original_thread_;
|
||||
};
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ RadioModel::RadioModel(Application *app, QObject *parent)
|
||||
root_->lazy_loaded = true;
|
||||
|
||||
if (app_) {
|
||||
QObject::connect(app_->album_cover_loader(), &AlbumCoverLoader::AlbumCoverLoaded, this, &RadioModel::AlbumCoverLoaded);
|
||||
QObject::connect(&*app_->album_cover_loader(), &AlbumCoverLoader::AlbumCoverLoaded, this, &RadioModel::AlbumCoverLoaded);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "radioparadiseservice.h"
|
||||
#include "radiochannel.h"
|
||||
|
||||
RadioParadiseService::RadioParadiseService(Application *app, NetworkAccessManager *network, QObject *parent)
|
||||
RadioParadiseService::RadioParadiseService(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
: RadioService(Song::Source::RadioParadise, "Radio Paradise", IconLoader::Load("radioparadise"), app, network, parent) {}
|
||||
|
||||
QUrl RadioParadiseService::Homepage() { return QUrl("https://radioparadise.com/"); }
|
||||
|
||||
@@ -32,7 +32,7 @@ class RadioParadiseService : public RadioService {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RadioParadiseService(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
explicit RadioParadiseService(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
|
||||
|
||||
QUrl Homepage() override;
|
||||
QUrl Donate() override;
|
||||
|
||||
@@ -27,10 +27,11 @@
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/application.h"
|
||||
#include "radioservice.h"
|
||||
|
||||
RadioService::RadioService(const Song::Source source, const QString &name, const QIcon &icon, Application *app, NetworkAccessManager *network, QObject *parent)
|
||||
RadioService::RadioService(const Song::Source source, const QString &name, const QIcon &icon, Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
: QObject(parent),
|
||||
app_(app),
|
||||
network_(network),
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <QIcon>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/song.h"
|
||||
#include "radiochannel.h"
|
||||
|
||||
@@ -42,7 +43,7 @@ class RadioService : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RadioService(const Song::Source source, const QString &name, const QIcon &icon, Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
explicit RadioService(const Song::Source source, const QString &name, const QIcon &icon, Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
|
||||
|
||||
Song::Source source() const { return source_; }
|
||||
QString name() const { return name_; }
|
||||
@@ -66,7 +67,7 @@ class RadioService : public QObject {
|
||||
|
||||
protected:
|
||||
Application *app_;
|
||||
NetworkAccessManager *network_;
|
||||
SharedPtr<NetworkAccessManager> network_;
|
||||
Song::Source source_;
|
||||
QString name_;
|
||||
QIcon icon_;
|
||||
|
||||
@@ -17,10 +17,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QObject>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/application.h"
|
||||
#include "core/database.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
@@ -32,6 +35,8 @@
|
||||
#include "somafmservice.h"
|
||||
#include "radioparadiseservice.h"
|
||||
|
||||
using std::make_shared;
|
||||
|
||||
RadioServices::RadioServices(Application *app, QObject *parent)
|
||||
: QObject(parent),
|
||||
network_(app->network()),
|
||||
@@ -40,10 +45,10 @@ RadioServices::RadioServices(Application *app, QObject *parent)
|
||||
sort_model_(new QSortFilterProxyModel(this)),
|
||||
channels_refresh_(false) {
|
||||
|
||||
backend_ = new RadioBackend(app->database());
|
||||
app->MoveToThread(backend_, app->database()->thread());
|
||||
backend_ = make_shared<RadioBackend>(app->database());
|
||||
app->MoveToThread(&*backend_, app->database()->thread());
|
||||
|
||||
QObject::connect(backend_, &RadioBackend::NewChannels, this, &RadioServices::GotChannelsFromBackend);
|
||||
QObject::connect(&*backend_, &RadioBackend::NewChannels, this, &RadioServices::GotChannelsFromBackend);
|
||||
|
||||
sort_model_->setSourceModel(model_);
|
||||
sort_model_->setSortRole(RadioModel::Role_SortText);
|
||||
@@ -56,12 +61,6 @@ RadioServices::RadioServices(Application *app, QObject *parent)
|
||||
|
||||
}
|
||||
|
||||
RadioServices::~RadioServices() {
|
||||
|
||||
backend_->deleteLater();
|
||||
|
||||
}
|
||||
|
||||
void RadioServices::AddService(RadioService *service) {
|
||||
|
||||
qLog(Debug) << "Adding radio service:" << service->name();
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/song.h"
|
||||
#include "radiochannel.h"
|
||||
|
||||
@@ -39,7 +40,6 @@ class RadioServices : public QObject {
|
||||
|
||||
public:
|
||||
explicit RadioServices(Application *app, QObject *parent = nullptr);
|
||||
~RadioServices();
|
||||
|
||||
void AddService(RadioService *service);
|
||||
void RemoveService(RadioService *service);
|
||||
@@ -53,7 +53,7 @@ class RadioServices : public QObject {
|
||||
|
||||
void ReloadSettings();
|
||||
|
||||
RadioBackend *radio_backend() const { return backend_; }
|
||||
SharedPtr<RadioBackend> radio_backend() const { return backend_; }
|
||||
QSortFilterProxyModel *sort_model() const { return sort_model_; }
|
||||
|
||||
private slots:
|
||||
@@ -66,8 +66,8 @@ class RadioServices : public QObject {
|
||||
void RefreshChannels();
|
||||
|
||||
private:
|
||||
NetworkAccessManager *network_;
|
||||
RadioBackend *backend_;
|
||||
SharedPtr<NetworkAccessManager> network_;
|
||||
SharedPtr<RadioBackend> backend_;
|
||||
RadioModel *model_;
|
||||
QSortFilterProxyModel *sort_model_;
|
||||
QMap<Song::Source, RadioService*> services_;
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
const char *SomaFMService::kApiChannelsUrl = "https://somafm.com/channels.json";
|
||||
|
||||
SomaFMService::SomaFMService(Application *app, NetworkAccessManager *network, QObject *parent)
|
||||
SomaFMService::SomaFMService(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
: RadioService(Song::Source::SomaFM, "SomaFM", IconLoader::Load("somafm"), app, network, parent) {}
|
||||
|
||||
SomaFMService::~SomaFMService() {
|
||||
|
||||
@@ -34,7 +34,7 @@ class SomaFMService : public RadioService {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SomaFMService(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
explicit SomaFMService(Application *app, SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
|
||||
~SomaFMService();
|
||||
|
||||
QUrl Homepage() override;
|
||||
|
||||
Reference in New Issue
Block a user