Add scrobbler with support for Last.fm, Libre.fm and ListenBrainz

This commit is contained in:
Jonas Kvinge
2018-12-23 18:54:27 +01:00
parent 517285085a
commit 0d7e12e781
43 changed files with 3565 additions and 169 deletions

View File

@@ -0,0 +1,230 @@
/*
* Strawberry Music Player
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
*
* 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/>.
*
*/
#include "scrobblersettingspage.h"
#include "ui_scrobblersettingspage.h"
#include <QDesktopServices>
#include <QMessageBox>
#include <QSettings>
#include "core/application.h"
#include "core/iconloader.h"
#include "scrobbler/audioscrobbler.h"
#include "scrobbler/scrobblerservice.h"
#include "scrobbler/lastfmscrobbler.h"
#include "scrobbler/librefmscrobbler.h"
#include "scrobbler/listenbrainzscrobbler.h"
const char *ScrobblerSettingsPage::kSettingsGroup = "Scrobbler";
ScrobblerSettingsPage::ScrobblerSettingsPage(SettingsDialog *parent)
: SettingsPage(parent),
scrobbler_(dialog()->app()->scrobbler()),
lastfmscrobbler_(dialog()->app()->scrobbler()->Service<LastFMScrobbler>()),
librefmscrobbler_(dialog()->app()->scrobbler()->Service<LibreFMScrobbler>()),
listenbrainzscrobbler_(dialog()->app()->scrobbler()->Service<ListenBrainzScrobbler>()),
ui_(new Ui_ScrobblerSettingsPage),
lastfm_waiting_for_auth_(false),
librefm_waiting_for_auth_(false),
listenbrainz_waiting_for_auth_(false)
{
ui_->setupUi(this);
setWindowIcon(IconLoader::Load("scrobble"));
// Last.fm
connect(lastfmscrobbler_, SIGNAL(AuthenticationComplete(bool, QString)), SLOT(LastFM_AuthenticationComplete(bool, QString)));
connect(ui_->button_lastfm_login, SIGNAL(clicked()), SLOT(LastFM_Login()));
connect(ui_->widget_lastfm_login_state, SIGNAL(LoginClicked()), SLOT(LastFM_Login()));
connect(ui_->widget_lastfm_login_state, SIGNAL(LogoutClicked()), SLOT(LastFM_Logout()));
ui_->widget_lastfm_login_state->AddCredentialGroup(ui_->widget_lastfm_login);
// Libre.fm
connect(librefmscrobbler_, SIGNAL(AuthenticationComplete(bool, QString)), SLOT(LibreFM_AuthenticationComplete(bool, QString)));
connect(ui_->button_librefm_login, SIGNAL(clicked()), SLOT(LibreFM_Login()));
connect(ui_->widget_librefm_login_state, SIGNAL(LoginClicked()), SLOT(LibreFM_Login()));
connect(ui_->widget_librefm_login_state, SIGNAL(LogoutClicked()), SLOT(LibreFM_Logout()));
ui_->widget_librefm_login_state->AddCredentialGroup(ui_->widget_librefm_login);
// ListenBrainz
connect(listenbrainzscrobbler_, SIGNAL(AuthenticationComplete(bool, QString)), SLOT(ListenBrainz_AuthenticationComplete(bool, QString)));
connect(ui_->button_listenbrainz_login, SIGNAL(clicked()), SLOT(ListenBrainz_Login()));
connect(ui_->widget_listenbrainz_login_state, SIGNAL(LoginClicked()), SLOT(ListenBrainz_Login()));
connect(ui_->widget_listenbrainz_login_state, SIGNAL(LogoutClicked()), SLOT(ListenBrainz_Logout()));
ui_->widget_listenbrainz_login_state->AddCredentialGroup(ui_->widget_listenbrainz_login);
resize(sizeHint());
}
ScrobblerSettingsPage::~ScrobblerSettingsPage() { delete ui_; }
void ScrobblerSettingsPage::Load() {
ui_->checkbox_enable->setChecked(scrobbler_->IsEnabled());
ui_->checkbox_scrobble_button->setChecked(scrobbler_->ScrobbleButton());
ui_->checkbox_offline->setChecked(scrobbler_->IsOffline());
ui_->checkbox_lastfm_enable->setChecked(lastfmscrobbler_->IsEnabled());
LastFM_RefreshControls(lastfmscrobbler_->IsAuthenticated());
ui_->checkbox_librefm_enable->setChecked(librefmscrobbler_->IsEnabled());
LibreFM_RefreshControls(librefmscrobbler_->IsAuthenticated());
ui_->checkbox_listenbrainz_enable->setChecked(listenbrainzscrobbler_->IsEnabled());
ui_->lineedit_listenbrainz_user_token->setText(listenbrainzscrobbler_->user_token());
ListenBrainz_RefreshControls(listenbrainzscrobbler_->IsAuthenticated());
}
void ScrobblerSettingsPage::Save() {
QSettings s;
s.beginGroup(kSettingsGroup);
s.setValue("enabled", ui_->checkbox_enable->isChecked());
s.setValue("scrobble_button", ui_->checkbox_scrobble_button->isChecked());
s.setValue("offline", ui_->checkbox_offline->isChecked());
s.endGroup();
s.beginGroup(LastFMScrobbler::kSettingsGroup);
s.setValue("enabled", ui_->checkbox_lastfm_enable->isChecked());
s.endGroup();
s.beginGroup(LibreFMScrobbler::kSettingsGroup);
s.setValue("enabled", ui_->checkbox_librefm_enable->isChecked());
s.endGroup();
s.beginGroup(ListenBrainzScrobbler::kSettingsGroup);
s.setValue("enabled", ui_->checkbox_listenbrainz_enable->isChecked());
s.setValue("user_token", ui_->lineedit_listenbrainz_user_token->text());
s.endGroup();
scrobbler_->ReloadSettings();
}
void ScrobblerSettingsPage::LastFM_Login() {
lastfm_waiting_for_auth_ = true;
ui_->widget_lastfm_login_state->SetLoggedIn(LoginStateWidget::LoginInProgress);
lastfmscrobbler_->Authenticate();
}
void ScrobblerSettingsPage::LastFM_Logout() {
lastfmscrobbler_->Logout();
LastFM_RefreshControls(false);
}
void ScrobblerSettingsPage::LastFM_AuthenticationComplete(const bool success, QString error) {
if (!lastfm_waiting_for_auth_) return;
lastfm_waiting_for_auth_ = false;
if (success) {
Save();
}
else {
QMessageBox::warning(this, "Authentication failed", error);
}
LastFM_RefreshControls(success);
}
void ScrobblerSettingsPage::LastFM_RefreshControls(bool authenticated) {
ui_->widget_lastfm_login_state->SetLoggedIn(authenticated ? LoginStateWidget::LoggedIn : LoginStateWidget::LoggedOut, lastfmscrobbler_->username());
}
void ScrobblerSettingsPage::LibreFM_Login() {
librefm_waiting_for_auth_ = true;
ui_->widget_librefm_login_state->SetLoggedIn(LoginStateWidget::LoginInProgress);
librefmscrobbler_->Authenticate();
}
void ScrobblerSettingsPage::LibreFM_Logout() {
librefmscrobbler_->Logout();
LibreFM_RefreshControls(false);
}
void ScrobblerSettingsPage::LibreFM_AuthenticationComplete(const bool success, QString error) {
if (!librefm_waiting_for_auth_) return;
librefm_waiting_for_auth_ = false;
if (success) {
Save();
}
else {
QMessageBox::warning(this, "Authentication failed", error);
}
LibreFM_RefreshControls(success);
}
void ScrobblerSettingsPage::LibreFM_RefreshControls(bool authenticated) {
ui_->widget_librefm_login_state->SetLoggedIn(authenticated ? LoginStateWidget::LoggedIn : LoginStateWidget::LoggedOut, librefmscrobbler_->username());
}
void ScrobblerSettingsPage::ListenBrainz_Login() {
listenbrainz_waiting_for_auth_ = true;
ui_->widget_listenbrainz_login_state->SetLoggedIn(LoginStateWidget::LoginInProgress);
listenbrainzscrobbler_->Authenticate();
}
void ScrobblerSettingsPage::ListenBrainz_Logout() {
listenbrainzscrobbler_->Logout();
ListenBrainz_RefreshControls(false);
}
void ScrobblerSettingsPage::ListenBrainz_AuthenticationComplete(const bool success, QString error) {
if (!listenbrainz_waiting_for_auth_) return;
listenbrainz_waiting_for_auth_ = false;
if (success) {
Save();
}
else {
QMessageBox::warning(this, "Authentication failed", error);
}
ListenBrainz_RefreshControls(success);
}
void ScrobblerSettingsPage::ListenBrainz_RefreshControls(bool authenticated) {
ui_->widget_listenbrainz_login_state->SetLoggedIn(authenticated ? LoginStateWidget::LoggedIn : LoginStateWidget::LoggedOut);
}

