mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-21 03:06:34 +01:00
added permission to allow plugins in private mode
This commit is contained in:
parent
9d9766dc13
commit
f09238115f
@ -21,6 +21,7 @@
|
|||||||
#include "updater.h"
|
#include "updater.h"
|
||||||
#include "qztools.h"
|
#include "qztools.h"
|
||||||
#include "sqldatabase.h"
|
#include "sqldatabase.h"
|
||||||
|
#include "plugins.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QSqlError>
|
#include <QSqlError>
|
||||||
@ -305,6 +306,18 @@ void ProfileManager::connectDatabase()
|
|||||||
qCritical() << "Error creating database schema" << query.lastError().text();
|
qCritical() << "Error creating database schema" << query.lastError().text();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Insert default allowed plugins to allowed_plugins table
|
||||||
|
QStringList defaultAllowedPlugins = Plugins::getDefaultAllowedPlugins();
|
||||||
|
QSqlQuery query(SqlDatabase::instance()->database());
|
||||||
|
for (const QString &defaultPlugin : defaultAllowedPlugins) {
|
||||||
|
query.prepare("INSERT INTO allowed_plugins VALUES (?, ?)");
|
||||||
|
query.addBindValue(defaultPlugin);
|
||||||
|
query.addBindValue(1);
|
||||||
|
if (!query.exec()) {
|
||||||
|
qWarning() << "Unable to insert" << defaultPlugin << "into database";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SqlDatabase::instance()->setDatabase(db);
|
SqlDatabase::instance()->setDatabase(db);
|
||||||
|
@ -55,4 +55,9 @@ CREATE TABLE icons (
|
|||||||
);
|
);
|
||||||
CREATE UNIQUE INDEX icons_urluniqueindex ON icons (url);
|
CREATE UNIQUE INDEX icons_urluniqueindex ON icons (url);
|
||||||
|
|
||||||
|
CREATE TABLE allowed_plugins (
|
||||||
|
pluginId TEXT NOT NULL UNIQUE,
|
||||||
|
allowInPrivateMode INTEGER DEFAULT 0 NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
-- Data
|
-- Data
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
#include "desktopfile.h"
|
#include "desktopfile.h"
|
||||||
#include "qml/qmlplugins.h"
|
#include "qml/qmlplugins.h"
|
||||||
|
#include "sqldatabase.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <QPluginLoader>
|
#include <QPluginLoader>
|
||||||
@ -89,19 +90,15 @@ void Plugins::unloadPlugin(Plugins::Plugin* plugin)
|
|||||||
|
|
||||||
void Plugins::loadSettings()
|
void Plugins::loadSettings()
|
||||||
{
|
{
|
||||||
QStringList defaultAllowedPlugins = {
|
QSqlQuery query(SqlDatabase::instance()->database());
|
||||||
QSL("internal:adblock")
|
if (mApp->isPrivate()) {
|
||||||
};
|
query.exec(QSL("SELECT * FROM allowed_plugins WHERE allowInPrivateMode=1"));
|
||||||
|
} else {
|
||||||
// Enable KDE Frameworks Integration when running inside KDE session
|
query.exec(QSL("SELECT * FROM allowed_plugins"));
|
||||||
if (qgetenv("KDE_FULL_SESSION") == QByteArray("true")) {
|
}
|
||||||
defaultAllowedPlugins.append(QSL("lib:KDEFrameworksIntegration.so"));
|
while (query.next()) {
|
||||||
|
m_allowedPlugins.append(query.value(0).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings settings;
|
|
||||||
settings.beginGroup("Plugin-Settings");
|
|
||||||
m_allowedPlugins = settings.value("AllowedPlugins", defaultAllowedPlugins).toStringList();
|
|
||||||
settings.endGroup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plugins::shutdown()
|
void Plugins::shutdown()
|
||||||
@ -481,3 +478,18 @@ void Plugins::initQmlPlugin(Plugin *plugin)
|
|||||||
plugin->qmlPluginLoader->setName(plugin->pluginSpec.name);
|
plugin->qmlPluginLoader->setName(plugin->pluginSpec.name);
|
||||||
plugin->instance = qobject_cast<PluginInterface*>(plugin->qmlPluginLoader->instance());
|
plugin->instance = qobject_cast<PluginInterface*>(plugin->qmlPluginLoader->instance());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
QStringList Plugins::getDefaultAllowedPlugins()
|
||||||
|
{
|
||||||
|
QStringList defaultAllowedPlugins = {
|
||||||
|
QSL("internal:adblock")
|
||||||
|
};
|
||||||
|
|
||||||
|
// Enable KDE Frameworks Integration when running inside KDE session
|
||||||
|
if (qgetenv("KDE_FULL_SESSION") == QByteArray("true")) {
|
||||||
|
defaultAllowedPlugins.append(QSL("lib:KDEFrameworksIntegration.so"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultAllowedPlugins;
|
||||||
|
}
|
||||||
|
@ -103,6 +103,8 @@ public:
|
|||||||
|
|
||||||
static PluginSpec createSpec(const DesktopFile &metaData);
|
static PluginSpec createSpec(const DesktopFile &metaData);
|
||||||
|
|
||||||
|
static QStringList getDefaultAllowedPlugins();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
|
|
||||||
|
@ -57,6 +57,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="allowInPrivateModeBox">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Allow in private mode</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "pluginsmanager.h"
|
#include "pluginsmanager.h"
|
||||||
#include "ui_pluginslist.h"
|
#include "ui_pluginslist.h"
|
||||||
#include "pluginproxy.h"
|
|
||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
#include "plugininterface.h"
|
#include "plugininterface.h"
|
||||||
#include "pluginlistdelegate.h"
|
#include "pluginlistdelegate.h"
|
||||||
@ -25,10 +24,12 @@
|
|||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "iconprovider.h"
|
#include "iconprovider.h"
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
|
#include "sqldatabase.h"
|
||||||
|
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QCheckBox>
|
||||||
|
|
||||||
PluginsManager::PluginsManager(QWidget* parent)
|
PluginsManager::PluginsManager(QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
@ -50,7 +51,7 @@ PluginsManager::PluginsManager(QWidget* parent)
|
|||||||
connect(ui->butSettings, SIGNAL(clicked()), this, SLOT(settingsClicked()));
|
connect(ui->butSettings, SIGNAL(clicked()), this, SLOT(settingsClicked()));
|
||||||
connect(ui->list, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(currentChanged(QListWidgetItem*)));
|
connect(ui->list, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(currentChanged(QListWidgetItem*)));
|
||||||
connect(ui->list, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
|
connect(ui->list, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
|
||||||
|
connect(ui->allowInPrivateModeBox, &QCheckBox::toggled, this, &PluginsManager::allowInPrivateModeBoxToggled);
|
||||||
ui->list->setItemDelegate(new PluginListDelegate(ui->list));
|
ui->list->setItemDelegate(new PluginListDelegate(ui->list));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,20 +69,25 @@ void PluginsManager::save()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList allowedPlugins;
|
if (mApp->isPrivate()) {
|
||||||
for (int i = 0; i < ui->list->count(); i++) {
|
QMessageBox::warning(this, tr("Error!"), tr("Cannot manage extensions in private mode!"));
|
||||||
QListWidgetItem* item = ui->list->item(i);
|
return;
|
||||||
|
|
||||||
if (item->checkState() == Qt::Checked) {
|
|
||||||
const Plugins::Plugin plugin = item->data(Qt::UserRole + 10).value<Plugins::Plugin>();
|
|
||||||
allowedPlugins.append(plugin.pluginId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings settings;
|
for (int i = 0; i < ui->list->count(); i++) {
|
||||||
settings.beginGroup("Plugin-Settings");
|
QListWidgetItem* item = ui->list->item(i);
|
||||||
settings.setValue("AllowedPlugins", allowedPlugins);
|
const Plugins::Plugin plugin = item->data(Qt::UserRole + 10).value<Plugins::Plugin>();
|
||||||
settings.endGroup();
|
if (item->checkState() == Qt::Checked) {
|
||||||
|
auto job = new SqlQueryJob(QSL("INSERT OR REPLACE INTO allowed_plugins (pluginId, allowInPrivateMode) VALUES (?, ?)"), this);
|
||||||
|
job->addBindValue(plugin.pluginId);
|
||||||
|
job->addBindValue(m_allowInPrivateMode[plugin.pluginId]);
|
||||||
|
job->start();
|
||||||
|
} else {
|
||||||
|
auto job = new SqlQueryJob(QSL("DELETE FROM allowed_plugins WHERE pluginId = ?"), this);
|
||||||
|
job->addBindValue(plugin.pluginId);
|
||||||
|
job->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginsManager::refresh()
|
void PluginsManager::refresh()
|
||||||
@ -120,6 +126,12 @@ void PluginsManager::refresh()
|
|||||||
sortItems();
|
sortItems();
|
||||||
|
|
||||||
connect(ui->list, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
|
connect(ui->list, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
|
||||||
|
|
||||||
|
QSqlQuery query(SqlDatabase::instance()->database());
|
||||||
|
query.exec(QSL("SELECT * FROM allowed_plugins"));
|
||||||
|
while (query.next()) {
|
||||||
|
m_allowInPrivateMode[query.value(0).toString()] = query.value(1).toInt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginsManager::sortItems()
|
void PluginsManager::sortItems()
|
||||||
@ -154,12 +166,21 @@ void PluginsManager::currentChanged(QListWidgetItem* item)
|
|||||||
|
|
||||||
const Plugins::Plugin plugin = item->data(Qt::UserRole + 10).value<Plugins::Plugin>();
|
const Plugins::Plugin plugin = item->data(Qt::UserRole + 10).value<Plugins::Plugin>();
|
||||||
bool showSettings = plugin.pluginSpec.hasSettings;
|
bool showSettings = plugin.pluginSpec.hasSettings;
|
||||||
|
bool enableAllowInPrivateModeBox = true;
|
||||||
|
|
||||||
if (!plugin.isLoaded()) {
|
if (plugin.isLoaded()) {
|
||||||
|
if (m_allowInPrivateMode[plugin.pluginId]) {
|
||||||
|
ui->allowInPrivateModeBox->setChecked(true);
|
||||||
|
} else {
|
||||||
|
ui->allowInPrivateModeBox->setChecked(false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
showSettings = false;
|
showSettings = false;
|
||||||
|
enableAllowInPrivateModeBox = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->butSettings->setEnabled(showSettings);
|
ui->butSettings->setEnabled(showSettings);
|
||||||
|
ui->allowInPrivateModeBox->setEnabled(enableAllowInPrivateModeBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginsManager::itemChanged(QListWidgetItem* item)
|
void PluginsManager::itemChanged(QListWidgetItem* item)
|
||||||
@ -194,19 +215,12 @@ void PluginsManager::itemChanged(QListWidgetItem* item)
|
|||||||
|
|
||||||
void PluginsManager::settingsClicked()
|
void PluginsManager::settingsClicked()
|
||||||
{
|
{
|
||||||
QListWidgetItem* item = ui->list->currentItem();
|
Plugins::Plugin plugin = getCurrentPlugin();
|
||||||
if (!item || item->checkState() == Qt::Unchecked) {
|
|
||||||
|
if (plugin.type == Plugins::Plugin::Invalid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Plugins::Plugin plugin = item->data(Qt::UserRole + 10).value<Plugins::Plugin>();
|
|
||||||
|
|
||||||
if (!plugin.isLoaded()) {
|
|
||||||
mApp->plugins()->loadPlugin(&plugin);
|
|
||||||
|
|
||||||
item->setData(Qt::UserRole + 10, QVariant::fromValue(plugin));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plugin.isLoaded() && plugin.pluginSpec.hasSettings) {
|
if (plugin.isLoaded() && plugin.pluginSpec.hasSettings) {
|
||||||
plugin.instance->showSettings(this);
|
plugin.instance->showSettings(this);
|
||||||
}
|
}
|
||||||
@ -216,3 +230,38 @@ PluginsManager::~PluginsManager()
|
|||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PluginsManager::allowInPrivateModeBoxToggled(bool state)
|
||||||
|
{
|
||||||
|
Plugins::Plugin plugin = getCurrentPlugin();
|
||||||
|
|
||||||
|
if (plugin.type == Plugins::Plugin::Invalid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plugin.isLoaded()) {
|
||||||
|
if (state) {
|
||||||
|
m_allowInPrivateMode[plugin.pluginId] = 1;
|
||||||
|
} else {
|
||||||
|
m_allowInPrivateMode[plugin.pluginId] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Plugins::Plugin PluginsManager::getCurrentPlugin()
|
||||||
|
{
|
||||||
|
QListWidgetItem* item = ui->list->currentItem();
|
||||||
|
if (!item || item->checkState() == Qt::Unchecked) {
|
||||||
|
return Plugins::Plugin();
|
||||||
|
}
|
||||||
|
|
||||||
|
Plugins::Plugin plugin = item->data(Qt::UserRole + 10).value<Plugins::Plugin>();
|
||||||
|
|
||||||
|
if (!plugin.isLoaded()) {
|
||||||
|
mApp->plugins()->loadPlugin(&plugin);
|
||||||
|
|
||||||
|
item->setData(Qt::UserRole + 10, QVariant::fromValue(plugin));
|
||||||
|
}
|
||||||
|
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include "qzcommon.h"
|
#include "qzcommon.h"
|
||||||
|
#include "pluginproxy.h"
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
@ -44,14 +45,17 @@ private Q_SLOTS:
|
|||||||
void settingsClicked();
|
void settingsClicked();
|
||||||
void currentChanged(QListWidgetItem* item);
|
void currentChanged(QListWidgetItem* item);
|
||||||
void itemChanged(QListWidgetItem* item);
|
void itemChanged(QListWidgetItem* item);
|
||||||
|
void allowInPrivateModeBoxToggled(bool state);
|
||||||
|
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void sortItems();
|
void sortItems();
|
||||||
|
Plugins::Plugin getCurrentPlugin();
|
||||||
|
|
||||||
Ui::PluginsList* ui;
|
Ui::PluginsList* ui;
|
||||||
bool m_loaded;
|
bool m_loaded;
|
||||||
|
QMap<QString, int> m_allowInPrivateMode;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLUGINSMANAGER_H
|
#endif // PLUGINSMANAGER_H
|
||||||
|
Loading…
Reference in New Issue
Block a user