]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/widgets/PrivacyWebEngineView.cpp
Open new tabs adjacent to the current tab. https://redmine.stoutner.com/issues/1110
[PrivacyBrowserPC.git] / src / widgets / PrivacyWebEngineView.cpp
index 96a0da5d67735743225293e0ca6a8db1990e5922..05c765925d8aa6da639c4f4f019634ffc3d956f5 100644 (file)
@@ -30,7 +30,7 @@
 #include <QMenu>
 
 // Construct the class.
-PrivacyWebEngineView::PrivacyWebEngineView() : QWebEngineView(nullptr)
+PrivacyWebEngineView::PrivacyWebEngineView(QWidget *parentWidgetPointer) : QWebEngineView(parentWidgetPointer)
 {
     // Create an off-the-record profile (the default when no profile name is specified).
     webEngineProfilePointer = new QWebEngineProfile(QLatin1String(""));
@@ -45,7 +45,7 @@ PrivacyWebEngineView::PrivacyWebEngineView() : QWebEngineView(nullptr)
     webEngineSettingsPointer = webEnginePagePointer->settings();
 
     // Instantiate the URL request interceptor.
-    UrlRequestInterceptor *urlRequestInterceptorPointer = new UrlRequestInterceptor();
+    UrlRequestInterceptor *urlRequestInterceptorPointer = new UrlRequestInterceptor(this);
 
     // Set the URL request interceptor.
     webEngineProfilePointer->setUrlRequestInterceptor(urlRequestInterceptorPointer);
@@ -86,14 +86,11 @@ void PrivacyWebEngineView::applyDomainSettings(const QString &hostname, const bo
     // Check if the hostname has domain settings.
     if (domainQuery.isValid())  // The hostname has domain settings.
     {
-        // Get the domain record.
-        QSqlRecord domainRecord = domainQuery.record();
-
         // Store the domain settings name.
-        domainSettingsName = domainRecord.field(DomainsDatabase::DOMAIN_NAME).value().toString();
+        domainSettingsName = domainQuery.value(DomainsDatabase::DOMAIN_NAME).toString();
 
         // Set the JavaScript status.
-        switch (domainRecord.field(DomainsDatabase::JAVASCRIPT).value().toInt())
+        switch (domainQuery.value(DomainsDatabase::JAVASCRIPT).toInt())
         {
             // Set the default JavaScript status.
             case (DomainsDatabase::SYSTEM_DEFAULT):
@@ -103,25 +100,25 @@ void PrivacyWebEngineView::applyDomainSettings(const QString &hostname, const bo
                 break;
             }
 
-            // Disable JavaScript.
-            case (DomainsDatabase::DISABLED):
+            // Enable JavaScript.
+            case (DomainsDatabase::ENABLED):
             {
-                webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
+                webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
 
                 break;
             }
 
-            // Enable JavaScript.
-            case (DomainsDatabase::ENABLED):
+            // Disable JavaScript.
+            case (DomainsDatabase::DISABLED):
             {
-                webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
+                webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
 
                 break;
             }
         }
 
         // Set the local storage status.
-        switch (domainRecord.field(DomainsDatabase::LOCAL_STORAGE).value().toInt())
+        switch (domainQuery.value(DomainsDatabase::LOCAL_STORAGE).toInt())
         {
             // Set the default local storage status.
             case (DomainsDatabase::SYSTEM_DEFAULT):
@@ -131,25 +128,25 @@ void PrivacyWebEngineView::applyDomainSettings(const QString &hostname, const bo
                 break;
             }
 
-            // Disable local storage.
-            case (DomainsDatabase::DISABLED):
+            // Enable local storage.
+            case (DomainsDatabase::ENABLED):
             {
-                localStorageEnabled = false;
+                localStorageEnabled = true;
 
                 break;
             }
 
-            // Enable local storage.
-            case (DomainsDatabase::ENABLED):
+            // Disable local storage.
+            case (DomainsDatabase::DISABLED):
             {
-                localStorageEnabled = true;
+                localStorageEnabled = false;
 
                 break;
             }
         }
 
         // Set the DOM storage status.
-        switch (domainRecord.field(DomainsDatabase::DOM_STORAGE).value().toInt())
+        switch (domainQuery.value(DomainsDatabase::DOM_STORAGE).toInt())
         {
             // Set the default DOM storage status.  QWebEngineSettings confusingly calls this local storage.
             case (DomainsDatabase::SYSTEM_DEFAULT):
@@ -159,36 +156,36 @@ void PrivacyWebEngineView::applyDomainSettings(const QString &hostname, const bo
                 break;
             }
 
-            // Disable DOM storage.  QWebEngineSettings confusingly calls this local storage.
-            case (DomainsDatabase::DISABLED):
+            // Enable DOM storage.  QWebEngineSettings confusingly calls this local storage.
+            case (DomainsDatabase::ENABLED):
             {
-                webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, false);
+                webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, true);
 
                 break;
             }
 
-            // Enable DOM storage.  QWebEngineSettings confusingly calls this local storage.
-            case (DomainsDatabase::ENABLED):
+            // Disable DOM storage.  QWebEngineSettings confusingly calls this local storage.
+            case (DomainsDatabase::DISABLED):
             {
-                webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, true);
+                webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, false);
 
                 break;
             }
         }
 
         // Set the user agent.
