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