View File

@@ -0,0 +1,71 @@
/*
* Strawberry Music Player
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
*
* 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 SCROBBLERSETTINGSPAGE_H
#define SCROBBLERSETTINGSPAGE_H
#include "settingspage.h"
class Ui_ScrobblerSettingsPage;
class AudioScrobbler;
class LastFMScrobbler;
class LibreFMScrobbler;
class ListenBrainzScrobbler;
class ScrobblerSettingsPage : public SettingsPage {
Q_OBJECT
public:
explicit ScrobblerSettingsPage(SettingsDialog *dialog);
~ScrobblerSettingsPage();
static const char *kSettingsGroup;
void Load();
void Save();
private slots:
void LastFM_Login();
void LastFM_Logout();
void LastFM_AuthenticationComplete(const bool success, QString error = QString());
void LibreFM_Login();
void LibreFM_Logout();
void LibreFM_AuthenticationComplete(const bool success, QString error = QString());
void ListenBrainz_Login();
void ListenBrainz_Logout();
void ListenBrainz_AuthenticationComplete(const bool success, QString error = QString());
private:
AudioScrobbler *scrobbler_;
LastFMScrobbler *lastfmscrobbler_;
LibreFMScrobbler *librefmscrobbler_;
ListenBrainzScrobbler *listenbrainzscrobbler_;
Ui_ScrobblerSettingsPage* ui_;
bool lastfm_waiting_for_auth_;
bool librefm_waiting_for_auth_;
bool listenbrainz_waiting_for_auth_;
void LastFM_RefreshControls(bool authenticated);
void LibreFM_RefreshControls(bool authenticated);
void ListenBrainz_RefreshControls(bool authenticated);
};
#endif // SCROBBLERSETTINGSPAGE_H

View File

@@ -0,0 +1,243 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ScrobblerSettingsPage</class>
<widget class="QWidget" name="ScrobblerSettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>769</width>
<height>611</height>
</rect>
</property>
<property name="windowTitle">
<string>Scrobbler</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="checkbox_enable">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Enable</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkbox_offline">
<property name="text">
<string>Enable offline mode</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkbox_scrobble_button">
<property name="text">
<string>Show scrobble button</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupbox_lastfm">
<property name="title">
<string>Last.fm</string>
</property>
<layout class="QVBoxLayout" name="layout_lastfm">
<item>
<widget class="QCheckBox" name="checkbox_lastfm_enable">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
<item>
<widget class="LoginStateWidget" name="widget_lastfm_login_state" native="true"/>
</item>
<item>
<widget class="QWidget" name="widget_lastfm_login" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="layout_lastfm_button_login">
<item>
<widget class="QPushButton" name="button_lastfm_login">
<property name="text">
<string>Login</string>
</property>
</widget>
</item>
<item>
<spacer name="spacer_lastfm_login">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupbox_librefm">
<property name="title">
<string>Libre.fm</string>
</property>
<layout class="QVBoxLayout" name="layout_lastfm_3">
<item>
<widget class="QCheckBox" name="checkbox_librefm_enable">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
<item>
<widget class="LoginStateWidget" name="widget_librefm_login_state" native="true"/>
</item>
<item>
<widget class="QWidget" name="widget_librefm_login" native="true">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QHBoxLayout" name="layout_librefm_button_login">
<item>
<widget class="QPushButton" name="button_librefm_login">
<property name="text">
<string>Login</string>
</property>
</widget>
</item>
<item>
<spacer name="spacer_librefm_login">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupbox_listenbrainz">
<property name="title">
<string>Listenbrainz</string>
</property>
<layout class="QVBoxLayout" name="layout_lastfm_4">
<item>
<widget class="QCheckBox" name="checkbox_listenbrainz_enable">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="layout_listenbrainz_user_token">
<item>
<widget class="QLabel" name="label_listenbrainz_user_token">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>User token:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineedit_listenbrainz_user_token"/>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enter your user token found on: &lt;a href=&quot;https://listenbrainz.org/profile/&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;https://listenbrainz.org/profile/&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="LoginStateWidget" name="widget_listenbrainz_login_state" native="true"/>
</item>
<item>
<widget class="QWidget" name="widget_listenbrainz_login" native="true">
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="layout_listenbrainz_button_login">
<item>
<widget class="QPushButton" name="button_listenbrainz_login">
<property name="text">
<string>Login</string>
</property>
</widget>
</item>
<item>
<spacer name="spacer_listenbrainz_login">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LoginStateWidget</class>
<extends>QWidget</extends>
<header>widgets/loginstatewidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -56,12 +56,13 @@
#include "backendsettingspage.h"
#include "behavioursettingspage.h"
#include "collectionsettingspage.h"
#include "networkproxysettingspage.h"
#include "notificationssettingspage.h"
#include "playbacksettingspage.h"
#include "playlistsettingspage.h"
#include "shortcutssettingspage.h"
#include "transcodersettingspage.h"
#include "networkproxysettingspage.h"
#include "scrobblersettingspage.h"
#ifdef HAVE_STREAM_TIDAL
# include "tidalsettingspage.h"
#endif
@@ -123,10 +124,11 @@ SettingsDialog::SettingsDialog(Application *app, QWidget *parent)
AddPage(Page_Backend, new BackendSettingsPage(this), general);
AddPage(Page_Playback, new PlaybackSettingsPage(this), general);
AddPage(Page_Playlist, new PlaylistSettingsPage(this), general);
AddPage(Page_Proxy, new NetworkProxySettingsPage(this), general);
#ifdef HAVE_GSTREAMER
AddPage(Page_Transcoding, new TranscoderSettingsPage(this), general);
#endif
AddPage(Page_Proxy, new NetworkProxySettingsPage(this), general);
AddPage(Page_Scrobbler, new ScrobblerSettingsPage(this), general);
QTreeWidgetItem *iface = AddCategory(tr("User interface"));
AddPage(Page_Appearance, new AppearanceSettingsPage(this), iface);
@@ -134,13 +136,13 @@ SettingsDialog::SettingsDialog(Application *app, QWidget *parent)
AddPage(Page_GlobalShortcuts, new GlobalShortcutsSettingsPage(this), iface);
#if defined(HAVE_STREAM_TIDAL) || defined(HAVE_STREAM_DEEZER)
QTreeWidgetItem *internet = AddCategory(tr("Streaming"));
QTreeWidgetItem *streaming = AddCategory(tr("Streaming"));
#endif
#ifdef HAVE_STREAM_TIDAL
AddPage(Page_Tidal, new TidalSettingsPage(this), internet);
AddPage(Page_Tidal, new TidalSettingsPage(this), streaming);
#endif
#ifdef HAVE_STREAM_DEEZER
AddPage(Page_Deezer, new DeezerSettingsPage(this), internet);
AddPage(Page_Deezer, new DeezerSettingsPage(this), streaming);
#endif
// List box

View File

@@ -79,8 +79,9 @@ public:
Page_GlobalShortcuts,
Page_Appearance,
Page_Notifications,
Page_Proxy,
Page_Transcoding,
Page_Proxy,
Page_Scrobbler,
Page_Tidal,
Page_Deezer,
};