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