From 455108aa18c90514c0dad3c12dfea98180dfb471 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Fri, 1 Apr 2022 12:38:28 -0700 Subject: [PATCH] Add controls for local storage. https://redmine.stoutner.com/issues/830 --- src/CMakeLists.txt | 10 ++-- src/dialogs/DomainSettingsDialog.cpp | 68 ++++++++++++++++++++++----- src/dialogs/DomainSettingsDialog.h | 4 ++ src/helpers/DomainsDatabaseHelper.cpp | 15 ++++-- src/helpers/DomainsDatabaseHelper.h | 1 + src/{ => settings}/Settings.kcfg | 4 ++ src/{ => settings}/Settings.kcfgc | 0 src/ui.rc/browser_ui.rc | 6 ++- src/{ => ui}/BrowserView.ui | 0 src/{ => ui}/DomainSettingsDialog.ui | 55 +++++++++++++++++++--- src/{ => ui}/SettingsGeneral.ui | 0 src/{ => ui}/SettingsPrivacy.ui | 21 +++++++-- src/views/BrowserView.cpp | 44 +++++++++++++++++ src/views/BrowserView.h | 4 +- src/windows/BrowserWindow.cpp | 42 ++++++++++++----- src/windows/BrowserWindow.h | 3 ++ 16 files changed, 232 insertions(+), 45 deletions(-) rename src/{ => settings}/Settings.kcfg (95%) rename src/{ => settings}/Settings.kcfgc (100%) rename src/{ => ui}/BrowserView.ui (100%) rename src/{ => ui}/DomainSettingsDialog.ui (85%) rename src/{ => ui}/SettingsGeneral.ui (100%) rename src/{ => ui}/SettingsPrivacy.ui (87%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 709b74c..8371822 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,14 +32,14 @@ ecm_qt_declare_logging_category(privacy-browser ) # Include the KConfig controller file. -kconfig_add_kcfg_files(privacy-browser Settings.kcfgc) +kconfig_add_kcfg_files(privacy-browser settings/Settings.kcfgc) # Use KDE Frameworks to handle internationalization of the following UI files. ki18n_wrap_ui(privacy-browser - BrowserView.ui - DomainSettingsDialog.ui - SettingsGeneral.ui - SettingsPrivacy.ui + ui/BrowserView.ui + ui/DomainSettingsDialog.ui + ui/SettingsGeneral.ui + ui/SettingsPrivacy.ui ) # Link the following libraries. diff --git a/src/dialogs/DomainSettingsDialog.cpp b/src/dialogs/DomainSettingsDialog.cpp index e3745b5..a8960cd 100644 --- a/src/dialogs/DomainSettingsDialog.cpp +++ b/src/dialogs/DomainSettingsDialog.cpp @@ -43,6 +43,8 @@ DomainSettingsDialog::DomainSettingsDialog(QWidget *parent) : QDialog(parent) domainNameLineEditPointer = domainSettingsDialogUi.domainNameLineEdit; javaScriptComboBoxPointer = domainSettingsDialogUi.javaScriptComboBox; javaScriptLabelPointer = domainSettingsDialogUi.javaScriptLabel; + localStorageComboBoxPointer = domainSettingsDialogUi.localStorageComboBox; + localStorageLabelPointer = domainSettingsDialogUi.localStorageLabel; userAgentComboBoxPointer = domainSettingsDialogUi.userAgentComboBox; userAgentLabelPointer = domainSettingsDialogUi.userAgentLabel; zoomFactorComboBoxPointer = domainSettingsDialogUi.zoomFactorComboBox; @@ -89,6 +91,7 @@ DomainSettingsDialog::DomainSettingsDialog(QWidget *parent) : QDialog(parent) // Connect the domain settings. connect(domainNameLineEditPointer, SIGNAL(textEdited(QString)), this, SLOT(domainNameChanged(QString))); connect(javaScriptComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(javaScriptChanged(int))); + connect(localStorageComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(localStorageChanged(int))); connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(QString)), this, SLOT(userAgentChanged(QString))); connect(zoomFactorComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(zoomFactorComboBoxChanged(int))); connect(customZoomFactorSpinBoxPointer, SIGNAL(valueChanged(double)), this, SLOT(customZoomFactorChanged(double))); @@ -149,7 +152,6 @@ void DomainSettingsDialog::customZoomFactorChanged(const double &newValue) const updateUi(); } - void DomainSettingsDialog::domainNameChanged(const QString &updatedDomainName) const { // Update the domains table model. @@ -159,7 +161,6 @@ void DomainSettingsDialog::domainNameChanged(const QString &updatedDomainName) c updateUi(); } - void DomainSettingsDialog::domainSelected(const QModelIndex &modelIndex) const { // Populate the domain name line edit pointer. @@ -168,6 +169,9 @@ void DomainSettingsDialog::domainSelected(const QModelIndex &modelIndex) const // Populate the JavaScript combo box. javaScriptComboBoxPointer->setCurrentIndex(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::JAVASCRIPT)).data().toInt()); + // Populate the local storage combo box. + localStorageComboBoxPointer->setCurrentIndex(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::LOCAL_STORAGE)).data().toInt()); + // Get the user agent string. QString userAgent = modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::USER_AGENT)).data().toString(); @@ -194,6 +198,7 @@ void DomainSettingsDialog::domainSelected(const QModelIndex &modelIndex) const // Populate the labels. populateJavaScriptLabel(); + populateLocalStorageLabel(); populateUserAgentLabel(userAgentComboBoxPointer->currentText()); // Update the UI. @@ -213,6 +218,18 @@ void DomainSettingsDialog::javaScriptChanged(const int &newIndex) const updateUi(); } +void DomainSettingsDialog::localStorageChanged(const int &newIndex) const +{ + // Update the domains table model. + domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::LOCAL_STORAGE)), + newIndex); + + // Populate the local storage label. + populateLocalStorageLabel(); + + // Update the UI. + updateUi(); +} void DomainSettingsDialog::ok() { @@ -234,14 +251,40 @@ void DomainSettingsDialog::populateJavaScriptLabel() const case (DomainsDatabaseHelper::SYSTEM_DEFAULT): { // Set the text according to the system default. - if (Settings::javaScript()) - { - javaScriptLabelPointer->setText(i18nc("Domains settings labels", "JavaScript enabled")); - } - else - { - javaScriptLabelPointer->setText(i18nc("Domain settings labels", "JavaScript disabled")); - } + if (Settings::javaScript()) javaScriptLabelPointer->setText(i18nc("Domains settings label", "JavaScript enabled")); + else javaScriptLabelPointer->setText(i18nc("Domain settings label", "JavaScript disabled")); + + break; + } + + case (DomainsDatabaseHelper::DISABLED): + { + // Set the label text in bold. + javaScriptLabelPointer->setText(i18nc("Domain settings label. The tags should be retained.", "JavaScript disabled")); + + break; + } + + case (DomainsDatabaseHelper::ENABLED): + { + // Set the label text in bold. + javaScriptLabelPointer->setText(i18nc("Domains settings label. The tags should be retained.", "JavaScript enabled")); + + break; + } + } +} + +void DomainSettingsDialog::populateLocalStorageLabel() const +{ + // Populate the label according to the currently selected index. + switch (localStorageComboBoxPointer->currentIndex()) + { + case (DomainsDatabaseHelper::SYSTEM_DEFAULT): + { + // Set the text according to the system default. + if (Settings::localStorage()) localStorageLabelPointer->setText(i18nc("Local storage label", "Local storage enabled")); + else localStorageLabelPointer->setText(i18nc("Local storage label", "Local storage disabled")); break; } @@ -249,7 +292,7 @@ void DomainSettingsDialog::populateJavaScriptLabel() const case (DomainsDatabaseHelper::DISABLED): { // Set the label text in bold. - javaScriptLabelPointer->setText(i18nc("Domain settings labels. The tags should be retained.", "JavaScript disabled")); + localStorageLabelPointer->setText(i18nc("Local storage label. The tags should be retained.", "Local storage disabled")); break; } @@ -257,7 +300,7 @@ void DomainSettingsDialog::populateJavaScriptLabel() const case (DomainsDatabaseHelper::ENABLED): { // Set the label text in bold. - javaScriptLabelPointer->setText(i18nc("Domains settings labels. The tags should be retained.", "JavaScript enabled")); + localStorageLabelPointer->setText(i18nc("Local storage label. The tags should be retained.", "Local storage enabled")); break; } @@ -312,6 +355,7 @@ void DomainSettingsDialog::showAddMessageBox() // Set the values for the new domain. newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOMAIN_NAME), newDomainName); newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::JAVASCRIPT), DomainsDatabaseHelper::SYSTEM_DEFAULT); + newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::LOCAL_STORAGE), DomainsDatabaseHelper::SYSTEM_DEFAULT); newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::USER_AGENT), UserAgentHelper::SYSTEM_DEFAULT_DATABASE); newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::ZOOM_FACTOR), DomainsDatabaseHelper::SYSTEM_DEFAULT); newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::CUSTOM_ZOOM_FACTOR), 1.0); diff --git a/src/dialogs/DomainSettingsDialog.h b/src/dialogs/DomainSettingsDialog.h index 0694177..41438ce 100644 --- a/src/dialogs/DomainSettingsDialog.h +++ b/src/dialogs/DomainSettingsDialog.h @@ -49,6 +49,7 @@ private Q_SLOTS: void domainNameChanged(const QString &updatedDomainName) const; void domainSelected(const QModelIndex &modelIndex) const; void javaScriptChanged(const int &newIndex) const; + void localStorageChanged(const int &newIndex) const; void ok(); void reset() const; void showAddMessageBox(); @@ -67,6 +68,8 @@ private: QSqlTableModel *domainsTableModelPointer; QComboBox *javaScriptComboBoxPointer; QLabel *javaScriptLabelPointer; + QComboBox *localStorageComboBoxPointer; + QLabel *localStorageLabelPointer; QPushButton *resetButtonPointer; QComboBox *userAgentComboBoxPointer; QLabel *userAgentLabelPointer; @@ -74,6 +77,7 @@ private: // The private functions. void populateJavaScriptLabel() const; + void populateLocalStorageLabel() const; void populateUserAgentLabel(const QString &userAgentName) const; void updateUi() const; }; diff --git a/src/helpers/DomainsDatabaseHelper.cpp b/src/helpers/DomainsDatabaseHelper.cpp index 5b6c4fa..ed62e6a 100644 --- a/src/helpers/DomainsDatabaseHelper.cpp +++ b/src/helpers/DomainsDatabaseHelper.cpp @@ -26,12 +26,13 @@ const QString DomainsDatabaseHelper::CONNECTION_NAME = "domains_database"; const QString DomainsDatabaseHelper::DOMAINS_TABLE = "domains"; // Define the private static schema constants. -const int DomainsDatabaseHelper::SCHEMA_VERSION = 3; +const int DomainsDatabaseHelper::SCHEMA_VERSION = 4; // Define the public static database field names. const QString DomainsDatabaseHelper::_ID = "_id"; const QString DomainsDatabaseHelper::DOMAIN_NAME = "domain_name"; const QString DomainsDatabaseHelper::JAVASCRIPT = "javascript"; +const QString DomainsDatabaseHelper::LOCAL_STORAGE = "local_storage"; const QString DomainsDatabaseHelper::USER_AGENT = "user_agent"; const QString DomainsDatabaseHelper::ZOOM_FACTOR = "zoom_factor"; const QString DomainsDatabaseHelper::CUSTOM_ZOOM_FACTOR = "custom_zoom_factor"; @@ -74,9 +75,6 @@ void DomainsDatabaseHelper::addDatabase() // Add the JavaScript column. domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + JAVASCRIPT + " INTEGER DEFAULT 0"); - // Set the default value. - domainsDatabase.exec("UPDATE " + DOMAINS_TABLE + " SET " + JAVASCRIPT + " = 0" ); - // Fallthrough to the next case. [[fallthrough]]; } @@ -97,7 +95,15 @@ void DomainsDatabaseHelper::addDatabase() // Add the Zoom Factor columns. domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + ZOOM_FACTOR + " INTEGER DEFAULT 0"); domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + CUSTOM_ZOOM_FACTOR + " REAL DEFAULT 1.0"); + + // Fallthrough to the next case. + [[fallthrough]]; } + + // Upgrade from schema version 3. + case 3: + // Add the Local Storage column. + domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + LOCAL_STORAGE + " INTEGER DEFAULT 0"); } // Update the schema version. @@ -114,6 +120,7 @@ void DomainsDatabaseHelper::addDatabase() _ID + " INTEGER PRIMARY KEY, " + DOMAIN_NAME + " TEXT, " + JAVASCRIPT + " INTEGER DEFAULT 0, " + + LOCAL_STORAGE + " INTEGER DEFAULT 0, " + USER_AGENT + " TEXT DEFAULT '" + UserAgentHelper::SYSTEM_DEFAULT_DATABASE + "', " + ZOOM_FACTOR + " INTEGER DEFAULT 0, " + CUSTOM_ZOOM_FACTOR + " REAL DEFAULT 1.0)" diff --git a/src/helpers/DomainsDatabaseHelper.h b/src/helpers/DomainsDatabaseHelper.h index b95988d..2ec812b 100644 --- a/src/helpers/DomainsDatabaseHelper.h +++ b/src/helpers/DomainsDatabaseHelper.h @@ -46,6 +46,7 @@ public: static const QString DOMAIN_NAME; static const QString DOMAINS_TABLE; static const QString JAVASCRIPT; + static const QString LOCAL_STORAGE; static const QString USER_AGENT; static const QString ZOOM_FACTOR; diff --git a/src/Settings.kcfg b/src/settings/Settings.kcfg similarity index 95% rename from src/Settings.kcfg rename to src/settings/Settings.kcfg index 25b12a8..c5435fa 100644 --- a/src/Settings.kcfg +++ b/src/settings/Settings.kcfg @@ -32,6 +32,10 @@ false + + false + + Privacy Browser diff --git a/src/Settings.kcfgc b/src/settings/Settings.kcfgc similarity index 100% rename from src/Settings.kcfgc rename to src/settings/Settings.kcfgc diff --git a/src/ui.rc/browser_ui.rc b/src/ui.rc/browser_ui.rc index 3c46ee0..dbbeb31 100644 --- a/src/ui.rc/browser_ui.rc +++ b/src/ui.rc/browser_ui.rc @@ -69,5 +69,9 @@ - URL Toolbar + URL Toolbar + + + + diff --git a/src/BrowserView.ui b/src/ui/BrowserView.ui similarity index 100% rename from src/BrowserView.ui rename to src/ui/BrowserView.ui diff --git a/src/DomainSettingsDialog.ui b/src/ui/DomainSettingsDialog.ui similarity index 85% rename from src/DomainSettingsDialog.ui rename to src/ui/DomainSettingsDialog.ui index 82d6a0d..0b2f56f 100644 --- a/src/DomainSettingsDialog.ui +++ b/src/ui/DomainSettingsDialog.ui @@ -148,16 +148,59 @@ - + - User Agent + Local storage + + + Local storage, sometimes also called DOM storage, is like cookies on steroids. + + + + + System default + + + + + + Local storage disabled + + + + + + Local storage enabled + + + + + + + + + Qt::RichText + + + + + + + + + User agent + + + + + @@ -220,7 +263,7 @@ - + Qt::RichText @@ -229,7 +272,7 @@ - + Zoom factor @@ -237,7 +280,7 @@ - + @@ -253,7 +296,7 @@ - + Set the zoom factor between 0.25 and 5.00. The default is 1.00. diff --git a/src/SettingsGeneral.ui b/src/ui/SettingsGeneral.ui similarity index 100% rename from src/SettingsGeneral.ui rename to src/ui/SettingsGeneral.ui diff --git a/src/SettingsPrivacy.ui b/src/ui/SettingsPrivacy.ui similarity index 87% rename from src/SettingsPrivacy.ui rename to src/ui/SettingsPrivacy.ui index 74c7a0f..a1445b6 100644 --- a/src/SettingsPrivacy.ui +++ b/src/ui/SettingsPrivacy.ui @@ -25,7 +25,7 @@ - + JavaScript @@ -37,8 +37,21 @@ + + + + + Local storage + + + + Local storage, sometimes also called DOM storage, is like cookies on steroids. + + + + - + User agent @@ -46,7 +59,7 @@ - + @@ -107,7 +120,7 @@ - + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse diff --git a/src/views/BrowserView.cpp b/src/views/BrowserView.cpp index 21e1493..933a300 100644 --- a/src/views/BrowserView.cpp +++ b/src/views/BrowserView.cpp @@ -162,6 +162,34 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload } } + // Set local storage. + switch (domainRecord.field(DomainsDatabaseHelper::LOCAL_STORAGE).value().toInt()) + { + case (DomainsDatabaseHelper::SYSTEM_DEFAULT): + { + // Set the default local storage status. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::localStorage()); + + break; + } + + case (DomainsDatabaseHelper::DISABLED): + { + // Disable local storage. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, false); + + break; + } + + case (DomainsDatabaseHelper::ENABLED): + { + // Enable local storage. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, true); + + break; + } + } + // Set the user agent. webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getResultingDomainSettingsUserAgent(domainRecord.field(DomainsDatabaseHelper::USER_AGENT).value().toString())); @@ -188,6 +216,9 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload // Set the JavaScript status. webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScript()); + // Set local storage. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::localStorage()); + // Set the user agent. webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent())); @@ -203,6 +234,7 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload // Emit the update actions signals. emit updateJavaScriptAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled)); + emit updateLocalStorageAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); emit updateUserAgentActions(webEngineProfilePointer->httpUserAgent()); emit updateZoomFactorAction(webEngineViewPointer->zoomFactor()); @@ -358,6 +390,18 @@ void BrowserView::toggleJavaScript() const webEngineViewPointer->reload(); } +void BrowserView::toggleLocalStorage() const +{ + // Toggle local storage. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, !webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); + + // Update the local storage icon. + emit updateLocalStorageAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); + + // Reload the website. + webEngineViewPointer->reload(); +} + void BrowserView::updateUrl(const QUrl &url) const { // Update the URL line edit. diff --git a/src/views/BrowserView.h b/src/views/BrowserView.h index 143db41..1401468 100644 --- a/src/views/BrowserView.h +++ b/src/views/BrowserView.h @@ -41,6 +41,8 @@ public: // The public functions. void applyOnTheFlyZoomFactor(const double &zoomFactor); void loadInitialWebsite(); + void toggleJavaScript() const; + void toggleLocalStorage() const; signals: // The signals. @@ -51,6 +53,7 @@ signals: void updateDomainSettingsIndicator(const bool status) const; void updateForwardAction(const bool &isEnabled) const; void updateJavaScriptAction(const bool &isEnabled) const; + void updateLocalStorageAction(const bool &isEnabled) const; void updateSearchEngineActions(const QString &searchEngine) const; void updateUrlLineEdit(const QString &newUrl) const; void updateUserAgentActions(const QString &userAgent) const; @@ -67,7 +70,6 @@ public Q_SLOTS: void forward() const; void home() const; void loadUrlFromLineEdit(QString url) const; - void toggleJavaScript() const; void refresh() const; private Q_SLOTS: diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index 03ababc..13f470e 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -72,6 +72,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() searchEngineYahooActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_yahoo")); searchEngineCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_custom")); javaScriptActionPointer = actionCollectionPointer->addAction(QStringLiteral("javascript")); + localStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("local_storage")); domainSettingsActionPointer = actionCollectionPointer->addAction(QStringLiteral("domain_settings")); // Create the action groups @@ -127,6 +128,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing")); searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo")); javaScriptActionPointer->setText(i18nc("JavaScript button", "JavaScript")); + localStorageActionPointer->setText(i18nc("Local Storage Button", "Local Storage")); domainSettingsActionPointer->setText(i18nc("Domain Settings button", "Domain Settings")); // Set the action icons. @@ -162,12 +164,14 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() // Connect the URL toolbar actions. connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript())); + connect(localStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleLocalStorage())); connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(openDomainSettings())); // 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))); // Setup the GUI based on the browser_ui.rc file. setupGUI(StandardWindowOption::Default, ("browser_ui.rc")); @@ -179,9 +183,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() urlLineEditPointer = new KLineEdit(); // Populate the URL toolbar. - urlToolBarPointer->addWidget(urlLineEditPointer); - urlToolBarPointer->addAction(javaScriptActionPointer); - urlToolBarPointer->addAction(domainSettingsActionPointer); + urlToolBarPointer->insertWidget(javaScriptActionPointer, urlLineEditPointer); // Load a new URL from the URL line edit. connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString))); @@ -324,15 +326,6 @@ void BrowserWindow::showProgressBar(const int &progress) const progressBarPointer->show(); } -void BrowserWindow::toggleJavaScript() const -{ - // Remove the focus from the URL line edit. - urlLineEditPointer->clearFocus(); - - // Toggle JavaScript. - browserViewPointer->toggleJavaScript(); -} - QSize BrowserWindow::sizeHint() const { // Return the default window size. @@ -414,6 +407,24 @@ void BrowserWindow::settingsConfigure() } } +void BrowserWindow::toggleJavaScript() const +{ + // Remove the focus from the URL line edit. + urlLineEditPointer->clearFocus(); + + // Toggle JavaScript. + browserViewPointer->toggleJavaScript(); +} + +void BrowserWindow::toggleLocalStorage() const +{ + // Remove the focus from the URL line edit. + urlLineEditPointer->clearFocus(); + + // Toggle JavaScript. + browserViewPointer->toggleLocalStorage(); +} + void BrowserWindow::updateDomainSettingsIndicator(const bool &status) const { // Set the domain palette according to the status. @@ -428,6 +439,13 @@ void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) const else javaScriptActionPointer->setIcon(QIcon(":/icons/privacy-mode")); } +void BrowserWindow::updateLocalStorageAction(const bool &isEnabled) const +{ + // Set the icon according to the status. + if (isEnabled) localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota-low")); + else localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota")); +} + void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const { // Initialize the custom search engine flag. diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index 02978d4..b3630db 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -56,8 +56,10 @@ private Q_SLOTS: void settingsConfigure(); void showProgressBar(const int &progress) const; void toggleJavaScript() const; + void toggleLocalStorage() const; void updateDomainSettingsIndicator(const bool &status) const; void updateJavaScriptAction(const bool &isEnabled) const; + void updateLocalStorageAction(const bool &isEnabled) const; void updateSearchEngineActions(const QString &searchEngine) const; void updateUserAgentActions(const QString &userAgent) const; void updateZoomFactorAction(const double &zoomFactor); @@ -73,6 +75,7 @@ private: QPalette domainSettingsPalette; double currentZoomFactor; QAction *javaScriptActionPointer; + QAction *localStorageActionPointer; QPalette noDomainSettingsPalette; QProgressBar *progressBarPointer; QLabel *searchEngineLabelPointer; -- 2.45.2