disable plugin tabs for not loaded plugins

This commit is contained in:
Patrick von Reth 2015-03-04 11:34:43 +01:00
parent efce32156e
commit bf39165bca
9 changed files with 87 additions and 46 deletions

View File

@ -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<SnorePlugin::PluginTypes> &PluginContainer::types()
{
static QList<SnorePlugin::PluginTypes> 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<QString, PluginContainer *> PluginContainer::pluginCache(SnorePlugin
}
QHash<QString, PluginContainer *> out;
for (auto t : types()) {
for (auto t : SnorePlugin::types()) {
if (t & type) {
out.unite(s_pluginCache.value(t));
}

View File

@ -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<SnorePlugin::PluginTypes> &types();
private:
static QHash<SnorePlugin::PluginTypes, PluginContaienrHash > 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;
}

View File

@ -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::PluginTypes> &SnorePlugin::types()
{
static QList<SnorePlugin::PluginTypes> 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<int>(type);
return out;
}
QDataStream &operator>>(QDataStream &in, Snore::SnorePlugin::PluginTypes &type)
{
int key;
in >> key;
type = static_cast<SnorePlugin::PluginTypes>(key);
return in;
}

View File

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

View File

@ -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<SnorePlugin::PluginTypes>();
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();

View File

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

View File

@ -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));
}

View File

@ -193,6 +193,8 @@ void SnoreCorePrivate::registerMetaTypes()
{
qRegisterMetaType<Notification>();
qRegisterMetaType<Application>();
qRegisterMetaType<SnorePlugin::PluginTypes>();
qRegisterMetaTypeStreamOperators<SnorePlugin::PluginTypes>();
}
QString SnoreCorePrivate::tempPath()

View File

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