#include "Settings.h"
#include "ui_BrowserView.h"
#include "UrlRequestInterceptor.h"
+#include "dialogs/DomainSettingsDialog.h"
+#include "helpers/DomainsDatabaseHelper.h"
#include "helpers/SearchEngineHelper.h"
#include "helpers/UserAgentHelper.h"
#include "windows/BrowserWindow.h"
-#include "windows/DomainSettingsWindow.h"
// Qt framework headers.
#include <QAction>
connect(javaScriptButtonPointer, SIGNAL(clicked()), this, SLOT(toggleJavaScript()));
connect(domainSettingsButtonPointer, SIGNAL(clicked()), this, SLOT(openDomainSettings()));
+ // Get the URL line edit palettes.
+ noDomainSettingsPalette = urlLineEditPointer->palette();
+ domainSettingsPalette = urlLineEditPointer->palette();
+
+ // Modify the domain settings palette.
+ domainSettingsPalette.setColor(QPalette::Base, QColor("#C8E6C9"));
+
// Instantiate the mouse event pointer.
MouseEventFilter *mouseEventFilterPointer = new MouseEventFilter(webEngineViewPointer);
webEngineProfilePointer->setUrlRequestInterceptor(urlRequestInterceptorPointer);
// Reapply the domain settings when the host changes.
- connect(urlRequestInterceptorPointer, SIGNAL(applyDomainSettings()), this, SLOT(applyDomainSettingsWithoutReloading()));
+ connect(urlRequestInterceptorPointer, SIGNAL(applyDomainSettings(QString)), this, SLOT(applyDomainSettingsWithoutReloading(QString)));
// Disable the cache.
webEngineProfilePointer->setHttpCacheType(QWebEngineProfile::NoCache);
void BrowserView::applyDomainSettingsAndReload() const
{
// Apply the domain settings. `true` reloads the website.
- applyDomainSettings(true);
+ applyDomainSettings(webEngineViewPointer->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.
-void BrowserView::applyDomainSettingsWithoutReloading() const
+void BrowserView::applyDomainSettingsWithoutReloading(const QString &hostname) const
{
// Apply the domain settings `false` does not reload the website.
- applyDomainSettings(false);
+ applyDomainSettings(hostname, false);
}
-void BrowserView::applyDomainSettings(bool reloadWebsite) const
+void BrowserView::applyDomainSettings(const QString &hostname, const bool reloadWebsite) const
{
- // Set the JavaScript status.
- webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScript());
+ // Get the record for the hostname.
+ QSqlQuery domainQuery = DomainsDatabaseHelper::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();
+
+ // Set the JavaScript status.
+ switch (domainRecord.field(DomainsDatabaseHelper::JAVASCRIPT).value().toInt())
+ {
+ case (DomainsDatabaseHelper::SYSTEM_DEFAULT):
+ {
+ // Set the default JavaScript status.
+ webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScript());
+
+ break;
+ }
+
+ case (DomainsDatabaseHelper::DISABLED):
+ {
+ // Disable JavaScript.
+ webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
+
+ break;
+ }
+
+ case (DomainsDatabaseHelper::ENABLED):
+ {
+ // Enable JavaScript.
+ webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
+
+ break;
+ }
+ }
+
+ // Apply the user agent.
+ webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgent(Settings::userAgent()));
+
+ // Set the zoom factor.
+ webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
+
+ // Apply the domain settings palette to the URL line edit.
+ urlLineEditPointer->setPalette(domainSettingsPalette);
+ }
+ else // The hostname does not have domain settings.
+ {
+ // Set the JavaScript status.
+ webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScript());
+
+ // Apply the user agent.
+ webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgent(Settings::userAgent()));
+
+ // Set the zoom factor.
+ webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
+
+ // Apply the no domain settings palette to the URL line edit.
+ urlLineEditPointer->setPalette(noDomainSettingsPalette);
+ }
// Update the JavaScript button.
- if (Settings::javaScript())
+ if (webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled))
{
javaScriptButtonPointer->setIcon(QIcon(":/icons/javascript-warning"));
}
javaScriptButtonPointer->setIcon(QIcon(":/icons/privacy-mode"));
}
- // Apply the user agent.
- webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgent(Settings::userAgent()));
-
- // Set the zoom factor.
- webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
-
// Emit the on-the-fly menu update signals.
emit userAgentUpdated(Settings::userAgent());
emit zoomFactorUpdated(Settings::zoomFactor());
void BrowserView::openDomainSettings() const
{
- // Get a list of the top level widgets.
- const QWidgetList topLevelWidgets = QApplication::topLevelWidgets();
+ // Instantiate the domain settings window.
+ DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
- // Initialize a domain settings window exists boolean.
- bool domainSettingsWindowExists = false;
+ // Set the dialog window title.
+ domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
- // Iterate through the top level widgets.
- for (QWidget *widgetPointer : topLevelWidgets)
- {
- // Check for an existing domain settings window.
- if (widgetPointer->objectName() == QStringLiteral("domain_settings"))
- {
- // Show the existing domain settings window if it is hidden.
- widgetPointer->show();
-
- // Raise the existing domain settings window if it is below other windows.
- widgetPointer->raise();
-
- // Restore the existing domain settings window if it has been minimized.
- if (widgetPointer->isMinimized()) {
- widgetPointer->showNormal();
- }
-
- // Activate the existing domain settings window, which brings its virtual desktop into focus.
- widgetPointer->activateWindow();
+ // Resize the dialog window.
+ domainSettingsDialogPointer->resize(1500, 1000);
- // Update the domain settings window exists boolean.
- domainSettingsWindowExists = true;
- }
- }
+ // Set the modality.
+ domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
- if (!domainSettingsWindowExists)
- {
- // Instantiate the domain settings window.
- DomainSettingsWindow *domainSettingsWindowPointer = new DomainSettingsWindow();
-
- // Show the window.
- domainSettingsWindowPointer->show();
- }
+ // Show the dialog.
+ domainSettingsDialogPointer->show();
}
void BrowserView::pageLinkHovered(const QString &linkUrl) const