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