2012-03-09 16:25:49 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2012, David Sansome <me@davidsansome.com>
|
2014-11-02 19:50:39 +01:00
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
2014-11-01 19:38:39 +01:00
|
|
|
Copyright 2014, John Maguire <john.maguire@gmail.com>
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-03-09 16:25:49 +01:00
|
|
|
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.
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-03-09 16:25:49 +01:00
|
|
|
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.
|
2014-02-07 16:34:20 +01:00
|
|
|
|
2012-03-09 16:25:49 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "podcastsettingspage.h"
|
|
|
|
#include "ui_podcastsettingspage.h"
|
2014-12-13 02:24:20 +01:00
|
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QSettings>
|
|
|
|
|
2012-03-09 16:25:49 +01:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/closure.h"
|
2012-03-12 20:35:47 +01:00
|
|
|
#include "core/timeconstants.h"
|
2014-12-13 02:24:20 +01:00
|
|
|
#include "gpoddersync.h"
|
2012-03-10 16:32:36 +01:00
|
|
|
#include "library/librarydirectorymodel.h"
|
|
|
|
#include "library/librarymodel.h"
|
2014-12-13 02:24:20 +01:00
|
|
|
#include "podcastdownloader.h"
|
2012-03-09 16:25:49 +01:00
|
|
|
#include "ui/settingsdialog.h"
|
|
|
|
|
|
|
|
const char* PodcastSettingsPage::kSettingsGroup = "Podcasts";
|
|
|
|
|
|
|
|
PodcastSettingsPage::PodcastSettingsPage(SettingsDialog* dialog)
|
2014-02-07 16:34:20 +01:00
|
|
|
: SettingsPage(dialog), ui_(new Ui_PodcastSettingsPage) {
|
2012-03-09 16:25:49 +01:00
|
|
|
ui_->setupUi(this);
|
|
|
|
connect(ui_->login, SIGNAL(clicked()), SLOT(LoginClicked()));
|
|
|
|
connect(ui_->login_state, SIGNAL(LoginClicked()), SLOT(LoginClicked()));
|
|
|
|
connect(ui_->login_state, SIGNAL(LogoutClicked()), SLOT(LogoutClicked()));
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(ui_->download_dir_browse, SIGNAL(clicked()),
|
|
|
|
SLOT(DownloadDirBrowse()));
|
2012-03-09 16:25:49 +01:00
|
|
|
|
|
|
|
ui_->login_state->AddCredentialField(ui_->username);
|
|
|
|
ui_->login_state->AddCredentialField(ui_->device_name);
|
2012-03-09 17:47:19 +01:00
|
|
|
ui_->login_state->AddCredentialField(ui_->password);
|
2012-03-09 16:25:49 +01:00
|
|
|
ui_->login_state->AddCredentialGroup(ui_->login_group);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->check_interval->setItemData(0, 0); // manually
|
|
|
|
ui_->check_interval->setItemData(1, 10 * 60); // 10 minutes
|
|
|
|
ui_->check_interval->setItemData(2, 20 * 60); // 20 minutes
|
|
|
|
ui_->check_interval->setItemData(3, 30 * 60); // 30 minutes
|
|
|
|
ui_->check_interval->setItemData(4, 60 * 60); // 1 hour
|
|
|
|
ui_->check_interval->setItemData(5, 2 * 60 * 60); // 2 hours
|
|
|
|
ui_->check_interval->setItemData(6, 6 * 60 * 60); // 6 hours
|
|
|
|
ui_->check_interval->setItemData(7, 12 * 60 * 60); // 12 hours
|
2012-03-09 16:25:49 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
PodcastSettingsPage::~PodcastSettingsPage() { delete ui_; }
|
2012-03-09 16:25:49 +01:00
|
|
|
|
|
|
|
void PodcastSettingsPage::Load() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
|
|
|
|
const int update_interval = s.value("update_interval_secs", 0).toInt();
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->check_interval->setCurrentIndex(
|
|
|
|
ui_->check_interval->findData(update_interval));
|
2012-03-09 16:25:49 +01:00
|
|
|
|
2012-03-10 16:32:36 +01:00
|
|
|
const QString default_download_dir =
|
|
|
|
dialog()->app()->podcast_downloader()->DefaultDownloadDir();
|
|
|
|
ui_->download_dir->setText(QDir::toNativeSeparators(
|
|
|
|
s.value("download_dir", default_download_dir).toString()));
|
|
|
|
|
2012-03-09 16:25:49 +01:00
|
|
|
ui_->auto_download->setChecked(s.value("auto_download", false).toBool());
|
2012-03-12 20:35:47 +01:00
|
|
|
ui_->delete_after->setValue(s.value("delete_after", 0).toInt() / kSecsPerDay);
|
2012-03-09 16:25:49 +01:00
|
|
|
ui_->username->setText(s.value("gpodder_username").toString());
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->device_name->setText(
|
|
|
|
s.value("gpodder_device_name", GPodderSync::DefaultDeviceName())
|
|
|
|
.toString());
|
2012-03-10 16:32:36 +01:00
|
|
|
|
2012-03-10 23:43:05 +01:00
|
|
|
if (dialog()->app()->gpodder_sync()->is_logged_in()) {
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn,
|
|
|
|
ui_->username->text());
|
2012-03-10 23:43:05 +01:00
|
|
|
} else {
|
|
|
|
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut);
|
|
|
|
}
|
2012-03-09 16:25:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PodcastSettingsPage::Save() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
s.setValue("update_interval_secs", ui_->check_interval->itemData(
|
|
|
|
ui_->check_interval->currentIndex()));
|
|
|
|
s.setValue("download_dir",
|
|
|
|
QDir::fromNativeSeparators(ui_->download_dir->text()));
|
2012-03-09 16:25:49 +01:00
|
|
|
s.setValue("auto_download", ui_->auto_download->isChecked());
|
2012-03-12 20:35:47 +01:00
|
|
|
s.setValue("delete_after", ui_->delete_after->value() * kSecsPerDay);
|
2012-03-09 16:25:49 +01:00
|
|
|
s.setValue("gpodder_device_name", ui_->device_name->text());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PodcastSettingsPage::LoginClicked() {
|
|
|
|
ui_->login_state->SetLoggedIn(LoginStateWidget::LoginInProgress);
|
|
|
|
|
|
|
|
QNetworkReply* reply = dialog()->app()->gpodder_sync()->Login(
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->username->text(), ui_->password->text(), ui_->device_name->text());
|
2012-03-09 16:25:49 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
NewClosure(reply, SIGNAL(finished()), this,
|
|
|
|
SLOT(LoginFinished(QNetworkReply*)), reply);
|
2012-03-09 16:25:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PodcastSettingsPage::LoginFinished(QNetworkReply* reply) {
|
|
|
|
const bool success = reply->error() == QNetworkReply::NoError;
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->login_state->SetLoggedIn(
|
|
|
|
success ? LoginStateWidget::LoggedIn : LoginStateWidget::LoggedOut,
|
|
|
|
ui_->username->text());
|
2012-03-09 17:47:19 +01:00
|
|
|
|
|
|
|
ui_->login_state->SetAccountTypeVisible(!success);
|
|
|
|
if (!success) {
|
|
|
|
ui_->login_state->SetAccountTypeText(tr("Login failed") + ": " +
|
|
|
|
reply->errorString());
|
|
|
|
}
|
2012-03-09 16:25:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PodcastSettingsPage::LogoutClicked() {
|
|
|
|
ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut);
|
|
|
|
ui_->password->clear();
|
|
|
|
dialog()->app()->gpodder_sync()->Logout();
|
|
|
|
}
|
2012-03-10 16:32:36 +01:00
|
|
|
|
|
|
|
void PodcastSettingsPage::DownloadDirBrowse() {
|
|
|
|
QString directory = QFileDialog::getExistingDirectory(
|
2014-02-07 16:34:20 +01:00
|
|
|
this, tr("Choose podcast download directory"), ui_->download_dir->text());
|
|
|
|
if (directory.isEmpty()) return;
|
2012-03-10 16:32:36 +01:00
|
|
|
|
|
|
|
ui_->download_dir->setText(QDir::toNativeSeparators(directory));
|
|
|
|
}
|