2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2012-01-01 15:29:55 +01:00
|
|
|
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "pluginslist.h"
|
|
|
|
#include "ui_pluginslist.h"
|
|
|
|
#include "pluginproxy.h"
|
|
|
|
#include "mainapplication.h"
|
|
|
|
#include "plugininterface.h"
|
2012-02-25 12:34:16 +01:00
|
|
|
#include "pluginlistdelegate.h"
|
2012-01-11 21:58:25 +01:00
|
|
|
#include "settings.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QMessageBox>
|
2012-03-12 18:21:00 +01:00
|
|
|
#include <QTimer>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2011-12-12 21:14:43 +01:00
|
|
|
PluginsList::PluginsList(QWidget* parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, ui(new Ui::PluginsList)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
//Application Extensions
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings settings;
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.beginGroup("Plugin-Settings");
|
2012-03-12 18:21:00 +01:00
|
|
|
bool appPluginsEnabled = settings.value("EnablePlugins", DEFAULT_ENABLE_PLUGINS).toBool();
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.endGroup();
|
2012-03-12 18:21:00 +01:00
|
|
|
|
|
|
|
ui->allowAppPlugins->setChecked(appPluginsEnabled);
|
|
|
|
ui->list->setEnabled(appPluginsEnabled);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-19 16:01:51 +01:00
|
|
|
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->allowAppPlugins, SIGNAL(clicked(bool)), this, SLOT(allowAppPluginsChanged(bool)));
|
|
|
|
|
2012-03-07 21:28:31 +01:00
|
|
|
ui->list->setItemDelegate(new PluginListDelegate(ui->list));
|
2012-02-25 12:34:16 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
//WebKit Plugins
|
|
|
|
connect(ui->add, SIGNAL(clicked()), this, SLOT(addWhitelist()));
|
|
|
|
connect(ui->remove, SIGNAL(clicked()), this, SLOT(removeWhitelist()));
|
|
|
|
connect(ui->allowClick2Flash, SIGNAL(clicked(bool)), this, SLOT(allowC2FChanged(bool)));
|
|
|
|
|
|
|
|
settings.beginGroup("ClickToFlash");
|
2011-03-04 13:59:07 +01:00
|
|
|
QStringList whitelist = mApp->plugins()->c2f_getWhiteList();
|
2011-12-22 23:43:05 +01:00
|
|
|
ui->allowClick2Flash->setChecked(settings.value("Enable", true).toBool());
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.endGroup();
|
2012-01-24 19:12:31 +01:00
|
|
|
foreach(const QString & site, whitelist) {
|
2011-03-02 16:57:41 +01:00
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem(ui->whitelist);
|
|
|
|
item->setText(0, site);
|
|
|
|
}
|
2012-02-19 16:01:51 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
allowC2FChanged(ui->allowClick2Flash->isChecked());
|
2012-03-12 18:21:00 +01:00
|
|
|
|
|
|
|
if (appPluginsEnabled) {
|
|
|
|
QTimer::singleShot(0, this, SLOT(refresh()));
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PluginsList::addWhitelist()
|
|
|
|
{
|
|
|
|
QString site = QInputDialog::getText(this, tr("Add site to whitelist"), tr("Server without http:// (ex. youtube.com)"));
|
2011-11-06 17:01:23 +01:00
|
|
|
if (site.isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-03-04 13:59:07 +01:00
|
|
|
mApp->plugins()->c2f_addWhitelist(site);
|
2011-03-02 16:57:41 +01:00
|
|
|
ui->whitelist->insertTopLevelItem(0, new QTreeWidgetItem(QStringList(site)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PluginsList::removeWhitelist()
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* item = ui->whitelist->currentItem();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-03-04 13:59:07 +01:00
|
|
|
mApp->plugins()->c2f_removeWhitelist(item->text(0));
|
2011-03-02 16:57:41 +01:00
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PluginsList::save()
|
|
|
|
{
|
2012-02-19 16:01:51 +01:00
|
|
|
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>();
|
|
|
|
|
2012-03-12 18:21:00 +01:00
|
|
|
allowedPlugins.append(plugin.fullPath);
|
2012-02-19 16:01:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings settings;
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.beginGroup("Plugin-Settings");
|
2011-11-06 17:01:23 +01:00
|
|
|
settings.setValue("EnablePlugins", ui->allowAppPlugins->isChecked());
|
2012-02-19 16:01:51 +01:00
|
|
|
settings.setValue("AllowedPlugins", allowedPlugins);
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.endGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PluginsList::allowAppPluginsChanged(bool state)
|
|
|
|
{
|
2012-02-19 16:01:51 +01:00
|
|
|
ui->list->setEnabled(state);
|
|
|
|
|
|
|
|
if (state) {
|
|
|
|
refresh();
|
|
|
|
}
|
2012-03-12 18:21:00 +01:00
|
|
|
else {
|
|
|
|
for (int i = 0; i < ui->list->count(); i++) {
|
|
|
|
QListWidgetItem* item = ui->list->item(i);
|
|
|
|
|
|
|
|
if (item->checkState() == Qt::Checked) {
|
|
|
|
item->setCheckState(Qt::Unchecked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PluginsList::allowC2FChanged(bool state)
|
|
|
|
{
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings settings;
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.beginGroup("ClickToFlash");
|
|
|
|
settings.setValue("Enable", state);
|
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
ui->whitelist->setEnabled(state);
|
|
|
|
ui->add->setEnabled(state);
|
|
|
|
ui->remove->setEnabled(state);
|
|
|
|
|
2011-03-04 13:59:07 +01:00
|
|
|
mApp->plugins()->c2f_setEnabled(state);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PluginsList::refresh()
|
|
|
|
{
|
|
|
|
ui->list->clear();
|
|
|
|
ui->butSettings->setEnabled(false);
|
2012-02-19 16:01:51 +01:00
|
|
|
disconnect(ui->list, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-19 16:01:51 +01:00
|
|
|
const QList<Plugins::Plugin> &allPlugins = mApp->plugins()->getAvailablePlugins();
|
|
|
|
|
|
|
|
foreach(const Plugins::Plugin & plugin, allPlugins) {
|
|
|
|
PluginSpec spec = plugin.pluginSpec;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
QListWidgetItem* item = new QListWidgetItem(ui->list);
|
2012-03-07 21:28:31 +01:00
|
|
|
QString pluginInfo = QString("<b>%1</b> %2 (%3)<br/>\n%4<br/>\n%5\n").arg(spec.name, spec.version, spec.author, spec.info, spec.description);
|
2012-02-19 16:01:51 +01:00
|
|
|
item->setText(pluginInfo);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-25 12:34:16 +01:00
|
|
|
|
2012-02-25 10:22:23 +01:00
|
|
|
QIcon icon = QIcon(spec.icon);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (icon.isNull()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
icon = QIcon(":/icons/preferences/extension.png");
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
item->setIcon(icon);
|
|
|
|
|
|
|
|
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
2012-02-19 16:01:51 +01:00
|
|
|
item->setCheckState(plugin.isLoaded() ? Qt::Checked : Qt::Unchecked);
|
|
|
|
item->setData(Qt::UserRole + 10, qVariantFromValue(plugin));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
ui->list->addItem(item);
|
|
|
|
}
|
2012-02-19 16:01:51 +01:00
|
|
|
|
|
|
|
connect(ui->list, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void PluginsList::currentChanged(QListWidgetItem* item)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-19 16:01:51 +01:00
|
|
|
const Plugins::Plugin &plugin = item->data(Qt::UserRole + 10).value<Plugins::Plugin>();
|
|
|
|
bool showSettings = plugin.pluginSpec.hasSettings;
|
|
|
|
|
|
|
|
if (!plugin.isLoaded()) {
|
|
|
|
showSettings = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->butSettings->setEnabled(showSettings);
|
|
|
|
}
|
|
|
|
|
2012-02-20 15:56:26 +01:00
|
|
|
void PluginsList::itemChanged(QListWidgetItem* item)
|
2012-02-19 16:01:51 +01:00
|
|
|
{
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Plugins::Plugin plugin = item->data(Qt::UserRole + 10).value<Plugins::Plugin>();
|
|
|
|
|
|
|
|
if (item->checkState() == Qt::Checked) {
|
|
|
|
mApp->plugins()->loadPlugin(&plugin);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-02-19 16:01:51 +01:00
|
|
|
mApp->plugins()->unloadPlugin(&plugin);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-19 16:01:51 +01:00
|
|
|
disconnect(ui->list, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
|
|
|
|
|
|
|
|
if (item->checkState() == Qt::Checked && !plugin.isLoaded()) {
|
|
|
|
item->setCheckState(Qt::Unchecked);
|
2012-03-14 14:04:20 +01:00
|
|
|
QMessageBox::critical(this, tr("Error!"), tr("Cannot load extension!"));
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-19 16:01:51 +01:00
|
|
|
item->setData(Qt::UserRole + 10, qVariantFromValue(plugin));
|
|
|
|
|
|
|
|
connect(ui->list, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
|
|
|
|
|
|
|
|
|
|
|
|
currentChanged(ui->list->currentItem());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PluginsList::settingsClicked()
|
|
|
|
{
|
2012-02-19 16:01:51 +01:00
|
|
|
QListWidgetItem* item = ui->list->currentItem();
|
|
|
|
if (!item) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-19 16:01:51 +01:00
|
|
|
Plugins::Plugin plugin = item->data(Qt::UserRole + 10).value<Plugins::Plugin>();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-19 16:01:51 +01:00
|
|
|
if (!plugin.isLoaded()) {
|
|
|
|
mApp->plugins()->loadPlugin(&plugin);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-19 16:01:51 +01:00
|
|
|
item->setData(Qt::UserRole + 10, qVariantFromValue(plugin));
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-19 16:01:51 +01:00
|
|
|
if (plugin.isLoaded()) {
|
|
|
|
plugin.instance->showSettings(this);
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PluginsList::~PluginsList()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|