X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fwindows%2FBrowserWindow.cpp;h=33aef29f77ad309caf13e4acc3ad3d5c6b1cf30a;hb=refs%2Fheads%2Fmaster;hp=fe3b5939e86ea73d157d4ee87adf7165c59e839d;hpb=c5706a6ff3fbc42418e60b79fbe3f5c19396f7d2;p=PrivacyBrowserPC.git diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index fe3b593..2ff9a11 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -1,24 +1,25 @@ -/* - * Copyright 2022-2024 Soren Stoutner . +/* SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2022-2025 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program 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. + * This program 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 . + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . */ // Application headers. #include "BrowserWindow.h" +#include "GlobalVariables.h" #include "Settings.h" #include "databases/BookmarksDatabase.h" #include "databases/DomainsDatabase.h" @@ -29,18 +30,15 @@ #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 #include #include @@ -56,6 +54,12 @@ #include #include +// KDE Frameworks headers. +#include +#include +#include +#include + // Construct the class. BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) : KXmlGuiWindow() { @@ -93,6 +97,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) QAction *newTabActionPointer = actionCollectionPointer->addAction(QLatin1String("new_tab")); QAction *newWindowActionPointer = actionCollectionPointer->addAction(QLatin1String("new_window")); QAction *saveArchiveActionPointer = actionCollectionPointer->addAction(QLatin1String("save_archive")); + QAction *openWithFirefoxActionPointer = actionCollectionPointer->addAction(QLatin1String("open_with_firefox")); + QAction *openWithChromiumActionPointer = actionCollectionPointer->addAction(QLatin1String("open_with_chromium")); zoomDefaultActionPointer = actionCollectionPointer->addAction(QLatin1String("zoom_default")); QAction *reloadAndBypassCacheActionPointer = actionCollectionPointer->addAction(QLatin1String("reload_and_bypass_cache")); stopActionPointer = actionCollectionPointer->addAction(QLatin1String("stop")); @@ -119,9 +125,17 @@ 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")); + ultraPrivacyActionPointer = actionCollectionPointer->addAction(QLatin1String("ultraprivacy")); + ultraListActionPointer = actionCollectionPointer->addAction(QLatin1String("ultralist")); + easyPrivacyActionPointer = actionCollectionPointer->addAction(QLatin1String("easyprivacy")); + easyListActionPointer = actionCollectionPointer->addAction(QLatin1String("easylist")); + fanboysAnnoyanceListPointer = actionCollectionPointer->addAction(QLatin1String("fanboys_annoyance_list")); + 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")); + blockedRequestsActionPointer = actionCollectionPointer->addAction(QLatin1String("blocked_requests")); findCaseSensitiveActionPointer = actionCollectionPointer->addAction(QLatin1String("find_case_sensitive")); hideFindTextActionPointer = actionCollectionPointer->addAction(QLatin1String("hide_find_actions")); @@ -170,6 +184,11 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) searchEngineBingActionPointer->setCheckable(true); searchEngineYahooActionPointer->setCheckable(true); searchEngineCustomActionPointer->setCheckable(true); + ultraPrivacyActionPointer->setCheckable(true); + ultraListActionPointer->setCheckable(true); + easyPrivacyActionPointer->setCheckable(true); + easyListActionPointer->setCheckable(true); + fanboysAnnoyanceListPointer->setCheckable(true); viewBookmarksToolBarActionPointer->setCheckable(true); // Instantiate the user agent helper. @@ -179,6 +198,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) newTabActionPointer->setText(i18nc("New tab action", "New Tab")); newWindowActionPointer->setText(i18nc("New window action", "New Window")); saveArchiveActionPointer->setText(i18nc("Save archive action", "Save Archive")); + openWithFirefoxActionPointer->setText(i18nc("Open with Firefox action", "Open With Firefox")); + openWithChromiumActionPointer->setText(i18nc("Open with Chromium action", "Open With Chromium")); zoomDefaultActionPointer->setText(i18nc("Zoom default action", "Zoom Default")); reloadAndBypassCacheActionPointer->setText(i18nc("Reload and bypass cache action", "Reload and Bypass Cache")); stopActionPointer->setText(i18nc("Stop action", "Stop")); @@ -186,7 +207,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); @@ -196,29 +217,42 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) userAgentChromeWindowsActionPointer->setText(userAgentHelperPointer->CHROME_WINDOWS_TRANSLATED); userAgentEdgeWindowsActionPointer->setText(userAgentHelperPointer->EDGE_WINDOWS_TRANSLATED); userAgentSafariMacosActionPointer->setText(userAgentHelperPointer->SAFARI_MACOS_TRANSLATED); - searchEngineMojeekActionPointer->setText(i18nc("Search engine", "Mojeek")); - searchEngineMonoclesActionPointer->setText(i18nc("Search engine", "Monocles")); - searchEngineMetagerActionPointer->setText(i18nc("Search engine", "MetaGer")); - searchEngineGoogleActionPointer->setText(i18nc("Search engine", "Google")); - searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing")); - searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo")); - viewBookmarksToolBarActionPointer->setText(i18nc("View bookmarks toolbar", "View Bookmarks Toolbar")); + searchEngineMojeekActionPointer->setText(i18nc("Mojeek search engine action", "Mojeek")); + searchEngineMonoclesActionPointer->setText(i18nc("Monocles search engine action", "Monocles")); + searchEngineMetagerActionPointer->setText(i18nc("MetaGer search engine action", "MetaGer")); + searchEngineGoogleActionPointer->setText(i18nc("Google search engine action", "Google")); + searchEngineBingActionPointer->setText(i18nc("Bing search engine action", "Bing")); + searchEngineYahooActionPointer->setText(i18nc("Yahoo search engine action", "Yahoo")); + ultraPrivacyActionPointer->setText(i18nc("UltraPrivacy action", "UltraPrivacy - %1 Blocked", 0)); + ultraListActionPointer->setText(i18nc("UltraList action", "UltraList - %1 Blocked", 0)); + easyPrivacyActionPointer->setText(i18nc("EasyPrivacy action", "EasyPrivacy - %1 Blocked", 0)); + easyListActionPointer->setText(i18nc("EasyList action", "EasyList - %1 Blocked", 0)); + fanboysAnnoyanceListPointer->setText(i18nc("Fanboy's Annoyance List action", "Fanboy’s Annoyance List - %1 Blocked", 0)); + 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 action", "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)); + cookiesActionPointer->setText(i18nc("Cookies action, which also displays the number of cookies", "Cookies - %1", 0)); + blockedRequestsActionPointer->setText(QLatin1String("0")); findCaseSensitiveActionPointer->setText(i18nc("Find Case Sensitive action", "Find Case Sensitive")); hideFindTextActionPointer->setText(i18nc("Hide Find Text action (the text should include the language-specific escape keyboard shortcut).", "Hide Find Text (Esc)")); + // Set the tool tips. + blockedRequestsActionPointer->setToolTip(i18nc("Blocked requests action tool tip", "%1 Blocked Requests (Ctrl+R)", 0)); + // Set the action icons. Gnome doesn't contain some of the icons that KDE has. // The toolbar icons don't pick up unless the size is explicit, probably because the toolbar ends up being an intermediate size. newTabActionPointer->setIcon(QIcon::fromTheme(QLatin1String("tab-new"))); newWindowActionPointer->setIcon(QIcon::fromTheme(QLatin1String("window-new"))); saveArchiveActionPointer->setIcon(QIcon::fromTheme(QLatin1String("document-save"))); + openWithFirefoxActionPointer->setIcon(QIcon::fromTheme(QLatin1String("firefox-esr"))); + openWithChromiumActionPointer->setIcon(QIcon::fromTheme(QLatin1String("chromium"))); zoomDefaultActionPointer->setIcon(QIcon::fromTheme(QLatin1String("zoom-fit-best"))); reloadAndBypassCacheActionPointer->setIcon(QIcon::fromTheme(QLatin1String("view-refresh"))); stopActionPointer->setIcon(QIcon::fromTheme(QLatin1String("process-stop"))); viewSourceActionPointer->setIcon(QIcon::fromTheme(QLatin1String("view-choose"), QIcon::fromTheme(QLatin1String("accessories-text-editor")))); viewSourceInNewTabActionPointer->setIcon(QIcon::fromTheme(QLatin1String("view-choose"), QIcon::fromTheme(QLatin1String("accessories-text-editor")))); - developerToolsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("add-subtitle"), QIcon::fromTheme("system-run"))); + developerToolsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("add-subtitle"), QIcon::fromTheme(QLatin1String("system-run")))); domStorageActionPointer->setIcon(QIcon::fromTheme(QLatin1String("code-class"), QIcon(QLatin1String("/usr/share/icons/gnome/32x32/actions/gtk-unindent-ltr.png")))); userAgentPrivacyBrowserActionPointer->setIcon(QIcon(QLatin1String(":/icons/privacy-mode.svg"))); userAgentWebEngineDefaultActionPointer->setIcon(QIcon::fromTheme(QLatin1String("qtlogo"), QIcon::fromTheme(QLatin1String("user-group-properties"), @@ -232,6 +266,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 +274,13 @@ 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")))); + ultraPrivacyActionPointer->setIcon(QIcon::fromTheme(QLatin1String("view-list-text"), QIcon::fromTheme(QLatin1String("format-justify-left")))); + ultraListActionPointer->setIcon(QIcon::fromTheme(QLatin1String("view-list-text"), QIcon::fromTheme(QLatin1String("format-justify-left")))); + easyPrivacyActionPointer->setIcon(QIcon::fromTheme(QLatin1String("view-list-text"), QIcon::fromTheme(QLatin1String("format-justify-left")))); + easyListActionPointer->setIcon(QIcon::fromTheme(QLatin1String("view-list-text"), QIcon::fromTheme(QLatin1String("format-justify-left")))); + fanboysAnnoyanceListPointer->setIcon(QIcon::fromTheme(QLatin1String("view-list-text"), QIcon::fromTheme(QLatin1String("format-justify-left")))); + 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")))); @@ -251,6 +292,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) QKeySequence ctrlTKeySequence = QKeySequence(i18nc("The open new tab key sequence.", "Ctrl+T")); QKeySequence ctrlNKeySequence = QKeySequence(i18nc("The open new window key sequence.", "Ctrl+N")); QKeySequence ctrlAKeySequence = QKeySequence(i18nc("The save archive key sequence.", "Ctrl+A")); + QKeySequence altFKeySequence = QKeySequence(i18nc("The open with Firefox key sequence.", "Alt+F")); + QKeySequence altCKeySequence = QKeySequence(i18nc("The open with Chromium key sequence.", "Alt+C")); QKeySequence ctrl0KeySequence = QKeySequence(i18nc("The zoom default key sequence.", "Ctrl+0")); QKeySequence ctrlF5KeySequence = QKeySequence(i18nc("The reload and bypass cache key sequence.", "Ctrl+F5")); QKeySequence ctrlShiftXKeySequence = QKeySequence(i18nc("The stop key sequence.", "Ctrl+Shift+X")); @@ -279,6 +322,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")); @@ -288,6 +333,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) actionCollectionPointer->setDefaultShortcut(newTabActionPointer, ctrlTKeySequence); actionCollectionPointer->setDefaultShortcut(newWindowActionPointer, ctrlNKeySequence); actionCollectionPointer->setDefaultShortcut(saveArchiveActionPointer, ctrlAKeySequence); + actionCollectionPointer->setDefaultShortcut(openWithFirefoxActionPointer, altFKeySequence); + actionCollectionPointer->setDefaultShortcut(openWithChromiumActionPointer, altCKeySequence); actionCollectionPointer->setDefaultShortcut(zoomDefaultActionPointer, ctrl0KeySequence); actionCollectionPointer->setDefaultShortcut(reloadAndBypassCacheActionPointer, ctrlF5KeySequence); actionCollectionPointer->setDefaultShortcut(stopActionPointer, ctrlShiftXKeySequence); @@ -316,15 +363,19 @@ 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); actionCollectionPointer->setDefaultShortcut(cookiesActionPointer, ctrlSemicolonKeySequence); - // Execute the actions. + // Connect the actions. connect(newTabActionPointer, SIGNAL(triggered()), tabWidgetPointer, SLOT(addTab())); connect(newWindowActionPointer, SIGNAL(triggered()), this, SLOT(newWindow())); connect(saveArchiveActionPointer, SIGNAL(triggered()), tabWidgetPointer, SLOT(saveArchive())); + connect(openWithFirefoxActionPointer, SIGNAL(triggered()), this, SLOT(openWithFirefox())); + connect(openWithChromiumActionPointer, SIGNAL(triggered()), this, SLOT(openWithChromium())); connect(zoomDefaultActionPointer, SIGNAL(triggered()), this, SLOT(zoomDefault())); connect(reloadAndBypassCacheActionPointer, SIGNAL(triggered()), this, SLOT(reloadAndBypassCache())); connect(stopActionPointer, SIGNAL(triggered()), tabWidgetPointer, SLOT(stop())); @@ -332,9 +383,12 @@ 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())); + connect(blockedRequestsActionPointer, SIGNAL(triggered()), this, SLOT(showRequestsDialog())); // Update the on-the-fly menus. connect(tabWidgetPointer, SIGNAL(updateUserAgentActions(QString, bool)), this, SLOT(updateUserAgentActions(QString, bool))); @@ -345,18 +399,33 @@ 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 QVector)), this, SLOT(updateRequestsAction(const QVector))); + // 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))); + // Connect the filter list actions. + connect(ultraPrivacyActionPointer, SIGNAL(triggered()), tabWidgetPointer, SLOT(toggleUltraPrivacy())); + connect(ultraListActionPointer, SIGNAL(triggered()), tabWidgetPointer, SLOT(toggleUltraList())); + connect(easyPrivacyActionPointer, SIGNAL(triggered()), tabWidgetPointer, SLOT(toggleEasyPrivacy())); + connect(easyListActionPointer, SIGNAL(triggered()), tabWidgetPointer, SLOT(toggleEasyList())); + connect(fanboysAnnoyanceListPointer, SIGNAL(triggered()), tabWidgetPointer, SLOT(toggleFanboysAnnoyanceList())); + // Connect the URL toolbar actions. connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript())); connect(localStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleLocalStorage())); connect(domStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleDomStorage())); // Update the actions from the tab widget. + connect(tabWidgetPointer, SIGNAL(easyListStatusChanged(bool)), easyListActionPointer, SLOT(setChecked(bool))); + connect(tabWidgetPointer, SIGNAL(easyPrivacyStatusChanged(bool)), easyPrivacyActionPointer, SLOT(setChecked(bool))); + connect(tabWidgetPointer, SIGNAL(fanboysAnnoyanceListStatusChanged(bool)), fanboysAnnoyanceListPointer, SLOT(setChecked(bool))); + connect(tabWidgetPointer, SIGNAL(ultraListStatusChanged(bool)), ultraListActionPointer, SLOT(setChecked(bool))); + connect(tabWidgetPointer, SIGNAL(ultraPrivacyStatusChanged(bool)), ultraPrivacyActionPointer, SLOT(setChecked(bool))); connect(tabWidgetPointer, SIGNAL(updateDeveloperToolsAction(bool)), developerToolsActionPointer, SLOT(setChecked(bool))); connect(tabWidgetPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool))); connect(tabWidgetPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool))); @@ -371,19 +440,23 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) // Setup the GUI based on the browserwindowui.rc file. - setupGUI(StandardWindowOption::Default, ("browserwindowui.rc")); + setupGUI(StandardWindowOption::Default, (QLatin1String("browserwindowui.rc"))); + + // Set the open with other browser actions visibility. + openWithFirefoxActionPointer->setVisible(globalFirefoxInstalled); + openWithChromiumActionPointer->setVisible(globalChromiumInstalled); - // Get lists of the actions' associated widgets. - QList userAgentAssociatedWidgetsPointerList = userAgentPrivacyBrowserActionPointer->associatedWidgets(); - QList searchEngineAssociatedWidgetsPointerList = searchEngineMojeekActionPointer->associatedWidgets(); + // Get lists of the actions' associated the widgets. + QList userAgentAssociatedObjectsPointerList = userAgentPrivacyBrowserActionPointer->associatedObjects(); + QList searchEngineAssociatedObjectsPointerList = searchEngineMojeekActionPointer->associatedObjects(); // Get the menu widget pointers. It is the second entry, after the main window. - QWidget *userAgentMenuWidgetPointer = userAgentAssociatedWidgetsPointerList[1]; - QWidget *searchEngineMenuWidgetPointer = searchEngineAssociatedWidgetsPointerList[1]; + QObject *userAgentMenuObjectPointer = userAgentAssociatedObjectsPointerList[1]; + QObject *searchEngineMenuObjectPointer = searchEngineAssociatedObjectsPointerList[1]; // Get the menu pointers. - QMenu *userAgentMenuPointer = qobject_cast(userAgentMenuWidgetPointer); - QMenu *searchEngineMenuPointer = qobject_cast(searchEngineMenuWidgetPointer); + QMenu *userAgentMenuPointer = qobject_cast(userAgentMenuObjectPointer); + QMenu *searchEngineMenuPointer = qobject_cast(searchEngineMenuObjectPointer); // Get the menu actions. userAgentMenuActionPointer = userAgentMenuPointer->menuAction(); @@ -394,6 +467,9 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) urlToolBarPointer = toolBar(QLatin1String("url_toolbar")); bookmarksToolBarPointer = toolBar(QLatin1String("bookmarks_toolbar")); + // Set the blocked requests action pointer widget object name (required to change the background color with a style sheet). + urlToolBarPointer->widgetForAction(blockedRequestsActionPointer)->setObjectName("blocked_requests"); + // Populate the view bookmarks toolbar checkbox. connect(bookmarksToolBarPointer, SIGNAL(visibilityChanged(bool)), this, SLOT(updateViewBookmarksToolBarCheckbox(bool))); @@ -426,9 +502,10 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) findTextLineEditPointer->setClearButtonEnabled(true); // Add the actions to the URL line edit. - bookmarkedActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme("non-starred-symbolic"), QLineEdit::LeadingPosition); - QAction *addOrEditDomainSettingsActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme("settings-configure", QIcon::fromTheme(QLatin1String("preferences-desktop"))), + bookmarkedActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme(QLatin1String("non-starred-symbolic")), QLineEdit::LeadingPosition); + QAction *addOrEditDomainSettingsActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme(QLatin1String("settings-configure"), QIcon::fromTheme(QLatin1String("preferences-desktop"))), QLineEdit::TrailingPosition); + restoreUrlTextActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme(QLatin1String("edit-undo")), QLineEdit::TrailingPosition); // Set the bookmarked action pointer to be checkable. bookmarkedActionPointer->setCheckable(true); @@ -436,6 +513,7 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) // Connect the URL line edit actions. connect(bookmarkedActionPointer, SIGNAL(triggered()), this, SLOT(toggleBookmark())); connect(addOrEditDomainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(addOrEditDomainSettings())); + connect(restoreUrlTextActionPointer, SIGNAL(triggered()), this, SLOT(restoreUrlText())); // Create a find text label pointer. findTextLabelPointer = new QLabel(); @@ -443,10 +521,23 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) // Set the default label text. findTextLabelPointer->setText(QLatin1String(" ") + i18nc("Default find results.", "0/0") + QLatin1String(" ")); + // Create the spacer widgets. + QWidget *blockedRequestsInitialSpacerWidgetPointer = new QWidget(); + QWidget *blockedRequestsFinalSpacerWidgetPointer = new QWidget(); + QWidget *findTextSpacerWidgetPointer = new QWidget(); + + // Set the widths for the spacer widgets. + blockedRequestsInitialSpacerWidgetPointer->setFixedSize(3, 0); + blockedRequestsFinalSpacerWidgetPointer->setFixedSize(2, 0); + findTextSpacerWidgetPointer->setFixedSize(2, 0); + // Insert the widgets into the toolbars. - urlToolBarPointer->insertWidget(javaScriptActionPointer, urlLineEditPointer); + urlToolBarPointer->insertWidget(blockedRequestsActionPointer, urlLineEditPointer); + urlToolBarPointer->insertWidget(blockedRequestsActionPointer, blockedRequestsInitialSpacerWidgetPointer); + urlToolBarPointer->insertWidget(javaScriptActionPointer, blockedRequestsFinalSpacerWidgetPointer); findTextLineEditActionPointer = urlToolBarPointer->insertWidget(findNextActionPointer, findTextLineEditPointer); findTextLabelActionPointer = urlToolBarPointer->insertWidget(findNextActionPointer, findTextLabelPointer); + findTextSpacerActionPointer = urlToolBarPointer->insertWidget(findTextLineEditActionPointer, findTextSpacerWidgetPointer); // Initially hide the find text actions. hideFindTextActions(); @@ -472,6 +563,9 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) // Update the window title. connect(tabWidgetPointer, SIGNAL(updateWindowTitle(const QString)), this, SLOT(updateWindowTitle(const QString))); + // Store the URL line edit when it changes. + connect(urlLineEditPointer, SIGNAL(textChanged(const QString &)), this, SLOT(processUrlTextChanges(const QString &))); + // Get a handle for the status bar. QStatusBar *statusBarPointer = statusBar(); @@ -482,8 +576,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) zoomPlusButtonPointer = new QPushButton(); // Set the button icons. - zoomMinusButtonPointer->setIcon(QIcon::fromTheme(QStringLiteral("list-remove-symbolic"))); - zoomPlusButtonPointer->setIcon(QIcon::fromTheme(QStringLiteral("list-add-symbolic"))); + zoomMinusButtonPointer->setIcon(QIcon::fromTheme(QLatin1String("zoom-out"), QIcon::fromTheme(QLatin1String("list-remove-symbolic")))); + zoomPlusButtonPointer->setIcon(QIcon::fromTheme(QLatin1String("zoom-in"), QIcon::fromTheme(QLatin1String("list-add-symbolic")))); // Set the button icons to be flat (no borders). zoomMinusButtonPointer->setFlat(true); @@ -496,7 +590,7 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) connect(zoomPlusButtonPointer, SIGNAL(clicked()), this, SLOT(incrementZoom())); // Remove the padding around the current zoom button text. - currentZoomButtonPointer->setStyleSheet("padding: 0px;"); + currentZoomButtonPointer->setStyleSheet(QLatin1String("padding: 0px;")); // Add the widgets to the far right of the status bar. statusBarPointer->addPermanentWidget(progressBarPointer); @@ -531,14 +625,16 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) // Create keyboard shortcuts. QShortcut *f11ShortcutPointer = new QShortcut(QKeySequence(i18nc("The toggle full screen shortcut.", "F11")), this); + QShortcut *ctrlShiftRShortcut = new QShortcut(QKeySequence(i18nc("The restore URL text key sequence.", "Ctrl+Shift+R")), this); QShortcut *escapeShortcutPointer = new QShortcut(QKeySequence::Cancel, this); // Connect the keyboard shortcuts. connect(f11ShortcutPointer, SIGNAL(activated()), fullScreenActionPointer, SLOT(trigger())); + connect(ctrlShiftRShortcut, SIGNAL(activated()), restoreUrlTextActionPointer, SLOT(trigger())); connect(escapeShortcutPointer, SIGNAL(activated()), this, SLOT(escape())); // Get a handle for the Bookmarks menu. - bookmarksMenuPointer = qobject_cast(guiFactory()->container("bookmarks", this)); + bookmarksMenuPointer = qobject_cast(guiFactory()->container(QLatin1String("bookmarks"), this)); // Add a separator to the bookmarks menu. bookmarksMenuPointer->addSeparator(); @@ -779,7 +875,7 @@ void BrowserWindow::addOrEditDomainSettings() urlLineEditPointer->clearFocus(); // Get the current domain settings name. - QString ¤tDomainSettingsName = tabWidgetPointer->getDomainSettingsName(); + QString currentDomainSettingsName = tabWidgetPointer->getDomainSettingsName(); // Run the commands according to the current domain settings status. if (currentDomainSettingsName == QStringLiteral("")) // Domain settings are not currently applied. @@ -788,6 +884,11 @@ void BrowserWindow::addOrEditDomainSettings() int javaScriptInt = calculateSettingsInt(javaScriptEnabled, Settings::javaScriptEnabled()); int localStorageInt = calculateSettingsInt(localStorageActionPointer->isChecked(), Settings::localStorageEnabled()); int domStorageInt = calculateSettingsInt(domStorageActionPointer->isChecked(), Settings::domStorageEnabled()); + int ultraPrivacyInt = calculateSettingsInt(ultraPrivacyActionPointer->isChecked(), Settings::ultraPrivacyEnabled()); + int ultraListInt = calculateSettingsInt(ultraListActionPointer->isChecked(), Settings::ultraListEnabled()); + int easyPrivacyInt = calculateSettingsInt(easyPrivacyActionPointer->isChecked(), Settings::easyPrivacyEnabled()); + int easyListInt = calculateSettingsInt(easyListActionPointer->isChecked(), Settings::easyListEnabled()); + int fanboysAnnoyanceListInt = calculateSettingsInt(fanboysAnnoyanceListPointer->isChecked(), Settings::fanboysAnnoyanceListEnabled()); // Get the current user agent string. QString currentUserAgentString = tabWidgetPointer->getCurrentUserAgent(); @@ -809,23 +910,39 @@ void BrowserWindow::addOrEditDomainSettings() if (abs(currentZoomFactorDouble - defaultZoomFactorDouble ) > 0.01) zoomFactorInt = DomainsDatabase::CUSTOM; + // Update the current domain settings name. + currentDomainSettingsName = currentUrl.host(); + // Add the domain. - DomainsDatabase::addDomain(currentUrl.host(), javaScriptInt, localStorageInt, domStorageInt, userAgentDatabaseString, zoomFactorInt, currentZoomFactorDouble); + DomainsDatabase::addDomain(currentDomainSettingsName, javaScriptInt, localStorageInt, domStorageInt, userAgentDatabaseString, ultraPrivacyInt, ultraListInt, easyPrivacyInt, easyListInt, + fanboysAnnoyanceListInt, zoomFactorInt, currentZoomFactorDouble); - // Apply the domain settings. - tabWidgetPointer->applyDomainSettingsAndReload(); + // Apply the domain settings in all windows. + applyDomainSettingsInAllWindows(); } // Create the domain settings dialog pointer. DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog(this, DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsName); - // Reload the tabs when domain settings are updated. - connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload())); + // Apply the domain settings in all windows when domain settings are updated. + connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), this, SLOT(applyDomainSettingsInAllWindows())); // Show the dialog. domainSettingsDialogPointer->show(); } +void BrowserWindow::applyDomainSettingsInAllWindows() const +{ + // Apply the domain settings in all windows. + runMethodInAllWindows(QLatin1String("applyDomainSettingsInThisWindow")); +} + +void BrowserWindow::applyDomainSettingsInThisWindow() +{ + // Apply domain settings and reload the tabs. + tabWidgetPointer->applyDomainSettingsAndReload(); +} + void BrowserWindow::back() const { // Remove the focus from the URL line edit. @@ -863,9 +980,6 @@ void BrowserWindow::decrementZoom() // Set the new zoom factor. tabWidgetPointer->applyOnTheFlyZoomFactor(currentZoomFactorDouble); - - // Update the on-the-fly action text. - updateZoomActions(currentZoomFactorDouble); } void BrowserWindow::editBookmarks() @@ -999,15 +1113,13 @@ void BrowserWindow::getZoomFactorFromUser() { // Set the new zoom factor. tabWidgetPointer->applyOnTheFlyZoomFactor(newZoomFactorDouble); - - // Update the on-the-fly action text. - updateZoomActions(newZoomFactorDouble); } } void BrowserWindow::hideFindTextActions() const { // Hide the find text actions. + findTextSpacerActionPointer->setVisible(false); findTextLineEditActionPointer->setVisible(false); findTextLabelActionPointer->setVisible(false); findNextActionPointer->setVisible(false); @@ -1050,9 +1162,6 @@ void BrowserWindow::incrementZoom() // Set the new zoom factor. tabWidgetPointer->applyOnTheFlyZoomFactor(currentZoomFactorDouble); - - // Update the on-the-fly action text. - updateZoomActions(currentZoomFactorDouble); } void BrowserWindow::loadUrlFromLineEdit(const QString &url) const @@ -1073,23 +1182,22 @@ void BrowserWindow::newWindow() const browserWindowPointer->show(); } -void BrowserWindow::populateBookmarksInAllWindows() const +void BrowserWindow::openWithChromium() const { - // Get a list of all the registered service names. - QStringList registeredServiceNames = QDBusConnection::sessionBus().interface()->registeredServiceNames().value(); - - // Get a list of all the Privacy Browser windows, which will be `com.stoutner.privacybrowser-` with the PID appended. - QStringList privacyBrowserServiceNames = registeredServiceNames.filter("com.stoutner.privacybrowser"); + // Open the current URL in Chromium + QProcess::startDetached(QLatin1String("chromium"), QStringList(urlLineEditPointer->text())); +} - // Repopulate the bookmarks in each window. - for (QString privacyBrowserServiceName : privacyBrowserServiceNames) - { - // Prepare the D-Bus message. - QDBusMessage dBusMessage = QDBusMessage::createMethodCall(privacyBrowserServiceName, "/privacybrowser/MainWindow_1", "com.stoutner.privacybrowser.BrowserWindow", "populateBookmarksInThisWindow"); +void BrowserWindow::openWithFirefox() const +{ + // Open the current URL in Firefox. + QProcess::startDetached(QLatin1String("firefox-esr"), QStringList(urlLineEditPointer->text())); +} - // Make it so. - QDBusConnection::sessionBus().send(dBusMessage); - } +void BrowserWindow::populateBookmarksInAllWindows() const +{ + // Populate the bookmarks in all windows. + runMethodInAllWindows(QLatin1String("populateBookmarksInThisWindow")); } void BrowserWindow::populateBookmarksInThisWindow() @@ -1316,6 +1424,15 @@ void BrowserWindow::populateBookmarksToolBarSubfolders(const double folderId, QM } } +void BrowserWindow::processUrlTextChanges(const QString &newUrlText) const +{ + // Update the visibility of the restore URL text action pointer. + restoreUrlTextActionPointer->setVisible(newUrlText != tabWidgetPointer->getCurrentTabUrl()); + + // Store the new URL text in the WebEngine View. + tabWidgetPointer->storeCurrentUrlText(newUrlText); +} + void BrowserWindow::refresh() const { // Remove the focus from the URL line edit. @@ -1334,6 +1451,32 @@ void BrowserWindow::reloadAndBypassCache() const tabWidgetPointer->refresh(); } +void BrowserWindow::restoreUrlText() const +{ + // Restore the URL text to the current URL. + urlLineEditPointer->setText(tabWidgetPointer->getCurrentTabUrl()); +} + +void BrowserWindow::runMethodInAllWindows(const QString &methodString) const +{ + // Get a list of all the registered service names. + QStringList registeredServiceNames = QDBusConnection::sessionBus().interface()->registeredServiceNames().value(); + + // Get a list of all the Privacy Browser windows, which will be `com.stoutner.privacybrowser-` with the PID appended. + QStringList privacyBrowserServiceNames = registeredServiceNames.filter(QLatin1String("com.stoutner.privacybrowser")); + + // Reapply domain settings in each window. + for (QString privacyBrowserServiceName : privacyBrowserServiceNames) + { + // Prepare the D-Bus message. + QDBusMessage dBusMessage = QDBusMessage::createMethodCall(privacyBrowserServiceName, QLatin1String("/privacybrowser/MainWindow_1"), QLatin1String("com.stoutner.privacybrowser.BrowserWindow"), + methodString); + + // Make it so. + QDBusConnection::sessionBus().send(dBusMessage); + } +} + void BrowserWindow::showBookmarkContextMenu(const QPoint &point) { // Get the bookmark action. @@ -1458,8 +1601,8 @@ void BrowserWindow::showBookmarkContextMenu(const QPoint &point) // Temporarily set the context menu policy to the default. bookmarksToolBarPointer->setContextMenuPolicy(Qt::DefaultContextMenu); - // Create a context menu event with the same position. - QContextMenuEvent *contextMenuEventPointer = new QContextMenuEvent(QContextMenuEvent::Mouse, point); + // Create a context menu event with the same position. The global position is set to the current mouse position. + QContextMenuEvent *contextMenuEventPointer = new QContextMenuEvent(QContextMenuEvent::Mouse, point, QCursor::pos()); // Send the context menu event to the toolbar. QCoreApplication::sendEvent(bookmarksToolBarPointer, contextMenuEventPointer); @@ -1495,15 +1638,25 @@ void BrowserWindow::showDomainSettingsDialog() DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog(this); // Reload the tabs when domain settings are updated. - connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload())); + connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), this, SLOT(applyDomainSettingsInAllWindows())); // Show the dialog. 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. + findTextSpacerActionPointer->setVisible(true); findTextLineEditActionPointer->setVisible(true); findTextLabelActionPointer->setVisible(true); findNextActionPointer->setVisible(true); @@ -1535,6 +1688,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. @@ -1558,6 +1720,7 @@ void BrowserWindow::showSettingsDialog() // Apply the settings handled by KConfig. connect(settingsDialogPointer, SIGNAL(spellCheckLanguagesUpdated()), tabWidgetPointer, SLOT(applySpellCheckLanguages())); connect(settingsDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyApplicationSettings())); + //connect(settingsDialogPointer, SIGNAL(settingsChanged(QString)), this, SLOT(applyDomainSettingsInAllWindows())); connect(settingsDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyDomainSettingsAndReload())); } @@ -1680,36 +1843,63 @@ void BrowserWindow::toggleViewBookmarksToolBar() void BrowserWindow::toggleViewSourceInNewTab() const { // Get the current URL. - QString url = urlLineEditPointer->text(); + QString urlString = urlLineEditPointer->text(); // Toggle the URL. - if (url.startsWith(QLatin1String("view-source:"))) // The source is currently being viewed. + if (urlString.startsWith(QLatin1String("view-source:"))) // The source is currently being viewed. { // Remove `view-source:` from the URL. - url = url.remove(0, 12); + urlString = urlString.remove(0, 12); } else // The source is not currently being viewed. { // Prepend `view-source:` from the URL. - url = url.prepend(QLatin1String("view-source:")); + urlString = urlString.prepend(QLatin1String("view-source:")); } // Add the new tab. `true` removes the URL line edit focus, `true` opens the new tab in an adjacent tab. `false` does not open a background tab. - tabWidgetPointer->addTab(true, true, false, url); + tabWidgetPointer->addTab(true, true, false, urlString); } void BrowserWindow::updateBookmarkedAction() const { // Update the bookmarked action to reflect the current state. if (bookmarkedActionPointer->isChecked()) - bookmarkedActionPointer->setIcon(QIcon::fromTheme("starred-symbolic")); + bookmarkedActionPointer->setIcon(QIcon::fromTheme(QLatin1String("starred-symbolic"))); else - bookmarkedActionPointer->setIcon(QIcon::fromTheme("non-starred-symbolic")); + bookmarkedActionPointer->setIcon(QIcon::fromTheme(QLatin1String("non-starred-symbolic"))); +} + +void BrowserWindow::updateRequestsAction(const QVector blockedRequestsVector) const +{ + // Update the text for the actions. + ultraPrivacyActionPointer->setText(i18nc("UltraPrivacy action", "UltraPrivacy - %1 Blocked", blockedRequestsVector[PrivacyWebEngineView::ULTRAPRIVACY])); + ultraListActionPointer->setText(i18nc("UltraList action", "UltraList - %1 Blocked", blockedRequestsVector[PrivacyWebEngineView::ULTRALIST])); + easyPrivacyActionPointer->setText(i18nc("EasyPrivacy action", "EasyPrivacy - %1 Blocked", blockedRequestsVector[PrivacyWebEngineView::EASYPRIVACY])); + easyListActionPointer->setText(i18nc("EasyList action", "EasyList - %1 Blocked", blockedRequestsVector[PrivacyWebEngineView::EASYLIST])); + fanboysAnnoyanceListPointer->setText(i18nc("Fanboy's Annoyance List action", "Fanboy’s Annoyance List - %1 Blocked", blockedRequestsVector[PrivacyWebEngineView::FANBOYS_ANNOYANCE_LIST])); + requestsActionPointer->setText(i18nc("Requests action", "Requests - %1 Blocked", blockedRequestsVector[PrivacyWebEngineView::TOTAL])); + blockedRequestsActionPointer->setText(QString::number(blockedRequestsVector[PrivacyWebEngineView::TOTAL])); + + // Update the tool tips. + blockedRequestsActionPointer->setToolTip(i18nc("Blocked requests action tool tip", "%1 Blocked Requests (Ctrl+R)", blockedRequestsVector[PrivacyWebEngineView::TOTAL])); + + // Update the blocked requests action background color. + if (blockedRequestsVector[PrivacyWebEngineView::TOTAL] > 0) + urlToolBarPointer->setStyleSheet(QLatin1String("QToolButton#blocked_requests { background-color: tomato; border-radius: 5px; padding: 4px; }")); + else + urlToolBarPointer->setStyleSheet(QLatin1String("QToolButton#blocked_requests { background-color: transparent; }")); + + // Restore the domain settings indicator. + if (domainSettingsApplied) + urlLineEditPointer->setPalette(positiveBackgroundPalette); + else + urlLineEditPointer->setPalette(normalBackgroundPalette); } 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)); } @@ -1727,8 +1917,11 @@ void BrowserWindow::updateDomStorageAction(const bool &isEnabled) const void BrowserWindow::updateDomainSettingsIndicator(const bool status) { + // Store the domain settings applied status. + domainSettingsApplied = status; + // Set the domain palette according to the status. - if (status) + if (domainSettingsApplied) urlLineEditPointer->setPalette(positiveBackgroundPalette); else urlLineEditPointer->setPalette(normalBackgroundPalette); @@ -1798,7 +1991,7 @@ void BrowserWindow::updateSearchEngineActions(const QString &searchEngine, const // Initialize the custom search engine flag. bool customSearchEngine = false; - if (searchEngine == "Mojeek") // Mojeek. + if (searchEngine == QLatin1String("Mojeek")) // Mojeek. { // Check the Mojeek user agent action. searchEngineMojeekActionPointer->setChecked(true); @@ -1809,7 +2002,7 @@ void BrowserWindow::updateSearchEngineActions(const QString &searchEngine, const // Update the search engine menu action text. searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Mojeek")); } - else if (searchEngine == "Monocles") // Monocles. + else if (searchEngine == QLatin1String("Monocles")) // Monocles. { // Check the Monocles user agent action. searchEngineMonoclesActionPointer->setChecked(true); @@ -1820,7 +2013,7 @@ void BrowserWindow::updateSearchEngineActions(const QString &searchEngine, const // Update the search engine menu action text. searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Monocles")); } - else if (searchEngine == "MetaGer") // MetaGer. + else if (searchEngine == QLatin1String("MetaGer")) // MetaGer. { // Check the MetaGer user agent action. searchEngineMetagerActionPointer->setChecked(true); @@ -1831,7 +2024,7 @@ void BrowserWindow::updateSearchEngineActions(const QString &searchEngine, const // Update the search engine menu action text. searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - MetaGer")); } - else if (searchEngine == "Google") // Google. + else if (searchEngine == QLatin1String("Google")) // Google. { // Check the Google user agent action. searchEngineGoogleActionPointer->setChecked(true); @@ -1842,7 +2035,7 @@ void BrowserWindow::updateSearchEngineActions(const QString &searchEngine, const // Update the search engine menu action text. searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Google")); } - else if (searchEngine == "Bing") // Bing. + else if (searchEngine == QLatin1String("Bing")) // Bing. { // Check the Bing user agent action. searchEngineBingActionPointer->setChecked(true); @@ -1853,7 +2046,7 @@ void BrowserWindow::updateSearchEngineActions(const QString &searchEngine, const // Update the search engine menu action text. searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Bing")); } - else if (searchEngine == "Yahoo") // Yahoo. + else if (searchEngine == QLatin1String("Yahoo")) // Yahoo. { // Check the Yahoo user agent action. searchEngineYahooActionPointer->setChecked(true); @@ -1905,7 +2098,7 @@ void BrowserWindow::updateSearchEngineActions(const QString &searchEngine, const void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl) { // Get the new URL string in encoded form, which displays punycode. - QString newUrlString = newUrl.toEncoded(); + QString newUrlString = QLatin1String(newUrl.toEncoded()); // Update the view source actions. if (newUrlString.startsWith(QLatin1String("view-source:"))) // The source is currently being viewed. @@ -1937,8 +2130,8 @@ void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl) // Update the bookmarked action. updateBookmarkedAction(); - // Set the focus if the new URL is blank. - if (newUrlString == QStringLiteral("")) + // Set the focus if the new URL is blank and a website is not currently loading. + if (newUrlString == QStringLiteral("") && progressBarPointer->isHidden()) urlLineEditPointer->setFocus(); } @@ -1958,7 +2151,7 @@ void BrowserWindow::updateUserAgentActions(const QString &userAgent, const bool userAgentPrivacyBrowserActionPointer->setChecked(true); // Update the user agent menu action icon. - userAgentMenuActionPointer->setIcon(QIcon(":/icons/privacy-mode.svg")); + userAgentMenuActionPointer->setIcon(QIcon(QLatin1String(":/icons/privacy-mode.svg"))); // Update the user agent menu action text. userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Privacy Browser")); @@ -2130,7 +2323,4 @@ void BrowserWindow::zoomDefault() { // Set the new zoom factor. tabWidgetPointer->applyOnTheFlyZoomFactor(defaultZoomFactorDouble); - - // Update the on-the-fly action text. - updateZoomActions(defaultZoomFactorDouble); }