/*
* Copyright 2022-2024 Soren Stoutner <soren@stoutner.com>.
*
- * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/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
#include "dialogs/DomainSettingsDialog.h"
#include "dialogs/EditBookmarkDialog.h"
#include "dialogs/EditFolderDialog.h"
+#include "dialogs/FilterListsDialog.h"
+#include "dialogs/RequestsDialog.h"
#include "dialogs/SettingsDialog.h"
#include "helpers/SearchEngineHelper.h"
#include "helpers/UserAgentHelper.h"
#include "structs/BookmarkStruct.h"
-// KDE Frameworks headers.
-#include <KActionCollection>
-#include <KColorScheme>
-#include <KLocalizedString>
-#include <KXMLGUIFactory>
-
// Qt toolkit headers.
#include <QClipboard>
#include <QContextMenuEvent>
#include <QStatusBar>
#include <QWebEngineFindTextResult>
+// KDE Frameworks headers.
+#include <KActionCollection>
+#include <KColorScheme>
+#include <KLocalizedString>
+#include <KXMLGUIFactory>
+
// Construct the class.
BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) : KXmlGuiWindow()
{
searchEngineBingActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_bing"));
searchEngineYahooActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_yahoo"));
searchEngineCustomActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_custom"));
+ requestsActionPointer = actionCollectionPointer->addAction(QLatin1String("requests"));
+ QAction *viewFilterListsActionPointer = actionCollectionPointer->addAction(QLatin1String("view_filter_lists"));
viewBookmarksToolBarActionPointer = actionCollectionPointer->addAction(QLatin1String("view_bookmarks_toolbar"));
QAction *domainSettingsActionPointer = actionCollectionPointer->addAction(QLatin1String("domain_settings"));
cookiesActionPointer = actionCollectionPointer->addAction(QLatin1String("cookies"));
viewSourceInNewTabActionPointer->setText(i18nc("View source in new tab action", "View Source in New Tab"));
developerToolsActionPointer->setText(i18nc("Developer tools action", "Developer Tools"));
javaScriptActionPointer->setText(i18nc("JavaScript action", "JavaScript"));
- localStorageActionPointer->setText(i18nc("The Local Storage action", "Local Storage"));
+ localStorageActionPointer->setText(i18nc("Local Storage action", "Local Storage"));
domStorageActionPointer->setText(i18nc("DOM Storage action", "DOM Storage"));
userAgentPrivacyBrowserActionPointer->setText(userAgentHelperPointer->PRIVACY_BROWSER_TRANSLATED);
userAgentWebEngineDefaultActionPointer->setText(userAgentHelperPointer->WEB_ENGINE_DEFAULT_TRANSLATED);
searchEngineGoogleActionPointer->setText(i18nc("Search engine", "Google"));
searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing"));
searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo"));
+ requestsActionPointer->setText(i18nc("Requests action", "Requests - %1 Blocked", 0));
+ viewFilterListsActionPointer->setText(i18nc("View filter lists action", "View Filter Lists"));
viewBookmarksToolBarActionPointer->setText(i18nc("View bookmarks toolbar", "View Bookmarks Toolbar"));
domainSettingsActionPointer->setText(i18nc("Domain Settings action", "Domain Settings"));
cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", 0));
userAgentEdgeWindowsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("user-group-properties"), QIcon::fromTheme(QLatin1String("contact-new"))));
userAgentSafariMacosActionPointer->setIcon(QIcon::fromTheme(QLatin1String("user-group-properties"), QIcon::fromTheme(QLatin1String("contact-new"))));
userAgentCustomActionPointer->setIcon(QIcon::fromTheme(QLatin1String("user-group-properties"), QIcon::fromTheme(QLatin1String("contact-new"))));
+ zoomFactorActionPointer->setIcon(QIcon::fromTheme(QLatin1String("zoom-fit-best")));
searchEngineMojeekActionPointer->setIcon(QIcon::fromTheme(QLatin1String("edit-find")));
searchEngineMonoclesActionPointer->setIcon(QIcon::fromTheme(QLatin1String("edit-find")));
searchEngineMetagerActionPointer->setIcon(QIcon::fromTheme(QLatin1String("edit-find")));
searchEngineBingActionPointer->setIcon(QIcon::fromTheme(QLatin1String("edit-find")));
searchEngineYahooActionPointer->setIcon(QIcon::fromTheme(QLatin1String("im-yahoo"), QIcon::fromTheme(QLatin1String("edit-find"))));
searchEngineCustomActionPointer->setIcon(QIcon::fromTheme(QLatin1String("edit-find")));
- zoomFactorActionPointer->setIcon(QIcon::fromTheme(QLatin1String("zoom-fit-best")));
+ requestsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("document-equal"), QIcon::fromTheme(QLatin1String("system-lock-screen"))));
+ viewFilterListsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("view-list-text"), QIcon::fromTheme(QLatin1String("format-justify-left"))));
editBookmarksActionPointer->setIcon(QIcon::fromTheme(QLatin1String("bookmark-edit"), QIcon::fromTheme(QLatin1String("bookmark-new"))));
viewBookmarksToolBarActionPointer->setIcon(QIcon::fromTheme(QLatin1String("bookmarks"), QIcon::fromTheme(QLatin1String("bookmark-new"))));
domainSettingsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("settings-configure"), QIcon::fromTheme(QLatin1String("preferences-desktop"))));
QKeySequence ctrlShiftBKeySequence = QKeySequence(i18nc("The Bing search engine key sequence.", "Ctrl+Shift+B"));
QKeySequence ctrlShiftYKeySequence = QKeySequence(i18nc("The Yahoo search engine key sequence.", "Ctrl+Shift+Y"));
QKeySequence ctrlShiftCKeySequence = QKeySequence(i18nc("The custom search engine key sequence.", "Ctrl+Shift+C"));
+ QKeySequence ctrlRKeySequence = QKeySequence(i18nc("The requests key sequence.", "Ctrl+R"));
+ QKeySequence ctrlShiftLKeySequence = QKeySequence(i18nc("The view filter lists key sequence.", "Ctrl+Shift+L"));
QKeySequence ctrlAltShiftBKeySequence = QKeySequence(i18nc("The edit bookmarks key sequence.", "Ctrl+Alt+Shift+B"));
QKeySequence ctrlAltBKeySequence = QKeySequence(i18nc("The view bookmarks toolbar key sequence.", "Ctrl+Alt+B"));
QKeySequence ctrlShiftDKeySequence = QKeySequence(i18nc("The domain settings key sequence.", "Ctrl+Shift+D"));
actionCollectionPointer->setDefaultShortcut(searchEngineBingActionPointer, ctrlShiftBKeySequence);
actionCollectionPointer->setDefaultShortcut(searchEngineYahooActionPointer, ctrlShiftYKeySequence);
actionCollectionPointer->setDefaultShortcut(searchEngineCustomActionPointer, ctrlShiftCKeySequence);
+ actionCollectionPointer->setDefaultShortcut(requestsActionPointer, ctrlRKeySequence);
+ actionCollectionPointer->setDefaultShortcut(viewFilterListsActionPointer, ctrlShiftLKeySequence);
actionCollectionPointer->setDefaultShortcut(editBookmarksActionPointer, ctrlAltShiftBKeySequence);
actionCollectionPointer->setDefaultShortcut(viewBookmarksToolBarActionPointer, ctrlAltBKeySequence);
actionCollectionPointer->setDefaultShortcut(domainSettingsActionPointer, ctrlShiftDKeySequence);
connect(viewSourceInNewTabActionPointer, SIGNAL(triggered()), this, SLOT(toggleViewSourceInNewTab()));
connect(developerToolsActionPointer, SIGNAL(triggered()), this, SLOT(toggleDeveloperTools()));
connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
+ connect(requestsActionPointer, SIGNAL(triggered()), this, SLOT(showRequestsDialog()));
+ connect(viewFilterListsActionPointer, SIGNAL(triggered()), this, SLOT(showFilterListsDialog()));
connect(viewBookmarksToolBarActionPointer, SIGNAL(triggered()), this, SLOT(toggleViewBookmarksToolBar()));
connect(cookiesActionPointer, SIGNAL(triggered()), this, SLOT(showCookiesDialog()));
connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(showDomainSettingsDialog()));
connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), tabWidgetPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), tabWidgetPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
+ // Process blocked requests.
+ connect(tabWidgetPointer, SIGNAL(blockedRequestsUpdated(const int)), this, SLOT(updateRequestsAction(const int)));
+
// Process cookie changes.
- connect(tabWidgetPointer, SIGNAL(updateCookiesAction(int)), this, SLOT(updateCookiesAction(int)));
+ connect(tabWidgetPointer, SIGNAL(cookiesChanged(const int)), this, SLOT(updateCookiesAction(const int)));
// Store the default zoom factor.
connect(tabWidgetPointer, SIGNAL(updateDefaultZoomFactor(double)), this, SLOT(updateDefaultZoomFactor(double)));
// Add a separator to the bookmarks menu.
bookmarksMenuPointer->addSeparator();
- // Initialize the current bookmarks lists.
- finalBookmarkFolderMenuActionList = QList<QPair<QMenu *, QAction *> *>();
+ // Initialize the bookmark action lists.
+ bookmarkFolderFinalActionList = QList<QPair<QMenu *, QAction *> *>();
bookmarksMenuActionList = QList<QPair<QMenu *, QAction *> *>();
bookmarksMenuSubmenuList = QList<QPair<QMenu *, QMenu *> *>();
bookmarksToolBarActionList = QList<QAction*>();
- bookmarksToolBarSubfolderActionList = QList<QPair<QMenu *, QAction * > *>();
+ bookmarksToolBarSubfolderActionList = QList<QPair<QMenu *, QAction *> *>();
// Set the bookmarks toolbar context menu policy.
bookmarksToolBarPointer->setContextMenuPolicy(Qt::CustomContextMenu);
}
}
-void BrowserWindow::addFinalBookmarkFolderMenuActions(QMenu *menuPointer, double folderId)
+// If actions are part of a context menu they do not need to be added to the list as they will be deleted automatically when the context menu closes.
+void BrowserWindow::addBookmarkFolderFinalActions(QMenu *menuPointer, const double folderId, const bool addToList)
{
// Get the database ID.
int folderDatabaseId = BookmarksDatabase::getFolderDatabaseId(folderId);
}
);
- // Add the action to the beginning of the final bookmark folder menu action list.
- finalBookmarkFolderMenuActionList.prepend(new QPair<QMenu *, QAction *>(menuPointer, editFolderActionPointer));
+ // Add the action to the beginning of the bookmark folder final action list if requsted.
+ if (addToList)
+ bookmarkFolderFinalActionList.prepend(new QPair<QMenu *, QAction *>(menuPointer, editFolderActionPointer));
}
// Add the delete folder action to the menu.
actionCollectionPointer->setDefaultShortcut(addFolderActionPointer, metaFKeySequence);
}
- // Add the actions to the beginning of the final bookmark folder menu action list.
- finalBookmarkFolderMenuActionList.prepend(new QPair<QMenu *, QAction *>(menuPointer, addBookmarkActionPointer));
- finalBookmarkFolderMenuActionList.prepend(new QPair<QMenu *, QAction *>(menuPointer, addFolderActionPointer));
- finalBookmarkFolderMenuActionList.prepend(new QPair<QMenu *, QAction *>(menuPointer, openFolderInNewTabsActionPointer));
- finalBookmarkFolderMenuActionList.prepend(new QPair<QMenu *, QAction *>(menuPointer, openFolderInBackgroundTabsActionPointer));
- finalBookmarkFolderMenuActionList.prepend(new QPair<QMenu *, QAction *>(menuPointer, openFolderInNewWindowActionPointer));
- finalBookmarkFolderMenuActionList.prepend(new QPair<QMenu *, QAction *>(menuPointer, deleteFolderActionPointer));
+ // Add the actions to the beginning of the bookmark folder final action list if requested.
+ if (addToList) {
+ bookmarkFolderFinalActionList.prepend(new QPair<QMenu *, QAction *>(menuPointer, addBookmarkActionPointer));
+ bookmarkFolderFinalActionList.prepend(new QPair<QMenu *, QAction *>(menuPointer, addFolderActionPointer));
+ bookmarkFolderFinalActionList.prepend(new QPair<QMenu *, QAction *>(menuPointer, openFolderInNewTabsActionPointer));
+ bookmarkFolderFinalActionList.prepend(new QPair<QMenu *, QAction *>(menuPointer, openFolderInBackgroundTabsActionPointer));
+ bookmarkFolderFinalActionList.prepend(new QPair<QMenu *, QAction *>(menuPointer, openFolderInNewWindowActionPointer));
+ bookmarkFolderFinalActionList.prepend(new QPair<QMenu *, QAction *>(menuPointer, deleteFolderActionPointer));
+ }
}
void BrowserWindow::addOrEditDomainSettings()
void BrowserWindow::populateBookmarksInThisWindow()
{
// Remove all the final bookmark folder menu actions.
- for (QPair<QMenu *, QAction *> *finalBookmarkFolderMenuActionPair : finalBookmarkFolderMenuActionList)
+ for (QPair<QMenu *, QAction *> *bookmarkFolderFinalActionPairPointer : bookmarkFolderFinalActionList)
{
// Remove the action.
- finalBookmarkFolderMenuActionPair->first->removeAction(finalBookmarkFolderMenuActionPair->second);
+ bookmarkFolderFinalActionPairPointer->first->removeAction(bookmarkFolderFinalActionPairPointer->second);
}
// Remove all the current menu bookmarks.
bookmarksToolBarPointer->removeAction(bookmarkAction);
}
- // Clear the current bookmark lists.
+ // Clear the action lists.
+ bookmarkFolderFinalActionList.clear();
bookmarksMenuActionList.clear();
bookmarksMenuSubmenuList.clear();
- bookmarksToolBarActionList.clear();
bookmarksToolBarSubfolderActionList.clear();
+ bookmarksToolBarActionList.clear();
// Populate the bookmarks subfolders, beginning with the root folder (`0`);
populateBookmarksMenuSubfolders(0, bookmarksMenuPointer);
}
}
- // Add the extra items at the bottom of the menu.
- addFinalBookmarkFolderMenuActions(menuPointer, folderId);
+ // Add the extra items at the bottom of the menu. `true` adds them to the list of actions to be deleted on repopulate.
+ addBookmarkFolderFinalActions(menuPointer, folderId, true);
}
void BrowserWindow::populateBookmarksToolBar()
// Add the extra items to the toolbar folder menus. The first item in the pair is the menu pointer. The second is the folder ID.
for (QPair<QMenu *, const double> *menuAndFolderIdPairPointer : bookmarksToolBarMenuList)
{
- // Populate the final bookmarks menu entries.
- addFinalBookmarkFolderMenuActions(menuAndFolderIdPairPointer->first, menuAndFolderIdPairPointer->second);
+ // Populate the final bookmarks menu entries. `true` adds them to the list of actions to be deleted on repopulate.
+ addBookmarkFolderFinalActions(menuAndFolderIdPairPointer->first, menuAndFolderIdPairPointer->second, true);
}
}
// Create the menu according to the type.
if (BookmarksDatabase::isFolder(databaseId)) // A folder was clicked.
{
- // Populate the final bookmarks menu entries.
- addFinalBookmarkFolderMenuActions(bookmarkContextMenuPointer, BookmarksDatabase::getFolderId(databaseId));
+ // Populate the final bookmarks menu entries. `false` does not add the actions to the delete list, as they will be automatically deleted when the menu closes.
+ addBookmarkFolderFinalActions(bookmarkContextMenuPointer, BookmarksDatabase::getFolderId(databaseId), false);
}
else // A bookmark was clicked.
{
domainSettingsDialogPointer->show();
}
+void BrowserWindow::showFilterListsDialog()
+{
+ // Instantiate the filter lists dialog.
+ FilterListsDialog *filterListsDialogPointer = new FilterListsDialog(this);
+
+ // Show the dialog.
+ filterListsDialogPointer->show();
+}
+
void BrowserWindow::showFindTextActions() const
{
// Show the find text actions.
stopActionPointer->setVisible(true);
}
+void BrowserWindow::showRequestsDialog()
+{
+ // Instantiate the requests dialog.
+ RequestsDialog *requestsDialogPointer = new RequestsDialog(this, tabWidgetPointer->currentPrivacyWebEngineViewPointer->requestsListPointer);
+
+ // Show the dialog.
+ requestsDialogPointer->show();
+}
+
void BrowserWindow::showSettingsDialog()
{
// Get a handle for the KConfig skeleton.
bookmarkedActionPointer->setIcon(QIcon::fromTheme("non-starred-symbolic"));
}
+void BrowserWindow::updateRequestsAction(const int blockedRequests) const
+{
+ // Update the requests action text.
+ requestsActionPointer->setText(i18nc("Requests action", "Requests - %1 Blocked", blockedRequests));
+}
+
void BrowserWindow::updateCookiesAction(const int numberOfCookies) const
{
- // Update the action text.
+ // Update the cookies action text.
cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", numberOfCookies));
}