X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=blobdiff_plain;f=src%2Fwindows%2FBrowserWindow.cpp;h=fe3b5939e86ea73d157d4ee87adf7165c59e839d;hp=f0cd4dfc76e33223e4d75c44deacefd08b3c72ce;hb=HEAD;hpb=ce90749b5fc2c4a3fcee6daee60c0d6e2aa0e1d6 diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index f0cd4df..af050ef 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -1,7 +1,7 @@ /* * Copyright 2022-2024 Soren Stoutner . * - * This file is part of Privacy Browser PC . + * 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 @@ -29,17 +29,13 @@ #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 -#include -#include -#include - // Qt toolkit headers. #include #include @@ -56,6 +52,12 @@ #include #include +// KDE Frameworks headers. +#include +#include +#include +#include + // Construct the class. BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) : KXmlGuiWindow() { @@ -119,6 +121,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) 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")); @@ -186,7 +190,7 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) 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); @@ -202,6 +206,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) 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)); @@ -232,6 +238,7 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) 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"))); @@ -239,7 +246,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) 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")))); @@ -279,6 +287,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) 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")); @@ -316,6 +326,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) 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); @@ -332,6 +344,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) 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())); @@ -345,8 +359,11 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) 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))); @@ -543,12 +560,12 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) // Add a separator to the bookmarks menu. bookmarksMenuPointer->addSeparator(); - // Initialize the current bookmarks lists. - finalBookmarkFolderMenuActionList = QList *>(); + // Initialize the bookmark action lists. + bookmarkFolderFinalActionList = QList *>(); bookmarksMenuActionList = QList *>(); bookmarksMenuSubmenuList = QList *>(); bookmarksToolBarActionList = QList(); - bookmarksToolBarSubfolderActionList = QList *>(); + bookmarksToolBarSubfolderActionList = QList *>(); // Set the bookmarks toolbar context menu policy. bookmarksToolBarPointer->setContextMenuPolicy(Qt::CustomContextMenu); @@ -580,7 +597,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) } } -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); @@ -688,8 +706,9 @@ void BrowserWindow::addFinalBookmarkFolderMenuActions(QMenu *menuPointer, double } ); - // Add the action to the beginning of the final bookmark folder menu action list. - finalBookmarkFolderMenuActionList.prepend(new QPair(menuPointer, editFolderActionPointer)); + // Add the action to the beginning of the bookmark folder final action list if requsted. + if (addToList) + bookmarkFolderFinalActionList.prepend(new QPair(menuPointer, editFolderActionPointer)); } // Add the delete folder action to the menu. @@ -760,13 +779,15 @@ void BrowserWindow::addFinalBookmarkFolderMenuActions(QMenu *menuPointer, double actionCollectionPointer->setDefaultShortcut(addFolderActionPointer, metaFKeySequence); } - // Add the actions to the beginning of the final bookmark folder menu action list. - finalBookmarkFolderMenuActionList.prepend(new QPair(menuPointer, addBookmarkActionPointer)); - finalBookmarkFolderMenuActionList.prepend(new QPair(menuPointer, addFolderActionPointer)); - finalBookmarkFolderMenuActionList.prepend(new QPair(menuPointer, openFolderInNewTabsActionPointer)); - finalBookmarkFolderMenuActionList.prepend(new QPair(menuPointer, openFolderInBackgroundTabsActionPointer)); - finalBookmarkFolderMenuActionList.prepend(new QPair(menuPointer, openFolderInNewWindowActionPointer)); - finalBookmarkFolderMenuActionList.prepend(new QPair(menuPointer, deleteFolderActionPointer)); + // Add the actions to the beginning of the bookmark folder final action list if requested. + if (addToList) { + bookmarkFolderFinalActionList.prepend(new QPair(menuPointer, addBookmarkActionPointer)); + bookmarkFolderFinalActionList.prepend(new QPair(menuPointer, addFolderActionPointer)); + bookmarkFolderFinalActionList.prepend(new QPair(menuPointer, openFolderInNewTabsActionPointer)); + bookmarkFolderFinalActionList.prepend(new QPair(menuPointer, openFolderInBackgroundTabsActionPointer)); + bookmarkFolderFinalActionList.prepend(new QPair(menuPointer, openFolderInNewWindowActionPointer)); + bookmarkFolderFinalActionList.prepend(new QPair(menuPointer, deleteFolderActionPointer)); + } } void BrowserWindow::addOrEditDomainSettings() @@ -1091,10 +1112,10 @@ void BrowserWindow::populateBookmarksInAllWindows() const void BrowserWindow::populateBookmarksInThisWindow() { // Remove all the final bookmark folder menu actions. - for (QPair *finalBookmarkFolderMenuActionPair : finalBookmarkFolderMenuActionList) + for (QPair *bookmarkFolderFinalActionPairPointer : bookmarkFolderFinalActionList) { // Remove the action. - finalBookmarkFolderMenuActionPair->first->removeAction(finalBookmarkFolderMenuActionPair->second); + bookmarkFolderFinalActionPairPointer->first->removeAction(bookmarkFolderFinalActionPairPointer->second); } // Remove all the current menu bookmarks. @@ -1125,11 +1146,12 @@ void BrowserWindow::populateBookmarksInThisWindow() 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); @@ -1189,8 +1211,8 @@ void BrowserWindow::populateBookmarksMenuSubfolders(const double folderId, QMenu } } - // 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() @@ -1252,8 +1274,8 @@ 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 *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); } } @@ -1346,8 +1368,8 @@ void BrowserWindow::showBookmarkContextMenu(const QPoint &point) // 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. { @@ -1496,6 +1518,15 @@ void BrowserWindow::showDomainSettingsDialog() 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. @@ -1530,6 +1561,15 @@ void BrowserWindow::showProgressBar(const int &progress) const 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. @@ -1702,9 +1742,15 @@ void BrowserWindow::updateBookmarkedAction() const 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)); }