Add smart playlists, ratings and Qobuz

Fixes #259
Fixes #264
This commit is contained in:
Jonas Kvinge
2020-09-17 17:50:17 +02:00
parent fdf96e8342
commit 89d6b7cec0
102 changed files with 10949 additions and 525 deletions

View File

@@ -121,6 +121,10 @@ void CoversSettingsPage::CurrentItemChanged(QListWidgetItem *item_current, QList
DisableAuthentication();
ui_->label_auth_info->setText(tr("Use Tidal settings to authenticate."));
}
else if (provider->name() == "Qobuz" && !provider->IsAuthenticated()) {
DisableAuthentication();
ui_->label_auth_info->setText(tr("Use Qobuz settings to authenticate."));
}
else {
ui_->login_state->SetLoggedIn(provider->IsAuthenticated() ? LoginStateWidget::LoggedIn : LoginStateWidget::LoggedOut);
ui_->button_authenticate->setEnabled(true);
@@ -229,6 +233,10 @@ void CoversSettingsPage::LogoutClicked() {
DisableAuthentication();
ui_->label_auth_info->setText(tr("Use Tidal settings to authenticate."));
}
else if (provider->name() == "Qobuz") {
DisableAuthentication();
ui_->label_auth_info->setText(tr("Use Qobuz settings to authenticate."));
}
else {
ui_->button_authenticate->setEnabled(true);
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut);

View File

@@ -0,0 +1,171 @@
/*
* Strawberry Music Player
* Copyright 2019, 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 "config.h"
#include <QObject>
#include <QVariant>
#include <QByteArray>
#include <QString>
#include <QSettings>
#include <QMessageBox>
#include <QCheckBox>
#include <QComboBox>
#include <QLineEdit>
#include <QPushButton>
#include <QSpinBox>
#include <QEvent>
#include "settingsdialog.h"
#include "qobuzsettingspage.h"
#include "ui_qobuzsettingspage.h"
#include "core/application.h"
#include "core/iconloader.h"
#include "widgets/loginstatewidget.h"
#include "internet/internetservices.h"
#include "qobuz/qobuzservice.h"
const char *QobuzSettingsPage::kSettingsGroup = "Qobuz";
QobuzSettingsPage::QobuzSettingsPage(SettingsDialog *parent)
: SettingsPage(parent),
ui_(new Ui::QobuzSettingsPage),
service_(dialog()->app()->internet_services()->Service<QobuzService>()) {
ui_->setupUi(this);
setWindowIcon(IconLoader::Load("qobuz"));
connect(ui_->button_login, SIGNAL(clicked()), SLOT(LoginClicked()));
connect(ui_->login_state, SIGNAL(LogoutClicked()), SLOT(LogoutClicked()));
connect(this, SIGNAL(Login(QString, QString, QString)), service_, SLOT(SendLogin(QString, QString, QString)));
connect(service_, SIGNAL(LoginFailure(QString)), SLOT(LoginFailure(QString)));
connect(service_, SIGNAL(LoginSuccess()), SLOT(LoginSuccess()));
dialog()->installEventFilter(this);
ui_->format->addItem("MP3 320", 5);
ui_->format->addItem("FLAC Lossless", 6);
ui_->format->addItem("FLAC Hi-Res <= 96kHz", 7);
ui_->format->addItem("FLAC Hi-Res > 96kHz", 27);
}
QobuzSettingsPage::~QobuzSettingsPage() { delete ui_; }
void QobuzSettingsPage::Load() {
QSettings s;
s.beginGroup(kSettingsGroup);
ui_->enable->setChecked(s.value("enabled", false).toBool());
ui_->app_id->setText(s.value("app_id").toString());
ui_->app_secret->setText(s.value("app_secret").toString());
ui_->username->setText(s.value("username").toString());
QByteArray password = s.value("password").toByteArray();
if (password.isEmpty()) ui_->password->clear();
else ui_->password->setText(QString::fromUtf8(QByteArray::fromBase64(password)));
dialog()->ComboBoxLoadFromSettings(s, ui_->format, "format", 27);
ui_->searchdelay->setValue(s.value("searchdelay", 1500).toInt());
ui_->artistssearchlimit->setValue(s.value("artistssearchlimit", 4).toInt());
ui_->albumssearchlimit->setValue(s.value("albumssearchlimit", 10).toInt());
ui_->songssearchlimit->setValue(s.value("songssearchlimit", 10).toInt());
ui_->checkbox_download_album_covers->setChecked(s.value("downloadalbumcovers", true).toBool());
s.endGroup();
if (service_->authenticated()) ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn);
Init(ui_->layout_qobuzsettingspage->parentWidget());
}
void QobuzSettingsPage::Save() {
QSettings s;
s.beginGroup(kSettingsGroup);
s.setValue("enabled", ui_->enable->isChecked());
s.setValue("app_id", ui_->app_id->text());
s.setValue("app_secret", ui_->app_secret->text());
s.setValue("username", ui_->username->text());
s.setValue("password", QString::fromUtf8(ui_->password->text().toUtf8().toBase64()));
s.setValue("format", ui_->format->itemData(ui_->format->currentIndex()));
s.setValue("searchdelay", ui_->searchdelay->value());
s.setValue("artistssearchlimit", ui_->artistssearchlimit->value());
s.setValue("albumssearchlimit", ui_->albumssearchlimit->value());
s.setValue("songssearchlimit", ui_->songssearchlimit->value());
s.setValue("downloadalbumcovers", ui_->checkbox_download_album_covers->isChecked());
s.endGroup();
service_->ReloadSettings();
}
void QobuzSettingsPage::LoginClicked() {
if (ui_->app_id->text().isEmpty()) {
QMessageBox::critical(this, tr("Configuration incomplete"), tr("Missing app id."));
return;
}
if (ui_->username->text().isEmpty()) {
QMessageBox::critical(this, tr("Configuration incomplete"), tr("Missing username."));
return;
}
if (ui_->password->text().isEmpty()) {
QMessageBox::critical(this, tr("Configuration incomplete"), tr("Missing password."));
return;
}
emit Login(ui_->app_id->text(), ui_->username->text(), ui_->password->text());
ui_->button_login->setEnabled(false);
}
bool QobuzSettingsPage::eventFilter(QObject *object, QEvent *event) {
if (object == dialog() && event->type() == QEvent::Enter) {
ui_->button_login->setEnabled(true);
return false;
}
return SettingsPage::eventFilter(object, event);
}
void QobuzSettingsPage::LogoutClicked() {
service_->Logout();
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut);
ui_->button_login->setEnabled(true);
}
void QobuzSettingsPage::LoginSuccess() {
if (!this->isVisible()) return;
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn);
ui_->button_login->setEnabled(true);
}
void QobuzSettingsPage::LoginFailure(QString failure_reason) {
if (!this->isVisible()) return;
QMessageBox::warning(this, tr("Authentication failed"), failure_reason);
}

View File

@@ -0,0 +1,62 @@
/*
* Strawberry Music Player
* Copyright 2019, 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 QOBUZSETTINGSPAGE_H
#define QOBUZSETTINGSPAGE_H
#include <QObject>
#include <QString>
#include "settings/settingspage.h"
class QEvent;
class SettingsDialog;
class QobuzService;
class Ui_QobuzSettingsPage;
class QobuzSettingsPage : public SettingsPage {
Q_OBJECT
public:
explicit QobuzSettingsPage(SettingsDialog* parent = nullptr);
~QobuzSettingsPage();
static const char *kSettingsGroup;
void Load();
void Save();
bool eventFilter(QObject *object, QEvent *event);
signals:
void Login();
void Login(const QString &username, const QString &password, const QString &token);
private slots:
void LoginClicked();
void LogoutClicked();
void LoginSuccess();
void LoginFailure(QString failure_reason);
private:
Ui_QobuzSettingsPage* ui_;
QobuzService *service_;
};
#endif

View File

@@ -0,0 +1,306 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QobuzSettingsPage</class>
<widget class="QWidget" name="QobuzSettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>472</width>
<height>697</height>
</rect>
</property>
<property name="windowTitle">
<string>Qobuz</string>
</property>
<layout class="QVBoxLayout" name="layout_qobuzsettingspage">
<item>
<widget class="QCheckBox" name="enable">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_warning">
<property name="text">
<string>Qobuz support is not official and requires an API app ID and secret from a registered application to work. We can't help you getting these.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="margin">
<number>10</number>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="credential_group">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Authentication</string>
</property>
<layout class="QFormLayout" name="layout_credential_group">
<item row="1" column="0">
<widget class="QLabel" name="label_app_id">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>App ID</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="app_id"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_username">
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="username"/>
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_password">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="password">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_app_secret">
<property name="text">
<string>App Secret</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="app_secret"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_login">
<property name="text">
<string>Login</string>
</property>
</widget>
</item>
<item>
<widget class="LoginStateWidget" name="login_state" native="true"/>
</item>
<item>
<widget class="QGroupBox" name="groupbox_preferences">
<property name="title">
<string>Preferences</string>
</property>
<layout class="QFormLayout" name="layout_preferences">
<item row="0" column="0">
<widget class="QLabel" name="label_format">
<property name="text">
<string>Audio format</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="format"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_searchdelay">
<property name="text">
<string>Search delay</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="searchdelay">
<property name="suffix">
<string>ms</string>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
<property name="singleStep">
<number>50</number>
</property>
<property name="value">
<number>1500</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_artistssearchlimit">
<property name="text">
<string>Artists search limit</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="artistssearchlimit">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>50</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_albumssearchlimit">
<property name="text">
<string>Albums search limit</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="albumssearchlimit">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>1000</number>
</property>
<property name="value">
<number>50</number>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_songssearchlimit">
<property name="text">
<string>Songs search limit</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="songssearchlimit">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>1000</number>
</property>
<property name="value">
<number>50</number>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="checkbox_download_album_covers">
<property name="text">
<string>Download album covers</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="spacer_middle">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>30</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="layout_bottom">
<item>
<spacer name="spacer_bottom">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_qobuz">
<property name="minimumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="pixmap">
<pixmap resource="../../data/icons.qrc">:/icons/64x64/qobuz.png</pixmap>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LoginStateWidget</class>
<extends>QWidget</extends>
<header>widgets/loginstatewidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>enable</tabstop>
<tabstop>app_id</tabstop>
<tabstop>app_secret</tabstop>
<tabstop>username</tabstop>
<tabstop>password</tabstop>
<tabstop>button_login</tabstop>
<tabstop>format</tabstop>
<tabstop>searchdelay</tabstop>
<tabstop>artistssearchlimit</tabstop>
<tabstop>albumssearchlimit</tabstop>
<tabstop>songssearchlimit</tabstop>
<tabstop>checkbox_download_album_covers</tabstop>
</tabstops>
<resources>
<include location="../../data/data.qrc"/>
<include location="../../data/icons.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -78,6 +78,9 @@
#ifdef HAVE_TIDAL
# include "tidalsettingspage.h"
#endif
#ifdef HAVE_QOBUZ
# include "qobuzsettingspage.h"
#endif
#include "ui_settingsdialog.h"
@@ -153,7 +156,7 @@ SettingsDialog::SettingsDialog(Application *app, OSDBase *osd, QMainWindow *main
AddPage(Page_Moodbar, new MoodbarSettingsPage(this), iface);
#endif
#if defined(HAVE_SUBSONIC) || defined(HAVE_TIDAL)
#if defined(HAVE_SUBSONIC) || defined(HAVE_TIDAL) || defined(HAVE_QOBUZ)
QTreeWidgetItem *streaming = AddCategory(tr("Streaming"));
#endif
@@ -163,6 +166,9 @@ SettingsDialog::SettingsDialog(Application *app, OSDBase *osd, QMainWindow *main
#ifdef HAVE_TIDAL
AddPage(Page_Tidal, new TidalSettingsPage(this), streaming);
#endif
#ifdef HAVE_QOBUZ
AddPage(Page_Qobuz, new QobuzSettingsPage(this), streaming);
#endif
// List box
connect(ui_->list, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), SLOT(CurrentItemChanged(QTreeWidgetItem*)));

View File

@@ -90,6 +90,7 @@ class SettingsDialog : public QDialog {
Page_Moodbar,
Page_Subsonic,
Page_Tidal,
Page_Qobuz,
};
enum Role {