From 36f90f04041be071e2c274eb39578ff893670b04 Mon Sep 17 00:00:00 2001 From: nowrep Date: Mon, 12 Mar 2012 18:21:00 +0100 Subject: [PATCH] Loading info about all plugins when necessary, not on startup. - should slightly improve starting time when bigger amount of plugins is available --- scripts/headergenerator.sh | 11 ---- src/lib/plugins/plugins.cpp | 69 ++++++++++++++++------ src/lib/plugins/plugins.h | 6 +- src/lib/preferences/pluginlistdelegate.cpp | 4 +- src/lib/preferences/pluginslist.cpp | 30 ++++++---- src/lib/preferences/pluginslist.h | 5 +- 6 files changed, 80 insertions(+), 45 deletions(-) delete mode 100755 scripts/headergenerator.sh diff --git a/scripts/headergenerator.sh b/scripts/headergenerator.sh deleted file mode 100755 index 98a37ff6e..000000000 --- a/scripts/headergenerator.sh +++ /dev/null @@ -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 diff --git a/src/lib/plugins/plugins.cpp b/src/lib/plugins/plugins.cpp index a7fbdf508..b65504d4b 100644 --- a/src/lib/plugins/plugins.cpp +++ b/src/lib/plugins/plugins.cpp @@ -38,6 +38,13 @@ Plugins::Plugins(QObject* parent) loadSettings(); } +QList 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(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; } @@ -114,41 +152,36 @@ void Plugins::loadPlugins() QStringList dirs; dirs << mApp->DATADIR + "plugins/" -#ifdef Q_WS_X11 + #ifdef Q_WS_X11 << "/usr/lib/qupzilla/" -#endif + #endif << mApp->PROFILEDIR + "plugins/"; 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(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(); - } + loader->unload(); m_availablePlugins.append(plugin); } } - - refreshLoadedPlugins(); - - std::cout << m_loadedPlugins.count() << " plugins loaded" << std::endl; } PluginInterface* Plugins::initPlugin(PluginInterface* interface, QPluginLoader* loader) diff --git a/src/lib/plugins/plugins.h b/src/lib/plugins/plugins.h index c19c4d9a4..24d8a38c9 100644 --- a/src/lib/plugins/plugins.h +++ b/src/lib/plugins/plugins.h @@ -54,7 +54,7 @@ public: explicit Plugins(QObject* parent = 0); - QList getAvailablePlugins() { return m_availablePlugins; } + QList 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 m_availablePlugins; - QStringList m_allowedPluginFileNames; + QStringList m_allowedPlugins; bool m_pluginsEnabled; bool m_pluginsLoaded; diff --git a/src/lib/preferences/pluginlistdelegate.cpp b/src/lib/preferences/pluginlistdelegate.cpp index 17ba3d0e2..3342d2317 100644 --- a/src/lib/preferences/pluginlistdelegate.cpp +++ b/src/lib/preferences/pluginlistdelegate.cpp @@ -23,6 +23,7 @@ #include #include #include +#include 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)); diff --git a/src/lib/preferences/pluginslist.cpp b/src/lib/preferences/pluginslist.cpp index 17e2c262e..5855e8c1e 100644 --- a/src/lib/preferences/pluginslist.cpp +++ b/src/lib/preferences/pluginslist.cpp @@ -25,6 +25,7 @@ #include #include +#include #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(); - 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) diff --git a/src/lib/preferences/pluginslist.h b/src/lib/preferences/pluginslist.h index ea88a9351..49a1da32c 100644 --- a/src/lib/preferences/pluginslist.h +++ b/src/lib/preferences/pluginslist.h @@ -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; };