diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index 7d90ab169..60cc29587 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -854,6 +854,7 @@ void MainApplication::saveSettings() m_searchEnginesManager->saveSettings(); m_plugins->shutdown(); m_networkManager->shutdown(); + m_siteSettingsManager->saveSettings(); qzSettings->saveSettings(); QFile::remove(DataPaths::currentProfilePath() + QLatin1String("/WebpageIcons.db")); diff --git a/src/lib/other/sitesettingsmanager.cpp b/src/lib/other/sitesettingsmanager.cpp index 3a94c7aeb..db19038f6 100644 --- a/src/lib/other/sitesettingsmanager.cpp +++ b/src/lib/other/sitesettingsmanager.cpp @@ -35,8 +35,44 @@ SiteSettingsManager::~SiteSettingsManager() noexcept void SiteSettingsManager::loadSettings() { Settings settings; - settings.beginGroup("Web-Browser-Settings"); +// settings.beginGroup("Web-Browser-Settings"); // m_isSaving = settings.value("allowPerDomainZoom", true).toBool(); +// settings.endGroup(); + + settings.beginGroup("Site-Settings"); +/* These are handled by already existing parts of Falkon */ +// m_defaults[poAllowJavascript] = settings.value("allowJavascript", Default).toInt(); +// m_defaults[poAllowImages] = settings.value("allowImages", Default).toInt(); +// m_defaults[poAllowCookies] = settings.value("allowCookies", Default).toInt(); +// m_defaults[poZoomLevel] = settings.value("defaultZoomLevel", Default).toInt(); // fail + m_defaults[poAllowNotifications] = intToPermission(settings.value("allowNotifications", Default).toInt()); + m_defaults[poAllowGeolocation] = intToPermission(settings.value("allowGealocation", Default).toInt()); + m_defaults[poAllowMediaAudioCapture] = intToPermission(settings.value("allowMicrophone", Default).toInt()); + m_defaults[poAllowMediaVideoCapture] = intToPermission(settings.value("allowCamera", Default).toInt()); + m_defaults[poAllowMediaAudioVideoCapture] = intToPermission(settings.value("allowCameraAndMicrophone", Default).toInt()); + m_defaults[poAllowMouseLock] = intToPermission(settings.value("allowMouseLock", Default).toInt()); + m_defaults[poAllowDesktopVideoCapture] = intToPermission(settings.value("allowDesktopVideoCapture", Default).toInt()); + m_defaults[poAllowDesktopAudioVideoCapture] = intToPermission(settings.value("allowDesktopAudioVideoCapture", Default).toInt()); + settings.endGroup(); +} + +void SiteSettingsManager::saveSettings() +{ + Settings settings; + settings.beginGroup("Site-Settings"); +/* These are handled by already existing parts of Falkon */ +// settings.setValue("allowJavascript", m_defaults[poAllowJavascript]); +// settings.setValue("allowIbutmages", m_defaults[poAllowImages]); +// settings.setValue("allowCookies", m_defaults[poAllowCookies]); +// settings.setValue("defaultZoomLevel", m_defaults[poZoomLevel]); + settings.setValue("allowNotifications", m_defaults[poAllowNotifications]); + settings.setValue("allowGealocation", m_defaults[poAllowGeolocation]); + settings.setValue("allowMicrophone", m_defaults[poAllowMediaAudioCapture]); + settings.setValue("allowCamera", m_defaults[poAllowMediaVideoCapture]); + settings.setValue("allowCameraAndMicrophone", m_defaults[poAllowMediaAudioVideoCapture]); + settings.setValue("allowMouseLock", m_defaults[poAllowMouseLock]); + settings.setValue("allowDesktopVideoCapture", m_defaults[poAllowDesktopVideoCapture]); + settings.setValue("allowDesktopAudioVideoCapture", m_defaults[poAllowDesktopAudioVideoCapture]); settings.endGroup(); } @@ -129,16 +165,7 @@ SiteSettingsManager::Permission SiteSettingsManager::getPermission(const SiteSet if (query.next()) { int allow_option = query.value(column).toInt(); - switch (allow_option) { - case Allow: - return Allow; - case Deny: - return Deny; - case Ask: - return Ask; - default: - return Default; - } + return intToPermission(allow_option); } return Default; @@ -205,6 +232,33 @@ SiteSettingsManager::Permission SiteSettingsManager::getDefaultPermission(const case poAllowImages: return testAttribute(QWebEngineSettings::AutoLoadImages); + case poAllowNotifications: + return m_defaults[poAllowNotifications]; + + case poAllowGeolocation: + return m_defaults[poAllowGeolocation]; + + case poAllowMediaAudioCapture: + return m_defaults[poAllowMediaAudioCapture]; + + case poAllowMediaVideoCapture: + return m_defaults[poAllowMediaVideoCapture]; + + case poAllowMediaAudioVideoCapture: + return m_defaults[poAllowMediaAudioVideoCapture]; + + case poAllowMouseLock: + return m_defaults[poAllowMouseLock]; + + case poAllowDesktopVideoCapture: + return m_defaults[poAllowDesktopVideoCapture]; + + case poAllowDesktopAudioVideoCapture: + return m_defaults[poAllowDesktopAudioVideoCapture]; + + // so far not implemented + case poZoomLevel: + case poAllowCookies: default: Q_UNREACHABLE(); qWarning() << "Unknown option" << option; @@ -212,6 +266,68 @@ SiteSettingsManager::Permission SiteSettingsManager::getDefaultPermission(const } } +SiteSettingsManager::Permission SiteSettingsManager::getDefaultPermission(const QWebEnginePage::Feature& feature) +{ + auto option = optionFromWebEngineFeature(feature); + return getDefaultPermission(option); +} + +void SiteSettingsManager::setDefaultPermission(const SiteSettingsManager::PageOptions& option, const int& value) +{ + switch (option) { + case poAllowNotifications: + case poAllowGeolocation: + case poAllowMediaAudioCapture: + case poAllowMediaVideoCapture: + case poAllowMediaAudioVideoCapture: + case poAllowMouseLock: + case poAllowDesktopVideoCapture: + case poAllowDesktopAudioVideoCapture: + setDefaultPermission(option, intToPermission(value)); + break; + + case poZoomLevel: + case poAllowCookies: + case poAllowJavascript: + case poAllowImages: + default: + Q_UNREACHABLE(); + qWarning() << "Unknown option" << option; + } +} + +void SiteSettingsManager::setDefaultPermission(const SiteSettingsManager::PageOptions& option, const SiteSettingsManager::Permission& permission) +{ + switch (option) { + case poZoomLevel: + case poAllowCookies: + case poAllowJavascript: + case poAllowImages: + qWarning() << "So far not implemented" << option; + break; + + case poAllowNotifications: + case poAllowGeolocation: + case poAllowMediaAudioCapture: + case poAllowMediaVideoCapture: + case poAllowMediaAudioVideoCapture: + case poAllowMouseLock: + case poAllowDesktopVideoCapture: + case poAllowDesktopAudioVideoCapture: + m_defaults[option] = permission; + break; + default: + Q_UNREACHABLE(); + qWarning() << "Unknown option" << option; + } +} + +void SiteSettingsManager::setDefaultPermission(const QWebEnginePage::Feature& feature, const SiteSettingsManager::Permission& value) +{ + auto option = optionFromWebEngineFeature(feature); + setDefaultPermission(option, value); +} + bool SiteSettingsManager::getDefaultOptionValue(const SiteSettingsManager::PageOptions& option) { switch (option) { @@ -283,3 +399,17 @@ SiteSettingsManager::Permission SiteSettingsManager::testAttribute(const QWebEng return Deny; } } + +SiteSettingsManager::Permission SiteSettingsManager::intToPermission(const int permission) const +{ + switch (permission) { + case Allow: + return Allow; + case Deny: + return Deny; + case Ask: + return Ask; + default: + return Default; + } +} diff --git a/src/lib/other/sitesettingsmanager.h b/src/lib/other/sitesettingsmanager.h index bbfee2233..4a51507b0 100644 --- a/src/lib/other/sitesettingsmanager.h +++ b/src/lib/other/sitesettingsmanager.h @@ -82,6 +82,7 @@ public: ~SiteSettingsManager(); void loadSettings(); + void saveSettings(); /** * @brief Get settings which should be applied to webpage before loading. @@ -100,14 +101,22 @@ public: void setOption(const PageOptions option, const QUrl &url, const int value); void setOption(const QWebEnginePage::Feature &feature, const QUrl &url, const Permission &value); + Permission getDefaultPermission(const PageOptions &option); + Permission getDefaultPermission(const QWebEnginePage::Feature &feature); + void setDefaultPermission(const PageOptions &option, const Permission &permission); + void setDefaultPermission(const QWebEnginePage::Feature &feature, const Permission &value); + void setDefaultPermission(const PageOptions &option, const int &value); + QString sqlColumnFromWebEngineFeature(const QWebEnginePage::Feature &feature); private: QString optionToSqlColumn(const PageOptions &option); bool getDefaultOptionValue(const PageOptions &option); - Permission getDefaultPermission(const PageOptions &option); PageOptions optionFromWebEngineFeature(const QWebEnginePage::Feature &feature) const; Permission testAttribute(const QWebEngineSettings::WebAttribute attribute) const; + Permission intToPermission(const int permission) const; + + QMap m_defaults; }; diff --git a/src/lib/tools/html5permissions/html5permissionsdialog.cpp b/src/lib/tools/html5permissions/html5permissionsdialog.cpp index e6be295cf..1b5a908e4 100644 --- a/src/lib/tools/html5permissions/html5permissionsdialog.cpp +++ b/src/lib/tools/html5permissions/html5permissionsdialog.cpp @@ -42,14 +42,7 @@ HTML5PermissionsDialog::HTML5PermissionsDialog(QWidget* parent) connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &HTML5PermissionsDialog::saveSettings); showFeaturePermissions(currentFeature()); - - for (int i = 0; i < 8; ++i) { - // Create permission item - auto* listItem = new QListWidgetItem(ui->listWidgetDefaults); - auto* permItem = new HTML5PermissionsItem(indexToFeature(i), SiteSettingsManager::Ask, this); - ui->listWidgetDefaults->setItemWidget(listItem, permItem); - listItem->setSizeHint(permItem->sizeHint()); - } + showDefaultPermissions(); } HTML5PermissionsDialog::~HTML5PermissionsDialog() @@ -175,4 +168,24 @@ void HTML5PermissionsDialog::saveSettings() qDebug() << query.lastError(); } } + + for (int i = 0; i < 8; ++i) { + auto* item = static_cast(ui->listWidgetDefaults->itemWidget(ui->listWidgetDefaults->item(i))); + const auto feature = item->getFeature(); + const auto permission = item->getPermission(); + mApp->siteSettingsManager()->setDefaultPermission(feature, permission); + } +} + +void HTML5PermissionsDialog::showDefaultPermissions() +{ + for (int i = 0; i < 8; ++i) { + const auto feature = indexToFeature(i); + const auto permission = mApp->siteSettingsManager()->getDefaultPermission(feature); + + auto* listItem = new QListWidgetItem(ui->listWidgetDefaults); + auto* permItem = new HTML5PermissionsItem(feature, permission, this); + ui->listWidgetDefaults->setItemWidget(listItem, permItem); + listItem->setSizeHint(permItem->sizeHint()); + } } diff --git a/src/lib/tools/html5permissions/html5permissionsdialog.h b/src/lib/tools/html5permissions/html5permissionsdialog.h index 3849fe4c6..1ee1ebb7f 100644 --- a/src/lib/tools/html5permissions/html5permissionsdialog.h +++ b/src/lib/tools/html5permissions/html5permissionsdialog.h @@ -42,6 +42,8 @@ private Q_SLOTS: void removeEntry(); void featureIndexChanged(); + void showDefaultPermissions(); + void saveSettings(); private: diff --git a/src/lib/tools/html5permissions/html5permissionsitem.cpp b/src/lib/tools/html5permissions/html5permissionsitem.cpp index aeaac226c..27fda8337 100644 --- a/src/lib/tools/html5permissions/html5permissionsitem.cpp +++ b/src/lib/tools/html5permissions/html5permissionsitem.cpp @@ -109,6 +109,7 @@ void HTML5PermissionsItem::setCombo() ui->comboBox->setCurrentIndex(1); break; case SiteSettingsManager::Ask: + case SiteSettingsManager::Default: ui->comboBox->setCurrentIndex(2); break; default: