#include "Settings.h"
#include "ui_SettingsPrivacy.h"
#include "ui_SettingsGeneral.h"
-#include "databases/CookiesDatabase.h"
#include "dialogs/CookiesDialog.h"
#include "dialogs/DomainSettingsDialog.h"
#include "helpers/SearchEngineHelper.h"
BrowserWindow::BrowserWindow() : KXmlGuiWindow()
{
// Initialize the variables.
- cookieListPointer = new std::list<QNetworkCookie>;
javaScriptEnabled = false;
localStorageEnabled = false;
- // Instantiate the main view pointer.
- browserViewPointer = new BrowserView(this);
+ // Instantiate the privacy tab widget pointer.
+ tabWidgetPointer = new TabWidget(this);
- // Set the main view as the central widget.
- setCentralWidget(browserViewPointer);
+ // Set the privacy tab widget as the central widget.
+ setCentralWidget(tabWidgetPointer);
// Get a handle for the action collection.
KActionCollection *actionCollectionPointer = this->actionCollection();
// Add the standard actions.
KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer);
- KStandardAction::print(browserViewPointer, SLOT(print()), actionCollectionPointer);
- KStandardAction::printPreview(browserViewPointer, SLOT(printPreview()), actionCollectionPointer);
+ KStandardAction::print(tabWidgetPointer, SLOT(print()), actionCollectionPointer);
+ KStandardAction::printPreview(tabWidgetPointer, SLOT(printPreview()), actionCollectionPointer);
KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer);
KStandardAction::redisplay(this, SLOT(refresh()), actionCollectionPointer);
fullScreenActionPointer = KStandardAction::fullScreen(this, SLOT(toggleFullScreen()), this, actionCollectionPointer);
searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing"));
searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo"));
domainSettingsActionPointer->setText(i18nc("Domain Settings action", "Domain Settings"));
- cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", cookieListPointer->size()));
+ cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", 0));
javaScriptActionPointer->setText(i18nc("JavaScript action", "JavaScript"));
localStorageActionPointer->setText(i18nc("The Local Storage action", "Local Storage"));
domStorageActionPointer->setText(i18nc("DOM Storage action", "DOM Storage"));
zoomFactorActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("zoom")));
domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("settings-configure")));
cookiesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("preferences-web-browser-cookies")));
- domStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("view-web-browser-dom-tree")));
+ domStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("code-class")));
// Update the on-the-fly menus.
- connect(browserViewPointer, SIGNAL(updateUserAgentActions(QString, bool)), this, SLOT(updateUserAgentActions(QString, bool)));
- connect(browserViewPointer, SIGNAL(updateZoomFactorAction(double)), this, SLOT(updateZoomFactorAction(double)));
- connect(browserViewPointer, SIGNAL(updateSearchEngineActions(QString, bool)), this, SLOT(updateSearchEngineActions(QString, bool)));
+ connect(tabWidgetPointer, SIGNAL(updateUserAgentActions(QString, bool)), this, SLOT(updateUserAgentActions(QString, bool)));
+ connect(tabWidgetPointer, SIGNAL(updateZoomFactorAction(double)), this, SLOT(updateZoomFactorAction(double)));
+ connect(tabWidgetPointer, SIGNAL(updateSearchEngineActions(QString, bool)), this, SLOT(updateSearchEngineActions(QString, bool)));
// Apply the on-the-fly settings when selected.
- connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
- connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), browserViewPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
+ connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), tabWidgetPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
+ connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), tabWidgetPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
+
+ // Process cookie changes.
+ connect(tabWidgetPointer, SIGNAL(updateCookiesAction(int)), this, SLOT(updateCookiesAction(int)));
// Display dialogs.
connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
connect(domStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleDomStorage()));
// Update the URL toolbar actions.
- connect(browserViewPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
- connect(browserViewPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool)));
- connect(browserViewPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool)));
- connect(browserViewPointer, SIGNAL(updateLocalStorageAction(bool)), this, SLOT(updateLocalStorageAction(bool)));
- connect(browserViewPointer, SIGNAL(updateDomStorageAction(bool)), this, SLOT(updateDomStorageAction(bool)));
+ connect(tabWidgetPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
+ connect(tabWidgetPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool)));
+ connect(tabWidgetPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool)));
+ connect(tabWidgetPointer, SIGNAL(updateLocalStorageAction(bool)), this, SLOT(updateLocalStorageAction(bool)));
+ connect(tabWidgetPointer, SIGNAL(updateDomStorageAction(bool)), this, SLOT(updateDomStorageAction(bool)));
// Setup the GUI based on the browser_ui.rc file.
setupGUI(StandardWindowOption::Default, ("browser_ui.rc"));
connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
// Update the URL line edit on page loads.
- connect(browserViewPointer, SIGNAL(updateUrlLineEdit(QUrl)), this, SLOT(updateUrlLineEdit(QUrl)));
+ connect(tabWidgetPointer, SIGNAL(updateUrlLineEdit(QUrl)), this, SLOT(updateUrlLineEdit(QUrl)));
// Get a handle for the status bar.
QStatusBar *statusBarPointer = statusBar();
statusBarPointer->addPermanentWidget(progressBarPointer);
// Update the status bar with the URL when a link is hovered.
- connect(browserViewPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
+ connect(tabWidgetPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
// Update the progress bar.
- connect(browserViewPointer, SIGNAL(showProgressBar(const int)), this, SLOT(showProgressBar(const int)));
- connect(browserViewPointer, SIGNAL(hideProgressBar()), progressBarPointer, SLOT(hide()));
+ connect(tabWidgetPointer, SIGNAL(showProgressBar(const int)), this, SLOT(showProgressBar(const int)));
+ connect(tabWidgetPointer, SIGNAL(hideProgressBar()), progressBarPointer, SLOT(hide()));
- // Clear the URL line edit focus when requested.
- connect(browserViewPointer, SIGNAL(clearUrlLineEditFocus()), this, SLOT(clearUrlLineEditFocus()));
+ // Update the URL line edit focus.
+ connect(tabWidgetPointer, SIGNAL(clearUrlLineEditFocus()), this, SLOT(clearUrlLineEditFocus()));
// Get the URL line edit palettes.
noDomainSettingsPalette = urlLineEditPointer->palette();
domainSettingsPalette.setColor(QPalette::Base, QColor("#C8E6C9"));
// Update the applied palette.
- connect(browserViewPointer, SIGNAL(updateDomainSettingsIndicator(bool, QString)), this, SLOT(updateDomainSettingsIndicator(bool, QString)));
-
- // Process cookie changes.
- connect(browserViewPointer, SIGNAL(addCookie(QNetworkCookie)), this, SLOT(addCookieToList(QNetworkCookie)));
- connect(browserViewPointer, SIGNAL(removeCookie(QNetworkCookie)), this, SLOT(removeCookieFromList(QNetworkCookie)));
+ connect(tabWidgetPointer, SIGNAL(updateDomainSettingsIndicator(const bool)), this, SLOT(updateDomainSettingsIndicator(const bool)));
// Process full screen requests.
- connect(browserViewPointer, SIGNAL(fullScreenRequested(bool)), this, SLOT(fullScreenRequested(bool)));
+ connect(tabWidgetPointer, SIGNAL(fullScreenRequested(bool)), this, SLOT(fullScreenRequested(bool)));
// Create keyboard shortcuts.
+ QShortcut *ctrlTShortcutPointer = new QShortcut(QKeySequence(i18nc("The open new tab shortcut.", "Ctrl+t")), this);
QShortcut *f11ShortcutPointer = new QShortcut(QKeySequence(i18nc("The toggle full screen shortcut.", "F11")), this);
QShortcut *escapeShortcutPointer = new QShortcut(QKeySequence::Cancel, this);
// Connect the keyboard shortcuts to the actions.
+ connect(ctrlTShortcutPointer, SIGNAL(activated()), tabWidgetPointer, SLOT(addTab()));
connect(f11ShortcutPointer, SIGNAL(activated()), fullScreenActionPointer, SLOT(trigger()));
connect(escapeShortcutPointer, SIGNAL(activated()), this, SLOT(escape()));
// Load the initial website.
- browserViewPointer->loadInitialWebsite();
-}
-
-void BrowserWindow::addCookieToList(const QNetworkCookie &newCookie) const
-{
- //qDebug() << "Add cookie: " << newCookie.toRawForm();
-
- // Add the new cookie to the list.
- cookieListPointer->push_front(newCookie);
-
- // Update the action text.
- cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", cookieListPointer->size()));
-
- // Update the cookie if it is durable and has new data.
- if (CookiesDatabase::isUpdate(newCookie))
- CookiesDatabase::updateCookie(newCookie);
+ tabWidgetPointer->loadInitialWebsite();
}
void BrowserWindow::addOrEditDomainSettings() const
// Create the domain settings dialog pointer.
DomainSettingsDialog *domainSettingsDialogPointer;
+ // Get the current domain settings name.
+ QString ¤tDomainSettingsName = tabWidgetPointer->getDomainSettingsName();
+
// Run the commands according to the current domain settings status.
- if (currentDomainSettingsDomain == "") // Domain settings are not currently applied.
+ if (currentDomainSettingsName == QStringLiteral("")) // Domain settings are not currently applied.
{
// Instruct the domain settings dialog to add a new domain.
domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::ADD_DOMAIN, currentUrl.host());
else // Domain settings are currently applied.
{
// Instruct the domain settings dialog to edit the current domain.
- domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsDomain);
+ domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsName);
}
// Set the dialog window title.
domainSettingsDialogPointer->show();
// Reload the tabs when domain settings are updated.
- connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
+ connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
}
void BrowserWindow::back() const
urlLineEditPointer->clearFocus();
// Go back.
- browserViewPointer->back();
+ tabWidgetPointer->back();
}
void BrowserWindow::clearUrlLineEditFocus() const
urlLineEditPointer->clearFocus();
// Go forward.
- browserViewPointer->forward();
+ tabWidgetPointer->forward();
}
void BrowserWindow::fullScreenRequested(const bool toggleOn)
menuBar()->setVisible(false);
navigationToolBarPointer->setVisible(false);
urlToolBarPointer->setVisible(false);
+ tabWidgetPointer->setTabBarVisible(false);
statusBar()->setVisible(false);
}
else // Turn full screen mode off.
menuBar()->setVisible(true);
navigationToolBarPointer->setVisible(true);
urlToolBarPointer->setVisible(true);
+ tabWidgetPointer->setTabBarVisible(true);
statusBar()->setVisible(true);
}
}
currentZoomFactor = newZoomFactor;
// Set the new zoom factor.
- browserViewPointer->applyOnTheFlyZoomFactor(newZoomFactor);
+ tabWidgetPointer->applyOnTheFlyZoomFactor(newZoomFactor);
// Update the on-the-fly action text.
updateZoomFactorAction(newZoomFactor);
urlLineEditPointer->clearFocus();
// Go home.
- browserViewPointer->home();
+ tabWidgetPointer->home();
}
void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
urlLineEditPointer->clearFocus();
// Load the URL.
- browserViewPointer->loadUrlFromLineEdit(url);
+ tabWidgetPointer->loadUrlFromLineEdit(url);
}
void BrowserWindow::refresh() const
urlLineEditPointer->clearFocus();
// Refresh the web page.
- browserViewPointer->refresh();
-}
-
-void BrowserWindow::removeCookieFromList(const QNetworkCookie &cookie) const
-{
- //qDebug() << "Remove cookie: " << cookie.toRawForm();
-
- // Remove the cookie from the list.
- cookieListPointer->remove(cookie);
-
- // Update the action text.
- cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", cookieListPointer->size()));
+ tabWidgetPointer->refresh();
}
void BrowserWindow::showCookiesDialog()
urlLineEditPointer->clearFocus();
// Instantiate the cookie settings dialog.
- CookiesDialog *cookiesDialogPointer = new CookiesDialog(cookieListPointer);
+ CookiesDialog *cookiesDialogPointer = new CookiesDialog(tabWidgetPointer->getCookieList());
// Show the dialog.
cookiesDialogPointer->show();
// Connect the dialog signals.
- connect(cookiesDialogPointer, SIGNAL(addCookie(QNetworkCookie)), browserViewPointer, SLOT(addCookieToStore(QNetworkCookie)));
- connect(cookiesDialogPointer, SIGNAL(deleteAllCookies()), browserViewPointer, SLOT(deleteAllCookies()));
- connect(cookiesDialogPointer, SIGNAL(deleteCookie(QNetworkCookie)), browserViewPointer, SLOT(deleteCookieFromStore(QNetworkCookie)));
+ connect(cookiesDialogPointer, SIGNAL(addCookie(QNetworkCookie)), tabWidgetPointer, SLOT(addCookieToStore(QNetworkCookie)));
+ connect(cookiesDialogPointer, SIGNAL(deleteAllCookies()), tabWidgetPointer, SLOT(deleteAllCookies()));
+ connect(cookiesDialogPointer, SIGNAL(deleteCookie(QNetworkCookie)), tabWidgetPointer, SLOT(deleteCookieFromStore(QNetworkCookie)));
}
void BrowserWindow::showDownloadLocationBrowseDialog() const
domainSettingsDialogPointer->show();
// Reload the tabs when domain settings are updated.
- connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
+ connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
}
void BrowserWindow::showProgressBar(const int &progress) const
configDialogPointer->resize(1000, 500);
// Apply the settings when they are updated.
- connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyApplicationSettings()));
- connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
+ connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyApplicationSettings()));
+ connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyDomainSettingsAndReload()));
}
QSize BrowserWindow::sizeHint() const
urlLineEditPointer->clearFocus();
// Toggle DOM storage.
- browserViewPointer->toggleDomStorage();
+ tabWidgetPointer->toggleDomStorage();
}
void BrowserWindow::toggleJavaScript() const
urlLineEditPointer->clearFocus();
// Toggle JavaScript.
- browserViewPointer->toggleJavaScript();
+ tabWidgetPointer->toggleJavaScript();
}
void BrowserWindow::toggleLocalStorage() const
urlLineEditPointer->clearFocus();
// Toggle local storage.
- browserViewPointer->toggleLocalStorage();
+ tabWidgetPointer->toggleLocalStorage();
}
void BrowserWindow::toggleFullScreen()
urlToolBarPointer->setVisible(false);
}
+ // Hide the tab bar if specified.
+ if (Settings::fullScreenHideTabBar())
+ tabWidgetPointer->setTabBarVisible(false);
+
// Hide the status bar if specified.
if (Settings::fullScreenHideStatusBar())
statusBar()->setVisible(false);
navigationToolBarPointer->setVisible(true);
urlToolBarPointer->setVisible(true);
+ // Show the tab bar.
+ tabWidgetPointer->setTabBarVisible(true);
+
// Show the status bar.
statusBar()->setVisible(true);
}
}
+void BrowserWindow::updateCookiesAction(const int numberOfCookies) const
+{
+ // Update the action text.
+ cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", numberOfCookies));
+}
+
void BrowserWindow::updateDomStorageAction(const bool &isEnabled) const
{
// Set the action checked status.
domStorageActionPointer->setChecked(isEnabled);
}
-void BrowserWindow::updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain)
+void BrowserWindow::updateDomainSettingsIndicator(const bool status)
{
// Set the domain palette according to the status.
if (status)
urlLineEditPointer->setPalette(domainSettingsPalette);
else
urlLineEditPointer->setPalette(noDomainSettingsPalette);
-
- // Store the domain.
- currentDomainSettingsDomain = domainSettingsDomain;
}
void BrowserWindow::updateJavaScriptAction(const bool &isEnabled)
// Update the user agent menu action text.
userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Privacy Browser"));
}
- else if (userAgent == BrowserView::webEngineDefaultUserAgent) // WebEngine default.
+ else if (userAgent == TabWidget::webEngineDefaultUserAgent) // WebEngine default.
{
// check the WebEngine default user agent action.
userAgentWebEngineDefaultActionPointer->setChecked(true);
// Update the URL line edit if it does not have focus.
if (!urlLineEditPointer->hasFocus())
{
+ // Get the new URL string.
+ QString newUrlString = newUrl.toString();
+
// Update the URL line edit.
- urlLineEditPointer->setText(newUrl.toString());
+ urlLineEditPointer->setText(newUrlString);
+
+ // Set the focus if the new URL is blank.
+ if (newUrlString == QStringLiteral(""))
+ urlLineEditPointer->setFocus();
}
// Store the current URL.