]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/widgets/TabWidget.cpp
Implement opening web pages in other browsers. https://redmine.stoutner.com/issues...
[PrivacyBrowserPC.git] / src / widgets / TabWidget.cpp
index 58ccfc65281af538a445d44411e174973dc44113..c7de2207b00b40a977c0c236c4d53fe083b72218 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 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
@@ -22,7 +22,6 @@
 #include "TabWidget.h"
 #include "Settings.h"
 #include "ui_AddTabWidget.h"
-#include "ui_Tab.h"
 #include "ui_TabWidget.h"
 #include "databases/CookiesDatabase.h"
 #include "dialogs/SaveDialog.h"
@@ -44,6 +43,7 @@
 #include <QPrintDialog>
 #include <QPrintPreviewDialog>
 #include <QPrinter>
+#include <QSplitter>
 
 // Initialize the public static variables.
 QString TabWidget::webEngineDefaultUserAgent = QLatin1String("");
@@ -452,12 +452,20 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const
     // Plugins must be enabled for the PDF viewer to work.  <https://doc.qt.io/qt-5/qtwebengine-features.html#pdf-file-viewing>
     webEngineSettingsPointer->setAttribute(QWebEngineSettings::PluginsEnabled, true);
 
+    // Update the blocked requests action.
+    connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::requestBlocked, [this, privacyWebEngineViewPointer] (const QVector<int> blockedRequestsVector)
+    {
+        // Update the blocked requests action if the specified privacy WebEngine view is the current privacy WebEngine view.
+        if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
+            emit blockedRequestsUpdated(blockedRequestsVector);
+    });
+
     // Update the cookies action.
-    connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::updateCookiesAction, [this, privacyWebEngineViewPointer] (const int numberOfCookies)
+    connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::numberOfCookiesChanged, [this, privacyWebEngineViewPointer] (const int numberOfCookies)
     {
         // Update the cookie action if the specified privacy WebEngine view is the current privacy WebEngine view.
         if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
-            emit updateCookiesAction(numberOfCookies);
+            emit cookiesChanged(numberOfCookies);
     });
 
     // Process cookie changes.
@@ -906,6 +914,9 @@ void TabWidget::printWebpage(QPrinter *printerPointer) const
 
 void TabWidget::refresh() const
 {
+    // Reset the HTTP authentication dialog counter.
+    currentPrivacyWebEngineViewPointer->httpAuthenticationDialogsDisplayed = 0;
+
     // Reload the website.
     currentPrivacyWebEngineViewPointer->reload();
 }
@@ -967,7 +978,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 +1121,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 &)));
@@ -1174,6 +1185,33 @@ void TabWidget::toggleDomStorage() const
     currentPrivacyWebEngineViewPointer->reload();
 }
 
+void TabWidget::toggleEasyList() const
+{
+    // Toggle EasyList.
+    currentPrivacyWebEngineViewPointer->easyListEnabled = !currentPrivacyWebEngineViewPointer->easyListEnabled;
+
+    // Reload the website.
+    currentPrivacyWebEngineViewPointer->reload();
+}
+
+void TabWidget::toggleEasyPrivacy() const
+{
+    // Toggle EasyPrivacy.
+    currentPrivacyWebEngineViewPointer->easyPrivacyEnabled = !currentPrivacyWebEngineViewPointer->easyPrivacyEnabled;
+
+    // Reload the website.
+    currentPrivacyWebEngineViewPointer->reload();
+}
+
+void TabWidget::toggleFanboysAnnoyanceList() const
+{
+    // Toggle Fanboy's Annoyance List.
+    currentPrivacyWebEngineViewPointer->fanboysAnnoyanceListEnabled = !currentPrivacyWebEngineViewPointer->fanboysAnnoyanceListEnabled;
+
+    // Reload the website.
+    currentPrivacyWebEngineViewPointer->reload();
+}
+
 void TabWidget::toggleFindCaseSensitive(const QString &text)
 {
     // Toggle find case sensitive.
@@ -1213,6 +1251,24 @@ void TabWidget::toggleLocalStorage()
     currentPrivacyWebEngineViewPointer->reload();
 }
 
