diff --git a/src/core/song.cpp b/src/core/song.cpp index 42696c588..baace42d8 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -480,6 +480,21 @@ QString Song::TextForSource(Source source) { } +Song::Source Song::SourceFromText(const QString &source) { + + if (source == "file") return Source_LocalFile; + if (source == "collection") return Source_Collection; + if (source == "cd") return Source_CDDA; + if (source == "device") return Source_Device; + if (source == "stream") return Source_Stream; + if (source == "tidal") return Source_Tidal; + if (source == "subsonic") return Source_Subsonic; + if (source == "qobuz") return Source_Qobuz; + + return Source_Unknown; + +} + QIcon Song::IconForSource(Source source) { switch (source) { diff --git a/src/core/song.h b/src/core/song.h index a5cbd3de3..cefd46a11 100644 --- a/src/core/song.h +++ b/src/core/song.h @@ -132,6 +132,7 @@ class Song { static Source SourceFromURL(const QUrl &url); static QString TextForSource(Source source); + static Song::Source SourceFromText(const QString &source); static QIcon IconForSource(Source source); static QString TextForFiletype(FileType filetype); static QString ExtensionForFiletype(FileType filetype); diff --git a/src/scrobbler/audioscrobbler.cpp b/src/scrobbler/audioscrobbler.cpp index c56093102..fa44eafce 100644 --- a/src/scrobbler/audioscrobbler.cpp +++ b/src/scrobbler/audioscrobbler.cpp @@ -74,8 +74,28 @@ void AudioScrobbler::ReloadSettings() { submit_delay_ = s.value("submit", 0).toInt(); prefer_albumartist_ = s.value("albumartist", false).toBool(); show_error_dialog_ = s.value("show_error_dialog", true).toBool(); + QStringList sources = s.value("sources").toStringList(); s.endGroup(); + sources_.clear(); + + if (sources.isEmpty()) { + sources_ << Song::Source_Unknown + << Song::Source_LocalFile + << Song::Source_Collection + << Song::Source_CDDA + << Song::Source_Device + << Song::Source_Stream + << Song::Source_Tidal + << Song::Source_Subsonic + << Song::Source_Qobuz; + } + else { + for (const QString &source : sources) { + sources_ << Song::SourceFromText(source); + } + } + emit ScrobblingEnabledChanged(enabled_); emit ScrobbleButtonVisibilityChanged(scrobble_button_); emit LoveButtonVisibilityChanged(love_button_); @@ -122,6 +142,8 @@ void AudioScrobbler::ShowConfig() { void AudioScrobbler::UpdateNowPlaying(const Song &song) { + if (!sources_.contains(song.source())) return; + qLog(Debug) << "Sending now playing for song" << song.artist() << song.album() << song.title(); for (ScrobblerService *service : scrobbler_services_->List()) { @@ -142,6 +164,8 @@ void AudioScrobbler::ClearPlaying() { void AudioScrobbler::Scrobble(const Song &song, const int scrobble_point) { + if (!sources_.contains(song.source())) return; + qLog(Debug) << "Scrobbling song" << song.artist() << song.album() << song.title() << "at" << scrobble_point; for (ScrobblerService *service : scrobbler_services_->List()) { diff --git a/src/scrobbler/audioscrobbler.h b/src/scrobbler/audioscrobbler.h index 23aac344e..90780d56d 100644 --- a/src/scrobbler/audioscrobbler.h +++ b/src/scrobbler/audioscrobbler.h @@ -23,8 +23,10 @@ #include "config.h" #include +#include #include +#include "core/song.h" #include "scrobblerservices.h" class Application; @@ -46,6 +48,7 @@ class AudioScrobbler : public QObject { int SubmitDelay() const { return submit_delay_; } bool PreferAlbumArtist() const { return prefer_albumartist_; } bool ShowErrorDialog() const { return show_error_dialog_; } + QList sources() const { return sources_; } void UpdateNowPlaying(const Song &song); void ClearPlaying(); @@ -86,6 +89,7 @@ class AudioScrobbler : public QObject { int submit_delay_; bool prefer_albumartist_; bool show_error_dialog_; + QList sources_; }; diff --git a/src/settings/scrobblersettingspage.cpp b/src/settings/scrobblersettingspage.cpp index 20db22bb6..413d66973 100644 --- a/src/settings/scrobblersettingspage.cpp +++ b/src/settings/scrobblersettingspage.cpp @@ -33,6 +33,7 @@ #include "settingspage.h" #include "core/application.h" #include "core/iconloader.h" +#include "core/song.h" #include "widgets/loginstatewidget.h" #include "scrobbler/audioscrobbler.h" @@ -96,6 +97,15 @@ void ScrobblerSettingsPage::Load() { ui_->checkbox_albumartist->setChecked(scrobbler_->PreferAlbumArtist()); ui_->checkbox_show_error_dialog->setChecked(scrobbler_->ShowErrorDialog()); + ui_->checkbox_source_collection->setChecked(scrobbler_->sources().contains(Song::Source_Collection)); + ui_->checkbox_source_local->setChecked(scrobbler_->sources().contains(Song::Source_LocalFile)); + ui_->checkbox_source_cdda->setChecked(scrobbler_->sources().contains(Song::Source_CDDA)); + ui_->checkbox_source_device->setChecked(scrobbler_->sources().contains(Song::Source_Device)); + ui_->checkbox_source_tidal->setChecked(scrobbler_->sources().contains(Song::Source_Tidal)); + ui_->checkbox_source_subsonic->setChecked(scrobbler_->sources().contains(Song::Source_Subsonic)); + ui_->checkbox_source_stream->setChecked(scrobbler_->sources().contains(Song::Source_Stream)); + ui_->checkbox_source_unknown->setChecked(scrobbler_->sources().contains(Song::Source_Unknown)); + ui_->checkbox_lastfm_enable->setChecked(lastfmscrobbler_->IsEnabled()); ui_->checkbox_lastfm_https->setChecked(lastfmscrobbler_->IsUseHTTPS()); LastFM_RefreshControls(lastfmscrobbler_->IsAuthenticated()); @@ -123,6 +133,19 @@ void ScrobblerSettingsPage::Save() { s.setValue("submit", ui_->spinbox_submit->value()); s.setValue("albumartist", ui_->checkbox_albumartist->isChecked()); s.setValue("show_error_dialog", ui_->checkbox_show_error_dialog->isChecked()); + + QStringList sources; + if (ui_->checkbox_source_collection->isChecked()) sources << Song::TextForSource(Song::Source_Collection); + if (ui_->checkbox_source_local->isChecked()) sources << Song::TextForSource(Song::Source_LocalFile); + if (ui_->checkbox_source_cdda->isChecked()) sources << Song::TextForSource(Song::Source_CDDA); + if (ui_->checkbox_source_device->isChecked()) sources << Song::TextForSource(Song::Source_Device); + if (ui_->checkbox_source_tidal->isChecked()) sources << Song::TextForSource(Song::Source_Tidal); + if (ui_->checkbox_source_subsonic->isChecked()) sources << Song::TextForSource(Song::Source_Subsonic); + if (ui_->checkbox_source_stream->isChecked()) sources << Song::TextForSource(Song::Source_Stream); + if (ui_->checkbox_source_unknown->isChecked()) sources << Song::TextForSource(Song::Source_Unknown); + + s.setValue("sources", sources); + s.endGroup(); s.beginGroup(LastFMScrobbler::kSettingsGroup); diff --git a/src/settings/scrobblersettingspage.ui b/src/settings/scrobblersettingspage.ui index deee663fd..25a765a22 100644 --- a/src/settings/scrobblersettingspage.ui +++ b/src/settings/scrobblersettingspage.ui @@ -7,7 +7,7 @@ 0 0 460 - 960 + 1009 @@ -116,6 +116,131 @@ + + + + Enable scrobbling for the following sources: + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Collection + + + + + + + + 0 + 0 + + + + Tidal + + + + + + + + 0 + 0 + + + + CDDA + + + + + + + + 0 + 0 + + + + Stream + + + + + + + + 0 + 0 + + + + Unknown + + + + + + + + 0 + 0 + + + + Subsonic + + + + + + + + 0 + 0 + + + + Local file + + + + + + + + 0 + 0 + + + + Device + + + + + +