-        webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getResultingDomainSettingsUserAgent(domainRecord.field(DomainsDatabase::USER_AGENT).value().toString()));
+        webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getResultingDomainSettingsUserAgent(domainQuery.value(DomainsDatabase::USER_AGENT).toString()));
 
         // Check if a custom zoom factor is set.
-        if (domainRecord.field(DomainsDatabase::ZOOM_FACTOR).value().toInt())
+        if (domainQuery.value(DomainsDatabase::ZOOM_FACTOR).toInt())
         {
             // Store the current zoom factor.
-            setZoomFactor(domainRecord.field(DomainsDatabase::CUSTOM_ZOOM_FACTOR).value().toDouble());
+            defaultZoomFactor = domainQuery.value(DomainsDatabase::CUSTOM_ZOOM_FACTOR).toDouble();
         }
         else
         {
-            // Reset the current zoom factor.
-            setZoomFactor(Settings::zoomFactor());
+            // Store the current zoom factor.
+            defaultZoomFactor = Settings::zoomFactor();
         }
     }
     else  // The hostname does not have domain settings.
@@ -208,10 +205,13 @@ void PrivacyWebEngineView::applyDomainSettings(const QString &hostname, const bo
         // Set the user agent.
         webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent()));
 
-        // Set the zoom factor.
-        setZoomFactor(Settings::zoomFactor());
+        // Store the zoom factor.
+        defaultZoomFactor = Settings::zoomFactor();
     }
 
+    // Set the current zoom factor.
+    setZoomFactor(defaultZoomFactor);
+
     // Reload the website if requested.
     if (reloadWebsite)
         reload();
@@ -259,9 +259,9 @@ QWebEngineView* PrivacyWebEngineView::createWindow(QWebEnginePage::WebWindowType
     {
         case QWebEnginePage::WebBrowserTab:
         {
-            // Create the new tab and return the privacy WebEngine view pointer.  `true` removes the focus from the blank URL line edit.
+            // Create the new tab and return the privacy WebEngine view pointer.  `true` removes the focus from the blank URL line edit.  `true` adds the new tab adjacent to the current tab.
             // The new privacy WebEngine view pointer is returned so it can be populated with the link from the context menu.
-            return browserWindowPointer->tabWidgetPointer->addTab(true);
+            return browserWindowPointer->tabWidgetPointer->addTab(true, true);
         }
 
         case QWebEnginePage::WebBrowserWindow:
@@ -278,9 +278,10 @@ QWebEngineView* PrivacyWebEngineView::createWindow(QWebEnginePage::WebWindowType
 
         case QWebEnginePage::WebBrowserBackgroundTab:
         {
-            // Create the new tab and return the privacy WebEngine view pointer.  `false` does not clear the URL line edit.  `true` creates a background tab.
+            // Create the new tab and return the privacy WebEngine view pointer.  `false` does not clear the URL line edit.  `true` adds the new tab adjacent to the current tab.
+            // `true` creates a background tab.
             // The new privacy WebEngine view pointer is returned so it can be populated with the link from the context menu.
-            return browserWindowPointer->tabWidgetPointer->addTab(false, true);
+            return browserWindowPointer->tabWidgetPointer->addTab(false, true, true);
         }
 
         default: