X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=src%2Fwidgets%2FTabWidget.cpp;h=f8044e2152f2b02784460de8ac79e10fe7d274a8;hb=6a4af266d064e144822e46dc193f6d8c27ea6eb5;hp=28a6cf2da591ef59e5e8d9a72b0f5fe5f6424d5c;hpb=2cdfb2ff48e9933d9d957fd706a449bf5a6f322f;p=PrivacyBrowserPC.git diff --git a/src/widgets/TabWidget.cpp b/src/widgets/TabWidget.cpp index 28a6cf2..f8044e2 100644 --- a/src/widgets/TabWidget.cpp +++ b/src/widgets/TabWidget.cpp @@ -47,7 +47,7 @@ QString TabWidget::webEngineDefaultUserAgent = QLatin1String(""); // Construct the class. -TabWidget::TabWidget(QWidget *parent) : QWidget(parent) +TabWidget::TabWidget(QWidget *windowPointer) : QWidget(windowPointer) { // Create a QProcess to check if KDE is running. QProcess *checkIfRunningKdeQProcessPointer = new QProcess(); @@ -94,6 +94,9 @@ TabWidget::TabWidget(QWidget *parent) : QWidget(parent) // Set the loading favorite icon movie file name. loadingFavoriteIconMoviePointer->setFileName(QStringLiteral(":/icons/loading.gif")); + // Stop the loading favorite icon movie if the window is destroyed. Otherwise, the app will crash if there is more than one window open and a window is closed while at tab is loading. + connect(windowPointer, SIGNAL(destroyed()), this, SLOT(stopLoadingFavoriteIconMovie())); + // Add the first tab. addFirstTab(); @@ -118,8 +121,11 @@ TabWidget::TabWidget(QWidget *parent) : QWidget(parent) 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(qTabWidgetPointer->widget(i)); @@ -293,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(qTabWidgetPointer->widget(i)); + PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast(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; } @@ -388,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); @@ -457,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(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()); @@ -466,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(qTabWidgetPointer->widget(i)); + + // Apply the spatial navigation settings to each page. + privacyWebEngineViewPointer->applyDomainSettings(privacyWebEngineViewPointer->url().host(), true); + } } void TabWidget::applyOnTheFlySearchEngine(QAction *searchEngineActionPointer) @@ -518,10 +548,10 @@ void TabWidget::applySpellCheckLanguages() const for (int i = 0; i < numberOfTabs; ++i) { // Get the WebEngine view pointer. - PrivacyWebEngineView *webEngineViewPointer = qobject_cast(qTabWidgetPointer->currentWidget()); + PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast(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(); @@ -741,6 +771,12 @@ void TabWidget::pageLinkHovered(const QString &linkUrl) const emit linkHovered(linkUrl); } +void TabWidget::stopLoadingFavoriteIconMovie() const +{ + // Stop the loading favorite icon movie. Otherwise, the browser will crash if a second window is closed while a tab in it is loading. + loadingFavoriteIconMoviePointer->stop(); +} + void TabWidget::print() const { // Create a printer. @@ -801,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.