make it possible to disable backends
This commit is contained in:
parent
9314047b14
commit
910d4e6482
|
@ -137,6 +137,7 @@ void PluginContainer::updatePluginCache()
|
|||
|
||||
const QHash<QString, PluginContainer *> PluginContainer::pluginCache(SnorePlugin::PluginTypes type)
|
||||
{
|
||||
snoreDebug(SNORE_DEBUG) << type;
|
||||
if (s_pluginCache.isEmpty()) {
|
||||
QTime time;
|
||||
time.start();
|
||||
|
@ -145,12 +146,11 @@ const QHash<QString, PluginContainer *> PluginContainer::pluginCache(SnorePlugin
|
|||
}
|
||||
|
||||
QHash<QString, PluginContainer *> out;
|
||||
if (type == SnorePlugin::ALL) {
|
||||
foreach(const SnorePlugin::PluginTypes & t, types()) {
|
||||
for(auto t:types()){
|
||||
if(t & type)
|
||||
{
|
||||
out.unite(s_pluginCache.value(t));
|
||||
}
|
||||
} else {
|
||||
out = s_pluginCache[type];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ bool SnorePlugin::initialize(SnoreCore *snore)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool SnorePlugin::isInitialized()
|
||||
bool SnorePlugin::isInitialized() const
|
||||
{
|
||||
return m_initialized;
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
virtual ~SnorePlugin();
|
||||
virtual bool initialize(SnoreCore *snore);
|
||||
virtual bool deinitialize();
|
||||
bool isInitialized();
|
||||
bool isInitialized() const;
|
||||
SnoreCore *snore();
|
||||
const SnoreCore *snore() const;
|
||||
|
||||
|
|
|
@ -73,15 +73,16 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
|
|||
continue;
|
||||
}
|
||||
snoreDebug(SNORE_DEBUG) << info->name() << "is a" << info->type();
|
||||
d->m_plugins[info->type()].append(info->name());
|
||||
d->m_pluginNames[info->type()].append(info->name());
|
||||
d->m_plugins[info->name()] = info->load();
|
||||
}
|
||||
if (d->m_plugins.contains(type)) {
|
||||
qSort(d->m_plugins[type]);
|
||||
if (d->m_pluginNames.contains(type)) {
|
||||
qSort(d->m_pluginNames[type]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
snoreDebug(SNORE_INFO) << "Loaded Plugins:" << d->m_plugins;
|
||||
snoreDebug(SNORE_INFO) << "Loaded Plugins:" << d->m_pluginNames;
|
||||
}
|
||||
|
||||
void SnoreCore::broadcastNotification(Notification notification)
|
||||
|
@ -120,22 +121,17 @@ const QHash<QString, Application> &SnoreCore::aplications() const
|
|||
return d->m_applications;
|
||||
}
|
||||
|
||||
const QStringList SnoreCore::notificationBackends() const
|
||||
const QStringList SnoreCore::pluginNames(SnorePlugin::PluginTypes type) const
|
||||
{
|
||||
Q_D(const SnoreCore);
|
||||
return d->m_plugins.value(SnorePlugin::BACKEND);
|
||||
}
|
||||
|
||||
const QStringList SnoreCore::notificationFrontends() const
|
||||
{
|
||||
Q_D(const SnoreCore);
|
||||
return d->m_plugins.value(SnorePlugin::FRONTEND);
|
||||
}
|
||||
|
||||
const QStringList SnoreCore::secondaryNotificationBackends() const
|
||||
{
|
||||
Q_D(const SnoreCore);
|
||||
return d->m_plugins.value(SnorePlugin::SECONDARY_BACKEND);
|
||||
QStringList out;
|
||||
for(auto t:PluginContainer::types()){
|
||||
if(t & type)
|
||||
{
|
||||
out.append(d->m_pluginNames.value(t));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
bool SnoreCore::setPrimaryNotificationBackend(const QString &backend)
|
||||
|
@ -228,11 +224,12 @@ bool SnoreCore::primaryBackendSupportsRichtext()
|
|||
|
||||
QList<PluginSettingsWidget*> SnoreCore::settingWidgets()
|
||||
{
|
||||
Q_D(SnoreCore);
|
||||
QList<PluginSettingsWidget*> list;
|
||||
for(auto p:PluginContainer::pluginCache(SnorePlugin::ALL))
|
||||
for(auto p:d->m_plugins)
|
||||
{
|
||||
//TODO: mem leak?
|
||||
PluginSettingsWidget *w = p->load()->settingsWidget();
|
||||
PluginSettingsWidget *w = p->settingsWidget();
|
||||
if(w) {
|
||||
list.append(w);
|
||||
}
|
||||
|
@ -257,6 +254,27 @@ const QHash<QString, QString> &SnoreCore::settingsDescription() const
|
|||
return d->m_help;
|
||||
}
|
||||
|
||||
|
||||
bool SnoreCore::setPluginEnabled(const QString &pluginName, bool enable)
|
||||
{
|
||||
Q_D(SnoreCore);
|
||||
SnorePlugin *plugin = d->m_plugins.value(pluginName);
|
||||
if(!plugin->isInitialized() && enable)
|
||||
{
|
||||
return plugin->initialize(this);
|
||||
} else if(plugin->isInitialized() && !enable)
|
||||
{
|
||||
return plugin->deinitialize();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SnoreCore::pluginIsEnabled(const QString &pluginName) const
|
||||
{
|
||||
Q_D(const SnoreCore);
|
||||
return d->m_plugins.value(pluginName)->isInitialized();
|
||||
}
|
||||
|
||||
const SnoreCorePrivate *SnoreCore::d()
|
||||
{
|
||||
Q_D(SnoreCore);
|
||||
|
|
|
@ -106,21 +106,9 @@ public:
|
|||
|
||||
/**
|
||||
*
|
||||
* @return a list of all known notification backends
|
||||
* @return a list of plugins
|
||||
*/
|
||||
const QStringList notificationBackends() const;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a list of all known notification frontends
|
||||
*/
|
||||
const QStringList notificationFrontends() const;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a list of all known notification secondary backends
|
||||
*/
|
||||
const QStringList secondaryNotificationBackends() const;
|
||||
const QStringList pluginNames(SnorePlugin::PluginTypes type) const;
|
||||
|
||||
/**
|
||||
* Sets the primary backend.
|
||||
|
@ -180,6 +168,9 @@ public:
|
|||
*/
|
||||
const QHash<QString,QString> &settingsDescription() const;
|
||||
|
||||
bool setPluginEnabled(const QString& pluginName,bool enable);
|
||||
bool pluginIsEnabled(const QString& pluginName) const;
|
||||
|
||||
/**
|
||||
* @return a pointer to the private class, for internal use only.
|
||||
*/
|
||||
|
|
|
@ -68,7 +68,7 @@ void SnoreCorePrivate::notificationActionInvoked(Notification notification) cons
|
|||
bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
|
||||
{
|
||||
Q_Q(SnoreCore);
|
||||
if (m_plugins[SnorePlugin::BACKEND].contains(backend)) {
|
||||
if (m_pluginNames[SnorePlugin::BACKEND].contains(backend)) {
|
||||
return q->setPrimaryNotificationBackend(backend);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -78,7 +78,8 @@ private:
|
|||
|
||||
QHash<QString, Application> m_applications;
|
||||
|
||||
QHash<SnorePlugin::PluginTypes, QStringList> m_plugins;
|
||||
QHash<SnorePlugin::PluginTypes, QStringList> m_pluginNames;
|
||||
QHash<QString, SnorePlugin*> m_plugins;
|
||||
|
||||
QPointer<SnoreBackend> m_notificationBackend;
|
||||
|
||||
|
|
|
@ -3,10 +3,9 @@ if(WITH_SNORE_DAEMON)
|
|||
include(ECMInstallIcons)
|
||||
ecm_add_app_icon(SNORENOTIFY_DAEMON_DEPS ICONS ${PROJECT_SOURCE_DIR}/data/128-apps-snore.png)
|
||||
|
||||
|
||||
qt5_wrap_ui(UI settingsdialog.ui)
|
||||
|
||||
add_executable( snorenotify WIN32 main.cpp snorenotify.cpp trayicon.cpp settingsdialog.cpp ${SNORENOTIFY_DAEMON_DEPS} ${UI})
|
||||
add_executable( snorenotify WIN32 main.cpp snorenotify.cpp trayicon.cpp settingsdialog.cpp ${UI} ${SNORENOTIFY_DAEMON_DEPS})
|
||||
target_link_libraries( snorenotify libsnore Qt5::Gui Qt5::Widgets )
|
||||
install(TARGETS snorenotify ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
|
||||
|
||||
|
|
|
@ -1,9 +1,28 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2015 Patrick von Reth <vonreth@kde.org>
|
||||
|
||||
SnoreNotify is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
SnoreNotify is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "settingsdialog.h"
|
||||
#include "ui_settingsdialog.h"
|
||||
#include <QTabWidget>
|
||||
|
||||
#include "snore.h"
|
||||
|
||||
#include <QTabWidget>
|
||||
#include <QFormLayout>
|
||||
#include <QCheckBox>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
SettingsDialog::SettingsDialog(SnoreCore *snore, QWidget *parent) :
|
||||
|
@ -12,7 +31,16 @@ SettingsDialog::SettingsDialog(SnoreCore *snore, QWidget *parent) :
|
|||
m_snore(snore)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->tabWidget->clear();
|
||||
for(const QString &plugin : snore->pluginNames(SnorePlugin::FRONTEND|SnorePlugin::SECONDARY_BACKEND|SnorePlugin::PLUGIN))
|
||||
{
|
||||
QCheckBox *box = new QCheckBox(plugin);
|
||||
box->setChecked(snore->pluginIsEnabled(plugin));
|
||||
connect(box,QCheckBox::toggled,[plugin,snore,box](bool checked){
|
||||
snore->setPluginEnabled(plugin,checked);
|
||||
box->setChecked(snore->pluginIsEnabled(plugin));
|
||||
});
|
||||
ui->verticalLayout2->addWidget(box);
|
||||
}
|
||||
for(auto widget : snore->settingWidgets())
|
||||
{
|
||||
ui->tabWidget->addTab(widget,widget->name());
|
||||
|
|
|
@ -1,3 +1,20 @@
|
|||
/*
|
||||
SnoreNotify is a Notification Framework based on Qt
|
||||
Copyright (C) 2015 Patrick von Reth <vonreth@kde.org>
|
||||
|
||||
SnoreNotify is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
SnoreNotify is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef SETTINGSDIALOG_H
|
||||
#define SETTINGSDIALOG_H
|
||||
|
||||
|
|
|
@ -21,13 +21,9 @@
|
|||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>Tab 1</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Tab 2</string>
|
||||
<string>Active Backends</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout2"/>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -56,7 +56,7 @@ void TrayIcon::initConextMenu(SnoreCore *snore)
|
|||
m_trayMenu->addSeparator();
|
||||
m_backendActions = new QActionGroup(m_trayMenu);
|
||||
m_backendActions->setExclusive(true);
|
||||
foreach(const QString & back, m_snore->notificationBackends()) {
|
||||
for(const QString & back : m_snore->pluginNames(SnorePlugin::BACKEND)) {
|
||||
QAction *b = m_trayMenu->addAction(back, this, SLOT(setPrimaryBackend()));
|
||||
b->setCheckable(true);
|
||||
if (back == m_snore->primaryNotificationBackend()) {
|
||||
|
|
Loading…
Reference in New Issue