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