2014-10-15 20:44:09 +02:00
|
|
|
/* This file is part of Clementine.
|
2014-12-17 19:02:21 +01:00
|
|
|
Copyright 2014, Chocobozzz <florian.bigard@gmail.com>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
2014-10-15 20:44:09 +02: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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "internetshowsettingspage.h"
|
|
|
|
|
|
|
|
#include "core/application.h"
|
2015-10-14 03:01:08 +02:00
|
|
|
#include "ui/iconloader.h"
|
2014-10-15 20:44:09 +02:00
|
|
|
#include "ui/settingsdialog.h"
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/core/internetservice.h"
|
|
|
|
#include "internet/core/internetmodel.h"
|
2014-10-15 20:44:09 +02:00
|
|
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
|
|
|
InternetShowSettingsPage::InternetShowSettingsPage(SettingsDialog* parent)
|
|
|
|
: SettingsPage(parent), ui_(new Ui::InternetShowSettingsPage) {
|
|
|
|
ui_->setupUi(this);
|
2015-10-14 03:01:08 +02:00
|
|
|
setWindowIcon(IconLoader::Load("internet-services", IconLoader::Base));
|
2014-10-15 20:44:09 +02:00
|
|
|
|
2015-04-11 22:52:31 +02:00
|
|
|
ui_->sources->header()->setSectionResizeMode(0, QHeaderView::Stretch);
|
|
|
|
ui_->sources->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
2014-10-15 20:44:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void InternetShowSettingsPage::Load() {
|
|
|
|
QMap<InternetService*, InternetModel::ServiceItem> shown_services =
|
|
|
|
dialog()->app()->internet_model()->shown_services();
|
|
|
|
|
|
|
|
ui_->sources->clear();
|
|
|
|
|
2014-10-24 09:22:35 +02:00
|
|
|
for (auto service_it = shown_services.constBegin();
|
|
|
|
service_it != shown_services.constEnd(); service_it++) {
|
2014-10-15 20:44:09 +02:00
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem;
|
|
|
|
|
|
|
|
// Get the same text and the same icon as the service tree
|
2014-10-24 09:22:35 +02:00
|
|
|
item->setText(0, service_it.value().item->text());
|
|
|
|
item->setIcon(0, service_it.value().item->icon());
|
2014-10-15 20:44:09 +02:00
|
|
|
|
2014-10-15 21:57:57 +02:00
|
|
|
Qt::CheckState check_state =
|
2019-02-22 18:44:39 +01:00
|
|
|
service_it.value().shown ? Qt::Checked : Qt::Unchecked;
|
2014-10-15 20:44:09 +02:00
|
|
|
item->setData(0, Qt::CheckStateRole, check_state);
|
|
|
|
/* We have to store the constant name of the service */
|
2014-10-24 09:22:35 +02:00
|
|
|
item->setData(1, Qt::UserRole, service_it.key()->name());
|
2014-10-15 20:44:09 +02:00
|
|
|
|
|
|
|
ui_->sources->invisibleRootItem()->addChild(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
ui_->sources->invisibleRootItem()->sortChildren(0, Qt::AscendingOrder);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InternetShowSettingsPage::Save() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(InternetModel::kSettingsGroup);
|
|
|
|
|
|
|
|
for (int i = 0; i < ui_->sources->invisibleRootItem()->childCount(); ++i) {
|
|
|
|
QTreeWidgetItem* item = ui_->sources->invisibleRootItem()->child(i);
|
|
|
|
s.setValue(item->data(1, Qt::UserRole).toString(),
|
|
|
|
(item->data(0, Qt::CheckStateRole).toBool()));
|
|
|
|
}
|
|
|
|
|
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
dialog()->app()->internet_model()->UpdateServices();
|
|
|
|
}
|