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"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "ui_addstreamdialog.h"
|
|
|
|
#include "radio/radiomodel.h"
|
|
|
|
#include "radio/savedradio.h"
|
2010-02-24 23:26:01 +01:00
|
|
|
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QtDebug>
|
|
|
|
|
|
|
|
const char* AddStreamDialog::kSettingsGroup = "AddStreamDialog";
|
|
|
|
|
|
|
|
AddStreamDialog::AddStreamDialog(QWidget *parent)
|
|
|
|
: QDialog(parent),
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_(new Ui_AddStreamDialog),
|
2010-02-24 23:26:01 +01:00
|
|
|
saved_radio_(NULL)
|
|
|
|
{
|
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)));
|
2010-02-24 23:26:01 +01:00
|
|
|
TextChanged(QString::null);
|
|
|
|
|
|
|
|
// 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());
|
2010-02-24 23:26:01 +01:00
|
|
|
}
|
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
AddStreamDialog::~AddStreamDialog() {
|
|
|
|
delete ui_;
|
|
|
|
}
|
|
|
|
|
2010-02-24 23:26:01 +01:00
|
|
|
QUrl AddStreamDialog::url() const {
|
2010-05-10 23:50:31 +02:00
|
|
|
return QUrl(ui_->url->text());
|
2010-02-24 23:26:01 +01:00
|
|
|
}
|
|
|
|
|
2010-05-28 00:53:07 +02:00
|
|
|
QString AddStreamDialog::name() const {
|
|
|
|
return ui_->name->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddStreamDialog::set_name(const QString &name) {
|
|
|
|
ui_->name->setText(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddStreamDialog::set_url(const QUrl &url) {
|
|
|
|
ui_->url->setText(url.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddStreamDialog::set_save_visible(bool visible) {
|
|
|
|
ui_->save->setVisible(visible);
|
|
|
|
if (!visible)
|
|
|
|
ui_->name_container->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
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_) {
|
|
|
|
saved_radio_->Add(url(), name());
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddStreamDialog::TextChanged(const QString &text) {
|
|
|
|
// 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
|
|
|
|
|
|
|
bool valid = url.isValid() &&
|
|
|
|
!url.scheme().isEmpty() &&
|
|
|
|
!url.toString().isEmpty();
|
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->button_box->button(QDialogButtonBox::Ok)->setEnabled(valid);
|
2010-02-24 23:26:01 +01:00
|
|
|
}
|
|
|
|
|
2010-06-16 18:21:38 +02:00
|
|
|
void AddStreamDialog::showEvent(QShowEvent *) {
|
|
|
|
ui_->url->setFocus();
|
|
|
|
ui_->url->selectAll();
|
|
|
|
}
|