1
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:
nowrep 2012-03-12 18:21:00 +01:00
parent c554e6dfdc
commit 36f90f0404
6 changed files with 80 additions and 45 deletions

View File

@ -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

View File

@ -38,6 +38,13 @@ Plugins::Plugins(QObject* parent)
loadSettings(); loadSettings();
} }
QList<Plugins::Plugin> Plugins::getAvailablePlugins()
{
loadAvailablePlugins();
return m_availablePlugins;
}
bool Plugins::loadPlugin(Plugins::Plugin* plugin) bool Plugins::loadPlugin(Plugins::Plugin* plugin)
{ {
if (plugin->isLoaded()) { if (plugin->isLoaded()) {
@ -52,7 +59,7 @@ bool Plugins::loadPlugin(Plugins::Plugin* plugin)
m_availablePlugins.removeOne(*plugin); m_availablePlugins.removeOne(*plugin);
plugin->instance = initPlugin(iPlugin, plugin->pluginLoader); plugin->instance = initPlugin(iPlugin, plugin->pluginLoader);
m_availablePlugins.append(*plugin); m_availablePlugins.prepend(*plugin);
refreshLoadedPlugins(); refreshLoadedPlugins();
@ -80,7 +87,7 @@ void Plugins::loadSettings()
Settings settings; Settings settings;
settings.beginGroup("Plugin-Settings"); settings.beginGroup("Plugin-Settings");
m_pluginsEnabled = settings.value("EnablePlugins", DEFAULT_ENABLE_PLUGINS).toBool(); 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(); settings.endGroup();
c2f_loadSettings(); c2f_loadSettings();
@ -106,7 +113,38 @@ void Plugins::c2f_saveSettings()
void Plugins::loadPlugins() 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; return;
} }
@ -114,41 +152,36 @@ void Plugins::loadPlugins()
QStringList dirs; QStringList dirs;
dirs << mApp->DATADIR + "plugins/" dirs << mApp->DATADIR + "plugins/"
#ifdef Q_WS_X11 #ifdef Q_WS_X11
<< "/usr/lib/qupzilla/" << "/usr/lib/qupzilla/"
#endif #endif
<< mApp->PROFILEDIR + "plugins/"; << mApp->PROFILEDIR + "plugins/";
foreach(const QString & dir, dirs) { foreach(const QString & dir, dirs) {
QDir pluginsDir = QDir(dir); QDir pluginsDir = QDir(dir);
foreach(const QString & fileName, pluginsDir.entryList(QDir::Files)) { 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()); PluginInterface* iPlugin = qobject_cast<PluginInterface*>(loader->instance());
if (!iPlugin) { if (!iPlugin) {
continue; continue;
} }
Plugin plugin; Plugin plugin;
plugin.fileName = fileName; plugin.fullPath = absolutePath;
plugin.fullPath = pluginsDir.absoluteFilePath(fileName);
plugin.pluginSpec = iPlugin->pluginSpec(); plugin.pluginSpec = iPlugin->pluginSpec();
plugin.pluginLoader = loader; plugin.pluginLoader = loader;
plugin.instance = 0; plugin.instance = 0;
if (m_allowedPluginFileNames.contains(fileName)) { loader->unload();
plugin.instance = initPlugin(iPlugin, loader);
}
else {
loader->unload();
}
m_availablePlugins.append(plugin); m_availablePlugins.append(plugin);
} }
} }
refreshLoadedPlugins();
std::cout << m_loadedPlugins.count() << " plugins loaded" << std::endl;
} }
PluginInterface* Plugins::initPlugin(PluginInterface* interface, QPluginLoader* loader) PluginInterface* Plugins::initPlugin(PluginInterface* interface, QPluginLoader* loader)

View File

