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 "qztools.h"
|
||||
#include "sqldatabase.h"
|
||||
#include "plugins.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QSqlError>
|
||||
@ -305,6 +306,18 @@ void ProfileManager::connectDatabase()
|
||||
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);
|
||||
|
@ -55,4 +55,9 @@ CREATE TABLE icons (
|
||||
);
|
||||
CREATE UNIQUE INDEX icons_urluniqueindex ON icons (url);
|
||||
|
||||
CREATE TABLE allowed_plugins (
|
||||
pluginId TEXT NOT NULL UNIQUE,
|
||||
allowInPrivateMode INTEGER DEFAULT 0 NOT NULL
|
||||
);
|
||||
|
||||
-- Data
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "../config.h"
|
||||
#include "desktopfile.h"
|
||||
#include "qml/qmlplugins.h"
|
||||
#include "sqldatabase.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <QPluginLoader>
|
||||
@ -89,19 +90,15 @@ void Plugins::unloadPlugin(Plugins::Plugin* plugin)
|
||||
|
||||
void Plugins::loadSettings()
|
||||
{
|
||||
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"));
|
||||
QSqlQuery query(SqlDatabase::instance()->database());
|
||||
if (mApp->isPrivate()) {
|
||||
query.exec(QSL("SELECT * FROM allowed_plugins WHERE allowInPrivateMode=1"));
|
||||
} else {
|
||||
query.exec(QSL("SELECT * FROM allowed_plugins"));
|
||||
}
|
||||
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()
|
||||
@ -481,3 +478,18 @@ void Plugins::initQmlPlugin(Plugin *plugin)
|
||||
plugin->qmlPluginLoader->setName(plugin->pluginSpec.name);
|
||||
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 QStringList getDefaultAllowedPlugins();
|
||||
|
||||
public Q_SLOTS:
|
||||
void loadSettings();
|
||||
|
||||
|
@ -57,6 +57,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
|
@ -17,7 +17,6 @@
|
||||
* ============================================================ */
|
||||
#include "pluginsmanager.h"
|
||||
#include "ui_pluginslist.h"
|
||||
#include "pluginproxy.h"
|
||||
#include "mainapplication.h"
|
||||
#include "plugininterface.h"
|
||||
#include "pluginlistdelegate.h"
|
||||
@ -25,10 +24,12 @@
|
||||
#include "settings.h"
|
||||
#include "iconprovider.h"
|
||||
#include "../config.h"
|
||||
#include "sqldatabase.h"
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
#include <QCheckBox>
|
||||
|
||||
PluginsManager::PluginsManager(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
@ -50,7 +51,7 @@ PluginsManager::PluginsManager(QWidget* parent)
|
||||
connect(ui->butSettings, SIGNAL(clicked()), this, SLOT(settingsClicked()));
|
||||
connect(ui->list, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(currentChanged(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));
|
||||
}
|
||||
|
||||
@ -68,20 +69,25 @@ void PluginsManager::save()
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList allowedPlugins;
|
||||
for (int i = 0; i < ui->list->count(); i++) {
|
||||
QListWidgetItem* item = ui->list->item(i);
|
||||
|
||||
if (item->checkState() == Qt::Checked) {
|
||||
const Plugins::Plugin plugin = item->data(Qt::UserRole + 10).value<Plugins::Plugin>();
|
||||
allowedPlugins.append(plugin.pluginId);
|
||||
}
|
||||
if (mApp->isPrivate()) {
|
||||
QMessageBox::warning(this, tr("Error!"), tr("Cannot manage extensions in private mode!"));
|
||||
return;
|
||||
}
|
||||
|
||||
Settings settings;
|
||||
settings.beginGroup("Plugin-Settings");
|
||||
settings.setValue("AllowedPlugins", allowedPlugins);
|
||||
settings.endGroup();
|
||||
for (int i = 0; i < ui->list->count(); i++) {
|
||||
QListWidgetItem* item = ui->list->item(i);
|
||||
const Plugins::Plugin plugin = item->data(Qt::UserRole + 10).value<Plugins::Plugin>();
|
||||
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()
|
||||
@ -120,6 +126,12 @@ void PluginsManager::refresh()
|
||||
sortItems();
|
||||
|
||||
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()
|
||||
@ -154,12 +166,21 @@ void PluginsManager::currentChanged(QListWidgetItem* item)
|
||||
|
||||
const Plugins::Plugin plugin = item->data(Qt::UserRole + 10).value<Plugins::Plugin>();
|
||||
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;
|
||||
enableAllowInPrivateModeBox = false;
|
||||
}
|
||||
|
||||
ui->butSettings->setEnabled(showSettings);
|
||||
ui->allowInPrivateModeBox->setEnabled(enableAllowInPrivateModeBox);
|
||||
}
|
||||
|
||||
void PluginsManager::itemChanged(QListWidgetItem* item)
|
||||
@ -194,19 +215,12 @@ void PluginsManager::itemChanged(QListWidgetItem* item)
|
||||
|
||||
void PluginsManager::settingsClicked()
|
||||
{
|
||||
QListWidgetItem* item = ui->list->currentItem();
|
||||
if (!item || item->checkState() == Qt::Unchecked) {
|
||||
Plugins::Plugin plugin = getCurrentPlugin();
|
||||
|
||||
if (plugin.type == Plugins::Plugin::Invalid) {
|
||||
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) {
|
||||
plugin.instance->showSettings(this);
|
||||
}
|
||||
@ -216,3 +230,38 @@ PluginsManager::~PluginsManager()
|
||||
{
|
||||
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 "qzcommon.h"
|
||||
#include "pluginproxy.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
@ -44,14 +45,17 @@ private Q_SLOTS:
|
||||
void settingsClicked();
|
||||
void currentChanged(QListWidgetItem* item);
|
||||
void itemChanged(QListWidgetItem* item);
|
||||
void allowInPrivateModeBoxToggled(bool state);
|
||||
|
||||
void refresh();
|
||||
|
||||
private:
|
||||
void sortItems();
|
||||
Plugins::Plugin getCurrentPlugin();
|
||||
|
||||
Ui::PluginsList* ui;
|
||||
bool m_loaded;
|
||||
QMap<QString, int> m_allowInPrivateMode;
|
||||
};
|
||||
|
||||
#endif // PLUGINSMANAGER_H
|
||||
|
Loading…
Reference in New Issue
Block a user