]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/widgets/TabWidget.cpp
Prevent duplicate domain settings entries from being automatically created. https...
[PrivacyBrowserPC.git] / src / widgets / TabWidget.cpp
index 05f10d23b970520b50a919e59cd3146c1b5cd3e2..f8044e2152f2b02784460de8ac79e10fe7d274a8 100644 (file)
@@ -121,8 +121,11 @@ TabWidget::TabWidget(QWidget *windowPointer) : QWidget(windowPointer)
 
 TabWidget::~TabWidget()
 {
+    // Get the number of tabs.
+    int numberOfTabs = qTabWidgetPointer->count();
+
     // Manually delete each WebEngine page.
-    for (int i = 0; i < qTabWidgetPointer->count(); ++i)
+    for (int i = 0; i < numberOfTabs; ++i)
     {
         // Get the privacy WebEngine view.
         PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast<PrivacyWebEngineView *>(qTabWidgetPointer->widget(i));
@@ -296,14 +299,17 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const
         // Create a no tabs loading variable.
         bool noTabsLoading = true;
 
+        // Get the number of tabs.
+        int numberOfTabs = qTabWidgetPointer->count();
+
         // Check to see if any other tabs are loading.
-        for (int i = 0; i < qTabWidgetPointer->count(); i++)
+        for (int i = 0; i < numberOfTabs; i++)
         {
             // Get the privacy WebEngine view for the tab.
-            PrivacyWebEngineView *webEngineViewPointer = qobject_cast<PrivacyWebEngineView*>(qTabWidgetPointer->widget(i));
+            PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast<PrivacyWebEngineView*>(qTabWidgetPointer->widget(i));
 
-            // Check to see if it is currently loading.
-            if (webEngineViewPointer->isLoading)
+            // Check to see if it is currently loading.  If at least one tab is loading, this flag will end up being marked `false` when the for loop has finished.
+            if (privacyWebEngineViewPointer->isLoading)
                 noTabsLoading = false;
         }
 
@@ -391,8 +397,8 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const
     // Don't allow JavaScript to open windows.
     webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false);
 
-    // Allow keyboard navigation.
-    webEngineSettingsPointer->setAttribute(QWebEngineSettings::SpatialNavigationEnabled, true);
+    // Allow keyboard navigation between links and input fields.
+    webEngineSettingsPointer->setAttribute(QWebEngineSettings::SpatialNavigationEnabled, Settings::spatialNavigation());
 
     // Enable full screen support.
     webEngineSettingsPointer->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true);
@@ -460,6 +466,18 @@ void TabWidget::applyApplicationSettings()
     else
         qTabWidgetPointer->setTabPosition(QTabWidget::South);
 
+    // Get the number of tabs.
+    int numberOfTabs = qTabWidgetPointer->count();
+
+    // Apply the spatial navigation settings to each WebEngine.
+    for (int i = 0; i < numberOfTabs; ++i) {
+        // Get the WebEngine view pointer.
+        PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast<PrivacyWebEngineView *>(qTabWidgetPointer->widget(i));
+
+        // Apply the spatial navigation settings to each page.
+        privacyWebEngineViewPointer->page()->settings()->setAttribute(QWebEngineSettings::SpatialNavigationEnabled, Settings::spatialNavigation());
+    }
+
     // Set the search engine URL.
     searchEngineUrl = SearchEngineHelper::getSearchUrl(Settings::searchEngine());
 
@@ -469,8 +487,17 @@ void TabWidget::applyApplicationSettings()
 
 void TabWidget::applyDomainSettingsAndReload()
 {
-    // Apply the domain settings.  `true` reloads the website.
-    currentPrivacyWebEngineViewPointer->applyDomainSettings(currentPrivacyWebEngineViewPointer->url().host(), true);
+    // Get the number of tabs.
+    int numberOfTabs = qTabWidgetPointer->count();
+
+    // Apply the domain settings to each WebEngine.
+    for (int i = 0; i < numberOfTabs; ++i) {
+        // Get the WebEngine view pointer.
+        PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast<PrivacyWebEngineView *>(qTabWidgetPointer->widget(i));
+
+        // Apply the spatial navigation settings to each page.
+        privacyWebEngineViewPointer->applyDomainSettings(privacyWebEngineViewPointer->url().host(), true);
+    }
 }
 
 void TabWidget::applyOnTheFlySearchEngine(QAction *searchEngineActionPointer)
@@ -521,10 +548,10 @@ void TabWidget::applySpellCheckLanguages() const
     for (int i = 0; i < numberOfTabs; ++i)
     {
         // Get the WebEngine view pointer.
-        PrivacyWebEngineView *webEngineViewPointer = qobject_cast<PrivacyWebEngineView *>(qTabWidgetPointer->currentWidget());
+        PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast<PrivacyWebEngineView *>(qTabWidgetPointer->widget(i));
 
         // Get the WebEngine page pointer.
-        QWebEnginePage *webEnginePagePointer = webEngineViewPointer->page();
+        QWebEnginePage *webEnginePagePointer = privacyWebEngineViewPointer->page();
 
         // Get the WebEngine profile pointer.
         QWebEngineProfile *webEngineProfilePointer = webEnginePagePointer->profile();
@@ -810,6 +837,13 @@ void TabWidget::refresh() const
     currentPrivacyWebEngineViewPointer->reload();
 }
 
+void TabWidget::reloadAndBypassCache() const
+{
+    // Reload the website, bypassing the cache.
+    currentWebEnginePagePointer->triggerAction(QWebEnginePage::ReloadAndBypassCache);
+}
+
+
 void TabWidget::setTabBarVisible(const bool visible) const
 {
     // Set the tab bar visibility.