Add Deezer support

This commit is contained in:
Jonas Kvinge
2018-10-14 00:08:33 +02:00
parent 4aad44cb62
commit 0a81fa99fc
78 changed files with 5309 additions and 630 deletions

View File

@@ -96,6 +96,9 @@ void BackendSettingsPage::Load() {
#ifdef HAVE_PHONON
ui_->combobox_engine->addItem(IconLoader::Load("speaker"), EngineDescription(Engine::Phonon), Engine::Phonon);
#endif
#ifdef HAVE_DEEZER
ui_->combobox_engine->addItem(IconLoader::Load("deezer"), EngineDescription(Engine::Deezer), Engine::Deezer);
#endif
enginetype_current_ = enginetype;
output_current_ = s_.value("output", "").toString();

View File

@@ -0,0 +1,142 @@
/*
* 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 "config.h"
#include <QObject>
#include <QString>
#include <QSettings>
#include <QMessageBox>
#include <QEvent>
#include "deezersettingspage.h"
#include "ui_deezersettingspage.h"
#include "core/application.h"
#include "core/iconloader.h"
#include "internet/internetmodel.h"
#include "deezer/deezerservice.h"
const char *DeezerSettingsPage::kSettingsGroup = "Deezer";
DeezerSettingsPage::DeezerSettingsPage(SettingsDialog *parent)
: SettingsPage(parent),
ui_(new Ui::DeezerSettingsPage),
service_(dialog()->app()->internet_model()->Service<DeezerService>()) {
ui_->setupUi(this);
setWindowIcon(IconLoader::Load("deezer"));
connect(ui_->button_login, SIGNAL(clicked()), SLOT(LoginClicked()));
connect(ui_->login_state, SIGNAL(LogoutClicked()), SLOT(LogoutClicked()));
connect(this, SIGNAL(Login()), service_, SLOT(StartAuthorisation()));
connect(service_, SIGNAL(LoginFailure(QString)), SLOT(LoginFailure(QString)));
connect(service_, SIGNAL(LoginSuccess()), SLOT(LoginSuccess()));
dialog()->installEventFilter(this);
ui_->combobox_quality->addItem("AAC (64)", "AAC_64");
ui_->combobox_quality->addItem("MP3 (64)", "MP3_64");
ui_->combobox_quality->addItem("MP3 (128)", "MP3_128");
ui_->combobox_quality->addItem("MP3 (256)", "MP3_256");
ui_->combobox_quality->addItem("MP3 (320)", "MP3_320");
ui_->combobox_quality->addItem("FLAC", "FLAC");
ui_->combobox_coversize->addItem("Small", "cover_small");
ui_->combobox_coversize->addItem("Medium", "cover_medium");
ui_->combobox_coversize->addItem("Big", "cover_big");
ui_->combobox_coversize->addItem("XL", "cover_xl");
}
DeezerSettingsPage::~DeezerSettingsPage() { delete ui_; }
void DeezerSettingsPage::Load() {
QSettings s;
s.beginGroup(kSettingsGroup);
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_->combobox_quality, "quality", "FLAC");
ui_->spinbox_searchdelay->setValue(s.value("searchdelay", 1500).toInt());
ui_->spinbox_albumssearchlimit->setValue(s.value("albumssearchlimit", 100).toInt());
ui_->spinbox_songssearchlimit->setValue(s.value("songssearchlimit", 100).toInt());
ui_->checkbox_fetchalbums->setChecked(s.value("fetchalbums", false).toBool());
dialog()->ComboBoxLoadFromSettings(s, ui_->combobox_coversize, "coversize", "cover_big");
ui_->checkbox_preview->setChecked(s.value("preview", false).toBool());
s.endGroup();
if (service_->authenticated()) ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn);
}
void DeezerSettingsPage::Save() {
QSettings s;
s.beginGroup(kSettingsGroup);
s.setValue("username", ui_->username->text());
s.setValue("password", QString::fromUtf8(ui_->password->text().toUtf8().toBase64()));
s.setValue("quality", ui_->combobox_quality->itemData(ui_->combobox_quality->currentIndex()));
s.setValue("searchdelay", ui_->spinbox_searchdelay->value());
s.setValue("albumssearchlimit", ui_->spinbox_albumssearchlimit->value());
s.setValue("songssearchlimit", ui_->spinbox_songssearchlimit->value());
s.setValue("fetchalbums", ui_->checkbox_fetchalbums->isChecked());
s.setValue("coversize", ui_->combobox_coversize->itemData(ui_->combobox_coversize->currentIndex()));
s.setValue("preview", ui_->checkbox_preview->isChecked());
s.endGroup();
service_->ReloadSettings();
}
void DeezerSettingsPage::LoginClicked() {
emit Login();
ui_->button_login->setEnabled(false);
}
bool DeezerSettingsPage::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 DeezerSettingsPage::LogoutClicked() {
service_->Logout();
ui_->button_login->setEnabled(true);
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut);
}
void DeezerSettingsPage::LoginSuccess() {
if (!this->isVisible()) return;
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn);
ui_->button_login->setEnabled(false);
}
void DeezerSettingsPage::LoginFailure(QString failure_reason) {
if (!this->isVisible()) return;
QMessageBox::warning(this, tr("Authentication failed"), failure_reason);
}

View File

@@ -0,0 +1,66 @@
/*
* 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 DEEZERSETTINGSPAGE_H
#define DEEZERSETTINGSPAGE_H
#include <QObject>
#include <QString>
#include <QEvent>
#include "settings/settingspage.h"
class DeezerService;
class Ui_DeezerSettingsPage;
class DeezerSettingsPage : public SettingsPage {
Q_OBJECT
public:
explicit DeezerSettingsPage(SettingsDialog* parent = nullptr);
~DeezerSettingsPage();
enum SearchBy {
SearchBy_Songs = 1,
SearchBy_Albums = 2,
};
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);
private slots:
void LoginClicked();
void LogoutClicked();
void LoginSuccess();
void LoginFailure(QString failure_reason);
private:
Ui_DeezerSettingsPage* ui_;
DeezerService *service_;
};
#endif

View File

@@ -0,0 +1,417 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DeezerSettingsPage</class>
<widget class="QWidget" name="DeezerSettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>715</width>
<height>547</height>
</rect>
</property>
<property name="windowTitle">
<string>Deezer</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<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="formLayout">
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QPushButton" name="button_login">
<property name="text">
<string>Login</string>
</property>
</widget>
</item>
<item>
<spacer name="spacer_auth">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="layout_username">
<item>
<widget class="QLabel" name="label_username">
<property name="minimumSize">
<size>
<width>70</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="username"/>
</item>
<item>
<spacer name="spacer_username">
<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>
<item>
<layout class="QHBoxLayout" name="layout_password">
<item>
<widget class="QLabel" name="label_password">
<property name="minimumSize">
<size>
<width>70</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="password">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item>
<spacer name="spacer_password">
<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>
<item>
<widget class="LoginStateWidget" name="login_state" native="true"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupbox_preferences">
<property name="title">
<string>Preferences</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_quality">
<item>
<widget class="QLabel" name="label_quality">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Audio quality</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="combobox_quality"/>
</item>
<item>
<spacer name="spacer_quality">
<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>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_searchdelay">
<item>
<widget class="QLabel" name="label_searchdelay">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Search delay</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinbox_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>
<spacer name="spacer_searchdelay">
<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>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_albumssearchlimit">
<item>
<widget class="QLabel" name="label_albumssearchlimit">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Albums search limit</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinbox_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>
<spacer name="spacer_albumssearchlimit">
<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>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_songssearchlimit">
<item>
<widget class="QLabel" name="label_songssearchlimit">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Songs search limit</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinbox_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>
<spacer name="spacer_songssearchlimit">
<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>
<item>
<widget class="QCheckBox" name="checkbox_fetchalbums">
<property name="text">
<string>Fetch entire albums when searching songs</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_coversize">
<item>
<widget class="QLabel" name="label_coversize">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Album cover size</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="combobox_coversize"/>
</item>
<item>
<spacer name="spacer_coversize">
<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>
<item>
<widget class="QCheckBox" name="checkbox_preview">
<property name="text">
<string>Use 30 seconds preview streams</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="horizontalLayout_3">
<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_deezer">
<property name="minimumSize">
<size>
<width>200</width>
<height>62</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>62</height>
</size>
</property>
<property name="pixmap">
<pixmap resource="../../data/data.qrc">:/pictures/deezer.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>
<resources>
<include location="../../data/data.qrc"/>
<include location="../../data/icons.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -63,6 +63,7 @@
#include "shortcutssettingspage.h"
#include "transcodersettingspage.h"
#include "tidalsettingspage.h"
#include "deezersettingspage.h"
#include "ui_settingsdialog.h"
@@ -114,7 +115,6 @@ SettingsDialog::SettingsDialog(Application *app, QWidget *parent)
ui_->list->setItemDelegate(new SettingsItemDelegate(this));
QTreeWidgetItem *general = AddCategory(tr("General"));
AddPage(Page_Behaviour, new BehaviourSettingsPage(this), general);
AddPage(Page_Collection, new CollectionSettingsPage(this), general);
AddPage(Page_Backend, new BackendSettingsPage(this), general);
@@ -124,7 +124,10 @@ SettingsDialog::SettingsDialog(Application *app, QWidget *parent)
#ifdef HAVE_GSTREAMER
AddPage(Page_Transcoding, new TranscoderSettingsPage(this), general);
#endif
AddPage(Page_Tidal, new TidalSettingsPage(this), general);
QTreeWidgetItem *internet = AddCategory(tr("Internet"));
AddPage(Page_Tidal, new TidalSettingsPage(this), internet);
AddPage(Page_Deezer, new DeezerSettingsPage(this), internet);
// User interface
QTreeWidgetItem *iface = AddCategory(tr("User interface"));

View File

@@ -82,6 +82,7 @@ public:
Page_Proxy,
Page_Transcoding,
Page_Tidal,
Page_Deezer,
};
enum Role {

View File

@@ -14,7 +14,7 @@
<string>Settings</string>
</property>
<property name="windowIcon">
<iconset resource="../../data/data.qrc">
<iconset resource="../../data/icons.qrc">
<normaloff>:/icons/64x64/strawberry.png</normaloff>:/icons/64x64/strawberry.png</iconset>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
@@ -97,6 +97,7 @@
</tabstops>
<resources>
<include location="../../data/data.qrc"/>
<include location="../../data/icons.qrc"/>
</resources>
<connections>
<connection>

View File

@@ -14,7 +14,7 @@
<string>Shortcuts</string>
</property>
<property name="windowIcon">
<iconset resource="../../data/data.qrc">
<iconset resource="../../data/icons.qrc">
<normaloff>:/icons/64x64/strawberry.png</normaloff>:/icons/64x64/strawberry.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@@ -212,6 +212,7 @@
</tabstops>
<resources>
<include location="../../data/data.qrc"/>
<include location="../../data/icons.qrc"/>
</resources>
<connections>
<connection>

View File

@@ -76,7 +76,7 @@ void TidalSettingsPage::Load() {
s.beginGroup(kSettingsGroup);
ui_->username->setText(s.value("username").toString());
QByteArray password = s.value("password").toByteArray();
if (password.isEmpty()) ui_->password->setText("");
if (password.isEmpty()) ui_->password->clear();
else ui_->password->setText(QString::fromUtf8(QByteArray::fromBase64(password)));
dialog()->ComboBoxLoadFromSettings(s, ui_->combobox_quality, "quality", "HIGH");
ui_->spinbox_searchdelay->setValue(s.value("searchdelay", 1500).toInt());

View File

@@ -360,7 +360,7 @@
</size>
</property>
<property name="pixmap">
<pixmap resource="../../data/data.qrc">:/icons/64x64/tidal.png</pixmap>
<pixmap resource="../../data/icons.qrc">:/icons/64x64/tidal.png</pixmap>
</property>
</widget>
</item>
@@ -383,6 +383,7 @@
</tabstops>
<resources>
<include location="../../data/data.qrc"/>
<include location="../../data/icons.qrc"/>
</resources>
<connections/>
</ui>