Add tidal support

This commit is contained in:
Jonas Kvinge
2018-08-09 18:10:03 +02:00
parent 26062bd07b
commit 820124f9e1
74 changed files with 5420 additions and 273 deletions

View File

@@ -15,7 +15,7 @@
*
* 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"

View File

@@ -15,7 +15,7 @@
*
* 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"
@@ -62,6 +62,8 @@
#include "playlistsettingspage.h"
#include "shortcutssettingspage.h"
#include "transcodersettingspage.h"
#include "tidalsettingspage.h"
#include "ui_settingsdialog.h"
class QShowEvent;
@@ -122,6 +124,7 @@ SettingsDialog::SettingsDialog(Application *app, QWidget *parent)
#ifdef HAVE_GSTREAMER
AddPage(Page_Transcoding, new TranscoderSettingsPage(this), general);
#endif
AddPage(Page_Tidal, new TidalSettingsPage(this), general);
// User interface
QTreeWidgetItem *iface = AddCategory(tr("User interface"));

View File

@@ -15,7 +15,7 @@
*
* You should have received a copy of the GNU General Public License
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
#ifndef SETTINGSDIALOG_H
@@ -79,6 +79,7 @@ public:
Page_Notifications,
Page_Proxy,
Page_Transcoding,
Page_Tidal,
};
enum Role {

View File

@@ -0,0 +1,118 @@
/*
* 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 "tidalsettingspage.h"
#include "ui_tidalsettingspage.h"
#include "core/application.h"
#include "core/iconloader.h"
#include "internet/internetmodel.h"
#include "tidal/tidalservice.h"
const char *TidalSettingsPage::kSettingsGroup = "Tidal";
TidalSettingsPage::TidalSettingsPage(SettingsDialog *parent)
: SettingsPage(parent),
ui_(new Ui::TidalSettingsPage),
service_(dialog()->app()->internet_model()->Service<TidalService>()) {
ui_->setupUi(this);
setWindowIcon(IconLoader::Load("tidal"));
connect(ui_->button_login, SIGNAL(clicked()), SLOT(LoginClicked()));
connect(ui_->login_state, SIGNAL(LogoutClicked()), SLOT(LogoutClicked()));
connect(service_, SIGNAL(LoginFailure(QString)), SLOT(LoginFailure(QString)));
connect(service_, SIGNAL(LoginSuccess()), SLOT(LoginSuccess()));
dialog()->installEventFilter(this);
ui_->combobox_quality->addItem("Low", "LOW");
ui_->combobox_quality->addItem("High", "HIGH");
ui_->combobox_quality->addItem("Lossless", "LOSSLESS");
}
TidalSettingsPage::~TidalSettingsPage() { delete ui_; }
void TidalSettingsPage::Load() {
QSettings s;
s.beginGroup(kSettingsGroup);
ui_->username->setText(s.value("username").toString());
ui_->password->setText(s.value("password").toString());
QString quality = s.value("quality", "HIGH").toString();
ui_->combobox_quality->setCurrentIndex(ui_->combobox_quality->findData(quality));
s.endGroup();
if (service_->authenticated()) ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn);
}
void TidalSettingsPage::Save() {
QSettings s;
s.beginGroup(kSettingsGroup);
s.setValue("username", ui_->username->text());
s.setValue("password", ui_->password->text());
s.setValue("quality", ui_->combobox_quality->itemData(ui_->combobox_quality->currentIndex()));
s.endGroup();
service_->ReloadSettings();
}
void TidalSettingsPage::LoginClicked() {
service_->Login(ui_->username->text(), ui_->password->text());
ui_->button_login->setEnabled(false);
}
bool TidalSettingsPage::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 TidalSettingsPage::LogoutClicked() {
service_->Logout();
ui_->button_login->setEnabled(true);
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut);
}
void TidalSettingsPage::LoginSuccess() {
if (!this->isVisible()) return;
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn);
ui_->button_login->setEnabled(false);
}
void TidalSettingsPage::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 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 TIDALSETTINGSPAGE_H
#define TIDALSETTINGSPAGE_H
#include <QObject>
#include <QString>
#include <QEvent>
#include "settings/settingspage.h"
class TidalService;
class Ui_TidalSettingsPage;
class TidalSettingsPage : public SettingsPage {
Q_OBJECT
public:
explicit TidalSettingsPage(SettingsDialog* parent = nullptr);
~TidalSettingsPage();
enum SearchBy {
SearchBy_Songs = 1,
SearchBy_Albums = 2,
};
static const char *kSettingsGroup;
void Load();
void Save();
bool eventFilter(QObject *object, QEvent *event);
private slots:
void LoginClicked();
void LogoutClicked();
void LoginSuccess();
void LoginFailure(QString failure_reason);
private:
Ui_TidalSettingsPage* ui_;
TidalService *service_;
};
#endif

View File

@@ -0,0 +1,157 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TidalSettingsPage</class>
<widget class="QWidget" name="TidalSettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>715</width>
<height>425</height>
</rect>
</property>
<property name="windowTitle">
<string>Tidal</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="LoginStateWidget" name="login_state" native="true"/>
</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>Account details</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_username">
<property name="text">
<string>Tidal username</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="username"/>
</item>
<item>
<widget class="QPushButton" name="button_login">
<property name="text">
<string>Login</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_password">
<property name="text">
<string>Tidal password</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="password">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupbox_pref">
<property name="title">
<string>Preferences</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_quality">
<property name="text">
<string>Audio quality</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="combobox_quality"/>
</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_tidal">
<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/data.qrc">:/icons/64x64/tidal.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>
<tabstop>button_login</tabstop>
</tabstops>
<resources>
<include location="../../data/data.qrc"/>
</resources>
<connections/>
</ui>