2 * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
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.
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.
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/>.
20 // Application headers.
21 #include "BrowserWindow.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"
30 // KDE Frameworks headers.
31 #include <KActionCollection>
34 // Qt toolkit headers.
35 #include <QInputDialog>
36 #include <QNetworkCookie>
39 BrowserWindow::BrowserWindow() : KXmlGuiWindow()
41 // Instantiate the main view pointer.
42 browserViewPointer = new BrowserView(this);
44 // Set the main view as the central widget.
45 setCentralWidget(browserViewPointer);
47 // Get a handle for the action collection.
48 KActionCollection *actionCollectionPointer = this->actionCollection();
50 // Add the standard actions.
51 QAction *backActionPointer = KStandardAction::back(this, SLOT(back()), actionCollectionPointer);
52 QAction *forwardActionPointer = KStandardAction::forward(this, SLOT(forward()), actionCollectionPointer);
53 KStandardAction::home(this, SLOT(home()), actionCollectionPointer);
54 KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer);
55 KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer);
56 KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollectionPointer);
57 KStandardAction::redisplay(this, SLOT(refresh()), actionCollectionPointer);
59 // Add the custom actions.
60 userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_privacy_browser"));
61 userAgentWebEngineDefaultActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_webengine_default"));
62 userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_linux"));
63 userAgentChromiumLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chromium_linux"));
64 userAgentFirefoxWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_windows"));
65 userAgentChromeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chrome_windows"));
66 userAgentEdgeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_edge_windows"));
67 userAgentSafariMacosActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_safari_macos"));
68 userAgentCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_custom"));
69 zoomFactorActionPointer = actionCollectionPointer->addAction(QStringLiteral("zoom_factor"));
70 searchEngineMojeekActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_mojeek"));
71 searchEngineMonoclesActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_monocles"));
72 searchEngineMetagerActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_metager"));
73 searchEngineGoogleActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_google"));
74 searchEngineBingActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_bing"));
75 searchEngineYahooActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_yahoo"));
76 searchEngineCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_custom"));
77 QAction *domainSettingsActionPointer = actionCollectionPointer->addAction(QStringLiteral("domain_settings"));
78 QAction *cookiesActionPointer = actionCollectionPointer->addAction(QStringLiteral("cookies"));
79 javaScriptActionPointer = actionCollectionPointer->addAction(QStringLiteral("javascript"));
80 localStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("local_storage"));
82 // Create the action groups
83 QActionGroup *userAgentActionGroupPointer = new QActionGroup(this);
84 QActionGroup *searchEngineActionGroupPointer = new QActionGroup(this);
86 // Add the actions to the groups.
87 userAgentActionGroupPointer->addAction(userAgentPrivacyBrowserActionPointer);
88 userAgentActionGroupPointer->addAction(userAgentWebEngineDefaultActionPointer);
89 userAgentActionGroupPointer->addAction(userAgentFirefoxLinuxActionPointer);
90 userAgentActionGroupPointer->addAction(userAgentChromiumLinuxActionPointer);
91 userAgentActionGroupPointer->addAction(userAgentFirefoxWindowsActionPointer);
92 userAgentActionGroupPointer->addAction(userAgentChromeWindowsActionPointer);
93 userAgentActionGroupPointer->addAction(userAgentEdgeWindowsActionPointer);
94 userAgentActionGroupPointer->addAction(userAgentSafariMacosActionPointer);
95 userAgentActionGroupPointer->addAction(userAgentCustomActionPointer);
96 searchEngineActionGroupPointer->addAction(searchEngineMojeekActionPointer);
97 searchEngineActionGroupPointer->addAction(searchEngineMonoclesActionPointer);
98 searchEngineActionGroupPointer->addAction(searchEngineMetagerActionPointer);
99 searchEngineActionGroupPointer->addAction(searchEngineGoogleActionPointer);
100 searchEngineActionGroupPointer->addAction(searchEngineBingActionPointer);
101 searchEngineActionGroupPointer->addAction(searchEngineYahooActionPointer);
102 searchEngineActionGroupPointer->addAction(searchEngineCustomActionPointer);
104 // Set some actions to be checkable.
105 userAgentPrivacyBrowserActionPointer->setCheckable(true);
106 userAgentWebEngineDefaultActionPointer->setCheckable(true);
107 userAgentFirefoxLinuxActionPointer->setCheckable(true);
108 userAgentChromiumLinuxActionPointer->setCheckable(true);
109 userAgentFirefoxWindowsActionPointer->setCheckable(true);
110 userAgentChromeWindowsActionPointer->setCheckable(true);
111 userAgentEdgeWindowsActionPointer->setCheckable(true);
112 userAgentSafariMacosActionPointer->setCheckable(true);
113 userAgentCustomActionPointer->setCheckable(true);
114 searchEngineMojeekActionPointer->setCheckable(true);
115 searchEngineMonoclesActionPointer->setCheckable(true);
116 searchEngineMetagerActionPointer->setCheckable(true);
117 searchEngineGoogleActionPointer->setCheckable(true);
118 searchEngineBingActionPointer->setCheckable(true);
119 searchEngineYahooActionPointer->setCheckable(true);
120 searchEngineCustomActionPointer->setCheckable(true);
122 // Set the non-mutable action text.
123 userAgentPrivacyBrowserActionPointer->setText(UserAgentHelper::PRIVACY_BROWSER_TRANSLATED);
124 userAgentWebEngineDefaultActionPointer->setText(UserAgentHelper::WEB_ENGINE_DEFAULT_TRANSLATED);
125 userAgentFirefoxLinuxActionPointer->setText(UserAgentHelper::FIREFOX_LINUX_TRANSLATED);
126 userAgentChromiumLinuxActionPointer->setText(UserAgentHelper::CHROMIUM_LINUX_TRANSLATED);
127 userAgentFirefoxWindowsActionPointer->setText(UserAgentHelper::FIREFOX_WINDOWS_TRANSLATED);
128 userAgentChromeWindowsActionPointer->setText(UserAgentHelper::CHROME_WINDOWS_TRANSLATED);
129 userAgentEdgeWindowsActionPointer->setText(UserAgentHelper::EDGE_WINDOWS_TRANSLATED);
130 userAgentSafariMacosActionPointer->setText(UserAgentHelper::SAFARI_MACOS_TRANSLATED);
131 searchEngineMojeekActionPointer->setText(i18nc("Search engine", "Mojeek"));
132 searchEngineMonoclesActionPointer->setText(i18nc("Search engine", "Monocles"));
133 searchEngineMetagerActionPointer->setText(i18nc("Search engine", "MetaGer"));
134 searchEngineGoogleActionPointer->setText(i18nc("Search engine", "Google"));
135 searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing"));
136 searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo"));
137 domainSettingsActionPointer->setText(i18nc("Domain Settings action", "Domain Settings"));
138 cookiesActionPointer->setText(i18nc("Cookies action", "Cookies"));
139 javaScriptActionPointer->setText(i18nc("JavaScript action", "JavaScript"));
140 localStorageActionPointer->setText(i18nc("Local Storage action", "Local Storage"));
142 // Set the action icons.
143 userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
144 userAgentWebEngineDefaultActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
145 userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
146 userAgentChromiumLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
147 userAgentFirefoxWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
148 userAgentChromeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
149 userAgentEdgeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
150 userAgentSafariMacosActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
151 userAgentCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
152 searchEngineMojeekActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
153 searchEngineMonoclesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
154 searchEngineMetagerActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
155 searchEngineGoogleActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-google")));
156 searchEngineBingActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
157 searchEngineYahooActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-yahoo")));
158 searchEngineCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
159 zoomFactorActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("zoom")));
160 domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("settings-configure")));
161 cookiesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("preferences-web-browser-cookies")));
163 // Update the on-the-fly menus.
164 connect(browserViewPointer, SIGNAL(updateUserAgentActions(QString)), this, SLOT(updateUserAgentActions(QString)));
165 connect(browserViewPointer, SIGNAL(updateZoomFactorAction(double)), this, SLOT(updateZoomFactorAction(double)));
166 connect(browserViewPointer, SIGNAL(updateSearchEngineActions(QString)), this, SLOT(updateSearchEngineActions(QString)));
168 // Apply the on-the-fly settings when selected.
169 connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
170 connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
173 connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
174 connect(cookiesActionPointer, SIGNAL(triggered()), this, SLOT(openCookiesDialog()));
175 connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(openDomainSettings()));
177 // Connect the URL toolbar actions.
178 connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript()));
179 connect(localStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleLocalStorage()));
181 // Update the URL toolbar actions.
182 connect(browserViewPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
183 connect(browserViewPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool)));
184 connect(browserViewPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool)));
185 connect(browserViewPointer, SIGNAL(updateLocalStorageAction(bool)), this, SLOT(updateLocalStorageAction(bool)));
187 // Setup the GUI based on the browser_ui.rc file.
188 setupGUI(StandardWindowOption::Default, ("browser_ui.rc"));
190 // Get a handle for the URL toolbar.
191 KToolBar *urlToolBarPointer = toolBar(QStringLiteral("url_toolbar"));
193 // Create a URL line edit.
194 urlLineEditPointer = new KLineEdit();
196 // Add an edit or add domain settings action to the URL line edit.
197 QAction *addOrEditDomainSettingsActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme("settings-configure"), QLineEdit::TrailingPosition);
199 // Add or edit the current domain settings.
200 connect(addOrEditDomainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(addOrEditDomainSettings()));
202 // Populate the URL toolbar.
203 urlToolBarPointer->insertWidget(javaScriptActionPointer, urlLineEditPointer);
205 // Load a new URL from the URL line edit.
206 connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
208 // Update the URL line edit on page loads.
209 connect(browserViewPointer, SIGNAL(updateUrlLineEdit(QUrl)), this, SLOT(updateUrlLineEdit(QUrl)));
211 // Get a handle for the status bar.
212 QStatusBar *statusBarPointer = statusBar();
214 // Create a progress bar.
215 progressBarPointer = new QProgressBar();
217 // Add the progress bar to to the status bar.
218 statusBarPointer->addPermanentWidget(progressBarPointer);
220 // Update the status bar with the URL when a link is hovered.
221 connect(browserViewPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
223 // Update the progress bar.
224 connect(browserViewPointer, SIGNAL(showProgressBar(const int)), this, SLOT(showProgressBar(const int)));
225 connect(browserViewPointer, SIGNAL(hideProgressBar()), progressBarPointer, SLOT(hide()));
227 // Clear the URL line edit focus when requested.
228 connect(browserViewPointer, SIGNAL(clearUrlLineEditFocus()), this, SLOT(clearUrlLineEditFocus()));
230 // Get the URL line edit palettes.
231 noDomainSettingsPalette = urlLineEditPointer->palette();
232 domainSettingsPalette = urlLineEditPointer->palette();
234 // Modify the domain settings palette.
235 domainSettingsPalette.setColor(QPalette::Base, QColor("#C8E6C9"));
237 // Update the applied palette.
238 connect(browserViewPointer, SIGNAL(updateDomainSettingsIndicator(bool, QString)), this, SLOT(updateDomainSettingsIndicator(bool, QString)));
240 // Initialize the cookie list.
241 cookieListPointer = new QList<QNetworkCookie>;
243 // Add new cookies to the list.
244 connect(browserViewPointer, SIGNAL(addCookie(QNetworkCookie)), this, SLOT(addCookieToList(QNetworkCookie)));
246 // Load the initial website.
247 browserViewPointer->loadInitialWebsite();
250 void BrowserWindow::addCookieToList(const QNetworkCookie &newCookie) const
252 // Check to see if the list already contains a cookie with this ID.
253 for (QNetworkCookie existingCookie : *cookieListPointer)
255 // Remove the old version of the cookie.
256 if (existingCookie.hasSameIdentifier(newCookie)) cookieListPointer->removeOne(existingCookie);
259 // Add the new cookie to the list.
260 cookieListPointer->append(newCookie);
263 void BrowserWindow::addOrEditDomainSettings() const
265 // Remove the focus from the URL line edit.
266 urlLineEditPointer->clearFocus();
268 // Create the domain settings dialog pointer.
269 DomainSettingsDialog *domainSettingsDialogPointer;
271 // Run the commands according to the current domain settings status.
272 if (currentDomainSettingsDomain == "") // Domain settings are not currently applied.
274 // Instruct the domain settings dialog to add a new domain.
275 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::ADD_DOMAIN, currentUrl.host());
277 else // Domain settings are currently applied.
279 // Instruct the domain settings dialog to edit the current domain.
280 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsDomain);
283 // Set the dialog window title.
284 domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
287 domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
290 domainSettingsDialogPointer->show();
292 // Reload the tabs when domain settings are updated.
293 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
296 void BrowserWindow::back() const
298 // Remove the focus from the URL line edit.
299 urlLineEditPointer->clearFocus();
302 browserViewPointer->back();
305 void BrowserWindow::clearUrlLineEditFocus() const
307 // Remove the focus from the URL line edit.
308 urlLineEditPointer->clearFocus();
311 void BrowserWindow::fileNew() const
313 // Display a new instance of Privacy Browser.
314 (new BrowserWindow)->show();
317 void BrowserWindow::forward() const
319 // Remove the focus from the URL line edit.
320 urlLineEditPointer->clearFocus();
323 browserViewPointer->forward();
326 void BrowserWindow::getZoomFactorFromUser()
328 // Create an OK flag.
331 // 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.
332 double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"),
333 i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
334 currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
336 // Update the zoom factor if the user clicked OK.
339 // Update the current zoom factor.
340 currentZoomFactor = newZoomFactor;
342 // Set the new zoom factor.
343 browserViewPointer->applyOnTheFlyZoomFactor(newZoomFactor);
345 // Update the on-the-fly action text.
346 updateZoomFactorAction(newZoomFactor);
350 void BrowserWindow::home() const
352 // Remove the focus from the URL line edit.
353 urlLineEditPointer->clearFocus();
356 browserViewPointer->home();
359 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
361 // Remove the focus from the URL line edit.
362 urlLineEditPointer->clearFocus();
365 browserViewPointer->loadUrlFromLineEdit(url);
368 void BrowserWindow::openCookiesDialog()
370 // Remove the focus from the URL line edit.
371 urlLineEditPointer->clearFocus();
373 // Instantiate the cookie settings dialog.
374 CookiesDialog *cookiesDialogPointer = new CookiesDialog(cookieListPointer);
377 cookiesDialogPointer->show();
379 // Connect the dialog signals.
380 connect(cookiesDialogPointer, SIGNAL(addCookie(QNetworkCookie)), browserViewPointer, SLOT(addCookieToStore(QNetworkCookie)));
381 connect(cookiesDialogPointer, SIGNAL(deleteAllCookies()), browserViewPointer, SLOT(deleteAllCookies()));
384 void BrowserWindow::openDomainSettings() const
386 // Remove the focus from the URL line edit.
387 urlLineEditPointer->clearFocus();
389 // Instantiate the domain settings dialog.
390 DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
393 domainSettingsDialogPointer->show();
395 // Reload the tabs when domain settings are updated.
396 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
399 void BrowserWindow::refresh() const
401 // Remove the focus from the URL line edit.
402 urlLineEditPointer->clearFocus();
404 // Refresh the web page.
405 browserViewPointer->refresh();
408 void BrowserWindow::showProgressBar(const int &progress) const
410 // Set the progress bar value.
411 progressBarPointer->setValue(progress);
413 // Show the progress bar.
414 progressBarPointer->show();
417 QSize BrowserWindow::sizeHint() const
419 // Return the default window size.
420 return QSize(1500, 1200);
423 void BrowserWindow::settingsConfigure()
425 // Check to make sure the dialog box isn't already displayed.
426 if (KConfigDialog::exists(QStringLiteral("settings")))
428 // Show the existing config dialog if it is hidden.
429 configDialogPointer->show();
431 // Raise the existing config dialog if it is below other windows.
432 configDialogPointer->raise();
434 // Restore the existing config dialog if it has been minimized.
435 if (configDialogPointer->isMinimized()) {
436 configDialogPointer->showNormal();
439 // Activate the existing config dialog, which brings its virtual desktop into focus.
440 configDialogPointer->activateWindow();
444 // Create the settings widgets.
445 QWidget *privacySettingsWidgetPointer = new QWidget;
446 QWidget *generalSettingsWidgetPointer = new QWidget;
448 // Instantiate the settings UI.
449 Ui::PrivacySettings privacySettingsUi;
450 Ui::GeneralSettings generalSettingsUi;
452 // Setup the UI to display the settings widgets.
453 privacySettingsUi.setupUi(privacySettingsWidgetPointer);
454 generalSettingsUi.setupUi(generalSettingsWidgetPointer);
456 // Get handles for the widgets.
457 QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
458 userAgentLabelPointer = privacySettingsUi.userAgentLabel;
459 QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
460 searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
462 // Populate the combo box labels.
463 updateUserAgentLabel(userAgentComboBoxPointer->currentText());
464 updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
466 // Update the labels when the combo boxes change.
467 connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
468 connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
470 // Instantiate a settings config dialog from the settings.kcfg file.
471 configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
473 // Add the settings widgets as config dialog pages.
474 configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("@title:tab", "Privacy"), QStringLiteral("privacy-browser"));
475 configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
477 // Delete the config dialog when it is closed.
478 configDialogPointer->setAttribute(Qt::WA_DeleteOnClose);
481 configDialogPointer->show();
483 // TODO. KConfigDialog does not respect expanding size policies. <https://redmine.stoutner.com/issues/823>
484 //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
485 //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
486 //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
487 //configDialogPointer->adjustSize();
489 // Expand the config dialog.
490 configDialogPointer->resize(1000, 500);
492 // Apply the settings when they are updated.
493 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyApplicationSettings()));
494 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
498 void BrowserWindow::toggleJavaScript() const
500 // Remove the focus from the URL line edit.
501 urlLineEditPointer->clearFocus();
503 // Toggle JavaScript.
504 browserViewPointer->toggleJavaScript();
507 void BrowserWindow::toggleLocalStorage() const
509 // Remove the focus from the URL line edit.
510 urlLineEditPointer->clearFocus();
512 // Toggle JavaScript.
513 browserViewPointer->toggleLocalStorage();
516 void BrowserWindow::updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain)
518 // Set the domain palette according to the status.
519 if (status) urlLineEditPointer->setPalette(domainSettingsPalette);
520 else urlLineEditPointer->setPalette(noDomainSettingsPalette);
523 currentDomainSettingsDomain = domainSettingsDomain;
526 void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) const
528 // Set the icon according to the status.
529 if (isEnabled) javaScriptActionPointer->setIcon(QIcon(":/icons/javascript-warning"));
530 else javaScriptActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
533 void BrowserWindow::updateLocalStorageAction(const bool &isEnabled) const
535 // Set the icon according to the status.
536 if (isEnabled) localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota-low"));
537 else localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota"));
540 void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const
542 // Initialize the custom search engine flag.
543 bool customSearchEngine = false;
545 if (searchEngine == "Mojeek") // Mojeek.
547 searchEngineMojeekActionPointer->setChecked(true);
549 else if (searchEngine == "Monocles") // Monocles.
551 searchEngineMonoclesActionPointer->setChecked(true);
553 else if (searchEngine == "MetaGer") // MetaGer.
555 searchEngineMetagerActionPointer->setChecked(true);
557 else if (searchEngine == "Google") // Google.
559 searchEngineGoogleActionPointer->setChecked(true);
561 else if (searchEngine == "Bing") // Bing.
563 searchEngineBingActionPointer->setChecked(true);
565 else if (searchEngine == "Yahoo") // Yahoo.
567 searchEngineYahooActionPointer->setChecked(true);
569 else // Custom search engine.
571 // Check the user agent.
572 searchEngineCustomActionPointer->setChecked(true);
574 // Set the custom search engine flag.
575 customSearchEngine = true;
578 // Format the custom search engine.
579 if (customSearchEngine)
581 // Enable the custom search engine.
582 searchEngineCustomActionPointer->setEnabled(true);
584 // Set the custom search engine text.
585 searchEngineCustomActionPointer->setText(searchEngine);
589 // Disable the custom search engine.
590 searchEngineCustomActionPointer->setEnabled(false);
592 // Reset the custom search engine text.
593 searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
597 void BrowserWindow::updateUserAgentActions(const QString &userAgent) const
599 // Initialize the custom user agent flag.
600 bool customUserAgent = false;
602 // Check the indicated on-the-fly user agent.
603 if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) userAgentPrivacyBrowserActionPointer->setChecked(true); // Privacy Browser.
604 else if (userAgent == BrowserView::webEngineDefaultUserAgent) userAgentWebEngineDefaultActionPointer->setChecked(true); // WebEngine default.
605 else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) userAgentFirefoxLinuxActionPointer->setChecked(true); // Firefox Linux.
606 else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) userAgentChromiumLinuxActionPointer->setChecked(true); // Chromium Linux.
607 else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) userAgentFirefoxWindowsActionPointer->setChecked(true); // Firefox Windows.
608 else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) userAgentChromeWindowsActionPointer->setChecked(true); // Chrome Windows.
609 else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) userAgentEdgeWindowsActionPointer->setChecked(true); // Edge Windows.
610 else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) userAgentSafariMacosActionPointer->setChecked(true); // Safara macOS.
611 else // Custom user agent.
613 // Check the user agent.
614 userAgentCustomActionPointer->setChecked(true);
616 // Set the custom user agent flag.
617 customUserAgent = true;
621 // Format the custom user agent.
624 // Enable the custom user agent.
625 userAgentCustomActionPointer->setEnabled(true);
627 // Set the custom user agent text.
628 userAgentCustomActionPointer->setText(userAgent);
632 // Disable the custom user agent.
633 userAgentCustomActionPointer->setEnabled(false);
635 // Reset the custom user agent text.
636 userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
640 void BrowserWindow::updateZoomFactorAction(const double &zoomFactor)
642 // Set the current zoom factor.
643 currentZoomFactor = zoomFactor;
645 // Update the zoom factor action text, formatting the double with 2 decimal places.
646 zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
649 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
651 // Update the search engine label.
652 searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
655 void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl)
657 // Update the URL line edit if it does not have focus.
658 if (!urlLineEditPointer->hasFocus())
660 // Update the URL line edit.
661 urlLineEditPointer->setText(newUrl.toString());
664 // Store the current URL.
668 void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
670 // Update the user agent label.
671 userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));