+void TabWidget::toggleUltraList() const
+{
+    // Toggle UltraList.
+    currentPrivacyWebEngineViewPointer->ultraListEnabled = !currentPrivacyWebEngineViewPointer->ultraListEnabled;
+
+    // Reload the website.
+    currentPrivacyWebEngineViewPointer->reload();
+}
+
+void TabWidget::toggleUltraPrivacy() const
+{
+    // Toggle UltraPrivacy.
+    currentPrivacyWebEngineViewPointer->ultraPrivacyEnabled = !currentPrivacyWebEngineViewPointer->ultraPrivacyEnabled;
+
+    // Reload the website.
+    currentPrivacyWebEngineViewPointer->reload();
+}
+
 void TabWidget::updateDownloadDirectory(QString newDownloadDirectory) const
 {
     // Remove the file name from the save file path.
@@ -1234,6 +1290,11 @@ void TabWidget::updateUiFromWebEngineView(const PrivacyWebEngineView *privacyWeb
     if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
     {
         // Update the UI.
+        emit easyListStatusChanged(currentPrivacyWebEngineViewPointer->easyListEnabled);
+        emit easyPrivacyStatusChanged(currentPrivacyWebEngineViewPointer->easyPrivacyEnabled);
+        emit fanboysAnnoyanceListStatusChanged(currentPrivacyWebEngineViewPointer->fanboysAnnoyanceListEnabled);
+        emit ultraListStatusChanged(currentPrivacyWebEngineViewPointer->ultraListEnabled);
+        emit ultraPrivacyStatusChanged(currentPrivacyWebEngineViewPointer->ultraPrivacyEnabled);
         emit updateDefaultZoomFactor(currentPrivacyWebEngineViewPointer->defaultZoomFactor);
         emit updateDomainSettingsIndicator(currentPrivacyWebEngineViewPointer->domainSettingsName != QLatin1String(""));
         emit updateJavaScriptAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled));
@@ -1261,9 +1322,15 @@ void TabWidget::updateUiWithTabSettings()
     DevToolsWebEngineView *devToolsWebEngineViewPointer = qTabWidgetPointer->currentWidget()->findChild<DevToolsWebEngineView *>();
 
     // Update the actions.
-    emit updateDefaultZoomFactor(currentPrivacyWebEngineViewPointer->defaultZoomFactor);
+    emit easyListStatusChanged(currentPrivacyWebEngineViewPointer->easyListEnabled);
+    emit easyPrivacyStatusChanged(currentPrivacyWebEngineViewPointer->easyPrivacyEnabled);
+    emit fanboysAnnoyanceListStatusChanged(currentPrivacyWebEngineViewPointer->fanboysAnnoyanceListEnabled);
+    emit ultraListStatusChanged(currentPrivacyWebEngineViewPointer->ultraListEnabled);
+    emit ultraPrivacyStatusChanged(currentPrivacyWebEngineViewPointer->ultraPrivacyEnabled);
+    emit blockedRequestsUpdated(currentPrivacyWebEngineViewPointer->blockedRequestsVector);
+    emit cookiesChanged(currentPrivacyWebEngineViewPointer->cookieListPointer->size());
     emit updateBackAction(currentWebEngineHistoryPointer->canGoBack());
-    emit updateCookiesAction(currentPrivacyWebEngineViewPointer->cookieListPointer->size());
+    emit updateDefaultZoomFactor(currentPrivacyWebEngineViewPointer->defaultZoomFactor);
     emit updateDeveloperToolsAction(devToolsWebEngineViewPointer->isVisible());
     emit updateDomStorageAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled));
     emit updateForwardAction(currentWebEngineHistoryPointer->canGoForward());
@@ -1336,3 +1403,4 @@ void TabWidget::useNativeKdeDownloader(QUrl &downloadUrl, QString &suggestedFile
     // Show the dialog.
     saveFileDialogPointer->show();
 }
+