From c54d1baf1574c9561b4b8130b6523fd36d5f357f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 15 Oct 2014 20:44:09 +0200 Subject: [PATCH] Allow user to hide internet services. Closes #2784 --- data/data.qrc | 1 + data/icons/32x32/internet-services.png | Bin 0 -> 5196 bytes src/CMakeLists.txt | 3 + src/internet/internetmodel.cpp | 59 +++++++++++++++- src/internet/internetmodel.h | 16 +++++ src/internet/internetshowsettingspage.cpp | 73 +++++++++++++++++++ src/internet/internetshowsettingspage.h | 43 ++++++++++++ src/internet/internetshowsettingspage.ui | 82 ++++++++++++++++++++++ src/ui/settingsdialog.cpp | 3 +- src/ui/settingsdialog.h | 3 +- 10 files changed, 280 insertions(+), 3 deletions(-) create mode 100644 data/icons/32x32/internet-services.png create mode 100644 src/internet/internetshowsettingspage.cpp create mode 100644 src/internet/internetshowsettingspage.h create mode 100644 src/internet/internetshowsettingspage.ui diff --git a/data/data.qrc b/data/data.qrc index ba05aab3d..838816aab 100644 --- a/data/data.qrc +++ b/data/data.qrc @@ -425,5 +425,6 @@ providers/vk.png vk/link.png providers/seafile.png + icons/32x32/internet-services.png diff --git a/data/icons/32x32/internet-services.png b/data/icons/32x32/internet-services.png new file mode 100644 index 0000000000000000000000000000000000000000..464115e4a54cfb48ab51d625762016d2c9e49f06 GIT binary patch literal 5196 zcmV-S6tnAzP)uJ@VVD_UC<6{NG_fI~0ue<-1QkJoA_k0xBC#Thg@9ne9*`iQ#9$Or zQF$}6R&?d%y_c8YA7_1QpS|}zXYYO1x&V;8{kgn!SPFnNo`4_X6{c}T{8k*B#$jdxfFg<9uYy1K45IaYvHg`_dOZM)Sy63ve6hvv z1)yUy0P^?0*fb9UASvow`@mQCp^4`uNg&9uGcn1|&Nk+9SjOUl{-OWr@Hh0;_l(8q z{wNRKos+;6rV8ldy0Owz(}jF`W(JeRp&R{qi2rfmU!TJ;gp(Kmm5I1s5m_f-n#TRsj}B0%?E`vOzxB2#P=n*a3EfYETOrKoe*ICqM@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bX4zVb~q0UpE!m?ut&*LH`q@l^0vZ1|Y zTS`|~_nH$YPWy-;3)y$+n$cq`TKd1}@sk!Q&Um zTYL4Sb#D(@w6ckxQue@l0MaYExpU{v0D#u^jvx1H_8pU?WtG)d)hv7{KVMg-OjO7@ zE*djgtfn*F-N(;;(!3Rb@rEX;pD^Z$zdm>Xp|8*XfA&B0$8hh-xU2yH0000* 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() == service) { + // Don't remove the standarditem behind the row + invisibleRootItem()->takeRow(i); + break; + } + } + + shown_services_[service].shown = false; +} diff --git a/src/internet/internetmodel.h b/src/internet/internetmodel.h index 794cbd94a..13fe80348 100644 --- a/src/internet/internetmodel.h +++ b/src/internet/internetmodel.h @@ -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 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 shown_services() const { + return shown_services_; + } signals: void StreamError(const QString& message); @@ -167,6 +180,9 @@ signals: void ServiceDeleted(); private: + + QMap shown_services_; + static QMap* sServices; Application* app_; diff --git a/src/internet/internetshowsettingspage.cpp b/src/internet/internetshowsettingspage.cpp new file mode 100644 index 000000000..baba3887f --- /dev/null +++ b/src/internet/internetshowsettingspage.cpp @@ -0,0 +1,73 @@ +/* This file is part of Clementine. + Copyright 2011, David Sansome + + 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 . +*/ + +#include "internetshowsettingspage.h" + +#include "core/application.h" +#include "ui/settingsdialog.h" +#include "internetservice.h" +#include "internetmodel.h" + +#include + +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 shown_services = + dialog()->app()->internet_model()->shown_services(); + + ui_->sources->clear(); + + for (QMap::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(); +} diff --git a/src/internet/internetshowsettingspage.h b/src/internet/internetshowsettingspage.h new file mode 100644 index 000000000..b9afdc994 --- /dev/null +++ b/src/internet/internetshowsettingspage.h @@ -0,0 +1,43 @@ +/* This file is part of Clementine. + Copyright 2011, David Sansome + + 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 . +*/ + +#ifndef INTERNETSHOWSETTINGSPAGE_H +#define INTERNETSHOWSETTINGSPAGE_H + +#include "ui/settingspage.h" +#include "ui_internetshowsettingspage.h" + +#include + +class QTreeWidgetItem; +class Ui_InternetShowSettingsPage; + +class InternetShowSettingsPage : public SettingsPage { + Q_OBJECT + + public: + InternetShowSettingsPage(SettingsDialog* dialog); + + void Load(); + void Save(); + + private: + std::unique_ptr ui_; + QIcon warning_icon_; +}; + +#endif // INTERNETSHOWSETTINGSPAGE_H diff --git a/src/internet/internetshowsettingspage.ui b/src/internet/internetshowsettingspage.ui new file mode 100644 index 000000000..7b019a029 --- /dev/null +++ b/src/internet/internetshowsettingspage.ui @@ -0,0 +1,82 @@ + + + InternetShowSettingsPage + + + + 0 + 0 + 654 + 506 + + + + Internet services + + + + :/icons/32x32/internet-services.png:/icons/32x32/internet-services.png + + + + + + Sources + + + + + + Choose the internet services you want to show. + + + true + + + + + + + + + Qt::ScrollBarAlwaysOff + + + false + + + 2 + + + false + + + false + + + + 1 + + + + + 2 + + + + + + + + + + + + + sources + + + + + + diff --git a/src/ui/settingsdialog.cpp b/src/ui/settingsdialog.cpp index b23017a35..6cd09ae85 100644 --- a/src/ui/settingsdialog.cpp +++ b/src/ui/settingsdialog.cpp @@ -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 #include #include @@ -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")); diff --git a/src/ui/settingsdialog.h b/src/ui/settingsdialog.h index d3d913c71..2c4a29db6 100644 --- a/src/ui/settingsdialog.h +++ b/src/ui/settingsdialog.h @@ -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 };