X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=src%2Fwindows%2FBrowserWindow.cpp;h=2484061633266d0e7e3d5d49ddb57c38aaed5ad1;hb=1ce11bc5f6630bf81aa67bdaca411fbea93dc017;hp=15b683e77f114e7342e11e5c7ea926631384f1ce;hpb=730c65f4a8c48df65ed0fcd8ddfbbc9bcfda0c1f;p=PrivacyBrowserPC.git diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index 15b683e..2484061 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include // Construct the class. @@ -56,13 +57,16 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() 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::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::openNew(this, SLOT(fileNew()), actionCollectionPointer); - KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer); KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollectionPointer); - KStandardAction::redisplay(this, SLOT(refresh()), actionCollectionPointer); // Add the custom actions. userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_privacy_browser")); @@ -175,9 +179,9 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() domStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("view-web-browser-dom-tree"))); // Update the on-the-fly menus. - connect(browserViewPointer, SIGNAL(updateUserAgentActions(QString)), this, SLOT(updateUserAgentActions(QString))); + 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)), this, SLOT(updateSearchEngineActions(QString))); + connect(browserViewPointer, 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*))); @@ -185,8 +189,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 +223,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,13 +278,24 @@ 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(); } void BrowserWindow::addCookieToList(const QNetworkCookie &newCookie) const { - qDebug() << "Add cookie: " << newCookie.toRawForm(); + //qDebug() << "Add cookie: " << newCookie.toRawForm(); // Add the new cookie to the list. cookieListPointer->push_front(newCookie); @@ -340,6 +356,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 +378,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 +447,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,7 +484,7 @@ void BrowserWindow::openCookiesDialog() connect(cookiesDialogPointer, SIGNAL(deleteCookie(QNetworkCookie)), browserViewPointer, SLOT(deleteCookieFromStore(QNetworkCookie))); } -void BrowserWindow::openDomainSettings() const +void BrowserWindow::showDomainSettingsDialog() const { // Remove the focus from the URL line edit. urlLineEditPointer->clearFocus(); @@ -429,26 +499,6 @@ void BrowserWindow::openDomainSettings() const connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload())); } -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::showProgressBar(const int &progress) const { // Set the progress bar value. @@ -539,13 +589,13 @@ void BrowserWindow::settingsConfigure() } } -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 +607,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 @@ -620,7 +710,7 @@ void BrowserWindow::updateLocalStorageAction(const bool &isEnabled) domStorageActionPointer->setEnabled(localStorageEnabled & javaScriptEnabled); } -void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const +void BrowserWindow::updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus) { // Initialize the custom search engine flag. bool customSearchEngine = false; @@ -681,18 +771,22 @@ void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const // Update the search engine menu action text. searchEngineMenuActionPointer->setText(i18nc("The main search engine menu action", "Search Engine - Custom")); + // Set the custom search engine text. + searchEngineCustomActionPointer->setText(searchEngine); + // Set the custom search engine flag. customSearchEngine = true; } + // Update the custom search engine enabled boolean. + if (updateCustomSearchEngineStatus) + customSearchEngineEnabled = customSearchEngine; + // Format the custom search engine. - if (customSearchEngine) + if (customSearchEngineEnabled) { // Enable the custom search engine. searchEngineCustomActionPointer->setEnabled(true); - - // Set the custom search engine text. - searchEngineCustomActionPointer->setText(searchEngine); } else { @@ -704,7 +798,7 @@ void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const } } -void BrowserWindow::updateUserAgentActions(const QString &userAgent) const +void BrowserWindow::updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus) { // Initialize the custom user agent flag. bool customUserAgent = false; @@ -782,19 +876,23 @@ void BrowserWindow::updateUserAgentActions(const QString &userAgent) const // Update the user agent menu action text. userAgentMenuActionPointer->setText(i18nc("The main user agent menu action", "User Agent - Custom")); + // Set the custom user agent text. + userAgentCustomActionPointer->setText(userAgent); + // Set the custom user agent flag. customUserAgent = true; } + // Update the custom user agent enabled boolean. + if (updateCustomUserAgentStatus) + customUserAgentEnabled = customUserAgent; + // Format the custom user agent. - if (customUserAgent) + if (customUserAgentEnabled) { // Enable the custom user agent. userAgentCustomActionPointer->setEnabled(true); - - // Set the custom user agent text. - userAgentCustomActionPointer->setText(userAgent); } else {