mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 03:27:40 +01:00
Allow user to hide internet services. Closes #2784
This commit is contained in:
parent
aa3671b54a
commit
c54d1baf15
@ -425,5 +425,6 @@
|
||||
<file>providers/vk.png</file>
|
||||
<file>vk/link.png</file>
|
||||
<file>providers/seafile.png</file>
|
||||
<file>icons/32x32/internet-services.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
BIN
data/icons/32x32/internet-services.png
Normal file
BIN
data/icons/32x32/internet-services.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
@ -183,6 +183,7 @@ set(SOURCES
|
||||
internet/internetmodel.cpp
|
||||
internet/internetplaylistitem.cpp
|
||||
internet/internetservice.cpp
|
||||
internet/internetshowsettingspage.cpp
|
||||
internet/internetview.cpp
|
||||
internet/internetviewcontainer.cpp
|
||||
internet/jamendodynamicplaylist.cpp
|
||||
@ -488,6 +489,7 @@ set(HEADERS
|
||||
internet/internetmimedata.h
|
||||
internet/internetmodel.h
|
||||
internet/internetservice.h
|
||||
internet/internetshowsettingspage.h
|
||||
internet/internetsongmimedata.h
|
||||
internet/internetview.h
|
||||
internet/internetviewcontainer.h
|
||||
@ -694,6 +696,7 @@ set(UI
|
||||
internet/digitallyimportedsettingspage.ui
|
||||
internet/groovesharksettingspage.ui
|
||||
internet/icecastfilterwidget.ui
|
||||
internet/internetshowsettingspage.ui
|
||||
internet/internetviewcontainer.ui
|
||||
internet/magnatunedownloaddialog.ui
|
||||
internet/magnatunesettingspage.ui
|
||||
|
@ -63,6 +63,8 @@ using smart_playlists::GeneratorPtr;
|
||||
|
||||
QMap<QString, InternetService*>* InternetModel::sServices = nullptr;
|
||||
|
||||
const char* InternetModel::kSettingsGroup = "InternetModel";
|
||||
|
||||
InternetModel::InternetModel(Application* app, QObject* parent)
|
||||
: QStandardItemModel(parent),
|
||||
app_(app),
|
||||
@ -108,7 +110,7 @@ InternetModel::InternetModel(Application* app, QObject* parent)
|
||||
AddService(new VkService(app, this));
|
||||
#endif
|
||||
|
||||
invisibleRootItem()->sortChildren(0, Qt::AscendingOrder);
|
||||
UpdateServices();
|
||||
}
|
||||
|
||||
void InternetModel::AddService(InternetService* service) {
|
||||
@ -126,6 +128,12 @@ void InternetModel::AddService(InternetService* service) {
|
||||
qLog(Debug) << "Adding internet service:" << service->name();
|
||||
sServices->insert(service->name(), service);
|
||||
|
||||
ServiceItem service_item;
|
||||
service_item.item = root;
|
||||
service_item.shown = true;
|
||||
|
||||
shown_services_.insert(service, service_item);
|
||||
|
||||
connect(service, SIGNAL(StreamError(QString)), SIGNAL(StreamError(QString)));
|
||||
connect(service, SIGNAL(StreamMetadataFound(QUrl, Song)),
|
||||
SIGNAL(StreamMetadataFound(QUrl, Song)));
|
||||
@ -154,6 +162,9 @@ void InternetModel::RemoveService(InternetService* service) {
|
||||
// Remove the service from the list
|
||||
sServices->remove(service->name());
|
||||
|
||||
// Don't forget to delete from shown_services too
|
||||
shown_services_.remove(service);
|
||||
|
||||
// Disconnect the service
|
||||
disconnect(service, 0, this, 0);
|
||||
}
|
||||
@ -315,3 +326,49 @@ void InternetModel::ReloadSettings() {
|
||||
service->ReloadSettings();
|
||||
}
|
||||
}
|
||||
|
||||
void InternetModel::UpdateServices() {
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
|
||||
QStringList keys = s.childKeys();
|
||||
|
||||
for (QString service_name : keys) {
|
||||
InternetService* internet_service = ServiceByName(service_name);
|
||||
bool setting_val = s.value(service_name).toBool();
|
||||
|
||||
// Only update if values are different
|
||||
if (setting_val == true && shown_services_[internet_service].shown == false) {
|
||||
ShowService(internet_service);
|
||||
} else if (setting_val == false &&
|
||||
shown_services_[internet_service].shown == true) {
|
||||
HideService(internet_service);
|
||||
}
|
||||
}
|
||||
|
||||
s.endGroup();
|
||||
|
||||
invisibleRootItem()->sortChildren(0, Qt::AscendingOrder);
|
||||
}
|
||||
|
||||
void InternetModel::ShowService(InternetService* service) {
|
||||
if(shown_services_[service].shown != true) {
|
||||
invisibleRootItem()->appendRow(shown_services_[service].item);
|
||||
shown_services_[service].shown = true;
|
||||
}
|
||||
}
|
||||
|
||||
void InternetModel::HideService(InternetService* service) {
|
||||
// Find and remove the root item that this service created
|
||||
for (int i = 0; i < invisibleRootItem()->rowCount(); ++i) {
|
||||
QStandardItem* item = invisibleRootItem()->child(i);
|
||||
if (!item ||
|
||||
item->data(Role_Service).value<InternetService*>() == service) {
|
||||
// Don't remove the standarditem behind the row
|
||||
invisibleRootItem()->takeRow(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
shown_services_[service].shown = false;
|
||||
}
|
||||
|
@ -114,8 +114,14 @@ class InternetModel : public QStandardItemModel {
|
||||
PlayBehaviour_DoubleClickAction,
|
||||
};
|
||||
|
||||
struct ServiceItem {
|
||||
QStandardItem *item;
|
||||
bool shown;
|
||||
};
|
||||
|
||||
// Needs to be static for InternetPlaylistItem::restore
|
||||
static InternetService* ServiceByName(const QString& name);
|
||||
static const char* kSettingsGroup;
|
||||
|
||||
template <typename T>
|
||||
static T* Service() {
|
||||
@ -127,6 +133,10 @@ class InternetModel : public QStandardItemModel {
|
||||
// removed from the model.
|
||||
void AddService(InternetService* service);
|
||||
void RemoveService(InternetService* service);
|
||||
void HideService(InternetService* service);
|
||||
void ShowService(InternetService* service);
|
||||
// Add or remove the services according to the setting file
|
||||
void UpdateServices();
|
||||
|
||||
// Returns the service that is a parent of this item. Works by walking up
|
||||
// the tree until it finds an item with Role_Service set.
|
||||
@ -155,6 +165,9 @@ class InternetModel : public QStandardItemModel {
|
||||
|
||||
const QModelIndex& current_index() const { return current_index_; }
|
||||
const QModelIndexList& selected_indexes() const { return selected_indexes_; }
|
||||
const QMap<InternetService*, ServiceItem> shown_services() const {
|
||||
return shown_services_;
|
||||
}
|
||||
|
||||
signals:
|
||||
void StreamError(const QString& message);
|
||||
@ -167,6 +180,9 @@ signals:
|
||||
void ServiceDeleted();
|
||||
|
||||
private:
|
||||
|
||||
QMap<InternetService*, ServiceItem> shown_services_;
|
||||
|
||||
static QMap<QString, InternetService*>* sServices;
|
||||
|
||||
Application* app_;
|
||||
|
73
src/internet/internetshowsettingspage.cpp
Normal file
73
src/internet/internetshowsettingspage.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
/* This file is part of Clementine.
|
||||
Copyright 2011, 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 "internetshowsettingspage.h"
|
||||
|
||||
#include "core/application.h"
|
||||
#include "ui/settingsdialog.h"
|
||||
#include "internetservice.h"
|
||||
#include "internetmodel.h"
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
InternetShowSettingsPage::InternetShowSettingsPage(SettingsDialog* parent)
|
||||
: SettingsPage(parent), ui_(new Ui::InternetShowSettingsPage) {
|
||||
ui_->setupUi(this);
|
||||
|
||||
ui_->sources->header()->setResizeMode(0, QHeaderView::Stretch);
|
||||
ui_->sources->header()->setResizeMode(1, QHeaderView::ResizeToContents);
|
||||
}
|
||||
|
||||
void InternetShowSettingsPage::Load() {
|
||||
QMap<InternetService*, InternetModel::ServiceItem> shown_services =
|
||||
dialog()->app()->internet_model()->shown_services();
|
||||
|
||||
ui_->sources->clear();
|
||||
|
||||
for (QMap<InternetService*, InternetModel::ServiceItem>::iterator service = shown_services.begin();
|
||||
service != shown_services.end(); ++service) {
|
||||
QTreeWidgetItem* item = new QTreeWidgetItem;
|
||||
|
||||
// Get the same text and the same icon as the service tree
|
||||
item->setText(0, service.value().item->text());
|
||||
item->setIcon(0, service.value().item->icon());
|
||||
|
||||
Qt::CheckState check_state = service.value().shown == true ? Qt::Checked : Qt::Unchecked;
|
||||
item->setData(0, Qt::CheckStateRole, check_state);
|
||||
/* We have to store the constant name of the service */
|
||||
item->setData(1, Qt::UserRole, service.key()->name());
|
||||
|
||||
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();
|
||||
}
|
43
src/internet/internetshowsettingspage.h
Normal file
43
src/internet/internetshowsettingspage.h
Normal file
@ -0,0 +1,43 @@
|
||||
/* This file is part of Clementine.
|
||||
Copyright 2011, 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/>.
|
||||
*/
|
||||
|
||||
#ifndef INTERNETSHOWSETTINGSPAGE_H
|
||||
#define INTERNETSHOWSETTINGSPAGE_H
|
||||
|
||||
#include "ui/settingspage.h"
|
||||
#include "ui_internetshowsettingspage.h"
|
||||
|
||||
#include <QIcon>
|
||||
|
||||
class QTreeWidgetItem;
|
||||
class Ui_InternetShowSettingsPage;
|
||||
|
||||
class InternetShowSettingsPage : public SettingsPage {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
InternetShowSettingsPage(SettingsDialog* dialog);
|
||||
|
||||
void Load();
|
||||
void Save();
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui_InternetShowSettingsPage> ui_;
|
||||
QIcon warning_icon_;
|
||||
};
|
||||
|
||||
#endif // INTERNETSHOWSETTINGSPAGE_H
|
82
src/internet/internetshowsettingspage.ui
Normal file
82
src/internet/internetshowsettingspage.ui
Normal file
@ -0,0 +1,82 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>InternetShowSettingsPage</class>
|
||||
<widget class="QWidget" name="InternetShowSettingsPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>654</width>
|
||||
<height>506</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string comment="Global search settings dialog title.">Internet services</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../../data/data.qrc">
|
||||
<normaloff>:/icons/32x32/internet-services.png</normaloff>:/icons/32x32/internet-services.png</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="sources_group">
|
||||
<property name="title">
|
||||
<string>Sources</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Choose the internet services you want to show.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="sources">
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="columnCount">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="headerStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">2</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>sources</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../../data/data.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
@ -37,6 +37,7 @@
|
||||
#include "globalsearch/globalsearchsettingspage.h"
|
||||
#include "internet/digitallyimportedsettingspage.h"
|
||||
#include "internet/groovesharksettingspage.h"
|
||||
#include "internet/internetshowsettingspage.h"
|
||||
#include "internet/magnatunesettingspage.h"
|
||||
#include "internet/soundcloudsettingspage.h"
|
||||
#include "internet/spotifysettingspage.h"
|
||||
@ -84,7 +85,6 @@
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#include <QAbstractButton>
|
||||
#include <QDesktopWidget>
|
||||
#include <QPainter>
|
||||
@ -156,6 +156,7 @@ SettingsDialog::SettingsDialog(Application* app, BackgroundStreams* streams,
|
||||
AddPage(Page_Appearance, new AppearanceSettingsPage(this), iface);
|
||||
AddPage(Page_SongInformation, new SongInfoSettingsPage(this), iface);
|
||||
AddPage(Page_Notifications, new NotificationsSettingsPage(this), iface);
|
||||
AddPage(Page_InternetShow, new InternetShowSettingsPage(this), iface);
|
||||
|
||||
// Internet providers
|
||||
QTreeWidgetItem* providers = AddCategory(tr("Internet providers"));
|
||||
|
@ -85,7 +85,8 @@ class SettingsDialog : public QDialog {
|
||||
Page_Skydrive,
|
||||
Page_Box,
|
||||
Page_Vk,
|
||||
Page_Seafile
|
||||
Page_Seafile,
|
||||
Page_InternetShow
|
||||
};
|
||||
|
||||
enum Role { Role_IsSeparator = Qt::UserRole };
|
||||
|
Loading…
x
Reference in New Issue
Block a user