From bf39165bca0b5cfd1f1bafc4774ccbcb62339170 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Wed, 4 Mar 2015 11:34:43 +0100 Subject: [PATCH] disable plugin tabs for not loaded plugins --- src/core/plugins/plugincontainer.cpp | 26 ++--------------- src/core/plugins/plugincontainer.h | 6 +--- src/core/plugins/plugins.cpp | 43 ++++++++++++++++++++++++++-- src/core/plugins/plugins.h | 15 ++++++++-- src/core/settingsdialog.cpp | 30 +++++++++++++------ src/core/settingsdialog.h | 3 ++ src/core/snore.cpp | 5 ++-- src/core/snore_p.cpp | 2 ++ src/settings/settingswindow.cpp | 3 +- 9 files changed, 87 insertions(+), 46 deletions(-) diff --git a/src/core/plugins/plugincontainer.cpp b/src/core/plugins/plugincontainer.cpp index 662ffae..22975aa 100644 --- a/src/core/plugins/plugincontainer.cpp +++ b/src/core/plugins/plugincontainer.cpp @@ -84,28 +84,6 @@ bool PluginContainer::isLoaded() const return m_loader.isLoaded(); } -SnorePlugin::PluginTypes PluginContainer::typeFromString(const QString &t) -{ - return (SnorePlugin::PluginTypes)SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")).keyToValue(t.toUpper().toLatin1()); -} - -QString PluginContainer::typeToString(const SnorePlugin::PluginTypes t) -{ - return SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")).valueToKey(t); -} - -const QList &PluginContainer::types() -{ - static QList t; - if (t.isEmpty()) { - QMetaEnum e = SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")); - for (int i = 0; i < e.keyCount(); ++i) { - t << (SnorePlugin::PluginTypes) e.value(i); - } - } - return t; -} - void PluginContainer::updatePluginCache() { snoreDebug(SNORE_DEBUG) << "Updating plugin cache"; @@ -116,7 +94,7 @@ void PluginContainer::updatePluginCache() list.clear(); } - foreach(const SnorePlugin::PluginTypes type, PluginContainer::types()) { + foreach(const SnorePlugin::PluginTypes type, SnorePlugin::types()) { foreach(const QFileInfo & file, pluginDir().entryInfoList( QStringList(pluginFileFilters(type)), QDir::Files)) { snoreDebug(SNORE_DEBUG) << "adding" << file.absoluteFilePath(); @@ -142,7 +120,7 @@ const QHash PluginContainer::pluginCache(SnorePlugin } QHash out; - for (auto t : types()) { + for (auto t : SnorePlugin::types()) { if (t & type) { out.unite(s_pluginCache.value(t)); } diff --git a/src/core/plugins/plugincontainer.h b/src/core/plugins/plugincontainer.h index e1a039c..c623c26 100644 --- a/src/core/plugins/plugincontainer.h +++ b/src/core/plugins/plugincontainer.h @@ -45,10 +45,6 @@ public: bool isLoaded() const; - static SnorePlugin::PluginTypes typeFromString(const QString &t); - static QString typeToString(const SnorePlugin::PluginTypes t); - static const QList &types(); - private: static QHash s_pluginCache; @@ -82,7 +78,7 @@ private: { QStringList out; foreach(const QString extention, pluginExtentions()) { - out << QString("libsnore_%1_*.%2").arg(typeToString(type).toLower(), extention); + out << QString("libsnore_%1_*.%2").arg(SnorePlugin::typeToString(type).toLower(), extention); } return out; } diff --git a/src/core/plugins/plugins.cpp b/src/core/plugins/plugins.cpp index d765fbc..80b8da6 100644 --- a/src/core/plugins/plugins.cpp +++ b/src/core/plugins/plugins.cpp @@ -100,7 +100,7 @@ SnorePlugin::PluginTypes SnorePlugin::type() const const QString SnorePlugin::typeName() const { - return PluginContainer::typeToString(m_type); + return SnorePlugin::typeToString(m_type); } QString SnorePlugin::settingsVersion() const @@ -118,7 +118,30 @@ bool SnorePlugin::deinitialize() return false; } -QDebug operator <<(QDebug debug, const Snore::SnorePlugin::PluginTypes &flags) +SnorePlugin::PluginTypes SnorePlugin::typeFromString(const QString &t) +{ + return (SnorePlugin::PluginTypes)SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")).keyToValue(t.toUpper().toLatin1()); +} + +QString SnorePlugin::typeToString(const SnorePlugin::PluginTypes t) +{ + return SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")).valueToKey(t); +} + +const QList &SnorePlugin::types() +{ + static QList t; + if (t.isEmpty()) { + QMetaEnum e = SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")); + for (int i = 0; i < e.keyCount(); ++i) { + t << (SnorePlugin::PluginTypes) e.value(i); + } + } + return t; +} + + +QDebug operator<<(QDebug debug, const Snore::SnorePlugin::PluginTypes &flags) { QMetaEnum e = SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")); debug.nospace() << "PluginTypes("; @@ -134,10 +157,24 @@ QDebug operator <<(QDebug debug, const Snore::SnorePlugin::PluginTypes &flags) } debug.nospace() << e.valueToKey(key); - } } debug << ')'; return debug.space(); } + + +QDataStream &operator<<(QDataStream &out, const Snore::SnorePlugin::PluginTypes &type) +{ + out << static_cast(type); + return out; +} + +QDataStream &operator>>(QDataStream &in, Snore::SnorePlugin::PluginTypes &type) +{ + int key; + in >> key; + type = static_cast(key); + return in; +} diff --git a/src/core/plugins/plugins.h b/src/core/plugins/plugins.h index ed3ffac..ab3712b 100644 --- a/src/core/plugins/plugins.h +++ b/src/core/plugins/plugins.h @@ -43,6 +43,11 @@ public: Q_DECLARE_FLAGS(PluginTypes, PluginType) Q_ENUMS(PluginType) + static PluginTypes typeFromString(const QString &t); + static QString typeToString(const PluginTypes t); + static const QList &types(); + + SnorePlugin(const QString &name); virtual ~SnorePlugin(); virtual bool initialize(); @@ -72,12 +77,18 @@ private: friend class PluginContainer; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(Snore::SnorePlugin::PluginTypes) } +Q_DECLARE_OPERATORS_FOR_FLAGS(Snore::SnorePlugin::PluginTypes) +Q_DECLARE_METATYPE(Snore::SnorePlugin::PluginTypes) + Q_DECLARE_INTERFACE(Snore::SnorePlugin, "org.Snore.SnorePlugin/1.0") -SNORE_EXPORT QDebug operator<< (QDebug, const Snore::SnorePlugin::PluginTypes &); +SNORE_EXPORT QDebug operator<<(QDebug, const Snore::SnorePlugin::PluginTypes &); + +SNORE_EXPORT QDataStream &operator<<(QDataStream &out, const Snore::SnorePlugin::PluginTypes &type); +SNORE_EXPORT QDataStream &operator>>(QDataStream &in, Snore::SnorePlugin::PluginTypes &type); + #endif//SNORE_PLUGINS_H diff --git a/src/core/settingsdialog.cpp b/src/core/settingsdialog.cpp index 300248d..cec4eb3 100644 --- a/src/core/settingsdialog.cpp +++ b/src/core/settingsdialog.cpp @@ -32,13 +32,30 @@ SettingsDialog::SettingsDialog(QWidget *parent) : ui(new Ui::SettingsDialog) { ui->setupUi(this); + initTabs(); +} +SettingsDialog::~SettingsDialog() +{ + delete ui; +} + +void SettingsDialog::initTabs() +{ + SnorePlugin::PluginTypes types = SnoreCore::instance().value("PluginTypes", LOCAL_SETTING).value(); + if(types == SnorePlugin::NONE) + { + types = SnorePlugin::ALL; + } auto addWidgets = [&](QTabWidget *target, QWidget *container, SnorePlugin::PluginTypes type){ bool enabled = false; - for (PluginSettingsWidget *widget : SnoreCore::instance().settingWidgets(type)) { - target->addTab(widget, widget->name()); - m_tabs.append(widget); - enabled = true; + target->clear(); + if (types & type) { + for (PluginSettingsWidget *widget : SnoreCore::instance().settingWidgets(type)) { + target->addTab(widget, widget->name()); + m_tabs.append(widget); + enabled = true; + } } ui->tabWidget->setTabEnabled(ui->tabWidget->indexOf(container), enabled); }; @@ -48,11 +65,6 @@ SettingsDialog::SettingsDialog(QWidget *parent) : addWidgets(ui->tabWidget_plugins, ui->tab_plugins, SnorePlugin::PLUGIN); } -SettingsDialog::~SettingsDialog() -{ - delete ui; -} - void Snore::SettingsDialog::on_pushButton_clicked() { Application app = SnoreCorePrivate::instance()->defaultApplication(); diff --git a/src/core/settingsdialog.h b/src/core/settingsdialog.h index 7fcdedd..aa97533 100644 --- a/src/core/settingsdialog.h +++ b/src/core/settingsdialog.h @@ -48,6 +48,9 @@ public: explicit SettingsDialog(QWidget *parent = 0); ~SettingsDialog(); + //TODO: move to private header + void initTabs(); + public slots: void setVisible(bool b) override; diff --git a/src/core/snore.cpp b/src/core/snore.cpp index 7dbf5cf..c6dacf1 100644 --- a/src/core/snore.cpp +++ b/src/core/snore.cpp @@ -56,7 +56,8 @@ SnoreCore::~SnoreCore() void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types) { Q_D(SnoreCore); - for (SnorePlugin::PluginTypes type : PluginContainer::types()) { + setValue("PluginTypes", QVariant::fromValue(types), LOCAL_SETTING); + for (SnorePlugin::PluginTypes type : SnorePlugin::types()) { if (type != SnorePlugin::ALL && types & type) { for (PluginContainer *info : PluginContainer::pluginCache(type).values()) { SnorePlugin *plugin = info->load(); @@ -137,7 +138,7 @@ const QStringList SnoreCore::pluginNames(SnorePlugin::PluginTypes type) const { Q_D(const SnoreCore); QStringList out; - for (auto t : PluginContainer::types()) { + for (auto t : SnorePlugin::types()) { if (t & type) { out.append(d->m_pluginNames.value(t)); } diff --git a/src/core/snore_p.cpp b/src/core/snore_p.cpp index e833959..bac50a3 100644 --- a/src/core/snore_p.cpp +++ b/src/core/snore_p.cpp @@ -193,6 +193,8 @@ void SnoreCorePrivate::registerMetaTypes() { qRegisterMetaType(); qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); } QString SnoreCorePrivate::tempPath() diff --git a/src/settings/settingswindow.cpp b/src/settings/settingswindow.cpp index 663fbf2..3a4db54 100644 --- a/src/settings/settingswindow.cpp +++ b/src/settings/settingswindow.cpp @@ -31,7 +31,8 @@ SettingsWindow::~SettingsWindow() void SettingsWindow::on_comboBox_currentIndexChanged(const QString &arg1) { SnoreCorePrivate::instance()->setLocalSttingsPrefix(arg1); - ui->widget->show(); + ui->widget->initTabs(); + ui->widget->setVisible(true); } void SettingsWindow::on_buttonBox_clicked(QAbstractButton *button)