2 * Copyright 2022-2023 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_SettingsGeneral.h"
24 #include "ui_SettingsPrivacy.h"
25 #include "ui_SettingsSpellCheck.h"
26 #include "dialogs/CookiesDialog.h"
27 #include "dialogs/DomainSettingsDialog.h"
28 #include "helpers/SearchEngineHelper.h"
29 #include "helpers/UserAgentHelper.h"
31 // KDE Frameworks headers.
32 #include <KActionCollection>
33 #include <KColorScheme>
36 // Qt toolkit headers.
37 #include <QFileDialog>
38 #include <QInputDialog>
39 #include <QNetworkCookie>
43 #include <QWebEngineFindTextResult>
45 // Construct the class.
46 BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
48 // Initialize the variables.
49 javaScriptEnabled = false;
50 localStorageEnabled = false;
52 // Instantiate the privacy tab widget pointer.
53 tabWidgetPointer = new TabWidget(this);
55 // Set the privacy tab widget as the central widget.
56 setCentralWidget(tabWidgetPointer);
58 // Get a handle for the action collection.
59 KActionCollection *actionCollectionPointer = this->actionCollection();
61 // Add the standard actions.
62 KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer);
63 KStandardAction::print(tabWidgetPointer, SLOT(print()), actionCollectionPointer);
64 KStandardAction::printPreview(tabWidgetPointer, SLOT(printPreview()), actionCollectionPointer);
65 KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer);
66 KStandardAction::redisplay(this, SLOT(refresh()), actionCollectionPointer);
67 fullScreenActionPointer = KStandardAction::fullScreen(this, SLOT(toggleFullScreen()), this, actionCollectionPointer);
68 QAction *backActionPointer = KStandardAction::back(this, SLOT(back()), actionCollectionPointer);
69 QAction *forwardActionPointer = KStandardAction::forward(this, SLOT(forward()), actionCollectionPointer);
70 KStandardAction::home(this, SLOT(home()), actionCollectionPointer);
71 KStandardAction::preferences(this, SLOT(showSettingsDialog()), actionCollectionPointer);
72 KStandardAction::find(this, SLOT(focusFindLineEdit()), actionCollectionPointer);
73 QAction *findNextActionPointer = KStandardAction::findNext(this, SLOT(findNext()), actionCollectionPointer);
74 KStandardAction::findPrev(this, SLOT(findPrevious()), actionCollectionPointer);
76 // Add the custom actions.
77 userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_privacy_browser"));
78 userAgentWebEngineDefaultActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_webengine_default"));
79 userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_linux"));
80 userAgentChromiumLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chromium_linux"));
81 userAgentFirefoxWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_windows"));
82 userAgentChromeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chrome_windows"));
83 userAgentEdgeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_edge_windows"));
84 userAgentSafariMacosActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_safari_macos"));
85 userAgentCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_custom"));
86 zoomFactorActionPointer = actionCollectionPointer->addAction(QStringLiteral("zoom_factor"));
87 searchEngineMojeekActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_mojeek"));
88 searchEngineMonoclesActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_monocles"));
89 searchEngineMetagerActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_metager"));
90 searchEngineGoogleActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_google"));
91 searchEngineBingActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_bing"));
92 searchEngineYahooActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_yahoo"));
93 searchEngineCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_custom"));
94 QAction *domainSettingsActionPointer = actionCollectionPointer->addAction(QStringLiteral("domain_settings"));
95 cookiesActionPointer = actionCollectionPointer->addAction(QStringLiteral("cookies"));
96 javaScriptActionPointer = actionCollectionPointer->addAction(QStringLiteral("javascript"));
97 localStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("local_storage"));
98 domStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("dom_storage"));
99 findCaseSensitiveActionPointer = actionCollectionPointer->addAction(QStringLiteral("find_case_sensitive"));
101 // Create the action groups
102 QActionGroup *userAgentActionGroupPointer = new QActionGroup(this);
103 QActionGroup *searchEngineActionGroupPointer = new QActionGroup(this);
105 // Add the actions to the groups.
106 userAgentActionGroupPointer->addAction(userAgentPrivacyBrowserActionPointer);
107 userAgentActionGroupPointer->addAction(userAgentWebEngineDefaultActionPointer);
108 userAgentActionGroupPointer->addAction(userAgentFirefoxLinuxActionPointer);
109 userAgentActionGroupPointer->addAction(userAgentChromiumLinuxActionPointer);
110 userAgentActionGroupPointer->addAction(userAgentFirefoxWindowsActionPointer);
111 userAgentActionGroupPointer->addAction(userAgentChromeWindowsActionPointer);
112 userAgentActionGroupPointer->addAction(userAgentEdgeWindowsActionPointer);
113 userAgentActionGroupPointer->addAction(userAgentSafariMacosActionPointer);
114 userAgentActionGroupPointer->addAction(userAgentCustomActionPointer);
115 searchEngineActionGroupPointer->addAction(searchEngineMojeekActionPointer);
116 searchEngineActionGroupPointer->addAction(searchEngineMonoclesActionPointer);
117 searchEngineActionGroupPointer->addAction(searchEngineMetagerActionPointer);
118 searchEngineActionGroupPointer->addAction(searchEngineGoogleActionPointer);
119 searchEngineActionGroupPointer->addAction(searchEngineBingActionPointer);
120 searchEngineActionGroupPointer->addAction(searchEngineYahooActionPointer);
121 searchEngineActionGroupPointer->addAction(searchEngineCustomActionPointer);
123 // Set some actions to be checkable.
124 javaScriptActionPointer->setCheckable(true);
125 localStorageActionPointer->setCheckable(true);
126 domStorageActionPointer->setCheckable(true);
127 findCaseSensitiveActionPointer->setCheckable(true);
128 userAgentPrivacyBrowserActionPointer->setCheckable(true);
129 userAgentWebEngineDefaultActionPointer->setCheckable(true);
130 userAgentFirefoxLinuxActionPointer->setCheckable(true);
131 userAgentChromiumLinuxActionPointer->setCheckable(true);
132 userAgentFirefoxWindowsActionPointer->setCheckable(true);
133 userAgentChromeWindowsActionPointer->setCheckable(true);
134 userAgentEdgeWindowsActionPointer->setCheckable(true);
135 userAgentSafariMacosActionPointer->setCheckable(true);
136 userAgentCustomActionPointer->setCheckable(true);
137 searchEngineMojeekActionPointer->setCheckable(true);
138 searchEngineMonoclesActionPointer->setCheckable(true);
139 searchEngineMetagerActionPointer->setCheckable(true);
140 searchEngineGoogleActionPointer->setCheckable(true);
141 searchEngineBingActionPointer->setCheckable(true);
142 searchEngineYahooActionPointer->setCheckable(true);
143 searchEngineCustomActionPointer->setCheckable(true);
145 // Instantiate the user agent helper.
146 UserAgentHelper *userAgentHelperPointer = new UserAgentHelper();
148 // Set the action text.
149 userAgentPrivacyBrowserActionPointer->setText(userAgentHelperPointer->PRIVACY_BROWSER_TRANSLATED);
150 userAgentWebEngineDefaultActionPointer->setText(userAgentHelperPointer->WEB_ENGINE_DEFAULT_TRANSLATED);
151 userAgentFirefoxLinuxActionPointer->setText(userAgentHelperPointer->FIREFOX_LINUX_TRANSLATED);
152 userAgentChromiumLinuxActionPointer->setText(userAgentHelperPointer->CHROMIUM_LINUX_TRANSLATED);
153 userAgentFirefoxWindowsActionPointer->setText(userAgentHelperPointer->FIREFOX_WINDOWS_TRANSLATED);
154 userAgentChromeWindowsActionPointer->setText(userAgentHelperPointer->CHROME_WINDOWS_TRANSLATED);
155 userAgentEdgeWindowsActionPointer->setText(userAgentHelperPointer->EDGE_WINDOWS_TRANSLATED);
156 userAgentSafariMacosActionPointer->setText(userAgentHelperPointer->SAFARI_MACOS_TRANSLATED);
157 searchEngineMojeekActionPointer->setText(i18nc("Search engine", "Mojeek"));
158 searchEngineMonoclesActionPointer->setText(i18nc("Search engine", "Monocles"));
159 searchEngineMetagerActionPointer->setText(i18nc("Search engine", "MetaGer"));
160 searchEngineGoogleActionPointer->setText(i18nc("Search engine", "Google"));
161 searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing"));
162 searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo"));
163 domainSettingsActionPointer->setText(i18nc("Domain Settings action", "Domain Settings"));
164 cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", 0));
165 javaScriptActionPointer->setText(i18nc("JavaScript action", "JavaScript"));
166 localStorageActionPointer->setText(i18nc("The Local Storage action", "Local Storage"));
167 domStorageActionPointer->setText(i18nc("DOM Storage action", "DOM Storage"));
168 findCaseSensitiveActionPointer->setText(i18nc("Find Case Sensitive action", "Find Case Sensitive"));
170 // Set the action icons.
171 userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
172 userAgentWebEngineDefaultActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
173 userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
174 userAgentChromiumLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
175 userAgentFirefoxWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
176 userAgentChromeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
177 userAgentEdgeWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
178 userAgentSafariMacosActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
179 userAgentCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
180 searchEngineMojeekActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
181 searchEngineMonoclesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
182 searchEngineMetagerActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
183 searchEngineGoogleActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-google")));
184 searchEngineBingActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
185 searchEngineYahooActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("im-yahoo")));
186 searchEngineCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
187 zoomFactorActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("zoom")));
188 domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("settings-configure")));
189 cookiesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("preferences-web-browser-cookies")));
190 domStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("code-class")));
191 findCaseSensitiveActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("format-text-lowercase")));
193 // Update the on-the-fly menus.
194 connect(tabWidgetPointer, SIGNAL(updateUserAgentActions(QString, bool)), this, SLOT(updateUserAgentActions(QString, bool)));
195 connect(tabWidgetPointer, SIGNAL(updateZoomFactorAction(double)), this, SLOT(updateZoomFactorAction(double)));
196 connect(tabWidgetPointer, SIGNAL(updateSearchEngineActions(QString, bool)), this, SLOT(updateSearchEngineActions(QString, bool)));
198 // Apply the on-the-fly settings when selected.
199 connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), tabWidgetPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
200 connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), tabWidgetPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
202 // Process cookie changes.
203 connect(tabWidgetPointer, SIGNAL(updateCookiesAction(int)), this, SLOT(updateCookiesAction(int)));
206 connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
207 connect(cookiesActionPointer, SIGNAL(triggered()), this, SLOT(showCookiesDialog()));
208 connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(showDomainSettingsDialog()));
210 // Connect the URL toolbar actions.
211 connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript()));
212 connect(localStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleLocalStorage()));
213 connect(domStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleDomStorage()));
215 // Update the URL toolbar actions.
216 connect(tabWidgetPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
217 connect(tabWidgetPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool)));
218 connect(tabWidgetPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool)));
219 connect(tabWidgetPointer, SIGNAL(updateLocalStorageAction(bool)), this, SLOT(updateLocalStorageAction(bool)));
220 connect(tabWidgetPointer, SIGNAL(updateDomStorageAction(bool)), this, SLOT(updateDomStorageAction(bool)));
222 // Connect the find text actions.
223 connect(findCaseSensitiveActionPointer, SIGNAL(triggered()), this, SLOT(toggleFindCaseSensitive()));
225 // Setup the GUI based on the browser_window_ui.rc file.
226 setupGUI(StandardWindowOption::Default, ("browserwindowui.rc"));
228 // Get lists of the actions' associated widgets.
229 QList<QWidget*> userAgentAssociatedWidgetsPointerList = userAgentPrivacyBrowserActionPointer->associatedWidgets();
230 QList<QWidget*> searchEngineAssociatedWidgetsPointerList = searchEngineMojeekActionPointer->associatedWidgets();
232 // Get the menu widget pointers. It is the second entry, after the main window.
233 QWidget *userAgentMenuWidgetPointer = userAgentAssociatedWidgetsPointerList[1];
234 QWidget *searchEngineMenuWidgetPointer = searchEngineAssociatedWidgetsPointerList[1];
236 // Get the menu pointers.
237 QMenu *userAgentMenuPointer = qobject_cast<QMenu*>(userAgentMenuWidgetPointer);
238 QMenu *searchEngineMenuPointer = qobject_cast<QMenu*>(searchEngineMenuWidgetPointer);
240 // Get the menu actions.
241 userAgentMenuActionPointer = userAgentMenuPointer->menuAction();
242 searchEngineMenuActionPointer = searchEngineMenuPointer->menuAction();
244 // Get handles for the toolbars.
245 navigationToolBarPointer = toolBar(QStringLiteral("navigation_toolbar"));
246 urlToolBarPointer = toolBar(QStringLiteral("url_toolbar"));
248 // Create the line edits.
249 urlLineEditPointer = new KLineEdit();
250 findTextLineEditPointer = new KLineEdit();
252 // Get the line edit size policies.
253 QSizePolicy urlLineEditSizePolicy = urlLineEditPointer->sizePolicy();
254 QSizePolicy findTextLineEditSizePolicy = findTextLineEditPointer->sizePolicy();
256 // Set the URL line edit horizontal stretch to be five times the find text line edit stretch.
257 urlLineEditSizePolicy.setHorizontalStretch(5);
258 findTextLineEditSizePolicy.setHorizontalStretch(1);
261 urlLineEditPointer->setSizePolicy(urlLineEditSizePolicy);
262 findTextLineEditPointer->setSizePolicy(findTextLineEditSizePolicy);
265 urlLineEditPointer->setMinimumWidth(350);
266 findTextLineEditPointer->setMinimumWidth(200);
267 findTextLineEditPointer->setMaximumWidth(350);
269 // Set the placehold text.
270 urlLineEditPointer->setPlaceholderText(i18nc("The URL line edit placeholder text", "URL or Search Terms"));
271 findTextLineEditPointer->setPlaceholderText(i18nc("The find line edit placeholder text", "Find Text"));
273 // Show the clear button on the find line edit.
274 findTextLineEditPointer->setClearButtonEnabled(true);
276 // Add an edit or add domain settings action to the URL line edit.
277 QAction *addOrEditDomainSettingsActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme("settings-configure"), QLineEdit::TrailingPosition);
279 // Add or edit the current domain settings.
280 connect(addOrEditDomainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(addOrEditDomainSettings()));
282 // Create a find text label pointer.
283 findTextLabelPointer = new QLabel();
285 // Set the default label text.
286 findTextLabelPointer->setText(QStringLiteral(" ") + i18nc("Default find results.", "0/0") + QStringLiteral(" "));
288 // Insert the widgets into the toolbars.
289 urlToolBarPointer->insertWidget(javaScriptActionPointer, urlLineEditPointer);
290 urlToolBarPointer->insertWidget(findNextActionPointer, findTextLineEditPointer);
291 urlToolBarPointer->insertWidget(findNextActionPointer, findTextLabelPointer);
293 // Load a new URL from the URL line edit.
294 connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
296 // Find text as it is typed.
297 connect(findTextLineEditPointer, SIGNAL(textEdited(const QString &)), tabWidgetPointer, SLOT(findText(const QString &)));
299 // Find next if the enter key is pressed.
300 connect(findTextLineEditPointer, SIGNAL(returnKeyPressed(const QString &)), tabWidgetPointer, SLOT(findText(const QString &)));
302 // Update find text when switching tabs.
303 connect(tabWidgetPointer, SIGNAL(updateFindText(const QString &, const bool)), this, SLOT(updateFindText(const QString &, const bool)));
305 // Update the find text results.
306 connect(tabWidgetPointer, SIGNAL(updateFindTextResults(const QWebEngineFindTextResult &)), this, SLOT(updateFindTextResults(const QWebEngineFindTextResult &)));
308 // Update the URL line edit on page loads.
309 connect(tabWidgetPointer, SIGNAL(updateUrlLineEdit(QUrl)), this, SLOT(updateUrlLineEdit(QUrl)));
311 // Update the window title.
312 connect(tabWidgetPointer, SIGNAL(updateWindowTitle(const QString)), this, SLOT(updateWindowTitle(const QString)));
314 // Get a handle for the status bar.
315 QStatusBar *statusBarPointer = statusBar();
317 // Create a progress bar.
318 progressBarPointer = new QProgressBar();
320 // Add the progress bar to to the status bar.
321 statusBarPointer->addPermanentWidget(progressBarPointer);
323 // Update the status bar with the URL when a link is hovered.
324 connect(tabWidgetPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
326 // Update the progress bar.
327 connect(tabWidgetPointer, SIGNAL(showProgressBar(const int)), this, SLOT(showProgressBar(const int)));
328 connect(tabWidgetPointer, SIGNAL(hideProgressBar()), progressBarPointer, SLOT(hide()));
330 // Update the URL line edit focus.
331 connect(tabWidgetPointer, SIGNAL(clearUrlLineEditFocus()), this, SLOT(clearUrlLineEditFocus()));
333 // Get the URL line edit palettes.
334 normalBackgroundPalette = urlLineEditPointer->palette();
335 negativeBackgroundPalette = normalBackgroundPalette;
336 positiveBackgroundPalette = normalBackgroundPalette;
338 // Modify the palettes.
339 KColorScheme::adjustBackground(negativeBackgroundPalette, KColorScheme::NegativeBackground);
340 KColorScheme::adjustBackground(positiveBackgroundPalette, KColorScheme::PositiveBackground);
342 // Update the applied palette.
343 connect(tabWidgetPointer, SIGNAL(updateDomainSettingsIndicator(const bool)), this, SLOT(updateDomainSettingsIndicator(const bool)));
345 // Process full screen requests.
346 connect(tabWidgetPointer, SIGNAL(fullScreenRequested(bool)), this, SLOT(fullScreenRequested(bool)));
348 // Create keyboard shortcuts.
349 QShortcut *ctrlTShortcutPointer = new QShortcut(QKeySequence(i18nc("The open new tab shortcut.", "Ctrl+t")), this);
350 QShortcut *f11ShortcutPointer = new QShortcut(QKeySequence(i18nc("The toggle full screen shortcut.", "F11")), this);
351 QShortcut *escapeShortcutPointer = new QShortcut(QKeySequence::Cancel, this);
353 // Connect the keyboard shortcuts to the actions.
354 connect(ctrlTShortcutPointer, SIGNAL(activated()), tabWidgetPointer, SLOT(addTab()));
355 connect(f11ShortcutPointer, SIGNAL(activated()), fullScreenActionPointer, SLOT(trigger()));
356 connect(escapeShortcutPointer, SIGNAL(activated()), this, SLOT(escape()));
359 // 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.
360 updateJavaScriptAction(Settings::javaScriptEnabled());
361 updateLocalStorageAction(Settings::localStorageEnabled());
362 updateDomStorageAction(Settings::domStorageEnabled());
363 updateUserAgentActions(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent()), true);
364 updateZoomFactorAction(Settings::zoomFactor());
366 // Load the initial website if this is the first window.
368 tabWidgetPointer->loadInitialWebsite();
371 void BrowserWindow::addOrEditDomainSettings() const
373 // Remove the focus from the URL line edit.
374 urlLineEditPointer->clearFocus();
376 // Create the domain settings dialog pointer.
377 DomainSettingsDialog *domainSettingsDialogPointer;
379 // Get the current domain settings name.
380 QString ¤tDomainSettingsName = tabWidgetPointer->getDomainSettingsName();
382 // Run the commands according to the current domain settings status.
383 if (currentDomainSettingsName == QStringLiteral("")) // Domain settings are not currently applied.
385 // Instruct the domain settings dialog to add a new domain.
386 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::ADD_DOMAIN, currentUrl.host());
388 else // Domain settings are currently applied.
390 // Instruct the domain settings dialog to edit the current domain.
391 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsName);
394 // Set the dialog window title.
395 domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
398 domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
401 domainSettingsDialogPointer->show();
403 // Reload the tabs when domain settings are updated.
404 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
407 void BrowserWindow::back() const
409 // Remove the focus from the URL line edit.
410 urlLineEditPointer->clearFocus();
413 tabWidgetPointer->back();
416 void BrowserWindow::clearUrlLineEditFocus() const
418 // Remove the focus from the URL line edit.
419 urlLineEditPointer->clearFocus();
422 void BrowserWindow::escape() const
424 // Process the excape according to the status of the browser.
425 if (fullScreenActionPointer->isChecked()) // Full screen browsing is enabled.
427 // Exit full screen browsing.
428 fullScreenActionPointer->trigger();
430 else if (!findTextLineEditPointer->text().isEmpty()) // Find text is activated.
432 // Clear the text in the line edit.
433 findTextLineEditPointer->clear();
435 // Clear the search in the WebEngine.
436 tabWidgetPointer->findText(QStringLiteral(""));
440 void BrowserWindow::fileNew() const
442 // Display a new instance of Privacy Browser.
443 (new BrowserWindow)->show();
446 void BrowserWindow::findNext() const
448 // Get the find string.
449 const QString findString = findTextLineEditPointer->text();
451 // Search for the text if it is not empty.
452 if (!findString.isEmpty())
453 tabWidgetPointer->findText(findString);
456 void BrowserWindow::findPrevious() const
458 // Get the find string.
459 const QString findString = findTextLineEditPointer->text();
461 // Search for the text if it is not empty.
462 if (!findString.isEmpty())
463 tabWidgetPointer->findPrevious(findString);
466 void BrowserWindow::focusFindLineEdit() const
468 // Set the focus on the find line edit.
469 findTextLineEditPointer->setFocus();
471 // Select all the text in the find line edit.
472 findTextLineEditPointer->selectAll();
475 void BrowserWindow::forward() const
477 // Remove the focus from the URL line edit.
478 urlLineEditPointer->clearFocus();
481 tabWidgetPointer->forward();
484 void BrowserWindow::fullScreenRequested(const bool toggleOn)
486 // Toggle full screen mode.
487 if (toggleOn) // Turn full screen mode on.
489 // Set the window to be full screen.
490 fullScreenActionPointer->setFullScreen(window(), true);
492 // Hide all the bars.
493 menuBar()->setVisible(false);
494 navigationToolBarPointer->setVisible(false);
495 urlToolBarPointer->setVisible(false);
496 tabWidgetPointer->setTabBarVisible(false);
497 statusBar()->setVisible(false);
499 else // Turn full screen mode off.
501 // Set the window to not be full screen.
502 fullScreenActionPointer->setFullScreen(window(), false);
504 // Show all the bars.
505 menuBar()->setVisible(true);
506 navigationToolBarPointer->setVisible(true);
507 urlToolBarPointer->setVisible(true);
508 tabWidgetPointer->setTabBarVisible(true);
509 statusBar()->setVisible(true);
513 void BrowserWindow::getZoomFactorFromUser()
515 // Create an OK flag.
518 // 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.
519 double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"),
520 i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
521 currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
523 // Update the zoom factor if the user clicked OK.
526 // Update the current zoom factor.
527 currentZoomFactor = newZoomFactor;
529 // Set the new zoom factor.
530 tabWidgetPointer->applyOnTheFlyZoomFactor(newZoomFactor);
532 // Update the on-the-fly action text.
533 updateZoomFactorAction(newZoomFactor);
537 void BrowserWindow::home() const
539 // Remove the focus from the URL line edit.
540 urlLineEditPointer->clearFocus();
543 tabWidgetPointer->home();
546 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
548 // Remove the focus from the URL line edit.
549 urlLineEditPointer->clearFocus();
552 tabWidgetPointer->loadUrlFromLineEdit(url);
555 void BrowserWindow::refresh() const
557 // Remove the focus from the URL line edit.
558 urlLineEditPointer->clearFocus();
560 // Refresh the web page.
561 tabWidgetPointer->refresh();
564 void BrowserWindow::showCookiesDialog()
566 // Remove the focus from the URL line edit.
567 urlLineEditPointer->clearFocus();
569 // Instantiate the cookie settings dialog.
570 CookiesDialog *cookiesDialogPointer = new CookiesDialog(tabWidgetPointer->getCookieList());
573 cookiesDialogPointer->show();
575 // Connect the dialog signals.
576 connect(cookiesDialogPointer, SIGNAL(addCookie(QNetworkCookie)), tabWidgetPointer, SLOT(addCookieToStore(QNetworkCookie)));
577 connect(cookiesDialogPointer, SIGNAL(deleteAllCookies()), tabWidgetPointer, SLOT(deleteAllCookies()));
578 connect(cookiesDialogPointer, SIGNAL(deleteCookie(QNetworkCookie)), tabWidgetPointer, SLOT(deleteCookieFromStore(QNetworkCookie)));
581 void BrowserWindow::showDownloadLocationBrowseDialog() const
583 // Get the current download location.
584 QString currentDownloadLocation = downloadLocationComboBoxPointer->currentText();
586 // Resolve the system download directory if specified.
587 if (currentDownloadLocation == QStringLiteral("System Download Directory"))
588 currentDownloadLocation = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
590 // Get the new download location.
591 QString newDownloadLocation = QFileDialog::getExistingDirectory(configDialogPointer, i18nc("Select download location dialog caption", "Select Download Location"), currentDownloadLocation);
593 // Populate the download location combo box according to the new download location.
594 if (newDownloadLocation == QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)) // The default download location was selected.
596 // Populate the download location with the default text.
597 downloadLocationComboBoxPointer->setCurrentText("System Download Directory");
599 else if (newDownloadLocation != QStringLiteral("")) // A different directory was selected.
601 // Populate the download location.
602 downloadLocationComboBoxPointer->setCurrentText(newDownloadLocation);
606 void BrowserWindow::showDomainSettingsDialog() const
608 // Remove the focus from the URL line edit.
609 urlLineEditPointer->clearFocus();
611 // Instantiate the domain settings dialog.
612 DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
615 domainSettingsDialogPointer->show();
617 // Reload the tabs when domain settings are updated.
618 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
621 void BrowserWindow::showProgressBar(const int &progress) const
623 // Set the progress bar value.
624 progressBarPointer->setValue(progress);
626 // Show the progress bar.
627 progressBarPointer->show();
630 void BrowserWindow::showSettingsDialog()
632 // Create the settings widgets.
633 QWidget *privacySettingsWidgetPointer = new QWidget;
634 QWidget *generalSettingsWidgetPointer = new QWidget;
635 QWidget *spellCheckSettingsWidgetPointer = new QWidget;
637 // Instantiate the settings UI.
638 Ui::PrivacySettings privacySettingsUi;
639 Ui::GeneralSettings generalSettingsUi;
640 Ui::SpellCheckSettings spellCheckSettingsUi;
642 // Setup the UI to display the settings widgets.
643 privacySettingsUi.setupUi(privacySettingsWidgetPointer);
644 generalSettingsUi.setupUi(generalSettingsWidgetPointer);
645 spellCheckSettingsUi.setupUi(spellCheckSettingsWidgetPointer);
647 // Get handles for the widgets.
648 QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
649 userAgentLabelPointer = privacySettingsUi.userAgentLabel;
650 QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
651 searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
652 downloadLocationComboBoxPointer = generalSettingsUi.kcfg_downloadLocation;
653 QPushButton *browseButtonPointer = generalSettingsUi.browseButton;
654 QListWidget *spellCheckListWidgetPointer = spellCheckSettingsUi.spellCheckListWidget;
656 // Populate the combo box labels.
657 updateUserAgentLabel(userAgentComboBoxPointer->currentText());
658 updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
660 // Update the labels when the combo boxes change.
661 connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
662 connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
664 // Connect the download location directory browse button.
665 connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(showDownloadLocationBrowseDialog()));
667 // Create a dictionaries QDir from the `QTWEBENGINE_DICTIONARIES_PATH` environment variable.
668 QDir dictionariesDir = QDir(qEnvironmentVariable("QTWEBENGINE_DICTIONARIES_PATH"));
670 // Get a dictionaries string list.
671 QStringList dictionariesStringList = dictionariesDir.entryList(QStringList(QLatin1String("*.bdic")), QDir::Files | QDir::NoSymLinks);
673 // Remove the `.bdic` file extensions from the dictionaries list.
674 dictionariesStringList.replaceInStrings(QLatin1String(".bdic"), QLatin1String(""));
676 // Get a list of the enabled spell check languages.
677 QStringList enabledSpellCheckLanguagesList = Settings::spellCheckLanguages();
679 // Add each dictionary to the spell check list widget.
680 foreach(QString dictionaryString, dictionariesStringList)
682 // Create a new list widget item pointer named after the dictionary string.
683 QListWidgetItem *listWidgetItemPointer = new QListWidgetItem(dictionaryString, spellCheckListWidgetPointer);
685 // Set the list widget item pointer to be checkable.
686 listWidgetItemPointer->setFlags(listWidgetItemPointer->flags() | Qt::ItemIsUserCheckable);
688 // Check the language if it is currently enabled.
689 if (enabledSpellCheckLanguagesList.contains(dictionaryString))
690 listWidgetItemPointer->setCheckState(Qt::Checked);
692 listWidgetItemPointer->setCheckState(Qt::Unchecked);
694 // Add the list widget item to the widget.
695 spellCheckListWidgetPointer->addItem(listWidgetItemPointer);
698 // Get a handle for the KConfig skeleton.
699 KConfigSkeleton *kConfigSkeletonPointer = Settings::self();
701 // Instantiate a settings config dialog from the settings.kcfg file.
702 configDialogPointer = new KConfigDialog(this, QLatin1String("settings"), kConfigSkeletonPointer);
704 // Add the settings widgets as config dialog pages.
705 configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("Settings tab title", "Privacy"), QLatin1String("privacy-browser"));
706 configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("Settings tab title", "General"), QLatin1String("breeze-settings"));
707 configDialogPointer->addPage(spellCheckSettingsWidgetPointer, i18nc("Settings tab title", "Spell Check"), QLatin1String("tools-check-spelling"));
709 // Get handles for the buttons.
710 QPushButton *applyButtonPointer = configDialogPointer->button(QDialogButtonBox::Apply);
711 QPushButton *okButtonPointer = configDialogPointer->button(QDialogButtonBox::Ok);
713 // Prevent interaction with the parent window while the dialog is open.
714 configDialogPointer->setWindowModality(Qt::WindowModal);
717 configDialogPointer->show();
719 // TODO. KConfigDialog does not respect expanding size policies. <https://redmine.stoutner.com/issues/823>
720 //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
721 //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
722 //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
723 //configDialogPointer->adjustSize();
725 // Expand the config dialog.
726 configDialogPointer->resize(1000, 500);
728 // Create a save spell check languages lambda.
729 auto saveSpellCheckLanguages = [spellCheckListWidgetPointer, kConfigSkeletonPointer, this] ()
731 // Create a list of enabled languages.
732 QStringList newSpellCheckLanguages = QStringList();
734 // Get a count of all the languages.
735 int allLanguagesCount = spellCheckListWidgetPointer->count();
737 // Get a list of all the checked languages.
738 for (int i = 0; i < allLanguagesCount; ++i) {
739 // Get the language item.
740 QListWidgetItem *languageItemPointer = spellCheckListWidgetPointer->item(i);
742 // Add the item to the enabled languages if it is checked.
743 if (languageItemPointer->checkState() == Qt::Checked)
744 newSpellCheckLanguages.append(languageItemPointer->text());
747 // Update the spell check languages.
748 if (Settings::spellCheckLanguages() != newSpellCheckLanguages)
750 // Update the spell check languages.
751 Settings::setSpellCheckLanguages(newSpellCheckLanguages);
753 // Write the settings to disk.
754 kConfigSkeletonPointer->save();
757 // Apply the spell check languages.
758 tabWidgetPointer->applySpellCheckLanguages();
762 connect(applyButtonPointer, &QPushButton::clicked, this, saveSpellCheckLanguages);
763 connect(okButtonPointer, &QPushButton::clicked, this, saveSpellCheckLanguages);
765 // Apply the settings handled by KConfig.
766 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyApplicationSettings()));
767 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
770 QSize BrowserWindow::sizeHint() const
772 // Return the default window size.
773 return QSize(1500, 1200);
776 void BrowserWindow::toggleDomStorage() const
778 // Remove the focus from the URL line edit.
779 urlLineEditPointer->clearFocus();
781 // Toggle DOM storage.
782 tabWidgetPointer->toggleDomStorage();
785 void BrowserWindow::toggleFindCaseSensitive() const
787 // Get the current find string.
788 const QString findString = findTextLineEditPointer->text();
790 // Toggle find case sensitive.
791 tabWidgetPointer->toggleFindCaseSensitive(findString);
794 void BrowserWindow::toggleJavaScript() const
796 // Remove the focus from the URL line edit.
797 urlLineEditPointer->clearFocus();
799 // Toggle JavaScript.
800 tabWidgetPointer->toggleJavaScript();
803 void BrowserWindow::toggleLocalStorage() const
805 // Remove the focus from the URL line edit.
806 urlLineEditPointer->clearFocus();
808 // Toggle local storage.
809 tabWidgetPointer->toggleLocalStorage();
812 void BrowserWindow::toggleFullScreen()
814 // Toggle the full screen status.
815 if (fullScreenActionPointer->isChecked()) // Enable full screen browsing mode.
817 // Enable full screen mode.
818 fullScreenActionPointer->setFullScreen(window(), true);
820 // Hide the menu bar if specified.
821 if (Settings::fullScreenHideMenuBar())
822 menuBar()->setVisible(false);
824 // Hide the toolbars if specified.
825 if (Settings::fullScreenHideToolBars())
827 navigationToolBarPointer->setVisible(false);
828 urlToolBarPointer->setVisible(false);
831 // Hide the tab bar if specified.
832 if (Settings::fullScreenHideTabBar())
833 tabWidgetPointer->setTabBarVisible(false);
835 // Hide the status bar if specified.
836 if (Settings::fullScreenHideStatusBar())
837 statusBar()->setVisible(false);
839 else // Disable full screen browsing mode.
841 // Disable full screen mode.
842 fullScreenActionPointer->setFullScreen(window(), false);
844 // Show the menu bar.
845 menuBar()->setVisible(true);
847 // Show the toolbars.
848 navigationToolBarPointer->setVisible(true);
849 urlToolBarPointer->setVisible(true);
852 tabWidgetPointer->setTabBarVisible(true);
854 // Show the status bar.
855 statusBar()->setVisible(true);
859 void BrowserWindow::updateCookiesAction(const int numberOfCookies) const
861 // Update the action text.
862 cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", numberOfCookies));
865 void BrowserWindow::updateDomStorageAction(const bool &isEnabled) const
867 // Set the action checked status.
868 domStorageActionPointer->setChecked(isEnabled);
871 void BrowserWindow::updateDomainSettingsIndicator(const bool status)
873 // Set the domain palette according to the status.
875 urlLineEditPointer->setPalette(positiveBackgroundPalette);
877 urlLineEditPointer->setPalette(normalBackgroundPalette);
880 void BrowserWindow::updateFindText(const QString &text, const bool findCaseSensitive) const
883 findTextLineEditPointer->setText(text);
885 // Set the find case sensitive action checked status.
886 findCaseSensitiveActionPointer->setChecked(findCaseSensitive);
889 void BrowserWindow::updateFindTextResults(const QWebEngineFindTextResult &findTextResult) const
891 // Update the find text label.
892 findTextLabelPointer->setText(QStringLiteral(" %1/%2 ").arg(findTextResult.activeMatch()).arg(findTextResult.numberOfMatches()));
894 // Set the background color according to the find status.
895 if (findTextLineEditPointer->text().isEmpty())
896 findTextLineEditPointer->setPalette(normalBackgroundPalette);
897 else if (findTextResult.numberOfMatches() == 0)
898 findTextLineEditPointer->setPalette(negativeBackgroundPalette);
900 findTextLineEditPointer->setPalette(positiveBackgroundPalette);
903 void BrowserWindow::updateJavaScriptAction(const bool &isEnabled)
905 // Update the JavaScript status.
906 javaScriptEnabled = isEnabled;
908 // Set the icon according to the status.
909 if (javaScriptEnabled)
910 javaScriptActionPointer->setIcon(QIcon(QStringLiteral(":/icons/javascript-warning")));
912 javaScriptActionPointer->setIcon(QIcon(QStringLiteral(":/icons/privacy-mode")));
914 // Set the action checked status.
915 javaScriptActionPointer->setChecked(javaScriptEnabled);
917 // Update the status of the DOM storage action.
918 domStorageActionPointer->setEnabled(javaScriptEnabled & localStorageEnabled);
921 void BrowserWindow::updateLocalStorageAction(const bool &isEnabled)
923 // Update the local storage status.
924 localStorageEnabled = isEnabled;
927 if (localStorageEnabled)
928 localStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("disk-quota-high")));
930 localStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("disk-quota")));
932 // Set the action checked status.
933 localStorageActionPointer->setChecked(localStorageEnabled);
935 // Update the status of the DOM storage action.
936 domStorageActionPointer->setEnabled(localStorageEnabled & javaScriptEnabled);
939 void BrowserWindow::updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus)
941 // Initialize the custom search engine flag.
942 bool customSearchEngine = false;
944 if (searchEngine == "Mojeek") // Mojeek.
946 // Check the Mojeek user agent action.
947 searchEngineMojeekActionPointer->setChecked(true);
949 // Update the search engine menu action text.
950 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Mojeek"));
952 else if (searchEngine == "Monocles") // Monocles.
954 // Check the Monocles user agent action.
955 searchEngineMonoclesActionPointer->setChecked(true);
957 // Update the search engine menu action text.
958 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Monocles"));
960 else if (searchEngine == "MetaGer") // MetaGer.
962 // Check the MetaGer user agent action.
963 searchEngineMetagerActionPointer->setChecked(true);
965 // Update the search engine menu action text.
966 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - MetaGer"));
968 else if (searchEngine == "Google") // Google.
970 // Check the Google user agent action.
971 searchEngineGoogleActionPointer->setChecked(true);
973 // Update the search engine menu action text.
974 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Google"));
976 else if (searchEngine == "Bing") // Bing.
978 // Check the Bing user agent action.
979 searchEngineBingActionPointer->setChecked(true);
981 // Update the search engine menu action text.
982 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Bing"));
984 else if (searchEngine == "Yahoo") // Yahoo.
986 // Check the Yahoo user agent action.
987 searchEngineYahooActionPointer->setChecked(true);
989 // Update the search engine menu action text.
990 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Yahoo"));
992 else // Custom search engine.
994 // Check the user agent.
995 searchEngineCustomActionPointer->setChecked(true);
997 // Update the search engine menu action text.
998 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Custom"));
1000 // Set the custom search engine text.
1001 searchEngineCustomActionPointer->setText(searchEngine);
1003 // Set the custom search engine flag.
1004 customSearchEngine = true;
1007 // Update the custom search engine enabled boolean.
1008 if (updateCustomSearchEngineStatus)
1009 customSearchEngineEnabled = customSearchEngine;
1011 // Format the custom search engine.
1012 if (customSearchEngineEnabled)
1014 // Enable the custom search engine.
1015 searchEngineCustomActionPointer->setEnabled(true);
1019 // Disable the custom search engine.
1020 searchEngineCustomActionPointer->setEnabled(false);
1022 // Reset the custom search engine text.
1023 searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
1027 void BrowserWindow::updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus)
1029 // Initialize the custom user agent flag.
1030 bool customUserAgent = false;
1032 // Check the indicated on-the-fly user agent.
1033 if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) // Privacy Browser.
1035 // Check the Privacy Browser user agent action.
1036 userAgentPrivacyBrowserActionPointer->setChecked(true);
1038 // Update the user agent menu action text.
1039 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Privacy Browser"));
1041 else if (userAgent == TabWidget::webEngineDefaultUserAgent) // WebEngine default.
1043 // check the WebEngine default user agent action.
1044 userAgentWebEngineDefaultActionPointer->setChecked(true);
1046 // Update the user agent menu action text.
1047 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - WebEngine default"));
1049 else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) // Firefox on Linux.
1051 // Check the Firefox on Linux user agent action.
1052 userAgentFirefoxLinuxActionPointer->setChecked(true);
1054 // Update the user agent menu action text.
1055 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Firefox on Linux"));
1057 else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) // Chromium on Linux.
1059 // Check the Chromium on Linux user agent action.
1060 userAgentChromiumLinuxActionPointer->setChecked(true);
1062 // Update the user agent menu action text.
1063 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Chromium on Linux"));
1065 else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) // Firefox on Windows.
1067 // Check the Firefox on Windows user agent action.
1068 userAgentFirefoxWindowsActionPointer->setChecked(true);
1070 // Update the user agent menu action text.
1071 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Firefox on Windows"));
1073 else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) // Chrome on Windows.
1075 // Check the Chrome on Windows user agent action.
1076 userAgentChromeWindowsActionPointer->setChecked(true);
1078 // Update the user agent menu action text.
1079 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Chrome on Windows"));
1081 else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) // Edge on Windows.
1083 // Check the Edge on Windows user agent action.
1084 userAgentEdgeWindowsActionPointer->setChecked(true);
1086 // Update the user agent menu action text.
1087 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Edge on Windows"));
1089 else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) // Safari on macOS.
1091 // Check the Safari on macOS user agent action.
1092 userAgentSafariMacosActionPointer->setChecked(true);
1094 // Update the user agent menu action text.
1095 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Safari on macOS"));
1097 else // Custom user agent.
1099 // Check the user agent.
1100 userAgentCustomActionPointer->setChecked(true);
1102 // Update the user agent menu action text.
1103 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Custom"));
1105 // Set the custom user agent text.
1106 userAgentCustomActionPointer->setText(userAgent);
1108 // Set the custom user agent flag.
1109 customUserAgent = true;
1112 // Update the custom user agent enabled boolean.
1113 // 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.
1114 if (updateCustomUserAgentStatus)
1115 customUserAgentEnabled = customUserAgent;
1118 // Format the custom user agent.
1119 if (customUserAgentEnabled)
1121 // Enable the custom user agent.
1122 userAgentCustomActionPointer->setEnabled(true);
1126 // Disable the custom user agent.
1127 userAgentCustomActionPointer->setEnabled(false);
1129 // Reset the custom user agent text.
1130 userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
1134 void BrowserWindow::updateZoomFactorAction(const double &zoomFactor)
1136 // Set the current zoom factor.
1137 currentZoomFactor = zoomFactor;
1139 // Update the zoom factor action text, formatting the double with 2 decimal places.
1140 zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
1143 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
1145 // Update the search engine label.
1146 searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
1149 void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl)
1151 // Update the URL line edit if it does not have focus.
1152 if (!urlLineEditPointer->hasFocus())
1154 // Get the new URL string.
1155 QString newUrlString = newUrl.toString();
1157 // Update the URL line edit.
1158 urlLineEditPointer->setText(newUrlString);
1160 // Set the focus if the new URL is blank.
1161 if (newUrlString == QStringLiteral(""))
1162 urlLineEditPointer->setFocus();
1165 // Store the current URL.
1166 currentUrl = newUrl;
1169 void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
1171 // Update the user agent label.
1172 userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));
1175 void BrowserWindow::updateWindowTitle(const QString &title)
1177 // Update the window title.
1178 setWindowTitle(title);