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