Refactoring
This commit is contained in:
@@ -25,22 +25,19 @@
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/application.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/song.h"
|
||||
#include "settings/settingsdialog.h"
|
||||
|
||||
#include "audioscrobbler.h"
|
||||
#include "scrobblersettings.h"
|
||||
#include "scrobblersettingsservice.h"
|
||||
#include "scrobblerservice.h"
|
||||
|
||||
using std::make_shared;
|
||||
|
||||
AudioScrobbler::AudioScrobbler(Application *app, QObject *parent)
|
||||
AudioScrobbler::AudioScrobbler(QObject *parent)
|
||||
: QObject(parent),
|
||||
app_(app),
|
||||
settings_(make_shared<ScrobblerSettings>(app)) {
|
||||
settings_(make_shared<ScrobblerSettingsService>()) {
|
||||
|
||||
ReloadSettings();
|
||||
|
||||
@@ -122,10 +119,6 @@ void AudioScrobbler::ToggleOffline() {
|
||||
|
||||
}
|
||||
|
||||
void AudioScrobbler::ShowConfig() {
|
||||
app_->OpenSettingsDialogAtPage(SettingsDialog::Page::Scrobbler);
|
||||
}
|
||||
|
||||
void AudioScrobbler::UpdateNowPlaying(const Song &song) {
|
||||
|
||||
if (!settings_->sources().contains(song.source())) return;
|
||||
|
||||
@@ -30,11 +30,10 @@
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/song.h"
|
||||
#include "scrobblersettings.h"
|
||||
#include "scrobblersettingsservice.h"
|
||||
|
||||
class Application;
|
||||
class ScrobblerService;
|
||||
class Song;
|
||||
|
||||
@@ -42,7 +41,7 @@ class AudioScrobbler : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AudioScrobbler(Application *app, QObject *parent = nullptr);
|
||||
explicit AudioScrobbler(QObject *parent = nullptr);
|
||||
~AudioScrobbler();
|
||||
|
||||
void AddService(SharedPtr<ScrobblerService> service);
|
||||
@@ -59,7 +58,7 @@ class AudioScrobbler : public QObject {
|
||||
}
|
||||
|
||||
void ReloadSettings();
|
||||
SharedPtr<ScrobblerSettings> settings() { return settings_; }
|
||||
SharedPtr<ScrobblerSettingsService> settings() { return settings_; }
|
||||
|
||||
bool enabled() const { return settings_->enabled(); }
|
||||
bool offline() const { return settings_->offline(); }
|
||||
@@ -71,8 +70,6 @@ class AudioScrobbler : public QObject {
|
||||
bool strip_remastered() const { return settings_->strip_remastered(); }
|
||||
QList<Song::Source> sources() const { return settings_->sources(); }
|
||||
|
||||
void ShowConfig();
|
||||
|
||||
void UpdateNowPlaying(const Song &song);
|
||||
void ClearPlaying();
|
||||
void Scrobble(const Song &song, const qint64 scrobble_point);
|
||||
@@ -89,8 +86,7 @@ class AudioScrobbler : public QObject {
|
||||
void ErrorMessage(const QString &error);
|
||||
|
||||
private:
|
||||
Application *app_;
|
||||
SharedPtr<ScrobblerSettings> settings_;
|
||||
SharedPtr<ScrobblerSettingsService> settings_;
|
||||
QMap<QString, SharedPtr<ScrobblerService>> services_;
|
||||
|
||||
Q_DISABLE_COPY(AudioScrobbler)
|
||||
|
||||
@@ -38,8 +38,8 @@
|
||||
#include <QJsonArray>
|
||||
#include <QJsonValue>
|
||||
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "core/settings.h"
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace {
|
||||
constexpr int kRequestsDelay = 2000;
|
||||
}
|
||||
|
||||
LastFMImport::LastFMImport(SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
LastFMImport::LastFMImport(const SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
: QObject(parent),
|
||||
network_(network),
|
||||
timer_flush_requests_(new QTimer(this)),
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include <QQueue>
|
||||
#include <QDateTime>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
|
||||
class QTimer;
|
||||
class QNetworkReply;
|
||||
@@ -42,7 +42,7 @@ class LastFMImport : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LastFMImport(SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
|
||||
explicit LastFMImport(const SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
|
||||
~LastFMImport() override;
|
||||
|
||||
void ReloadSettings();
|
||||
|
||||
@@ -21,10 +21,10 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
|
||||
#include "scrobblersettings.h"
|
||||
#include "scrobblersettingsservice.h"
|
||||
#include "lastfmscrobbler.h"
|
||||
|
||||
const char *LastFMScrobbler::kName = "Last.fm";
|
||||
@@ -36,5 +36,5 @@ constexpr char kAuthUrl[] = "https://www.last.fm/api/auth/";
|
||||
constexpr char kCacheFile[] = "lastfmscrobbler.cache";
|
||||
} // namespace
|
||||
|
||||
LastFMScrobbler::LastFMScrobbler(SharedPtr<ScrobblerSettings> settings, SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
LastFMScrobbler::LastFMScrobbler(const SharedPtr<ScrobblerSettingsService> settings, const SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
: ScrobblingAPI20(QLatin1String(kName), QLatin1String(kSettingsGroup), QLatin1String(kAuthUrl), QLatin1String(kApiUrl), true, QLatin1String(kCacheFile), settings, network, parent) {}
|
||||
|
||||
@@ -25,17 +25,17 @@
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "scrobblingapi20.h"
|
||||
|
||||
class AudioScrobbler;
|
||||
class ScrobblerSettingsService;
|
||||
class NetworkAccessManager;
|
||||
|
||||
class LastFMScrobbler : public ScrobblingAPI20 {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LastFMScrobbler(SharedPtr<ScrobblerSettings> settings, SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
|
||||
explicit LastFMScrobbler(const SharedPtr<ScrobblerSettingsService> settings, const SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
|
||||
|
||||
static const char *kName;
|
||||
static const char *kSettingsGroup;
|
||||
|
||||
@@ -21,10 +21,10 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
|
||||
#include "scrobblersettings.h"
|
||||
#include "scrobblersettingsservice.h"
|
||||
#include "scrobblingapi20.h"
|
||||
#include "librefmscrobbler.h"
|
||||
|
||||
@@ -34,5 +34,5 @@ const char *LibreFMScrobbler::kAuthUrl = "https://www.libre.fm/api/auth/";
|
||||
const char *LibreFMScrobbler::kApiUrl = "https://libre.fm/2.0/";
|
||||
const char *LibreFMScrobbler::kCacheFile = "librefmscrobbler.cache";
|
||||
|
||||
LibreFMScrobbler::LibreFMScrobbler(SharedPtr<ScrobblerSettings> settings, SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
LibreFMScrobbler::LibreFMScrobbler(const SharedPtr<ScrobblerSettingsService> settings, const SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
: ScrobblingAPI20(QLatin1String(kName), QLatin1String(kSettingsGroup), QLatin1String(kAuthUrl), QLatin1String(kApiUrl), false, QLatin1String(kCacheFile), settings, network, parent) {}
|
||||
|
||||
@@ -25,17 +25,17 @@
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "scrobblingapi20.h"
|
||||
|
||||
class ScrobblerSettings;
|
||||
class ScrobblerSettingsService;
|
||||
class NetworkAccessManager;
|
||||
|
||||
class LibreFMScrobbler : public ScrobblingAPI20 {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LibreFMScrobbler(SharedPtr<ScrobblerSettings> settings, SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
|
||||
explicit LibreFMScrobbler(const SharedPtr<ScrobblerSettingsService> settings, const SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
|
||||
|
||||
static const char *kName;
|
||||
static const char *kSettingsGroup;
|
||||
|
||||
@@ -41,16 +41,16 @@
|
||||
#include <QJsonArray>
|
||||
#include <QJsonValue>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "core/song.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/settings.h"
|
||||
#include "core/localredirectserver.h"
|
||||
#include "utilities/timeconstants.h"
|
||||
#include "settings/scrobblersettingspage.h"
|
||||
#include "constants/timeconstants.h"
|
||||
#include "constants/scrobblersettings.h"
|
||||
|
||||
#include "scrobblersettings.h"
|
||||
#include "scrobblersettingsservice.h"
|
||||
#include "scrobblerservice.h"
|
||||
#include "scrobblercache.h"
|
||||
#include "scrobblercacheitem.h"
|
||||
@@ -73,7 +73,7 @@ constexpr char kCacheFile[] = "listenbrainzscrobbler.cache";
|
||||
constexpr int kScrobblesPerRequest = 10;
|
||||
} // namespace
|
||||
|
||||
ListenBrainzScrobbler::ListenBrainzScrobbler(SharedPtr<ScrobblerSettings> settings, SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
ListenBrainzScrobbler::ListenBrainzScrobbler(const SharedPtr<ScrobblerSettingsService> settings, const SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
: ScrobblerService(QLatin1String(kName), settings, parent),
|
||||
network_(network),
|
||||
cache_(new ScrobblerCache(QLatin1String(kCacheFile), this)),
|
||||
@@ -119,12 +119,12 @@ void ListenBrainzScrobbler::ReloadSettings() {
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
enabled_ = s.value("enabled", false).toBool();
|
||||
user_token_ = s.value("user_token").toString();
|
||||
enabled_ = s.value(ScrobblerSettings::kEnabled, false).toBool();
|
||||
user_token_ = s.value(ScrobblerSettings::kUserToken).toString();
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup(ScrobblerSettingsPage::kSettingsGroup);
|
||||
prefer_albumartist_ = s.value("albumartist", false).toBool();
|
||||
s.beginGroup(ScrobblerSettings::kSettingsGroup);
|
||||
prefer_albumartist_ = s.value(ScrobblerSettings::kAlbumArtist, false).toBool();
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
@@ -632,7 +632,10 @@ void ListenBrainzScrobbler::Love() {
|
||||
|
||||
if (!song_playing_.is_valid() || !song_playing_.is_metadata_good()) return;
|
||||
|
||||
if (!authenticated()) settings_->ShowConfig();
|
||||
if (!authenticated()) {
|
||||
Q_EMIT OpenSettingsDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
if (song_playing_.musicbrainz_recording_id().isEmpty()) {
|
||||
Error(tr("Missing MusicBrainz recording ID for %1 %2 %3").arg(song_playing_.artist(), song_playing_.album(), song_playing_.title()));
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QTimer>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/song.h"
|
||||
#include "scrobblerservice.h"
|
||||
#include "scrobblercache.h"
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
class ScrobblerSettings;
|
||||
class ScrobblerSettingsService;
|
||||
class NetworkAccessManager;
|
||||
class LocalRedirectServer;
|
||||
|
||||
@@ -48,7 +48,7 @@ class ListenBrainzScrobbler : public ScrobblerService {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ListenBrainzScrobbler(SharedPtr<ScrobblerSettings> settings, SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
|
||||
explicit ListenBrainzScrobbler(const SharedPtr<ScrobblerSettingsService> settings, const SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
|
||||
~ListenBrainzScrobbler() override;
|
||||
|
||||
static const char *kName;
|
||||
@@ -64,7 +64,6 @@ class ListenBrainzScrobbler : public ScrobblerService {
|
||||
|
||||
void Authenticate();
|
||||
void Logout();
|
||||
void ShowConfig();
|
||||
void Submit() override;
|
||||
void UpdateNowPlaying(const Song &song) override;
|
||||
void ClearPlaying() override;
|
||||
@@ -101,7 +100,7 @@ class ListenBrainzScrobbler : public ScrobblerService {
|
||||
void StartSubmit(const bool initial = false) override;
|
||||
void CheckScrobblePrevSong();
|
||||
|
||||
SharedPtr<NetworkAccessManager> network_;
|
||||
const SharedPtr<NetworkAccessManager> network_;
|
||||
ScrobblerCache *cache_;
|
||||
LocalRedirectServer *server_;
|
||||
bool enabled_;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <QtGlobal>
|
||||
#include <QMetaType>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "scrobblemetadata.h"
|
||||
|
||||
class ScrobblerCacheItem {
|
||||
|
||||
@@ -27,11 +27,11 @@
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "scrobblerservice.h"
|
||||
#include "scrobblersettings.h"
|
||||
#include "scrobblersettingsservice.h"
|
||||
|
||||
#include "core/song.h"
|
||||
|
||||
ScrobblerService::ScrobblerService(const QString &name, SharedPtr<ScrobblerSettings> settings, QObject *parent) : QObject(parent), name_(name), settings_(settings) {}
|
||||
ScrobblerService::ScrobblerService(const QString &name, const SharedPtr<ScrobblerSettingsService> settings, QObject *parent) : QObject(parent), name_(name), settings_(settings) {}
|
||||
|
||||
bool ScrobblerService::ExtractJsonObj(const QByteArray &data, QJsonObject &json_obj, QString &error_description) {
|
||||
|
||||
|
||||
@@ -30,16 +30,16 @@
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/song.h"
|
||||
|
||||
#include "scrobblersettings.h"
|
||||
#include "scrobblersettingsservice.h"
|
||||
|
||||
class ScrobblerService : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ScrobblerService(const QString &name, SharedPtr<ScrobblerSettings> settings, QObject *parent);
|
||||
explicit ScrobblerService(const QString &name, const SharedPtr<ScrobblerSettingsService> settings, QObject *parent);
|
||||
|
||||
QString name() const { return name_; }
|
||||
|
||||
@@ -72,10 +72,11 @@ class ScrobblerService : public QObject {
|
||||
|
||||
Q_SIGNALS:
|
||||
void ErrorMessage(const QString &error);
|
||||
void OpenSettingsDialog();
|
||||
|
||||
protected:
|
||||
QString name_;
|
||||
SharedPtr<ScrobblerSettings> settings_;
|
||||
const QString name_;
|
||||
const SharedPtr<ScrobblerSettingsService> settings_;
|
||||
};
|
||||
|
||||
using ScrobblerServicePtr = SharedPtr<ScrobblerService>;
|
||||
|
||||
@@ -23,16 +23,13 @@
|
||||
#include <QString>
|
||||
#include <QSettings>
|
||||
|
||||
#include "core/application.h"
|
||||
#include "core/song.h"
|
||||
#include "core/settings.h"
|
||||
#include "settings/settingsdialog.h"
|
||||
#include "settings/scrobblersettingspage.h"
|
||||
#include "scrobblersettings.h"
|
||||
#include "constants/scrobblersettings.h"
|
||||
#include "scrobblersettingsservice.h"
|
||||
|
||||
ScrobblerSettings::ScrobblerSettings(Application *app, QObject *parent)
|
||||
ScrobblerSettingsService::ScrobblerSettingsService(QObject *parent)
|
||||
: QObject(parent),
|
||||
app_(app),
|
||||
enabled_(false),
|
||||
offline_(false),
|
||||
scrobble_button_(false),
|
||||
@@ -46,10 +43,10 @@ ScrobblerSettings::ScrobblerSettings(Application *app, QObject *parent)
|
||||
|
||||
}
|
||||
|
||||
void ScrobblerSettings::ReloadSettings() {
|
||||
void ScrobblerSettingsService::ReloadSettings() {
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(ScrobblerSettingsPage::kSettingsGroup);
|
||||
s.beginGroup(ScrobblerSettings::kSettingsGroup);
|
||||
enabled_ = s.value("enabled", false).toBool();
|
||||
offline_ = s.value("offline", false).toBool();
|
||||
scrobble_button_ = s.value("scrobble_button", false).toBool();
|
||||
@@ -88,13 +85,13 @@ void ScrobblerSettings::ReloadSettings() {
|
||||
|
||||
}
|
||||
|
||||
void ScrobblerSettings::ToggleScrobbling() {
|
||||
void ScrobblerSettingsService::ToggleScrobbling() {
|
||||
|
||||
bool enabled_old_ = enabled_;
|
||||
enabled_ = !enabled_;
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(ScrobblerSettingsPage::kSettingsGroup);
|
||||
s.beginGroup(ScrobblerSettings::kSettingsGroup);
|
||||
s.setValue("enabled", enabled_);
|
||||
s.endGroup();
|
||||
|
||||
@@ -102,13 +99,13 @@ void ScrobblerSettings::ToggleScrobbling() {
|
||||
|
||||
}
|
||||
|
||||
void ScrobblerSettings::ToggleOffline() {
|
||||
void ScrobblerSettingsService::ToggleOffline() {
|
||||
|
||||
bool offline_old_ = offline_;
|
||||
offline_ = !offline_;
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(ScrobblerSettingsPage::kSettingsGroup);
|
||||
s.beginGroup(ScrobblerSettings::kSettingsGroup);
|
||||
s.setValue("offline", offline_);
|
||||
s.endGroup();
|
||||
|
||||
@@ -116,10 +113,6 @@ void ScrobblerSettings::ToggleOffline() {
|
||||
|
||||
}
|
||||
|
||||
void ScrobblerSettings::ShowConfig() {
|
||||
app_->OpenSettingsDialogAtPage(SettingsDialog::Page::Scrobbler);
|
||||
}
|
||||
|
||||
void ScrobblerSettings::ErrorReceived(const QString &error) {
|
||||
void ScrobblerSettingsService::ErrorReceived(const QString &error) {
|
||||
Q_EMIT ErrorMessage(error);
|
||||
}
|
||||
@@ -17,8 +17,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SCROBBLERSETTINGS_H
|
||||
#define SCROBBLERSETTINGS_H
|
||||
#ifndef SCROBBLERSETTINGSSERVICE_H
|
||||
#define SCROBBLERSETTINGSSERVICE_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
@@ -29,14 +29,13 @@
|
||||
|
||||
#include "core/song.h"
|
||||
|
||||
class Application;
|
||||
class Song;
|
||||
|
||||
class ScrobblerSettings : public QObject {
|
||||
class ScrobblerSettingsService : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ScrobblerSettings(Application *app, QObject *parent = nullptr);
|
||||
explicit ScrobblerSettingsService(QObject *parent = nullptr);
|
||||
|
||||
void ReloadSettings();
|
||||
|
||||
@@ -50,8 +49,6 @@ class ScrobblerSettings : public QObject {
|
||||
bool strip_remastered() const { return strip_remastered_; }
|
||||
QList<Song::Source> sources() const { return sources_; }
|
||||
|
||||
void ShowConfig();
|
||||
|
||||
public Q_SLOTS:
|
||||
void ToggleScrobbling();
|
||||
void ToggleOffline();
|
||||
@@ -65,8 +62,6 @@ class ScrobblerSettings : public QObject {
|
||||
void LoveButtonVisibilityChanged(const bool value);
|
||||
|
||||
private:
|
||||
Application *app_;
|
||||
|
||||
bool enabled_;
|
||||
bool offline_;
|
||||
bool scrobble_button_;
|
||||
@@ -77,7 +72,7 @@ class ScrobblerSettings : public QObject {
|
||||
bool strip_remastered_;
|
||||
QList<Song::Source> sources_;
|
||||
|
||||
Q_DISABLE_COPY(ScrobblerSettings)
|
||||
Q_DISABLE_COPY(ScrobblerSettingsService)
|
||||
};
|
||||
|
||||
#endif // SCROBBLERSETTINGS_H
|
||||
#endif // SCROBBLERSETTINGSSERVICE_H
|
||||
@@ -45,16 +45,16 @@
|
||||
#include <QJsonValue>
|
||||
#include <QFlags>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "core/song.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/settings.h"
|
||||
#include "core/localredirectserver.h"
|
||||
#include "utilities/timeconstants.h"
|
||||
#include "settings/scrobblersettingspage.h"
|
||||
#include "constants/timeconstants.h"
|
||||
#include "constants/scrobblersettings.h"
|
||||
|
||||
#include "scrobblersettings.h"
|
||||
#include "scrobblersettingsservice.h"
|
||||
#include "scrobblerservice.h"
|
||||
#include "scrobblingapi20.h"
|
||||
#include "scrobblercache.h"
|
||||
@@ -70,7 +70,7 @@ constexpr char kSecret[] = "80fd738f49596e9709b1bf9319c444a8";
|
||||
constexpr int kScrobblesPerRequest = 50;
|
||||
}
|
||||
|
||||
ScrobblingAPI20::ScrobblingAPI20(const QString &name, const QString &settings_group, const QString &auth_url, const QString &api_url, const bool batch, const QString &cache_file, SharedPtr<ScrobblerSettings> settings, SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
ScrobblingAPI20::ScrobblingAPI20(const QString &name, const QString &settings_group, const QString &auth_url, const QString &api_url, const bool batch, const QString &cache_file, const SharedPtr<ScrobblerSettingsService> settings, const SharedPtr<NetworkAccessManager> network, QObject *parent)
|
||||
: ScrobblerService(name, settings, parent),
|
||||
name_(name),
|
||||
settings_group_(settings_group),
|
||||
@@ -118,11 +118,11 @@ void ScrobblingAPI20::ReloadSettings() {
|
||||
Settings s;
|
||||
|
||||
s.beginGroup(settings_group_);
|
||||
enabled_ = s.value("enabled", false).toBool();
|
||||
enabled_ = s.value(ScrobblerSettings::kEnabled, false).toBool();
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup(ScrobblerSettingsPage::kSettingsGroup);
|
||||
prefer_albumartist_ = s.value("albumartist", false).toBool();
|
||||
s.beginGroup(ScrobblerSettings::kSettingsGroup);
|
||||
prefer_albumartist_ = s.value(ScrobblerSettings::kAlbumArtist, false).toBool();
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
@@ -828,7 +828,10 @@ void ScrobblingAPI20::Love() {
|
||||
|
||||
if (!song_playing_.is_valid() || !song_playing_.is_metadata_good()) return;
|
||||
|
||||
if (!authenticated()) settings_->ShowConfig();
|
||||
if (!authenticated()) {
|
||||
Q_EMIT OpenSettingsDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
qLog(Debug) << name_ << "Sending love for song" << song_playing_.artist() << song_playing_.album() << song_playing_.title();
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/song.h"
|
||||
#include "scrobblerservice.h"
|
||||
#include "scrobblercache.h"
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
class ScrobblerSettings;
|
||||
class ScrobblerSettingsService;
|
||||
class NetworkAccessManager;
|
||||
class LocalRedirectServer;
|
||||
|
||||
@@ -46,7 +46,7 @@ class ScrobblingAPI20 : public ScrobblerService {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ScrobblingAPI20(const QString &name, const QString &settings_group, const QString &auth_url, const QString &api_url, const bool batch, const QString &cache_file, SharedPtr<ScrobblerSettings> settings, SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
|
||||
explicit ScrobblingAPI20(const QString &name, const QString &settings_group, const QString &auth_url, const QString &api_url, const bool batch, const QString &cache_file, const SharedPtr<ScrobblerSettingsService> settings, const SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
|
||||
~ScrobblingAPI20() override;
|
||||
|
||||
static const char *kApiKey;
|
||||
@@ -138,7 +138,7 @@ class ScrobblingAPI20 : public ScrobblerService {
|
||||
QString api_url_;
|
||||
bool batch_;
|
||||
|
||||
SharedPtr<NetworkAccessManager> network_;
|
||||
const SharedPtr<NetworkAccessManager> network_;
|
||||
ScrobblerCache *cache_;
|
||||
LocalRedirectServer *server_;
|
||||
|
||||
|
||||
@@ -27,16 +27,15 @@
|
||||
#include <QDateTime>
|
||||
#include <QTimer>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/application.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/song.h"
|
||||
#include "core/logging.h"
|
||||
#include "utilities/timeconstants.h"
|
||||
#include "settings/subsonicsettingspage.h"
|
||||
#include "streaming/streamingservices.h"
|
||||
#include "core/settings.h"
|
||||
#include "constants/timeconstants.h"
|
||||
#include "constants/subsonicsettings.h"
|
||||
#include "subsonic/subsonicservice.h"
|
||||
|
||||
#include "scrobblersettings.h"
|
||||
#include "scrobblersettingsservice.h"
|
||||
#include "scrobblerservice.h"
|
||||
#include "subsonicscrobbler.h"
|
||||
|
||||
@@ -44,10 +43,9 @@ namespace {
|
||||
constexpr char kName[] = "Subsonic";
|
||||
}
|
||||
|
||||
SubsonicScrobbler::SubsonicScrobbler(SharedPtr<ScrobblerSettings> settings, Application *app, QObject *parent)
|
||||
SubsonicScrobbler::SubsonicScrobbler(const SharedPtr<ScrobblerSettingsService> settings, const SharedPtr<SubsonicService> service, QObject *parent)
|
||||
: ScrobblerService(QLatin1String(kName), settings, parent),
|
||||
app_(app),
|
||||
service_(nullptr),
|
||||
service_(service),
|
||||
enabled_(false),
|
||||
submitted_(false) {
|
||||
|
||||
@@ -61,17 +59,13 @@ SubsonicScrobbler::SubsonicScrobbler(SharedPtr<ScrobblerSettings> settings, Appl
|
||||
void SubsonicScrobbler::ReloadSettings() {
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(SubsonicSettingsPage::kSettingsGroup);
|
||||
s.beginGroup(SubsonicSettings::kSettingsGroup);
|
||||
enabled_ = s.value("serversidescrobbling", false).toBool();
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
|
||||
SubsonicServicePtr SubsonicScrobbler::service() {
|
||||
|
||||
if (!service_) {
|
||||
service_ = app_->streaming_services()->Service<SubsonicService>();
|
||||
}
|
||||
SubsonicServicePtr SubsonicScrobbler::service() const {
|
||||
|
||||
return service_;
|
||||
|
||||
|
||||
@@ -30,19 +30,18 @@
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/song.h"
|
||||
#include "scrobblerservice.h"
|
||||
|
||||
class Application;
|
||||
class ScrobblerSettings;
|
||||
class ScrobblerSettingsService;
|
||||
class SubsonicService;
|
||||
|
||||
class SubsonicScrobbler : public ScrobblerService {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SubsonicScrobbler(SharedPtr<ScrobblerSettings> settings, Application *app, QObject *parent = nullptr);
|
||||
explicit SubsonicScrobbler(const SharedPtr<ScrobblerSettingsService> settings, const SharedPtr<SubsonicService> service, QObject *parent = nullptr);
|
||||
|
||||
void ReloadSettings() override;
|
||||
|
||||
@@ -56,15 +55,14 @@ class SubsonicScrobbler : public ScrobblerService {
|
||||
void StartSubmit(const bool initial = false) override { Q_UNUSED(initial) }
|
||||
bool submitted() const override { return submitted_; }
|
||||
|
||||
SharedPtr<SubsonicService> service();
|
||||
SharedPtr<SubsonicService> service() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void WriteCache() override {}
|
||||
void Submit() override;
|
||||
|
||||
private:
|
||||
Application *app_;
|
||||
SharedPtr<SubsonicService> service_;
|
||||
const SharedPtr<SubsonicService> service_;
|
||||
bool enabled_;
|
||||
bool submitted_;
|
||||
Song song_playing_;
|
||||
|
||||
Reference in New Issue
Block a user