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(showFindTextActions()), actionCollectionPointer);
73 findNextActionPointer = KStandardAction::findNext(this, SLOT(findNext()), actionCollectionPointer);
74 findPreviousActionPointer = KStandardAction::findPrev(this, SLOT(findPrevious()), actionCollectionPointer);
76 // Add the custom actions.
77 userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_privacy_browser"));
78 userAgentWebEngineDefaultActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_webengine_default"));
79 userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_firefox_linux"));
80 userAgentChromiumLinuxActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_chromium_linux"));
81 userAgentFirefoxWindowsActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_firefox_windows"));
82 userAgentChromeWindowsActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_chrome_windows"));
83 userAgentEdgeWindowsActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_edge_windows"));
84 userAgentSafariMacosActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_safari_macos"));
85 userAgentCustomActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_custom"));
86 zoomFactorActionPointer = actionCollectionPointer->addAction(QLatin1String("zoom_factor"));
87 searchEngineMojeekActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_mojeek"));
88 searchEngineMonoclesActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_monocles"));
89 searchEngineMetagerActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_metager"));
90 searchEngineGoogleActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_google"));
91 searchEngineBingActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_bing"));
92 searchEngineYahooActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_yahoo"));
93 searchEngineCustomActionPointer = actionCollectionPointer->addAction(QLatin1String("search_engine_custom"));
94 QAction *domainSettingsActionPointer = actionCollectionPointer->addAction(QLatin1String("domain_settings"));
95 cookiesActionPointer = actionCollectionPointer->addAction(QLatin1String("cookies"));
96 javaScriptActionPointer = actionCollectionPointer->addAction(QLatin1String("javascript"));
97 localStorageActionPointer = actionCollectionPointer->addAction(QLatin1String("local_storage"));
98 domStorageActionPointer = actionCollectionPointer->addAction(QLatin1String("dom_storage"));
99 findCaseSensitiveActionPointer = actionCollectionPointer->addAction(QLatin1String("find_case_sensitive"));
100 hideFindTextActionPointer = actionCollectionPointer->addAction(QLatin1String("hide_find_actions"));
102 // Create the action groups
103 QActionGroup *userAgentActionGroupPointer = new QActionGroup(this);
104 QActionGroup *searchEngineActionGroupPointer = new QActionGroup(this);
106 // Add the actions to the groups.
107 userAgentActionGroupPointer->addAction(userAgentPrivacyBrowserActionPointer);
108 userAgentActionGroupPointer->addAction(userAgentWebEngineDefaultActionPointer);
109 userAgentActionGroupPointer->addAction(userAgentFirefoxLinuxActionPointer);
110 userAgentActionGroupPointer->addAction(userAgentChromiumLinuxActionPointer);
111 userAgentActionGroupPointer->addAction(userAgentFirefoxWindowsActionPointer);
112 userAgentActionGroupPointer->addAction(userAgentChromeWindowsActionPointer);
113 userAgentActionGroupPointer->addAction(userAgentEdgeWindowsActionPointer);
114 userAgentActionGroupPointer->addAction(userAgentSafariMacosActionPointer);
115 userAgentActionGroupPointer->addAction(userAgentCustomActionPointer);
116 searchEngineActionGroupPointer->addAction(searchEngineMojeekActionPointer);
117 searchEngineActionGroupPointer->addAction(searchEngineMonoclesActionPointer);
118 searchEngineActionGroupPointer->addAction(searchEngineMetagerActionPointer);
119 searchEngineActionGroupPointer->addAction(searchEngineGoogleActionPointer);
120 searchEngineActionGroupPointer->addAction(searchEngineBingActionPointer);
121 searchEngineActionGroupPointer->addAction(searchEngineYahooActionPointer);
122 searchEngineActionGroupPointer->addAction(searchEngineCustomActionPointer);
124 // Set some actions to be checkable.
125 javaScriptActionPointer->setCheckable(true);
126 localStorageActionPointer->setCheckable(true);
127 domStorageActionPointer->setCheckable(true);
128 findCaseSensitiveActionPointer->setCheckable(true);
129 userAgentPrivacyBrowserActionPointer->setCheckable(true);
130 userAgentWebEngineDefaultActionPointer->setCheckable(true);
131 userAgentFirefoxLinuxActionPointer->setCheckable(true);
132 userAgentChromiumLinuxActionPointer->setCheckable(true);
133 userAgentFirefoxWindowsActionPointer->setCheckable(true);
134 userAgentChromeWindowsActionPointer->setCheckable(true);
135 userAgentEdgeWindowsActionPointer->setCheckable(true);
136 userAgentSafariMacosActionPointer->setCheckable(true);
137 userAgentCustomActionPointer->setCheckable(true);
138 searchEngineMojeekActionPointer->setCheckable(true);
139 searchEngineMonoclesActionPointer->setCheckable(true);
140 searchEngineMetagerActionPointer->setCheckable(true);
141 searchEngineGoogleActionPointer->setCheckable(true);
142 searchEngineBingActionPointer->setCheckable(true);
143 searchEngineYahooActionPointer->setCheckable(true);
144 searchEngineCustomActionPointer->setCheckable(true);
146 // Instantiate the user agent helper.
147 UserAgentHelper *userAgentHelperPointer = new UserAgentHelper();
149 // Set the action text.
150 userAgentPrivacyBrowserActionPointer->setText(userAgentHelperPointer->PRIVACY_BROWSER_TRANSLATED);
151 userAgentWebEngineDefaultActionPointer->setText(userAgentHelperPointer->WEB_ENGINE_DEFAULT_TRANSLATED);
152 userAgentFirefoxLinuxActionPointer->setText(userAgentHelperPointer->FIREFOX_LINUX_TRANSLATED);
153 userAgentChromiumLinuxActionPointer->setText(userAgentHelperPointer->CHROMIUM_LINUX_TRANSLATED);
154 userAgentFirefoxWindowsActionPointer->setText(userAgentHelperPointer->FIREFOX_WINDOWS_TRANSLATED);
155 userAgentChromeWindowsActionPointer->setText(userAgentHelperPointer->CHROME_WINDOWS_TRANSLATED);
156 userAgentEdgeWindowsActionPointer->setText(userAgentHelperPointer->EDGE_WINDOWS_TRANSLATED);
157 userAgentSafariMacosActionPointer->setText(userAgentHelperPointer->SAFARI_MACOS_TRANSLATED);
158 searchEngineMojeekActionPointer->setText(i18nc("Search engine", "Mojeek"));
159 searchEngineMonoclesActionPointer->setText(i18nc("Search engine", "Monocles"));
160 searchEngineMetagerActionPointer->setText(i18nc("Search engine", "MetaGer"));
161 searchEngineGoogleActionPointer->setText(i18nc("Search engine", "Google"));
162 searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing"));
163 searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo"));
164 domainSettingsActionPointer->setText(i18nc("Domain Settings action", "Domain Settings"));
165 cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", 0));
166 javaScriptActionPointer->setText(i18nc("JavaScript action", "JavaScript"));
167 localStorageActionPointer->setText(i18nc("The Local Storage action", "Local Storage"));
168 domStorageActionPointer->setText(i18nc("DOM Storage action", "DOM Storage"));
169 findCaseSensitiveActionPointer->setText(i18nc("Find Case Sensitive action", "Find Case Sensitive"));
170 hideFindTextActionPointer->setText(i18nc("Hide Find Text action", "Hide Find Text"));
172 // Set the action icons.
173 userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
174 userAgentWebEngineDefaultActionPointer->setIcon(QIcon::fromTheme(QLatin1String("user-group-properties")));
175 userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QLatin1String("firefox-esr")));
176 userAgentChromiumLinuxActionPointer->setIcon(QIcon::fromTheme(QLatin1String("chromium")));
177 userAgentFirefoxWindowsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("firefox-esr")));
178 userAgentChromeWindowsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("chromium")));
179 userAgentEdgeWindowsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("user-group-properties")));
180 userAgentSafariMacosActionPointer->setIcon(QIcon::fromTheme(QLatin1String("user-group-properties")));
181 userAgentCustomActionPointer->setIcon(QIcon::fromTheme(QLatin1String("user-group-properties")));
182 searchEngineMojeekActionPointer->setIcon(QIcon::fromTheme(QLatin1String("search")));
183 searchEngineMonoclesActionPointer->setIcon(QIcon::fromTheme(QLatin1String("search")));
184 searchEngineMetagerActionPointer->setIcon(QIcon::fromTheme(QLatin1String("search")));
185 searchEngineGoogleActionPointer->setIcon(QIcon::fromTheme(QLatin1String("im-google")));
186 searchEngineBingActionPointer->setIcon(QIcon::fromTheme(QLatin1String("search")));
187 searchEngineYahooActionPointer->setIcon(QIcon::fromTheme(QLatin1String("im-yahoo")));
188 searchEngineCustomActionPointer->setIcon(QIcon::fromTheme(QLatin1String("search")));
189 zoomFactorActionPointer->setIcon(QIcon::fromTheme(QLatin1String("zoom")));
190 domainSettingsActionPointer->setIcon(QIcon::fromTheme(QLatin1String("settings-configure")));
191 cookiesActionPointer->setIcon(QIcon::fromTheme(QLatin1String("preferences-web-browser-cookies")));
192 domStorageActionPointer->setIcon(QIcon::fromTheme(QLatin1String("code-class")));
193 findCaseSensitiveActionPointer->setIcon(QIcon::fromTheme(QLatin1String("format-text-lowercase")));
194 hideFindTextActionPointer->setIcon(QIcon::fromTheme(QLatin1String("window-close-symbolic")));
196 // Update the on-the-fly menus.
197 connect(tabWidgetPointer, SIGNAL(updateUserAgentActions(QString, bool)), this, SLOT(updateUserAgentActions(QString, bool)));
198 connect(tabWidgetPointer, SIGNAL(updateZoomFactorAction(double)), this, SLOT(updateZoomFactorAction(double)));
199 connect(tabWidgetPointer, SIGNAL(updateSearchEngineActions(QString, bool)), this, SLOT(updateSearchEngineActions(QString, bool)));
201 // Apply the on-the-fly settings when selected.
202 connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), tabWidgetPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
203 connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), tabWidgetPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
205 // Process cookie changes.
206 connect(tabWidgetPointer, SIGNAL(updateCookiesAction(int)), this, SLOT(updateCookiesAction(int)));
209 connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
210 connect(cookiesActionPointer, SIGNAL(triggered()), this, SLOT(showCookiesDialog()));
211 connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(showDomainSettingsDialog()));
213 // Connect the URL toolbar actions.
214 connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript()));
215 connect(localStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleLocalStorage()));
216 connect(domStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleDomStorage()));
218 // Update the URL toolbar actions.
219 connect(tabWidgetPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
220 connect(tabWidgetPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool)));
221 connect(tabWidgetPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool)));
222 connect(tabWidgetPointer, SIGNAL(updateLocalStorageAction(bool)), this, SLOT(updateLocalStorageAction(bool)));
223 connect(tabWidgetPointer, SIGNAL(updateDomStorageAction(bool)), this, SLOT(updateDomStorageAction(bool)));
225 // Connect the find text actions.
226 connect(findCaseSensitiveActionPointer, SIGNAL(triggered()), this, SLOT(toggleFindCaseSensitive()));
227 connect(hideFindTextActionPointer, SIGNAL(triggered()), this, SLOT(hideFindTextActions()));
229 // Setup the GUI based on the browserwindowui.rc file.
230 setupGUI(StandardWindowOption::Default, ("browserwindowui.rc"));
232 // Get lists of the actions' associated widgets.
233 QList<QWidget*> userAgentAssociatedWidgetsPointerList = userAgentPrivacyBrowserActionPointer->associatedWidgets();
234 QList<QWidget*> searchEngineAssociatedWidgetsPointerList = searchEngineMojeekActionPointer->associatedWidgets();
236 // Get the menu widget pointers. It is the second entry, after the main window.
237 QWidget *userAgentMenuWidgetPointer = userAgentAssociatedWidgetsPointerList[1];
238 QWidget *searchEngineMenuWidgetPointer = searchEngineAssociatedWidgetsPointerList[1];
240 // Get the menu pointers.
241 QMenu *userAgentMenuPointer = qobject_cast<QMenu*>(userAgentMenuWidgetPointer);
242 QMenu *searchEngineMenuPointer = qobject_cast<QMenu*>(searchEngineMenuWidgetPointer);
244 // Get the menu actions.
245 userAgentMenuActionPointer = userAgentMenuPointer->menuAction();
246 searchEngineMenuActionPointer = searchEngineMenuPointer->menuAction();
248 // Get handles for the toolbars.
249 navigationToolBarPointer = toolBar(QLatin1String("navigation_toolbar"));
250 urlToolBarPointer = toolBar(QLatin1String("url_toolbar"));
252 // Create the line edits.
253 urlLineEditPointer = new KLineEdit();
254 findTextLineEditPointer = new KLineEdit();
256 // Get the line edit size policies.
257 QSizePolicy urlLineEditSizePolicy = urlLineEditPointer->sizePolicy();
258 QSizePolicy findTextLineEditSizePolicy = findTextLineEditPointer->sizePolicy();
260 // Set the URL line edit horizontal stretch to be five times the find text line edit stretch.
261 urlLineEditSizePolicy.setHorizontalStretch(5);
262 findTextLineEditSizePolicy.setHorizontalStretch(1);
265 urlLineEditPointer->setSizePolicy(urlLineEditSizePolicy);
266 findTextLineEditPointer->setSizePolicy(findTextLineEditSizePolicy);
269 urlLineEditPointer->setMinimumWidth(350);
270 findTextLineEditPointer->setMinimumWidth(200);
271 findTextLineEditPointer->setMaximumWidth(350);
273 // Set the place holder text.
274 urlLineEditPointer->setPlaceholderText(i18nc("The URL line edit placeholder text", "URL or Search Terms"));
275 findTextLineEditPointer->setPlaceholderText(i18nc("The find line edit placeholder text", "Find Text"));
277 // Show the clear button on the find line edit.
278 findTextLineEditPointer->setClearButtonEnabled(true);
280 // Add an edit or add domain settings action to the URL line edit.
281 QAction *addOrEditDomainSettingsActionPointer = urlLineEditPointer->addAction(QIcon::fromTheme("settings-configure"), QLineEdit::TrailingPosition);
283 // Add or edit the current domain settings.
284 connect(addOrEditDomainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(addOrEditDomainSettings()));
286 // Create a find text label pointer.
287 findTextLabelPointer = new QLabel();
289 // Set the default label text.
290 findTextLabelPointer->setText(QLatin1String(" ") + i18nc("Default find results.", "0/0") + QLatin1String(" "));
292 // Insert the widgets into the toolbars.
293 urlToolBarPointer->insertWidget(javaScriptActionPointer, urlLineEditPointer);
294 findTextLineEditActionPointer = urlToolBarPointer->insertWidget(findNextActionPointer, findTextLineEditPointer);
295 findTextLabelActionPointer = urlToolBarPointer->insertWidget(findNextActionPointer, findTextLabelPointer);
297 // Initially hide the find text actions.
298 hideFindTextActions();
300 // Load a new URL from the URL line edit.
301 connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
303 // Find text as it is typed.
304 connect(findTextLineEditPointer, SIGNAL(textEdited(const QString &)), tabWidgetPointer, SLOT(findText(const QString &)));
306 // Find next if the enter key is pressed.
307 connect(findTextLineEditPointer, SIGNAL(returnKeyPressed(const QString &)), tabWidgetPointer, SLOT(findText(const QString &)));
309 // Update find text when switching tabs.
310 connect(tabWidgetPointer, SIGNAL(updateFindText(const QString &, const bool)), this, SLOT(updateFindText(const QString &, const bool)));
312 // Update the find text results.
313 connect(tabWidgetPointer, SIGNAL(updateFindTextResults(const QWebEngineFindTextResult &)), this, SLOT(updateFindTextResults(const QWebEngineFindTextResult &)));
315 // Update the URL line edit on page loads.
316 connect(tabWidgetPointer, SIGNAL(updateUrlLineEdit(QUrl)), this, SLOT(updateUrlLineEdit(QUrl)));
318 // Update the window title.
319 connect(tabWidgetPointer, SIGNAL(updateWindowTitle(const QString)), this, SLOT(updateWindowTitle(const QString)));
321 // Get a handle for the status bar.
322 QStatusBar *statusBarPointer = statusBar();
324 // Create a progress bar.
325 progressBarPointer = new QProgressBar();
327 // Add the progress bar to to the status bar.
328 statusBarPointer->addPermanentWidget(progressBarPointer);
330 // Update the status bar with the URL when a link is hovered.
331 connect(tabWidgetPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
333 // Update the progress bar.
334 connect(tabWidgetPointer, SIGNAL(showProgressBar(const int)), this, SLOT(showProgressBar(const int)));
335 connect(tabWidgetPointer, SIGNAL(hideProgressBar()), progressBarPointer, SLOT(hide()));
337 // Update the URL line edit focus.
338 connect(tabWidgetPointer, SIGNAL(clearUrlLineEditFocus()), this, SLOT(clearUrlLineEditFocus()));
340 // Get the URL line edit palettes.
341 normalBackgroundPalette = urlLineEditPointer->palette();
342 negativeBackgroundPalette = normalBackgroundPalette;
343 positiveBackgroundPalette = normalBackgroundPalette;
345 // Modify the palettes.
346 KColorScheme::adjustBackground(negativeBackgroundPalette, KColorScheme::NegativeBackground);
347 KColorScheme::adjustBackground(positiveBackgroundPalette, KColorScheme::PositiveBackground);
349 // Update the applied palette.
350 connect(tabWidgetPointer, SIGNAL(updateDomainSettingsIndicator(const bool)), this, SLOT(updateDomainSettingsIndicator(const bool)));
352 // Process full screen requests.
353 connect(tabWidgetPointer, SIGNAL(fullScreenRequested(bool)), this, SLOT(fullScreenRequested(bool)));
355 // Create keyboard shortcuts.
356 QShortcut *ctrlTShortcutPointer = new QShortcut(QKeySequence(i18nc("The open new tab shortcut.", "Ctrl+t")), this);
357 QShortcut *f11ShortcutPointer = new QShortcut(QKeySequence(i18nc("The toggle full screen shortcut.", "F11")), this);
358 QShortcut *escapeShortcutPointer = new QShortcut(QKeySequence::Cancel, this);
360 // Connect the keyboard shortcuts to the actions.
361 connect(ctrlTShortcutPointer, SIGNAL(activated()), tabWidgetPointer, SLOT(addTab()));
362 connect(f11ShortcutPointer, SIGNAL(activated()), fullScreenActionPointer, SLOT(trigger()));
363 connect(escapeShortcutPointer, SIGNAL(activated()), this, SLOT(escape()));
366 // 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.
367 updateJavaScriptAction(Settings::javaScriptEnabled());
368 updateLocalStorageAction(Settings::localStorageEnabled());
369 updateDomStorageAction(Settings::domStorageEnabled());
370 updateUserAgentActions(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent()), true);
371 updateZoomFactorAction(Settings::zoomFactor());
373 // Load the initial website if this is the first window.
375 tabWidgetPointer->loadInitialWebsite();
378 void BrowserWindow::addOrEditDomainSettings() const
380 // Remove the focus from the URL line edit.
381 urlLineEditPointer->clearFocus();
383 // Create the domain settings dialog pointer.
384 DomainSettingsDialog *domainSettingsDialogPointer;
386 // Get the current domain settings name.
387 QString ¤tDomainSettingsName = tabWidgetPointer->getDomainSettingsName();
389 // Run the commands according to the current domain settings status.
390 if (currentDomainSettingsName == QStringLiteral("")) // Domain settings are not currently applied.
392 // Instruct the domain settings dialog to add a new domain.
393 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::ADD_DOMAIN, currentUrl.host());
395 else // Domain settings are currently applied.
397 // Instruct the domain settings dialog to edit the current domain.
398 domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsName);
401 // Set the dialog window title.
402 domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
405 domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
408 domainSettingsDialogPointer->show();
410 // Reload the tabs when domain settings are updated.
411 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
414 void BrowserWindow::back() const
416 // Remove the focus from the URL line edit.
417 urlLineEditPointer->clearFocus();
420 tabWidgetPointer->back();
423 void BrowserWindow::clearUrlLineEditFocus() const
425 // Remove the focus from the URL line edit.
426 urlLineEditPointer->clearFocus();
429 void BrowserWindow::escape() const
431 // Process the escape according to the status of the browser.
432 if (fullScreenActionPointer->isChecked()) // Full screen browsing is enabled.
434 // Exit full screen browsing.
435 fullScreenActionPointer->trigger();
437 else if (!findTextLineEditPointer->text().isEmpty()) // Find text is populated.
439 // Clear the text in the line edit.
440 findTextLineEditPointer->clear();
442 // Clear the search in the WebEngine.
443 tabWidgetPointer->findText(QStringLiteral(""));
445 else if (findTextLineEditActionPointer->isVisible()) // Find text actions are visible.
447 // Hide the find text actions.
448 hideFindTextActions();
452 void BrowserWindow::fileNew() const
454 // Display a new instance of Privacy Browser.
455 (new BrowserWindow)->show();
458 void BrowserWindow::findNext() const
460 // Get the find string.
461 const QString findString = findTextLineEditPointer->text();
463 // Search for the text if it is not empty.
464 if (!findString.isEmpty())
465 tabWidgetPointer->findText(findString);
468 void BrowserWindow::findPrevious() const
470 // Get the find string.
471 const QString findString = findTextLineEditPointer->text();
473 // Search for the text if it is not empty.
474 if (!findString.isEmpty())
475 tabWidgetPointer->findPrevious(findString);
478 void BrowserWindow::forward() const
480 // Remove the focus from the URL line edit.
481 urlLineEditPointer->clearFocus();
484 tabWidgetPointer->forward();
487 void BrowserWindow::fullScreenRequested(const bool toggleOn)
489 // Toggle full screen mode.
490 if (toggleOn) // Turn full screen mode on.
492 // Set the window to be full screen.
493 fullScreenActionPointer->setFullScreen(window(), true);
495 // Hide all the bars.
496 menuBar()->setVisible(false);
497 navigationToolBarPointer->setVisible(false);
498 urlToolBarPointer->setVisible(false);
499 tabWidgetPointer->setTabBarVisible(false);
500 statusBar()->setVisible(false);
502 else // Turn full screen mode off.
504 // Set the window to not be full screen.
505 fullScreenActionPointer->setFullScreen(window(), false);
507 // Show all the bars.
508 menuBar()->setVisible(true);
509 navigationToolBarPointer->setVisible(true);
510 urlToolBarPointer->setVisible(true);
511 tabWidgetPointer->setTabBarVisible(true);
512 statusBar()->setVisible(true);
516 void BrowserWindow::getZoomFactorFromUser()
518 // Create an OK flag.
521 // 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.
522 double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"),
523 i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
524 currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
526 // Update the zoom factor if the user clicked OK.
529 // Update the current zoom factor.
530 currentZoomFactor = newZoomFactor;
532 // Set the new zoom factor.
533 tabWidgetPointer->applyOnTheFlyZoomFactor(newZoomFactor);
535 // Update the on-the-fly action text.
536 updateZoomFactorAction(newZoomFactor);
540 void BrowserWindow::hideFindTextActions() const
542 // Hide the find text actions.
543 findTextLineEditActionPointer->setVisible(false);
544 findTextLabelActionPointer->setVisible(false);
545 findNextActionPointer->setVisible(false);
546 findPreviousActionPointer->setVisible(false);
547 findCaseSensitiveActionPointer->setVisible(false);
548 hideFindTextActionPointer->setVisible(false);
551 void BrowserWindow::home() const
553 // Remove the focus from the URL line edit.
554 urlLineEditPointer->clearFocus();
557 tabWidgetPointer->home();
560 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
562 // Remove the focus from the URL line edit.
563 urlLineEditPointer->clearFocus();
566 tabWidgetPointer->loadUrlFromLineEdit(url);
569 void BrowserWindow::refresh() const
571 // Remove the focus from the URL line edit.
572 urlLineEditPointer->clearFocus();
574 // Refresh the web page.
575 tabWidgetPointer->refresh();
578 void BrowserWindow::showCookiesDialog()
580 // Remove the focus from the URL line edit.
581 urlLineEditPointer->clearFocus();
583 // Instantiate the cookie settings dialog.
584 CookiesDialog *cookiesDialogPointer = new CookiesDialog(tabWidgetPointer->getCookieList());
587 cookiesDialogPointer->show();
589 // Connect the dialog signals.
590 connect(cookiesDialogPointer, SIGNAL(addCookie(QNetworkCookie)), tabWidgetPointer, SLOT(addCookieToStore(QNetworkCookie)));
591 connect(cookiesDialogPointer, SIGNAL(deleteAllCookies()), tabWidgetPointer, SLOT(deleteAllCookies()));
592 connect(cookiesDialogPointer, SIGNAL(deleteCookie(QNetworkCookie)), tabWidgetPointer, SLOT(deleteCookieFromStore(QNetworkCookie)));
595 void BrowserWindow::showDownloadLocationBrowseDialog() const
597 // Get the current download location.
598 QString currentDownloadLocation = downloadLocationComboBoxPointer->currentText();
600 // Resolve the system download directory if specified.
601 if (currentDownloadLocation == QStringLiteral("System Download Directory"))
602 currentDownloadLocation = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
604 // Get the new download location.
605 QString newDownloadLocation = QFileDialog::getExistingDirectory(configDialogPointer, i18nc("Select download location dialog caption", "Select Download Location"), currentDownloadLocation);
607 // Populate the download location combo box according to the new download location.
608 if (newDownloadLocation == QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)) // The default download location was selected.
610 // Populate the download location with the default text.
611 downloadLocationComboBoxPointer->setCurrentText("System Download Directory");
613 else if (newDownloadLocation != QStringLiteral("")) // A different directory was selected.
615 // Populate the download location.
616 downloadLocationComboBoxPointer->setCurrentText(newDownloadLocation);
620 void BrowserWindow::showDomainSettingsDialog() const
622 // Remove the focus from the URL line edit.
623 urlLineEditPointer->clearFocus();
625 // Instantiate the domain settings dialog.
626 DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
629 domainSettingsDialogPointer->show();
631 // Reload the tabs when domain settings are updated.
632 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
635 void BrowserWindow::showFindTextActions() const
637 // Show the find text actions.
638 findTextLineEditActionPointer->setVisible(true);
639 findTextLabelActionPointer->setVisible(true);
640 findNextActionPointer->setVisible(true);
641 findPreviousActionPointer->setVisible(true);
642 findCaseSensitiveActionPointer->setVisible(true);
643 hideFindTextActionPointer->setVisible(true);
645 // Set the focus on the find line edit.
646 findTextLineEditPointer->setFocus();
648 // Select all the text in the find line edit.
649 findTextLineEditPointer->selectAll();
652 void BrowserWindow::showProgressBar(const int &progress) const
654 // Set the progress bar value.
655 progressBarPointer->setValue(progress);
657 // Show the progress bar.
658 progressBarPointer->show();
661 void BrowserWindow::showSettingsDialog()
663 // Create the settings widgets.
664 QWidget *privacySettingsWidgetPointer = new QWidget;
665 QWidget *generalSettingsWidgetPointer = new QWidget;
666 QWidget *spellCheckSettingsWidgetPointer = new QWidget;
668 // Instantiate the settings UI.
669 Ui::PrivacySettings privacySettingsUi;
670 Ui::GeneralSettings generalSettingsUi;
671 Ui::SpellCheckSettings spellCheckSettingsUi;
673 // Setup the UI to display the settings widgets.
674 privacySettingsUi.setupUi(privacySettingsWidgetPointer);
675 generalSettingsUi.setupUi(generalSettingsWidgetPointer);
676 spellCheckSettingsUi.setupUi(spellCheckSettingsWidgetPointer);
678 // Get handles for the widgets.
679 QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
680 userAgentLabelPointer = privacySettingsUi.userAgentLabel;
681 QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
682 searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
683 downloadLocationComboBoxPointer = generalSettingsUi.kcfg_downloadLocation;
684 QPushButton *browseButtonPointer = generalSettingsUi.browseButton;
685 QListWidget *spellCheckListWidgetPointer = spellCheckSettingsUi.spellCheckListWidget;
687 // Populate the combo box labels.
688 updateUserAgentLabel(userAgentComboBoxPointer->currentText());
689 updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
691 // Update the labels when the combo boxes change.
692 connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
693 connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
695 // Connect the download location directory browse button.
696 connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(showDownloadLocationBrowseDialog()));
698 // Create a dictionaries QDir from the `QTWEBENGINE_DICTIONARIES_PATH` environment variable.
699 QDir dictionariesDir = QDir(qEnvironmentVariable("QTWEBENGINE_DICTIONARIES_PATH"));
701 // Get a dictionaries string list.
702 QStringList dictionariesStringList = dictionariesDir.entryList(QStringList(QLatin1String("*.bdic")), QDir::Files | QDir::NoSymLinks);
704 // Remove the `.bdic` file extensions from the dictionaries list.
705 dictionariesStringList.replaceInStrings(QLatin1String(".bdic"), QLatin1String(""));
707 // Get a list of the enabled spell check languages.
708 QStringList enabledSpellCheckLanguagesList = Settings::spellCheckLanguages();
710 // Add each dictionary to the spell check list widget.
711 foreach(QString dictionaryString, dictionariesStringList)
713 // Create a new list widget item pointer named after the dictionary string.
714 QListWidgetItem *listWidgetItemPointer = new QListWidgetItem(dictionaryString, spellCheckListWidgetPointer);
716 // Set the list widget item pointer to be checkable.
717 listWidgetItemPointer->setFlags(listWidgetItemPointer->flags() | Qt::ItemIsUserCheckable);
719 // Check the language if it is currently enabled.
720 if (enabledSpellCheckLanguagesList.contains(dictionaryString))
721 listWidgetItemPointer->setCheckState(Qt::Checked);
723 listWidgetItemPointer->setCheckState(Qt::Unchecked);
725 // Add the list widget item to the widget.
726 spellCheckListWidgetPointer->addItem(listWidgetItemPointer);
729 // Get a handle for the KConfig skeleton.
730 KConfigSkeleton *kConfigSkeletonPointer = Settings::self();
732 // Instantiate a settings config dialog from the settings.kcfg file.
733 configDialogPointer = new KConfigDialog(this, QLatin1String("settings"), kConfigSkeletonPointer);
735 // Add the settings widgets as config dialog pages.
736 configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("Settings tab title", "Privacy"), QLatin1String("privacy-browser"));
737 configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("Settings tab title", "General"), QLatin1String("breeze-settings"));
738 configDialogPointer->addPage(spellCheckSettingsWidgetPointer, i18nc("Settings tab title", "Spell Check"), QLatin1String("tools-check-spelling"));
740 // Get handles for the buttons.
741 QPushButton *applyButtonPointer = configDialogPointer->button(QDialogButtonBox::Apply);
742 QPushButton *okButtonPointer = configDialogPointer->button(QDialogButtonBox::Ok);
744 // Prevent interaction with the parent window while the dialog is open.
745 configDialogPointer->setWindowModality(Qt::WindowModal);
748 configDialogPointer->show();
750 // TODO. KConfigDialog does not respect expanding size policies. <https://redmine.stoutner.com/issues/823>
751 //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
752 //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
753 //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
754 //configDialogPointer->adjustSize();
756 // Expand the config dialog.
757 configDialogPointer->resize(1000, 500);
759 // Create a save spell check languages lambda.
760 auto saveSpellCheckLanguages = [spellCheckListWidgetPointer, kConfigSkeletonPointer, this] ()
762 // Create a list of enabled languages.
763 QStringList newSpellCheckLanguages = QStringList();
765 // Get a count of all the languages.
766 int allLanguagesCount = spellCheckListWidgetPointer->count();
768 // Get a list of all the checked languages.
769 for (int i = 0; i < allLanguagesCount; ++i) {
770 // Get the language item.
771 QListWidgetItem *languageItemPointer = spellCheckListWidgetPointer->item(i);
773 // Add the item to the enabled languages if it is checked.
774 if (languageItemPointer->checkState() == Qt::Checked)
775 newSpellCheckLanguages.append(languageItemPointer->text());
778 // Update the spell check languages.
779 if (Settings::spellCheckLanguages() != newSpellCheckLanguages)
781 // Update the spell check languages.
782 Settings::setSpellCheckLanguages(newSpellCheckLanguages);
784 // Write the settings to disk.
785 kConfigSkeletonPointer->save();
788 // Apply the spell check languages.
789 tabWidgetPointer->applySpellCheckLanguages();
793 connect(applyButtonPointer, &QPushButton::clicked, this, saveSpellCheckLanguages);
794 connect(okButtonPointer, &QPushButton::clicked, this, saveSpellCheckLanguages);
796 // Apply the settings handled by KConfig.
797 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyApplicationSettings()));
798 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
801 QSize BrowserWindow::sizeHint() const
803 // Return the default window size.
804 return QSize(1500, 1200);
807 void BrowserWindow::toggleDomStorage() const
809 // Remove the focus from the URL line edit.
810 urlLineEditPointer->clearFocus();
812 // Toggle DOM storage.
813 tabWidgetPointer->toggleDomStorage();
816 void BrowserWindow::toggleFindCaseSensitive() const
818 // Get the current find string.
819 const QString findString = findTextLineEditPointer->text();
821 // Toggle find case sensitive.
822 tabWidgetPointer->toggleFindCaseSensitive(findString);
825 void BrowserWindow::toggleJavaScript() const
827 // Remove the focus from the URL line edit.
828 urlLineEditPointer->clearFocus();
830 // Toggle JavaScript.
831 tabWidgetPointer->toggleJavaScript();
834 void BrowserWindow::toggleLocalStorage() const
836 // Remove the focus from the URL line edit.
837 urlLineEditPointer->clearFocus();
839 // Toggle local storage.
840 tabWidgetPointer->toggleLocalStorage();
843 void BrowserWindow::toggleFullScreen()
845 // Toggle the full screen status.
846 if (fullScreenActionPointer->isChecked()) // Enable full screen browsing mode.
848 // Enable full screen mode.
849 fullScreenActionPointer->setFullScreen(window(), true);
851 // Hide the menu bar if specified.
852 if (Settings::fullScreenHideMenuBar())
853 menuBar()->setVisible(false);
855 // Hide the toolbars if specified.
856 if (Settings::fullScreenHideToolBars())
858 navigationToolBarPointer->setVisible(false);
859 urlToolBarPointer->setVisible(false);
862 // Hide the tab bar if specified.
863 if (Settings::fullScreenHideTabBar())
864 tabWidgetPointer->setTabBarVisible(false);
866 // Hide the status bar if specified.
867 if (Settings::fullScreenHideStatusBar())
868 statusBar()->setVisible(false);
870 else // Disable full screen browsing mode.
872 // Disable full screen mode.
873 fullScreenActionPointer->setFullScreen(window(), false);
875 // Show the menu bar.
876 menuBar()->setVisible(true);
878 // Show the toolbars.
879 navigationToolBarPointer->setVisible(true);
880 urlToolBarPointer->setVisible(true);
883 tabWidgetPointer->setTabBarVisible(true);
885 // Show the status bar.
886 statusBar()->setVisible(true);
890 void BrowserWindow::updateCookiesAction(const int numberOfCookies) const
892 // Update the action text.
893 cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", numberOfCookies));
896 void BrowserWindow::updateDomStorageAction(const bool &isEnabled) const
898 // Set the action checked status.
899 domStorageActionPointer->setChecked(isEnabled);
902 void BrowserWindow::updateDomainSettingsIndicator(const bool status)
904 // Set the domain palette according to the status.
906 urlLineEditPointer->setPalette(positiveBackgroundPalette);
908 urlLineEditPointer->setPalette(normalBackgroundPalette);
911 void BrowserWindow::updateFindText(const QString &text, const bool findCaseSensitive) const
914 findTextLineEditPointer->setText(text);
916 // Set the find case sensitive action checked status.
917 findCaseSensitiveActionPointer->setChecked(findCaseSensitive);
920 void BrowserWindow::updateFindTextResults(const QWebEngineFindTextResult &findTextResult) const
922 // Update the find text label.
923 findTextLabelPointer->setText(QStringLiteral(" %1/%2 ").arg(findTextResult.activeMatch()).arg(findTextResult.numberOfMatches()));
925 // Set the background color according to the find status.
926 if (findTextLineEditPointer->text().isEmpty())
927 findTextLineEditPointer->setPalette(normalBackgroundPalette);
928 else if (findTextResult.numberOfMatches() == 0)
929 findTextLineEditPointer->setPalette(negativeBackgroundPalette);
931 findTextLineEditPointer->setPalette(positiveBackgroundPalette);
934 void BrowserWindow::updateJavaScriptAction(const bool &isEnabled)
936 // Update the JavaScript status.
937 javaScriptEnabled = isEnabled;
939 // Set the icon according to the status.
940 if (javaScriptEnabled)
941 javaScriptActionPointer->setIcon(QIcon(QStringLiteral(":/icons/javascript-warning")));
943 javaScriptActionPointer->setIcon(QIcon(QStringLiteral(":/icons/privacy-mode")));
945 // Set the action checked status.
946 javaScriptActionPointer->setChecked(javaScriptEnabled);
948 // Update the status of the DOM storage action.
949 domStorageActionPointer->setEnabled(javaScriptEnabled & localStorageEnabled);
952 void BrowserWindow::updateLocalStorageAction(const bool &isEnabled)
954 // Update the local storage status.
955 localStorageEnabled = isEnabled;
958 if (localStorageEnabled)
959 localStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("disk-quota-high")));
961 localStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("disk-quota")));
963 // Set the action checked status.
964 localStorageActionPointer->setChecked(localStorageEnabled);
966 // Update the status of the DOM storage action.
967 domStorageActionPointer->setEnabled(localStorageEnabled & javaScriptEnabled);
970 void BrowserWindow::updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus)
972 // Initialize the custom search engine flag.
973 bool customSearchEngine = false;
975 if (searchEngine == "Mojeek") // Mojeek.
977 // Check the Mojeek user agent action.
978 searchEngineMojeekActionPointer->setChecked(true);
980 // Update the search engine menu action text.
981 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Mojeek"));
983 else if (searchEngine == "Monocles") // Monocles.
985 // Check the Monocles user agent action.
986 searchEngineMonoclesActionPointer->setChecked(true);
988 // Update the search engine menu action text.
989 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Monocles"));
991 else if (searchEngine == "MetaGer") // MetaGer.
993 // Check the MetaGer user agent action.
994 searchEngineMetagerActionPointer->setChecked(true);
996 // Update the search engine menu action text.
997 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - MetaGer"));
999 else if (searchEngine == "Google") // Google.
1001 // Check the Google user agent action.
1002 searchEngineGoogleActionPointer->setChecked(true);
1004 // Update the search engine menu action text.
1005 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Google"));
1007 else if (searchEngine == "Bing") // Bing.
1009 // Check the Bing user agent action.
1010 searchEngineBingActionPointer->setChecked(true);
1012 // Update the search engine menu action text.
1013 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Bing"));
1015 else if (searchEngine == "Yahoo") // Yahoo.
1017 // Check the Yahoo user agent action.
1018 searchEngineYahooActionPointer->setChecked(true);
1020 // Update the search engine menu action text.
1021 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Yahoo"));
1023 else // Custom search engine.
1025 // Check the user agent.
1026 searchEngineCustomActionPointer->setChecked(true);
1028 // Update the search engine menu action text.
1029 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Custom"));
1031 // Set the custom search engine text.
1032 searchEngineCustomActionPointer->setText(searchEngine);
1034 // Set the custom search engine flag.
1035 customSearchEngine = true;
1038 // Update the custom search engine enabled boolean.
1039 if (updateCustomSearchEngineStatus)
1040 customSearchEngineEnabled = customSearchEngine;
1042 // Format the custom search engine.
1043 if (customSearchEngineEnabled)
1045 // Enable the custom search engine.
1046 searchEngineCustomActionPointer->setEnabled(true);
1050 // Disable the custom search engine.
1051 searchEngineCustomActionPointer->setEnabled(false);
1053 // Reset the custom search engine text.
1054 searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
1058 void BrowserWindow::updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus)
1060 // Initialize the custom user agent flag.
1061 bool customUserAgent = false;
1063 // Check the indicated on-the-fly user agent.
1064 if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) // Privacy Browser.
1066 // Check the Privacy Browser user agent action.
1067 userAgentPrivacyBrowserActionPointer->setChecked(true);
1069 // Update the user agent menu action text.
1070 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Privacy Browser"));
1072 else if (userAgent == TabWidget::webEngineDefaultUserAgent) // WebEngine default.
1074 // check the WebEngine default user agent action.
1075 userAgentWebEngineDefaultActionPointer->setChecked(true);
1077 // Update the user agent menu action text.
1078 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - WebEngine default"));
1080 else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) // Firefox on Linux.
1082 // Check the Firefox on Linux user agent action.
1083 userAgentFirefoxLinuxActionPointer->setChecked(true);
1085 // Update the user agent menu action text.
1086 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Firefox on Linux"));
1088 else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) // Chromium on Linux.
1090 // Check the Chromium on Linux user agent action.
1091 userAgentChromiumLinuxActionPointer->setChecked(true);
1093 // Update the user agent menu action text.
1094 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Chromium on Linux"));
1096 else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) // Firefox on Windows.
1098 // Check the Firefox on Windows user agent action.
1099 userAgentFirefoxWindowsActionPointer->setChecked(true);
1101 // Update the user agent menu action text.
1102 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Firefox on Windows"));
1104 else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) // Chrome on Windows.
1106 // Check the Chrome on Windows user agent action.
1107 userAgentChromeWindowsActionPointer->setChecked(true);
1109 // Update the user agent menu action text.
1110 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Chrome on Windows"));
1112 else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) // Edge on Windows.
1114 // Check the Edge on Windows user agent action.
1115 userAgentEdgeWindowsActionPointer->setChecked(true);
1117 // Update the user agent menu action text.
1118 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Edge on Windows"));
1120 else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) // Safari on macOS.
1122 // Check the Safari on macOS user agent action.
1123 userAgentSafariMacosActionPointer->setChecked(true);
1125 // Update the user agent menu action text.
1126 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Safari on macOS"));
1128 else // Custom user agent.
1130 // Check the user agent.
1131 userAgentCustomActionPointer->setChecked(true);
1133 // Update the user agent menu action text.
1134 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Custom"));
1136 // Set the custom user agent text.
1137 userAgentCustomActionPointer->setText(userAgent);
1139 // Set the custom user agent flag.
1140 customUserAgent = true;
1143 // Update the custom user agent enabled boolean.
1144 // 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.
1145 if (updateCustomUserAgentStatus)
1146 customUserAgentEnabled = customUserAgent;
1149 // Format the custom user agent.
1150 if (customUserAgentEnabled)
1152 // Enable the custom user agent.
1153 userAgentCustomActionPointer->setEnabled(true);
1157 // Disable the custom user agent.
1158 userAgentCustomActionPointer->setEnabled(false);
1160 // Reset the custom user agent text.
1161 userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
1165 void BrowserWindow::updateZoomFactorAction(const double &zoomFactor)
1167 // Set the current zoom factor.
1168 currentZoomFactor = zoomFactor;
1170 // Update the zoom factor action text, formatting the double with 2 decimal places.
1171 zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
1174 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
1176 // Update the search engine label.
1177 searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
1180 void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl)
1182 // Update the URL line edit if it does not have focus.
1183 if (!urlLineEditPointer->hasFocus())
1185 // Get the new URL string.
1186 QString newUrlString = newUrl.toString();
1188 // Update the URL line edit.
1189 urlLineEditPointer->setText(newUrlString);
1191 // Set the focus if the new URL is blank.
1192 if (newUrlString == QStringLiteral(""))
1193 urlLineEditPointer->setFocus();
1196 // Store the current URL.
1197 currentUrl = newUrl;
1200 void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
1202 // Update the user agent label.
1203 userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));
1206 void BrowserWindow::updateWindowTitle(const QString &title)
1208 // Update the window title.
1209 setWindowTitle(title);