mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Loading info about all plugins when necessary, not on startup.
- should slightly improve starting time when bigger amount of plugins is available
This commit is contained in:
parent
c554e6dfdc
commit
36f90f0404
|
@ -1,11 +0,0 @@
|
|||
#!/bin/bash
|
||||
## headers.tar.gz generator
|
||||
cd ../src
|
||||
mkdir includes
|
||||
find . -name '*.h' -exec cp {} includes/ \;
|
||||
tar -cvzf headers.tar.gz includes/
|
||||
rm -r includes/
|
||||
mv headers.tar.gz ../headers.tar.gz
|
||||
|
||||
read -p "Press [ENTER] to close terminal"
|
||||
exit
|
|
@ -38,6 +38,13 @@ Plugins::Plugins(QObject* parent)
|
|||
loadSettings();
|
||||
}
|
||||
|
||||
QList<Plugins::Plugin> Plugins::getAvailablePlugins()
|
||||
{
|
||||
loadAvailablePlugins();
|
||||
|
||||
return m_availablePlugins;
|
||||
}
|
||||
|
||||
bool Plugins::loadPlugin(Plugins::Plugin* plugin)
|
||||
{
|
||||
if (plugin->isLoaded()) {
|
||||
|
@ -52,7 +59,7 @@ bool Plugins::loadPlugin(Plugins::Plugin* plugin)
|
|||
|
||||
m_availablePlugins.removeOne(*plugin);
|
||||
plugin->instance = initPlugin(iPlugin, plugin->pluginLoader);
|
||||
m_availablePlugins.append(*plugin);
|
||||
m_availablePlugins.prepend(*plugin);
|
||||
|
||||
refreshLoadedPlugins();
|
||||
|
||||
|
@ -80,7 +87,7 @@ void Plugins::loadSettings()
|
|||
Settings settings;
|
||||
settings.beginGroup("Plugin-Settings");
|
||||
m_pluginsEnabled = settings.value("EnablePlugins", DEFAULT_ENABLE_PLUGINS).toBool();
|
||||
m_allowedPluginFileNames = settings.value("AllowedPlugins", QStringList()).toStringList();
|
||||
m_allowedPlugins = settings.value("AllowedPlugins", QStringList()).toStringList();
|
||||
settings.endGroup();
|
||||
|
||||
c2f_loadSettings();
|
||||
|
@ -106,7 +113,38 @@ void Plugins::c2f_saveSettings()
|
|||
|
||||
void Plugins::loadPlugins()
|
||||
{
|
||||
if (!m_pluginsEnabled || m_pluginsLoaded) {
|
||||
if (!m_pluginsEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(const QString & fullPath, m_allowedPlugins) {
|
||||
QPluginLoader* loader = new QPluginLoader(fullPath);
|
||||
PluginInterface* iPlugin = qobject_cast<PluginInterface*>(loader->instance());
|
||||
if (!iPlugin) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Plugin plugin;
|
||||
plugin.fullPath = fullPath;
|
||||
plugin.pluginLoader = loader;
|
||||
plugin.instance = initPlugin(iPlugin, loader);
|
||||
plugin.pluginSpec = iPlugin->pluginSpec();
|
||||
|
||||
if (plugin.isLoaded()) {
|
||||
m_loadedPlugins.append(plugin.instance);
|
||||
}
|
||||
|
||||
m_availablePlugins.append(plugin);
|
||||
}
|
||||
|
||||
refreshLoadedPlugins();
|
||||
|
||||
std::cout << "QupZilla: " << m_loadedPlugins.count() << " plugins loaded" << std::endl;
|
||||
}
|
||||
|
||||
void Plugins::loadAvailablePlugins()
|
||||
{
|
||||
if (m_pluginsLoaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -122,33 +160,28 @@ void Plugins::loadPlugins()
|
|||
foreach(const QString & dir, dirs) {
|
||||
QDir pluginsDir = QDir(dir);
|
||||
foreach(const QString & fileName, pluginsDir.entryList(QDir::Files)) {
|
||||
QPluginLoader* loader = new QPluginLoader(pluginsDir.absoluteFilePath(fileName));
|
||||
const QString absolutePath = pluginsDir.absoluteFilePath(fileName);
|
||||
if (m_allowedPlugins.contains(absolutePath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QPluginLoader* loader = new QPluginLoader(absolutePath);
|
||||
PluginInterface* iPlugin = qobject_cast<PluginInterface*>(loader->instance());
|
||||
if (!iPlugin) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Plugin plugin;
|
||||
plugin.fileName = fileName;
|
||||
plugin.fullPath = pluginsDir.absoluteFilePath(fileName);
|
||||
plugin.fullPath = absolutePath;
|
||||
plugin.pluginSpec = iPlugin->pluginSpec();
|
||||
plugin.pluginLoader = loader;
|
||||
plugin.instance = 0;
|
||||
|
||||
if (m_allowedPluginFileNames.contains(fileName)) {
|
||||
plugin.instance = initPlugin(iPlugin, loader);
|
||||
}
|
||||
else {
|
||||
loader->unload();
|
||||
}
|
||||
|
||||
m_availablePlugins.append(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
refreshLoadedPlugins();
|
||||
|
||||
std::cout << m_loadedPlugins.count() << " plugins loaded" << std::endl;
|
||||
}
|
||||
|
||||
PluginInterface* Plugins::initPlugin(PluginInterface* interface, QPluginLoader* loader)
|
||||
|
|
|
@ -54,7 +54,7 @@ public:
|
|||
|
||||
explicit Plugins(QObject* parent = 0);
|
||||
|
||||
QList<Plugin> getAvailablePlugins() { return m_availablePlugins; }
|
||||
QList<Plugin> getAvailablePlugins();
|
||||
|
||||
bool loadPlugin(Plugin* plugin);
|
||||
void unloadPlugin(Plugin* plugin);
|
||||
|
@ -80,10 +80,12 @@ protected:
|
|||
|
||||
private:
|
||||
PluginInterface* initPlugin(PluginInterface* interface, QPluginLoader* loader);
|
||||
|
||||
void refreshLoadedPlugins();
|
||||
void loadAvailablePlugins();
|
||||
|
||||
QList<Plugin> m_availablePlugins;
|
||||
QStringList m_allowedPluginFileNames;
|
||||
QStringList m_allowedPlugins;
|
||||
|
||||
bool m_pluginsEnabled;
|
||||
bool m_pluginsLoaded;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <QTextDocument>
|
||||
#include <QTextBlock>
|
||||
#include <QApplication>
|
||||
#include <QScrollBar>
|
||||
|
||||
PluginListDelegate::PluginListDelegate(QListWidget* parent)
|
||||
: QItemDelegate(parent)
|
||||
|
@ -77,9 +78,10 @@ QSize PluginListDelegate::sizeHint(const QStyleOptionViewItem &option, const QMo
|
|||
Q_UNUSED(index)
|
||||
|
||||
const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0) + 1;
|
||||
const int scrollBarSize = m_listWidget->verticalScrollBar()->isVisible() ? m_listWidget->verticalScrollBar()->width() : 0;
|
||||
|
||||
QSize size;
|
||||
size.setWidth(m_listWidget->width() - 10);
|
||||
size.setWidth(m_listWidget->width() - 10 - scrollBarSize);
|
||||
|
||||
// ( height of font * 3 = 3 lines ) + ( text margins ) + ( 2 free lines = every line is 3px )
|
||||
size.setHeight((option.fontMetrics.height() * 3) + (textMargin * 2) + (2 * 3));
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
|
||||
#ifdef PORTABLE_BUILD
|
||||
#define DEFAULT_ENABLE_PLUGINS false
|
||||
|
@ -41,9 +42,11 @@ PluginsList::PluginsList(QWidget* parent)
|
|||
//Application Extensions
|
||||
Settings settings;
|
||||
settings.beginGroup("Plugin-Settings");
|
||||
ui->allowAppPlugins->setChecked(settings.value("EnablePlugins", DEFAULT_ENABLE_PLUGINS).toBool());
|
||||
bool appPluginsEnabled = settings.value("EnablePlugins", DEFAULT_ENABLE_PLUGINS).toBool();
|
||||
settings.endGroup();
|
||||
allowAppPluginsChanged(ui->allowAppPlugins->isChecked());
|
||||
|
||||
ui->allowAppPlugins->setChecked(appPluginsEnabled);
|
||||
ui->list->setEnabled(appPluginsEnabled);
|
||||
|
||||
connect(ui->butSettings, SIGNAL(clicked()), this, SLOT(settingsClicked()));
|
||||
connect(ui->list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(currentChanged(QListWidgetItem*)));
|
||||
|
@ -67,6 +70,10 @@ PluginsList::PluginsList(QWidget* parent)
|
|||
}
|
||||
|
||||
allowC2FChanged(ui->allowClick2Flash->isChecked());
|
||||
|
||||
if (appPluginsEnabled) {
|
||||
QTimer::singleShot(0, this, SLOT(refresh()));
|
||||
}
|
||||
}
|
||||
|
||||
void PluginsList::addWhitelist()
|
||||
|
@ -100,7 +107,7 @@ void PluginsList::save()
|
|||
if (item->checkState() == Qt::Checked) {
|
||||
const Plugins::Plugin &plugin = item->data(Qt::UserRole + 10).value<Plugins::Plugin>();
|
||||
|
||||
allowedPlugins.append(plugin.fileName);
|
||||
allowedPlugins.append(plugin.fullPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,19 +120,20 @@ void PluginsList::save()
|
|||
|
||||
void PluginsList::allowAppPluginsChanged(bool state)
|
||||
{
|
||||
Settings settings;
|
||||
settings.beginGroup("Plugin-Settings");
|
||||
settings.setValue("EnablePlugins", state);
|
||||
settings.endGroup();
|
||||
|
||||
mApp->plugins()->loadSettings();
|
||||
mApp->plugins()->loadPlugins();
|
||||
|
||||
ui->list->setEnabled(state);
|
||||
|
||||
if (state) {
|
||||
refresh();
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PluginsList::allowC2FChanged(bool state)
|
||||
|
|
|
@ -45,13 +45,14 @@ private slots:
|
|||
void itemChanged(QListWidgetItem* item);
|
||||
void allowAppPluginsChanged(bool state);
|
||||
|
||||
void refresh();
|
||||
|
||||
//WebKit plugins
|
||||
void addWhitelist();
|
||||
void removeWhitelist();
|
||||
void allowC2FChanged(bool state);
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
private:;
|
||||
|
||||
Ui::PluginsList* ui;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user