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