2012-07-29 16:06:23 +02:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2012, David Sansome <me@davidsansome.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 "googledriveclient.h"
|
|
|
|
#include "googledriveservice.h"
|
|
|
|
#include "googledrivesettingspage.h"
|
|
|
|
#include "ui_googledrivesettingspage.h"
|
|
|
|
#include "core/application.h"
|
|
|
|
#include "internet/internetmodel.h"
|
|
|
|
#include "ui/settingsdialog.h"
|
|
|
|
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
|
|
|
GoogleDriveSettingsPage::GoogleDriveSettingsPage(SettingsDialog* parent)
|
|
|
|
: SettingsPage(parent),
|
|
|
|
ui_(new Ui::GoogleDriveSettingsPage),
|
2012-08-17 22:48:45 +02:00
|
|
|
service_(dialog()->app()->internet_model()->Service<GoogleDriveService>())
|
2012-07-29 16:06:23 +02:00
|
|
|
{
|
|
|
|
ui_->setupUi(this);
|
2012-08-17 22:48:45 +02:00
|
|
|
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()));
|
2012-08-24 22:33:33 +02:00
|
|
|
|
|
|
|
dialog()->installEventFilter(this);
|
2012-07-29 16:06:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GoogleDriveSettingsPage::~GoogleDriveSettingsPage() {
|
|
|
|
delete ui_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GoogleDriveSettingsPage::Load() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(GoogleDriveService::kSettingsGroup);
|
|
|
|
|
2012-08-17 22:48:45 +02:00
|
|
|
const QString user_email = s.value("user_email").toString();
|
2013-02-26 16:24:47 +01:00
|
|
|
const QString refresh_token = s.value("refresh_token").toString();
|
2012-07-29 16:06:23 +02:00
|
|
|
|
2013-02-26 16:24:47 +01:00
|
|
|
if (!user_email.isEmpty() && !refresh_token.isEmpty()) {
|
2012-08-17 22:48:45 +02:00
|
|
|
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn, user_email);
|
2012-07-29 16:06:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GoogleDriveSettingsPage::Save() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(GoogleDriveService::kSettingsGroup);
|
2012-08-17 22:48:45 +02:00
|
|
|
}
|
2012-07-29 16:06:23 +02:00
|
|
|
|
2012-08-17 22:48:45 +02:00
|
|
|
void GoogleDriveSettingsPage::LoginClicked() {
|
|
|
|
service_->Connect();
|
2012-08-24 22:33:33 +02:00
|
|
|
ui_->login_button->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GoogleDriveSettingsPage::eventFilter(QObject* object, QEvent* event) {
|
|
|
|
if (object == dialog() && event->type() == QEvent::Enter) {
|
|
|
|
ui_->login_button->setEnabled(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SettingsPage::eventFilter(object, event);
|
2012-07-29 16:06:23 +02:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:48:45 +02:00
|
|
|
void GoogleDriveSettingsPage::LogoutClicked() {
|
|
|
|
service_->ForgetCredentials();
|
|
|
|
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut);
|
|
|
|
}
|
2012-07-29 16:06:23 +02:00
|
|
|
|
2012-08-17 22:48:45 +02:00
|
|
|
void GoogleDriveSettingsPage::Connected() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(GoogleDriveService::kSettingsGroup);
|
|
|
|
|
|
|
|
const QString user_email = s.value("user_email").toString();
|
|
|
|
|
|
|
|
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn, user_email);
|
2012-07-29 16:06:23 +02:00
|
|
|
}
|