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