Add Qobuz support (#181)

This commit is contained in:
Jonas Kvinge
2019-06-19 02:22:11 +02:00
committed by GitHub
parent dbd2edf442
commit 89252d0dba
44 changed files with 4428 additions and 22 deletions

View File

@@ -0,0 +1,152 @@
/*
* 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 <QString>
#include <QSettings>
#include <QMessageBox>
#include <QEvent>
#include "qobuzsettingspage.h"
#include "ui_qobuzsettingspage.h"
#include "core/application.h"
#include "core/iconloader.h"
#include "internet/internetservices.h"
#include "qobuz/qobuzservice.h"
#include "qobuz/qobuzstreamurlrequest.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", 5).toInt());
ui_->albumssearchlimit->setValue(s.value("albumssearchlimit", 100).toInt());
ui_->songssearchlimit->setValue(s.value("songssearchlimit", 100).toInt());
ui_->checkbox_cache_album_covers->setChecked(s.value("cachealbumcovers", true).toBool());
s.endGroup();
if (service_->authenticated()) ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn);
}
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("cachealbumcovers", ui_->checkbox_cache_album_covers->isChecked());
s.endGroup();
service_->ReloadSettings();
}
void QobuzSettingsPage::LoginClicked() {
if (ui_->app_id->text().isEmpty() || ui_->username->text().isEmpty() || ui_->password->text().isEmpty()) {
QMessageBox::critical(this, tr("Configuration incomplete"), tr("Missing app id, username or 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_->button_login->setEnabled(true);
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut);
}
void QobuzSettingsPage::LoginSuccess() {
if (!this->isVisible()) return;
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn);
ui_->button_login->setEnabled(false);
}
void QobuzSettingsPage::LoginFailure(QString failure_reason) {
if (!this->isVisible()) return;
QMessageBox::warning(this, tr("Authentication failed"), failure_reason);
}

View File

@@ -0,0 +1,61 @@
/*
* 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 <QEvent>
#include "settings/settingspage.h"
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,297 @@
<?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>715</width>
<height>836</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="Line" name="line_1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</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="0" 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="0" column="1">
<widget class="QLineEdit" name="app_id"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_username">
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="username"/>
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_password">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="password">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_app_secret">
<property name="text">
<string>App Secret</string>
</property>
</widget>
</item>
<item row="1" 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="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</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_cache_album_covers">
<property name="text">
<string>Cache 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>username</tabstop>
<tabstop>password</tabstop>
</tabstops>
<resources>
<include location="../../data/data.qrc"/>
<include location="../../data/icons.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -62,11 +62,14 @@
#include "transcodersettingspage.h"
#include "networkproxysettingspage.h"
#include "scrobblersettingspage.h"
#ifdef HAVE_MOODBAR
# include "moodbarsettingspage.h"
#endif
#ifdef HAVE_TIDAL
# include "tidalsettingspage.h"
#endif
#ifdef HAVE_MOODBAR
# include "moodbarsettingspage.h"
#ifdef HAVE_QOBUZ
# include "qobuzsettingspage.h"
#endif
#ifdef HAVE_SUBSONIC
# include "subsonicsettingspage.h"
@@ -143,12 +146,15 @@ SettingsDialog::SettingsDialog(Application *app, QWidget *parent)
AddPage(Page_Moodbar, new MoodbarSettingsPage(this), iface);
#endif
#if defined(HAVE_TIDAL) || defined(HAVE_SUBSONIC)
#if defined(HAVE_TIDAL) || defined(HAVE_SUBSONIC) || defined(HAVE_QOBUZ)
QTreeWidgetItem *streaming = AddCategory(tr("Streaming"));
#endif
#ifdef HAVE_TIDAL
AddPage(Page_Tidal, new TidalSettingsPage(this), streaming);
#endif
#ifdef HAVE_QOBUZ
AddPage(Page_Qobuz, new QobuzSettingsPage(this), streaming);
#endif
#ifdef HAVE_SUBSONIC
AddPage(Page_Subsonic, new SubsonicSettingsPage(this), streaming);
#endif
@@ -320,9 +326,20 @@ void SettingsDialog::CurrentItemChanged(QTreeWidgetItem *item) {
}
void SettingsDialog::ComboBoxLoadFromSettings(QSettings &s, QComboBox *combobox, QString setting, QString default_value) {
void SettingsDialog::ComboBoxLoadFromSettings(const QSettings &s, QComboBox *combobox, const QString &setting, const QString &default_value) {
QString value = s.value(setting, default_value).toString();
int i = combobox->findData(value);
if (i == -1) i = combobox->findData(default_value);
combobox->setCurrentIndex(i);
}
void SettingsDialog::ComboBoxLoadFromSettings(const QSettings &s, QComboBox *combobox, const QString &setting, const int default_value) {
int value = s.value(setting, default_value).toInt();
int i = combobox->findData(value);
if (i == -1) i = combobox->findData(default_value);
combobox->setCurrentIndex(i);
}

View File

@@ -82,9 +82,10 @@ class SettingsDialog : public QDialog {
Page_Transcoding,
Page_Proxy,
Page_Scrobbler,
Page_Moodbar,
Page_Tidal,
Page_Subsonic,
Page_Moodbar,
Page_Qobuz,
};
enum Role {
@@ -111,7 +112,8 @@ class SettingsDialog : public QDialog {
// QWidget
void showEvent(QShowEvent *e);
void ComboBoxLoadFromSettings(QSettings &s, QComboBox *combobox, QString setting, QString default_value);
void ComboBoxLoadFromSettings(const QSettings &s, QComboBox *combobox, const QString &setting, const QString &default_value);
void ComboBoxLoadFromSettings(const QSettings &s, QComboBox *combobox, const QString &setting, const int default_value);
signals:
void ReloadSettings();