3ddba02c9e3809475a6d7393354b5cbc5eae33fb
[PrivacyBrowserPC.git] / src / windows / BrowserWindow.cpp
1 /*
2  * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
5  *
6  * Privacy Browser PC is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Privacy Browser PC is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Privacy Browser PC.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 // Application headers.
21 #include "BrowserWindow.h"
22 #include "Settings.h"
23 #include "ui_SettingsPrivacy.h"
24 #include "ui_SettingsGeneral.h"
25 #include "dialogs/DomainSettingsDialog.h"
26 #include "helpers/SearchEngineHelper.h"
27 #include "helpers/UserAgentHelper.h"
28
29 // KDE Frameworks headers.
30 #include <KActionCollection>
31 #include <KToolBar>
32
33 // Qt toolkit headers.
34 #include <QInputDialog>
35 #include <QStatusBar>
36
37 BrowserWindow::BrowserWindow() : KXmlGuiWindow()
38 {
39     // Instantiate the main view pointer.
40     browserViewPointer = new BrowserView(this);
41
42     // Set the main view as the central widget.
43     setCentralWidget(browserViewPointer);
44
45     // Get a handle for the action collection.
46     KActionCollection *actionCollectionPointer = this->actionCollection();
47
48     // Add the standard actions.
49     QAction *backActionPointer = KStandardAction::back(this, SLOT(back()), actionCollectionPointer);
50     QAction *forwardActionPointer = KStandardAction::forward(this, SLOT(forward()), actionCollectionPointer);
51     KStandardAction::home(this, SLOT(home()), actionCollectionPointer);
52     KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer);
53     KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer);
54     KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollectionPointer);
55     KStandardAction::redisplay(this, SLOT(refresh()), actionCollectionPointer);
56
57     // Add the custom actions.
58     userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_privacy_browser"));
59     userAgentWebEngineDefaultActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_webengine_default"));
60     userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_linux"));
61     userAgentChromiumLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chromium_linux"));
62     userAgentFirefoxWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_windows"));
63     userAgentChromeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chrome_windows"));
64     userAgentEdgeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_edge_windows"));
65     userAgentSafariMacosActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_safari_macos"));
66     userAgentCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_custom"));
67     zoomFactorActionPointer = actionCollectionPointer->addAction(QStringLiteral("zoom_factor"));
68     searchEngineMojeekActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_mojeek"));
69     searchEngineMonoclesActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_monocles"));
70     searchEngineMetagerActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_metager"));
71     searchEngineGoogleActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_google"));
72     searchEngineBingActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_bing"));
73     searchEngineYahooActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_yahoo"));
74     searchEngineCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_custom"));
75     javaScriptActionPointer = actionCollectionPointer->addAction(QStringLiteral("javascript"));
76     localStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("local_storage"));
77     domainSettingsActionPointer = actionCollectionPointer->addAction(QStringLiteral("domain_settings"));
78
79     // Create the action groups
80     QActionGroup *userAgentActionGroupPointer = new QActionGroup(this);
81     QActionGroup *searchEngineActionGroupPointer = new QActionGroup(this);
82
83     // Add the actions to the groups.
84     userAgentActionGroupPointer->addAction(userAgentPrivacyBrowserActionPointer);
85     userAgentActionGroupPointer->addAction(userAgentWebEngineDefaultActionPointer);
86     userAgentActionGroupPointer->addAction(userAgentFirefoxLinuxActionPointer);
87     userAgentActionGroupPointer->addAction(userAgentChromiumLinuxActionPointer);
88     userAgentActionGroupPointer->addAction(userAgentFirefoxWindowsActionPointer);
89     userAgentActionGroupPointer->addAction(userAgentChromeWindowsActionPointer);
90     userAgentActionGroupPointer->addAction(userAgentEdgeWindowsActionPointer);
91     userAgentActionGroupPointer->addAction(userAgentSafariMacosActionPointer);
92     userAgentActionGroupPointer->addAction(userAgentCustomActionPointer);
93     searchEngineActionGroupPointer->addAction(searchEngineMojeekActionPointer);
94     searchEngineActionGroupPointer->addAction(searchEngineMonoclesActionPointer);
95     searchEngineActionGroupPointer->addAction(searchEngineMetagerActionPointer);
96     searchEngineActionGroupPointer->addAction(searchEngineGoogleActionPointer);
97     searchEngineActionGroupPointer->addAction(searchEngineBingActionPointer);
98     searchEngineActionGroupPointer->addAction(searchEngineYahooActionPointer);
99     searchEngineActionGroupPointer->addAction(searchEngineCustomActionPointer);
100
101     // Set some actions to be checkable.
102     userAgentPrivacyBrowserActionPointer->setCheckable(true);
103     userAgentWebEngineDefaultActionPointer->setCheckable(true);
104     userAgentFirefoxLinuxActionPointer->setCheckable(true);
105     userAgentChromiumLinuxActionPointer->setCheckable(true);
106     userAgentFirefoxWindowsActionPointer->setCheckable(true);
107     userAgentChromeWindowsActionPointer->setCheckable(true);
108     userAgentEdgeWindowsActionPointer->setCheckable(true);
109     userAgentSafariMacosActionPointer->setCheckable(true);
110     userAgentCustomActionPointer->setCheckable(true);
111     searchEngineMojeekActionPointer->setCheckable(true);
112     searchEngineMonoclesActionPointer->setCheckable(true);
113     searchEngineMetagerActionPointer->setCheckable(true);
114     searchEngineGoogleActionPointer->setCheckable(true);
115     searchEngineBingActionPointer->setCheckable(true);
116     searchEngineYahooActionPointer->setCheckable(true);
117     searchEngineCustomActionPointer->setCheckable(true);
118
119     // Set the non-mutable action text.
120     userAgentPrivacyBrowserActionPointer->setText(UserAgentHelper::PRIVACY_BROWSER_TRANSLATED);
121     userAgentWebEngineDefaultActionPointer->setText(UserAgentHelper::WEB_ENGINE_DEFAULT_TRANSLATED);
122     userAgentFirefoxLinuxActionPointer->setText(UserAgentHelper::FIREFOX_LINUX_TRANSLATED);
123     userAgentChromiumLinuxActionPointer->setText(UserAgentHelper::CHROMIUM_LINUX_TRANSLATED);
124     userAgentFirefoxWindowsActionPointer->setText(UserAgentHelper::FIREFOX_WINDOWS_TRANSLATED);
125     userAgentChromeWindowsActionPointer->setText(UserAgentHelper::CHROME_WINDOWS_TRANSLATED);
126     userAgentEdgeWindowsActionPointer->setText(UserAgentHelper::EDGE_WINDOWS_TRANSLATED);
127     userAgentSafariMacosActionPointer->setText(UserAgentHelper::SAFARI_MACOS_TRANSLATED);
128     searchEngineMojeekActionPointer->setText(i18nc("Search engine", "Mojeek"));
129     searchEngineMonoclesActionPointer->setText(i18nc("Search engine", "Monocles"));
130     searchEngineMetagerActionPointer->setText(i18nc("Search engine", "MetaGer"));
131     searchEngineGoogleActionPointer->setText(i18nc("Search engine", "Google"));
132     searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing"));
133     searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo"));
134     javaScriptActionPointer->setText(i18nc("JavaScript button", "JavaScript"));
135     localStorageActionPointer->setText(i18nc("Local Storage Button", "Local Storage"));
136     domainSettingsActionPointer->setText(i18nc("Domain Settings button", "Domain Settings"));
137
138     // Set the action icons.
139     userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
140     userAgentWebEngineDefaultActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
141     userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
142     userAgentChromiumLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
143     userAgentFirefoxWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
144     userAgentChromeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
145     userAgentEdgeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
146     userAgentSafariMacosActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
147     userAgentCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
148     searchEngineMojeekActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
149     searchEngineMonoclesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
150     searchEngineMetagerActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
151     searchEngineGoogleActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-google")));
152     searchEngineBingActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
153     searchEngineYahooActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-yahoo")));
154     searchEngineCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
155     zoomFactorActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("zoom")));
156     domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("settings-configure")));
157
158     // Update the on-the-fly menus.
159     connect(browserViewPointer, SIGNAL(updateUserAgentActions(QString)), this, SLOT(updateUserAgentActions(QString)));
160     connect(browserViewPointer, SIGNAL(updateZoomFactorAction(double)), this, SLOT(updateZoomFactorAction(double)));
161     connect(browserViewPointer, SIGNAL(updateSearchEngineActions(QString)), this, SLOT(updateSearchEngineActions(QString)));
162
163     // Apply the on-the-fly settings when selected.
164     connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
165     connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
166
167     // Display dialogs.
168     connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
169
170     // Connect the URL toolbar actions.
171     connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript()));
172     connect(localStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleLocalStorage()));
173     connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(openDomainSettings()));
174
175     // Update the URL toolbar actions.
176     connect(browserViewPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
177     connect(browserViewPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool)));
178     connect(browserViewPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool)));
179     connect(browserViewPointer, SIGNAL(updateLocalStorageAction(bool)), this, SLOT(updateLocalStorageAction(bool)));
180
181     // Setup the GUI based on the browser_ui.rc file.
182     setupGUI(StandardWindowOption::Default, ("browser_ui.rc"));
183
184     // Get a handle for the URL toolbar.
185     KToolBar *urlToolBarPointer = toolBar(QStringLiteral("url_toolbar"));
186
187     // Create a URL line edit.
188     urlLineEditPointer = new KLineEdit();
189
190     // Add an edit or add domain settings action to the URL line edit.
191     QAction *addOrEditDomainSettingsActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme("settings-configure"), QLineEdit::TrailingPosition);
192
193     // Add or edit the current domain settings.
194     connect(addOrEditDomainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(addOrEditDomainSettings()));
195
196     // Populate the URL toolbar.
197     urlToolBarPointer->insertWidget(javaScriptActionPointer, urlLineEditPointer);
198
199     // Load a new URL from the URL line edit.
200     connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
201
202     // Update the URL line edit on page loads.
203     connect(browserViewPointer, SIGNAL(updateUrlLineEdit(QUrl)), this, SLOT(updateUrlLineEdit(QUrl)));
204
205     // Get a handle for the status bar.
206     QStatusBar *statusBarPointer = statusBar();
207
208     // Create a progress bar.
209     progressBarPointer = new QProgressBar();
210
211     // Add the progress bar to to the status bar.
212     statusBarPointer->addPermanentWidget(progressBarPointer);
213
214     // Update the status bar with the URL when a link is hovered.
215     connect(browserViewPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
216
217     // Update the progress bar.
218     connect(browserViewPointer, SIGNAL(showProgressBar(const int)), this, SLOT(showProgressBar(const int)));
219     connect(browserViewPointer, SIGNAL(hideProgressBar()), progressBarPointer, SLOT(hide()));
220
221     // Clear the URL line edit focus when requested.
222     connect(browserViewPointer, SIGNAL(clearUrlLineEditFocus()), this, SLOT(clearUrlLineEditFocus()));
223
224     // Get the URL line edit palettes.
225     noDomainSettingsPalette = urlLineEditPointer->palette();
226     domainSettingsPalette = urlLineEditPointer->palette();
227
228     // Modify the domain settings palette.
229     domainSettingsPalette.setColor(QPalette::Base, QColor("#C8E6C9"));
230
231     // Update the applied palette.
232     connect(browserViewPointer, SIGNAL(updateDomainSettingsIndicator(bool, QString)), this, SLOT(updateDomainSettingsIndicator(bool, QString)));
233
234     // Load the initial website.
235     browserViewPointer->loadInitialWebsite();
236 }
237
238 void BrowserWindow::addOrEditDomainSettings() const
239 {
240     // Remove the focus from the URL line edit.
241     urlLineEditPointer->clearFocus();
242
243     // Create the domain settings dialog pointer.
244     DomainSettingsDialog *domainSettingsDialogPointer;
245
246     // Run the commands according to the current domain settings status.
247     if (currentDomainSettingsDomain == "")  // Domain settings are not currently applied.
248     {
249         // Instruct the domain settings dialog to add a new domain.
250         domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::ADD_DOMAIN, currentUrl.host());
251     }
252     else  // Domain settings are currently applied.
253     {
254         // Instruct the domain settings dialog to edit the current domain.
255         domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsDomain);
256     }
257
258     // Set the dialog window title.
259     domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
260
261     // Set the modality.
262     domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
263
264     // Show the dialog.
265     domainSettingsDialogPointer->show();
266
267     // Reload the tabs when domain settings are updated.
268     connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
269 }
270
271 void BrowserWindow::back() const
272 {
273     // Remove the focus from the URL line edit.
274     urlLineEditPointer->clearFocus();
275
276     // Go back.
277     browserViewPointer->back();
278 }
279
280 void BrowserWindow::clearUrlLineEditFocus() const
281 {
282     // Remove the focus from the URL line edit.
283     urlLineEditPointer->clearFocus();
284 }
285
286 void BrowserWindow::fileNew() const
287 {
288     // Display a new instance of Privacy Browser.
289     (new BrowserWindow)->show();
290 }
291
292 void BrowserWindow::forward() const
293 {
294     // Remove the focus from the URL line edit.
295     urlLineEditPointer->clearFocus();
296
297     // Go forward.
298     browserViewPointer->forward();
299 }
300
301 void BrowserWindow::getZoomFactorFromUser()
302 {
303     // Create an OK flag.
304     bool okClicked;
305
306     // Display a dialog to get the new zoom factor from the user.  Format the double to display two decimals and have a 0.25 step.
307     double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"),
308                                                    i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
309                                                    currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
310
311     // Update the zoom factor if the user clicked OK.
312     if (okClicked)
313     {
314         // Update the current zoom factor.
315         currentZoomFactor = newZoomFactor;
316
317         // Set the new zoom factor.
318         browserViewPointer->applyOnTheFlyZoomFactor(newZoomFactor);
319
320         // Update the on-the-fly action text.
321         updateZoomFactorAction(newZoomFactor);
322     }
323 }
324
325 void BrowserWindow::home() const
326 {
327     // Remove the focus from the URL line edit.
328     urlLineEditPointer->clearFocus();
329
330     // Go home.
331     browserViewPointer->home();
332 }
333
334 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
335 {
336     // Remove the focus from the URL line edit.
337     urlLineEditPointer->clearFocus();
338
339     // Load the URL.
340     browserViewPointer->loadUrlFromLineEdit(url);
341 }
342
343 void BrowserWindow::openDomainSettings() const
344 {
345     // Remove the focus from the URL line edit.
346     urlLineEditPointer->clearFocus();
347
348     // Instantiate the domain settings dialog.
349     DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
350
351     // Set the dialog window title.
352     domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
353
354     // Set the modality.
355     domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
356
357     // Show the dialog.
358     domainSettingsDialogPointer->show();
359
360     // Reload the tabs when domain settings are updated.
361     connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
362 }
363
364 void BrowserWindow::refresh() const
365 {
366     // Remove the focus from the URL line edit.
367     urlLineEditPointer->clearFocus();
368
369     // Refresh the web page.
370     browserViewPointer->refresh();
371 }
372
373 void BrowserWindow::showProgressBar(const int &progress) const
374 {
375     // Set the progress bar value.
376     progressBarPointer->setValue(progress);
377
378     // Show the progress bar.
379     progressBarPointer->show();
380 }
381
382 QSize BrowserWindow::sizeHint() const
383 {
384     // Return the default window size.
385     return QSize(1500, 1200);
386 }
387
388 void BrowserWindow::settingsConfigure()
389 {
390     // Check to make sure the dialog box isn't already displayed.
391     if (KConfigDialog::exists(QStringLiteral("settings")))
392     {
393         // Show the existing config dialog if it is hidden.
394         configDialogPointer->show();
395
396         // Raise the existing config dialog if it is below other windows.
397         configDialogPointer->raise();
398
399         // Restore the existing config dialog if it has been minimized.
400         if (configDialogPointer->isMinimized()) {
401             configDialogPointer->showNormal();
402         }
403
404         // Activate the existing config dialog, which brings its virtual desktop into focus.
405         configDialogPointer->activateWindow();
406     }
407     else
408     {
409         // Create the settings widgets.
410         QWidget *privacySettingsWidgetPointer = new QWidget;
411         QWidget *generalSettingsWidgetPointer = new QWidget;
412
413         // Instantiate the settings UI.
414         Ui::PrivacySettings privacySettingsUi;
415         Ui::GeneralSettings generalSettingsUi;
416
417         // Setup the UI to display the settings widgets.
418         privacySettingsUi.setupUi(privacySettingsWidgetPointer);
419         generalSettingsUi.setupUi(generalSettingsWidgetPointer);
420
421         // Get handles for the widgets.
422         QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
423         userAgentLabelPointer = privacySettingsUi.userAgentLabel;
424         QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
425         searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
426
427         // Populate the combo box labels.
428         updateUserAgentLabel(userAgentComboBoxPointer->currentText());
429         updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
430
431         // Update the labels when the combo boxes change.
432         connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
433         connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
434
435         // Instantiate a settings config dialog from the settings.kcfg file.
436         configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
437
438         // Add the settings widgets as config dialog pages.
439         configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("@title:tab", "Privacy"), QStringLiteral("privacy-browser"));
440         configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
441
442         // Delete the config dialog when it is closed.
443         configDialogPointer->setAttribute(Qt::WA_DeleteOnClose);
444
445         // Make it so.
446         configDialogPointer->show();
447
448         // TODO.  KConfigDialog does not respect expanding size policies.  <https://redmine.stoutner.com/issues/823>
449         //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
450         //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
451         //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
452         //configDialogPointer->adjustSize();
453
454         // Expand the config dialog.
455         configDialogPointer->resize(1000, 500);
456
457         // Apply the settings when they are updated.
458         connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyApplicationSettings()));
459         connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
460     }
461 }
462
463 void BrowserWindow::toggleJavaScript() const
464 {
465     // Remove the focus from the URL line edit.
466     urlLineEditPointer->clearFocus();
467
468     // Toggle JavaScript.
469     browserViewPointer->toggleJavaScript();
470 }
471
472 void BrowserWindow::toggleLocalStorage() const
473 {
474     // Remove the focus from the URL line edit.
475     urlLineEditPointer->clearFocus();
476
477     // Toggle JavaScript.
478     browserViewPointer->toggleLocalStorage();
479 }
480
481 void BrowserWindow::updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain)
482 {
483     // Set the domain palette according to the status.
484     if (status) urlLineEditPointer->setPalette(domainSettingsPalette);
485     else urlLineEditPointer->setPalette(noDomainSettingsPalette);
486
487     // Store the domain.
488     currentDomainSettingsDomain = domainSettingsDomain;
489 }
490
491 void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) const
492 {
493     // Set the icon according to the status.
494     if (isEnabled) javaScriptActionPointer->setIcon(QIcon(":/icons/javascript-warning"));
495     else javaScriptActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
496 }
497
498 void BrowserWindow::updateLocalStorageAction(const bool &isEnabled) const
499 {
500     // Set the icon according to the status.
501     if (isEnabled) localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota-low"));
502     else localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota"));
503 }
504
505 void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const
506 {
507     // Initialize the custom search engine flag.
508     bool customSearchEngine = false;
509
510     if (searchEngine == "Mojeek")  // Mojeek.
511     {
512         searchEngineMojeekActionPointer->setChecked(true);
513     }
514     else if (searchEngine == "Monocles")  // Monocles.
515     {
516         searchEngineMonoclesActionPointer->setChecked(true);
517     }
518     else if (searchEngine == "MetaGer")  // MetaGer.
519     {
520         searchEngineMetagerActionPointer->setChecked(true);
521     }
522     else if (searchEngine == "Google")  // Google.
523     {
524         searchEngineGoogleActionPointer->setChecked(true);
525     }
526     else if (searchEngine == "Bing")  // Bing.
527     {
528         searchEngineBingActionPointer->setChecked(true);
529     }
530     else if (searchEngine == "Yahoo")  // Yahoo.
531     {
532         searchEngineYahooActionPointer->setChecked(true);
533     }
534     else  // Custom search engine.
535     {
536         // Check the user agent.
537         searchEngineCustomActionPointer->setChecked(true);
538
539         // Set the custom search engine flag.
540         customSearchEngine = true;
541     }
542
543     // Format the custom search engine.
544     if (customSearchEngine)
545     {
546         // Enable the custom search engine.
547         searchEngineCustomActionPointer->setEnabled(true);
548
549         // Set the custom search engine text.
550         searchEngineCustomActionPointer->setText(searchEngine);
551     }
552     else
553     {
554         // Disable the custom search engine.
555         searchEngineCustomActionPointer->setEnabled(false);
556
557         // Reset the custom search engine text.
558         searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
559     }
560 }
561
562 void BrowserWindow::updateUserAgentActions(const QString &userAgent) const
563 {
564     // Initialize the custom user agent flag.
565     bool customUserAgent = false;
566
567     // Check the indicated on-the-fly user agent.
568     if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) userAgentPrivacyBrowserActionPointer->setChecked(true);  // Privacy Browser.
569     else if (userAgent == BrowserView::webEngineDefaultUserAgent) userAgentWebEngineDefaultActionPointer->setChecked(true);  // WebEngine default.
570     else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) userAgentFirefoxLinuxActionPointer->setChecked(true);  // Firefox Linux.
571     else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) userAgentChromiumLinuxActionPointer->setChecked(true);  // Chromium Linux.
572     else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) userAgentFirefoxWindowsActionPointer->setChecked(true);  // Firefox Windows.
573     else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) userAgentChromeWindowsActionPointer->setChecked(true);  // Chrome Windows.
574     else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) userAgentEdgeWindowsActionPointer->setChecked(true);  // Edge Windows.
575     else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) userAgentSafariMacosActionPointer->setChecked(true);  // Safara macOS.
576     else  // Custom user agent.
577     {
578         // Check the user agent.
579         userAgentCustomActionPointer->setChecked(true);
580
581         // Set the custom user agent flag.
582         customUserAgent = true;
583     }
584
585
586     // Format the custom user agent.
587     if (customUserAgent)
588     {
589         // Enable the custom user agent.
590         userAgentCustomActionPointer->setEnabled(true);
591
592         // Set the custom user agent text.
593         userAgentCustomActionPointer->setText(userAgent);
594     }
595     else
596     {
597         // Disable the custom user agent.
598         userAgentCustomActionPointer->setEnabled(false);
599
600         // Reset the custom user agent text.
601         userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
602     }
603 }
604
605 void BrowserWindow::updateZoomFactorAction(const double &zoomFactor)
606 {
607     // Set the current zoom factor.
608     currentZoomFactor = zoomFactor;
609
610     // Update the zoom factor action text, formatting the double with 2 decimal places.
611     zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
612 }
613
614 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
615 {
616     // Update the search engine label.
617     searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
618 }
619
620 void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl)
621 {
622     // Update the URL line edit if it does not have focus.
623     if (!urlLineEditPointer->hasFocus())
624     {
625         // Update the URL line edit.
626         urlLineEditPointer->setText(newUrl.toString());
627     }
628
629     // Store the current URL.
630     currentUrl = newUrl;
631 }
632
633 void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
634 {
635     // Update the user agent label.
636     userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));
637 }