]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blob - src/windows/BrowserWindow.cpp
Enable spell checking. https://redmine.stoutner.com/issues/840
[PrivacyBrowserPC.git] / src / windows / BrowserWindow.cpp
1 /*
2  * Copyright 2022-2023 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_SettingsGeneral.h"
24 #include "ui_SettingsPrivacy.h"
25 #include "ui_SettingsSpellCheck.h"
26 #include "dialogs/CookiesDialog.h"
27 #include "dialogs/DomainSettingsDialog.h"
28 #include "helpers/SearchEngineHelper.h"
29 #include "helpers/UserAgentHelper.h"
30
31 // KDE Frameworks headers.
32 #include <KActionCollection>
33 #include <KColorScheme>
34 #include <KToolBar>
35
36 // Qt toolkit headers.
37 #include <QFileDialog>
38 #include <QInputDialog>
39 #include <QNetworkCookie>
40 #include <QMenuBar>
41 #include <QShortcut>
42 #include <QStatusBar>
43 #include <QWebEngineFindTextResult>
44
45 // Construct the class.
46 BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
47 {
48     // Initialize the variables.
49     javaScriptEnabled = false;
50     localStorageEnabled = false;
51
52     // Instantiate the privacy tab widget pointer.
53     tabWidgetPointer = new TabWidget(this);
54
55     // Set the privacy tab widget as the central widget.
56     setCentralWidget(tabWidgetPointer);
57
58     // Get a handle for the action collection.
59     KActionCollection *actionCollectionPointer = this->actionCollection();
60
61     // Add the standard actions.
62     KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer);
63     KStandardAction::print(tabWidgetPointer, SLOT(print()), actionCollectionPointer);
64     KStandardAction::printPreview(tabWidgetPointer, SLOT(printPreview()), actionCollectionPointer);
65     KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer);
66     KStandardAction::redisplay(this, SLOT(refresh()), actionCollectionPointer);
67     fullScreenActionPointer = KStandardAction::fullScreen(this, SLOT(toggleFullScreen()), this, actionCollectionPointer);
68     QAction *backActionPointer = KStandardAction::back(this, SLOT(back()), actionCollectionPointer);
69     QAction *forwardActionPointer = KStandardAction::forward(this, SLOT(forward()), actionCollectionPointer);
70     KStandardAction::home(this, SLOT(home()), actionCollectionPointer);
71     KStandardAction::preferences(this, SLOT(showSettingsDialog()), actionCollectionPointer);
72     KStandardAction::find(this, SLOT(focusFindLineEdit()), actionCollectionPointer);
73     QAction *findNextActionPointer = KStandardAction::findNext(this, SLOT(findNext()), actionCollectionPointer);
74     KStandardAction::findPrev(this, SLOT(findPrevious()), actionCollectionPointer);
75
76     // Add the custom actions.
77     userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_privacy_browser"));
78     userAgentWebEngineDefaultActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_webengine_default"));
79     userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_linux"));
80     userAgentChromiumLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chromium_linux"));
81     userAgentFirefoxWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_windows"));
82     userAgentChromeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chrome_windows"));
83     userAgentEdgeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_edge_windows"));
84     userAgentSafariMacosActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_safari_macos"));
85     userAgentCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_custom"));
86     zoomFactorActionPointer = actionCollectionPointer->addAction(QStringLiteral("zoom_factor"));
87     searchEngineMojeekActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_mojeek"));
88     searchEngineMonoclesActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_monocles"));
89     searchEngineMetagerActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_metager"));
90     searchEngineGoogleActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_google"));
91     searchEngineBingActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_bing"));
92     searchEngineYahooActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_yahoo"));
93     searchEngineCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_custom"));
94     QAction *domainSettingsActionPointer = actionCollectionPointer->addAction(QStringLiteral("domain_settings"));
95     cookiesActionPointer = actionCollectionPointer->addAction(QStringLiteral("cookies"));
96     javaScriptActionPointer = actionCollectionPointer->addAction(QStringLiteral("javascript"));
97     localStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("local_storage"));
98     domStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("dom_storage"));
99     findCaseSensitiveActionPointer = actionCollectionPointer->addAction(QStringLiteral("find_case_sensitive"));
100
101     // Create the action groups
102     QActionGroup *userAgentActionGroupPointer = new QActionGroup(this);
103     QActionGroup *searchEngineActionGroupPointer = new QActionGroup(this);
104
105     // Add the actions to the groups.
106     userAgentActionGroupPointer->addAction(userAgentPrivacyBrowserActionPointer);
107     userAgentActionGroupPointer->addAction(userAgentWebEngineDefaultActionPointer);
108     userAgentActionGroupPointer->addAction(userAgentFirefoxLinuxActionPointer);
109     userAgentActionGroupPointer->addAction(userAgentChromiumLinuxActionPointer);
110     userAgentActionGroupPointer->addAction(userAgentFirefoxWindowsActionPointer);
111     userAgentActionGroupPointer->addAction(userAgentChromeWindowsActionPointer);
112     userAgentActionGroupPointer->addAction(userAgentEdgeWindowsActionPointer);
113     userAgentActionGroupPointer->addAction(userAgentSafariMacosActionPointer);
114     userAgentActionGroupPointer->addAction(userAgentCustomActionPointer);
115     searchEngineActionGroupPointer->addAction(searchEngineMojeekActionPointer);
116     searchEngineActionGroupPointer->addAction(searchEngineMonoclesActionPointer);
117     searchEngineActionGroupPointer->addAction(searchEngineMetagerActionPointer);
118     searchEngineActionGroupPointer->addAction(searchEngineGoogleActionPointer);
119     searchEngineActionGroupPointer->addAction(searchEngineBingActionPointer);
120     searchEngineActionGroupPointer->addAction(searchEngineYahooActionPointer);
121     searchEngineActionGroupPointer->addAction(searchEngineCustomActionPointer);
122
123     // Set some actions to be checkable.
124     javaScriptActionPointer->setCheckable(true);
125     localStorageActionPointer->setCheckable(true);
126     domStorageActionPointer->setCheckable(true);
127     findCaseSensitiveActionPointer->setCheckable(true);
128     userAgentPrivacyBrowserActionPointer->setCheckable(true);
129     userAgentWebEngineDefaultActionPointer->setCheckable(true);
130     userAgentFirefoxLinuxActionPointer->setCheckable(true);
131     userAgentChromiumLinuxActionPointer->setCheckable(true);
132     userAgentFirefoxWindowsActionPointer->setCheckable(true);
133     userAgentChromeWindowsActionPointer->setCheckable(true);
134     userAgentEdgeWindowsActionPointer->setCheckable(true);
135     userAgentSafariMacosActionPointer->setCheckable(true);
136     userAgentCustomActionPointer->setCheckable(true);
137     searchEngineMojeekActionPointer->setCheckable(true);
138     searchEngineMonoclesActionPointer->setCheckable(true);
139     searchEngineMetagerActionPointer->setCheckable(true);
140     searchEngineGoogleActionPointer->setCheckable(true);
141     searchEngineBingActionPointer->setCheckable(true);
142     searchEngineYahooActionPointer->setCheckable(true);
143     searchEngineCustomActionPointer->setCheckable(true);
144
145     // Instantiate the user agent helper.
146     UserAgentHelper *userAgentHelperPointer = new UserAgentHelper();
147
148     // Set the action text.
149     userAgentPrivacyBrowserActionPointer->setText(userAgentHelperPointer->PRIVACY_BROWSER_TRANSLATED);
150     userAgentWebEngineDefaultActionPointer->setText(userAgentHelperPointer->WEB_ENGINE_DEFAULT_TRANSLATED);
151     userAgentFirefoxLinuxActionPointer->setText(userAgentHelperPointer->FIREFOX_LINUX_TRANSLATED);
152     userAgentChromiumLinuxActionPointer->setText(userAgentHelperPointer->CHROMIUM_LINUX_TRANSLATED);
153     userAgentFirefoxWindowsActionPointer->setText(userAgentHelperPointer->FIREFOX_WINDOWS_TRANSLATED);
154     userAgentChromeWindowsActionPointer->setText(userAgentHelperPointer->CHROME_WINDOWS_TRANSLATED);
155     userAgentEdgeWindowsActionPointer->setText(userAgentHelperPointer->EDGE_WINDOWS_TRANSLATED);
156     userAgentSafariMacosActionPointer->setText(userAgentHelperPointer->SAFARI_MACOS_TRANSLATED);
157     searchEngineMojeekActionPointer->setText(i18nc("Search engine", "Mojeek"));
158     searchEngineMonoclesActionPointer->setText(i18nc("Search engine", "Monocles"));
159     searchEngineMetagerActionPointer->setText(i18nc("Search engine", "MetaGer"));
160     searchEngineGoogleActionPointer->setText(i18nc("Search engine", "Google"));
161     searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing"));
162     searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo"));
163     domainSettingsActionPointer->setText(i18nc("Domain Settings action", "Domain Settings"));
164     cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", 0));
165     javaScriptActionPointer->setText(i18nc("JavaScript action", "JavaScript"));
166     localStorageActionPointer->setText(i18nc("The Local Storage action", "Local Storage"));
167     domStorageActionPointer->setText(i18nc("DOM Storage action", "DOM Storage"));
168     findCaseSensitiveActionPointer->setText(i18nc("Find Case Sensitive action", "Find Case Sensitive"));
169
170     // Set the action icons.
171     userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
172     userAgentWebEngineDefaultActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
173     userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
174     userAgentChromiumLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
175     userAgentFirefoxWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
176     userAgentChromeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
177     userAgentEdgeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
178     userAgentSafariMacosActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
179     userAgentCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
180     searchEngineMojeekActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
181     searchEngineMonoclesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
182     searchEngineMetagerActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
183     searchEngineGoogleActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-google")));
184     searchEngineBingActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
185     searchEngineYahooActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-yahoo")));
186     searchEngineCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
187     zoomFactorActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("zoom")));
188     domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("settings-configure")));
189     cookiesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("preferences-web-browser-cookies")));
190     domStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("code-class")));
191     findCaseSensitiveActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("format-text-lowercase")));
192
193     // Update the on-the-fly menus.
194     connect(tabWidgetPointer, SIGNAL(updateUserAgentActions(QString, bool)), this, SLOT(updateUserAgentActions(QString, bool)));
195     connect(tabWidgetPointer, SIGNAL(updateZoomFactorAction(double)), this, SLOT(updateZoomFactorAction(double)));
196     connect(tabWidgetPointer, SIGNAL(updateSearchEngineActions(QString, bool)), this, SLOT(updateSearchEngineActions(QString, bool)));
197
198     // Apply the on-the-fly settings when selected.
199     connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), tabWidgetPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
200     connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), tabWidgetPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
201
202     // Process cookie changes.
203     connect(tabWidgetPointer, SIGNAL(updateCookiesAction(int)), this, SLOT(updateCookiesAction(int)));
204
205     // Display dialogs.
206     connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
207     connect(cookiesActionPointer, SIGNAL(triggered()), this, SLOT(showCookiesDialog()));
208     connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(showDomainSettingsDialog()));
209
210     // Connect the URL toolbar actions.
211     connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript()));
212     connect(localStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleLocalStorage()));
213     connect(domStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleDomStorage()));
214
215     // Update the URL toolbar actions.
216     connect(tabWidgetPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
217     connect(tabWidgetPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool)));
218     connect(tabWidgetPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool)));
219     connect(tabWidgetPointer, SIGNAL(updateLocalStorageAction(bool)), this, SLOT(updateLocalStorageAction(bool)));
220     connect(tabWidgetPointer, SIGNAL(updateDomStorageAction(bool)), this, SLOT(updateDomStorageAction(bool)));
221
222     // Connect the find text actions.
223     connect(findCaseSensitiveActionPointer, SIGNAL(triggered()), this, SLOT(toggleFindCaseSensitive()));
224
225     // Setup the GUI based on the browser_window_ui.rc file.
226     setupGUI(StandardWindowOption::Default, ("browserwindowui.rc"));
227
228     // Get lists of the actions' associated widgets.
229     QList<QWidget*> userAgentAssociatedWidgetsPointerList = userAgentPrivacyBrowserActionPointer->associatedWidgets();
230     QList<QWidget*> searchEngineAssociatedWidgetsPointerList = searchEngineMojeekActionPointer->associatedWidgets();
231
232     // Get the menu widget pointers.  It is the second entry, after the main window.
233     QWidget *userAgentMenuWidgetPointer = userAgentAssociatedWidgetsPointerList[1];
234     QWidget *searchEngineMenuWidgetPointer = searchEngineAssociatedWidgetsPointerList[1];
235
236     // Get the menu pointers.
237     QMenu *userAgentMenuPointer = qobject_cast<QMenu*>(userAgentMenuWidgetPointer);
238     QMenu *searchEngineMenuPointer = qobject_cast<QMenu*>(searchEngineMenuWidgetPointer);
239
240     // Get the menu actions.
241     userAgentMenuActionPointer = userAgentMenuPointer->menuAction();
242     searchEngineMenuActionPointer = searchEngineMenuPointer->menuAction();
243
244     // Get handles for the toolbars.
245     navigationToolBarPointer = toolBar(QStringLiteral("navigation_toolbar"));
246     urlToolBarPointer = toolBar(QStringLiteral("url_toolbar"));
247
248     // Create the line edits.
249     urlLineEditPointer = new KLineEdit();
250     findTextLineEditPointer = new KLineEdit();
251
252     // Get the line edit size policies.
253     QSizePolicy urlLineEditSizePolicy = urlLineEditPointer->sizePolicy();
254     QSizePolicy findTextLineEditSizePolicy = findTextLineEditPointer->sizePolicy();
255
256     // Set the URL line edit horizontal stretch to be five times the find text line edit stretch.
257     urlLineEditSizePolicy.setHorizontalStretch(5);
258     findTextLineEditSizePolicy.setHorizontalStretch(1);
259
260     // Set the policies.
261     urlLineEditPointer->setSizePolicy(urlLineEditSizePolicy);
262     findTextLineEditPointer->setSizePolicy(findTextLineEditSizePolicy);
263
264     // Set the widths.
265     urlLineEditPointer->setMinimumWidth(350);
266     findTextLineEditPointer->setMinimumWidth(200);
267     findTextLineEditPointer->setMaximumWidth(350);
268
269     // Set the placehold text.
270     urlLineEditPointer->setPlaceholderText(i18nc("The URL line edit placeholder text", "URL or Search Terms"));
271     findTextLineEditPointer->setPlaceholderText(i18nc("The find line edit placeholder text", "Find Text"));
272
273     // Show the clear button on the find line edit.
274     findTextLineEditPointer->setClearButtonEnabled(true);
275
276     // Add an edit or add domain settings action to the URL line edit.
277     QAction *addOrEditDomainSettingsActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme("settings-configure"), QLineEdit::TrailingPosition);
278
279     // Add or edit the current domain settings.
280     connect(addOrEditDomainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(addOrEditDomainSettings()));
281
282     // Create a find text label pointer.
283     findTextLabelPointer = new QLabel();
284
285     // Set the default label text.
286     findTextLabelPointer->setText(QStringLiteral("  ") + i18nc("Default find results.", "0/0") + QStringLiteral("  "));
287
288     // Insert the widgets into the toolbars.
289     urlToolBarPointer->insertWidget(javaScriptActionPointer, urlLineEditPointer);
290     urlToolBarPointer->insertWidget(findNextActionPointer, findTextLineEditPointer);
291     urlToolBarPointer->insertWidget(findNextActionPointer, findTextLabelPointer);
292
293     // Load a new URL from the URL line edit.
294     connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
295
296     // Find text as it is typed.
297     connect(findTextLineEditPointer, SIGNAL(textEdited(const QString &)), tabWidgetPointer, SLOT(findText(const QString &)));
298
299     // Find next if the enter key is pressed.
300     connect(findTextLineEditPointer, SIGNAL(returnKeyPressed(const QString &)), tabWidgetPointer, SLOT(findText(const QString &)));
301
302     // Update find text when switching tabs.
303     connect(tabWidgetPointer, SIGNAL(updateFindText(const QString &, const bool)), this, SLOT(updateFindText(const QString &, const bool)));
304
305     // Update the find text results.
306     connect(tabWidgetPointer, SIGNAL(updateFindTextResults(const QWebEngineFindTextResult &)), this, SLOT(updateFindTextResults(const QWebEngineFindTextResult &)));
307
308     // Update the URL line edit on page loads.
309     connect(tabWidgetPointer, SIGNAL(updateUrlLineEdit(QUrl)), this, SLOT(updateUrlLineEdit(QUrl)));
310
311     // Update the window title.
312     connect(tabWidgetPointer, SIGNAL(updateWindowTitle(const QString)), this, SLOT(updateWindowTitle(const QString)));
313
314     // Get a handle for the status bar.
315     QStatusBar *statusBarPointer = statusBar();
316
317     // Create a progress bar.
318     progressBarPointer = new QProgressBar();
319
320     // Add the progress bar to to the status bar.
321     statusBarPointer->addPermanentWidget(progressBarPointer);
322
323     // Update the status bar with the URL when a link is hovered.
324     connect(tabWidgetPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
325
326     // Update the progress bar.
327     connect(tabWidgetPointer, SIGNAL(showProgressBar(const int)), this, SLOT(showProgressBar(const int)));
328     connect(tabWidgetPointer, SIGNAL(hideProgressBar()), progressBarPointer, SLOT(hide()));
329
330     // Update the URL line edit focus.
331     connect(tabWidgetPointer, SIGNAL(clearUrlLineEditFocus()), this, SLOT(clearUrlLineEditFocus()));
332
333     // Get the URL line edit palettes.
334     normalBackgroundPalette = urlLineEditPointer->palette();
335     negativeBackgroundPalette = normalBackgroundPalette;
336     positiveBackgroundPalette = normalBackgroundPalette;
337
338     // Modify the palettes.
339     KColorScheme::adjustBackground(negativeBackgroundPalette, KColorScheme::NegativeBackground);
340     KColorScheme::adjustBackground(positiveBackgroundPalette, KColorScheme::PositiveBackground);
341
342     // Update the applied palette.
343     connect(tabWidgetPointer, SIGNAL(updateDomainSettingsIndicator(const bool)), this, SLOT(updateDomainSettingsIndicator(const bool)));
344
345     // Process full screen requests.
346     connect(tabWidgetPointer, SIGNAL(fullScreenRequested(bool)), this, SLOT(fullScreenRequested(bool)));
347
348     // Create keyboard shortcuts.
349     QShortcut *ctrlTShortcutPointer = new QShortcut(QKeySequence(i18nc("The open new tab shortcut.", "Ctrl+t")), this);
350     QShortcut *f11ShortcutPointer = new QShortcut(QKeySequence(i18nc("The toggle full screen shortcut.", "F11")), this);
351     QShortcut *escapeShortcutPointer = new QShortcut(QKeySequence::Cancel, this);
352
353     // Connect the keyboard shortcuts to the actions.
354     connect(ctrlTShortcutPointer, SIGNAL(activated()), tabWidgetPointer, SLOT(addTab()));
355     connect(f11ShortcutPointer, SIGNAL(activated()), fullScreenActionPointer, SLOT(trigger()));
356     connect(escapeShortcutPointer, SIGNAL(activated()), this, SLOT(escape()));
357
358     // Populate the UI.
359     // This must be done here, because otherwise, if a URL is loaded, like a local file, that does not trigger a call to TabWidget::applyDomainSettings, the UI will not be fully populated.
360     updateJavaScriptAction(Settings::javaScriptEnabled());
361     updateLocalStorageAction(Settings::localStorageEnabled());
362     updateDomStorageAction(Settings::domStorageEnabled());
363     updateUserAgentActions(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent()), true);
364     updateZoomFactorAction(Settings::zoomFactor());
365
366     // Load the initial website if this is the first window.
367     if (firstWindow)
368         tabWidgetPointer->loadInitialWebsite();
369 }
370
371 void BrowserWindow::addOrEditDomainSettings() const
372 {
373     // Remove the focus from the URL line edit.
374     urlLineEditPointer->clearFocus();
375
376     // Create the domain settings dialog pointer.
377     DomainSettingsDialog *domainSettingsDialogPointer;
378
379     // Get the current domain settings name.
380     QString &currentDomainSettingsName = tabWidgetPointer->getDomainSettingsName();
381
382     // Run the commands according to the current domain settings status.
383     if (currentDomainSettingsName == QStringLiteral(""))  // Domain settings are not currently applied.
384     {
385         // Instruct the domain settings dialog to add a new domain.
386         domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::ADD_DOMAIN, currentUrl.host());
387     }
388     else  // Domain settings are currently applied.
389     {
390         // Instruct the domain settings dialog to edit the current domain.
391         domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsName);
392     }
393
394     // Set the dialog window title.
395     domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
396
397     // Set the modality.
398     domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
399
400     // Show the dialog.
401     domainSettingsDialogPointer->show();
402
403     // Reload the tabs when domain settings are updated.
404     connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
405 }
406
407 void BrowserWindow::back() const
408 {
409     // Remove the focus from the URL line edit.
410     urlLineEditPointer->clearFocus();
411
412     // Go back.
413     tabWidgetPointer->back();
414 }
415
416 void BrowserWindow::clearUrlLineEditFocus() const
417 {
418     // Remove the focus from the URL line edit.
419     urlLineEditPointer->clearFocus();
420 }
421
422 void BrowserWindow::escape() const
423 {
424     // Process the excape according to the status of the browser.
425     if (fullScreenActionPointer->isChecked())  // Full screen browsing is enabled.
426     {
427         // Exit full screen browsing.
428         fullScreenActionPointer->trigger();
429     }
430     else if (!findTextLineEditPointer->text().isEmpty())  // Find text is activated.
431     {
432         // Clear the text in the line edit.
433         findTextLineEditPointer->clear();
434
435         // Clear the search in the WebEngine.
436         tabWidgetPointer->findText(QStringLiteral(""));
437     }
438 }
439
440 void BrowserWindow::fileNew() const
441 {
442     // Display a new instance of Privacy Browser.
443     (new BrowserWindow)->show();
444 }
445
446 void BrowserWindow::findNext() const
447 {
448     // Get the find string.
449     const QString findString = findTextLineEditPointer->text();
450
451     // Search for the text if it is not empty.
452     if (!findString.isEmpty())
453         tabWidgetPointer->findText(findString);
454 }
455
456 void BrowserWindow::findPrevious() const
457 {
458     // Get the find string.
459     const QString findString = findTextLineEditPointer->text();
460
461     // Search for the text if it is not empty.
462     if (!findString.isEmpty())
463         tabWidgetPointer->findPrevious(findString);
464 }
465
466 void BrowserWindow::focusFindLineEdit() const
467 {
468     // Set the focus on the find line edit.
469     findTextLineEditPointer->setFocus();
470
471     // Select all the text in the find line edit.
472     findTextLineEditPointer->selectAll();
473 }
474
475 void BrowserWindow::forward() const
476 {
477     // Remove the focus from the URL line edit.
478     urlLineEditPointer->clearFocus();
479
480     // Go forward.
481     tabWidgetPointer->forward();
482 }
483
484 void BrowserWindow::fullScreenRequested(const bool toggleOn)
485 {
486     // Toggle full screen mode.
487     if (toggleOn)  // Turn full screen mode on.
488     {
489         // Set the window to be full screen.
490         fullScreenActionPointer->setFullScreen(window(), true);
491
492         // Hide all the bars.
493         menuBar()->setVisible(false);
494         navigationToolBarPointer->setVisible(false);
495         urlToolBarPointer->setVisible(false);
496         tabWidgetPointer->setTabBarVisible(false);
497         statusBar()->setVisible(false);
498     }
499     else  // Turn full screen mode off.
500     {
501         // Set the window to not be full screen.
502         fullScreenActionPointer->setFullScreen(window(), false);
503
504         // Show all the bars.
505         menuBar()->setVisible(true);
506         navigationToolBarPointer->setVisible(true);
507         urlToolBarPointer->setVisible(true);
508         tabWidgetPointer->setTabBarVisible(true);
509         statusBar()->setVisible(true);
510     }
511 }
512
513 void BrowserWindow::getZoomFactorFromUser()
514 {
515     // Create an OK flag.
516     bool okClicked;
517
518     // 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.
519     double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"),
520                                                    i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
521                                                    currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
522
523     // Update the zoom factor if the user clicked OK.
524     if (okClicked)
525     {
526         // Update the current zoom factor.
527         currentZoomFactor = newZoomFactor;
528
529         // Set the new zoom factor.
530         tabWidgetPointer->applyOnTheFlyZoomFactor(newZoomFactor);
531
532         // Update the on-the-fly action text.
533         updateZoomFactorAction(newZoomFactor);
534     }
535 }
536
537 void BrowserWindow::home() const
538 {
539     // Remove the focus from the URL line edit.
540     urlLineEditPointer->clearFocus();
541
542     // Go home.
543     tabWidgetPointer->home();
544 }
545
546 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
547 {
548     // Remove the focus from the URL line edit.
549     urlLineEditPointer->clearFocus();
550
551     // Load the URL.
552     tabWidgetPointer->loadUrlFromLineEdit(url);
553 }
554
555 void BrowserWindow::refresh() const
556 {
557     // Remove the focus from the URL line edit.
558     urlLineEditPointer->clearFocus();
559
560     // Refresh the web page.
561     tabWidgetPointer->refresh();
562 }
563
564 void BrowserWindow::showCookiesDialog()
565 {
566     // Remove the focus from the URL line edit.
567     urlLineEditPointer->clearFocus();
568
569     // Instantiate the cookie settings dialog.
570     CookiesDialog *cookiesDialogPointer = new CookiesDialog(tabWidgetPointer->getCookieList());
571
572     // Show the dialog.
573     cookiesDialogPointer->show();
574
575     // Connect the dialog signals.
576     connect(cookiesDialogPointer, SIGNAL(addCookie(QNetworkCookie)), tabWidgetPointer, SLOT(addCookieToStore(QNetworkCookie)));
577     connect(cookiesDialogPointer, SIGNAL(deleteAllCookies()), tabWidgetPointer, SLOT(deleteAllCookies()));
578     connect(cookiesDialogPointer, SIGNAL(deleteCookie(QNetworkCookie)), tabWidgetPointer, SLOT(deleteCookieFromStore(QNetworkCookie)));
579 }
580
581 void BrowserWindow::showDownloadLocationBrowseDialog() const
582 {
583     // Get the current download location.
584     QString currentDownloadLocation = downloadLocationComboBoxPointer->currentText();
585
586     // Resolve the system download directory if specified.
587     if (currentDownloadLocation == QStringLiteral("System Download Directory"))
588         currentDownloadLocation = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
589
590     // Get the new download location.
591     QString newDownloadLocation = QFileDialog::getExistingDirectory(configDialogPointer, i18nc("Select download location dialog caption", "Select Download Location"), currentDownloadLocation);
592
593     // Populate the download location combo box according to the new download location.
594     if (newDownloadLocation == QStandardPaths::writableLocation(QStandardPaths::DownloadLocation))  // The default download location was selected.
595     {
596         // Populate the download location with the default text.
597         downloadLocationComboBoxPointer->setCurrentText("System Download Directory");
598     }
599     else if (newDownloadLocation != QStringLiteral(""))  // A different directory was selected.
600     {
601         // Populate the download location.
602         downloadLocationComboBoxPointer->setCurrentText(newDownloadLocation);
603     }
604 }
605
606 void BrowserWindow::showDomainSettingsDialog() const
607 {
608     // Remove the focus from the URL line edit.
609     urlLineEditPointer->clearFocus();
610
611     // Instantiate the domain settings dialog.
612     DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
613
614     // Show the dialog.
615     domainSettingsDialogPointer->show();
616
617     // Reload the tabs when domain settings are updated.
618     connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
619 }
620
621 void BrowserWindow::showProgressBar(const int &progress) const
622 {
623     // Set the progress bar value.
624     progressBarPointer->setValue(progress);
625
626     // Show the progress bar.
627     progressBarPointer->show();
628 }
629
630 void BrowserWindow::showSettingsDialog()
631 {
632     // Create the settings widgets.
633     QWidget *privacySettingsWidgetPointer = new QWidget;
634     QWidget *generalSettingsWidgetPointer = new QWidget;
635     QWidget *spellCheckSettingsWidgetPointer = new QWidget;
636
637     // Instantiate the settings UI.
638     Ui::PrivacySettings privacySettingsUi;
639     Ui::GeneralSettings generalSettingsUi;
640     Ui::SpellCheckSettings spellCheckSettingsUi;
641
642     // Setup the UI to display the settings widgets.
643     privacySettingsUi.setupUi(privacySettingsWidgetPointer);
644     generalSettingsUi.setupUi(generalSettingsWidgetPointer);
645     spellCheckSettingsUi.setupUi(spellCheckSettingsWidgetPointer);
646
647     // Get handles for the widgets.
648     QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
649     userAgentLabelPointer = privacySettingsUi.userAgentLabel;
650     QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
651     searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
652     downloadLocationComboBoxPointer = generalSettingsUi.kcfg_downloadLocation;
653     QPushButton *browseButtonPointer = generalSettingsUi.browseButton;
654     QListWidget *spellCheckListWidgetPointer = spellCheckSettingsUi.spellCheckListWidget;
655
656     // Populate the combo box labels.
657     updateUserAgentLabel(userAgentComboBoxPointer->currentText());
658     updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
659
660     // Update the labels when the combo boxes change.
661     connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
662     connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
663
664     // Connect the download location directory browse button.
665     connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(showDownloadLocationBrowseDialog()));
666
667     // Create a dictionaries QDir from the `QTWEBENGINE_DICTIONARIES_PATH` environment variable.
668     QDir dictionariesDir = QDir(qEnvironmentVariable("QTWEBENGINE_DICTIONARIES_PATH"));
669
670     // Get a dictionaries string list.
671     QStringList dictionariesStringList = dictionariesDir.entryList(QStringList(QLatin1String("*.bdic")), QDir::Files | QDir::NoSymLinks);
672
673     // Remove the `.bdic` file extensions from the dictionaries list.
674     dictionariesStringList.replaceInStrings(QLatin1String(".bdic"), QLatin1String(""));
675
676     // Get a list of the enabled spell check languages.
677     QStringList enabledSpellCheckLanguagesList = Settings::spellCheckLanguages();
678
679     // Add each dictionary to the spell check list widget.
680     foreach(QString dictionaryString, dictionariesStringList)
681     {
682         // Create a new list widget item pointer named after the dictionary string.
683         QListWidgetItem *listWidgetItemPointer = new QListWidgetItem(dictionaryString, spellCheckListWidgetPointer);
684
685         // Set the list widget item pointer to be checkable.
686         listWidgetItemPointer->setFlags(listWidgetItemPointer->flags() | Qt::ItemIsUserCheckable);
687
688         // Check the language if it is currently enabled.
689         if (enabledSpellCheckLanguagesList.contains(dictionaryString))
690             listWidgetItemPointer->setCheckState(Qt::Checked);
691         else
692             listWidgetItemPointer->setCheckState(Qt::Unchecked);
693
694         // Add the list widget item to the widget.
695         spellCheckListWidgetPointer->addItem(listWidgetItemPointer);
696     }
697
698     // Get a handle for the KConfig skeleton.
699     KConfigSkeleton *kConfigSkeletonPointer = Settings::self();
700
701     // Instantiate a settings config dialog from the settings.kcfg file.
702     configDialogPointer = new KConfigDialog(this, QLatin1String("settings"), kConfigSkeletonPointer);
703
704     // Add the settings widgets as config dialog pages.
705     configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("Settings tab title", "Privacy"), QLatin1String("privacy-browser"));
706     configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("Settings tab title", "General"), QLatin1String("breeze-settings"));
707     configDialogPointer->addPage(spellCheckSettingsWidgetPointer, i18nc("Settings tab title", "Spell Check"), QLatin1String("tools-check-spelling"));
708
709     // Get handles for the buttons.
710     QPushButton *applyButtonPointer = configDialogPointer->button(QDialogButtonBox::Apply);
711     QPushButton *okButtonPointer = configDialogPointer->button(QDialogButtonBox::Ok);
712
713     // Prevent interaction with the parent window while the dialog is open.
714     configDialogPointer->setWindowModality(Qt::WindowModal);
715
716     // Make it so.
717     configDialogPointer->show();
718
719     // TODO.  KConfigDialog does not respect expanding size policies.  <https://redmine.stoutner.com/issues/823>
720     //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
721     //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
722     //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
723     //configDialogPointer->adjustSize();
724
725     // Expand the config dialog.
726     configDialogPointer->resize(1000, 500);
727
728     // Create a save spell check languages lambda.
729     auto saveSpellCheckLanguages = [spellCheckListWidgetPointer, kConfigSkeletonPointer, this] ()
730     {
731         // Create a list of enabled languages.
732         QStringList newSpellCheckLanguages = QStringList();
733
734         // Get a count of all the languages.
735         int allLanguagesCount = spellCheckListWidgetPointer->count();
736
737         // Get a list of all the checked languages.
738         for (int i = 0; i < allLanguagesCount; ++i) {
739             // Get the language item.
740             QListWidgetItem *languageItemPointer = spellCheckListWidgetPointer->item(i);
741
742             // Add the item to the enabled languages if it is checked.
743             if (languageItemPointer->checkState() == Qt::Checked)
744                 newSpellCheckLanguages.append(languageItemPointer->text());
745         }
746
747         // Update the spell check languages.
748         if (Settings::spellCheckLanguages() != newSpellCheckLanguages)
749         {
750             // Update the spell check languages.
751             Settings::setSpellCheckLanguages(newSpellCheckLanguages);
752
753             // Write the settings to disk.
754             kConfigSkeletonPointer->save();
755         }
756
757         // Apply the spell check languages.
758         tabWidgetPointer->applySpellCheckLanguages();
759     };
760
761     // Process
762     connect(applyButtonPointer, &QPushButton::clicked, this, saveSpellCheckLanguages);
763     connect(okButtonPointer, &QPushButton::clicked, this, saveSpellCheckLanguages);
764
765     // Apply the settings handled by KConfig.
766     connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyApplicationSettings()));
767     connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
768 }
769
770 QSize BrowserWindow::sizeHint() const
771 {
772     // Return the default window size.
773     return QSize(1500, 1200);
774 }
775
776 void BrowserWindow::toggleDomStorage() const
777 {
778     // Remove the focus from the URL line edit.
779     urlLineEditPointer->clearFocus();
780
781     // Toggle DOM storage.
782     tabWidgetPointer->toggleDomStorage();
783 }
784
785 void BrowserWindow::toggleFindCaseSensitive() const
786 {
787     // Get the current find string.
788     const QString findString = findTextLineEditPointer->text();
789
790     // Toggle find case sensitive.
791     tabWidgetPointer->toggleFindCaseSensitive(findString);
792 }
793
794 void BrowserWindow::toggleJavaScript() const
795 {
796     // Remove the focus from the URL line edit.
797     urlLineEditPointer->clearFocus();
798
799     // Toggle JavaScript.
800     tabWidgetPointer->toggleJavaScript();
801 }
802
803 void BrowserWindow::toggleLocalStorage() const
804 {
805     // Remove the focus from the URL line edit.
806     urlLineEditPointer->clearFocus();
807
808     // Toggle local storage.
809     tabWidgetPointer->toggleLocalStorage();
810 }
811
812 void BrowserWindow::toggleFullScreen()
813 {
814     // Toggle the full screen status.
815     if (fullScreenActionPointer->isChecked())  // Enable full screen browsing mode.
816     {
817         // Enable full screen mode.
818         fullScreenActionPointer->setFullScreen(window(), true);
819
820         // Hide the menu bar if specified.
821         if (Settings::fullScreenHideMenuBar())
822             menuBar()->setVisible(false);
823
824         // Hide the toolbars if specified.
825         if (Settings::fullScreenHideToolBars())
826         {
827             navigationToolBarPointer->setVisible(false);
828             urlToolBarPointer->setVisible(false);
829         }
830
831         // Hide the tab bar if specified.
832         if (Settings::fullScreenHideTabBar())
833             tabWidgetPointer->setTabBarVisible(false);
834
835         // Hide the status bar if specified.
836         if (Settings::fullScreenHideStatusBar())
837             statusBar()->setVisible(false);
838     }
839     else  // Disable full screen browsing mode.
840     {
841         // Disable full screen mode.
842         fullScreenActionPointer->setFullScreen(window(), false);
843
844         // Show the menu bar.
845         menuBar()->setVisible(true);
846
847         // Show the toolbars.
848         navigationToolBarPointer->setVisible(true);
849         urlToolBarPointer->setVisible(true);
850
851         // Show the tab bar.
852         tabWidgetPointer->setTabBarVisible(true);
853
854         // Show the status bar.
855         statusBar()->setVisible(true);
856     }
857 }
858
859 void BrowserWindow::updateCookiesAction(const int numberOfCookies) const
860 {
861     // Update the action text.
862     cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", numberOfCookies));
863 }
864
865 void BrowserWindow::updateDomStorageAction(const bool &isEnabled) const
866 {
867     // Set the action checked status.
868     domStorageActionPointer->setChecked(isEnabled);
869 }
870
871 void BrowserWindow::updateDomainSettingsIndicator(const bool status)
872 {
873     // Set the domain palette according to the status.
874     if (status)
875         urlLineEditPointer->setPalette(positiveBackgroundPalette);
876     else
877         urlLineEditPointer->setPalette(normalBackgroundPalette);
878 }
879
880 void BrowserWindow::updateFindText(const QString &text, const bool findCaseSensitive) const
881 {
882     // Set the text.
883     findTextLineEditPointer->setText(text);
884
885     // Set the find case sensitive action checked status.
886     findCaseSensitiveActionPointer->setChecked(findCaseSensitive);
887 }
888
889 void BrowserWindow::updateFindTextResults(const QWebEngineFindTextResult &findTextResult) const
890 {
891     // Update the find text label.
892     findTextLabelPointer->setText(QStringLiteral("  %1/%2  ").arg(findTextResult.activeMatch()).arg(findTextResult.numberOfMatches()));
893
894     // Set the background color according to the find status.
895     if (findTextLineEditPointer->text().isEmpty())
896         findTextLineEditPointer->setPalette(normalBackgroundPalette);
897     else if (findTextResult.numberOfMatches() == 0)
898         findTextLineEditPointer->setPalette(negativeBackgroundPalette);
899     else
900         findTextLineEditPointer->setPalette(positiveBackgroundPalette);
901 }
902
903 void BrowserWindow::updateJavaScriptAction(const bool &isEnabled)
904 {
905     // Update the JavaScript status.
906     javaScriptEnabled = isEnabled;
907
908     // Set the icon according to the status.
909     if (javaScriptEnabled)
910         javaScriptActionPointer->setIcon(QIcon(QStringLiteral(":/icons/javascript-warning")));
911     else
912         javaScriptActionPointer->setIcon(QIcon(QStringLiteral(":/icons/privacy-mode")));
913
914     // Set the action checked status.
915     javaScriptActionPointer->setChecked(javaScriptEnabled);
916
917     // Update the status of the DOM storage action.
918     domStorageActionPointer->setEnabled(javaScriptEnabled & localStorageEnabled);
919 }
920
921 void BrowserWindow::updateLocalStorageAction(const bool &isEnabled)
922 {
923     // Update the local storage status.
924     localStorageEnabled = isEnabled;
925
926     // Update the icon.
927     if (localStorageEnabled)
928         localStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("disk-quota-high")));
929     else
930         localStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("disk-quota")));
931
932     // Set the action checked status.
933     localStorageActionPointer->setChecked(localStorageEnabled);
934
935     // Update the status of the DOM storage action.
936     domStorageActionPointer->setEnabled(localStorageEnabled & javaScriptEnabled);
937 }
938
939 void BrowserWindow::updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus)
940 {
941     // Initialize the custom search engine flag.
942     bool customSearchEngine = false;
943
944     if (searchEngine == "Mojeek")  // Mojeek.
945     {
946         // Check the Mojeek user agent action.
947         searchEngineMojeekActionPointer->setChecked(true);
948
949         // Update the search engine menu action text.
950         searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Mojeek"));
951     }
952     else if (searchEngine == "Monocles")  // Monocles.
953     {
954         // Check the Monocles user agent action.
955         searchEngineMonoclesActionPointer->setChecked(true);
956
957         // Update the search engine menu action text.
958         searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Monocles"));
959     }
960     else if (searchEngine == "MetaGer")  // MetaGer.
961     {
962         // Check the MetaGer user agent action.
963         searchEngineMetagerActionPointer->setChecked(true);
964
965         // Update the search engine menu action text.
966         searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - MetaGer"));
967     }
968     else if (searchEngine == "Google")  // Google.
969     {
970         // Check the Google user agent action.
971         searchEngineGoogleActionPointer->setChecked(true);
972
973         // Update the search engine menu action text.
974         searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Google"));
975     }
976     else if (searchEngine == "Bing")  // Bing.
977     {
978         // Check the Bing user agent action.
979         searchEngineBingActionPointer->setChecked(true);
980
981         // Update the search engine menu action text.
982         searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Bing"));
983     }
984     else if (searchEngine == "Yahoo")  // Yahoo.
985     {
986         // Check the Yahoo user agent action.
987         searchEngineYahooActionPointer->setChecked(true);
988
989         // Update the search engine menu action text.
990         searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Yahoo"));
991     }
992     else  // Custom search engine.
993     {
994         // Check the user agent.
995         searchEngineCustomActionPointer->setChecked(true);
996
997         // Update the search engine menu action text.
998         searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Custom"));
999
1000         // Set the custom search engine text.
1001         searchEngineCustomActionPointer->setText(searchEngine);
1002
1003         // Set the custom search engine flag.
1004         customSearchEngine = true;
1005     }
1006
1007     // Update the custom search engine enabled boolean.
1008     if (updateCustomSearchEngineStatus)
1009         customSearchEngineEnabled = customSearchEngine;
1010
1011     // Format the custom search engine.
1012     if (customSearchEngineEnabled)
1013     {
1014         // Enable the custom search engine.
1015         searchEngineCustomActionPointer->setEnabled(true);
1016     }
1017     else
1018     {
1019         // Disable the custom search engine.
1020         searchEngineCustomActionPointer->setEnabled(false);
1021
1022         // Reset the custom search engine text.
1023         searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
1024     }
1025 }
1026
1027 void BrowserWindow::updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus)
1028 {
1029     // Initialize the custom user agent flag.
1030     bool customUserAgent = false;
1031
1032     // Check the indicated on-the-fly user agent.
1033     if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT)  // Privacy Browser.
1034     {
1035         // Check the Privacy Browser user agent action.
1036         userAgentPrivacyBrowserActionPointer->setChecked(true);
1037
1038         // Update the user agent menu action text.
1039         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Privacy Browser"));
1040     }
1041     else if (userAgent == TabWidget::webEngineDefaultUserAgent)  // WebEngine default.
1042     {
1043         // check the WebEngine default user agent action.
1044         userAgentWebEngineDefaultActionPointer->setChecked(true);
1045
1046         // Update the user agent menu action text.
1047         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - WebEngine default"));
1048     }
1049     else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT)  // Firefox on Linux.
1050     {
1051         // Check the Firefox on Linux user agent action.
1052         userAgentFirefoxLinuxActionPointer->setChecked(true);
1053
1054         // Update the user agent menu action text.
1055         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Firefox on Linux"));
1056     }
1057     else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT)  // Chromium on Linux.
1058     {
1059         // Check the Chromium on Linux user agent action.
1060         userAgentChromiumLinuxActionPointer->setChecked(true);
1061
1062         // Update the user agent menu action text.
1063         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Chromium on Linux"));
1064     }
1065     else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT)  // Firefox on Windows.
1066     {
1067         // Check the Firefox on Windows user agent action.
1068         userAgentFirefoxWindowsActionPointer->setChecked(true);
1069
1070         // Update the user agent menu action text.
1071         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Firefox on Windows"));
1072     }
1073     else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT)  // Chrome on Windows.
1074     {
1075         // Check the Chrome on Windows user agent action.
1076         userAgentChromeWindowsActionPointer->setChecked(true);
1077
1078         // Update the user agent menu action text.
1079         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Chrome on Windows"));
1080     }
1081     else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT)  // Edge on Windows.
1082     {
1083         // Check the Edge on Windows user agent action.
1084         userAgentEdgeWindowsActionPointer->setChecked(true);
1085
1086         // Update the user agent menu action text.
1087         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Edge on Windows"));
1088     }
1089     else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT)  // Safari on macOS.
1090     {
1091         // Check the Safari on macOS user agent action.
1092         userAgentSafariMacosActionPointer->setChecked(true);
1093
1094         // Update the user agent menu action text.
1095         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Safari on macOS"));
1096     }
1097     else  // Custom user agent.
1098     {
1099         // Check the user agent.
1100         userAgentCustomActionPointer->setChecked(true);
1101
1102         // Update the user agent menu action text.
1103         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Custom"));
1104
1105         // Set the custom user agent text.
1106         userAgentCustomActionPointer->setText(userAgent);
1107
1108         // Set the custom user agent flag.
1109         customUserAgent = true;
1110     }
1111
1112     // Update the custom user agent enabled boolean.
1113     // This is not done when the current user agent is a custom one but it is temporarially being changed via on-the-fly settings so that the user can switch back to the custom user agent.
1114     if (updateCustomUserAgentStatus)
1115         customUserAgentEnabled = customUserAgent;
1116
1117
1118     // Format the custom user agent.
1119     if (customUserAgentEnabled)
1120     {
1121         // Enable the custom user agent.
1122         userAgentCustomActionPointer->setEnabled(true);
1123     }
1124     else
1125     {
1126         // Disable the custom user agent.
1127         userAgentCustomActionPointer->setEnabled(false);
1128
1129         // Reset the custom user agent text.
1130         userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
1131     }
1132 }
1133
1134 void BrowserWindow::updateZoomFactorAction(const double &zoomFactor)
1135 {
1136     // Set the current zoom factor.
1137     currentZoomFactor = zoomFactor;
1138
1139     // Update the zoom factor action text, formatting the double with 2 decimal places.
1140     zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
1141 }
1142
1143 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
1144 {
1145     // Update the search engine label.
1146     searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
1147 }
1148
1149 void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl)
1150 {
1151     // Update the URL line edit if it does not have focus.
1152     if (!urlLineEditPointer->hasFocus())
1153     {
1154         // Get the new URL string.
1155         QString newUrlString = newUrl.toString();
1156
1157         // Update the URL line edit.
1158         urlLineEditPointer->setText(newUrlString);
1159
1160         // Set the focus if the new URL is blank.
1161         if (newUrlString == QStringLiteral(""))
1162             urlLineEditPointer->setFocus();
1163     }
1164
1165     // Store the current URL.
1166     currentUrl = newUrl;
1167 }
1168
1169 void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
1170 {
1171     // Update the user agent label.
1172     userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));
1173 }
1174
1175 void BrowserWindow::updateWindowTitle(const QString &title)
1176 {
1177     // Update the window title.
1178     setWindowTitle(title);
1179 }