251
src/settings/lyricssettingspage.cpp
Normal file
251
src/settings/lyricssettingspage.cpp
Normal file
@@ -0,0 +1,251 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2020, 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 <algorithm>
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QPalette>
|
||||
#include <QSettings>
|
||||
#include <QGroupBox>
|
||||
#include <QPushButton>
|
||||
#include <QListWidget>
|
||||
#include <QListWidgetItem>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "settingsdialog.h"
|
||||
#include "lyricssettingspage.h"
|
||||
#include "ui_lyricssettingspage.h"
|
||||
#include "core/application.h"
|
||||
#include "core/iconloader.h"
|
||||
#include "core/logging.h"
|
||||
#include "lyrics/lyricsproviders.h"
|
||||
#include "lyrics/geniuslyricsprovider.h"
|
||||
#include "widgets/loginstatewidget.h"
|
||||
|
||||
const char *LyricsSettingsPage::kSettingsGroup = "Lyrics";
|
||||
|
||||
LyricsSettingsPage::LyricsSettingsPage(SettingsDialog *parent) : SettingsPage(parent), ui_(new Ui::LyricsSettingsPage), provider_selected_(false) {
|
||||
|
||||
ui_->setupUi(this);
|
||||
setWindowIcon(IconLoader::Load("view-media-lyrics"));
|
||||
|
||||
connect(ui_->providers_up, SIGNAL(clicked()), SLOT(ProvidersMoveUp()));
|
||||
connect(ui_->providers_down, SIGNAL(clicked()), SLOT(ProvidersMoveDown()));
|
||||
connect(ui_->providers, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), SLOT(CurrentItemChanged(QListWidgetItem*, QListWidgetItem*)));
|
||||
connect(ui_->providers, SIGNAL(itemSelectionChanged()), SLOT(ItemSelectionChanged()));
|
||||
connect(ui_->providers, SIGNAL(itemChanged(QListWidgetItem*)), SLOT(ItemChanged(QListWidgetItem*)));
|
||||
|
||||
connect(ui_->button_authenticate, SIGNAL(clicked()), SLOT(AuthenticateClicked()));
|
||||
connect(ui_->login_state, SIGNAL(LogoutClicked()), SLOT(LogoutClicked()));
|
||||
|
||||
NoProviderSelected();
|
||||
DisableAuthentication();
|
||||
|
||||
dialog()->installEventFilter(this);
|
||||
|
||||
}
|
||||
|
||||
LyricsSettingsPage::~LyricsSettingsPage() { delete ui_; }
|
||||
|
||||
void LyricsSettingsPage::Load() {
|
||||
|
||||
ui_->providers->clear();
|
||||
|
||||
QList<LyricsProvider*> lyrics_providers_sorted = dialog()->app()->lyrics_providers()->List();
|
||||
std::stable_sort(lyrics_providers_sorted.begin(), lyrics_providers_sorted.end(), ProviderCompareOrder);
|
||||
|
||||
for (LyricsProvider *provider : lyrics_providers_sorted) {
|
||||
QListWidgetItem *item = new QListWidgetItem(ui_->providers);
|
||||
item->setText(provider->name());
|
||||
item->setCheckState(provider->is_enabled() ? Qt::Checked : Qt::Unchecked);
|
||||
item->setForeground(provider->is_enabled() ? palette().color(QPalette::Active, QPalette::Text) : palette().color(QPalette::Disabled, QPalette::Text));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LyricsSettingsPage::Save() {
|
||||
|
||||
QStringList providers;
|
||||
for (int i = 0 ; i < ui_->providers->count() ; ++i) {
|
||||
const QListWidgetItem *item = ui_->providers->item(i);
|
||||
if (item->checkState() == Qt::Checked) providers << item->text();
|
||||
}
|
||||
|
||||
qLog(Debug) << providers;
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue("providers", providers);
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
|
||||
void LyricsSettingsPage::CurrentItemChanged(QListWidgetItem *item_current, QListWidgetItem *item_previous) {
|
||||
|
||||
if (item_previous) {
|
||||
LyricsProvider *provider = dialog()->app()->lyrics_providers()->ProviderByName(item_previous->text());
|
||||
if (provider && provider->AuthenticationRequired()) DisconnectAuthentication(provider);
|
||||
}
|
||||
|
||||
if (item_current) {
|
||||
const int row = ui_->providers->row(item_current);
|
||||
ui_->providers_up->setEnabled(row != 0);
|
||||
ui_->providers_down->setEnabled(row != ui_->providers->count() - 1);
|
||||
LyricsProvider *provider = dialog()->app()->lyrics_providers()->ProviderByName(item_current->text());
|
||||
if (provider && provider->AuthenticationRequired()) {
|
||||
ui_->login_state->SetLoggedIn(provider->IsAuthenticated() ? LoginStateWidget::LoggedIn : LoginStateWidget::LoggedOut);
|
||||
ui_->button_authenticate->setEnabled(true);
|
||||
ui_->button_authenticate->show();
|
||||
ui_->login_state->show();
|
||||
ui_->label_auth_info->setText(QString("%1 needs authentication.").arg(provider->name()));
|
||||
}
|
||||
else {
|
||||
DisableAuthentication();
|
||||
ui_->label_auth_info->setText(QString("%1 does not need authentication.").arg(provider->name()));
|
||||
}
|
||||
provider_selected_ = true;
|
||||
}
|
||||
else {
|
||||
DisableAuthentication();
|
||||
NoProviderSelected();
|
||||
ui_->providers_up->setEnabled(false);
|
||||
ui_->providers_down->setEnabled(false);
|
||||
provider_selected_ = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LyricsSettingsPage::ItemSelectionChanged() {
|
||||
|
||||
if (ui_->providers->selectedItems().count() == 0) {
|
||||
DisableAuthentication();
|
||||
NoProviderSelected();
|
||||
ui_->providers_up->setEnabled(false);
|
||||
ui_->providers_down->setEnabled(false);
|
||||
provider_selected_ = false;
|
||||
}
|
||||
else {
|
||||
if (ui_->providers->currentItem() && !provider_selected_) {
|
||||
CurrentItemChanged(ui_->providers->currentItem(), nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LyricsSettingsPage::ProvidersMoveUp() { ProvidersMove(-1); }
|
||||
|
||||
void LyricsSettingsPage::ProvidersMoveDown() { ProvidersMove(+1); }
|
||||
|
||||
void LyricsSettingsPage::ProvidersMove(const int d) {
|
||||
|
||||
const int row = ui_->providers->currentRow();
|
||||
QListWidgetItem *item = ui_->providers->takeItem(row);
|
||||
ui_->providers->insertItem(row + d, item);
|
||||
ui_->providers->setCurrentRow(row + d);
|
||||
|
||||
}
|
||||
|
||||
void LyricsSettingsPage::ItemChanged(QListWidgetItem *item) {
|
||||
|
||||
item->setForeground((item->checkState() == Qt::Checked) ? palette().color(QPalette::Active, QPalette::Text) : palette().color(QPalette::Disabled, QPalette::Text));
|
||||
|
||||
}
|
||||
|
||||
void LyricsSettingsPage::NoProviderSelected() {
|
||||
ui_->label_auth_info->setText(tr("No provider selected."));
|
||||
}
|
||||
|
||||
void LyricsSettingsPage::DisableAuthentication() {
|
||||
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut);
|
||||
ui_->button_authenticate->setEnabled(false);
|
||||
ui_->login_state->hide();
|
||||
ui_->button_authenticate->hide();
|
||||
|
||||
}
|
||||
|
||||
void LyricsSettingsPage::DisconnectAuthentication(LyricsProvider *provider) {
|
||||
|
||||
disconnect(provider, SIGNAL(AuthenticationFailure(QStringList)), this, SLOT(AuthenticationFailure(QStringList)));
|
||||
disconnect(provider, SIGNAL(AuthenticationSuccess()), this, SLOT(AuthenticationSuccess()));
|
||||
|
||||
}
|
||||
|
||||
void LyricsSettingsPage::AuthenticateClicked() {
|
||||
|
||||
if (!ui_->providers->currentItem()) return;
|
||||
LyricsProvider *provider = dialog()->app()->lyrics_providers()->ProviderByName(ui_->providers->currentItem()->text());
|
||||
if (!provider) return;
|
||||
ui_->button_authenticate->setEnabled(false);
|
||||
connect(provider, SIGNAL(AuthenticationFailure(QStringList)), this, SLOT(AuthenticationFailure(QStringList)));
|
||||
connect(provider, SIGNAL(AuthenticationSuccess()), this, SLOT(AuthenticationSuccess()));
|
||||
provider->Authenticate();
|
||||
|
||||
}
|
||||
|
||||
void LyricsSettingsPage::LogoutClicked() {
|
||||
|
||||
if (!ui_->providers->currentItem()) return;
|
||||
LyricsProvider *provider = dialog()->app()->lyrics_providers()->ProviderByName(ui_->providers->currentItem()->text());
|
||||
if (!provider) return;
|
||||
provider->Deauthenticate();
|
||||
|
||||
ui_->button_authenticate->setEnabled(true);
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut);
|
||||
|
||||
}
|
||||
|
||||
void LyricsSettingsPage::AuthenticationSuccess() {
|
||||
|
||||
LyricsProvider *provider = qobject_cast<LyricsProvider*>(sender());
|
||||
if (!provider) return;
|
||||
DisconnectAuthentication(provider);
|
||||
|
||||
if (!this->isVisible() || !ui_->providers->currentItem() || ui_->providers->currentItem()->text() != provider->name()) return;
|
||||
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn);
|
||||
ui_->button_authenticate->setEnabled(true);
|
||||
|
||||
}
|
||||
|
||||
void LyricsSettingsPage::AuthenticationFailure(const QStringList &errors) {
|
||||
|
||||
LyricsProvider *provider = qobject_cast<LyricsProvider*>(sender());
|
||||
if (!provider) return;
|
||||
DisconnectAuthentication(provider);
|
||||
|
||||
if (!this->isVisible() || !ui_->providers->currentItem() || ui_->providers->currentItem()->text() != provider->name()) return;
|
||||
|
||||
QMessageBox::warning(this, tr("Authentication failed"), errors.join("\n"));
|
||||
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut);
|
||||
ui_->button_authenticate->setEnabled(true);
|
||||
|
||||
}
|
||||
|
||||
bool LyricsSettingsPage::ProviderCompareOrder(LyricsProvider *a, LyricsProvider *b) {
|
||||
return a->order() < b->order();
|
||||
}
|
||||
72
src/settings/lyricssettingspage.h
Normal file
72
src/settings/lyricssettingspage.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2020, 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 LYRICSSETTINGSPAGE_H
|
||||
#define LYRICSSETTINGSPAGE_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include "settings/settingspage.h"
|
||||
|
||||
class QListWidgetItem;
|
||||
|
||||
class LyricsProvider;
|
||||
class SettingsDialog;
|
||||
class Ui_LyricsSettingsPage;
|
||||
|
||||
class LyricsSettingsPage : public SettingsPage {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LyricsSettingsPage(SettingsDialog *parent = nullptr);
|
||||
~LyricsSettingsPage();
|
||||
|
||||
static const char *kSettingsGroup;
|
||||
|
||||
void Load();
|
||||
void Save();
|
||||
|
||||
private:
|
||||
void NoProviderSelected();
|
||||
void ProvidersMove(const int d);
|
||||
void DisableAuthentication();
|
||||
void DisconnectAuthentication(LyricsProvider *provider);
|
||||
static bool ProviderCompareOrder(LyricsProvider *a, LyricsProvider *b);
|
||||
|
||||
private slots:
|
||||
void CurrentItemChanged(QListWidgetItem *item_current, QListWidgetItem *item_previous);
|
||||
void ItemSelectionChanged();
|
||||
void ItemChanged(QListWidgetItem *item);
|
||||
void ProvidersMoveUp();
|
||||
void ProvidersMoveDown();
|
||||
void AuthenticateClicked();
|
||||
void LogoutClicked();
|
||||
void AuthenticationSuccess();
|
||||
void AuthenticationFailure(const QStringList &errors);
|
||||
|
||||
private:
|
||||
Ui_LyricsSettingsPage *ui_;
|
||||
bool provider_selected_;
|
||||
};
|
||||
|
||||
#endif // LYRICSSETTINGSPAGE_H
|
||||
166
src/settings/lyricssettingspage.ui
Normal file
166
src/settings/lyricssettingspage.ui
Normal file
@@ -0,0 +1,166 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>LyricsSettingsPage</class>
|
||||
<widget class="QWidget" name="LyricsSettingsPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>460</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Lyrics</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="layout_tidalsettingspage">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupbox_providers">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Lyrics providers</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_15">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_enabled">
|
||||
<property name="text">
|
||||
<string>Choose the providers you want to use when searching for lyrics.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_providers">
|
||||
<item>
|
||||
<widget class="QListWidget" name="providers"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="layout_providers_updown">
|
||||
<item>
|
||||
<widget class="QPushButton" name="providers_up">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Move up</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="providers_down">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Move down</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="spacer_providers_updown">
|
||||
<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>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="authentication">
|
||||
<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="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_auth_info">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="LoginStateWidget" name="login_state" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_button_authenticate">
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_authenticate">
|
||||
<property name="text">
|
||||
<string>Authenticate</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="spacer_button_authenticate">
|
||||
<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>
|
||||
<item>
|
||||
<spacer name="spacer_bottom">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>30</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>
|
||||
<include location="../../data/data.qrc"/>
|
||||
<include location="../../data/icons.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -56,17 +56,18 @@
|
||||
|
||||
#include "settingsdialog.h"
|
||||
#include "settingspage.h"
|
||||
#include "appearancesettingspage.h"
|
||||
#include "backendsettingspage.h"
|
||||
#include "behavioursettingspage.h"
|
||||
#include "contextsettingspage.h"
|
||||
#include "collectionsettingspage.h"
|
||||
#include "notificationssettingspage.h"
|
||||
#include "backendsettingspage.h"
|
||||
#include "playlistsettingspage.h"
|
||||
#include "appearancesettingspage.h"
|
||||
#include "contextsettingspage.h"
|
||||
#include "scrobblersettingspage.h"
|
||||
#include "notificationssettingspage.h"
|
||||
#include "shortcutssettingspage.h"
|
||||
#include "transcodersettingspage.h"
|
||||
#include "networkproxysettingspage.h"
|
||||
#include "scrobblersettingspage.h"
|
||||
#include "lyricssettingspage.h"
|
||||
#ifdef HAVE_MOODBAR
|
||||
# include "moodbarsettingspage.h"
|
||||
#endif
|
||||
@@ -138,6 +139,7 @@ SettingsDialog::SettingsDialog(Application *app, QMainWindow *mainwindow, QWidge
|
||||
QTreeWidgetItem *iface = AddCategory(tr("User interface"));
|
||||
AddPage(Page_Appearance, new AppearanceSettingsPage(this), iface);
|
||||
AddPage(Page_Context, new ContextSettingsPage(this), iface);
|
||||
AddPage(Page_Lyrics, new LyricsSettingsPage(this), iface);
|
||||
AddPage(Page_Notifications, new NotificationsSettingsPage(this), iface);
|
||||
|
||||
#ifdef HAVE_GLOBALSHORTCUTS
|
||||
|
||||
@@ -81,6 +81,7 @@ class SettingsDialog : public QDialog {
|
||||
Page_GlobalShortcuts,
|
||||
Page_Appearance,
|
||||
Page_Context,
|
||||
Page_Lyrics,
|
||||
Page_Notifications,
|
||||
Page_Transcoding,
|
||||
Page_Proxy,
|
||||
|
||||
Reference in New Issue
Block a user