X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=src%2Fwindows%2FBrowserWindow.cpp;h=e44357f25c042bb264ac7384baa00b6ab4b3793c;hb=e28b208d6f953d24bd05927a16775d103714fd36;hp=d3800ad8e1674c93b7c54e77c0be5618c62eed6f;hpb=83e7c484d2440bfff54e8d02b2d532c2aba755ef;p=PrivacyBrowserPC.git diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index d3800ad..e44357f 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -33,9 +33,11 @@ #include // Qt toolkit headers. +#include #include #include #include +#include #include // Construct the class. @@ -56,13 +58,16 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() KActionCollection *actionCollectionPointer = this->actionCollection(); // Add the standard actions. - QAction *backActionPointer = KStandardAction::back(this, SLOT(back()), actionCollectionPointer); - QAction *forwardActionPointer = KStandardAction::forward(this, SLOT(forward()), actionCollectionPointer); - KStandardAction::home(this, SLOT(home()), actionCollectionPointer); KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer); + KStandardAction::print(browserViewPointer, SLOT(print()), actionCollectionPointer); + KStandardAction::printPreview(browserViewPointer, SLOT(printPreview()), actionCollectionPointer); KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer); - KStandardAction::preferences(this, SLOT(settingsConfigure()), 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(showSettingsDialog()), actionCollectionPointer); // Add the custom actions. userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_privacy_browser")); @@ -185,8 +190,8 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() // Display dialogs. connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser())); - connect(cookiesActionPointer, SIGNAL(triggered()), this, SLOT(openCookiesDialog())); - connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(openDomainSettings())); + connect(cookiesActionPointer, SIGNAL(triggered()), this, SLOT(showCookiesDialog())); + connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(showDomainSettingsDialog())); // Connect the URL toolbar actions. connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript())); @@ -219,8 +224,9 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() userAgentMenuActionPointer = userAgentMenuPointer->menuAction(); searchEngineMenuActionPointer = searchEngineMenuPointer->menuAction(); - // Get a handle for the URL toolbar. - KToolBar *urlToolBarPointer = toolBar(QStringLiteral("url_toolbar")); + // Get handles for the toolbars. + navigationToolBarPointer = toolBar(QStringLiteral("navigation_toolbar")); + urlToolBarPointer = toolBar(QStringLiteral("url_toolbar")); // Create a URL line edit. urlLineEditPointer = new KLineEdit(); @@ -273,6 +279,17 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() connect(browserViewPointer, SIGNAL(addCookie(QNetworkCookie)), this, SLOT(addCookieToList(QNetworkCookie))); connect(browserViewPointer, SIGNAL(removeCookie(QNetworkCookie)), this, SLOT(removeCookieFromList(QNetworkCookie))); + // Process full screen requests. + connect(browserViewPointer, SIGNAL(fullScreenRequested(bool)), this, SLOT(fullScreenRequested(bool))); + + // Create keyboard shortcuts. + 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(f11ShortcutPointer, SIGNAL(activated()), fullScreenActionPointer, SLOT(trigger())); + connect(escapeShortcutPointer, SIGNAL(activated()), this, SLOT(escape())); + // Load the initial website. browserViewPointer->loadInitialWebsite(); } @@ -340,6 +357,13 @@ void BrowserWindow::clearUrlLineEditFocus() const urlLineEditPointer->clearFocus(); } +void BrowserWindow::escape() const +{ + // Exit full screen browsing if it is enabled. + if (fullScreenActionPointer->isChecked()) + fullScreenActionPointer->trigger(); +} + void BrowserWindow::fileNew() const { // Display a new instance of Privacy Browser. @@ -355,6 +379,33 @@ void BrowserWindow::forward() const browserViewPointer->forward(); } +void BrowserWindow::fullScreenRequested(const bool toggleOn) +{ + // Toggle full screen mode. + if (toggleOn) // Turn full screen mode on. + { + // Set the window to be full screen. + fullScreenActionPointer->setFullScreen(window(), true); + + // Hide all the bars. + menuBar()->setVisible(false); + navigationToolBarPointer->setVisible(false); + urlToolBarPointer->setVisible(false); + statusBar()->setVisible(false); + } + else // Turn full screen mode off. + { + // Set the window to not be full screen. + fullScreenActionPointer->setFullScreen(window(), false); + + // Show all the bars. + menuBar()->setVisible(true); + navigationToolBarPointer->setVisible(true); + urlToolBarPointer->setVisible(true); + statusBar()->setVisible(true); + } +} + void BrowserWindow::getZoomFactorFromUser() { // Create an OK flag. @@ -397,7 +448,27 @@ void BrowserWindow::loadUrlFromLineEdit(const QString &url) const browserViewPointer->loadUrlFromLineEdit(url); } -void BrowserWindow::openCookiesDialog() +void BrowserWindow::refresh() const +{ + // Remove the focus from the URL line edit. + 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())); +} + +void BrowserWindow::showCookiesDialog() { // Remove the focus from the URL line edit. urlLineEditPointer->clearFocus(); @@ -414,39 +485,44 @@ void BrowserWindow::openCookiesDialog() connect(cookiesDialogPointer, SIGNAL(deleteCookie(QNetworkCookie)), browserViewPointer, SLOT(deleteCookieFromStore(QNetworkCookie))); } -void BrowserWindow::openDomainSettings() const +void BrowserWindow::showDownloadLocationBrowseDialog() const { - // Remove the focus from the URL line edit. - urlLineEditPointer->clearFocus(); + // Get the current download location. + QString currentDownloadLocation = downloadLocationComboBoxPointer->currentText(); - // Instantiate the domain settings dialog. - DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog(); + // Resolve the system download directory if specified. + if (currentDownloadLocation == QStringLiteral("System Download Directory")) + currentDownloadLocation = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); - // Show the dialog. - domainSettingsDialogPointer->show(); + // Get the new download location. + QString newDownloadLocation = QFileDialog::getExistingDirectory(configDialogPointer, i18nc("Select download location dialog caption", "Select Download Location"), currentDownloadLocation); - // Reload the tabs when domain settings are updated. - connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload())); + // 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::refresh() const +void BrowserWindow::showDomainSettingsDialog() const { // Remove the focus from the URL line edit. urlLineEditPointer->clearFocus(); - // Refresh the web page. - browserViewPointer->refresh(); -} - -void BrowserWindow::removeCookieFromList(const QNetworkCookie &cookie) const -{ - //qDebug() << "Remove cookie: " << cookie.toRawForm(); + // Instantiate the domain settings dialog. + DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog(); - // Remove the cookie from the list. - cookieListPointer->remove(cookie); + // Show the dialog. + domainSettingsDialogPointer->show(); - // Update the action text. - cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", cookieListPointer->size())); + // Reload the tabs when domain settings are updated. + connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload())); } void BrowserWindow::showProgressBar(const int &progress) const @@ -458,94 +534,79 @@ 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); + // Create the settings widgets. + QWidget *privacySettingsWidgetPointer = new QWidget; + QWidget *generalSettingsWidgetPointer = new QWidget; + + // Instantiate the settings UI. + Ui::PrivacySettings privacySettingsUi; + Ui::GeneralSettings generalSettingsUi; + + // Setup the UI to display the settings widgets. + privacySettingsUi.setupUi(privacySettingsWidgetPointer); + generalSettingsUi.setupUi(generalSettingsWidgetPointer); + + // 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; + + // Populate the combo box labels. + updateUserAgentLabel(userAgentComboBoxPointer->currentText()); + updateSearchEngineLabel(searchEngineComboBoxPointer->currentText()); + + // 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))); + + // Connect the download location directory browse button. + connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(showDownloadLocationBrowseDialog())); + + // Instantiate a settings config dialog from the settings.kcfg file. + configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self()); + + // 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")); + + // Prevent interaction with the parent window while the dialog is open. + configDialogPointer->setWindowModality(Qt::WindowModal); + + // Make it so. + configDialogPointer->show(); + + // 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)), browserViewPointer, SLOT(applyApplicationSettings())); + connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyDomainSettingsAndReload())); } -void BrowserWindow::settingsConfigure() +QSize BrowserWindow::sizeHint() const { - // 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(); - - // Raise the existing config dialog if it is below other windows. - configDialogPointer->raise(); - - // Restore the existing config dialog if it has been minimized. - if (configDialogPointer->isMinimized()) { - configDialogPointer->showNormal(); - } - - // 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; - - // Instantiate the settings UI. - Ui::PrivacySettings privacySettingsUi; - Ui::GeneralSettings generalSettingsUi; - - // Setup the UI to display the settings widgets. - privacySettingsUi.setupUi(privacySettingsWidgetPointer); - generalSettingsUi.setupUi(generalSettingsWidgetPointer); - - // Get handles for the widgets. - QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent; - userAgentLabelPointer = privacySettingsUi.userAgentLabel; - QComboBox *searchEngineComboBoxPointer = generalSettingsUi.kcfg_searchEngine; - searchEngineLabelPointer = generalSettingsUi.searchEngineLabel; - - // Populate the combo box labels. - updateUserAgentLabel(userAgentComboBoxPointer->currentText()); - updateSearchEngineLabel(searchEngineComboBoxPointer->currentText()); - - // 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))); - - // Instantiate a settings config dialog from the settings.kcfg file. - configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self()); - - // 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")); - - // Delete the config dialog when it is closed. - configDialogPointer->setAttribute(Qt::WA_DeleteOnClose); - - // Make it so. - configDialogPointer->show(); - - // 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)), browserViewPointer, SLOT(applyApplicationSettings())); - connect(configDialogPointer, SIGNAL(settingsChanged(QString)), browserViewPointer, SLOT(applyDomainSettingsAndReload())); - } + // Return the default window size. + return QSize(1500, 1200); } -void BrowserWindow::toggleLocalStorage() const +void BrowserWindow::toggleDomStorage() const { - // Remove the focus from teh URL line edit. + // Remove the focus from the URL line edit. urlLineEditPointer->clearFocus(); - // Toggle local storage. - browserViewPointer->toggleLocalStorage(); + // Toggle DOM storage. + browserViewPointer->toggleDomStorage(); } void BrowserWindow::toggleJavaScript() const @@ -557,13 +618,53 @@ void BrowserWindow::toggleJavaScript() const browserViewPointer->toggleJavaScript(); } -void BrowserWindow::toggleDomStorage() const +void BrowserWindow::toggleLocalStorage() const { // Remove the focus from the URL line edit. urlLineEditPointer->clearFocus(); - // Toggle DOM storage. - browserViewPointer->toggleDomStorage(); + // Toggle local storage. + browserViewPointer->toggleLocalStorage(); +} + +void BrowserWindow::toggleFullScreen() +{ + // Toggle the full screen status. + if (fullScreenActionPointer->isChecked()) // Enable full screen browsing mode. + { + // Enable full screen mode. + fullScreenActionPointer->setFullScreen(window(), true); + + // Hide the menu bar if specified. + if (Settings::fullScreenHideMenuBar()) + menuBar()->setVisible(false); + + // Hide the toolbars if specified. + if (Settings::fullScreenHideToolBars()) + { + navigationToolBarPointer->setVisible(false); + urlToolBarPointer->setVisible(false); + } + + // Hide the status bar if specified. + if (Settings::fullScreenHideStatusBar()) + statusBar()->setVisible(false); + } + else // Disable full screen browsing mode. + { + // Disable full screen mode. + fullScreenActionPointer->setFullScreen(window(), false); + + // Show the menu bar. + menuBar()->setVisible(true); + + // Show the toolbars. + navigationToolBarPointer->setVisible(true); + urlToolBarPointer->setVisible(true); + + // Show the status bar. + statusBar()->setVisible(true); + } } void BrowserWindow::updateDomStorageAction(const bool &isEnabled) const