2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2011-12-15 18:34:48 +01:00
|
|
|
* Copyright (C) 2010-2011 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"
|
|
|
|
|
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
|
|
|
|
refresh();
|
|
|
|
connect(ui->butSettings, SIGNAL(clicked()), this, SLOT(settingsClicked()));
|
2011-11-06 17:01:23 +01:00
|
|
|
connect(ui->list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(currentChanged(QListWidgetItem*)));
|
2011-03-02 16:57:41 +01:00
|
|
|
connect(ui->butLoad, SIGNAL(clicked()), this, SLOT(reloadPlugins()));
|
|
|
|
connect(ui->allowAppPlugins, SIGNAL(clicked(bool)), this, SLOT(allowAppPluginsChanged(bool)));
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat);
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.beginGroup("Plugin-Settings");
|
2011-11-06 17:01:23 +01:00
|
|
|
ui->allowAppPlugins->setChecked(settings.value("EnablePlugins", true).toBool());
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.endGroup();
|
|
|
|
allowAppPluginsChanged(ui->allowAppPlugins->isChecked());
|
|
|
|
|
|
|
|
//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-11-09 20:20:42 +01:00
|
|
|
ui->allowClick2Flash->setChecked(settings.value("Enable", false).toBool());
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.endGroup();
|
2011-11-06 17:01:23 +01:00
|
|
|
foreach(QString site, whitelist) {
|
2011-03-02 16:57:41 +01:00
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem(ui->whitelist);
|
|
|
|
item->setText(0, site);
|
|
|
|
}
|
|
|
|
allowC2FChanged(ui->allowClick2Flash->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat);
|
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());
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
reloadPlugins();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PluginsList::allowAppPluginsChanged(bool state)
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat);
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.beginGroup("Plugin-Settings");
|
|
|
|
settings.setValue("EnablePlugins", state);
|
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
ui->verticalFrame->setEnabled(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PluginsList::allowC2FChanged(bool state)
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat);
|
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);
|
|
|
|
|
2011-03-04 13:59:07 +01:00
|
|
|
QStringList availablePlugins = mApp->plugins()->getAvailablePlugins();
|
|
|
|
QStringList allowedPlugins = mApp->plugins()->getAllowedPlugins();
|
2011-11-06 17:01:23 +01:00
|
|
|
foreach(QString fileName, availablePlugins) {
|
2011-03-04 13:59:07 +01:00
|
|
|
PluginInterface* plugin = mApp->plugins()->getPlugin(fileName);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!plugin) {
|
2011-03-02 16:57:41 +01:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
QListWidgetItem* item = new QListWidgetItem(ui->list);
|
2011-11-06 17:01:23 +01:00
|
|
|
item->setText("" + plugin->pluginName() + " (" + plugin->pluginVersion() + ") by " + plugin->pluginAuthor() + "\n"
|
|
|
|
+ plugin->pluginInfo() + "\n" + plugin->pluginDescription());
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
QIcon icon = plugin->pluginIcon();
|
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);
|
2011-11-06 17:01:23 +01:00
|
|
|
item->setCheckState((allowedPlugins.contains(fileName)) ? Qt::Checked : Qt::Unchecked);
|
2011-03-02 16:57:41 +01:00
|
|
|
item->setWhatsThis(plugin->hasSettings() ? "1" : "0");
|
|
|
|
item->setToolTip(fileName);
|
|
|
|
|
|
|
|
ui->list->addItem(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
QString has = item->whatsThis();
|
|
|
|
bool show;
|
2011-11-06 17:01:23 +01:00
|
|
|
if (has == "1") {
|
2011-03-02 16:57:41 +01:00
|
|
|
show = true;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-03-02 16:57:41 +01:00
|
|
|
show = false;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (item->checkState() == Qt::Unchecked) {
|
2011-03-02 16:57:41 +01:00
|
|
|
show = false;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
ui->butSettings->setEnabled(show);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PluginsList::settingsClicked()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!ui->list->currentItem()) {
|
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
|
|
|
|
|
|
|
QString name = ui->list->currentItem()->toolTip();
|
2011-03-04 13:59:07 +01:00
|
|
|
PluginInterface* plugin = mApp->plugins()->getPlugin(name);
|
2011-03-02 16:57:41 +01:00
|
|
|
plugin->showSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PluginsList::reloadPlugins()
|
|
|
|
{
|
|
|
|
QStringList allowedPlugins;
|
|
|
|
for (int i = 0; i < ui->list->count(); i++) {
|
2011-11-06 17:01:23 +01:00
|
|
|
if (ui->list->item(i)->checkState() == Qt::Checked) {
|
2011-03-02 16:57:41 +01:00
|
|
|
allowedPlugins.append(ui->list->item(i)->toolTip());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat);
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.beginGroup("Plugin-Settings");
|
2011-11-06 17:01:23 +01:00
|
|
|
settings.setValue("AllowedPlugins", allowedPlugins);
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.endGroup();
|
|
|
|
|
2011-03-04 13:59:07 +01:00
|
|
|
mApp->plugins()->loadSettings();
|
|
|
|
mApp->plugins()->loadPlugins();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginsList::~PluginsList()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|