Rename class InternetModel to InternetServices

This commit is contained in:
Jonas Kvinge 2018-10-23 23:25:02 +02:00
parent 0c10013858
commit f4dcf6821f
22 changed files with 75 additions and 136 deletions

View File

@ -260,7 +260,7 @@ set(SOURCES
globalshortcuts/qxtglobalshortcutbackend.cpp
globalshortcuts/globalshortcutgrabber.cpp
internet/internetmodel.cpp
internet/internetservices.cpp
internet/internetservice.cpp
internet/internetplaylistitem.cpp
internet/internetsearch.cpp
@ -422,9 +422,8 @@ set(HEADERS
globalshortcuts/gnomeglobalshortcutbackend.h
globalshortcuts/globalshortcutgrabber.h
internet/internetmodel.h
internet/internetservices.h
internet/internetservice.h
internet/internetmimedata.h
internet/internetsongmimedata.h
internet/internetsearch.h
internet/internetsearchview.h

View File

@ -60,9 +60,16 @@
#include "lyrics/auddlyricsprovider.h"
#include "lyrics/apiseedslyricsprovider.h"
#include "internet/internetmodel.h"
#include "internet/internetservices.h"
#include "internet/internetsearch.h"
#ifdef HAVE_STREAM_TIDAL
# include "tidal/tidalservice.h"
#endif
#ifdef HAVE_STREAM_DEEZER
# include "deezer/deezerservice.h"
#endif
bool Application::kIsPortable = false;
class ApplicationImpl {
@ -116,7 +123,16 @@ class ApplicationImpl {
lyrics_providers->AddProvider(new APISeedsLyricsProvider(app));
return lyrics_providers;
}),
internet_model_([=]() { return new InternetModel(app, app); }),
internet_services_([=]() {
InternetServices *internet_services = new InternetServices(app);
#ifdef HAVE_STREAM_TIDAL
internet_services->AddService(new TidalService(app, internet_services));
#endif
#ifdef HAVE_STREAM_DEEZER
internet_services->AddService(new DeezerService(app, internet_services));
#endif
return internet_services;
}),
#ifdef HAVE_STREAM_TIDAL
tidal_search_([=]() { return new InternetSearch(app, Song::Source_Tidal, app); }),
#endif
@ -142,7 +158,7 @@ class ApplicationImpl {
Lazy<AlbumCoverLoader> album_cover_loader_;
Lazy<CurrentArtLoader> current_art_loader_;
Lazy<LyricsProviders> lyrics_providers_;
Lazy<InternetModel> internet_model_;
Lazy<InternetServices> internet_services_;
#ifdef HAVE_STREAM_TIDAL
Lazy<InternetSearch> tidal_search_;
#endif
@ -216,7 +232,7 @@ CurrentArtLoader *Application::current_art_loader() const { return p_->current_a
LyricsProviders *Application::lyrics_providers() const { return p_->lyrics_providers_.get(); }
PlaylistBackend *Application::playlist_backend() const { return p_->playlist_backend_.get(); }
PlaylistManager *Application::playlist_manager() const { return p_->playlist_manager_.get(); }
InternetModel *Application::internet_model() const { return p_->internet_model_.get(); }
InternetServices *Application::internet_services() const { return p_->internet_services_.get(); }
#ifdef HAVE_STREAM_TIDAL
InternetSearch *Application::tidal_search() const { return p_->tidal_search_.get(); }
#endif

View File

@ -54,7 +54,7 @@ class CoverProviders;
class AlbumCoverLoader;
class CurrentArtLoader;
class LyricsProviders;
class InternetModel;
class InternetServices;
class InternetSearch;
class Application : public QObject {
@ -89,7 +89,7 @@ class Application : public QObject {
LyricsProviders *lyrics_providers() const;
InternetModel *internet_model() const;
InternetServices *internet_services() const;
#ifdef HAVE_STREAM_TIDAL
InternetSearch *tidal_search() const;
#endif

View File

@ -140,7 +140,7 @@
# include "settings/deezersettingspage.h"
#endif
#include "internet/internetmodel.h"
#include "internet/internetservices.h"
#include "internet/internetservice.h"
#include "internet/internetsearchview.h"

View File

@ -73,7 +73,7 @@
#include "settings/backendsettingspage.h"
#include "settings/behavioursettingspage.h"
#include "settings/playlistsettingspage.h"
#include "internet/internetmodel.h"
#include "internet/internetservices.h"
#include "internet/internetservice.h"
using std::shared_ptr;

View File

@ -47,7 +47,7 @@ void CoverProviders::RemoveProvider(CoverProvider *provider) {
if (!provider) return;
// It's not safe to dereference provider at this pointbecause it might have already been destroyed.
// It's not safe to dereference provider at this point because it might have already been destroyed.
QString name;

View File

@ -54,7 +54,7 @@
#include "core/taskmanager.h"
#include "core/timeconstants.h"
#include "core/utilities.h"
#include "internet/internetmodel.h"
#include "internet/internetservices.h"
#include "internet/internetsearch.h"
#include "internet/localredirectserver.h"
#include "deezerservice.h"
@ -71,8 +71,8 @@ const char *DeezerService::kSecretKey = "06911976010b9ddd7256769adf2b2e56";
typedef QPair<QString, QString> Param;
DeezerService::DeezerService(Application *app, InternetModel *parent)
: InternetService(Song::Source_Deezer, "Deezer", "dzmedia", app, parent, parent),
DeezerService::DeezerService(Application *app, QObject *parent)
: InternetService(Song::Source_Deezer, "Deezer", "dzmedia", app, parent),
network_(new NetworkAccessManager(this)),
url_handler_(new DeezerUrlHandler(app, this)),
#ifdef HAVE_DZMEDIA

View File

@ -39,7 +39,7 @@
#include <QJsonValue>
#include "core/song.h"
#include "internet/internetmodel.h"
#include "internet/internetservices.h"
#include "internet/internetservice.h"
#include "internet/internetsearch.h"
@ -61,7 +61,7 @@ class DeezerService : public InternetService {
Q_OBJECT
public:
DeezerService(Application *app, InternetModel *parent);
DeezerService(Application *app, QObject *parent);
~DeezerService();
static const Song::Source kSource;

View File

@ -1,43 +0,0 @@
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Strawberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef INTERNETMIMEDATA_H
#define INTERNETMIMEDATA_H
#include "config.h"
#include <QObject>
#include <QModelIndexList>
#include "core/mimedata.h"
class InternetModel;
class InternetMimeData : public MimeData {
Q_OBJECT
public:
explicit InternetMimeData(const InternetModel *_model) : model(_model) {}
const InternetModel *model;
QModelIndexList indexes;
};
#endif

View File

@ -28,8 +28,8 @@
#include <QtDebug>
#include "internetplaylistitem.h"
#include "internetservices.h"
#include "internetservice.h"
#include "internetmodel.h"
#include "core/settingsprovider.h"
#include "collection/sqlrow.h"
#include "playlist/playlistbackend.h"
@ -50,11 +50,6 @@ bool InternetPlaylistItem::InitFromQuery(const SqlRow &query) {
return true;
}
InternetService *InternetPlaylistItem::service() const {
InternetService *ret = InternetModel::ServiceBySource(source_);
return ret;
}
QVariant InternetPlaylistItem::DatabaseValue(DatabaseColumn column) const {
return PlaylistItem::DatabaseValue(column);
}

View File

@ -47,7 +47,6 @@ class InternetPlaylistItem : public PlaylistItem {
private:
void InitMetadata();
InternetService *service() const;
private:
Song::Source source_;

View File

@ -48,7 +48,7 @@
#include "playlist/songmimedata.h"
#include "internetsearch.h"
#include "internetservice.h"
#include "internetmodel.h"
#include "internetservices.h"
using std::advance;
@ -60,7 +60,7 @@ InternetSearch::InternetSearch(Application *app, Song::Source source, QObject *p
: QObject(parent),
app_(app),
source_(source),
service_(app->internet_model()->ServiceBySource(source)),
service_(app->internet_services()->ServiceBySource(source)),
searches_next_id_(1),
art_searches_next_id_(1) {

View File

@ -24,9 +24,9 @@
#include "core/logging.h"
#include "core/mimedata.h"
#include "internetmodel.h"
#include "internetservices.h"
#include "internetservice.h"
InternetService::InternetService(Song::Source source, const QString &name, const QString &url_scheme, Application *app, InternetModel *model, QObject *parent)
: QObject(parent), app_(app), model_(model), source_(source), name_(name), url_scheme_(url_scheme) {
InternetService::InternetService(Song::Source source, const QString &name, const QString &url_scheme, Application *app, QObject *parent)
: QObject(parent), app_(app), source_(source), name_(name), url_scheme_(url_scheme) {
}

View File

@ -36,19 +36,18 @@
#include "internetsearch.h"
class Application;
class InternetModel;
class InternetServices;
class CollectionFilterWidget;
class InternetService : public QObject {
Q_OBJECT
public:
InternetService(Song::Source source, const QString &name, const QString &url_scheme, Application *app, InternetModel *model, QObject *parent = nullptr);
InternetService(Song::Source source, const QString &name, const QString &url_scheme, Application *app, QObject *parent = nullptr);
virtual ~InternetService() {}
virtual Song::Source source() const { return source_; }
virtual QString name() const { return name_; }
virtual QString url_scheme() const { return url_scheme_; }
virtual InternetModel *model() const { return model_; }
virtual bool has_initial_load_settings() const { return false; }
virtual void InitialLoadSettings() {}
virtual void ReloadSettings() {}
@ -62,7 +61,6 @@ class InternetService : public QObject {
protected:
Application *app_;
private:
InternetModel *model_;
Song::Source source_;
QString name_;
QString url_scheme_;

View File

@ -24,70 +24,50 @@
#include <QObject>
#include <QMap>
#include <QString>
#include <QStandardItemModel>
#include <QtDebug>
#include "core/logging.h"
#include "internetmodel.h"
#include "internetservices.h"
#include "internetservice.h"
#ifdef HAVE_STREAM_TIDAL
# include "tidal/tidalservice.h"
#endif
#ifdef HAVE_STREAM_DEEZER
# include "deezer/deezerservice.h"
#endif
QMap<Song::Source, InternetService*>* InternetModel::sServices = nullptr;
InternetServices::InternetServices(QObject *parent) : QObject(parent) {}
InternetServices::~InternetServices() {}
InternetModel::InternetModel(Application *app, QObject *parent)
: QStandardItemModel(parent),
app_(app) {
void InternetServices::AddService(InternetService *service) {
if (!sServices) sServices = new QMap<Song::Source, InternetService*>;
Q_ASSERT(sServices->isEmpty());
#ifdef HAVE_STREAM_TIDAL
AddService(new TidalService(app, this));
#endif
#ifdef HAVE_STREAM_DEEZER
AddService(new DeezerService(app, this));
#endif
}
void InternetModel::AddService(InternetService *service) {
qLog(Debug) << "Adding internet service:" << service->name();
sServices->insert(service->source(), service);
services_.insert(service->source(), service);
connect(service, SIGNAL(destroyed()), SLOT(ServiceDeleted()));
if (service->has_initial_load_settings()) service->InitialLoadSettings();
else service->ReloadSettings();
qLog(Debug) << "Added internet service" << service->name();
}
void InternetModel::RemoveService(InternetService *service) {
void InternetServices::RemoveService(InternetService *service) {
if (!sServices->contains(service->source())) return;
sServices->remove(service->source());
if (!services_.contains(service->source())) return;
services_.remove(service->source());
disconnect(service, 0, this, 0);
}
void InternetModel::ServiceDeleted() {
void InternetServices::ServiceDeleted() {
InternetService *service = qobject_cast<InternetService*>(sender());
if (service) RemoveService(service);
}
InternetService *InternetModel::ServiceBySource(const Song::Source &source) {
InternetService *InternetServices::ServiceBySource(const Song::Source &source) {
if (sServices->contains(source)) return sServices->value(source);
if (services_.contains(source)) return services_.value(source);
return nullptr;
}
void InternetModel::ReloadSettings() {
for (InternetService *service : sServices->values()) {
void InternetServices::ReloadSettings() {
for (InternetService *service : services_.values()) {
service->ReloadSettings();
}
}

View File

@ -19,8 +19,8 @@
*
*/
#ifndef INTERNETMODEL_H
#define INTERNETMODEL_H
#ifndef INTERNETSERVICES_H
#define INTERNETSERVICES_H
#include "config.h"
@ -39,11 +39,12 @@
class Application;
class InternetService;
class InternetModel : public QStandardItemModel {
class InternetServices : public QObject {
Q_OBJECT
public:
explicit InternetModel(Application* app, QObject *parent = nullptr);
explicit InternetServices(QObject *parent = nullptr);
~InternetServices();
enum Role {
// Services can use this role to distinguish between different types of items that they add.
@ -104,12 +105,10 @@ class InternetModel : public QStandardItemModel {
PlayBehaviour_DoubleClickAction,
};
// Needs to be static for InternetPlaylistItem::restore
static InternetService *ServiceBySource(const Song::Source &source);
InternetService *ServiceBySource(const Song::Source &source);
template <typename T>
static T *Service() {
return static_cast<T*>(ServiceBySource(T::kSource));
T *Service() {
return static_cast<T*>(this->ServiceBySource(T::kSource));
}
// Add and remove services. Ownership is not transferred and the service is not reparented.
@ -118,14 +117,11 @@ class InternetModel : public QStandardItemModel {
void RemoveService(InternetService *service);
void ReloadSettings();
Application *app() const { return app_; }
private slots:
void ServiceDeleted();
private:
static QMap<Song::Source, InternetService*> *sServices;
Application *app_;
QMap<Song::Source, InternetService*> services_;
};

View File

@ -85,9 +85,8 @@
#include "songplaylistitem.h"
#include "tagreadermessages.pb.h"
#include "internet/internetmodel.h"
#include "internet/internetservices.h"
#include "internet/internetplaylistitem.h"
#include "internet/internetmimedata.h"
#include "internet/internetsongmimedata.h"
using std::placeholders::_1;

View File

@ -54,7 +54,7 @@ class PlaylistBackend;
class PlaylistFilter;
class Queue;
class TaskManager;
class InternetModel;
class InternetServices;
class InternetService;
namespace PlaylistUndoCommands {

View File

@ -29,7 +29,7 @@
#include "ui_deezersettingspage.h"
#include "core/application.h"
#include "core/iconloader.h"
#include "internet/internetmodel.h"
#include "internet/internetservices.h"
#include "deezer/deezerservice.h"
const char *DeezerSettingsPage::kSettingsGroup = "Deezer";
@ -37,7 +37,7 @@ const char *DeezerSettingsPage::kSettingsGroup = "Deezer";
DeezerSettingsPage::DeezerSettingsPage(SettingsDialog *parent)
: SettingsPage(parent),
ui_(new Ui::DeezerSettingsPage),
service_(dialog()->app()->internet_model()->Service<DeezerService>()) {
service_(dialog()->app()->internet_services()->Service<DeezerService>()) {
ui_->setupUi(this);
setWindowIcon(IconLoader::Load("deezer"));

View File

@ -29,7 +29,7 @@
#include "ui_tidalsettingspage.h"
#include "core/application.h"
#include "core/iconloader.h"
#include "internet/internetmodel.h"
#include "internet/internetservices.h"
#include "tidal/tidalservice.h"
const char *TidalSettingsPage::kSettingsGroup = "Tidal";
@ -37,7 +37,7 @@ const char *TidalSettingsPage::kSettingsGroup = "Tidal";
TidalSettingsPage::TidalSettingsPage(SettingsDialog *parent)
: SettingsPage(parent),
ui_(new Ui::TidalSettingsPage),
service_(dialog()->app()->internet_model()->Service<TidalService>()) {
service_(dialog()->app()->internet_services()->Service<TidalService>()) {
ui_->setupUi(this);
setWindowIcon(IconLoader::Load("tidal"));

View File

@ -49,7 +49,7 @@
#include "core/taskmanager.h"
#include "core/timeconstants.h"
#include "core/utilities.h"
#include "internet/internetmodel.h"
#include "internet/internetservices.h"
#include "internet/internetsearch.h"
#include "tidalservice.h"
#include "tidalurlhandler.h"
@ -65,8 +65,8 @@ const int TidalService::kTimeResetLoginAttempts = 60000;
typedef QPair<QString, QString> Param;
TidalService::TidalService(Application *app, InternetModel *parent)
: InternetService(Song::Source_Tidal, "Tidal", "tidal", app, parent, parent),
TidalService::TidalService(Application *app, QObject *parent)
: InternetService(Song::Source_Tidal, "Tidal", "tidal", app, parent),
network_(new NetworkAccessManager(this)),
url_handler_(new TidalUrlHandler(app, this)),
timer_searchdelay_(new QTimer(this)),

View File

@ -35,7 +35,7 @@
#include <QJsonValue>
#include "core/song.h"
#include "internet/internetmodel.h"
#include "internet/internetservices.h"
#include "internet/internetservice.h"
#include "internet/internetsearch.h"
@ -46,7 +46,7 @@ class TidalService : public InternetService {
Q_OBJECT
public:
TidalService(Application *app, InternetModel *parent);
TidalService(Application *app, QObject *parent);
~TidalService();
static const Song::Source kSource;