1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-02-03 12:47:31 +01:00

Add a settings page for OneDrive

This commit is contained in:
David Sansome 2014-03-30 16:35:27 +11:00
parent 345e58ce6b
commit 9c66528c0f
7 changed files with 294 additions and 13 deletions

View File

@ -1120,10 +1120,14 @@ optional_source(HAVE_DROPBOX
optional_source(HAVE_SKYDRIVE
SOURCES
internet/skydriveservice.cpp
internet/skydrivesettingspage.cpp
internet/skydriveurlhandler.cpp
HEADERS
internet/skydriveservice.h
internet/skydrivesettingspage.h
internet/skydriveurlhandler.h
UI
internet/skydrivesettingspage.ui
)
# Box support

View File

@ -12,9 +12,7 @@
namespace {
static const char* kServiceName = "OneDrive";
static const char* kServiceId = "skydrive";
static const char* kSettingsGroup = "Skydrive";
static const char* kClientId = "0000000040111F16";
static const char* kClientSecret = "w2ClguSX0jG56cBl1CeUniypTBRjXt2Z";
@ -30,6 +28,9 @@ static const char* kSkydriveBase = "https://apis.live.net/v5.0/";
} // namespace
const char* SkydriveService::kServiceName = "OneDrive";
const char* SkydriveService::kSettingsGroup = "Skydrive";
SkydriveService::SkydriveService(Application* app, InternetModel* parent)
: CloudFileService(app, parent, kServiceName, kServiceId,
QIcon(":providers/skydrive.png"),
@ -37,16 +38,22 @@ SkydriveService::SkydriveService(Application* app, InternetModel* parent)
app->player()->RegisterUrlHandler(new SkydriveUrlHandler(this, this));
}
bool SkydriveService::has_credentials() const { return true; }
bool SkydriveService::has_credentials() const {
return !refresh_token().isEmpty();
}
QString SkydriveService::refresh_token() const {
QSettings s;
s.beginGroup(kSettingsGroup);
return s.value("refresh_token").toString();
}
void SkydriveService::Connect() {
OAuthenticator* oauth = new OAuthenticator(
kClientId, kClientSecret, OAuthenticator::RedirectStyle::REMOTE, this);
QSettings s;
s.beginGroup(kSettingsGroup);
if (s.contains("refresh_token")) {
oauth->RefreshAuthorisation(kOAuthTokenEndpoint,
s.value("refresh_token").toString());
if (!refresh_token().isEmpty()) {
oauth->RefreshAuthorisation(kOAuthTokenEndpoint, refresh_token());
} else {
oauth->StartAuthorisation(kOAuthEndpoint, kOAuthTokenEndpoint, kOAuthScope);
}
@ -162,3 +169,11 @@ void SkydriveService::EnsureConnected() {
Connect();
WaitForSignal(this, SIGNAL(Connected()));
}
void SkydriveService::ForgetCredentials() {
QSettings s;
s.beginGroup(kSettingsGroup);
s.remove("refresh_token");
s.remove("name");
}

View File

@ -14,22 +14,27 @@ class SkydriveService : public CloudFileService {
public:
SkydriveService(Application* app, InternetModel* parent);
static const char* kServiceName;
static const char* kSettingsGroup;
virtual bool has_credentials() const;
QUrl GetStreamingUrlFromSongId(const QString& song_id);
protected:
// CloudFileService
virtual bool has_credentials() const;
public slots:
virtual void Connect();
void ForgetCredentials();
private slots:
void ConnectFinished(OAuthenticator* oauth);
void FetchUserInfoFinished(QNetworkReply* reply);
void ListFilesFinished(QNetworkReply* reply);
signals:
signals:
void Connected();
private:
QString refresh_token() const;
void AddAuthorizationHeader(QNetworkRequest* request);
void ListFiles(const QString& folder);
void EnsureConnected();

View File

@ -0,0 +1,86 @@
/* This file is part of Clementine.
Copyright 2013, John Maguire <john.maguire@gmail.com>
Clementine 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.
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "skydrivesettingspage.h"
#include <QSortFilterProxyModel>
#include "ui_skydrivesettingspage.h"
#include "core/application.h"
#include "internet/skydriveservice.h"
#include "internet/internetmodel.h"
#include "ui/settingsdialog.h"
SkydriveSettingsPage::SkydriveSettingsPage(SettingsDialog* parent)
: SettingsPage(parent),
ui_(new Ui::SkydriveSettingsPage),
service_(dialog()->app()->internet_model()->Service<SkydriveService>()) {
ui_->setupUi(this);
ui_->login_state->AddCredentialGroup(ui_->login_container);
connect(ui_->login_button, SIGNAL(clicked()), SLOT(LoginClicked()));
connect(ui_->login_state, SIGNAL(LogoutClicked()), SLOT(LogoutClicked()));
connect(service_, SIGNAL(Connected()), SLOT(Connected()));
dialog()->installEventFilter(this);
}
SkydriveSettingsPage::~SkydriveSettingsPage() { delete ui_; }
void SkydriveSettingsPage::Load() {
QSettings s;
s.beginGroup(SkydriveService::kSettingsGroup);
const QString name = s.value("name").toString();
if (!name.isEmpty()) {
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn, name);
}
}
void SkydriveSettingsPage::Save() {
QSettings s;
s.beginGroup(SkydriveService::kSettingsGroup);
}
void SkydriveSettingsPage::LoginClicked() {
service_->Connect();
ui_->login_button->setEnabled(false);
}
bool SkydriveSettingsPage::eventFilter(QObject* object, QEvent* event) {
if (object == dialog() && event->type() == QEvent::Enter) {
ui_->login_button->setEnabled(true);
return false;
}
return SettingsPage::eventFilter(object, event);
}
void SkydriveSettingsPage::LogoutClicked() {
service_->ForgetCredentials();
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut);
}
void SkydriveSettingsPage::Connected() {
QSettings s;
s.beginGroup(SkydriveService::kSettingsGroup);
const QString name = s.value("name").toString();
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn, name);
}

View File

@ -0,0 +1,53 @@
/* This file is part of Clementine.
Copyright 2013, John Maguire <john.maguire@gmail.com>
Clementine 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.
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SKYDRIVESETTINGSPAGE_H
#define SKYDRIVESETTINGSPAGE_H
#include "ui/settingspage.h"
#include <QModelIndex>
#include <QWidget>
class SkydriveService;
class Ui_SkydriveSettingsPage;
class SkydriveSettingsPage : public SettingsPage {
Q_OBJECT
public:
SkydriveSettingsPage(SettingsDialog* parent = nullptr);
~SkydriveSettingsPage();
void Load();
void Save();
// QObject
bool eventFilter(QObject* object, QEvent* event);
private slots:
void LoginClicked();
void LogoutClicked();
void Connected();
private:
Ui_SkydriveSettingsPage* ui_;
SkydriveService* service_;
};
#endif // SKYDRIVESETTINGSPAGE_H

View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SkydriveSettingsPage</class>
<widget class="QWidget" name="SkydriveSettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>569</width>
<height>491</height>
</rect>
</property>
<property name="windowTitle">
<string>OneDrive</string>
</property>
<property name="windowIcon">
<iconset resource="../../data/data.qrc">
<normaloff>:/providers/skydrive.png</normaloff>:/providers/skydrive.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Clementine can play music that you have uploaded to OneDrive</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="LoginStateWidget" name="login_state" native="true"/>
</item>
<item>
<widget class="QWidget" name="login_container" 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="login_button">
<property name="text">
<string>Login</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<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="QLabel" name="label_2">
<property name="text">
<string>Clicking the Login button will open a web browser. You should return to Clementine after you have logged in.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<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>
<include location="../../data/data.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -77,7 +77,11 @@
#endif
#ifdef HAVE_VK
# include "internet/vksettingspage.h"
#include "internet/vksettingspage.h"
#endif
#ifdef HAVE_SKYDRIVE
#include "internet/skydrivesettingspage.h"
#endif
#include <QAbstractButton>
@ -177,6 +181,10 @@ SettingsDialog::SettingsDialog(Application* app, BackgroundStreams* streams,
AddPage(Page_Box, new BoxSettingsPage(this), providers);
#endif
#ifdef HAVE_SKYDRIVE
AddPage(Page_Skydrive, new SkydriveSettingsPage(this), providers);
#endif
AddPage(Page_SoundCloud, new SoundCloudSettingsPage(this), providers);
AddPage(Page_Spotify, new SpotifySettingsPage(this), providers);