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