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 activated.
439 // Clear the text in the line edit.
440 findTextLineEditPointer->clear();
442 // Clear the search in the WebEngine.
443 tabWidgetPointer->findText(QStringLiteral(""));
447 void BrowserWindow::fileNew() const
449 // Display a new instance of Privacy Browser.
450 (new BrowserWindow)->show();
453 void BrowserWindow::findNext() const
455 // Get the find string.
456 const QString findString = findTextLineEditPointer->text();
458 // Search for the text if it is not empty.
459 if (!findString.isEmpty())
460 tabWidgetPointer->findText(findString);
463 void BrowserWindow::findPrevious() const
465 // Get the find string.
466 const QString findString = findTextLineEditPointer->text();
468 // Search for the text if it is not empty.
469 if (!findString.isEmpty())
470 tabWidgetPointer->findPrevious(findString);
473 void BrowserWindow::forward() const
475 // Remove the focus from the URL line edit.
476 urlLineEditPointer->clearFocus();
479 tabWidgetPointer->forward();
482 void BrowserWindow::fullScreenRequested(const bool toggleOn)
484 // Toggle full screen mode.
485 if (toggleOn) // Turn full screen mode on.
487 // Set the window to be full screen.
488 fullScreenActionPointer->setFullScreen(window(), true);
490 // Hide all the bars.
491 menuBar()->setVisible(false);
492 navigationToolBarPointer->setVisible(false);
493 urlToolBarPointer->setVisible(false);
494 tabWidgetPointer->setTabBarVisible(false);
495 statusBar()->setVisible(false);
497 else // Turn full screen mode off.
499 // Set the window to not be full screen.
500 fullScreenActionPointer->setFullScreen(window(), false);
502 // Show all the bars.
503 menuBar()->setVisible(true);
504 navigationToolBarPointer->setVisible(true);
505 urlToolBarPointer->setVisible(true);
506 tabWidgetPointer->setTabBarVisible(true);
507 statusBar()->setVisible(true);
511 void BrowserWindow::getZoomFactorFromUser()
513 // Create an OK flag.
516 // 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.
517 double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"),
518 i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
519 currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
521 // Update the zoom factor if the user clicked OK.
524 // Update the current zoom factor.
525 currentZoomFactor = newZoomFactor;
527 // Set the new zoom factor.
528 tabWidgetPointer->applyOnTheFlyZoomFactor(newZoomFactor);
530 // Update the on-the-fly action text.
531 updateZoomFactorAction(newZoomFactor);
535 void BrowserWindow::hideFindTextActions() const
537 // Hide the find text actions.
538 findTextLineEditActionPointer->setVisible(false);
539 findTextLabelActionPointer->setVisible(false);
540 findNextActionPointer->setVisible(false);
541 findPreviousActionPointer->setVisible(false);
542 findCaseSensitiveActionPointer->setVisible(false);
543 hideFindTextActionPointer->setVisible(false);
546 void BrowserWindow::home() const
548 // Remove the focus from the URL line edit.
549 urlLineEditPointer->clearFocus();
552 tabWidgetPointer->home();
555 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
557 // Remove the focus from the URL line edit.
558 urlLineEditPointer->clearFocus();
561 tabWidgetPointer->loadUrlFromLineEdit(url);
564 void BrowserWindow::refresh() const
566 // Remove the focus from the URL line edit.
567 urlLineEditPointer->clearFocus();
569 // Refresh the web page.
570 tabWidgetPointer->refresh();
573 void BrowserWindow::showCookiesDialog()
575 // Remove the focus from the URL line edit.
576 urlLineEditPointer->clearFocus();
578 // Instantiate the cookie settings dialog.
579 CookiesDialog *cookiesDialogPointer = new CookiesDialog(tabWidgetPointer->getCookieList());
582 cookiesDialogPointer->show();
584 // Connect the dialog signals.
585 connect(cookiesDialogPointer, SIGNAL(addCookie(QNetworkCookie)), tabWidgetPointer, SLOT(addCookieToStore(QNetworkCookie)));
586 connect(cookiesDialogPointer, SIGNAL(deleteAllCookies()), tabWidgetPointer, SLOT(deleteAllCookies()));
587 connect(cookiesDialogPointer, SIGNAL(deleteCookie(QNetworkCookie)), tabWidgetPointer, SLOT(deleteCookieFromStore(QNetworkCookie)));
590 void BrowserWindow::showDownloadLocationBrowseDialog() const
592 // Get the current download location.
593 QString currentDownloadLocation = downloadLocationComboBoxPointer->currentText();
595 // Resolve the system download directory if specified.
596 if (currentDownloadLocation == QStringLiteral("System Download Directory"))
597 currentDownloadLocation = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
599 // Get the new download location.
600 QString newDownloadLocation = QFileDialog::getExistingDirectory(configDialogPointer, i18nc("Select download location dialog caption", "Select Download Location"), currentDownloadLocation);
602 // Populate the download location combo box according to the new download location.
603 if (newDownloadLocation == QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)) // The default download location was selected.
605 // Populate the download location with the default text.
606 downloadLocationComboBoxPointer->setCurrentText("System Download Directory");
608 else if (newDownloadLocation != QStringLiteral("")) // A different directory was selected.
610 // Populate the download location.
611 downloadLocationComboBoxPointer->setCurrentText(newDownloadLocation);
615 void BrowserWindow::showDomainSettingsDialog() const
617 // Remove the focus from the URL line edit.
618 urlLineEditPointer->clearFocus();
620 // Instantiate the domain settings dialog.
621 DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
624 domainSettingsDialogPointer->show();
626 // Reload the tabs when domain settings are updated.
627 connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
630 void BrowserWindow::showFindTextActions() const
632 // Show the find text actions.
633 findTextLineEditActionPointer->setVisible(true);
634 findTextLabelActionPointer->setVisible(true);
635 findNextActionPointer->setVisible(true);
636 findPreviousActionPointer->setVisible(true);
637 findCaseSensitiveActionPointer->setVisible(true);
638 hideFindTextActionPointer->setVisible(true);
640 // Set the focus on the find line edit.
641 findTextLineEditPointer->setFocus();
643 // Select all the text in the find line edit.
644 findTextLineEditPointer->selectAll();
647 void BrowserWindow::showProgressBar(const int &progress) const
649 // Set the progress bar value.
650 progressBarPointer->setValue(progress);
652 // Show the progress bar.
653 progressBarPointer->show();
656 void BrowserWindow::showSettingsDialog()
658 // Create the settings widgets.
659 QWidget *privacySettingsWidgetPointer = new QWidget;
660 QWidget *generalSettingsWidgetPointer = new QWidget;
661 QWidget *spellCheckSettingsWidgetPointer = new QWidget;
663 // Instantiate the settings UI.
664 Ui::PrivacySettings privacySettingsUi;
665 Ui::GeneralSettings generalSettingsUi;
666 Ui::SpellCheckSettings spellCheckSettingsUi;
668 // Setup the UI to display the settings widgets.
669 privacySettingsUi.setupUi(privacySettingsWidgetPointer);
670 generalSettingsUi.setupUi(generalSettingsWidgetPointer);
671 spellCheckSettingsUi.setupUi(spellCheckSettingsWidgetPointer);
673 // Get handles for the widgets.
674 QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
675 userAgentLabelPointer = privacySettingsUi.userAgentLabel;
676 QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine;
677 searchEngineLabelPointer = generalSettingsUi.searchEngineLabel;
678 downloadLocationComboBoxPointer = generalSettingsUi.kcfg_downloadLocation;
679 QPushButton *browseButtonPointer = generalSettingsUi.browseButton;
680 QListWidget *spellCheckListWidgetPointer = spellCheckSettingsUi.spellCheckListWidget;
682 // Populate the combo box labels.
683 updateUserAgentLabel(userAgentComboBoxPointer->currentText());
684 updateSearchEngineLabel(searchEngineComboBoxPointer->currentText());
686 // Update the labels when the combo boxes change.
687 connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString)));
688 connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString)));
690 // Connect the download location directory browse button.
691 connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(showDownloadLocationBrowseDialog()));
693 // Create a dictionaries QDir from the `QTWEBENGINE_DICTIONARIES_PATH` environment variable.
694 QDir dictionariesDir = QDir(qEnvironmentVariable("QTWEBENGINE_DICTIONARIES_PATH"));
696 // Get a dictionaries string list.
697 QStringList dictionariesStringList = dictionariesDir.entryList(QStringList(QLatin1String("*.bdic")), QDir::Files | QDir::NoSymLinks);
699 // Remove the `.bdic` file extensions from the dictionaries list.
700 dictionariesStringList.replaceInStrings(QLatin1String(".bdic"), QLatin1String(""));
702 // Get a list of the enabled spell check languages.
703 QStringList enabledSpellCheckLanguagesList = Settings::spellCheckLanguages();
705 // Add each dictionary to the spell check list widget.
706 foreach(QString dictionaryString, dictionariesStringList)
708 // Create a new list widget item pointer named after the dictionary string.
709 QListWidgetItem *listWidgetItemPointer = new QListWidgetItem(dictionaryString, spellCheckListWidgetPointer);
711 // Set the list widget item pointer to be checkable.
712 listWidgetItemPointer->setFlags(listWidgetItemPointer->flags() | Qt::ItemIsUserCheckable);
714 // Check the language if it is currently enabled.
715 if (enabledSpellCheckLanguagesList.contains(dictionaryString))
716 listWidgetItemPointer->setCheckState(Qt::Checked);
718 listWidgetItemPointer->setCheckState(Qt::Unchecked);
720 // Add the list widget item to the widget.
721 spellCheckListWidgetPointer->addItem(listWidgetItemPointer);
724 // Get a handle for the KConfig skeleton.
725 KConfigSkeleton *kConfigSkeletonPointer = Settings::self();
727 // Instantiate a settings config dialog from the settings.kcfg file.
728 configDialogPointer = new KConfigDialog(this, QLatin1String("settings"), kConfigSkeletonPointer);
730 // Add the settings widgets as config dialog pages.
731 configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("Settings tab title", "Privacy"), QLatin1String("privacy-browser"));
732 configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("Settings tab title", "General"), QLatin1String("breeze-settings"));
733 configDialogPointer->addPage(spellCheckSettingsWidgetPointer, i18nc("Settings tab title", "Spell Check"), QLatin1String("tools-check-spelling"));
735 // Get handles for the buttons.
736 QPushButton *applyButtonPointer = configDialogPointer->button(QDialogButtonBox::Apply);
737 QPushButton *okButtonPointer = configDialogPointer->button(QDialogButtonBox::Ok);
739 // Prevent interaction with the parent window while the dialog is open.
740 configDialogPointer->setWindowModality(Qt::WindowModal);
743 configDialogPointer->show();
745 // TODO. KConfigDialog does not respect expanding size policies. <https://redmine.stoutner.com/issues/823>
746 //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
747 //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
748 //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
749 //configDialogPointer->adjustSize();
751 // Expand the config dialog.
752 configDialogPointer->resize(1000, 500);
754 // Create a save spell check languages lambda.
755 auto saveSpellCheckLanguages = [spellCheckListWidgetPointer, kConfigSkeletonPointer, this] ()
757 // Create a list of enabled languages.
758 QStringList newSpellCheckLanguages = QStringList();
760 // Get a count of all the languages.
761 int allLanguagesCount = spellCheckListWidgetPointer->count();
763 // Get a list of all the checked languages.
764 for (int i = 0; i < allLanguagesCount; ++i) {
765 // Get the language item.
766 QListWidgetItem *languageItemPointer = spellCheckListWidgetPointer->item(i);
768 // Add the item to the enabled languages if it is checked.
769 if (languageItemPointer->checkState() == Qt::Checked)
770 newSpellCheckLanguages.append(languageItemPointer->text());
773 // Update the spell check languages.
774 if (Settings::spellCheckLanguages() != newSpellCheckLanguages)
776 // Update the spell check languages.
777 Settings::setSpellCheckLanguages(newSpellCheckLanguages);
779 // Write the settings to disk.
780 kConfigSkeletonPointer->save();
783 // Apply the spell check languages.
784 tabWidgetPointer->applySpellCheckLanguages();
788 connect(applyButtonPointer, &QPushButton::clicked, this, saveSpellCheckLanguages);
789 connect(okButtonPointer, &QPushButton::clicked, this, saveSpellCheckLanguages);
791 // Apply the settings handled by KConfig.
792 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyApplicationSettings()));
793 connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
796 QSize BrowserWindow::sizeHint() const
798 // Return the default window size.
799 return QSize(1500, 1200);
802 void BrowserWindow::toggleDomStorage() const
804 // Remove the focus from the URL line edit.
805 urlLineEditPointer->clearFocus();
807 // Toggle DOM storage.
808 tabWidgetPointer->toggleDomStorage();
811 void BrowserWindow::toggleFindCaseSensitive() const
813 // Get the current find string.
814 const QString findString = findTextLineEditPointer->text();
816 // Toggle find case sensitive.
817 tabWidgetPointer->toggleFindCaseSensitive(findString);
820 void BrowserWindow::toggleJavaScript() const
822 // Remove the focus from the URL line edit.
823 urlLineEditPointer->clearFocus();
825 // Toggle JavaScript.
826 tabWidgetPointer->toggleJavaScript();
829 void BrowserWindow::toggleLocalStorage() const
831 // Remove the focus from the URL line edit.
832 urlLineEditPointer->clearFocus();
834 // Toggle local storage.
835 tabWidgetPointer->toggleLocalStorage();
838 void BrowserWindow::toggleFullScreen()
840 // Toggle the full screen status.
841 if (fullScreenActionPointer->isChecked()) // Enable full screen browsing mode.
843 // Enable full screen mode.
844 fullScreenActionPointer->setFullScreen(window(), true);
846 // Hide the menu bar if specified.
847 if (Settings::fullScreenHideMenuBar())
848 menuBar()->setVisible(false);
850 // Hide the toolbars if specified.
851 if (Settings::fullScreenHideToolBars())
853 navigationToolBarPointer->setVisible(false);
854 urlToolBarPointer->setVisible(false);
857 // Hide the tab bar if specified.
858 if (Settings::fullScreenHideTabBar())
859 tabWidgetPointer->setTabBarVisible(false);
861 // Hide the status bar if specified.
862 if (Settings::fullScreenHideStatusBar())
863 statusBar()->setVisible(false);
865 else // Disable full screen browsing mode.
867 // Disable full screen mode.
868 fullScreenActionPointer->setFullScreen(window(), false);
870 // Show the menu bar.
871 menuBar()->setVisible(true);
873 // Show the toolbars.
874 navigationToolBarPointer->setVisible(true);
875 urlToolBarPointer->setVisible(true);
878 tabWidgetPointer->setTabBarVisible(true);
880 // Show the status bar.
881 statusBar()->setVisible(true);
885 void BrowserWindow::updateCookiesAction(const int numberOfCookies) const
887 // Update the action text.
888 cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", numberOfCookies));
891 void BrowserWindow::updateDomStorageAction(const bool &isEnabled) const
893 // Set the action checked status.
894 domStorageActionPointer->setChecked(isEnabled);
897 void BrowserWindow::updateDomainSettingsIndicator(const bool status)
899 // Set the domain palette according to the status.
901 urlLineEditPointer->setPalette(positiveBackgroundPalette);
903 urlLineEditPointer->setPalette(normalBackgroundPalette);
906 void BrowserWindow::updateFindText(const QString &text, const bool findCaseSensitive) const
909 findTextLineEditPointer->setText(text);
911 // Set the find case sensitive action checked status.
912 findCaseSensitiveActionPointer->setChecked(findCaseSensitive);
915 void BrowserWindow::updateFindTextResults(const QWebEngineFindTextResult &findTextResult) const
917 // Update the find text label.
918 findTextLabelPointer->setText(QStringLiteral(" %1/%2 ").arg(findTextResult.activeMatch()).arg(findTextResult.numberOfMatches()));
920 // Set the background color according to the find status.
921 if (findTextLineEditPointer->text().isEmpty())
922 findTextLineEditPointer->setPalette(normalBackgroundPalette);
923 else if (findTextResult.numberOfMatches() == 0)
924 findTextLineEditPointer->setPalette(negativeBackgroundPalette);
926 findTextLineEditPointer->setPalette(positiveBackgroundPalette);
929 void BrowserWindow::updateJavaScriptAction(const bool &isEnabled)
931 // Update the JavaScript status.
932 javaScriptEnabled = isEnabled;
934 // Set the icon according to the status.
935 if (javaScriptEnabled)
936 javaScriptActionPointer->setIcon(QIcon(QStringLiteral(":/icons/javascript-warning")));
938 javaScriptActionPointer->setIcon(QIcon(QStringLiteral(":/icons/privacy-mode")));
940 // Set the action checked status.
941 javaScriptActionPointer->setChecked(javaScriptEnabled);
943 // Update the status of the DOM storage action.
944 domStorageActionPointer->setEnabled(javaScriptEnabled & localStorageEnabled);
947 void BrowserWindow::updateLocalStorageAction(const bool &isEnabled)
949 // Update the local storage status.
950 localStorageEnabled = isEnabled;
953 if (localStorageEnabled)
954 localStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("disk-quota-high")));
956 localStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("disk-quota")));
958 // Set the action checked status.
959 localStorageActionPointer->setChecked(localStorageEnabled);
961 // Update the status of the DOM storage action.
962 domStorageActionPointer->setEnabled(localStorageEnabled & javaScriptEnabled);
965 void BrowserWindow::updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus)
967 // Initialize the custom search engine flag.
968 bool customSearchEngine = false;
970 if (searchEngine == "Mojeek") // Mojeek.
972 // Check the Mojeek user agent action.
973 searchEngineMojeekActionPointer->setChecked(true);
975 // Update the search engine menu action text.
976 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Mojeek"));
978 else if (searchEngine == "Monocles") // Monocles.
980 // Check the Monocles user agent action.
981 searchEngineMonoclesActionPointer->setChecked(true);
983 // Update the search engine menu action text.
984 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Monocles"));
986 else if (searchEngine == "MetaGer") // MetaGer.
988 // Check the MetaGer user agent action.
989 searchEngineMetagerActionPointer->setChecked(true);
991 // Update the search engine menu action text.
992 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - MetaGer"));
994 else if (searchEngine == "Google") // Google.
996 // Check the Google user agent action.
997 searchEngineGoogleActionPointer->setChecked(true);
999 // Update the search engine menu action text.
1000 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Google"));
1002 else if (searchEngine == "Bing") // Bing.
1004 // Check the Bing user agent action.
1005 searchEngineBingActionPointer->setChecked(true);
1007 // Update the search engine menu action text.
1008 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Bing"));
1010 else if (searchEngine == "Yahoo") // Yahoo.
1012 // Check the Yahoo user agent action.
1013 searchEngineYahooActionPointer->setChecked(true);
1015 // Update the search engine menu action text.
1016 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Yahoo"));
1018 else // Custom search engine.
1020 // Check the user agent.
1021 searchEngineCustomActionPointer->setChecked(true);
1023 // Update the search engine menu action text.
1024 searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Custom"));
1026 // Set the custom search engine text.
1027 searchEngineCustomActionPointer->setText(searchEngine);
1029 // Set the custom search engine flag.
1030 customSearchEngine = true;
1033 // Update the custom search engine enabled boolean.
1034 if (updateCustomSearchEngineStatus)
1035 customSearchEngineEnabled = customSearchEngine;
1037 // Format the custom search engine.
1038 if (customSearchEngineEnabled)
1040 // Enable the custom search engine.
1041 searchEngineCustomActionPointer->setEnabled(true);
1045 // Disable the custom search engine.
1046 searchEngineCustomActionPointer->setEnabled(false);
1048 // Reset the custom search engine text.
1049 searchEngineCustomActionPointer->setText(i18nc("@action", "Custom"));
1053 void BrowserWindow::updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus)
1055 // Initialize the custom user agent flag.
1056 bool customUserAgent = false;
1058 // Check the indicated on-the-fly user agent.
1059 if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) // Privacy Browser.
1061 // Check the Privacy Browser user agent action.
1062 userAgentPrivacyBrowserActionPointer->setChecked(true);
1064 // Update the user agent menu action text.
1065 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Privacy Browser"));
1067 else if (userAgent == TabWidget::webEngineDefaultUserAgent) // WebEngine default.
1069 // check the WebEngine default user agent action.
1070 userAgentWebEngineDefaultActionPointer->setChecked(true);
1072 // Update the user agent menu action text.
1073 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - WebEngine default"));
1075 else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) // Firefox on Linux.
1077 // Check the Firefox on Linux user agent action.
1078 userAgentFirefoxLinuxActionPointer->setChecked(true);
1080 // Update the user agent menu action text.
1081 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Firefox on Linux"));
1083 else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) // Chromium on Linux.
1085 // Check the Chromium on Linux user agent action.
1086 userAgentChromiumLinuxActionPointer->setChecked(true);
1088 // Update the user agent menu action text.
1089 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Chromium on Linux"));
1091 else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) // Firefox on Windows.
1093 // Check the Firefox on Windows user agent action.
1094 userAgentFirefoxWindowsActionPointer->setChecked(true);
1096 // Update the user agent menu action text.
1097 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Firefox on Windows"));
1099 else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) // Chrome on Windows.
1101 // Check the Chrome on Windows user agent action.
1102 userAgentChromeWindowsActionPointer->setChecked(true);
1104 // Update the user agent menu action text.
1105 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Chrome on Windows"));
1107 else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) // Edge on Windows.
1109 // Check the Edge on Windows user agent action.
1110 userAgentEdgeWindowsActionPointer->setChecked(true);
1112 // Update the user agent menu action text.
1113 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Edge on Windows"));
1115 else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) // Safari on macOS.
1117 // Check the Safari on macOS user agent action.
1118 userAgentSafariMacosActionPointer->setChecked(true);
1120 // Update the user agent menu action text.
1121 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Safari on macOS"));
1123 else // Custom user agent.
1125 // Check the user agent.
1126 userAgentCustomActionPointer->setChecked(true);
1128 // Update the user agent menu action text.
1129 userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Custom"));
1131 // Set the custom user agent text.
1132 userAgentCustomActionPointer->setText(userAgent);
1134 // Set the custom user agent flag.
1135 customUserAgent = true;
1138 // Update the custom user agent enabled boolean.
1139 // 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.
1140 if (updateCustomUserAgentStatus)
1141 customUserAgentEnabled = customUserAgent;
1144 // Format the custom user agent.
1145 if (customUserAgentEnabled)
1147 // Enable the custom user agent.
1148 userAgentCustomActionPointer->setEnabled(true);
1152 // Disable the custom user agent.
1153 userAgentCustomActionPointer->setEnabled(false);
1155 // Reset the custom user agent text.
1156 userAgentCustomActionPointer->setText(i18nc("@action", "Custom"));
1160 void BrowserWindow::updateZoomFactorAction(const double &zoomFactor)
1162 // Set the current zoom factor.
1163 currentZoomFactor = zoomFactor;
1165 // Update the zoom factor action text, formatting the double with 2 decimal places.
1166 zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
1169 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
1171 // Update the search engine label.
1172 searchEngineLabelPointer->setText(SearchEngineHelper::getSearchUrl(searchEngineString));
1175 void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl)
1177 // Update the URL line edit if it does not have focus.
1178 if (!urlLineEditPointer->hasFocus())
1180 // Get the new URL string.
1181 QString newUrlString = newUrl.toString();
1183 // Update the URL line edit.
1184 urlLineEditPointer->setText(newUrlString);
1186 // Set the focus if the new URL is blank.
1187 if (newUrlString == QStringLiteral(""))
1188 urlLineEditPointer->setFocus();
1191 // Store the current URL.
1192 currentUrl = newUrl;
1195 void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
1197 // Update the user agent label.
1198 userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));
1201 void BrowserWindow::updateWindowTitle(const QString &title)
1203 // Update the window title.
1204 setWindowTitle(title);