X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=src%2Fwidgets%2FTabWidget.cpp;h=dd11a6776c0f0fdc798fe4492879ff2ce5a84a08;hb=425fed98271cd951cddef9904e5e271f0fb76fc1;hp=05f10d23b970520b50a919e59cd3146c1b5cd3e2;hpb=75a38db8a253d1458aaa5a2811afb58bc4eb7855;p=PrivacyBrowserPC.git diff --git a/src/widgets/TabWidget.cpp b/src/widgets/TabWidget.cpp index 05f10d2..dd11a67 100644 --- a/src/widgets/TabWidget.cpp +++ b/src/widgets/TabWidget.cpp @@ -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(qTabWidgetPointer->widget(i)); @@ -168,7 +171,7 @@ void TabWidget::addFirstTab() qTabWidgetPointer->currentWidget()->setFocus(); } -PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const bool backgroundTab) +PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const bool backgroundTab, const QString urlString) { // Create a privacy WebEngine view. PrivacyWebEngineView *privacyWebEngineViewPointer = new PrivacyWebEngineView(); @@ -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(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; } @@ -338,12 +344,12 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const } }); - // Update the zoom factor when changed by CTRL-Scrolling. This can be modified when is fixed. + // Update the zoom actions when changed by CTRL-Scrolling. This can be modified when is fixed. connect(webEnginePagePointer, &QWebEnginePage::contentsSizeChanged, [webEnginePagePointer, this] () { - // Only update the zoom factor action text if this is the current tab. + // Only update the zoom actions if this is the current tab. if (webEnginePagePointer == currentWebEnginePagePointer) - emit updateZoomFactorAction(webEnginePagePointer->zoomFactor()); + emit updateZoomActions(webEnginePagePointer->zoomFactor()); }); // Display find text results. @@ -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); @@ -448,6 +454,9 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const if (removeUrlLineEditFocus) emit clearUrlLineEditFocus(); + if (urlString != nullptr) + privacyWebEngineViewPointer->load(QUrl::fromUserInput(urlString)); + // Return the privacy WebEngine view pointer. return privacyWebEngineViewPointer; } @@ -460,6 +469,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()); @@ -469,8 +490,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) @@ -521,10 +551,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(); @@ -688,7 +718,7 @@ void TabWidget::loadInitialWebsite() void TabWidget::loadUrlFromLineEdit(QString url) const { // Decide if the text is more likely to be a URL or a search. - if (url.startsWith("file://")) // The text is likely a file URL. + if (url.startsWith("file://") || url.startsWith("view-source:")) // The text is likely a file or view source URL. { // Load the URL. currentPrivacyWebEngineViewPointer->load(QUrl::fromUserInput(url)); @@ -810,6 +840,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. @@ -869,15 +906,15 @@ void TabWidget::showSaveDialog(QWebEngineDownloadItem *webEngineDownloadItemPoin // Set the notification text. fileDownloadNotificationPointer->setText(i18nc("Downloading notification text", "Downloading %1", saveFileName)); + // Get the download icon from the theme. + QIcon downloadIcon = QIcon::fromTheme(QLatin1String("download"), QIcon::fromTheme(QLatin1String("document-save"))); + // Set the notification icon. - fileDownloadNotificationPointer->setIconName(QLatin1String("download")); + fileDownloadNotificationPointer->setIconName(downloadIcon.name()); // Set the action list cancel button. fileDownloadNotificationPointer->setActions(QStringList({i18nc("Download notification action","Cancel")})); - // Set the notification to display indefinitely. - fileDownloadNotificationPointer->setFlags(KNotification::Persistent); - // Prevent the notification from being autodeleted if it is closed. Otherwise, the updates to the notification below cause a crash. fileDownloadNotificationPointer->setAutoDelete(false); @@ -1034,12 +1071,13 @@ void TabWidget::updateUiFromWebEngineView(const PrivacyWebEngineView *privacyWeb if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer) { // Update the UI. + emit updateDefaultZoomFactor(currentPrivacyWebEngineViewPointer->defaultZoomFactor); emit updateDomainSettingsIndicator(currentPrivacyWebEngineViewPointer->domainSettingsName != QLatin1String("")); emit updateJavaScriptAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled)); emit updateLocalStorageAction(currentPrivacyWebEngineViewPointer->localStorageEnabled); emit updateDomStorageAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); emit updateUserAgentActions(currentWebEngineProfilePointer->httpUserAgent(), true); - emit updateZoomFactorAction(currentPrivacyWebEngineViewPointer->zoomFactor()); + emit updateZoomActions(currentPrivacyWebEngineViewPointer->zoomFactor()); } } @@ -1057,6 +1095,7 @@ void TabWidget::updateUiWithTabSettings() emit clearUrlLineEditFocus(); // Update the actions. + emit updateDefaultZoomFactor(currentPrivacyWebEngineViewPointer->defaultZoomFactor); emit updateBackAction(currentWebEngineHistoryPointer->canGoBack()); emit updateCookiesAction(currentPrivacyWebEngineViewPointer->cookieListPointer->size()); emit updateDomStorageAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); @@ -1064,7 +1103,7 @@ void TabWidget::updateUiWithTabSettings() emit updateJavaScriptAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled)); emit updateLocalStorageAction(currentPrivacyWebEngineViewPointer->localStorageEnabled); emit updateUserAgentActions(currentWebEngineProfilePointer->httpUserAgent(), true); - emit updateZoomFactorAction(currentPrivacyWebEngineViewPointer->zoomFactor()); + emit updateZoomActions(currentPrivacyWebEngineViewPointer->zoomFactor()); // Update the URL. emit updateWindowTitle(currentPrivacyWebEngineViewPointer->title());