From 5e66d268d985552aeeae3e9ae7d0967d359a557f Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Sat, 13 Jan 2024 14:58:06 -0700 Subject: [PATCH] Move the Settings Dialog to its own class. https://redmine.stoutner.com/issues/1151 --- src/dialogs/AddBookmarkDialog.cpp | 5 +- src/dialogs/AddBookmarkDialog.h | 4 +- src/dialogs/AddFolderDialog.cpp | 4 +- src/dialogs/AddFolderDialog.h | 4 +- src/dialogs/AddOrEditCookieDialog.cpp | 4 +- src/dialogs/AddOrEditCookieDialog.h | 4 +- src/dialogs/BookmarksDialog.cpp | 18 +- src/dialogs/BookmarksDialog.h | 8 +- src/dialogs/CMakeLists.txt | 3 +- src/dialogs/CookiesDialog.cpp | 14 +- src/dialogs/CookiesDialog.h | 8 +- src/dialogs/DomainSettingsDialog.cpp | 2 +- src/dialogs/DomainSettingsDialog.h | 2 +- src/dialogs/DurableCookiesDialog.cpp | 4 +- src/dialogs/DurableCookiesDialog.h | 4 +- src/dialogs/EditBookmarkDialog.cpp | 4 +- src/dialogs/EditBookmarkDialog.h | 4 +- src/dialogs/EditFolderDialog.cpp | 4 +- src/dialogs/EditFolderDialog.h | 4 +- src/dialogs/SaveDialog.cpp | 6 +- src/dialogs/SaveDialog.h | 4 +- src/dialogs/SettingsDialog.cpp | 231 ++++++++++++++++++++++++ src/dialogs/SettingsDialog.h | 53 ++++++ src/widgets/TabWidget.cpp | 4 +- src/widgets/TabWidget.h | 2 +- src/windows/BrowserWindow.cpp | 244 +++----------------------- src/windows/BrowserWindow.h | 13 +- 27 files changed, 372 insertions(+), 289 deletions(-) create mode 100644 src/dialogs/SettingsDialog.cpp create mode 100644 src/dialogs/SettingsDialog.h diff --git a/src/dialogs/AddBookmarkDialog.cpp b/src/dialogs/AddBookmarkDialog.cpp index 4c91c2c..e35759b 100644 --- a/src/dialogs/AddBookmarkDialog.cpp +++ b/src/dialogs/AddBookmarkDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2023 Soren Stoutner . + * Copyright 2023-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -30,7 +30,8 @@ #include // Construct the class. -AddBookmarkDialog::AddBookmarkDialog(const QString &bookmarkName, const QString &bookmarkUrl, const QIcon &favoriteIcon, const double parentFolderId) : QDialog(nullptr) +AddBookmarkDialog::AddBookmarkDialog(QWidget *parentWidgetPointer, const QString &bookmarkName, const QString &bookmarkUrl, const QIcon &favoriteIcon, const double parentFolderId) : + QDialog(parentWidgetPointer) { // Set the window title. setWindowTitle(i18nc("The add bookmark dialog window title.", "Add Bookmark")); diff --git a/src/dialogs/AddBookmarkDialog.h b/src/dialogs/AddBookmarkDialog.h index 311f139..7d38628 100644 --- a/src/dialogs/AddBookmarkDialog.h +++ b/src/dialogs/AddBookmarkDialog.h @@ -1,5 +1,5 @@ /* - * Copyright 2023 Soren Stoutner . + * Copyright 2023-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -36,7 +36,7 @@ class AddBookmarkDialog : public QDialog public: // The primary constructor. - explicit AddBookmarkDialog(const QString &bookmarkName, const QString &bookmarkUrl, const QIcon &favoriteIcon, const double parentFolderId); + explicit AddBookmarkDialog(QWidget *parentWidgetPointer, const QString &bookmarkName, const QString &bookmarkUrl, const QIcon &favoriteIcon, const double parentFolderId); signals: // The signals. diff --git a/src/dialogs/AddFolderDialog.cpp b/src/dialogs/AddFolderDialog.cpp index ec41ce3..7462930 100644 --- a/src/dialogs/AddFolderDialog.cpp +++ b/src/dialogs/AddFolderDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2023 Soren Stoutner . + * Copyright 2023-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -28,7 +28,7 @@ #include // Construct the class. -AddFolderDialog::AddFolderDialog(const QIcon ¤tWebsiteFavoriteIcon, const double parentFolderId) : QDialog(nullptr) +AddFolderDialog::AddFolderDialog(QWidget *parentWidgetPointer, const QIcon ¤tWebsiteFavoriteIcon, const double parentFolderId) : QDialog(parentWidgetPointer) { // Set the window title. setWindowTitle(i18nc("The add folder dialog window title.", "Add Folder")); diff --git a/src/dialogs/AddFolderDialog.h b/src/dialogs/AddFolderDialog.h index 3397b68..e0673a3 100644 --- a/src/dialogs/AddFolderDialog.h +++ b/src/dialogs/AddFolderDialog.h @@ -1,5 +1,5 @@ /* - * Copyright 2023 Soren Stoutner . + * Copyright 2023-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -36,7 +36,7 @@ class AddFolderDialog : public QDialog public: // The primary constructor. - explicit AddFolderDialog(const QIcon ¤tWebsiteFavoriteIcon, const double parentFolderId); + explicit AddFolderDialog(QWidget *parentWidgetPointer, const QIcon ¤tWebsiteFavoriteIcon, const double parentFolderId); signals: // The signals. diff --git a/src/dialogs/AddOrEditCookieDialog.cpp b/src/dialogs/AddOrEditCookieDialog.cpp index eba44b8..bb07c42 100644 --- a/src/dialogs/AddOrEditCookieDialog.cpp +++ b/src/dialogs/AddOrEditCookieDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Soren Stoutner . + * Copyright 2022-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -34,7 +34,7 @@ const int AddOrEditCookieDialog::AddCookie = 0; const int AddOrEditCookieDialog::EditCookie = 1; // Construct the class. -AddOrEditCookieDialog::AddOrEditCookieDialog(const int &dialogType, const QNetworkCookie *cookiePointer, const bool &isDurable) : QDialog(nullptr) +AddOrEditCookieDialog::AddOrEditCookieDialog(QWidget *parentWidgetPointer, const int dialogType, const QNetworkCookie *cookiePointer, const bool isDurable) : QDialog(parentWidgetPointer) { // Set the dialog window title according to the dialog type. if (dialogType == AddCookie) diff --git a/src/dialogs/AddOrEditCookieDialog.h b/src/dialogs/AddOrEditCookieDialog.h index 895b14a..cb641c9 100644 --- a/src/dialogs/AddOrEditCookieDialog.h +++ b/src/dialogs/AddOrEditCookieDialog.h @@ -1,5 +1,5 @@ /* - * Copyright 2022 Soren Stoutner . + * Copyright 2022, 2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -33,7 +33,7 @@ class AddOrEditCookieDialog : public QDialog public: // The primary constructor. - explicit AddOrEditCookieDialog(const int &dialogType, const QNetworkCookie *cookiePointer = nullptr, const bool &isDurable = false); + explicit AddOrEditCookieDialog(QWidget *parentWidgetPointer, const int dialogType, const QNetworkCookie *cookiePointer = nullptr, const bool isDurable = false); // The public static constants. static const int AddCookie; diff --git a/src/dialogs/BookmarksDialog.cpp b/src/dialogs/BookmarksDialog.cpp index 0fa2b4f..683d240 100644 --- a/src/dialogs/BookmarksDialog.cpp +++ b/src/dialogs/BookmarksDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2023 Soren Stoutner . + * Copyright 2023-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -34,8 +34,8 @@ #include // Construct the class. -BookmarksDialog::BookmarksDialog(QString currentWebsiteTitle, QString currentWebsiteUrl, QIcon currentWebsiteFavorieIcon) : - QDialog(nullptr), websiteFavoriteIcon(currentWebsiteFavorieIcon), websiteTitle(currentWebsiteTitle), websiteUrl(currentWebsiteUrl) +BookmarksDialog::BookmarksDialog(QWidget *parentWidgetPointer, QIcon currentWebsiteFavorieIcon, QString currentWebsiteTitle, QString currentWebsiteUrl) : + QDialog(parentWidgetPointer), websiteFavoriteIcon(currentWebsiteFavorieIcon), websiteTitle(currentWebsiteTitle), websiteUrl(currentWebsiteUrl) { // Set the dialog window title. setWindowTitle(i18nc("The bookmarks dialog window title", "Bookmarks")); @@ -301,7 +301,7 @@ void BookmarksDialog::selectSubfolderContents(const QModelIndex &parentModelInde } } -void BookmarksDialog::showAddBookmarkDialog() const +void BookmarksDialog::showAddBookmarkDialog() { // Return the most recently selected index. QModelIndex currentIndex = treeSelectionModelPointer->currentIndex(); @@ -322,7 +322,7 @@ void BookmarksDialog::showAddBookmarkDialog() const } // Instantiate an add bookmark dialog. - AddBookmarkDialog *addBookmarkDialogPointer = new AddBookmarkDialog(websiteTitle, websiteUrl, websiteFavoriteIcon, parentFolderId); + AddBookmarkDialog *addBookmarkDialogPointer = new AddBookmarkDialog(this, websiteTitle, websiteUrl, websiteFavoriteIcon, parentFolderId); // Update the displayed bookmarks when a new one is added. connect(addBookmarkDialogPointer, SIGNAL(bookmarkAdded()), this, SLOT(refreshBookmarks())); @@ -331,7 +331,7 @@ void BookmarksDialog::showAddBookmarkDialog() const addBookmarkDialogPointer->show(); } -void BookmarksDialog::showAddFolderDialog() const +void BookmarksDialog::showAddFolderDialog() { // Get the most recently selected index. QModelIndex currentIndex = treeSelectionModelPointer->currentIndex(); @@ -352,7 +352,7 @@ void BookmarksDialog::showAddFolderDialog() const } // Instantiate an add folder dialog. - AddFolderDialog *addFolderDialogPointer = new AddFolderDialog(websiteFavoriteIcon, parentFolderId); + AddFolderDialog *addFolderDialogPointer = new AddFolderDialog(this, websiteFavoriteIcon, parentFolderId); // Update the displayed bookmarks when a folder is added. connect(addFolderDialogPointer, SIGNAL(folderAdded()), this, SLOT(refreshBookmarks())); @@ -370,7 +370,7 @@ void BookmarksDialog::showEditDialog() if (currentIndex.siblingAtColumn(IS_FOLDER_COLUMN).data().toInt() == 1) // The selected item is a folder. { // Instantiate an edit folder dialog. - QDialog *editFolderDialogPointer = new EditFolderDialog(currentIndex.siblingAtColumn(DATABASE_ID_COLUMN).data().toInt(), websiteFavoriteIcon); + QDialog *editFolderDialogPointer = new EditFolderDialog(this, currentIndex.siblingAtColumn(DATABASE_ID_COLUMN).data().toInt(), websiteFavoriteIcon); // Show the dialog. editFolderDialogPointer->show(); @@ -381,7 +381,7 @@ void BookmarksDialog::showEditDialog() else // The selected item is a bookmark. { // Instantiate an edit bookmark dialog. - QDialog *editBookmarkDialogPointer = new EditBookmarkDialog(currentIndex.siblingAtColumn(DATABASE_ID_COLUMN).data().toInt(), websiteFavoriteIcon); + QDialog *editBookmarkDialogPointer = new EditBookmarkDialog(this, currentIndex.siblingAtColumn(DATABASE_ID_COLUMN).data().toInt(), websiteFavoriteIcon); // Show the dialog. editBookmarkDialogPointer->show(); diff --git a/src/dialogs/BookmarksDialog.h b/src/dialogs/BookmarksDialog.h index 78a4896..0df0903 100644 --- a/src/dialogs/BookmarksDialog.h +++ b/src/dialogs/BookmarksDialog.h @@ -1,5 +1,5 @@ /* - * Copyright 2023 Soren Stoutner . + * Copyright 2023-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -36,7 +36,7 @@ class BookmarksDialog : public QDialog public: // The primary constructor. - explicit BookmarksDialog(QString currentWebsiteTitle, QString currentWebsiteUrl, QIcon currentWebsiteFavoriteIcon); + BookmarksDialog(QWidget *parentWidgetPointer, QIcon currentWebsiteFavorieIcon, QString currentWebsiteTitle, QString currentWebsiteUrl); // The public constants. static const int NAME_COLUMN = 0; @@ -54,8 +54,8 @@ private Q_SLOTS: // The private slots. void deleteItems() const; void refreshBookmarks() const; - void showAddBookmarkDialog() const; - void showAddFolderDialog() const; + void showAddBookmarkDialog(); + void showAddFolderDialog(); void showEditDialog(); void updateBookmarkFromTree(QStandardItem *modifiedStandardItem); void updateSelection() const; diff --git a/src/dialogs/CMakeLists.txt b/src/dialogs/CMakeLists.txt index 4b72f5c..32ac523 100644 --- a/src/dialogs/CMakeLists.txt +++ b/src/dialogs/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2022-2023 Soren Stoutner . +# Copyright 2022-2024 Soren Stoutner . # # This file is part of Privacy Browser PC . # @@ -28,4 +28,5 @@ target_sources(privacybrowser PRIVATE EditBookmarkDialog.cpp EditFolderDialog.cpp SaveDialog.cpp + SettingsDialog.cpp ) diff --git a/src/dialogs/CookiesDialog.cpp b/src/dialogs/CookiesDialog.cpp index 4ca8c1c..57e5ed7 100644 --- a/src/dialogs/CookiesDialog.cpp +++ b/src/dialogs/CookiesDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Soren Stoutner . + * Copyright 2022-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -594,10 +594,10 @@ void CookiesDialog::deleteCookieFromDialog(const QNetworkCookie &cookie) const emit deleteCookie(cookie); } -void CookiesDialog::showAddCookieDialog() const +void CookiesDialog::showAddCookieDialog() { // Instantiate an add cookie dialog. - QDialog *addCookieDialogPointer = new AddOrEditCookieDialog(AddOrEditCookieDialog::AddCookie); + QDialog *addCookieDialogPointer = new AddOrEditCookieDialog(this, AddOrEditCookieDialog::AddCookie); // Show the dialog. addCookieDialogPointer->show(); @@ -744,10 +744,10 @@ void CookiesDialog::showDeleteCookieMessageBox() const } } -void CookiesDialog::showDurableCookiesDialog() const +void CookiesDialog::showDurableCookiesDialog() { // Instantiate a durable cookies dialog. - QDialog *durableCookiesDialogPointer = new DurableCookiesDialog(); + QDialog *durableCookiesDialogPointer = new DurableCookiesDialog(this); // Show the dialog. durableCookiesDialogPointer->show(); @@ -758,7 +758,7 @@ void CookiesDialog::showDurableCookiesDialog() const connect(durableCookiesDialogPointer, SIGNAL(updateParentUi()), this, SLOT(updateUi())); } -void CookiesDialog::showEditCookieDialog() const +void CookiesDialog::showEditCookieDialog() { // Get the current model index. QModelIndex currentIndex = treeSelectionModelPointer->currentIndex(); @@ -783,7 +783,7 @@ void CookiesDialog::showEditCookieDialog() const } // Instantiate an edit cookie dialog. - QDialog *editCookieDialogPointer = new AddOrEditCookieDialog(AddOrEditCookieDialog::EditCookie, &cookieToEdit, currentIndex.siblingAtColumn(1).data().toString() == i18n("yes")); + QDialog *editCookieDialogPointer = new AddOrEditCookieDialog(this, AddOrEditCookieDialog::EditCookie, &cookieToEdit, currentIndex.siblingAtColumn(1).data().toString() == i18n("yes")); // Show the dialog. editCookieDialogPointer->show(); diff --git a/src/dialogs/CookiesDialog.h b/src/dialogs/CookiesDialog.h index be4acda..5319897 100644 --- a/src/dialogs/CookiesDialog.h +++ b/src/dialogs/CookiesDialog.h @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Soren Stoutner . + * Copyright 2022-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -50,11 +50,11 @@ private Q_SLOTS: void addCookieFromDialog(const QNetworkCookie &cookie, const bool &isDurable) const; void deleteCookieFromDatabase(const QNetworkCookie &cookie) const; void deleteCookieFromDialog(const QNetworkCookie &cookie) const; - void showAddCookieDialog() const; + void showAddCookieDialog(); void showDeleteAllMessageBox() const; void showDeleteCookieMessageBox() const; - void showDurableCookiesDialog() const; - void showEditCookieDialog() const; + void showDurableCookiesDialog(); + void showEditCookieDialog(); void updateUi() const; private: diff --git a/src/dialogs/DomainSettingsDialog.cpp b/src/dialogs/DomainSettingsDialog.cpp index 13791f0..0907a18 100644 --- a/src/dialogs/DomainSettingsDialog.cpp +++ b/src/dialogs/DomainSettingsDialog.cpp @@ -34,7 +34,7 @@ const int DomainSettingsDialog::SHOW_ALL_DOMAINS = 0; const int DomainSettingsDialog::EDIT_DOMAIN = 1; // Construct the class. -DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString &domainName) : QDialog(nullptr) +DomainSettingsDialog::DomainSettingsDialog(QWidget *parentWidgetPointer, const int &startType, const QString &domainName) : QDialog(parentWidgetPointer) { // Set the window title. setWindowTitle(i18nc("The domain settings dialog window title", "Domain Settings")); diff --git a/src/dialogs/DomainSettingsDialog.h b/src/dialogs/DomainSettingsDialog.h index 1537016..a78d6e3 100644 --- a/src/dialogs/DomainSettingsDialog.h +++ b/src/dialogs/DomainSettingsDialog.h @@ -39,7 +39,7 @@ class DomainSettingsDialog : public QDialog public: // The primary constructor. - explicit DomainSettingsDialog(const int &startType = SHOW_ALL_DOMAINS, const QString &domainName = QStringLiteral("")); + explicit DomainSettingsDialog(QWidget *parentWidgetPointer, const int &startType = SHOW_ALL_DOMAINS, const QString &domainName = QStringLiteral("")); // The public static int constants. static const int SHOW_ALL_DOMAINS; diff --git a/src/dialogs/DurableCookiesDialog.cpp b/src/dialogs/DurableCookiesDialog.cpp index abc21e9..f076985 100644 --- a/src/dialogs/DurableCookiesDialog.cpp +++ b/src/dialogs/DurableCookiesDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Soren Stoutner . + * Copyright 2022-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -26,7 +26,7 @@ // KDE Frameworks headers. #include -DurableCookiesDialog::DurableCookiesDialog() : QDialog(nullptr) +DurableCookiesDialog::DurableCookiesDialog(QWidget *parentWidgetPointer) : QDialog(parentWidgetPointer) { // Set the dialog window title. setWindowTitle(i18nc("The durable cookies dialog window title", "Durable Cookies")); diff --git a/src/dialogs/DurableCookiesDialog.h b/src/dialogs/DurableCookiesDialog.h index e611d58..64294f8 100644 --- a/src/dialogs/DurableCookiesDialog.h +++ b/src/dialogs/DurableCookiesDialog.h @@ -1,5 +1,5 @@ /* - * Copyright © 2022 Soren Stoutner . + * Copyright 2022, 2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -33,7 +33,7 @@ class DurableCookiesDialog : public QDialog public: // The default constructor. - explicit DurableCookiesDialog(); + explicit DurableCookiesDialog(QWidget *parentWidgetPointer); signals: // The signals. diff --git a/src/dialogs/EditBookmarkDialog.cpp b/src/dialogs/EditBookmarkDialog.cpp index a0c0c77..bad010e 100644 --- a/src/dialogs/EditBookmarkDialog.cpp +++ b/src/dialogs/EditBookmarkDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2023 Soren Stoutner . + * Copyright 2023-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -26,7 +26,7 @@ #include // Construct the class. -EditBookmarkDialog::EditBookmarkDialog(const int databaseId, QIcon ¤tWebsiteFavoriteIcon) : QDialog(nullptr), bookmarkDatabaseId(databaseId) +EditBookmarkDialog::EditBookmarkDialog(QWidget *parentWidgetPointer, const int databaseId, QIcon ¤tWebsiteFavoriteIcon) : QDialog(parentWidgetPointer), bookmarkDatabaseId(databaseId) { // Set the window title. setWindowTitle(i18nc("The edit bookmark dialog window title.", "Edit Bookmark")); diff --git a/src/dialogs/EditBookmarkDialog.h b/src/dialogs/EditBookmarkDialog.h index bbba43e..f862bc0 100644 --- a/src/dialogs/EditBookmarkDialog.h +++ b/src/dialogs/EditBookmarkDialog.h @@ -1,5 +1,5 @@ /* - * Copyright 2023 Soren Stoutner . + * Copyright 2023-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -36,7 +36,7 @@ class EditBookmarkDialog : public QDialog public: // The primary constructor. - explicit EditBookmarkDialog(const int databaseId, QIcon ¤tWebsiteFavoriteIcon); + explicit EditBookmarkDialog(QWidget *parentWidgetPointer, const int databaseId, QIcon ¤tWebsiteFavoriteIcon); signals: // The signals. diff --git a/src/dialogs/EditFolderDialog.cpp b/src/dialogs/EditFolderDialog.cpp index 4285444..950e502 100644 --- a/src/dialogs/EditFolderDialog.cpp +++ b/src/dialogs/EditFolderDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2023 Soren Stoutner . + * Copyright 2023-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -26,7 +26,7 @@ #include // Construct the class. -EditFolderDialog::EditFolderDialog(const int databaseId, QIcon ¤tWebsiteFavoriteIcon) : QDialog(nullptr), folderDatabaseId(databaseId) +EditFolderDialog::EditFolderDialog(QWidget *parentWidgetPointer, const int databaseId, QIcon ¤tWebsiteFavoriteIcon) : QDialog(parentWidgetPointer), folderDatabaseId(databaseId) { // Set the window title. setWindowTitle(i18nc("The edit folder dialog window title.", "Edit Folder")); diff --git a/src/dialogs/EditFolderDialog.h b/src/dialogs/EditFolderDialog.h index ac203d8..8f38324 100644 --- a/src/dialogs/EditFolderDialog.h +++ b/src/dialogs/EditFolderDialog.h @@ -1,5 +1,5 @@ /* - * Copyright 2023 Soren Stoutner . + * Copyright 2023-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -35,7 +35,7 @@ class EditFolderDialog : public QDialog public: // The primary constructor. - explicit EditFolderDialog(const int databaseId, QIcon ¤tWebsiteFavoriteIcon); + explicit EditFolderDialog(QWidget *parentWidgetPointer, const int databaseId, QIcon ¤tWebsiteFavoriteIcon); signals: // The signals. diff --git a/src/dialogs/SaveDialog.cpp b/src/dialogs/SaveDialog.cpp index 5e96916..dac011c 100644 --- a/src/dialogs/SaveDialog.cpp +++ b/src/dialogs/SaveDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Soren Stoutner . + * Copyright 2022-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -30,7 +30,8 @@ #include #include -SaveDialog::SaveDialog(QUrl &url, QString &mimeTypeString, int totalBytes, QString fileName, bool nativeDownloader): downloadUrl(url), suggestedFileName(fileName) +SaveDialog::SaveDialog(QWidget *parentWidgetPointer, QUrl &url, QString &mimeTypeString, int totalBytes, QString fileName, bool nativeDownloader) : + QDialog(parentWidgetPointer), downloadUrl(url), suggestedFileName(fileName) { // Set the dialog window title. setWindowTitle(i18nc("The save dialog window title", "Save")); @@ -118,4 +119,3 @@ void SaveDialog::showFilePicker() // Close the dialog. reject(); } - diff --git a/src/dialogs/SaveDialog.h b/src/dialogs/SaveDialog.h index a3ce841..a994d18 100644 --- a/src/dialogs/SaveDialog.h +++ b/src/dialogs/SaveDialog.h @@ -1,5 +1,5 @@ /* - * Copyright 2022 Soren Stoutner . + * Copyright 2022, 2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -32,7 +32,7 @@ class SaveDialog : public QDialog public: // The primary constructor. - explicit SaveDialog(QUrl &url, QString &mimeTypeString, int totalBytes, QString fileName = QString(), bool nativeDownloader = false); + explicit SaveDialog(QWidget *parentWidgetPointer, QUrl &url, QString &mimeTypeString, int totalBytes, QString fileName = QString(), bool nativeDownloader = false); signals: // The signals. diff --git a/src/dialogs/SettingsDialog.cpp b/src/dialogs/SettingsDialog.cpp new file mode 100644 index 0000000..1f3fb79 --- /dev/null +++ b/src/dialogs/SettingsDialog.cpp @@ -0,0 +1,231 @@ +/* + * Copyright 2024 Soren Stoutner . + * + * This file is part of Privacy Browser PC . + * + * Privacy Browser PC 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. + * + * Privacy Browser PC 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 Privacy Browser PC. If not, see . + */ + +// Application headers. +#include "Settings.h" +#include "SettingsDialog.h" +#include "helpers/SearchEngineHelper.h" +#include "helpers/UserAgentHelper.h" +#include "ui_SettingsGeneral.h" +#include "ui_SettingsPrivacy.h" +#include "ui_SettingsSpellCheck.h" + +// Qt toolkit headers. +#include +#include + +SettingsDialog::SettingsDialog(QWidget *parentWidgetPointer, KCoreConfigSkeleton *coreConfigSkeletonPointer) : + KConfigDialog(parentWidgetPointer, QLatin1String("settings"), coreConfigSkeletonPointer) +{ + // Instantiate the settings UI. + Ui::PrivacySettings privacySettingsUi; + Ui::GeneralSettings generalSettingsUi; + Ui::SpellCheckSettings spellCheckSettingsUi; + + // Create the settings widgets. + QWidget *privacySettingsWidgetPointer = new QWidget; + QWidget *generalSettingsWidgetPointer = new QWidget; + QWidget *spellCheckSettingsWidgetPointer = new QWidget; + + // Setup the UI to display the settings widgets. + privacySettingsUi.setupUi(privacySettingsWidgetPointer); + generalSettingsUi.setupUi(generalSettingsWidgetPointer); + spellCheckSettingsUi.setupUi(spellCheckSettingsWidgetPointer); + + // Get handles for the widgets. + QCheckBox *javaScriptCheckBoxPointer = privacySettingsUi.kcfg_javaScriptEnabled; + QCheckBox *localStorageCheckBoxPointer = privacySettingsUi.kcfg_localStorageEnabled; + QCheckBox *domStorageCheckBoxPointer = privacySettingsUi.kcfg_domStorageEnabled; + QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent; + userAgentLabelPointer = privacySettingsUi.userAgentLabel; + QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine; + searchEngineLabelPointer = generalSettingsUi.searchEngineLabel; + downloadDirectoryComboBoxPointer = generalSettingsUi.kcfg_downloadDirectory; + QPushButton *browseButtonPointer = generalSettingsUi.browseButton; + QListWidget *spellCheckListWidgetPointer = spellCheckSettingsUi.spellCheckListWidget; + + // Create a save spell check languages lambda. + auto updateCheckBoxes = [javaScriptCheckBoxPointer, localStorageCheckBoxPointer, domStorageCheckBoxPointer] () + { + // Only enable the DOM storage check box if both JavaScript and local storage are checked. + domStorageCheckBoxPointer->setEnabled(javaScriptCheckBoxPointer->isChecked() && localStorageCheckBoxPointer->isChecked()); + }; + + // Update the status of the DOM storage check box when either JavaScript or local storage are changed. + connect(javaScriptCheckBoxPointer, &QCheckBox::stateChanged, this, updateCheckBoxes); + connect(localStorageCheckBoxPointer, &QCheckBox::stateChanged, this, updateCheckBoxes); + + // Populate the combo box labels. + updateUserAgentLabel(userAgentComboBoxPointer->currentText()); + updateSearchEngineLabel(searchEngineComboBoxPointer->currentText()); + + // Update the labels when the combo boxes change. + connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString))); + connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString))); + + // Connect the download directory directory browse button. + connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(showDownloadDirectoryBrowseDialog())); + + // Create a dictionaries QDir from the `QTWEBENGINE_DICTIONARIES_PATH` environment variable. + QDir dictionariesDir = QDir(qEnvironmentVariable("QTWEBENGINE_DICTIONARIES_PATH")); + + // Get a dictionaries string list. + QStringList dictionariesStringList = dictionariesDir.entryList(QStringList(QLatin1String("*.bdic")), QDir::Files | QDir::NoSymLinks); + + // Remove the `.bdic` file extensions from the dictionaries list. + dictionariesStringList.replaceInStrings(QLatin1String(".bdic"), QLatin1String("")); + + // Get a list of the enabled spell check languages. + QStringList enabledSpellCheckLanguagesList = Settings::spellCheckLanguages(); + + // Add each dictionary to the spell check list widget. + foreach(QString dictionaryString, dictionariesStringList) + { + // Create a new list widget item pointer. + QListWidgetItem *listWidgetItemPointer = new QListWidgetItem(); + + // Create a dictionary check box widget with the name of the dictionary string. + QCheckBox *dictionaryCheckBoxWidget = new QCheckBox(dictionaryString); + + // Check the language if it is currently enabled. + if (enabledSpellCheckLanguagesList.contains(dictionaryString)) + dictionaryCheckBoxWidget->setCheckState(Qt::Checked); + else + dictionaryCheckBoxWidget->setCheckState(Qt::Unchecked); + + // Add the list widget item to the spell check list widget. + spellCheckListWidgetPointer->addItem(listWidgetItemPointer); + + // Set the list widget item check box widget. + spellCheckListWidgetPointer->setItemWidget(listWidgetItemPointer, dictionaryCheckBoxWidget); + } + + // Create a settings icon string. + QString settingsIconString; + + // Get a settings icon that matches the theme. + if (QIcon::hasThemeIcon("breeze-settings")) + { + // KDE uses breeze-settings. + settingsIconString = QLatin1String("breeze-settings"); + } + else + { + // Gnome uses preferences-desktop. + settingsIconString = QLatin1String("preferences-desktop"); + } + + // Add the settings widgets as config dialog pages. + addPage(privacySettingsWidgetPointer, i18nc("Settings tab title", "Privacy"), QLatin1String("privacybrowser")); + addPage(generalSettingsWidgetPointer, i18nc("Settings tab title", "General"), settingsIconString); + addPage(spellCheckSettingsWidgetPointer, i18nc("Settings tab title", "Spell Check"), QLatin1String("tools-check-spelling")); + + // Get handles for the buttons. + QPushButton *applyButtonPointer = button(QDialogButtonBox::Apply); + QPushButton *okButtonPointer = button(QDialogButtonBox::Ok); + + // Prevent interaction with the parent window while the dialog is open. + setWindowModality(Qt::WindowModal); + + // Create a save spell check languages lambda. + auto saveSpellCheckLanguages = [spellCheckListWidgetPointer, coreConfigSkeletonPointer, this] () + { + // Create a list of enabled languages. + QStringList newSpellCheckLanguages = QStringList(); + + // Get a count of all the languages. + int allLanguagesCount = spellCheckListWidgetPointer->count(); + + // Get a list of all the checked languages. + for (int i = 0; i < allLanguagesCount; ++i) { + // Get the language item. + QListWidgetItem *languageItemPointer = spellCheckListWidgetPointer->item(i); + + // Get the language check box. + QCheckBox *languageCheckBoxPointer = qobject_cast(spellCheckListWidgetPointer->itemWidget(languageItemPointer)); + + // Add the item to the enabled languages if it is checked. + if (languageCheckBoxPointer->checkState() == Qt::Checked) + { + // Get the text. + QString languageString = languageCheckBoxPointer->text(); + + // Remove all instances of `&`, which may have been added automatically when creating the check box text. + languageString.remove(QChar('&')); + + // Add the language string to the list. + newSpellCheckLanguages.append(languageString); + } + } + + // Update the spell check languages. + if (Settings::spellCheckLanguages() != newSpellCheckLanguages) + { + // Update the spell check languages. + Settings::setSpellCheckLanguages(newSpellCheckLanguages); + + // Write the settings to disk. + coreConfigSkeletonPointer->save(); + + // Emit the spell check languages updated signal. + emit spellCheckLanguagesUpdated(); + } + }; + + // Process clicks on the buttons. + connect(applyButtonPointer, &QPushButton::clicked, this, saveSpellCheckLanguages); + connect(okButtonPointer, &QPushButton::clicked, this, saveSpellCheckLanguages); +} + +void SettingsDialog::showDownloadDirectoryBrowseDialog() +{ + // Get the current download directory. + QString currentDownloadDirectory = downloadDirectoryComboBoxPointer->currentText(); + + // Resolve the system download directory if specified. + if (currentDownloadDirectory == QStringLiteral("System Download Directory")) + currentDownloadDirectory = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); + + // Get the new download directory. + QString newDownloadDirectory = QFileDialog::getExistingDirectory(this, i18nc("Select download directory dialog caption", "Select Download Directory"), currentDownloadDirectory); + + // Populate the download directory combo box according to the new download location. + if (newDownloadDirectory == QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)) // The default download location was selected. + { + // Populate the download location with the default text. + downloadDirectoryComboBoxPointer->setCurrentText("System Download Directory"); + } + else if (newDownloadDirectory != QStringLiteral("")) // A different directory was selected. + { + // Populate the download location. + downloadDirectoryComboBoxPointer->setCurrentText(newDownloadDirectory); + } +} + +void SettingsDialog::updateSearchEngineLabel(const QString &searchEngineString) const +{ + // Update the search engine label. + searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString)); +} + +void SettingsDialog::updateUserAgentLabel(const QString &userAgentDatabaseName) const +{ + // Update the user agent label. + userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName)); +} diff --git a/src/dialogs/SettingsDialog.h b/src/dialogs/SettingsDialog.h new file mode 100644 index 0000000..bf56e18 --- /dev/null +++ b/src/dialogs/SettingsDialog.h @@ -0,0 +1,53 @@ +/* + * Copyright 2024 Soren Stoutner . + * + * This file is part of Privacy Browser PC . + * + * Privacy Browser PC 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. + * + * Privacy Browser PC 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 Privacy Browser PC. If not, see . + */ + +#ifndef SETTINGSDIALOG_H +#define SETTINGSDIALOG_H + +// KDE Framework headers. +#include + +// Qt toolkit headers. +#include +#include + +class SettingsDialog : public KConfigDialog +{ + // Include the Q_OBJECT macro. + Q_OBJECT + +public: + // The primary constructor. + explicit SettingsDialog(QWidget *parentWidgetPointer, KCoreConfigSkeleton *coreConfigSkeletonPointer); + +signals: + void spellCheckLanguagesUpdated() const; + +private Q_SLOTS: + void showDownloadDirectoryBrowseDialog(); + void updateSearchEngineLabel(const QString &searchEngineString) const; + void updateUserAgentLabel(const QString &userAgentDatabaseName) const; + +private: + // The private variables. + QComboBox *downloadDirectoryComboBoxPointer; + QLabel *searchEngineLabelPointer; + QLabel *userAgentLabelPointer; +}; +#endif diff --git a/src/widgets/TabWidget.cpp b/src/widgets/TabWidget.cpp index 58ccfc6..bdc541c 100644 --- a/src/widgets/TabWidget.cpp +++ b/src/widgets/TabWidget.cpp @@ -967,7 +967,7 @@ void TabWidget::showSaveDialog(QWebEngineDownloadItem *webEngineDownloadItemPoin if (!isRunningKde || currentPrivacyWebEngineViewPointer->localStorageEnabled) // KDE is not running or local storage (cookies) is enabled. Use WebEngine's downloader. { // Instantiate the save dialog. - SaveDialog *saveDialogPointer = new SaveDialog(downloadUrl, mimeTypeString, totalBytes); + SaveDialog *saveDialogPointer = new SaveDialog(this, downloadUrl, mimeTypeString, totalBytes); // Display the save dialog. int saveDialogResult = saveDialogPointer->exec(); @@ -1110,7 +1110,7 @@ void TabWidget::showSaveDialog(QWebEngineDownloadItem *webEngineDownloadItemPoin // This must use the show command to launch a separate dialog which cancels WebEngine's automatic background download of the file to a temporary location. { // Instantiate the save dialog. `true` instructs it to use the native downloader - SaveDialog *saveDialogPointer = new SaveDialog(downloadUrl, mimeTypeString, totalBytes, suggestedFileName, true); + SaveDialog *saveDialogPointer = new SaveDialog(this, downloadUrl, mimeTypeString, totalBytes, suggestedFileName, true); // Connect the save button. connect(saveDialogPointer, SIGNAL(useNativeKdeDownloader(QUrl &, QString &)), this, SLOT(useNativeKdeDownloader(QUrl &, QString &))); diff --git a/src/widgets/TabWidget.h b/src/widgets/TabWidget.h index 7dbb581..4b06c64 100644 --- a/src/widgets/TabWidget.h +++ b/src/widgets/TabWidget.h @@ -52,7 +52,6 @@ public: // The public functions. void applyOnTheFlyZoomFactor(const double zoomFactorDouble) const; - void applySpellCheckLanguages() const; PrivacyWebEngineView* loadBlankInitialWebsite(); void loadInitialWebsite(); void findPrevious(const QString &text) const; @@ -106,6 +105,7 @@ public Q_SLOTS: void applyDomainSettingsAndReload(); void applyOnTheFlySearchEngine(QAction *searchEngineActionPointer); void applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const; + void applySpellCheckLanguages() const; void back() const; void deleteAllCookies() const; void deleteCookieFromStore(const QNetworkCookie &cookie) const; diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index 7533432..88f9894 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -20,9 +20,6 @@ // Application headers. #include "BrowserWindow.h" #include "Settings.h" -#include "ui_SettingsGeneral.h" -#include "ui_SettingsPrivacy.h" -#include "ui_SettingsSpellCheck.h" #include "databases/BookmarksDatabase.h" #include "databases/DomainsDatabase.h" #include "dialogs/AddBookmarkDialog.h" @@ -32,6 +29,7 @@ #include "dialogs/DomainSettingsDialog.h" #include "dialogs/EditBookmarkDialog.h" #include "dialogs/EditFolderDialog.h" +#include "dialogs/SettingsDialog.h" #include "helpers/SearchEngineHelper.h" #include "helpers/UserAgentHelper.h" #include "structs/BookmarkStruct.h" @@ -39,6 +37,7 @@ // KDE Frameworks headers. #include #include +#include #include // Qt toolkit headers. @@ -47,8 +46,9 @@ #include #include #include -#include +#include #include +#include #include #include #include @@ -592,7 +592,7 @@ void BrowserWindow::addFinalBookmarkFolderMenuActions(QMenu *menuPointer, double QAction *addBookmarkActionPointer = menuPointer->addAction(QIcon::fromTheme(QLatin1String("bookmark-new")), i18nc("The add bookmark action", "Add Bookmark"), [=] { // Instantiate an add bookmark dialog. - AddBookmarkDialog *addBookmarkDialogPointer = new AddBookmarkDialog(tabWidgetPointer->getCurrentTabTitle(), tabWidgetPointer->getCurrentTabUrl(), + AddBookmarkDialog *addBookmarkDialogPointer = new AddBookmarkDialog(this, tabWidgetPointer->getCurrentTabTitle(), tabWidgetPointer->getCurrentTabUrl(), tabWidgetPointer->getCurrentTabFavoritIcon(), folderId); // Update the displayed bookmarks when a new one is added. @@ -607,7 +607,7 @@ void BrowserWindow::addFinalBookmarkFolderMenuActions(QMenu *menuPointer, double QAction *addFolderActionPointer = menuPointer->addAction(QIcon::fromTheme(QLatin1String("folder-add")), i18nc("The add folder action", "Add Folder"), [=] { // Instantiate an add folder dialog. - AddFolderDialog *addFolderDialogPointer = new AddFolderDialog(tabWidgetPointer->getCurrentTabFavoritIcon(), folderId); + AddFolderDialog *addFolderDialogPointer = new AddFolderDialog(this, tabWidgetPointer->getCurrentTabFavoritIcon(), folderId); // Update the displayed bookmarks when a folder is added. connect(addFolderDialogPointer, SIGNAL(folderAdded()), this, SLOT(populateBookmarksInAllWindows())); @@ -678,7 +678,7 @@ void BrowserWindow::addFinalBookmarkFolderMenuActions(QMenu *menuPointer, double QIcon currentTabFavoriteIcon = tabWidgetPointer->getCurrentTabFavoritIcon(); // Instantiate an edit folder dialog. - QDialog *editFolderDialogPointer = new EditFolderDialog(folderDatabaseId, currentTabFavoriteIcon); + QDialog *editFolderDialogPointer = new EditFolderDialog(this, folderDatabaseId, currentTabFavoriteIcon); // Show the dialog. editFolderDialogPointer->show(); @@ -769,7 +769,7 @@ void BrowserWindow::addFinalBookmarkFolderMenuActions(QMenu *menuPointer, double finalBookmarkFolderMenuActionList.prepend(new QPair(menuPointer, deleteFolderActionPointer)); } -void BrowserWindow::addOrEditDomainSettings() const +void BrowserWindow::addOrEditDomainSettings() { // Remove the focus from the URL line edit. urlLineEditPointer->clearFocus(); @@ -813,7 +813,7 @@ void BrowserWindow::addOrEditDomainSettings() const } // Create the domain settings dialog pointer. - DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsName); + DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog(this, DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsName); // Reload the tabs when domain settings are updated. connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload())); @@ -864,10 +864,10 @@ void BrowserWindow::decrementZoom() updateZoomActions(currentZoomFactorDouble); } -void BrowserWindow::editBookmarks() const +void BrowserWindow::editBookmarks() { // Instantiate an edit bookmarks dialog. - BookmarksDialog *bookmarksDialogPointer = new BookmarksDialog(tabWidgetPointer->getCurrentTabTitle(), tabWidgetPointer->getCurrentTabUrl(), tabWidgetPointer->getCurrentTabFavoritIcon()); + BookmarksDialog *bookmarksDialogPointer = new BookmarksDialog(this, tabWidgetPointer->getCurrentTabFavoritIcon(), tabWidgetPointer->getCurrentTabTitle(), tabWidgetPointer->getCurrentTabUrl()); // Update the displayed bookmarks when edited. connect(bookmarksDialogPointer, SIGNAL(bookmarkUpdated()), this, SLOT(populateBookmarksInAllWindows())); @@ -1397,7 +1397,7 @@ void BrowserWindow::showBookmarkContextMenu(const QPoint &point) QIcon currentTabFavoriteIcon = tabWidgetPointer->getCurrentTabFavoritIcon(); // Instantiate an edit bookmark dialog. - QDialog *editBookmarkDialogPointer = new EditBookmarkDialog(databaseId, currentTabFavoriteIcon); + QDialog *editBookmarkDialogPointer = new EditBookmarkDialog(this, databaseId, currentTabFavoriteIcon); // Show the dialog. editBookmarkDialogPointer->show(); @@ -1481,39 +1481,13 @@ void BrowserWindow::showCookiesDialog() connect(cookiesDialogPointer, SIGNAL(deleteCookie(QNetworkCookie)), tabWidgetPointer, SLOT(deleteCookieFromStore(QNetworkCookie))); } -void BrowserWindow::showDownloadDirectoryBrowseDialog() const -{ - // Get the current download directory. - QString currentDownloadDirectory = downloadDirectoryComboBoxPointer->currentText(); - - // Resolve the system download directory if specified. - if (currentDownloadDirectory == QStringLiteral("System Download Directory")) - currentDownloadDirectory = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); - - // Get the new download directory. - QString newDownloadDirectory = QFileDialog::getExistingDirectory(configDialogPointer, i18nc("Select download directory dialog caption", "Select Download Directory"), - currentDownloadDirectory); - - // Populate the download directory combo box according to the new download location. - if (newDownloadDirectory == QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)) // The default download location was selected. - { - // Populate the download location with the default text. - downloadDirectoryComboBoxPointer->setCurrentText("System Download Directory"); - } - else if (newDownloadDirectory != QStringLiteral("")) // A different directory was selected. - { - // Populate the download location. - downloadDirectoryComboBoxPointer->setCurrentText(newDownloadDirectory); - } -} - -void BrowserWindow::showDomainSettingsDialog() const +void BrowserWindow::showDomainSettingsDialog() { // Remove the focus from the URL line edit. urlLineEditPointer->clearFocus(); // Instantiate the domain settings dialog. - DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog(); + DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog(this); // Reload the tabs when domain settings are updated. connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload())); @@ -1558,186 +1532,28 @@ void BrowserWindow::showProgressBar(const int &progress) const void BrowserWindow::showSettingsDialog() { - // Create the settings widgets. - QWidget *privacySettingsWidgetPointer = new QWidget; - QWidget *generalSettingsWidgetPointer = new QWidget; - QWidget *spellCheckSettingsWidgetPointer = new QWidget; - - // Instantiate the settings UI. - Ui::PrivacySettings privacySettingsUi; - Ui::GeneralSettings generalSettingsUi; - Ui::SpellCheckSettings spellCheckSettingsUi; - - // Setup the UI to display the settings widgets. - privacySettingsUi.setupUi(privacySettingsWidgetPointer); - generalSettingsUi.setupUi(generalSettingsWidgetPointer); - spellCheckSettingsUi.setupUi(spellCheckSettingsWidgetPointer); - - // Get handles for the widgets. - QCheckBox *javaScriptCheckBoxPointer = privacySettingsUi.kcfg_javaScriptEnabled; - QCheckBox *localStorageCheckBoxPointer = privacySettingsUi.kcfg_localStorageEnabled; - QCheckBox *domStorageCheckBoxPointer = privacySettingsUi.kcfg_domStorageEnabled; - QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent; - userAgentLabelPointer = privacySettingsUi.userAgentLabel; - QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine; - searchEngineLabelPointer = generalSettingsUi.searchEngineLabel; - downloadDirectoryComboBoxPointer = generalSettingsUi.kcfg_downloadDirectory; - QPushButton *browseButtonPointer = generalSettingsUi.browseButton; - QListWidget *spellCheckListWidgetPointer = spellCheckSettingsUi.spellCheckListWidget; - - // Create a save spell check languages lambda. - auto updateCheckBoxes = [javaScriptCheckBoxPointer, localStorageCheckBoxPointer, domStorageCheckBoxPointer] () - { - // Only enable the DOM storage check box if both JavaScript and local storage are checked. - domStorageCheckBoxPointer->setEnabled(javaScriptCheckBoxPointer->isChecked() && localStorageCheckBoxPointer->isChecked()); - }; - - // Update the status of the DOM storage check box when either JavaScript or local storage are changed. - connect(javaScriptCheckBoxPointer, &QCheckBox::stateChanged, this, updateCheckBoxes); - connect(localStorageCheckBoxPointer, &QCheckBox::stateChanged, this, updateCheckBoxes); - - // Populate the combo box labels. - updateUserAgentLabel(userAgentComboBoxPointer->currentText()); - updateSearchEngineLabel(searchEngineComboBoxPointer->currentText()); - - // Update the labels when the combo boxes change. - connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString))); - connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString))); - - // Connect the download directory directory browse button. - connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(showDownloadDirectoryBrowseDialog())); - - // Create a dictionaries QDir from the `QTWEBENGINE_DICTIONARIES_PATH` environment variable. - QDir dictionariesDir = QDir(qEnvironmentVariable("QTWEBENGINE_DICTIONARIES_PATH")); - - // Get a dictionaries string list. - QStringList dictionariesStringList = dictionariesDir.entryList(QStringList(QLatin1String("*.bdic")), QDir::Files | QDir::NoSymLinks); - - // Remove the `.bdic` file extensions from the dictionaries list. - dictionariesStringList.replaceInStrings(QLatin1String(".bdic"), QLatin1String("")); - - // Get a list of the enabled spell check languages. - QStringList enabledSpellCheckLanguagesList = Settings::spellCheckLanguages(); - - // Add each dictionary to the spell check list widget. - foreach(QString dictionaryString, dictionariesStringList) - { - // Create a new list widget item pointer. - QListWidgetItem *listWidgetItemPointer = new QListWidgetItem(); - - // Create a dictionary check box widget with the name of the dictionary string. - QCheckBox *dictionaryCheckBoxWidget = new QCheckBox(dictionaryString); - - // Check the language if it is currently enabled. - if (enabledSpellCheckLanguagesList.contains(dictionaryString)) - dictionaryCheckBoxWidget->setCheckState(Qt::Checked); - else - dictionaryCheckBoxWidget->setCheckState(Qt::Unchecked); - - // Add the list widget item to the spell check list widget. - spellCheckListWidgetPointer->addItem(listWidgetItemPointer); - - // Set the list widget item check box widget. - spellCheckListWidgetPointer->setItemWidget(listWidgetItemPointer, dictionaryCheckBoxWidget); - } - // Get a handle for the KConfig skeleton. KConfigSkeleton *kConfigSkeletonPointer = Settings::self(); - // Instantiate a settings config dialog from the settings.kcfg file. - configDialogPointer = new KConfigDialog(this, QLatin1String("settings"), kConfigSkeletonPointer); + // Instantiate a settings dialog. + SettingsDialog *settingsDialogPointer = new SettingsDialog(this, kConfigSkeletonPointer); - // Create a settings icon string. - QString settingsIconString; - - // Get a settings icon that matches the theme. - if (QIcon::hasThemeIcon("breeze-settings")) - { - // KDE uses breeze-settings. - settingsIconString = QLatin1String("breeze-settings"); - } - else - { - // Gnome uses preferences-desktop. - settingsIconString = QLatin1String("preferences-desktop"); - } - - // Add the settings widgets as config dialog pages. - configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("Settings tab title", "Privacy"), QLatin1String("privacybrowser")); - configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("Settings tab title", "General"), settingsIconString); - configDialogPointer->addPage(spellCheckSettingsWidgetPointer, i18nc("Settings tab title", "Spell Check"), QLatin1String("tools-check-spelling")); - - // Get handles for the buttons. - QPushButton *applyButtonPointer = configDialogPointer->button(QDialogButtonBox::Apply); - QPushButton *okButtonPointer = configDialogPointer->button(QDialogButtonBox::Ok); - - // Prevent interaction with the parent window while the dialog is open. - configDialogPointer->setWindowModality(Qt::WindowModal); - - // Make it so. - configDialogPointer->show(); + // Show the dialog + settingsDialogPointer->show(); // TODO. KConfigDialog does not respect expanding size policies. - //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + //settingsDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - //configDialogPointer->adjustSize(); + //settingsDialogPointer->adjustSize(); // Expand the config dialog. - configDialogPointer->resize(1000, 500); - - // Create a save spell check languages lambda. - auto saveSpellCheckLanguages = [spellCheckListWidgetPointer, kConfigSkeletonPointer, this] () - { - // Create a list of enabled languages. - QStringList newSpellCheckLanguages = QStringList(); - - // Get a count of all the languages. - int allLanguagesCount = spellCheckListWidgetPointer->count(); - - // Get a list of all the checked languages. - for (int i = 0; i < allLanguagesCount; ++i) { - // Get the language item. - QListWidgetItem *languageItemPointer = spellCheckListWidgetPointer->item(i); - - // Get the language check box. - QCheckBox *languageCheckBoxPointer = qobject_cast(spellCheckListWidgetPointer->itemWidget(languageItemPointer)); - - // Add the item to the enabled languages if it is checked. - if (languageCheckBoxPointer->checkState() == Qt::Checked) - { - // Get the text. - QString languageString = languageCheckBoxPointer->text(); - - // Remove all instances of `&`, which may have been added automatically when creating the check box text. - languageString.remove(QChar('&')); - - // Add the language string to the list. - newSpellCheckLanguages.append(languageString); - } - } - - // Update the spell check languages. - if (Settings::spellCheckLanguages() != newSpellCheckLanguages) - { - // Update the spell check languages. - Settings::setSpellCheckLanguages(newSpellCheckLanguages); - - // Write the settings to disk. - kConfigSkeletonPointer->save(); - } - - // Apply the spell check languages. - tabWidgetPointer->applySpellCheckLanguages(); - }; - - // Process - connect(applyButtonPointer, &QPushButton::clicked, this, saveSpellCheckLanguages); - connect(okButtonPointer, &QPushButton::clicked, this, saveSpellCheckLanguages); + settingsDialogPointer->resize(1000, 500); // Apply the settings handled by KConfig. - connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyApplicationSettings())); - connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyDomainSettingsAndReload())); + connect(settingsDialogPointer, SIGNAL(spellCheckLanguagesUpdated()), tabWidgetPointer, SLOT(applySpellCheckLanguages())); + connect(settingsDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyApplicationSettings())); + connect(settingsDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyDomainSettingsAndReload())); } QSize BrowserWindow::sizeHint() const @@ -2081,12 +1897,6 @@ void BrowserWindow::updateSearchEngineActions(const QString &searchEngine, const } } -void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const -{ - // Update the search engine label. - searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString)); -} - void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl) { // Get the new URL string in encoded form, which displays punycode. @@ -2265,12 +2075,6 @@ void BrowserWindow::updateUserAgentActions(const QString &userAgent, const bool } } -void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const -{ - // Update the user agent label. - userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName)); -} - void BrowserWindow::updateViewBookmarksToolBarCheckbox(const bool visible) { // Update the view bookmarks toolbar checkbox. diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index eedc250..74e31b8 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -55,11 +55,11 @@ public Q_SLOTS: private Q_SLOTS: // The private slots. - void addOrEditDomainSettings() const; + void addOrEditDomainSettings(); void back() const; void clearUrlLineEditFocus() const; void decrementZoom(); - void editBookmarks() const; + void editBookmarks(); void escape() const; void findNext() const; void findPrevious() const; @@ -77,8 +77,7 @@ private Q_SLOTS: void reloadAndBypassCache() const; void showBookmarkContextMenu(const QPoint &point); void showCookiesDialog(); - void showDownloadDirectoryBrowseDialog() const; - void showDomainSettingsDialog() const; + void showDomainSettingsDialog(); void showFindTextActions() const; void showProgressBar(const int &progress) const; void showSettingsDialog(); @@ -103,9 +102,7 @@ private Q_SLOTS: void updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus); void updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus); void updateZoomActions(const double zoomFactorDouble); - void updateSearchEngineLabel(const QString &searchEngineString) const; void updateUrlLineEdit(const QUrl &newUrl); - void updateUserAgentLabel(const QString &userAgentDatabaseName) const; void updateViewBookmarksToolBarCheckbox(const bool visible); void updateWindowTitle(const QString &title); void zoomDefault(); @@ -123,7 +120,6 @@ private: QList *> bookmarksToolBarSubfolderActionList; bool bookmarksToolBarIsVisible = false; bool bookmarksToolBarUninitialized = true; - KConfigDialog *configDialogPointer; QAction *cookiesActionPointer; QUrl currentUrl; QPushButton *currentZoomButtonPointer; @@ -133,7 +129,6 @@ private: double defaultZoomFactorDouble; QAction *developerToolsActionPointer; QAction *domStorageActionPointer; - QComboBox *downloadDirectoryComboBoxPointer; QList *> finalBookmarkFolderMenuActionList; QAction *findCaseSensitiveActionPointer; QAction *findNextActionPointer; @@ -154,7 +149,6 @@ private: QPalette positiveBackgroundPalette; QProgressBar *progressBarPointer; QAction *refreshActionPointer; - QLabel *searchEngineLabelPointer; QAction *searchEngineMenuActionPointer; QAction *searchEngineMojeekActionPointer; QAction *searchEngineMonoclesActionPointer; @@ -164,7 +158,6 @@ private: QAction *searchEngineYahooActionPointer; QAction *searchEngineCustomActionPointer; QAction *stopActionPointer; - QLabel *userAgentLabelPointer; QAction *userAgentMenuActionPointer; QAction *userAgentPrivacyBrowserActionPointer; QAction *userAgentWebEngineDefaultActionPointer; -- 2.45.2