]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blob - src/windows/BrowserWindow.cpp
Hide the find text actions by default. https://redmine.stoutner.com/issues/960
[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 activated.
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 }
446
447 void BrowserWindow::fileNew() const
448 {
449     // Display a new instance of Privacy Browser.
450     (new BrowserWindow)->show();
451 }
452
453 void BrowserWindow::findNext() const
454 {
455     // Get the find string.
456     const QString findString = findTextLineEditPointer->text();
457
458     // Search for the text if it is not empty.
459     if (!findString.isEmpty())
460         tabWidgetPointer->findText(findString);
461 }
462
463 void BrowserWindow::findPrevious() const
464 {
465     // Get the find string.
466     const QString findString = findTextLineEditPointer->text();
467
468     // Search for the text if it is not empty.
469     if (!findString.isEmpty())
470         tabWidgetPointer->findPrevious(findString);
471 }
472
473 void BrowserWindow::forward() const
474 {
475     // Remove the focus from the URL line edit.
476     urlLineEditPointer->clearFocus();
477
478     // Go forward.
479     tabWidgetPointer->forward();
480 }
481
482 void BrowserWindow::fullScreenRequested(const bool toggleOn)
483 {
484     // Toggle full screen mode.
485     if (toggleOn)  // Turn full screen mode on.
486     {
487         // Set the window to be full screen.
488         fullScreenActionPointer->setFullScreen(window(), true);
489
490         // Hide all the bars.
491         menuBar()->setVisible(false);
492         navigationToolBarPointer->setVisible(false);
493         urlToolBarPointer->setVisible(false);
494         tabWidgetPointer->setTabBarVisible(false);
495         statusBar()->setVisible(false);
496     }
497     else  // Turn full screen mode off.
498     {
499         // Set the window to not be full screen.
500         fullScreenActionPointer->setFullScreen(window(), false);
501
502         // Show all the bars.
503         menuBar()->setVisible(true);
504         navigationToolBarPointer->setVisible(true);
505         urlToolBarPointer->setVisible(true);
506         tabWidgetPointer->setTabBarVisible(true);
507         statusBar()->setVisible(true);
508     }
509 }
510
511 void BrowserWindow::getZoomFactorFromUser()
512 {
513     // Create an OK flag.
514     bool okClicked;
515
516     // 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.
517     double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"),
518                                                    i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
519                                                    currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
520
521     // Update the zoom factor if the user clicked OK.
522     if (okClicked)
523     {
524         // Update the current zoom factor.
525         currentZoomFactor = newZoomFactor;
526
527         // Set the new zoom factor.
528         tabWidgetPointer->applyOnTheFlyZoomFactor(newZoomFactor);
529
530         // Update the on-the-fly action text.
531         updateZoomFactorAction(newZoomFactor);
532     }
533 }
534
535 void BrowserWindow::hideFindTextActions() const
536 {
537     // Hide the find text actions.
538     findTextLineEditActionPointer->setVisible(false);
539     findTextLabelActionPointer->setVisible(false);
540     findNextActionPointer->setVisible(false);
541     findPreviousActionPointer->setVisible(false);
542     findCaseSensitiveActionPointer->setVisible(false);
543     hideFindTextActionPointer->setVisible(false);
544 }
545
546 void BrowserWindow::home() const
547 {
548     // Remove the focus from the URL line edit.
549     urlLineEditPointer->clearFocus();
550
551     // Go home.
552     tabWidgetPointer->home();
553 }
554
555 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
556 {
557     // Remove the focus from the URL line edit.
558     urlLineEditPointer->clearFocus();
559
560     // Load the URL.
561     tabWidgetPointer->loadUrlFromLineEdit(url);
562 }
563
564 void BrowserWindow::refresh() const
565 {
566     // Remove the focus from the URL line edit.
567     urlLineEditPointer->clearFocus();
568
569     // Refresh the web page.
570     tabWidgetPointer->refresh();
571 }
572
573 void BrowserWindow::showCookiesDialog()
574 {
575     // Remove the focus from the URL line edit.
576     urlLineEditPointer->clearFocus();
577
578     // Instantiate the cookie settings dialog.
579     CookiesDialog *cookiesDialogPointer = new CookiesDialog(tabWidgetPointer->getCookieList());
580
581     // Show the dialog.
582     cookiesDialogPointer->show();
583
584     // Connect the dialog signals.
585     connect(cookiesDialogPointer, SIGNAL(addCookie(QNetworkCookie)), tabWidgetPointer, SLOT(addCookieToStore(QNetworkCookie)));
586     connect(cookiesDialogPointer, SIGNAL(deleteAllCookies()), tabWidgetPointer, SLOT(deleteAllCookies()));
587     connect(cookiesDialogPointer, SIGNAL(deleteCookie(QNetworkCookie)), tabWidgetPointer, SLOT(deleteCookieFromStore(QNetworkCookie)));
588 }
589
590 void BrowserWindow::showDownloadLocationBrowseDialog() const
591 {
592     // Get the current download location.
593     QString currentDownloadLocation = downloadLocationComboBoxPointer->currentText();
594
595     // Resolve the system download directory if specified.
596     if (currentDownloadLocation == QStringLiteral("System Download Directory"))
597         currentDownloadLocation = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
598
599     // Get the new download location.
600     QString newDownloadLocation = QFileDialog::getExistingDirectory(configDialogPointer, i18nc("Select download location dialog caption", "Select Download Location"), currentDownloadLocation);
601
602     // Populate the download location combo box according to the new download location.
603     if (newDownloadLocation == QStandardPaths::writableLocation(QStandardPaths::DownloadLocation))  // The default download location was selected.
604     {
605         // Populate the download location with the default text.
606         downloadLocationComboBoxPointer->setCurrentText("System Download Directory");
607     }
608     else if (newDownloadLocation != QStringLiteral(""))  // A different directory was selected.
609     {
610         // Populate the download location.
611         downloadLocationComboBoxPointer->setCurrentText(newDownloadLocation);
612     }
613 }
614
615 void BrowserWindow::showDomainSettingsDialog() const
616 {
617     // Remove the focus from the URL line edit.
618     urlLineEditPointer->clearFocus();
619
620     // Instantiate the domain settings dialog.
621     DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
622
623     // Show the dialog.
624     domainSettingsDialogPointer->show();
625
626     // Reload the tabs when domain settings are updated.
627     connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
628 }
629
630 void BrowserWindow::showFindTextActions() const
631 {
632     // Show the find text actions.
633     findTextLineEditActionPointer->setVisible(true);
634     findTextLabelActionPointer->setVisible(true);
635     findNextActionPointer->setVisible(true);
636     findPreviousActionPointer->setVisible(true);
637     findCaseSensitiveActionPointer->setVisible(true);
638     hideFindTextActionPointer->setVisible(true);
639
640     // Set the focus on the find line edit.
641     findTextLineEditPointer->setFocus();
642
643     // Select all the text in the find line edit.
644     findTextLineEditPointer->selectAll();
645 }
646
647 void BrowserWindow::showProgressBar(const int &progress) const
648 {
649     // Set the progress bar value.
650     progressBarPointer->setValue(progress);
651
652     // Show the progress bar.
653     progressBarPointer->show();
654 }
655
656 void BrowserWindow::showSettingsDialog()
657 {
658     // Create the settings widgets.
659     QWidget *privacySettingsWidgetPointer = new QWidget;
660     QWidget *generalSettingsWidgetPointer = new QWidget;
661     QWidget *spellCheckSettingsWidgetPointer = new QWidget;
662
663     // Instantiate the settings UI.
664     Ui::PrivacySettings privacySettingsUi;
665     Ui::GeneralSettings generalSettingsUi;
666     Ui::SpellCheckSettings spellCheckSettingsUi;
667
668     // Setup the UI to display the settings widgets.
669     privacySettingsUi.setupUi(privacySettingsWidgetPointer);
670     generalSettingsUi.setupUi(generalSettingsWidgetPointer);
671     spellCheckSettingsUi.setupUi(spellCheckSettingsWidgetPointer);
672
673     // Get handles for the widgets.
674     QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
675     userAgentLabelPointer = privacySettingsUi.userAgentLabel;
676     QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
677     searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
678     downloadLocationComboBoxPointer = generalSettingsUi.kcfg_downloadLocation;
679     QPushButton *browseButtonPointer = generalSettingsUi.browseButton;
680     QListWidget *spellCheckListWidgetPointer = spellCheckSettingsUi.spellCheckListWidget;
681
682     // Populate the combo box labels.
683     updateUserAgentLabel(userAgentComboBoxPointer->currentText());
684     updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
685
686     // Update the labels when the combo boxes change.
687     connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
688     connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
689
690     // Connect the download location directory browse button.
691     connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(showDownloadLocationBrowseDialog()));
692
693     // Create a dictionaries QDir from the `QTWEBENGINE_DICTIONARIES_PATH` environment variable.
694     QDir dictionariesDir = QDir(qEnvironmentVariable("QTWEBENGINE_DICTIONARIES_PATH"));
695
696     // Get a dictionaries string list.
697     QStringList dictionariesStringList = dictionariesDir.entryList(QStringList(QLatin1String("*.bdic")), QDir::Files | QDir::NoSymLinks);
698
699     // Remove the `.bdic` file extensions from the dictionaries list.
700     dictionariesStringList.replaceInStrings(QLatin1String(".bdic"), QLatin1String(""));
701
702     // Get a list of the enabled spell check languages.
703     QStringList enabledSpellCheckLanguagesList = Settings::spellCheckLanguages();
704
705     // Add each dictionary to the spell check list widget.
706     foreach(QString dictionaryString, dictionariesStringList)
707     {
708         // Create a new list widget item pointer named after the dictionary string.
709         QListWidgetItem *listWidgetItemPointer = new QListWidgetItem(dictionaryString, spellCheckListWidgetPointer);
710
711         // Set the list widget item pointer to be checkable.
712         listWidgetItemPointer->setFlags(listWidgetItemPointer->flags() | Qt::ItemIsUserCheckable);
713
714         // Check the language if it is currently enabled.
715         if (enabledSpellCheckLanguagesList.contains(dictionaryString))
716             listWidgetItemPointer->setCheckState(Qt::Checked);
717         else
718             listWidgetItemPointer->setCheckState(Qt::Unchecked);
719
720         // Add the list widget item to the widget.
721         spellCheckListWidgetPointer->addItem(listWidgetItemPointer);
722     }
723
724     // Get a handle for the KConfig skeleton.
725     KConfigSkeleton *kConfigSkeletonPointer = Settings::self();
726
727     // Instantiate a settings config dialog from the settings.kcfg file.
728     configDialogPointer = new KConfigDialog(this, QLatin1String("settings"), kConfigSkeletonPointer);
729
730     // Add the settings widgets as config dialog pages.
731     configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("Settings tab title", "Privacy"), QLatin1String("privacy-browser"));
732     configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("Settings tab title", "General"), QLatin1String("breeze-settings"));
733     configDialogPointer->addPage(spellCheckSettingsWidgetPointer, i18nc("Settings tab title", "Spell Check"), QLatin1String("tools-check-spelling"));
734
735     // Get handles for the buttons.
736     QPushButton *applyButtonPointer = configDialogPointer->button(QDialogButtonBox::Apply);
737     QPushButton *okButtonPointer = configDialogPointer->button(QDialogButtonBox::Ok);
738
739     // Prevent interaction with the parent window while the dialog is open.
740     configDialogPointer->setWindowModality(Qt::WindowModal);
741
742     // Make it so.
743     configDialogPointer->show();
744
745     // TODO.  KConfigDialog does not respect expanding size policies.  <https://redmine.stoutner.com/issues/823>
746     //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
747     //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
748     //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
749     //configDialogPointer->adjustSize();
750
751     // Expand the config dialog.
752     configDialogPointer->resize(1000, 500);
753
754     // Create a save spell check languages lambda.
755     auto saveSpellCheckLanguages = [spellCheckListWidgetPointer, kConfigSkeletonPointer, this] ()
756     {
757         // Create a list of enabled languages.
758         QStringList newSpellCheckLanguages = QStringList();
759
760         // Get a count of all the languages.
761         int allLanguagesCount = spellCheckListWidgetPointer->count();
762
763         // Get a list of all the checked languages.
764         for (int i = 0; i < allLanguagesCount; ++i) {
765             // Get the language item.
766             QListWidgetItem *languageItemPointer = spellCheckListWidgetPointer->item(i);
767
768             // Add the item to the enabled languages if it is checked.
769             if (languageItemPointer->checkState() == Qt::Checked)
770                 newSpellCheckLanguages.append(languageItemPointer->text());
771         }
772
773         // Update the spell check languages.
774         if (Settings::spellCheckLanguages() != newSpellCheckLanguages)
775         {
776             // Update the spell check languages.
777             Settings::setSpellCheckLanguages(newSpellCheckLanguages);
778
779             // Write the settings to disk.
780             kConfigSkeletonPointer->save();
781         }
782
783         // Apply the spell check languages.
784         tabWidgetPointer->applySpellCheckLanguages();
785     };
786
787     // Process
788     connect(applyButtonPointer, &QPushButton::clicked, this, saveSpellCheckLanguages);
789     connect(okButtonPointer, &QPushButton::clicked, this, saveSpellCheckLanguages);
790
791     // Apply the settings handled by KConfig.
792     connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyApplicationSettings()));
793     connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
794 }
795
796 QSize BrowserWindow::sizeHint() const
797 {
798     // Return the default window size.
799     return QSize(1500, 1200);
800 }
801
802 void BrowserWindow::toggleDomStorage() const
803 {
804     // Remove the focus from the URL line edit.
805     urlLineEditPointer->clearFocus();
806
807     // Toggle DOM storage.
808     tabWidgetPointer->toggleDomStorage();
809 }
810
811 void BrowserWindow::toggleFindCaseSensitive() const
812 {
813     // Get the current find string.
814     const QString findString = findTextLineEditPointer->text();
815
816     // Toggle find case sensitive.
817     tabWidgetPointer->toggleFindCaseSensitive(findString);
818 }
819
820 void BrowserWindow::toggleJavaScript() const
821 {
822     // Remove the focus from the URL line edit.
823     urlLineEditPointer->clearFocus();
824
825     // Toggle JavaScript.
826     tabWidgetPointer->toggleJavaScript();
827 }
828
829 void BrowserWindow::toggleLocalStorage() const
830 {
831     // Remove the focus from the URL line edit.
832     urlLineEditPointer->clearFocus();
833
834     // Toggle local storage.
835     tabWidgetPointer->toggleLocalStorage();
836 }
837
838 void BrowserWindow::toggleFullScreen()
839 {
840     // Toggle the full screen status.
841     if (fullScreenActionPointer->isChecked())  // Enable full screen browsing mode.
842     {
843         // Enable full screen mode.
844         fullScreenActionPointer->setFullScreen(window(), true);
845
846         // Hide the menu bar if specified.
847         if (Settings::fullScreenHideMenuBar())
848             menuBar()->setVisible(false);
849
850         // Hide the toolbars if specified.
851         if (Settings::fullScreenHideToolBars())
852         {
853             navigationToolBarPointer->setVisible(false);
854             urlToolBarPointer->setVisible(false);
855         }
856
857         // Hide the tab bar if specified.
858         if (Settings::fullScreenHideTabBar())
859             tabWidgetPointer->setTabBarVisible(false);
860
861         // Hide the status bar if specified.
862         if (Settings::fullScreenHideStatusBar())
863             statusBar()->setVisible(false);
864     }
865     else  // Disable full screen browsing mode.
866     {
867         // Disable full screen mode.
868         fullScreenActionPointer->setFullScreen(window(), false);
869
870         // Show the menu bar.
871         menuBar()->setVisible(true);
872
873         // Show the toolbars.
874         navigationToolBarPointer->setVisible(true);
875         urlToolBarPointer->setVisible(true);
876
877         // Show the tab bar.
878         tabWidgetPointer->setTabBarVisible(true);
879
880         // Show the status bar.
881         statusBar()->setVisible(true);
882     }
883 }
884
885 void BrowserWindow::updateCookiesAction(const int numberOfCookies) const
886 {
887     // Update the action text.
888     cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", numberOfCookies));
889 }
890
891 void BrowserWindow::updateDomStorageAction(const bool &isEnabled) const
892 {
893     // Set the action checked status.
894     domStorageActionPointer->setChecked(isEnabled);
895 }
896
897 void BrowserWindow::updateDomainSettingsIndicator(const bool status)
898 {
899     // Set the domain palette according to the status.
900     if (status)
901         urlLineEditPointer->setPalette(positiveBackgroundPalette);
902     else
903         urlLineEditPointer->setPalette(normalBackgroundPalette);
904 }
905
906 void BrowserWindow::updateFindText(const QString &text, const bool findCaseSensitive) const
907 {
908     // Set the text.
909     findTextLineEditPointer->setText(text);
910
911     // Set the find case sensitive action checked status.
912     findCaseSensitiveActionPointer->setChecked(findCaseSensitive);
913 }
914
915 void BrowserWindow::updateFindTextResults(const QWebEngineFindTextResult &findTextResult) const
916 {
917     // Update the find text label.
918     findTextLabelPointer->setText(QStringLiteral("  %1/%2  ").arg(findTextResult.activeMatch()).arg(findTextResult.numberOfMatches()));
919
920     // Set the background color according to the find status.
921     if (findTextLineEditPointer->text().isEmpty())
922         findTextLineEditPointer->setPalette(normalBackgroundPalette);
923     else if (findTextResult.numberOfMatches() == 0)
924         findTextLineEditPointer->setPalette(negativeBackgroundPalette);
925     else
926         findTextLineEditPointer->setPalette(positiveBackgroundPalette);
927 }
928
929 void BrowserWindow::updateJavaScriptAction(const bool &isEnabled)
930 {
931     // Update the JavaScript status.
932     javaScriptEnabled = isEnabled;
933
934     // Set the icon according to the status.
935     if (javaScriptEnabled)
936         javaScriptActionPointer->setIcon(QIcon(QStringLiteral(":/icons/javascript-warning")));
937     else
938         javaScriptActionPointer->setIcon(QIcon(QStringLiteral(":/icons/privacy-mode")));
939
940     // Set the action checked status.
941     javaScriptActionPointer->setChecked(javaScriptEnabled);
942
943     // Update the status of the DOM storage action.
944     domStorageActionPointer->setEnabled(javaScriptEnabled & localStorageEnabled);
945 }
946
947 void BrowserWindow::updateLocalStorageAction(const bool &isEnabled)
948 {
949     // Update the local storage status.
950     localStorageEnabled = isEnabled;
951
952     // Update the icon.
953     if (localStorageEnabled)
954         localStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("disk-quota-high")));
955     else
956         localStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("disk-quota")));
957
958     // Set the action checked status.
959     localStorageActionPointer->setChecked(localStorageEnabled);
960
961     // Update the status of the DOM storage action.
962     domStorageActionPointer->setEnabled(localStorageEnabled & javaScriptEnabled);
963 }
964
965 void BrowserWindow::updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus)
966 {
967     // Initialize the custom search engine flag.
968     bool customSearchEngine = false;
969
970     if (searchEngine == "Mojeek")  // Mojeek.
971     {
972         // Check the Mojeek user agent action.
973         searchEngineMojeekActionPointer->setChecked(true);
974
975         // Update the search engine menu action text.
976         searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Mojeek"));
977     }
978     else if (searchEngine == "Monocles")  // Monocles.
979     {
980         // Check the Monocles user agent action.
981         searchEngineMonoclesActionPointer->setChecked(true);
982
983         // Update the search engine menu action text.
984         searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Monocles"));
985     }
986     else if (searchEngine == "MetaGer")  // MetaGer.
987     {
988         // Check the MetaGer user agent action.
989         searchEngineMetagerActionPointer->setChecked(true);
990
991         // Update the search engine menu action text.
992         searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - MetaGer"));
993     }
994     else if (searchEngine == "Google")  // Google.
995     {
996         // Check the Google user agent action.
997         searchEngineGoogleActionPointer->setChecked(true);
998
999         // Update the search engine menu action text.
1000         searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Google"));
1001     }
1002     else if (searchEngine == "Bing")  // Bing.
1003     {
1004         // Check the Bing user agent action.
1005         searchEngineBingActionPointer->setChecked(true);
1006
1007         // Update the search engine menu action text.
1008         searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Bing"));
1009     }
1010     else if (searchEngine == "Yahoo")  // Yahoo.
1011     {
1012         // Check the Yahoo user agent action.
1013         searchEngineYahooActionPointer->setChecked(true);
1014
1015         // Update the search engine menu action text.
1016         searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Yahoo"));
1017     }
1018     else  // Custom search engine.
1019     {
1020         // Check the user agent.
1021         searchEngineCustomActionPointer->setChecked(true);
1022
1023         // Update the search engine menu action text.
1024         searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Custom"));
1025
1026         // Set the custom search engine text.
1027         searchEngineCustomActionPointer->setText(searchEngine);
1028
1029         // Set the custom search engine flag.
1030         customSearchEngine = true;
1031     }
1032
1033     // Update the custom search engine enabled boolean.
1034     if (updateCustomSearchEngineStatus)
1035         customSearchEngineEnabled = customSearchEngine;
1036
1037     // Format the custom search engine.
1038     if (customSearchEngineEnabled)
1039     {
1040         // Enable the custom search engine.
1041         searchEngineCustomActionPointer->setEnabled(true);
1042     }
1043     else
1044     {
1045         // Disable the custom search engine.
1046         searchEngineCustomActionPointer->setEnabled(false);
1047
1048         // Reset the custom search engine text.
1049         searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
1050     }
1051 }
1052
1053 void BrowserWindow::updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus)
1054 {
1055     // Initialize the custom user agent flag.
1056     bool customUserAgent = false;
1057
1058     // Check the indicated on-the-fly user agent.
1059     if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT)  // Privacy Browser.
1060     {
1061         // Check the Privacy Browser user agent action.
1062         userAgentPrivacyBrowserActionPointer->setChecked(true);
1063
1064         // Update the user agent menu action text.
1065         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Privacy Browser"));
1066     }
1067     else if (userAgent == TabWidget::webEngineDefaultUserAgent)  // WebEngine default.
1068     {
1069         // check the WebEngine default user agent action.
1070         userAgentWebEngineDefaultActionPointer->setChecked(true);
1071
1072         // Update the user agent menu action text.
1073         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - WebEngine default"));
1074     }
1075     else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT)  // Firefox on Linux.
1076     {
1077         // Check the Firefox on Linux user agent action.
1078         userAgentFirefoxLinuxActionPointer->setChecked(true);
1079
1080         // Update the user agent menu action text.
1081         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Firefox on Linux"));
1082     }
1083     else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT)  // Chromium on Linux.
1084     {
1085         // Check the Chromium on Linux user agent action.
1086         userAgentChromiumLinuxActionPointer->setChecked(true);
1087
1088         // Update the user agent menu action text.
1089         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Chromium on Linux"));
1090     }
1091     else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT)  // Firefox on Windows.
1092     {
1093         // Check the Firefox on Windows user agent action.
1094         userAgentFirefoxWindowsActionPointer->setChecked(true);
1095
1096         // Update the user agent menu action text.
1097         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Firefox on Windows"));
1098     }
1099     else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT)  // Chrome on Windows.
1100     {
1101         // Check the Chrome on Windows user agent action.
1102         userAgentChromeWindowsActionPointer->setChecked(true);
1103
1104         // Update the user agent menu action text.
1105         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Chrome on Windows"));
1106     }
1107     else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT)  // Edge on Windows.
1108     {
1109         // Check the Edge on Windows user agent action.
1110         userAgentEdgeWindowsActionPointer->setChecked(true);
1111
1112         // Update the user agent menu action text.
1113         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Edge on Windows"));
1114     }
1115     else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT)  // Safari on macOS.
1116     {
1117         // Check the Safari on macOS user agent action.
1118         userAgentSafariMacosActionPointer->setChecked(true);
1119
1120         // Update the user agent menu action text.
1121         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Safari on macOS"));
1122     }
1123     else  // Custom user agent.
1124     {
1125         // Check the user agent.
1126         userAgentCustomActionPointer->setChecked(true);
1127
1128         // Update the user agent menu action text.
1129         userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Custom"));
1130
1131         // Set the custom user agent text.
1132         userAgentCustomActionPointer->setText(userAgent);
1133
1134         // Set the custom user agent flag.
1135         customUserAgent = true;
1136     }
1137
1138     // Update the custom user agent enabled boolean.
1139     // 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.
1140     if (updateCustomUserAgentStatus)
1141         customUserAgentEnabled = customUserAgent;
1142
1143
1144     // Format the custom user agent.
1145     if (customUserAgentEnabled)
1146     {
1147         // Enable the custom user agent.
1148         userAgentCustomActionPointer->setEnabled(true);
1149     }
1150     else
1151     {
1152         // Disable the custom user agent.
1153         userAgentCustomActionPointer->setEnabled(false);
1154
1155         // Reset the custom user agent text.
1156         userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
1157     }
1158 }
1159
1160 void BrowserWindow::updateZoomFactorAction(const double &zoomFactor)
1161 {
1162     // Set the current zoom factor.
1163     currentZoomFactor = zoomFactor;
1164
1165     // Update the zoom factor action text, formatting the double with 2 decimal places.
1166     zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
1167 }
1168
1169 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
1170 {
1171     // Update the search engine label.
1172     searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
1173 }
1174
1175 void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl)
1176 {
1177     // Update the URL line edit if it does not have focus.
1178     if (!urlLineEditPointer->hasFocus())
1179     {
1180         // Get the new URL string.
1181         QString newUrlString = newUrl.toString();
1182
1183         // Update the URL line edit.
1184         urlLineEditPointer->setText(newUrlString);
1185
1186         // Set the focus if the new URL is blank.
1187         if (newUrlString == QStringLiteral(""))
1188             urlLineEditPointer->setFocus();
1189     }
1190
1191     // Store the current URL.
1192     currentUrl = newUrl;
1193 }
1194
1195 void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
1196 {
1197     // Update the user agent label.
1198     userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));
1199 }
1200
1201 void BrowserWindow::updateWindowTitle(const QString &title)
1202 {
1203     // Update the window title.
1204     setWindowTitle(title);
1205 }