Add Dropbox
This commit is contained in:
144
src/settings/dropboxsettingspage.cpp
Normal file
144
src/settings/dropboxsettingspage.cpp
Normal file
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, 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 <QObject>
|
||||
#include <QVariant>
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QSettings>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QSpinBox>
|
||||
#include <QMessageBox>
|
||||
#include <QEvent>
|
||||
|
||||
#include "constants/dropboxsettings.h"
|
||||
#include "core/settings.h"
|
||||
#include "core/iconloader.h"
|
||||
#include "widgets/loginstatewidget.h"
|
||||
#include "dropbox/dropboxservice.h"
|
||||
#include "settingsdialog.h"
|
||||
#include "dropboxsettingspage.h"
|
||||
#include "ui_dropboxsettingspage.h"
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
using namespace DropboxSettings;
|
||||
|
||||
DropboxSettingsPage::DropboxSettingsPage(SettingsDialog *dialog, const SharedPtr<DropboxService> service, QWidget *parent)
|
||||
: SettingsPage(dialog, parent),
|
||||
ui_(new Ui_DropboxSettingsPage),
|
||||
service_(service) {
|
||||
|
||||
Q_ASSERT(service);
|
||||
|
||||
ui_->setupUi(this);
|
||||
|
||||
setWindowIcon(IconLoader::Load(u"dropbox"_s));
|
||||
|
||||
ui_->login_state->AddCredentialGroup(ui_->widget_authorization);
|
||||
|
||||
QObject::connect(ui_->button_login, &QPushButton::clicked, this, &DropboxSettingsPage::LoginClicked);
|
||||
QObject::connect(ui_->button_reset, &QPushButton::clicked, this, &DropboxSettingsPage::ResetClicked);
|
||||
QObject::connect(ui_->login_state, &LoginStateWidget::LogoutClicked, this, &DropboxSettingsPage::LogoutClicked);
|
||||
|
||||
QObject::connect(this, &DropboxSettingsPage::Authorize, &*service_, &DropboxService::Authenticate);
|
||||
QObject::connect(&*service_, &StreamingService::LoginFailure, this, &DropboxSettingsPage::LoginFailure);
|
||||
QObject::connect(&*service_, &StreamingService::LoginSuccess, this, &DropboxSettingsPage::LoginSuccess);
|
||||
|
||||
dialog->installEventFilter(this);
|
||||
|
||||
}
|
||||
|
||||
DropboxSettingsPage::~DropboxSettingsPage() {
|
||||
delete ui_;
|
||||
}
|
||||
|
||||
void DropboxSettingsPage::Load() {
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
ui_->enable->setChecked(s.value(kEnabled, false).toBool());
|
||||
s.endGroup();
|
||||
|
||||
if (service_->authenticated()) ui_->login_state->SetLoggedIn(LoginStateWidget::State::LoggedIn);
|
||||
|
||||
Init(ui_->layout_dropboxsettingspage->parentWidget());
|
||||
|
||||
if (!Settings().childGroups().contains(QLatin1String(kSettingsGroup))) set_changed();
|
||||
|
||||
}
|
||||
|
||||
void DropboxSettingsPage::Save() {
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue(kEnabled, ui_->enable->isChecked());
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
|
||||
void DropboxSettingsPage::LoginClicked() {
|
||||
|
||||
Q_EMIT Authorize();
|
||||
|
||||
ui_->button_login->setEnabled(false);
|
||||
|
||||
}
|
||||
|
||||
bool DropboxSettingsPage::eventFilter(QObject *object, QEvent *event) {
|
||||
|
||||
if (object == dialog() && event->type() == QEvent::Enter) {
|
||||
ui_->button_login->setEnabled(true);
|
||||
}
|
||||
|
||||
return SettingsPage::eventFilter(object, event);
|
||||
|
||||
}
|
||||
|
||||
void DropboxSettingsPage::LogoutClicked() {
|
||||
|
||||
service_->ClearSession();
|
||||
ui_->button_login->setEnabled(true);
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::State::LoggedOut);
|
||||
|
||||
}
|
||||
|
||||
void DropboxSettingsPage::LoginSuccess() {
|
||||
|
||||
if (!isVisible()) return;
|
||||
ui_->login_state->SetLoggedIn(LoginStateWidget::State::LoggedIn);
|
||||
ui_->button_login->setEnabled(true);
|
||||
|
||||
}
|
||||
|
||||
void DropboxSettingsPage::LoginFailure(const QString &failure_reason) {
|
||||
|
||||
if (!isVisible()) return;
|
||||
QMessageBox::warning(this, tr("Authentication failed"), failure_reason);
|
||||
ui_->button_login->setEnabled(true);
|
||||
|
||||
}
|
||||
|
||||
void DropboxSettingsPage::ResetClicked() {
|
||||
|
||||
service_->Reset();
|
||||
|
||||
}
|
||||
58
src/settings/dropboxsettingspage.h
Normal file
58
src/settings/dropboxsettingspage.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2025, 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 DROPBOXSETTINGSPAGE_H
|
||||
#define DROPBOXSETTINGSPAGE_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "settingspage.h"
|
||||
|
||||
class DropboxService;
|
||||
class Ui_DropboxSettingsPage;
|
||||
|
||||
class DropboxSettingsPage : public SettingsPage {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DropboxSettingsPage(SettingsDialog *dialog, const SharedPtr<DropboxService> service, QWidget *parent);
|
||||
~DropboxSettingsPage();
|
||||
|
||||
void Load() override;
|
||||
void Save() override;
|
||||
|
||||
bool eventFilter(QObject *object, QEvent *event) override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void Authorize();
|
||||
|
||||
private Q_SLOTS:
|
||||
void LoginClicked();
|
||||
void LogoutClicked();
|
||||
void LoginSuccess();
|
||||
void LoginFailure(const QString &failure_reason);
|
||||
void ResetClicked();
|
||||
|
||||
private:
|
||||
Ui_DropboxSettingsPage *ui_;
|
||||
const SharedPtr<DropboxService> service_;
|
||||
};
|
||||
|
||||
#endif // DROPBOXSETTINGSPAGE_H
|
||||
125
src/settings/dropboxsettingspage.ui
Normal file
125
src/settings/dropboxsettingspage.ui
Normal file
@@ -0,0 +1,125 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DropboxSettingsPage</class>
|
||||
<widget class="QWidget" name="DropboxSettingsPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>569</width>
|
||||
<height>491</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dropbox</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="layout_dropboxsettingspage">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_info">
|
||||
<property name="text">
|
||||
<string>Strawberry can play music that you have uploaded to Dropbox</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="enable">
|
||||
<property name="text">
|
||||
<string>Enable</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="LoginStateWidget" name="login_state" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_authorization" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>28</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_login">
|
||||
<property name="text">
|
||||
<string>Login</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="spacer_login">
|
||||
<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>
|
||||
<layout class="QHBoxLayout" name="layout_buttons">
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_reset">
|
||||
<property name="text">
|
||||
<string>Reset cursor and songs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="spacer_buttons">
|
||||
<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>
|
||||
<spacer name="spacer_bottom">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>357</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/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -90,6 +90,10 @@
|
||||
# include "qobuz/qobuzservice.h"
|
||||
# include "qobuzsettingspage.h"
|
||||
#endif
|
||||
#ifdef HAVE_DROPBOX
|
||||
# include "dropbox/dropboxservice.h"
|
||||
# include "dropboxsettingspage.h"
|
||||
#endif
|
||||
|
||||
#include "ui_settingsdialog.h"
|
||||
|
||||
@@ -144,7 +148,7 @@ SettingsDialog::SettingsDialog(const SharedPtr<Player> player,
|
||||
AddPage(Page::Moodbar, new MoodbarSettingsPage(this, this), iface);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SUBSONIC) || defined(HAVE_TIDAL) || defined(HAVE_SPOTIFY) || defined(HAVE_QOBUZ)
|
||||
#if defined(HAVE_SUBSONIC) || defined(HAVE_TIDAL) || defined(HAVE_SPOTIFY) || defined(HAVE_QOBUZ) || defined(HAVE_DROPBOX)
|
||||
QTreeWidgetItem *streaming = AddCategory(tr("Streaming"));
|
||||
#endif
|
||||
|
||||
@@ -160,6 +164,9 @@ SettingsDialog::SettingsDialog(const SharedPtr<Player> player,
|
||||
#ifdef HAVE_QOBUZ
|
||||
AddPage(Page::Qobuz, new QobuzSettingsPage(this, streaming_services->Service<QobuzService>(), this), streaming);
|
||||
#endif
|
||||
#ifdef HAVE_DROPBOX
|
||||
AddPage(Page::Dropbox, new DropboxSettingsPage(this, streaming_services->Service<DropboxService>(), this), streaming);
|
||||
#endif
|
||||
|
||||
// List box
|
||||
QObject::connect(ui_->list, &QTreeWidget::currentItemChanged, this, &SettingsDialog::CurrentItemChanged);
|
||||
|
||||
@@ -93,6 +93,8 @@ class SettingsDialog : public QDialog {
|
||||
Tidal,
|
||||
Qobuz,
|
||||
Spotify,
|
||||
Dropbox,
|
||||
OneDrive,
|
||||
};
|
||||
|
||||
enum Role {
|
||||
|
||||
Reference in New Issue
Block a user