@ -54,7 +54,7 @@ public:
explicit Plugins(QObject* parent = 0); explicit Plugins(QObject* parent = 0);
QList<Plugin> getAvailablePlugins() { return m_availablePlugins; } QList<Plugin> getAvailablePlugins();
bool loadPlugin(Plugin* plugin); bool loadPlugin(Plugin* plugin);
void unloadPlugin(Plugin* plugin); void unloadPlugin(Plugin* plugin);
@ -80,10 +80,12 @@ protected:
private: private:
PluginInterface* initPlugin(PluginInterface* interface, QPluginLoader* loader); PluginInterface* initPlugin(PluginInterface* interface, QPluginLoader* loader);
void refreshLoadedPlugins(); void refreshLoadedPlugins();
void loadAvailablePlugins();
QList<Plugin> m_availablePlugins; QList<Plugin> m_availablePlugins;
QStringList m_allowedPluginFileNames; QStringList m_allowedPlugins;
bool m_pluginsEnabled; bool m_pluginsEnabled;
bool m_pluginsLoaded; bool m_pluginsLoaded;

View File

@ -23,6 +23,7 @@
#include <QTextDocument> #include <QTextDocument>
#include <QTextBlock> #include <QTextBlock>
#include <QApplication> #include <QApplication>
#include <QScrollBar>
PluginListDelegate::PluginListDelegate(QListWidget* parent) PluginListDelegate::PluginListDelegate(QListWidget* parent)
: QItemDelegate(parent) : QItemDelegate(parent)
@ -77,9 +78,10 @@ QSize PluginListDelegate::sizeHint(const QStyleOptionViewItem &option, const QMo
Q_UNUSED(index) Q_UNUSED(index)
const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0) + 1; 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; 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 ) // ( 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)); size.setHeight((option.fontMetrics.height() * 3) + (textMargin * 2) + (2 * 3));

View File

@ -25,6 +25,7 @@
#include <QInputDialog> #include <QInputDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QTimer>
#ifdef PORTABLE_BUILD #ifdef PORTABLE_BUILD
#define DEFAULT_ENABLE_PLUGINS false #define DEFAULT_ENABLE_PLUGINS false
@ -41,9 +42,11 @@ PluginsList::PluginsList(QWidget* parent)
//Application Extensions //Application Extensions
Settings settings; Settings settings;
settings.beginGroup("Plugin-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(); settings.endGroup();
allowAppPluginsChanged(ui->allowAppPlugins->isChecked());
ui->allowAppPlugins->setChecked(appPluginsEnabled);
ui->list->setEnabled(appPluginsEnabled);
connect(ui->butSettings, SIGNAL(clicked()), this, SLOT(settingsClicked())); connect(ui->butSettings, SIGNAL(clicked()), this, SLOT(settingsClicked()));
connect(ui->list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(currentChanged(QListWidgetItem*))); connect(ui->list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(currentChanged(QListWidgetItem*)));
@ -67,6 +70,10 @@ PluginsList::PluginsList(QWidget* parent)
} }
allowC2FChanged(ui->allowClick2Flash->isChecked()); allowC2FChanged(ui->allowClick2Flash->isChecked());
if (appPluginsEnabled) {
QTimer::singleShot(0, this, SLOT(refresh()));
}
} }
void PluginsList::addWhitelist() void PluginsList::addWhitelist()
@ -100,7 +107,7 @@ void PluginsList::save()
if (item->checkState() == Qt::Checked) { if (item->checkState() == Qt::Checked) {
const Plugins::Plugin &plugin = item->data(Qt::UserRole + 10).value<Plugins::Plugin>(); 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) 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); ui->list->setEnabled(state);
if (state) { if (state) {
refresh(); 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) void PluginsList::allowC2FChanged(bool state)

View File

@ -45,13 +45,14 @@ private slots:
void itemChanged(QListWidgetItem* item); void itemChanged(QListWidgetItem* item);
void allowAppPluginsChanged(bool state); void allowAppPluginsChanged(bool state);
void refresh();
//WebKit plugins //WebKit plugins
void addWhitelist(); void addWhitelist();
void removeWhitelist(); void removeWhitelist();
void allowC2FChanged(bool state); void allowC2FChanged(bool state);
private: private:;
void refresh();
Ui::PluginsList* ui; Ui::PluginsList* ui;
}; };