From ae8a420690fb8e17eee764687736e9bb9891b856 Mon Sep 17 00:00:00 2001 From: Jim Broadus Date: Wed, 31 Mar 2021 23:25:49 -0700 Subject: [PATCH] settings: Move AddPage to SettingsCategory This will allow future subclasses of SettingsCategory to populate their own pages. --- src/ui/settingscategory.cpp | 16 ++++++++ src/ui/settingscategory.h | 2 + src/ui/settingsdialog.cpp | 75 ++++++++++++++----------------------- src/ui/settingsdialog.h | 1 - 4 files changed, 46 insertions(+), 48 deletions(-) diff --git a/src/ui/settingscategory.cpp b/src/ui/settingscategory.cpp index bdde0063a..df59ae7d8 100644 --- a/src/ui/settingscategory.cpp +++ b/src/ui/settingscategory.cpp @@ -34,3 +34,19 @@ SettingsCategory::SettingsCategory(SettingsDialog::Page id, SettingsPage* page, setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); dialog->AddPageToStack(id, page, this); } + +void SettingsCategory::AddPage(SettingsDialog::Page id, SettingsPage* page) { + // Create the list item + QTreeWidgetItem* item = new QTreeWidgetItem; + item->setText(0, page->windowTitle()); + item->setIcon(0, page->windowIcon()); + item->setData(0, SettingsDialog::Role_IsSeparator, false); + + if (!page->IsEnabled()) { + item->setFlags(Qt::NoItemFlags); + } + + addChild(item); + + dialog_->AddPageToStack(id, page, item); +} diff --git a/src/ui/settingscategory.h b/src/ui/settingscategory.h index e6d7956e6..b7902689d 100644 --- a/src/ui/settingscategory.h +++ b/src/ui/settingscategory.h @@ -30,6 +30,8 @@ class SettingsCategory : public QTreeWidgetItem { SettingsCategory(SettingsDialog::Page id, SettingsPage* page, SettingsDialog* dialog); + void AddPage(SettingsDialog::Page id, SettingsPage* page); + protected: SettingsDialog* dialog_; }; diff --git a/src/ui/settingsdialog.cpp b/src/ui/settingsdialog.cpp index 038245597..28f78d714 100644 --- a/src/ui/settingsdialog.cpp +++ b/src/ui/settingsdialog.cpp @@ -138,18 +138,18 @@ SettingsDialog::SettingsDialog(Application* app, BackgroundStreams* streams, SettingsCategory* general = new SettingsCategory(tr("General"), this); AddCategory(general); - AddPage(Page_Playback, new PlaybackSettingsPage(this), general); - AddPage(Page_Behaviour, new BehaviourSettingsPage(this), general); - AddPage(Page_Library, new LibrarySettingsPage(this), general); - AddPage(Page_BackgroundStreams, new BackgroundStreamsSettingsPage(this), - general); - AddPage(Page_Proxy, new NetworkProxySettingsPage(this), general); - AddPage(Page_Transcoding, new TranscoderSettingsPage(this), general); - AddPage(Page_NetworkRemote, new NetworkRemoteSettingsPage(this), general); + general->AddPage(Page_Playback, new PlaybackSettingsPage(this)); + general->AddPage(Page_Behaviour, new BehaviourSettingsPage(this)); + general->AddPage(Page_Library, new LibrarySettingsPage(this)); + general->AddPage(Page_BackgroundStreams, + new BackgroundStreamsSettingsPage(this)); + general->AddPage(Page_Proxy, new NetworkProxySettingsPage(this)); + general->AddPage(Page_Transcoding, new TranscoderSettingsPage(this)); + general->AddPage(Page_NetworkRemote, new NetworkRemoteSettingsPage(this)); #ifdef HAVE_WIIMOTEDEV WiimoteSettingsPage* wii_page = new WiimoteSettingsPage(this); - AddPage(Page_Wiimotedev, wii_page, general); + general->AddPage(Page_Wiimotedev, wii_page); connect(wii_page, SIGNAL(SetWiimotedevInterfaceActived(bool)), SIGNAL(SetWiimotedevInterfaceActived(bool))); #endif @@ -157,14 +157,14 @@ SettingsDialog::SettingsDialog(Application* app, BackgroundStreams* streams, // User interface SettingsCategory* iface = new SettingsCategory(tr("User interface"), this); AddCategory(iface); - AddPage(Page_GlobalShortcuts, new GlobalShortcutsSettingsPage(this), iface); - AddPage(Page_GlobalSearch, new GlobalSearchSettingsPage(this), iface); - AddPage(Page_Appearance, new AppearanceSettingsPage(this), iface); - AddPage(Page_SongInformation, new SongInfoSettingsPage(this), iface); + iface->AddPage(Page_GlobalShortcuts, new GlobalShortcutsSettingsPage(this)); + iface->AddPage(Page_GlobalSearch, new GlobalSearchSettingsPage(this)); + iface->AddPage(Page_Appearance, new AppearanceSettingsPage(this)); + iface->AddPage(Page_SongInformation, new SongInfoSettingsPage(this)); NotificationsSettingsPage* notification_page = new NotificationsSettingsPage(this); - AddPage(Page_Notifications, notification_page, iface); + iface->AddPage(Page_Notifications, notification_page); connect(notification_page, SIGNAL(NotificationPreview(OSD::Behaviour, QString, QString)), SIGNAL(NotificationPreview(OSD::Behaviour, QString, QString))); @@ -176,43 +176,43 @@ SettingsDialog::SettingsDialog(Application* app, BackgroundStreams* streams, AddCategory(providers); #ifdef HAVE_LIBLASTFM - AddPage(Page_Lastfm, new LastFMSettingsPage(this), providers); + providers->AddPage(Page_Lastfm, new LastFMSettingsPage(this)); #endif #ifdef HAVE_GOOGLE_DRIVE - AddPage(Page_GoogleDrive, new GoogleDriveSettingsPage(this), providers); + providers->AddPage(Page_GoogleDrive, new GoogleDriveSettingsPage(this)); #endif #ifdef HAVE_DROPBOX - AddPage(Page_Dropbox, new DropboxSettingsPage(this), providers); + providers->AddPage(Page_Dropbox, new DropboxSettingsPage(this)); #endif #ifdef HAVE_BOX - AddPage(Page_Box, new BoxSettingsPage(this), providers); + providers->AddPage(Page_Box, new BoxSettingsPage(this)); #endif #ifdef HAVE_SKYDRIVE - AddPage(Page_Skydrive, new SkydriveSettingsPage(this), providers); + providers->AddPage(Page_Skydrive, new SkydriveSettingsPage(this)); #endif #ifdef HAVE_SPOTIFY - AddPage(Page_Spotify, new SpotifySettingsPage(this), providers); + providers->AddPage(Page_Spotify, new SpotifySettingsPage(this)); #endif #ifdef HAVE_SEAFILE - AddPage(Page_Seafile, new SeafileSettingsPage(this), providers); + providers->AddPage(Page_Seafile, new SeafileSettingsPage(this)); #endif #ifdef HAVE_AMAZON_CLOUD_DRIVE - AddPage(Page_AmazonCloudDrive, new AmazonSettingsPage(this), providers); + providers->AddPage(Page_AmazonCloudDrive, new AmazonSettingsPage(this)); #endif - AddPage(Page_Magnatune, new MagnatuneSettingsPage(this), providers); - AddPage(Page_DigitallyImported, new DigitallyImportedSettingsPage(this), - providers); - AddPage(Page_Subsonic, new SubsonicSettingsPage(this), providers); - AddPage(Page_Podcasts, new PodcastSettingsPage(this), providers); - AddPage(Page_RadioBrowser, new RadioBrowserSettingsPage(this), providers); + providers->AddPage(Page_Magnatune, new MagnatuneSettingsPage(this)); + providers->AddPage(Page_DigitallyImported, + new DigitallyImportedSettingsPage(this)); + providers->AddPage(Page_Subsonic, new SubsonicSettingsPage(this)); + providers->AddPage(Page_Podcasts, new PodcastSettingsPage(this)); + providers->AddPage(Page_RadioBrowser, new RadioBrowserSettingsPage(this)); providers->sortChildren(0, Qt::AscendingOrder); @@ -238,25 +238,6 @@ void SettingsDialog::AddCategory(SettingsCategory* category) { category->setExpanded(true); } -void SettingsDialog::AddPage(Page id, SettingsPage* page, - QTreeWidgetItem* parent) { - if (!parent) parent = ui_->list->invisibleRootItem(); - - // Create the list item - QTreeWidgetItem* item = new QTreeWidgetItem; - item->setText(0, page->windowTitle()); - item->setIcon(0, page->windowIcon()); - item->setData(0, Role_IsSeparator, false); - - if (!page->IsEnabled()) { - item->setFlags(Qt::NoItemFlags); - } - - parent->addChild(item); - - AddPageToStack(id, page, item); -} - void SettingsDialog::AddPageToStack(Page id, SettingsPage* page, QTreeWidgetItem* item) { // Create a scroll area containing the page diff --git a/src/ui/settingsdialog.h b/src/ui/settingsdialog.h index fdcc1eb31..c869e02cd 100644 --- a/src/ui/settingsdialog.h +++ b/src/ui/settingsdialog.h @@ -134,7 +134,6 @@ class SettingsDialog : public QDialog { }; void AddCategory(SettingsCategory* category); - void AddPage(Page id, SettingsPage* page, QTreeWidgetItem* parent = nullptr); private: friend class SettingsCategory;