X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=src%2Fwindows%2FBrowserWindow.cpp;h=acf72db504019702db450969a89e17523b0a0681;hb=fb2760a23bc59d63c74e18c92628ef03ccd8bf3a;hp=2484061633266d0e7e3d5d49ddb57c38aaed5ad1;hpb=1ce11bc5f6630bf81aa67bdaca411fbea93dc017;p=PrivacyBrowserPC.git diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index 2484061..acf72db 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -22,7 +22,6 @@ #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" @@ -33,6 +32,7 @@ #include // Qt toolkit headers. +#include #include #include #include @@ -43,30 +43,29 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() { // Initialize the variables. - cookieListPointer = new std::list; 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); QAction *backActionPointer = KStandardAction::back(this, SLOT(back()), actionCollectionPointer); QAction *forwardActionPointer = KStandardAction::forward(this, SLOT(forward()), actionCollectionPointer); KStandardAction::home(this, SLOT(home()), actionCollectionPointer); - KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollectionPointer); + KStandardAction::preferences(this, SLOT(showSettingsDialog()), actionCollectionPointer); // Add the custom actions. userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_privacy_browser")); @@ -151,7 +150,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() 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")); @@ -176,16 +175,19 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() 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())); @@ -198,11 +200,11 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() 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")); @@ -243,7 +245,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() 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(); @@ -255,14 +257,14 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() 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(); @@ -272,40 +274,23 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() 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 @@ -316,8 +301,11 @@ 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()); @@ -325,7 +313,7 @@ void BrowserWindow::addOrEditDomainSettings() const 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. @@ -338,7 +326,7 @@ void BrowserWindow::addOrEditDomainSettings() 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::back() const @@ -347,7 +335,7 @@ void BrowserWindow::back() const urlLineEditPointer->clearFocus(); // Go back. - browserViewPointer->back(); + tabWidgetPointer->back(); } void BrowserWindow::clearUrlLineEditFocus() const @@ -375,7 +363,7 @@ void BrowserWindow::forward() const urlLineEditPointer->clearFocus(); // Go forward. - browserViewPointer->forward(); + tabWidgetPointer->forward(); } void BrowserWindow::fullScreenRequested(const bool toggleOn) @@ -390,6 +378,7 @@ 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. @@ -401,6 +390,7 @@ void BrowserWindow::fullScreenRequested(const bool toggleOn) menuBar()->setVisible(true); navigationToolBarPointer->setVisible(true); urlToolBarPointer->setVisible(true); + tabWidgetPointer->setTabBarVisible(true); statusBar()->setVisible(true); } } @@ -422,7 +412,7 @@ void BrowserWindow::getZoomFactorFromUser() currentZoomFactor = newZoomFactor; // Set the new zoom factor. - browserViewPointer->applyOnTheFlyZoomFactor(newZoomFactor); + tabWidgetPointer->applyOnTheFlyZoomFactor(newZoomFactor); // Update the on-the-fly action text. updateZoomFactorAction(newZoomFactor); @@ -435,7 +425,7 @@ void BrowserWindow::home() const urlLineEditPointer->clearFocus(); // Go home. - browserViewPointer->home(); + tabWidgetPointer->home(); } void BrowserWindow::loadUrlFromLineEdit(const QString &url) const @@ -444,7 +434,7 @@ void BrowserWindow::loadUrlFromLineEdit(const QString &url) const urlLineEditPointer->clearFocus(); // Load the URL. - browserViewPointer->loadUrlFromLineEdit(url); + tabWidgetPointer->loadUrlFromLineEdit(url); } void BrowserWindow::refresh() const @@ -453,18 +443,7 @@ 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() @@ -473,15 +452,40 @@ 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 +{ + // Get the current download location. + QString currentDownloadLocation = downloadLocationComboBoxPointer->currentText(); + + // Resolve the system download directory if specified. + if (currentDownloadLocation == QStringLiteral("System Download Directory")) + currentDownloadLocation = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); + + // Get the new download location. + QString newDownloadLocation = QFileDialog::getExistingDirectory(configDialogPointer, i18nc("Select download location dialog caption", "Select Download Location"), currentDownloadLocation); + + // Populate the download location combo box according to the new download location. + if (newDownloadLocation == QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)) // The default download location was selected. + { + // Populate the download location with the default text. + downloadLocationComboBoxPointer->setCurrentText("System Download Directory"); + } + else if (newDownloadLocation != QStringLiteral("")) // A different directory was selected. + { + // Populate the download location. + downloadLocationComboBoxPointer->setCurrentText(newDownloadLocation); + } } void BrowserWindow::showDomainSettingsDialog() const @@ -496,7 +500,7 @@ void BrowserWindow::showDomainSettingsDialog() 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 @@ -508,85 +512,70 @@ void BrowserWindow::showProgressBar(const int &progress) const progressBarPointer->show(); } -QSize BrowserWindow::sizeHint() const +void BrowserWindow::showSettingsDialog() { - // Return the default window size. - return QSize(1500, 1200); -} - -void BrowserWindow::settingsConfigure() -{ - // Check to make sure the dialog box isn't already displayed. - if (KConfigDialog::exists(QStringLiteral("settings"))) - { - // Show the existing config dialog if it is hidden. - configDialogPointer->show(); + // Create the settings widgets. + QWidget *privacySettingsWidgetPointer = new QWidget; + QWidget *generalSettingsWidgetPointer = new QWidget; - // Raise the existing config dialog if it is below other windows. - configDialogPointer->raise(); + // Instantiate the settings UI. + Ui::PrivacySettings privacySettingsUi; + Ui::GeneralSettings generalSettingsUi; - // Restore the existing config dialog if it has been minimized. - if (configDialogPointer->isMinimized()) { - configDialogPointer->showNormal(); - } + // Setup the UI to display the settings widgets. + privacySettingsUi.setupUi(privacySettingsWidgetPointer); + generalSettingsUi.setupUi(generalSettingsWidgetPointer); - // Activate the existing config dialog, which brings its virtual desktop into focus. - configDialogPointer->activateWindow(); - } - else - { - // Create the settings widgets. - QWidget *privacySettingsWidgetPointer = new QWidget; - QWidget *generalSettingsWidgetPointer = new QWidget; + // Get handles for the widgets. + QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent; + userAgentLabelPointer = privacySettingsUi.userAgentLabel; + QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine; + searchEngineLabelPointer = generalSettingsUi.searchEngineLabel; + downloadLocationComboBoxPointer = generalSettingsUi.kcfg_downloadLocation; + QPushButton *browseButtonPointer = generalSettingsUi.browseButton; - // Instantiate the settings UI. - Ui::PrivacySettings privacySettingsUi; - Ui::GeneralSettings generalSettingsUi; + // Populate the combo box labels. + updateUserAgentLabel(userAgentComboBoxPointer->currentText()); + updateSearchEngineLabel(searchEngineComboBoxPointer->currentText()); - // Setup the UI to display the settings widgets. - privacySettingsUi.setupUi(privacySettingsWidgetPointer); - generalSettingsUi.setupUi(generalSettingsWidgetPointer); + // Update the labels when the combo boxes change. + connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString))); + connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString))); - // Get handles for the widgets. - QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent; - userAgentLabelPointer = privacySettingsUi.userAgentLabel; - QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine; - searchEngineLabelPointer = generalSettingsUi.searchEngineLabel; + // Connect the download location directory browse button. + connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(showDownloadLocationBrowseDialog())); - // Populate the combo box labels. - updateUserAgentLabel(userAgentComboBoxPointer->currentText()); - updateSearchEngineLabel(searchEngineComboBoxPointer->currentText()); + // Instantiate a settings config dialog from the settings.kcfg file. + configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self()); - // Update the labels when the combo boxes change. - connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateUserAgentLabel(const QString))); - connect(searchEngineComboBoxPointer, SIGNAL(currentTextChanged(const QString)), this, SLOT(updateSearchEngineLabel(const QString))); + // Add the settings widgets as config dialog pages. + configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("@title:tab", "Privacy"), QStringLiteral("privacy-browser")); + configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings")); - // Instantiate a settings config dialog from the settings.kcfg file. - configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self()); + // Prevent interaction with the parent window while the dialog is open. + configDialogPointer->setWindowModality(Qt::WindowModal); - // Add the settings widgets as config dialog pages. - configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("@title:tab", "Privacy"), QStringLiteral("privacy-browser")); - configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings")); + // Make it so. + configDialogPointer->show(); - // Delete the config dialog when it is closed. - configDialogPointer->setAttribute(Qt::WA_DeleteOnClose); + // TODO. KConfigDialog does not respect expanding size policies. + //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + //configDialogPointer->adjustSize(); - // Make it so. - configDialogPointer->show(); + // Expand the config dialog. + configDialogPointer->resize(1000, 500); - // TODO. KConfigDialog does not respect expanding size policies. - //configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - //privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - //generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - //configDialogPointer->adjustSize(); - - // Expand the config dialog. - configDialogPointer->resize(1000, 500); + // Apply the settings when they are updated. + connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyApplicationSettings())); + connect(configDialogPointer, SIGNAL(settingsChanged(QString)), tabWidgetPointer, SLOT(applyDomainSettingsAndReload())); +} - // Apply the settings when they are updated. - connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyApplicationSettings())); - connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyDomainSettingsAndReload())); - } +QSize BrowserWindow::sizeHint() const +{ + // Return the default window size. + return QSize(1500, 1200); } void BrowserWindow::toggleDomStorage() const @@ -595,7 +584,7 @@ void BrowserWindow::toggleDomStorage() const urlLineEditPointer->clearFocus(); // Toggle DOM storage. - browserViewPointer->toggleDomStorage(); + tabWidgetPointer->toggleDomStorage(); } void BrowserWindow::toggleJavaScript() const @@ -604,7 +593,7 @@ void BrowserWindow::toggleJavaScript() const urlLineEditPointer->clearFocus(); // Toggle JavaScript. - browserViewPointer->toggleJavaScript(); + tabWidgetPointer->toggleJavaScript(); } void BrowserWindow::toggleLocalStorage() const @@ -613,7 +602,7 @@ void BrowserWindow::toggleLocalStorage() const urlLineEditPointer->clearFocus(); // Toggle local storage. - browserViewPointer->toggleLocalStorage(); + tabWidgetPointer->toggleLocalStorage(); } void BrowserWindow::toggleFullScreen() @@ -635,6 +624,10 @@ 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); @@ -651,27 +644,33 @@ void BrowserWindow::toggleFullScreen() 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) @@ -812,7 +811,7 @@ void BrowserWindow::updateUserAgentActions(const QString &userAgent, const bool // 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); @@ -924,8 +923,15 @@ void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl) // 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.