]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blob - src/windows/BrowserWindow.cpp
a29b5037c83af5ae69dcfd9f146228fc96f0e251
[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/DomainSettingsDialog.h"
26 #include "helpers/SearchEngineHelper.h"
27 #include "helpers/UserAgentHelper.h"
28
29 // KDE Frameworks headers.
30 #include <KActionCollection>
31 #include <KToolBar>
32
33 // Qt toolkit headers.
34 #include <QInputDialog>
35 #include <QStatusBar>
36
37 BrowserWindow::BrowserWindow() : KXmlGuiWindow()
38 {
39     // Instantiate the main view pointer.
40     browserViewPointer = new BrowserView(this);
41
42     // Set the main view as the central widget.
43     setCentralWidget(browserViewPointer);
44
45     // Get a handle for the action collection.
46     KActionCollection *actionCollectionPointer = this->actionCollection();
47
48     // Add the standard actions.
49     QAction *backActionPointer = KStandardAction::back(this, SLOT(back()), actionCollectionPointer);
50     QAction *forwardActionPointer = KStandardAction::forward(this, SLOT(forward()), actionCollectionPointer);
51     KStandardAction::home(this, SLOT(home()), actionCollectionPointer);
52     KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer);
53     KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer);
54     KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollectionPointer);
55     KStandardAction::redisplay(this, SLOT(refresh()), actionCollectionPointer);
56
57     // Add the custom actions.
58     userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_privacy_browser"));
59     userAgentWebEngineDefaultActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_webengine_default"));
60     userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_linux"));
61     userAgentChromiumLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chromium_linux"));
62     userAgentFirefoxWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_windows"));
63     userAgentChromeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chrome_windows"));
64     userAgentEdgeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_edge_windows"));
65     userAgentSafariMacosActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_safari_macos"));
66     userAgentCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_custom"));
67     zoomFactorActionPointer = actionCollectionPointer->addAction(QStringLiteral("zoom_factor"));
68     searchEngineMojeekActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_mojeek"));
69     searchEngineMonoclesActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_monocles"));
70     searchEngineMetagerActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_metager"));
71     searchEngineGoogleActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_google"));
72     searchEngineBingActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_bing"));
73     searchEngineYahooActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_yahoo"));
74     searchEngineCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_custom"));
75     javaScriptActionPointer = actionCollectionPointer->addAction(QStringLiteral("javascript"));
76     localStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("local_storage"));
77     domainSettingsActionPointer = actionCollectionPointer->addAction(QStringLiteral("domain_settings"));
78
79     // Create the action groups
80     QActionGroup *userAgentActionGroupPointer = new QActionGroup(this);
81     QActionGroup *searchEngineActionGroupPointer = new QActionGroup(this);
82
83     // Add the actions to the groups.
84     userAgentActionGroupPointer->addAction(userAgentPrivacyBrowserActionPointer);
85     userAgentActionGroupPointer->addAction(userAgentWebEngineDefaultActionPointer);
86     userAgentActionGroupPointer->addAction(userAgentFirefoxLinuxActionPointer);
87     userAgentActionGroupPointer->addAction(userAgentChromiumLinuxActionPointer);
88     userAgentActionGroupPointer->addAction(userAgentFirefoxWindowsActionPointer);
89     userAgentActionGroupPointer->addAction(userAgentChromeWindowsActionPointer);
90     userAgentActionGroupPointer->addAction(userAgentEdgeWindowsActionPointer);
91     userAgentActionGroupPointer->addAction(userAgentSafariMacosActionPointer);
92     userAgentActionGroupPointer->addAction(userAgentCustomActionPointer);
93     searchEngineActionGroupPointer->addAction(searchEngineMojeekActionPointer);
94     searchEngineActionGroupPointer->addAction(searchEngineMonoclesActionPointer);
95     searchEngineActionGroupPointer->addAction(searchEngineMetagerActionPointer);
96     searchEngineActionGroupPointer->addAction(searchEngineGoogleActionPointer);
97     searchEngineActionGroupPointer->addAction(searchEngineBingActionPointer);
98     searchEngineActionGroupPointer->addAction(searchEngineYahooActionPointer);
99     searchEngineActionGroupPointer->addAction(searchEngineCustomActionPointer);
100
101     // Set some actions to be checkable.
102     userAgentPrivacyBrowserActionPointer->setCheckable(true);
103     userAgentWebEngineDefaultActionPointer->setCheckable(true);
104     userAgentFirefoxLinuxActionPointer->setCheckable(true);
105     userAgentChromiumLinuxActionPointer->setCheckable(true);
106     userAgentFirefoxWindowsActionPointer->setCheckable(true);
107     userAgentChromeWindowsActionPointer->setCheckable(true);
108     userAgentEdgeWindowsActionPointer->setCheckable(true);
109     userAgentSafariMacosActionPointer->setCheckable(true);
110     userAgentCustomActionPointer->setCheckable(true);
111     searchEngineMojeekActionPointer->setCheckable(true);
112     searchEngineMonoclesActionPointer->setCheckable(true);
113     searchEngineMetagerActionPointer->setCheckable(true);
114     searchEngineGoogleActionPointer->setCheckable(true);
115     searchEngineBingActionPointer->setCheckable(true);
116     searchEngineYahooActionPointer->setCheckable(true);
117     searchEngineCustomActionPointer->setCheckable(true);
118
119     // Set the non-mutable action text.
120     userAgentPrivacyBrowserActionPointer->setText(UserAgentHelper::PRIVACY_BROWSER_TRANSLATED);
121     userAgentWebEngineDefaultActionPointer->setText(UserAgentHelper::WEB_ENGINE_DEFAULT_TRANSLATED);
122     userAgentFirefoxLinuxActionPointer->setText(UserAgentHelper::FIREFOX_LINUX_TRANSLATED);
123     userAgentChromiumLinuxActionPointer->setText(UserAgentHelper::CHROMIUM_LINUX_TRANSLATED);
124     userAgentFirefoxWindowsActionPointer->setText(UserAgentHelper::FIREFOX_WINDOWS_TRANSLATED);
125     userAgentChromeWindowsActionPointer->setText(UserAgentHelper::CHROME_WINDOWS_TRANSLATED);
126     userAgentEdgeWindowsActionPointer->setText(UserAgentHelper::EDGE_WINDOWS_TRANSLATED);
127     userAgentSafariMacosActionPointer->setText(UserAgentHelper::SAFARI_MACOS_TRANSLATED);
128     searchEngineMojeekActionPointer->setText(i18nc("Search engine", "Mojeek"));
129     searchEngineMonoclesActionPointer->setText(i18nc("Search engine", "Monocles"));
130     searchEngineMetagerActionPointer->setText(i18nc("Search engine", "MetaGer"));
131     searchEngineGoogleActionPointer->setText(i18nc("Search engine", "Google"));
132     searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing"));
133     searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo"));
134     javaScriptActionPointer->setText(i18nc("JavaScript button", "JavaScript"));
135     localStorageActionPointer->setText(i18nc("Local Storage Button", "Local Storage"));
136     domainSettingsActionPointer->setText(i18nc("Domain Settings button", "Domain Settings"));
137
138     // Set the action icons.
139     userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
140     userAgentWebEngineDefaultActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
141     userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
142     userAgentChromiumLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
143     userAgentFirefoxWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
144     userAgentChromeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
145     userAgentEdgeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
146     userAgentSafariMacosActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
147     userAgentCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
148     searchEngineMojeekActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
149     searchEngineMonoclesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
150     searchEngineMetagerActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
151     searchEngineGoogleActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-google")));
152     searchEngineBingActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
153     searchEngineYahooActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-yahoo")));
154     searchEngineCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
155     zoomFactorActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("zoom")));
156     domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("settings-configure")));
157
158     // Update the on-the-fly menus.
159     connect(browserViewPointer, SIGNAL(updateUserAgentActions(QString)), this, SLOT(updateUserAgentActions(QString)));
160     connect(browserViewPointer, SIGNAL(updateZoomFactorAction(double)), this, SLOT(updateZoomFactorAction(double)));
161     connect(browserViewPointer, SIGNAL(updateSearchEngineActions(QString)), this, SLOT(updateSearchEngineActions(QString)));
162
163     // Apply the on-the-fly settings when selected.
164     connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
165     connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
166
167     // Display dialogs.
168     connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
169
170     // Connect the URL toolbar actions.
171     connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript()));
172     connect(localStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleLocalStorage()));
173     connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(openDomainSettings()));
174
175     // Update the URL toolbar actions.
176     connect(browserViewPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
177     connect(browserViewPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool)));
178     connect(browserViewPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool)));
179     connect(browserViewPointer, SIGNAL(updateLocalStorageAction(bool)), this, SLOT(updateLocalStorageAction(bool)));
180
181     // Setup the GUI based on the browser_ui.rc file.
182     setupGUI(StandardWindowOption::Default, ("browser_ui.rc"));
183
184     // Get a handle for the URL toolbar.
185     KToolBar *urlToolBarPointer = toolBar(QStringLiteral("url_toolbar"));
186
187     // Create a URL line edit.
188     urlLineEditPointer = new KLineEdit();
189
190     // Add an edit or add domain settings action to the URL line edit.
191     QAction *addOrEditDomainSettingsActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme("settings-configure"), QLineEdit::TrailingPosition);
192
193     // Add or edit the current domain settings.
194     connect(addOrEditDomainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(addOrEditDomainSettings()));
195
196     // Populate the URL toolbar.
197     urlToolBarPointer->insertWidget(javaScriptActionPointer, urlLineEditPointer);
198
199     // Load a new URL from the URL line edit.
200     connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
201
202     // Update the URL line edit on page loads.
203     connect(browserViewPointer, SIGNAL(updateUrlLineEdit(QUrl)), this, SLOT(updateUrlLineEdit(QUrl)));
204
205     // Get a handle for the status bar.
206     QStatusBar *statusBarPointer = statusBar();
207
208     // Create a progress bar.
209     progressBarPointer = new QProgressBar();
210
211     // Add the progress bar to to the status bar.
212     statusBarPointer->addPermanentWidget(progressBarPointer);
213
214     // Update the status bar with the URL when a link is hovered.
215     connect(browserViewPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
216
217     // Update the progress bar.
218     connect(browserViewPointer, SIGNAL(showProgressBar(const int)), this, SLOT(showProgressBar(const int)));
219     connect(browserViewPointer, SIGNAL(hideProgressBar()), progressBarPointer, SLOT(hide()));
220
221     // Get the URL line edit palettes.
222     noDomainSettingsPalette = urlLineEditPointer->palette();
223     domainSettingsPalette = urlLineEditPointer->palette();
224
225     // Modify the domain settings palette.
226     domainSettingsPalette.setColor(QPalette::Base, QColor("#C8E6C9"));
227
228     // Update the applied palette.
229     connect(browserViewPointer, SIGNAL(updateDomainSettingsIndicator(bool, QString)), this, SLOT(updateDomainSettingsIndicator(bool, QString)));
230
231     // Load the initial website.
232     browserViewPointer->loadInitialWebsite();
233 }
234
235 void BrowserWindow::addOrEditDomainSettings() const
236 {
237     // Remove the focus from the URL line edit.
238     urlLineEditPointer->clearFocus();
239
240     // Create the domain settings dialog pointer.
241     DomainSettingsDialog *domainSettingsDialogPointer;
242
243     // Run the commands according to the current domain settings status.
244     if (currentDomainSettingsDomain == "")  // Domain settings are not currently applied.
245     {
246         // Instruct the domain settings dialog to add a new domain.
247         domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::ADD_DOMAIN, currentUrl.host());
248     }
249     else  // Domain settings are currently applied.
250     {
251         // Instruct the domain settings dialog to edit the current domain.
252         domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsDomain);
253     }
254
255     // Set the dialog window title.
256     domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
257
258     // Set the modality.
259     domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
260
261     // Show the dialog.
262     domainSettingsDialogPointer->show();
263
264     // Reload the tabs when domain settings are updated.
265     connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
266 }
267
268 void BrowserWindow::back() const
269 {
270     // Remove the focus from the URL line edit.
271     urlLineEditPointer->clearFocus();
272
273     // Go back.
274     browserViewPointer->back();
275 }
276
277 void BrowserWindow::fileNew() const
278 {
279     // Display a new instance of Privacy Browser.
280     (new BrowserWindow)->show();
281 }
282
283 void BrowserWindow::forward() const
284 {
285     // Remove the focus from the URL line edit.
286     urlLineEditPointer->clearFocus();
287
288     // Go forward.
289     browserViewPointer->forward();
290 }
291
292 void BrowserWindow::getZoomFactorFromUser()
293 {
294     // Create an OK flag.
295     bool okClicked;
296
297     // 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.
298     double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"),
299                                                    i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
300                                                    currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
301
302     // Update the zoom factor if the user clicked OK.
303     if (okClicked)
304     {
305         // Update the current zoom factor.
306         currentZoomFactor = newZoomFactor;
307
308         // Set the new zoom factor.
309         browserViewPointer->applyOnTheFlyZoomFactor(newZoomFactor);
310
311         // Update the on-the-fly action text.
312         updateZoomFactorAction(newZoomFactor);
313     }
314 }
315
316 void BrowserWindow::home() const
317 {
318     // Remove the focus from the URL line edit.
319     urlLineEditPointer->clearFocus();
320
321     // Go home.
322     browserViewPointer->home();
323 }
324
325 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
326 {
327     // Remove the focus from the URL line edit.
328     urlLineEditPointer->clearFocus();
329
330     // Load the URL.
331     browserViewPointer->loadUrlFromLineEdit(url);
332 }
333
334 void BrowserWindow::openDomainSettings() const
335 {
336     // Remove the focus from the URL line edit.
337     urlLineEditPointer->clearFocus();
338
339     // Instantiate the domain settings dialog.
340     DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
341
342     // Set the dialog window title.
343     domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
344
345     // Set the modality.
346     domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
347
348     // Show the dialog.
349     domainSettingsDialogPointer->show();
350
351     // Reload the tabs when domain settings are updated.
352     connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
353 }
354
355 void BrowserWindow::refresh() const
356 {
357     // Remove the focus from the URL line edit.
358     urlLineEditPointer->clearFocus();
359
360     // Refresh the web page.
361     browserViewPointer->refresh();
362 }
363
364 void BrowserWindow::showProgressBar(const int &progress) const
365 {
366     // Set the progress bar value.
367     progressBarPointer->setValue(progress);
368
369     // Show the progress bar.
370     progressBarPointer->show();
371 }
372
373 QSize BrowserWindow::sizeHint() const
374 {
375     // Return the default window size.
376     return QSize(1500, 1200);
377 }
378
379 void BrowserWindow::settingsConfigure()
380 {
381     // Check to make sure the dialog box isn't already displayed.
382     if (KConfigDialog::exists(QStringLiteral("settings")))
383     {
384         // Show the existing config dialog if it is hidden.
385         configDialogPointer->show();
386
387         // Raise the existing config dialog if it is below other windows.
388         configDialogPointer->raise();
389
390         // Restore the existing config dialog if it has been minimized.
391         if (configDialogPointer->isMinimized()) {
392             configDialogPointer->showNormal();
393         }
394
395         // Activate the existing config dialog, which brings its virtual desktop into focus.
396         configDialogPointer->activateWindow();
397     }
398     else
399     {
400         // Create the settings widgets.
401         QWidget *privacySettingsWidgetPointer = new QWidget;
402         QWidget *generalSettingsWidgetPointer = new QWidget;
403
404         // Instantiate the settings UI.
405         Ui::PrivacySettings privacySettingsUi;
406         Ui::GeneralSettings generalSettingsUi;
407
408         // Setup the UI to display the settings widgets.
409         privacySettingsUi.setupUi(privacySettingsWidgetPointer);
410         generalSettingsUi.setupUi(generalSettingsWidgetPointer);
411
412         // Get handles for the widgets.
413         QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
414         userAgentLabelPointer = privacySettingsUi.userAgentLabel;
415         QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
416         searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
417
418         // Populate the combo box labels.
419         updateUserAgentLabel(userAgentComboBoxPointer->currentText());
420         updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
421
422         // Update the labels when the combo boxes change.
423         connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
424         connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
425
426         // Instantiate a settings config dialog from the settings.kcfg file.
427         configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
428
429         // Add the settings widgets as config dialog pages.
430         configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("@title:tab", "Privacy"), QStringLiteral("privacy-browser"));
431         configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
432
433         // Delete the config dialog when it is closed.
434         configDialogPointer->setAttribute(Qt::WA_DeleteOnClose);
435
436         // Make it so.
437         configDialogPointer->show();
438
439         // TODO.  KConfigDialog does not respect expanding size policies.  <https://redmine.stoutner.com/issues/823>
440         //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
441         //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
442         //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
443         //configDialogPointer->adjustSize();
444
445         // Expand the config dialog.
446         configDialogPointer->resize(1000, 500);
447
448         // Apply the settings when they are updated.
449         connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyApplicationSettings()));
450         connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
451     }
452 }
453
454 void BrowserWindow::toggleJavaScript() const
455 {
456     // Remove the focus from the URL line edit.
457     urlLineEditPointer->clearFocus();
458
459     // Toggle JavaScript.
460     browserViewPointer->toggleJavaScript();
461 }
462
463 void BrowserWindow::toggleLocalStorage() const
464 {
465     // Remove the focus from the URL line edit.
466     urlLineEditPointer->clearFocus();
467
468     // Toggle JavaScript.
469     browserViewPointer->toggleLocalStorage();
470 }
471
472 void BrowserWindow::updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain)
473 {
474     // Set the domain palette according to the status.
475     if (status) urlLineEditPointer->setPalette(domainSettingsPalette);
476     else urlLineEditPointer->setPalette(noDomainSettingsPalette);
477
478     // Store the domain.
479     currentDomainSettingsDomain = domainSettingsDomain;
480 }
481
482 void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) const
483 {
484     // Set the icon according to the status.
485     if (isEnabled) javaScriptActionPointer->setIcon(QIcon(":/icons/javascript-warning"));
486     else javaScriptActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
487 }
488
489 void BrowserWindow::updateLocalStorageAction(const bool &isEnabled) const
490 {
491     // Set the icon according to the status.
492     if (isEnabled) localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota-low"));
493     else localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota"));
494 }
495
496 void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const
497 {
498     // Initialize the custom search engine flag.
499     bool customSearchEngine = false;
500
501     if (searchEngine == "Mojeek")  // Mojeek.
502     {
503         searchEngineMojeekActionPointer->setChecked(true);
504     }
505     else if (searchEngine == "Monocles")  // Monocles.
506     {
507         searchEngineMonoclesActionPointer->setChecked(true);
508     }
509     else if (searchEngine == "MetaGer")  // MetaGer.
510     {
511         searchEngineMetagerActionPointer->setChecked(true);
512     }
513     else if (searchEngine == "Google")  // Google.
514     {
515         searchEngineGoogleActionPointer->setChecked(true);
516     }
517     else if (searchEngine == "Bing")  // Bing.
518     {
519         searchEngineBingActionPointer->setChecked(true);
520     }
521     else if (searchEngine == "Yahoo")  // Yahoo.
522     {
523         searchEngineYahooActionPointer->setChecked(true);
524     }
525     else  // Custom search engine.
526     {
527         // Check the user agent.
528         searchEngineCustomActionPointer->setChecked(true);
529
530         // Set the custom search engine flag.
531         customSearchEngine = true;
532     }
533
534     // Format the custom search engine.
535     if (customSearchEngine)
536     {
537         // Enable the custom search engine.
538         searchEngineCustomActionPointer->setEnabled(true);
539
540         // Set the custom search engine text.
541         searchEngineCustomActionPointer->setText(searchEngine);
542     }
543     else
544     {
545         // Disable the custom search engine.
546         searchEngineCustomActionPointer->setEnabled(false);
547
548         // Reset the custom search engine text.
549         searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
550     }
551 }
552
553 void BrowserWindow::updateUserAgentActions(const QString &userAgent) const
554 {
555     // Initialize the custom user agent flag.
556     bool customUserAgent = false;
557
558     // Check the indicated on-the-fly user agent.
559     if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) userAgentPrivacyBrowserActionPointer->setChecked(true);  // Privacy Browser.
560     else if (userAgent == BrowserView::webEngineDefaultUserAgent) userAgentWebEngineDefaultActionPointer->setChecked(true);  // WebEngine default.
561     else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) userAgentFirefoxLinuxActionPointer->setChecked(true);  // Firefox Linux.
562     else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) userAgentChromiumLinuxActionPointer->setChecked(true);  // Chromium Linux.
563     else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) userAgentFirefoxWindowsActionPointer->setChecked(true);  // Firefox Windows.
564     else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) userAgentChromeWindowsActionPointer->setChecked(true);  // Chrome Windows.
565     else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) userAgentEdgeWindowsActionPointer->setChecked(true);  // Edge Windows.
566     else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) userAgentSafariMacosActionPointer->setChecked(true);  // Safara macOS.
567     else  // Custom user agent.
568     {
569         // Check the user agent.
570         userAgentCustomActionPointer->setChecked(true);
571
572         // Set the custom user agent flag.
573         customUserAgent = true;
574     }
575
576
577     // Format the custom user agent.
578     if (customUserAgent)
579     {
580         // Enable the custom user agent.
581         userAgentCustomActionPointer->setEnabled(true);
582
583         // Set the custom user agent text.
584         userAgentCustomActionPointer->setText(userAgent);
585     }
586     else
587     {
588         // Disable the custom user agent.
589         userAgentCustomActionPointer->setEnabled(false);
590
591         // Reset the custom user agent text.
592         userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
593     }
594 }
595
596 void BrowserWindow::updateZoomFactorAction(const double &zoomFactor)
597 {
598     // Set the current zoom factor.
599     currentZoomFactor = zoomFactor;
600
601     // Update the zoom factor action text, formatting the double with 2 decimal places.
602     zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
603 }
604
605 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
606 {
607     // Update the search engine label.
608     searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
609 }
610
611 void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl)
612 {
613     // Update the URL line edit if it does not have focus.
614     if (!urlLineEditPointer->hasFocus())
615     {
616         // Update the URL line edit.
617         urlLineEditPointer->setText(newUrl.toString());
618     }
619
620     // Store the current URL.
621     currentUrl = newUrl;
622 }
623
624 void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
625 {
626     // Update the user agent label.
627     userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));
628 }