From 8374070dbecda79d3970a4641d54052b30eb33a0 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Sat, 2 Nov 2024 20:29:52 -0700 Subject: [PATCH] Update the domains database in all windows when it changes. https://redmine.stoutner.com/issues/1235 --- src/interceptors/UrlRequestInterceptor.cpp | 2 +- src/widgets/PrivacyWebEngineView.cpp | 2 +- src/widgets/TabWidget.cpp | 2 +- src/windows/BrowserWindow.cpp | 79 +++++++++++++++------- src/windows/BrowserWindow.h | 6 +- 5 files changed, 63 insertions(+), 28 deletions(-) diff --git a/src/interceptors/UrlRequestInterceptor.cpp b/src/interceptors/UrlRequestInterceptor.cpp index 0a8c04f..251ef76 100644 --- a/src/interceptors/UrlRequestInterceptor.cpp +++ b/src/interceptors/UrlRequestInterceptor.cpp @@ -14,7 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Privacy Browser PC. If not, see . + * along with Privacy Browser PC. If not, see . */ // Application headers. diff --git a/src/widgets/PrivacyWebEngineView.cpp b/src/widgets/PrivacyWebEngineView.cpp index ac543fa..fd6f897 100644 --- a/src/widgets/PrivacyWebEngineView.cpp +++ b/src/widgets/PrivacyWebEngineView.cpp @@ -14,7 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Privacy Browser PC. If not, see . + * along with Privacy Browser PC. If not, see . */ // Application headers. diff --git a/src/widgets/TabWidget.cpp b/src/widgets/TabWidget.cpp index 173296b..7caccb1 100644 --- a/src/widgets/TabWidget.cpp +++ b/src/widgets/TabWidget.cpp @@ -543,7 +543,7 @@ void TabWidget::applyDomainSettingsAndReload() // Get the WebEngine view pointer. PrivacyWebEngineView *privacyWebEngineViewPointer = qTabWidgetPointer->widget(i)->findChild(); - // Apply the spatial navigation settings to each page. + // Apply the domain settings settings to each page. privacyWebEngineViewPointer->applyDomainSettings(privacyWebEngineViewPointer->url().host(), true); } } diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index bde4ccb..66196ca 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -861,7 +861,7 @@ void BrowserWindow::addOrEditDomainSettings() urlLineEditPointer->clearFocus(); // Get the current domain settings name. - QString ¤tDomainSettingsName = tabWidgetPointer->getDomainSettingsName(); + QString currentDomainSettingsName = tabWidgetPointer->getDomainSettingsName(); // Run the commands according to the current domain settings status. if (currentDomainSettingsName == QStringLiteral("")) // Domain settings are not currently applied. @@ -896,24 +896,39 @@ void BrowserWindow::addOrEditDomainSettings() if (abs(currentZoomFactorDouble - defaultZoomFactorDouble ) > 0.01) zoomFactorInt = DomainsDatabase::CUSTOM; + // Update the current domain settings name. + currentDomainSettingsName = currentUrl.host(); + // Add the domain. - DomainsDatabase::addDomain(currentUrl.host(), javaScriptInt, localStorageInt, domStorageInt, userAgentDatabaseString, ultraPrivacyInt, ultraListInt, easyPrivacyInt, easyListInt, + DomainsDatabase::addDomain(currentDomainSettingsName, javaScriptInt, localStorageInt, domStorageInt, userAgentDatabaseString, ultraPrivacyInt, ultraListInt, easyPrivacyInt, easyListInt, fanboysAnnoyanceListInt, zoomFactorInt, currentZoomFactorDouble); - // Apply the domain settings. - tabWidgetPointer->applyDomainSettingsAndReload(); + // Apply the domain settings in all windows. + applyDomainSettingsInAllWindows(); } // Create the domain settings dialog pointer. DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog(this, DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsName); - // Reload the tabs when domain settings are updated. - connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload())); + // Apply the domain settings in all windows when domain settings are updated. + connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), this, SLOT(applyDomainSettingsInAllWindows())); // Show the dialog. domainSettingsDialogPointer->show(); } +void BrowserWindow::applyDomainSettingsInAllWindows() const +{ + // Apply the domain settings in all windows. + runMethodInAllWindows(QLatin1String("applyDomainSettingsInThisWindow")); +} + +void BrowserWindow::applyDomainSettingsInThisWindow() +{ + // Apply domain settings and reload the tabs. + tabWidgetPointer->applyDomainSettingsAndReload(); +} + void BrowserWindow::back() const { // Remove the focus from the URL line edit. @@ -1175,21 +1190,8 @@ void BrowserWindow::openWithFirefox() const void BrowserWindow::populateBookmarksInAllWindows() const { - // Get a list of all the registered service names. - QStringList registeredServiceNames = QDBusConnection::sessionBus().interface()->registeredServiceNames().value(); - - // Get a list of all the Privacy Browser windows, which will be `com.stoutner.privacybrowser-` with the PID appended. - QStringList privacyBrowserServiceNames = registeredServiceNames.filter("com.stoutner.privacybrowser"); - - // Repopulate the bookmarks in each window. - for (QString privacyBrowserServiceName : privacyBrowserServiceNames) - { - // Prepare the D-Bus message. - QDBusMessage dBusMessage = QDBusMessage::createMethodCall(privacyBrowserServiceName, "/privacybrowser/MainWindow_1", "com.stoutner.privacybrowser.BrowserWindow", "populateBookmarksInThisWindow"); - - // Make it so. - QDBusConnection::sessionBus().send(dBusMessage); - } + // Populate the bookmarks in all windows. + runMethodInAllWindows(QLatin1String("populateBookmarksInThisWindow")); } void BrowserWindow::populateBookmarksInThisWindow() @@ -1449,6 +1451,25 @@ void BrowserWindow::restoreUrlText() const urlLineEditPointer->setText(tabWidgetPointer->getCurrentTabUrl()); } +void BrowserWindow::runMethodInAllWindows(const QString &methodString) const +{ + // Get a list of all the registered service names. + QStringList registeredServiceNames = QDBusConnection::sessionBus().interface()->registeredServiceNames().value(); + + // Get a list of all the Privacy Browser windows, which will be `com.stoutner.privacybrowser-` with the PID appended. + QStringList privacyBrowserServiceNames = registeredServiceNames.filter("com.stoutner.privacybrowser"); + + // Reapply domain settings in each window. + for (QString privacyBrowserServiceName : privacyBrowserServiceNames) + { + // Prepare the D-Bus message. + QDBusMessage dBusMessage = QDBusMessage::createMethodCall(privacyBrowserServiceName, "/privacybrowser/MainWindow_1", "com.stoutner.privacybrowser.BrowserWindow", methodString); + + // Make it so. + QDBusConnection::sessionBus().send(dBusMessage); + } +} + void BrowserWindow::showBookmarkContextMenu(const QPoint &point) { // Get the bookmark action. @@ -1610,7 +1631,7 @@ void BrowserWindow::showDomainSettingsDialog() DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog(this); // Reload the tabs when domain settings are updated. - connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload())); + connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), this, SLOT(applyDomainSettingsInAllWindows())); // Show the dialog. domainSettingsDialogPointer->show(); @@ -1691,6 +1712,7 @@ void BrowserWindow::showSettingsDialog() // Apply the settings handled by KConfig. connect(settingsDialogPointer, SIGNAL(spellCheckLanguagesUpdated()), tabWidgetPointer, SLOT(applySpellCheckLanguages())); connect(settingsDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyApplicationSettings())); + //connect(settingsDialogPointer, SIGNAL(settingsChanged(QString)), this, SLOT(applyDomainSettingsInAllWindows())); connect(settingsDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyDomainSettingsAndReload())); } @@ -1856,9 +1878,15 @@ void BrowserWindow::updateRequestsAction(const QVector blockedRequestsVecto // Update the blocked requests action background color. if (blockedRequestsVector[PrivacyWebEngineView::TOTAL] > 0) - urlToolBarPointer->setStyleSheet(QLatin1String("QToolButton#blocked_requests { background-color: tomato; }")); + urlToolBarPointer->setStyleSheet(QLatin1String("QToolButton#blocked_requests { background-color: tomato; border-radius: 5px; padding: 4px; }")); else urlToolBarPointer->setStyleSheet(QLatin1String("QToolButton#blocked_requests { background-color: transparent; }")); + + // Restore the domain settings indicator. + if (domainSettingsApplied) + urlLineEditPointer->setPalette(positiveBackgroundPalette); + else + urlLineEditPointer->setPalette(normalBackgroundPalette); } void BrowserWindow::updateCookiesAction(const int numberOfCookies) const @@ -1881,8 +1909,11 @@ void BrowserWindow::updateDomStorageAction(const bool &isEnabled) const void BrowserWindow::updateDomainSettingsIndicator(const bool status) { + // Store the domain settings applied status. + domainSettingsApplied = status; + // Set the domain palette according to the status. - if (status) + if (domainSettingsApplied) urlLineEditPointer->setPalette(positiveBackgroundPalette); else urlLineEditPointer->setPalette(normalBackgroundPalette); diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index a41226c..eb708f9 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -14,7 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Privacy Browser PC. If not, see . + * along with Privacy Browser PC. If not, see . */ #ifndef BROWSER_WINDOW_H @@ -52,11 +52,13 @@ public: public Q_SLOTS: // The public slots. + void applyDomainSettingsInThisWindow(); // This is public so that the domain settings can be reapplied over D-Bus when changed by another instance of Privacy Browser. void populateBookmarksInThisWindow(); // This is public so that the bookmarks can be repopulated over D-Bus when changed by another instance of Privacy Browser. private Q_SLOTS: // The private slots. void addOrEditDomainSettings(); + void applyDomainSettingsInAllWindows() const; void back() const; void clearUrlLineEditFocus() const; void decrementZoom(); @@ -80,6 +82,7 @@ private Q_SLOTS: void refresh() const; void reloadAndBypassCache() const; void restoreUrlText() const; + void runMethodInAllWindows(const QString &methodString) const; void showBookmarkContextMenu(const QPoint &point); void showCookiesDialog(); void showDomainSettingsDialog(); @@ -139,6 +142,7 @@ private: double defaultZoomFactorDouble; QAction *developerToolsActionPointer; QAction *domStorageActionPointer; + bool domainSettingsApplied = false; QAction *easyPrivacyActionPointer; QAction *easyListActionPointer; QAction *fanboysAnnoyanceListPointer; -- 2.45.2