X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=src%2Fwidgets%2FTabWidget.cpp;h=cbb84b3dfe3c9d9f081da5870c48d662b1dbe039;hb=efed1601e5f6e79d746866d55d625d777b64a248;hp=5b5a08c630cbae3985ef41b42711d6ba88459bef;hpb=93a1583163ca580a2218ba81836a17c3a6586ccf;p=PrivacyBrowserPC.git diff --git a/src/widgets/TabWidget.cpp b/src/widgets/TabWidget.cpp index 5b5a08c..cbb84b3 100644 --- a/src/widgets/TabWidget.cpp +++ b/src/widgets/TabWidget.cpp @@ -23,11 +23,9 @@ #include "ui_AddTabWidget.h" #include "ui_TabWidget.h" #include "databases/CookiesDatabase.h" -#include "databases/DomainsDatabase.h" #include "dialogs/SaveDialog.h" #include "filters/MouseEventFilter.h" #include "helpers/SearchEngineHelper.h" -#include "interceptors/UrlRequestInterceptor.h" #include "windows/BrowserWindow.h" // KDE Framework headers. @@ -40,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +49,22 @@ QString TabWidget::webEngineDefaultUserAgent = QLatin1String(""); // Construct the class. TabWidget::TabWidget(QWidget *parent) : QWidget(parent) { + // Create a QProcess to check if KDE is running. + QProcess *checkIfRunningKdeQProcessPointer = new QProcess(); + + // Create an argument string list that contains `ksmserver` (KDE Session Manager). + QStringList argument = QStringList(QLatin1String("ksmserver")); + + // Run `pidof` to check for the presence of `ksmserver`. + checkIfRunningKdeQProcessPointer->start(QLatin1String("pidof"), argument); + + // Monitor any standard output. + connect(checkIfRunningKdeQProcessPointer, &QProcess::readyReadStandardOutput, [this] + { + // If there is any standard output, `ksmserver` is running. + isRunningKde = true; + }); + // Instantiate the user agent helper. userAgentHelperPointer = new UserAgentHelper(); @@ -61,25 +76,31 @@ TabWidget::TabWidget(QWidget *parent) : QWidget(parent) tabWidgetUi.setupUi(this); // Get a handle for the tab widget. - tabWidgetPointer = tabWidgetUi.tabWidget; + qTabWidgetPointer = tabWidgetUi.tabWidget; // Setup the add tab UI. - addTabWidgetUi.setupUi(tabWidgetPointer); + addTabWidgetUi.setupUi(qTabWidgetPointer); // Get handles for the add tab widgets. QWidget *addTabWidgetPointer = addTabWidgetUi.addTabQWidget; QPushButton *addTabButtonPointer = addTabWidgetUi.addTabButton; // Display the add tab widget. - tabWidgetPointer->setCornerWidget(addTabWidgetPointer); + qTabWidgetPointer->setCornerWidget(addTabWidgetPointer); + + // Create the loading favorite icon movie. + loadingFavoriteIconMoviePointer = new QMovie(); + + // Set the loading favorite icon movie file name. + loadingFavoriteIconMoviePointer->setFileName(QStringLiteral(":/icons/loading.gif")); // Add the first tab. addFirstTab(); // Process tab events. - connect(tabWidgetPointer, SIGNAL(currentChanged(int)), this, SLOT(updateUiWithTabSettings())); + connect(qTabWidgetPointer, SIGNAL(currentChanged(int)), this, SLOT(updateUiWithTabSettings())); connect(addTabButtonPointer, SIGNAL(clicked()), this, SLOT(addTab())); - connect(tabWidgetPointer, SIGNAL(tabCloseRequested(int)), this, SLOT(deleteTab(int))); + connect(qTabWidgetPointer, SIGNAL(tabCloseRequested(int)), this, SLOT(deleteTab(int))); // Store a copy of the WebEngine default user agent. webEngineDefaultUserAgent = currentWebEngineProfilePointer->httpUserAgent(); @@ -98,10 +119,10 @@ TabWidget::TabWidget(QWidget *parent) : QWidget(parent) TabWidget::~TabWidget() { // Manually delete each WebEngine page. - for (int i = 0; i < tabWidgetPointer->count(); ++i) + for (int i = 0; i < qTabWidgetPointer->count(); ++i) { // Get the privacy WebEngine view. - PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast(tabWidgetPointer->widget(i)); + PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast(qTabWidgetPointer->widget(i)); // Deletion the WebEngine page to prevent the following error: `Release of profile requested but WebEnginePage still not deleted. Expect troubles !` delete privacyWebEngineViewPointer->page(); @@ -111,7 +132,7 @@ TabWidget::~TabWidget() // The cookie is copied instead of referenced so that changes made to the cookie do not create a race condition with the display of the cookie in the dialog. void TabWidget::addCookieToStore(QNetworkCookie cookie, QWebEngineCookieStore *webEngineCookieStorePointer) const { - // Create a url. + // Create a URL. QUrl url; // Check to see if the domain does not start with a `.` because Qt makes this harder than it should be. @@ -141,7 +162,7 @@ void TabWidget::addFirstTab() updateUiWithTabSettings(); // Set the focus on the current tab widget. This prevents the tab bar from showing a blue bar under the label of the first tab. - tabWidgetPointer->currentWidget()->setFocus(); + qTabWidgetPointer->currentWidget()->setFocus(); } PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const bool backgroundTab) @@ -150,26 +171,21 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const PrivacyWebEngineView *privacyWebEngineViewPointer = new PrivacyWebEngineView(); // Add a new tab. - int newTabIndex = tabWidgetPointer->addTab(privacyWebEngineViewPointer, i18nc("New tab label.", "New Tab")); + int newTabIndex = qTabWidgetPointer->addTab(privacyWebEngineViewPointer, i18nc("New tab label.", "New Tab")); // Set the default tab icon. - tabWidgetPointer->setTabIcon(newTabIndex, defaultTabIcon); - - // Create an off-the-record profile (the default when no profile name is specified). - QWebEngineProfile *webEngineProfilePointer = new QWebEngineProfile(QLatin1String("")); + qTabWidgetPointer->setTabIcon(newTabIndex, defaultFavoriteIcon); - // Create a WebEngine page. - QWebEnginePage *webEnginePagePointer = new QWebEnginePage(webEngineProfilePointer); - - // Set the WebEngine page. - privacyWebEngineViewPointer->setPage(webEnginePagePointer); + // Get handles for the WebEngine page and profile. + QWebEnginePage *webEnginePagePointer = privacyWebEngineViewPointer->page(); + QWebEngineProfile *webEngineProfilePointer = webEnginePagePointer->profile(); // Get handles for the web engine elements. QWebEngineCookieStore *webEngineCookieStorePointer = webEngineProfilePointer->cookieStore(); QWebEngineSettings *webEngineSettingsPointer = webEnginePagePointer->settings(); // Update the URL line edit when the URL changes. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::urlChanged, [privacyWebEngineViewPointer, this] (const QUrl &newUrl) + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::urlChanged, [this, privacyWebEngineViewPointer] (const QUrl &newUrl) { // Only update the UI if this is the current tab. if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer) @@ -181,24 +197,71 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const emit updateBackAction(currentWebEngineHistoryPointer->canGoBack()); emit updateForwardAction(currentWebEngineHistoryPointer->canGoForward()); } + }); + + // Update the title when it changes. + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::titleChanged, [this, privacyWebEngineViewPointer] (const QString &title) + { + // Get the index for this tab. + int tabIndex = qTabWidgetPointer->indexOf(privacyWebEngineViewPointer); + + // Update the title for this tab. + qTabWidgetPointer->setTabText(tabIndex, title); + + // Update the window title if this is the current tab. + if (tabIndex == qTabWidgetPointer->currentIndex()) + emit updateWindowTitle(title); + }); + + // Connect the loading favorite icon movie to the tab icon. + connect(loadingFavoriteIconMoviePointer, &QMovie::frameChanged, [this, privacyWebEngineViewPointer] + { + // Get the index for this tab. + int tabIndex = qTabWidgetPointer->indexOf(privacyWebEngineViewPointer); - // Reapply the zoom factor. This is a bug in QWebEngineView that resets the zoom with every load. It can be removed once is fixed. - privacyWebEngineViewPointer->setZoomFactor(currentZoomFactor); + // Display the loading favorite icon if this tab is loading. + if (privacyWebEngineViewPointer->isLoading) + qTabWidgetPointer->setTabIcon(tabIndex, loadingFavoriteIconMoviePointer->currentPixmap()); }); - // Update the progress bar when a load is started. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadStarted, [privacyWebEngineViewPointer, this] () + // Update the icon when it changes. + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::iconChanged, [this, privacyWebEngineViewPointer] (const QIcon &newFavoriteIcon) { + // Store the favorite icon in the privacy web engine view. + if (newFavoriteIcon.isNull()) + privacyWebEngineViewPointer->favoriteIcon = defaultFavoriteIcon; + else + privacyWebEngineViewPointer->favoriteIcon = newFavoriteIcon; + + // Get the index for this tab. + int tabIndex = qTabWidgetPointer->indexOf(privacyWebEngineViewPointer); + + // Update the icon for this tab. + if (newFavoriteIcon.isNull()) + qTabWidgetPointer->setTabIcon(tabIndex, defaultFavoriteIcon); + else + qTabWidgetPointer->setTabIcon(tabIndex, newFavoriteIcon); + }); + + // Update the progress bar and the favorite icon when a load is started. + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadStarted, [this, privacyWebEngineViewPointer] () + { + // Set the privacy web engine view to be loading. + privacyWebEngineViewPointer->isLoading = true; + // Store the load progress. privacyWebEngineViewPointer->loadProgressInt = 0; // Show the progress bar if this is the current tab. if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer) emit showProgressBar(0); + + // Start the loading favorite icon movie. + loadingFavoriteIconMoviePointer->start(); }); // Update the progress bar when a load progresses. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadProgress, [privacyWebEngineViewPointer, this] (const int progress) + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadProgress, [this, privacyWebEngineViewPointer] (const int progress) { // Store the load progress. privacyWebEngineViewPointer->loadProgressInt = progress; @@ -209,14 +272,67 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const }); // Update the progress bar when a load finishes. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadFinished, [privacyWebEngineViewPointer, this] () + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadFinished, [this, privacyWebEngineViewPointer] () { + // Set the privacy web engine view to be not loading. + privacyWebEngineViewPointer->isLoading = false; + // Store the load progress. privacyWebEngineViewPointer->loadProgressInt = -1; // Hide the progress bar if this is the current tab. if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer) emit hideProgressBar(); + + // Get the index for this tab. + int tabIndex = qTabWidgetPointer->indexOf(privacyWebEngineViewPointer); + + // Display the current favorite icon + qTabWidgetPointer->setTabIcon(tabIndex, privacyWebEngineViewPointer->favoriteIcon); + + // Create a no tabs loading variable. + bool noTabsLoading = true; + + // Check to see if any other tabs are loading. + for (int i = 0; i < qTabWidgetPointer->count(); i++) + { + // Get the privacy WebEngine view for the tab. + PrivacyWebEngineView *webEngineViewPointer = qobject_cast(qTabWidgetPointer->widget(i)); + + // Check to see if it is currently loading. + if (webEngineViewPointer->isLoading) + noTabsLoading = false; + } + + // Stop the loading favorite icon movie if there are no loading tabs. + if (noTabsLoading) + loadingFavoriteIconMoviePointer->stop(); + }); + + // Display HTTP Ping blocked dialogs. + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::displayHttpPingBlockedDialog, [this, privacyWebEngineViewPointer] (const QString &httpPingUrl) + { + // Only display the HTTP Ping blocked dialog if this is the current tab. + if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer) + { + // Instantiate an HTTP ping blocked message box. + QMessageBox httpPingBlockedMessageBox; + + // Set the icon. + httpPingBlockedMessageBox.setIcon(QMessageBox::Information); + + // Set the window title. + httpPingBlockedMessageBox.setWindowTitle(i18nc("HTTP Ping blocked dialog title", "HTTP Ping Blocked")); + + // Set the text. + httpPingBlockedMessageBox.setText(i18nc("HTTP Ping blocked dialog text", "This request has been blocked because it sends a naughty HTTP ping to %1.", httpPingUrl)); + + // Set the standard button. + httpPingBlockedMessageBox.setStandardButtons(QMessageBox::Ok); + + // Display the message box. + httpPingBlockedMessageBox.exec(); + } }); // Update the zoom factor when changed by CTRL-Scrolling. This can be modified when is fixed. @@ -239,15 +355,6 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const // Handle file downloads. connect(webEngineProfilePointer, SIGNAL(downloadRequested(QWebEngineDownloadItem *)), this, SLOT(showSaveDialog(QWebEngineDownloadItem *))); - // Instantiate the URL request interceptor. - UrlRequestInterceptor *urlRequestInterceptorPointer = new UrlRequestInterceptor(); - - // Set the URL request interceptor. - webEngineProfilePointer->setUrlRequestInterceptor(urlRequestInterceptorPointer); - - // Reapply the domain settings when the host changes. - connect(urlRequestInterceptorPointer, SIGNAL(applyDomainSettings(QString)), this, SLOT(applyDomainSettingsWithoutReloading(QString))); - // Set the local storage filter. webEngineCookieStorePointer->setCookieFilter([privacyWebEngineViewPointer](const QWebEngineCookieStore::FilterRequest &filterRequest) { @@ -300,7 +407,7 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const webEngineSettingsPointer->setAttribute(QWebEngineSettings::PluginsEnabled, true); // Update the cookies action. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::updateCookiesAction, [privacyWebEngineViewPointer, this] (const int numberOfCookies) + connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::updateCookiesAction, [this, privacyWebEngineViewPointer] (const int numberOfCookies) { // Update the cookie action if the specified privacy WebEngine view is the current privacy WebEngine view. if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer) @@ -318,33 +425,6 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const for (QNetworkCookie *cookiePointer : *durableCookiesListPointer) addCookieToStore(*cookiePointer, webEngineCookieStorePointer); - // Update the title when it changes. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::titleChanged, [this, privacyWebEngineViewPointer] (const QString &title) - { - // Get the index for this tab. - int tabIndex = tabWidgetPointer->indexOf(privacyWebEngineViewPointer); - - // Update the title for this tab. - tabWidgetPointer->setTabText(tabIndex, title); - - // Update the window title if this is the current tab. - if (tabIndex == tabWidgetPointer->currentIndex()) - emit updateWindowTitle(title); - }); - - // Update the icon when it changes. - connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::iconChanged, [privacyWebEngineViewPointer, this] (const QIcon &icon) - { - // Get the index for this tab. - int tabIndex = tabWidgetPointer->indexOf(privacyWebEngineViewPointer); - - // Update the icon for this tab. - if (icon.isNull()) - tabWidgetPointer->setTabIcon(tabIndex, defaultTabIcon); - else - tabWidgetPointer->setTabIcon(tabIndex, icon); - }); - // Enable spell checking. webEngineProfilePointer->setSpellCheckEnabled(true); @@ -354,9 +434,12 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const // Populate the zoom factor. This is necessary if a URL is being loaded, like a local URL, that does not trigger `applyDomainSettings()`. privacyWebEngineViewPointer->setZoomFactor(Settings::zoomFactor()); + // Update the UI when domain settings are applied. + connect(privacyWebEngineViewPointer, SIGNAL(updateUi(const PrivacyWebEngineView*)), this, SLOT(updateUiFromWebEngineView(const PrivacyWebEngineView*))); + // Move to the new tab if it is not a background tab. if (!backgroundTab) - tabWidgetPointer->setCurrentIndex(newTabIndex); + qTabWidgetPointer->setCurrentIndex(newTabIndex); // Clear the URL line edit focus so that it populates correctly when opening a new tab from the context menu. if (removeUrlLineEditFocus) @@ -370,9 +453,9 @@ void TabWidget::applyApplicationSettings() { // Set the tab position. if (Settings::tabsOnTop()) - tabWidgetPointer->setTabPosition(QTabWidget::North); + qTabWidgetPointer->setTabPosition(QTabWidget::North); else - tabWidgetPointer->setTabPosition(QTabWidget::South); + qTabWidgetPointer->setTabPosition(QTabWidget::South); // Set the search engine URL. searchEngineUrl = SearchEngineHelper::getSearchUrl(Settings::searchEngine()); @@ -381,174 +464,10 @@ void TabWidget::applyApplicationSettings() emit updateSearchEngineActions(Settings::searchEngine(), true); } -// This exists as a separate function from `applyDomainSettings()` so it can be listed as a slot and function without the need for a boolean argument. -// Once has been resolved this can be `const`. void TabWidget::applyDomainSettingsAndReload() { // Apply the domain settings. `true` reloads the website. - applyDomainSettings(currentPrivacyWebEngineViewPointer->url().host(), true); -} - -// This exists as a separate function from `applyDomainSettings()` so it can be listed as a slot and function without the need for a boolean argument. -// Once has been resolved this can be `const`. -void TabWidget::applyDomainSettingsWithoutReloading(const QString &hostname) -{ - // Apply the domain settings `false` does not reload the website. - applyDomainSettings(hostname, false); -} - -// Once has been resolved this can be `const`. -void TabWidget::applyDomainSettings(const QString &hostname, const bool reloadWebsite) -{ - // Get the record for the hostname. - QSqlQuery domainQuery = DomainsDatabase::getDomainQuery(hostname); - - // 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. - currentPrivacyWebEngineViewPointer->domainSettingsName = domainRecord.field(DomainsDatabase::DOMAIN_NAME).value().toString(); - - // Set the JavaScript status. - switch (domainRecord.field(DomainsDatabase::JAVASCRIPT).value().toInt()) - { - // Set the default JavaScript status. - case (DomainsDatabase::SYSTEM_DEFAULT): - { - currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScriptEnabled()); - - break; - } - - // Disable JavaScript. - case (DomainsDatabase::DISABLED): - { - currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, false); - - break; - } - - // Enable JavaScript. - case (DomainsDatabase::ENABLED): - { - currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, true); - - break; - } - } - - // Set the local storage status. - switch (domainRecord.field(DomainsDatabase::LOCAL_STORAGE).value().toInt()) - { - // Set the default local storage status. - case (DomainsDatabase::SYSTEM_DEFAULT): - { - currentPrivacyWebEngineViewPointer->localStorageEnabled = Settings::localStorageEnabled(); - - break; - } - - // Disable local storage. - case (DomainsDatabase::DISABLED): - { - currentPrivacyWebEngineViewPointer->localStorageEnabled = false; - - break; - } - - // Enable local storage. - case (DomainsDatabase::ENABLED): - { - currentPrivacyWebEngineViewPointer->localStorageEnabled = true; - - break; - } - } - - // Set the DOM storage status. - switch (domainRecord.field(DomainsDatabase::DOM_STORAGE).value().toInt()) - { - // Set the default DOM storage status. QWebEngineSettings confusingly calls this local storage. - case (DomainsDatabase::SYSTEM_DEFAULT): - { - currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::domStorageEnabled()); - - break; - } - - // Disable DOM storage. QWebEngineSettings confusingly calls this local storage. - case (DomainsDatabase::DISABLED): - { - currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, false); - - break; - } - - // Enable DOM storage. QWebEngineSettings confusingly calls this local storage. - case (DomainsDatabase::ENABLED): - { - currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, true); - - break; - } - } - - // Set the user agent. - currentWebEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getResultingDomainSettingsUserAgent(domainRecord.field(DomainsDatabase::USER_AGENT).value().toString())); - - // Check if a custom zoom factor is set. - if (domainRecord.field(DomainsDatabase::ZOOM_FACTOR).value().toInt()) - { - // Store the current zoom factor. - currentZoomFactor = domainRecord.field(DomainsDatabase::CUSTOM_ZOOM_FACTOR).value().toDouble(); - } - else - { - // Reset the current zoom factor. - currentZoomFactor = Settings::zoomFactor(); - } - - // Set the zoom factor. The use of `currentZoomFactor` can be removed once has been resolved. - currentPrivacyWebEngineViewPointer->setZoomFactor(currentZoomFactor); - } - else // The hostname does not have domain settings. - { - // Reset the domain settings name. - currentPrivacyWebEngineViewPointer->domainSettingsName = QLatin1String(""); - - // Set the JavaScript status. - currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScriptEnabled()); - - // Set the local storage status. - currentPrivacyWebEngineViewPointer->localStorageEnabled = Settings::localStorageEnabled(); - - // Set DOM storage. In QWebEngineSettings it is called Local Storage. - currentWebEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::domStorageEnabled()); - - // Set the user agent. - currentWebEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent())); - - // Store the current zoom factor. This can be removed once has been resolved. - currentZoomFactor = Settings::zoomFactor(); - - // Set the zoom factor. - currentPrivacyWebEngineViewPointer->setZoomFactor(Settings::zoomFactor()); - } - - // Update the UI. - 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()); - - // Reload the website if requested. - if (reloadWebsite) - currentPrivacyWebEngineViewPointer->reload(); + currentPrivacyWebEngineViewPointer->applyDomainSettings(currentPrivacyWebEngineViewPointer->url().host(), true); } void TabWidget::applyOnTheFlySearchEngine(QAction *searchEngineActionPointer) @@ -584,12 +503,8 @@ void TabWidget::applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const currentPrivacyWebEngineViewPointer->reload(); } -// This can be const once has been resolved. -void TabWidget::applyOnTheFlyZoomFactor(const double &zoomFactor) +void TabWidget::applyOnTheFlyZoomFactor(const double &zoomFactor) const { - // Update the current zoom factor. This can be removed once has been resolved. - currentZoomFactor = zoomFactor; - // Set the zoom factor. currentPrivacyWebEngineViewPointer->setZoomFactor(zoomFactor); } @@ -597,13 +512,13 @@ void TabWidget::applyOnTheFlyZoomFactor(const double &zoomFactor) void TabWidget::applySpellCheckLanguages() const { // Get the number of tab. - int numberOfTabs = tabWidgetPointer->count(); + int numberOfTabs = qTabWidgetPointer->count(); // Set the spell check languages for each tab. for (int i = 0; i < numberOfTabs; ++i) { // Get the WebEngine view pointer. - PrivacyWebEngineView *webEngineViewPointer = qobject_cast(tabWidgetPointer->currentWidget()); + PrivacyWebEngineView *webEngineViewPointer = qobject_cast(qTabWidgetPointer->currentWidget()); // Get the WebEngine page pointer. QWebEnginePage *webEnginePagePointer = webEngineViewPointer->page(); @@ -637,13 +552,13 @@ void TabWidget::deleteCookieFromStore(const QNetworkCookie &cookie) const void TabWidget::deleteTab(const int tabIndex) { // Get the privacy WebEngine view. - PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast(tabWidgetPointer->widget(tabIndex)); + PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast(qTabWidgetPointer->widget(tabIndex)); - // Proccess the tab delete according to the number of tabs. - if (tabWidgetPointer->count() > 1) // There is more than one tab. + // Process the tab delete according to the number of tabs. + if (qTabWidgetPointer->count() > 1) // There is more than one tab. { // Delete the tab. - tabWidgetPointer->removeTab(tabIndex); + qTabWidgetPointer->removeTab(tabIndex); // Delete the WebEngine page to prevent the following error: `Release of profile requested but WebEnginePage still not deleted. Expect troubles !` delete privacyWebEngineViewPointer->page(); @@ -688,7 +603,7 @@ void TabWidget::findText(const QString &text) const void TabWidget::findTextFinished(const QWebEngineFindTextResult &findTextResult) { - // Update the find text UI if it wasn't simply wiping the current find text selection. Otherwise the UI temporarially flashes `0/0`. + // Update the find text UI if it wasn't simply wiping the current find text selection. Otherwise the UI temporarily flashes `0/0`. if (wipingCurrentFindTextSelection) // The current selection is being wiped. { // Reset the flag. @@ -889,7 +804,7 @@ void TabWidget::refresh() const void TabWidget::setTabBarVisible(const bool visible) const { // Set the tab bar visibility. - tabWidgetPointer->tabBar()->setVisible(visible); + qTabWidgetPointer->tabBar()->setVisible(visible); } void TabWidget::showSaveDialog(QWebEngineDownloadItem *webEngineDownloadItemPointer) @@ -900,8 +815,8 @@ void TabWidget::showSaveDialog(QWebEngineDownloadItem *webEngineDownloadItemPoin QString suggestedFileName = webEngineDownloadItemPointer->suggestedFileName(); int totalBytes = webEngineDownloadItemPointer->totalBytes(); - // Check to see if local storage (cookies) is enabled. - if (currentPrivacyWebEngineViewPointer->localStorageEnabled) // Local storage (cookies) is enabled. Use WebEngine's downloader. + // Check to see if Privacy Browser is not running KDE or if local storage (cookies) is enabled. + 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); @@ -919,7 +834,7 @@ void TabWidget::showSaveDialog(QWebEngineDownloadItem *webEngineDownloadItemPoin if (downloadDirectory == QLatin1String("System Download Directory")) downloadDirectory = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); - // Display a save file dialog. + // Get a file path from the file picker. QString saveFilePath = QFileDialog::getSaveFileName(this, i18nc("Save file dialog caption", "Save File"), downloadDirectory + QLatin1Char('/') + suggestedFileName); // Process the save file path. @@ -985,15 +900,21 @@ void TabWidget::showSaveDialog(QWebEngineDownloadItem *webEngineDownloadItemPoin // Update the notification when the download progresses. connect(webEngineDownloadItemPointer, &QWebEngineDownloadItem::downloadProgress, [fileDownloadNotificationPointer, saveFileName] (qint64 bytesReceived, qint64 totalBytes) { - // Calculate the download percentage. - int downloadPercentage = 100 * bytesReceived / totalBytes; - // Set the new text. Total bytes will be 0 if the download size is unknown. if (totalBytes > 0) + { + // Calculate the download percentage. + int downloadPercentage = 100 * bytesReceived / totalBytes; + + // Set the file download notification text. fileDownloadNotificationPointer->setText(i18nc("Download progress notification text", "%1\% of %2 downloaded (%3 of %4 bytes)", downloadPercentage, saveFileName, bytesReceived, totalBytes)); + } else + { + // Set the file download notification text. fileDownloadNotificationPointer->setText(i18nc("Download progress notification text", "%1: %2 bytes downloaded", saveFileName, bytesReceived)); + } // Display the updated notification. fileDownloadNotificationPointer->update(); @@ -1033,14 +954,14 @@ void TabWidget::showSaveDialog(QWebEngineDownloadItem *webEngineDownloadItemPoin webEngineDownloadItemPointer->cancel(); } } - else // Local storage (cookies) is disabled. Use KDE's native downloader. + else // KDE is running and local storage (cookies) is disabled. Use KDE's native downloader. // 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); // Connect the save button. - connect(saveDialogPointer, SIGNAL(useNativeDownloader(QUrl &, QString &)), this, SLOT(useNativeDownloader(QUrl &, QString &))); + connect(saveDialogPointer, SIGNAL(useNativeKdeDownloader(QUrl &, QString &)), this, SLOT(useNativeKdeDownloader(QUrl &, QString &))); // Show the dialog. saveDialogPointer->show(); @@ -1098,10 +1019,25 @@ void TabWidget::toggleLocalStorage() currentPrivacyWebEngineViewPointer->reload(); } +void TabWidget::updateUiFromWebEngineView(const PrivacyWebEngineView *privacyWebEngineViewPointer) const +{ + // Only update the UI if the signal was emitted from the current privacy WebEngine. + if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer) + { + // Update the UI. + 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()); + } +} + void TabWidget::updateUiWithTabSettings() { // Update the current WebEngine pointers. - currentPrivacyWebEngineViewPointer = qobject_cast(tabWidgetPointer->currentWidget()); + currentPrivacyWebEngineViewPointer = qobject_cast(qTabWidgetPointer->currentWidget()); currentWebEngineSettingsPointer = currentPrivacyWebEngineViewPointer->settings(); currentWebEnginePagePointer = currentPrivacyWebEngineViewPointer->page(); currentWebEngineProfilePointer = currentWebEnginePagePointer->profile(); @@ -1137,7 +1073,7 @@ void TabWidget::updateUiWithTabSettings() emit hideProgressBar(); } -void TabWidget::useNativeDownloader(QUrl &downloadUrl, QString &suggestedFileName) +void TabWidget::useNativeKdeDownloader(QUrl &downloadUrl, QString &suggestedFileName) { // Get the download directory. QString downloadDirectory = Settings::downloadLocation();