2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +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.
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2010-02-24 23:26:01 +01:00
|
|
|
#include "addstreamdialog.h"
|
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
#include <QPushButton>
|
2010-02-24 23:26:01 +01:00
|
|
|
#include <QSettings>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QtDebug>
|
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
#include "internet/core/internetmodel.h"
|
|
|
|
#include "internet/internetradio/savedradio.h"
|
|
|
|
#include "ui_addstreamdialog.h"
|
|
|
|
|
2010-02-24 23:26:01 +01:00
|
|
|
const char* AddStreamDialog::kSettingsGroup = "AddStreamDialog";
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
AddStreamDialog::AddStreamDialog(QWidget* parent)
|
|
|
|
: QDialog(parent), ui_(new Ui_AddStreamDialog), saved_radio_(nullptr) {
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->setupUi(this);
|
2010-02-24 23:26:01 +01:00
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
connect(ui_->url, SIGNAL(textChanged(QString)), SLOT(TextChanged(QString)));
|
2019-11-09 23:45:28 +01:00
|
|
|
TextChanged(QString());
|
2010-02-24 23:26:01 +01:00
|
|
|
|
|
|
|
// Restore settings
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->save->setChecked(s.value("save", true).toBool());
|
|
|
|
ui_->url->setText(s.value("url").toString());
|
2010-05-28 00:53:07 +02:00
|
|
|
ui_->name->setText(s.value("name").toString());
|
2020-11-27 13:05:53 +01:00
|
|
|
ui_->url_logo->setText(s.value("url_logo").toString());
|
2010-02-24 23:26:01 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
AddStreamDialog::~AddStreamDialog() { delete ui_; }
|
2010-05-10 23:50:31 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QUrl AddStreamDialog::url() const { return QUrl(ui_->url->text()); }
|
|
|
|
QString AddStreamDialog::name() const { return ui_->name->text(); }
|
2020-11-27 13:05:53 +01:00
|
|
|
QUrl AddStreamDialog::url_logo() const { return QUrl(ui_->url_logo->text()); }
|
2010-05-28 00:53:07 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void AddStreamDialog::set_name(const QString& name) {
|
2010-05-28 00:53:07 +02:00
|
|
|
ui_->name->setText(name);
|
|
|
|
}
|
2014-02-07 16:34:20 +01:00
|
|
|
void AddStreamDialog::set_url(const QUrl& url) {
|
2010-05-28 00:53:07 +02:00
|
|
|
ui_->url->setText(url.toString());
|
|
|
|
}
|
2020-11-27 13:05:53 +01:00
|
|
|
void AddStreamDialog::set_url_logo(const QUrl& url) {
|
|
|
|
ui_->url_logo->setText(url.toString());
|
|
|
|
}
|
2010-05-28 00:53:07 +02:00
|
|
|
|
|
|
|
void AddStreamDialog::set_save_visible(bool visible) {
|
|
|
|
ui_->save->setVisible(visible);
|
2020-11-27 13:05:53 +01:00
|
|
|
if (!visible) ui_->details_container->setEnabled(true);
|
2010-05-28 00:53:07 +02:00
|
|
|
}
|
|
|
|
|
2010-02-24 23:26:01 +01:00
|
|
|
void AddStreamDialog::accept() {
|
2010-05-28 00:53:07 +02:00
|
|
|
if (ui_->save->isChecked() && saved_radio_) {
|
2020-11-27 13:05:53 +01:00
|
|
|
saved_radio_->Add(url(), name(), url_logo());
|
2010-02-24 23:26:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save settings
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
2010-05-10 23:50:31 +02:00
|
|
|
s.setValue("save", ui_->save->isChecked());
|
2010-02-24 23:26:01 +01:00
|
|
|
s.setValue("url", url().toString());
|
2010-05-28 00:53:07 +02:00
|
|
|
s.setValue("name", ui_->name->text());
|
2010-02-24 23:26:01 +01:00
|
|
|
|
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void AddStreamDialog::TextChanged(const QString& text) {
|
2010-02-24 23:26:01 +01:00
|
|
|
// Decide whether the URL is valid
|
2010-02-25 00:49:14 +01:00
|
|
|
QUrl url(text);
|
2010-02-24 23:26:01 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
bool valid =
|
|
|
|
url.isValid() && !url.scheme().isEmpty() && !url.toString().isEmpty();
|
2010-02-24 23:26:01 +01:00
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->button_box->button(QDialogButtonBox::Ok)->setEnabled(valid);
|
2010-02-24 23:26:01 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void AddStreamDialog::showEvent(QShowEvent*) {
|
2010-06-16 18:21:38 +02:00
|
|
|
ui_->url->setFocus();
|
|
|
|
ui_->url->selectAll();
|
|
|
|
}
|