improve the way plugins are initialized, looks a bit fishy for frontends

This commit is contained in:
Patrick von Reth 2015-07-13 17:20:51 +02:00
parent 3f9d5ec325
commit 753dfc9109
36 changed files with 267 additions and 288 deletions

View File

@ -35,6 +35,11 @@ SnorePlugin::SnorePlugin()
if (thread() != qApp->thread()) {
snoreDebug(SNORE_WARNING) << "Plugin initialized in wrong thread.";
}
connect(this, &SnorePlugin::initialisationFinished, [this](bool b) {
snoreDebug(SNORE_DEBUG) << "Plugin:" << name() << "initialized" << b;
Q_ASSERT_X(!(b && m_initialized), Q_FUNC_INFO, "Plugin initialized multiple times.");
m_initialized = b;
});
}
SnorePlugin::~SnorePlugin()
@ -42,22 +47,16 @@ SnorePlugin::~SnorePlugin()
snoreDebug(SNORE_DEBUG) << name() << this << "deleted";
}
bool SnorePlugin::initialize()
{
if (m_initialized) {
qFatal("Something went wrong, plugin %s is already initialized", this->name().toLatin1().constData());
return false;
}
snoreDebug(SNORE_DEBUG) << "Initialize" << name() << this;
m_initialized = true;
return true;
}
bool SnorePlugin::isInitialized() const
{
return m_initialized;
}
bool SnorePlugin::isEnabled() const
{
return m_enabled;
}
QVariant SnorePlugin::settingsValue(const QString &key, SettingsType type) const
{
return SnoreCore::instance().settingsValue(normaliseKey(key), type);
@ -114,14 +113,20 @@ void SnorePlugin::setDefaultSettings()
setDefaultSettingsValue(QLatin1String("Enabled"), false, LOCAL_SETTING);
}
bool SnorePlugin::deinitialize()
void SnorePlugin::setEnabled(bool enabled)
{
if (m_initialized) {
snoreDebug(SNORE_DEBUG) << "Deinitialize" << name() << this;
m_initialized = false;
return true;
}
return false;
Q_ASSERT_X(isInitialized(), Q_FUNC_INFO, "Plugin not initialized");
m_enabled = enabled;
}
void SnorePlugin::enable()
{
setEnabled(true);
}
void SnorePlugin::disable()
{
setEnabled(false);
}
SnorePlugin::PluginTypes SnorePlugin::typeFromString(const QString &t)

View File

@ -53,11 +53,15 @@ public:
SnorePlugin();
virtual ~SnorePlugin();
// TODO: remove need of recursive calling of parent methode....
virtual bool initialize();
virtual bool deinitialize();
virtual void setEnabled(bool enabled);
void enable();
void disable();
bool isInitialized() const;
bool isEnabled() const;
/**
* Returns the name of the plugin.
*/
@ -79,6 +83,12 @@ public:
virtual PluginSettingsWidget *settingsWidget();
Q_SIGNALS:
void initialisationFinished(bool initialized);
public Q_SLOTS:
virtual void slotInitialize() = 0;
protected:
/**
* Returns the version suffix used for the plugin settings.
@ -95,6 +105,7 @@ private:
void setDefaultSettingsPlugin();
bool m_initialized = false;
bool m_enabled = false;
PluginContainer *m_container = nullptr;
friend class PluginContainer;

View File

@ -34,28 +34,23 @@ SnoreBackend::~SnoreBackend()
snoreDebug(SNORE_DEBUG) << "Deleting" << name();
}
bool SnoreBackend::initialize()
void SnoreBackend::setEnabled(bool enabled)
{
if (!SnorePlugin::initialize()) {
return false;
if (enabled == isEnabled()) {
return;
}
SnorePlugin::setEnabled(enabled);
if (enabled) {
connect(SnoreCorePrivate::instance(), &SnoreCorePrivate::applicationRegistered, this, &SnoreBackend::slotRegisterApplication, Qt::QueuedConnection);
connect(SnoreCorePrivate::instance(), &SnoreCorePrivate::applicationDeregistered, this, &SnoreBackend::slotDeregisterApplication, Qt::QueuedConnection);
connect(SnoreCorePrivate::instance(), &SnoreCorePrivate::applicationRegistered, this, &SnoreBackend::slotRegisterApplication, Qt::QueuedConnection);
connect(SnoreCorePrivate::instance(), &SnoreCorePrivate::applicationDeregistered, this, &SnoreBackend::slotDeregisterApplication, Qt::QueuedConnection);
connect(this, &SnoreBackend::notificationClosed, SnoreCorePrivate::instance(), &SnoreCorePrivate::slotNotificationClosed, Qt::QueuedConnection);
connect(SnoreCorePrivate::instance(), &SnoreCorePrivate::notify, this, &SnoreBackend::slotNotify, Qt::QueuedConnection);
connect(this, &SnoreBackend::notificationClosed, SnoreCorePrivate::instance(), &SnoreCorePrivate::slotNotificationClosed, Qt::QueuedConnection);
connect(SnoreCorePrivate::instance(), &SnoreCorePrivate::notify, this, &SnoreBackend::slotNotify, Qt::QueuedConnection);
for (const Application &a : SnoreCore::instance().aplications()) {
QMetaObject::invokeMethod(this, "slotRegisterApplication", Qt::QueuedConnection, Q_ARG(Snore::Application, a));
}
return true;
}
bool SnoreBackend::deinitialize()
{
if (SnorePlugin::deinitialize()) {
for (const Application &a : SnoreCore::instance().aplications()) {
slotRegisterApplication(a);
}
} else {
for (const Application &a : SnoreCore::instance().aplications()) {
slotDeregisterApplication(a);
}
@ -64,9 +59,8 @@ bool SnoreBackend::deinitialize()
disconnect(this, &SnoreBackend::notificationClosed, SnoreCorePrivate::instance(), &SnoreCorePrivate::slotNotificationClosed);
disconnect(SnoreCorePrivate::instance(), &SnoreCorePrivate::notify, this, &SnoreBackend::slotNotify);
return true;
}
return false;
}
void SnoreBackend::requestCloseNotification(Notification notification, Notification::CloseReasons reason)
@ -101,24 +95,19 @@ SnoreSecondaryBackend::~SnoreSecondaryBackend()
snoreDebug(SNORE_DEBUG) << "Deleting" << name();
}
bool SnoreSecondaryBackend::initialize()
void SnoreSecondaryBackend::setEnabled(bool enabled)
{
if (!SnorePlugin::initialize()) {
return false;
if (enabled == isEnabled()) {
return;
}
connect(SnoreCorePrivate::instance(), &SnoreCorePrivate::notify, this, &SnoreSecondaryBackend::slotNotify, Qt::QueuedConnection);
connect(SnoreCorePrivate::instance(), &SnoreCorePrivate::notificationDisplayed, this, &SnoreSecondaryBackend::slotNotificationDisplayed, Qt::QueuedConnection);
return true;
}
bool SnoreSecondaryBackend::deinitialize()
{
if (SnorePlugin::deinitialize()) {
SnorePlugin::setEnabled(enabled);
if (enabled) {
connect(SnoreCorePrivate::instance(), &SnoreCorePrivate::notify, this, &SnoreSecondaryBackend::slotNotify, Qt::QueuedConnection);
connect(SnoreCorePrivate::instance(), &SnoreCorePrivate::notificationDisplayed, this, &SnoreSecondaryBackend::slotNotificationDisplayed, Qt::QueuedConnection);
} else {
disconnect(SnoreCorePrivate::instance(), &SnoreCorePrivate::notify, this, &SnoreSecondaryBackend::slotNotify);
disconnect(SnoreCorePrivate::instance(), &SnoreCorePrivate::notificationDisplayed, this, &SnoreSecondaryBackend::slotNotificationDisplayed);
return true;
}
return false;
}
void SnoreSecondaryBackend::slotNotify(Notification)

View File

@ -33,8 +33,8 @@ class SNORE_EXPORT SnoreBackend : public SnorePlugin
public:
SnoreBackend() = default;
virtual ~SnoreBackend();
virtual bool initialize() override;
virtual bool deinitialize() override;
virtual void setEnabled(bool enabled) override;
void requestCloseNotification(Snore::Notification notification, Notification::CloseReasons reason);
@ -74,8 +74,8 @@ class SNORE_EXPORT SnoreSecondaryBackend : public SnorePlugin
public:
SnoreSecondaryBackend() = default;
virtual ~SnoreSecondaryBackend();
virtual bool initialize();
virtual bool deinitialize();
virtual void setEnabled(bool enabled) override;
public Q_SLOTS:
virtual void slotNotify(Snore::Notification notification);

View File

@ -26,24 +26,19 @@ SnoreFrontend::~SnoreFrontend()
snoreDebug(SNORE_DEBUG) << "Deleting" << name();
}
bool SnoreFrontend::initialize()
void SnoreFrontend::setEnabled(bool enabled)
{
if (!SnorePlugin::initialize()) {
return false;
if (enabled == isEnabled()) {
return;
}
connect(&SnoreCore::instance(), &SnoreCore::notificationClosed, this, &SnoreFrontend::slotNotificationClosed, Qt::QueuedConnection);
connect(&SnoreCore::instance(), &SnoreCore::actionInvoked, this, &SnoreFrontend::slotActionInvoked, Qt::QueuedConnection);
return true;
}
bool SnoreFrontend::deinitialize()
{
if (SnorePlugin::deinitialize()) {
SnorePlugin::setEnabled(enabled);
if (enabled) {
connect(&SnoreCore::instance(), &SnoreCore::notificationClosed, this, &SnoreFrontend::slotNotificationClosed, Qt::QueuedConnection);
connect(&SnoreCore::instance(), &SnoreCore::actionInvoked, this, &SnoreFrontend::slotActionInvoked, Qt::QueuedConnection);
} else {
disconnect(&SnoreCore::instance(), &SnoreCore::notificationClosed, this, &SnoreFrontend::slotNotificationClosed);
disconnect(&SnoreCore::instance(), &SnoreCore::actionInvoked, this, &SnoreFrontend::slotActionInvoked);
return true;
}
return false;
}
void SnoreFrontend::slotActionInvoked(Notification)

View File

@ -34,8 +34,7 @@ public:
SnoreFrontend() = default;
virtual ~SnoreFrontend();
virtual bool initialize() override;
virtual bool deinitialize() override;
virtual void setEnabled(bool enabled) override;
public Q_SLOTS:
virtual void slotActionInvoked(Snore::Notification notification);

View File

@ -113,7 +113,7 @@ void SettingsDialog::save()
SnoreCore::instance().setSettingsValue(QLatin1String("Silent"), ui->disableNotificationSoundCheckBox->isChecked(), LOCAL_SETTING);
if (dirty) {
SnoreCorePrivate::instance()->syncSettings();
QMetaObject::invokeMethod(SnoreCorePrivate::instance(), "slotSyncSettings", Qt::QueuedConnection);
}
}

View File

@ -77,26 +77,24 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
if (!plugin) {
continue;
}
switch (info->type()) {
case SnorePlugin::BACKEND:
break;
case SnorePlugin::SECONDARY_BACKEND:
case SnorePlugin::FRONTEND:
case SnorePlugin::PLUGIN: {
if (plugin->settingsValue(QLatin1String("Enabled"), LOCAL_SETTING).toBool()) {
if (!plugin->initialize()) {
snoreDebug(SNORE_WARNING) << "Failed to initialize" << plugin->name();
plugin->deinitialize();
//info->unload();
break;
case SnorePlugin::PLUGIN:
connect(plugin, &SnorePlugin::initialisationFinished, [plugin](bool initialized) {
if (initialized) {
plugin->setEnabled(plugin->settingsValue(QLatin1String("Enabled"), LOCAL_SETTING).toBool());
}
}
}
break;
});
break;
default:
snoreDebug(SNORE_WARNING) << "Plugin Cache corrupted\n" << info->file() << info->type();
continue;
}
QMetaObject::invokeMethod(plugin, "slotInitialize", Qt::QueuedConnection);
snoreDebug(SNORE_DEBUG) << info->name() << "is a" << info->type();
d->m_pluginNames[info->type()].append(info->name());
auto key = qMakePair(type, info->name());
@ -108,7 +106,7 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
}
}
}
d->initPrimaryNotificationBackend();
QMetaObject::invokeMethod(d, "slotInitPrimaryNotificationBackend", Qt::QueuedConnection);
snoreDebug(SNORE_INFO) << "Loaded Plugins:" << d->m_pluginNames;
}

View File

@ -87,23 +87,22 @@ bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
snoreDebug(SNORE_DEBUG) << "Setting Notification Backend to:" << backend;
SnoreBackend *b = qobject_cast<SnoreBackend *>(backends.value(backend)->load());
if (!b->isInitialized()) {
if (!b->initialize()) {
snoreDebug(SNORE_DEBUG) << "Failed to initialize" << b->name();
return false;
}
snoreDebug(SNORE_DEBUG) << "Failed to initialize" << b->name();
return false;
}
if (m_notificationBackend) {
m_notificationBackend->deinitialize();
m_notificationBackend->disable();
}
m_notificationBackend = b;
m_notificationBackend->enable();
q->setSettingsValue(QLatin1String("PrimaryBackend"), backend, LOCAL_SETTING);
return true;
}
return false;
}
bool SnoreCorePrivate::initPrimaryNotificationBackend()
bool SnoreCorePrivate::slotInitPrimaryNotificationBackend()
{
Q_Q(SnoreCore);
snoreDebug(SNORE_DEBUG) << q->settingsValue(QLatin1String("PrimaryBackend"), LOCAL_SETTING).toString();
@ -155,7 +154,7 @@ void SnoreCorePrivate::setDefaultSettingsValueIntern(const QString &key, const Q
}
}
void SnoreCorePrivate::syncSettings()
void SnoreCorePrivate::slotSyncSettings()
{
Q_Q(SnoreCore);
QString newBackend = q->settingsValue(QLatin1String("PrimaryBackend"), LOCAL_SETTING).toString();
@ -163,7 +162,7 @@ void SnoreCorePrivate::syncSettings()
QString oldBackend;
if (m_notificationBackend) {
oldBackend = m_notificationBackend->name();
m_notificationBackend->deinitialize();
m_notificationBackend->disable();
m_notificationBackend = nullptr;
}
if (!setBackendIfAvailible(newBackend)) {
@ -179,11 +178,7 @@ void SnoreCorePrivate::syncSettings()
auto key = qMakePair(type, pluginName);
SnorePlugin *plugin = m_plugins.value(key);
bool enable = m_plugins[key]->settingsValue(QLatin1String("Enabled"), LOCAL_SETTING).toBool();
if (!plugin->isInitialized() && enable) {
plugin->initialize();
} else if (plugin->isInitialized() && !enable) {
plugin->deinitialize();
}
plugin->setEnabled(enable);
}
}
}
@ -192,7 +187,7 @@ void SnoreCorePrivate::setLocalSttingsPrefix(const QString &prefix)
{
m_localSettingsPrefix = prefix;
init();
syncSettings();
QMetaObject::invokeMethod(this, "slotSyncSettings", Qt::QueuedConnection);
}
QString SnoreCorePrivate::tempPath()
@ -223,7 +218,7 @@ void SnoreCorePrivate::slotAboutToQuit()
for (PluginContainer *p : PluginContainer::pluginCache(SnorePlugin::ALL)) {
if (p->isLoaded()) {
snoreDebug(SNORE_DEBUG) << "deinitialize" << p->name();
p->load()->deinitialize();
p->load()->disable();
}
}
}

View File

@ -55,10 +55,6 @@ public:
*/
bool primaryBackendCanUpdateNotification() const;
bool initPrimaryNotificationBackend();
void syncSettings();
QString normalizeSettingsKey(const QString &key, SettingsType type) const
{
return Snore::Utils::normalizeSettingsKey(key, type, m_localSettingsPrefix);
@ -81,6 +77,10 @@ private Q_SLOTS:
void slotNotificationClosed(Snore::Notification);
void slotAboutToQuit();
void slotSyncSettings();
bool slotInitPrimaryNotificationBackend();
Q_SIGNALS:
void applicationRegistered(const Snore::Application &);
void applicationDeregistered(const Snore::Application &);

View File

@ -10,34 +10,32 @@
using namespace Snore;
bool FreedesktopBackend::initialize()
void FreedesktopBackend::slotInitialize()
{
m_interface = new org::freedesktop::Notifications(QLatin1String("org.freedesktop.Notifications"),
QLatin1String("/org/freedesktop/Notifications"),
QDBusConnection::sessionBus(), this);
QDBusPendingReply<QStringList> reply = m_interface->GetCapabilities();
reply.waitForFinished();
QStringList caps = reply.value();
m_supportsRichtext = caps.contains(QLatin1String("body-markup"));
connect(m_interface, SIGNAL(ActionInvoked(uint,QString)), this, SLOT(slotActionInvoked(uint,QString)));
connect(m_interface, SIGNAL(NotificationClosed(uint,uint)), this , SLOT(slotNotificationClosed(uint,uint)));
return SnoreBackend::initialize();
emit initialisationFinished(true);
}
bool FreedesktopBackend::deinitialize()
void FreedesktopBackend::setEnabled(bool enabled)
{
if (SnoreBackend::deinitialize()) {
disconnect(m_interface, SIGNAL(ActionInvoked(uint,QString)), this, SLOT(slotActionInvoked(uint,QString)));
disconnect(m_interface, SIGNAL(NotificationClosed(uint,uint)), this , SLOT(slotNotificationClosed(uint,uint)));
m_interface->deleteLater();
m_interface = nullptr;
m_dbusIdMap.clear();
return true;
if (enabled == isEnabled()) {
return;
}
SnoreBackend::setEnabled(enabled);
if (enabled) {
connect(m_interface, &org::freedesktop::Notifications::ActionInvoked, this, &FreedesktopBackend::slotActionInvoked);
connect(m_interface, &org::freedesktop::Notifications::NotificationClosed, this , &FreedesktopBackend::slotNotificationClosed);
} else {
disconnect(m_interface, &org::freedesktop::Notifications::ActionInvoked, this, &FreedesktopBackend::slotActionInvoked);
disconnect(m_interface, &org::freedesktop::Notifications::NotificationClosed, this , &FreedesktopBackend::slotNotificationClosed);
}
return false;
}
bool FreedesktopBackend::canCloseNotification() const

View File

@ -11,13 +11,15 @@ class FreedesktopBackend: public Snore::SnoreBackend
public:
FreedesktopBackend() = default;
~FreedesktopBackend() = default;
bool initialize() override;
bool deinitialize() override;
void setEnabled(bool enabled) override;
bool canCloseNotification() const override;
bool canUpdateNotification() const override;
public Q_SLOTS:
void slotInitialize() override;
void slotNotify(Snore::Notification notification) override;
void slotCloseNotification(Snore::Notification notification) override;

View File

@ -29,13 +29,10 @@ using namespace Snore;
GrowlBackend *GrowlBackend::s_instance = nullptr;
bool GrowlBackend::initialize()
GrowlBackend::GrowlBackend()
{
if (!SnoreBackend::initialize()) {
return false;
}
s_instance = this;
auto func = [](growl_callback_data * data)->void {
snoreDebug(SNORE_DEBUG) << data->id << QString::fromUtf8(data->reason) << QString::fromUtf8(data->data);
Notification n = Snore::SnoreCore::instance().getActiveNotificationByID(data->id);
@ -58,20 +55,17 @@ bool GrowlBackend::initialize()
}
s_instance->closeNotification(n, r);
};
if (Growl::init((GROWL_CALLBACK)static_cast<void(*)(growl_callback_data *)>(func))
&& Growl::isRunning(GROWL_TCP, settingsValue(QLatin1String("Host")).toString().toUtf8().constData())) {
return true;
}
snoreDebug(SNORE_DEBUG) << "Growl is not running";
return false;
Growl::init((GROWL_CALLBACK)static_cast<void(*)(growl_callback_data *)>(func));
}
bool GrowlBackend::deinitialize()
GrowlBackend::~GrowlBackend()
{
if (!Growl::shutdown()) {
return false;
}
return SnoreBackend::deinitialize();
Growl::shutdown();
}
void GrowlBackend::slotInitialize()
{
emit initialisationFinished(Growl::isRunning(GROWL_TCP, settingsValue(QLatin1String("Host")).toString().toUtf8().constData()));
}
void GrowlBackend::slotRegisterApplication(const Application &application)

View File

@ -30,10 +30,8 @@ class GrowlBackend: public Snore::SnoreBackend
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json")
public:
GrowlBackend() = default;
~GrowlBackend() = default;
bool initialize() override;
bool deinitialize() override;
GrowlBackend();
~GrowlBackend();
Snore::PluginSettingsWidget *settingsWidget() override;
protected:
@ -45,6 +43,7 @@ private:
QHash<QString, Growl *> m_applications;
public Q_SLOTS:
void slotInitialize() override;
void slotRegisterApplication(const Snore::Application &application) override;
void slotDeregisterApplication(const Snore::Application &application) override;
void slotNotify(Snore::Notification notification) override;

View File

@ -111,35 +111,22 @@ private:
};
bool SnarlBackend::initialize()
SnarlBackend::SnarlBackend():
m_eventLoop(new SnarlBackend::SnarlWidget(this))
{
if (!SnoreBackend::initialize()) {
return false;
}
SnarlInterface *snarlInterface = new SnarlInterface();
if (!snarlInterface->IsSnarlRunning()) {
snoreDebug(SNORE_WARNING) << "Snarl is not running";
delete snarlInterface;
return false;
}
m_eventLoop = new SnarlBackend::SnarlWidget(this);
snoreDebug(SNORE_DEBUG) << "Initiating Snarl Backend, Snarl version: " << snarlInterface->GetVersion();
delete snarlInterface;
return true;
}
bool SnarlBackend::deinitialize()
SnarlBackend::~SnarlBackend()
{
if (SnoreBackend::deinitialize()) {
if (m_eventLoop) {
m_eventLoop->deleteLater();
m_eventLoop = nullptr;
m_idMap.clear();
}
return true;
}
return false;
delete m_eventLoop;
}
void SnarlBackend::slotInitialize()
{
SnarlInterface *snarlInterface = new SnarlInterface();
emit initialisationFinished(snarlInterface->IsSnarlRunning());
delete snarlInterface;
}
PluginSettingsWidget *SnarlBackend::settingsWidget()

View File

@ -27,10 +27,8 @@ class SnarlBackend: public Snore::SnoreBackend
Q_INTERFACES(Snore::SnoreBackend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json")
public:
SnarlBackend() = default;
~SnarlBackend() = default;
bool initialize() override;
bool deinitialize() override;
SnarlBackend();
~SnarlBackend();
Snore::PluginSettingsWidget *settingsWidget() override;
virtual bool canCloseNotification() const override;
@ -45,6 +43,7 @@ private:
QHash<QString, Snarl::V42::SnarlInterface *> m_applications;
public Q_SLOTS:
void slotInitialize() override;
void slotRegisterApplication(const Snore::Application &application);
void slotDeregisterApplication(const Snore::Application &application);
void slotNotify(Snore::Notification notification);

View File

@ -105,39 +105,25 @@ void SnoreNotifier::slotCloseNotification(Snore::Notification notification)
//the timer will show the next
}
bool SnoreNotifier::initialize()
void SnoreNotifier::slotInitialize()
{
if (SnoreBackend::initialize()) {
for (int i = 0; i < m_widgets.size(); ++i) {
NotifyWidget *w = new NotifyWidget(i, this);
m_widgets[i] = w;
connect(w, &NotifyWidget::dismissed, [this, w]() {
Notification notification = w->notification();
closeNotification(notification, Notification::DISMISSED);
slotCloseNotification(notification);
});
for (int i = 0; i < m_widgets.size(); ++i) {
NotifyWidget *w = new NotifyWidget(i, this);
m_widgets[i] = w;
connect(w, &NotifyWidget::dismissed, [this, w]() {
Notification notification = w->notification();
closeNotification(notification, Notification::DISMISSED);
slotCloseNotification(notification);
});
connect(w, &NotifyWidget::invoked, [this, w]() {
Notification notification = w->notification();
slotNotificationActionInvoked(notification);
closeNotification(notification, Notification::ACTIVATED);
slotCloseNotification(notification);
});
}
return true;
connect(w, &NotifyWidget::invoked, [this, w]() {
Notification notification = w->notification();
slotNotificationActionInvoked(notification);
closeNotification(notification, Notification::ACTIVATED);
slotCloseNotification(notification);
});
}
return false;
}
bool SnoreNotifier::deinitialize()
{
if (SnoreBackend::deinitialize()) {
for (auto w : m_widgets) {
w->deleteLater();
}
return true;
}
return false;
emit initialisationFinished(true);
}
bool SnoreNotifier::canCloseNotification() const

View File

@ -32,9 +32,6 @@ public:
SnoreNotifier();
~SnoreNotifier();
bool initialize() override;
bool deinitialize() override;
bool canCloseNotification() const override;
bool canUpdateNotification() const override;
@ -44,6 +41,7 @@ protected:
void setDefaultSettings() override;
public Q_SLOTS:
void slotInitialize() override;
virtual void slotNotify(Snore::Notification notification) override;
virtual void slotCloseNotification(Snore::Notification notification) override;

View File

@ -14,16 +14,13 @@
using namespace Snore;
bool SnoreToast::initialize()
void SnoreToast::slotInitialize()
{
if (!SnoreBackend::initialize()) {
return false;
}
if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8) {
snoreDebug(SNORE_DEBUG) << "SnoreToast does not work on windows" << QSysInfo::windowsVersion();
return false;
emit initialisationFinished(false);
}
return true;
emit initialisationFinished(true);
}
bool SnoreToast::canCloseNotification() const

View File

@ -12,11 +12,11 @@ class SnoreToast : public Snore::SnoreBackend
public:
SnoreToast() = default;
~SnoreToast() = default;
virtual bool initialize() override;
virtual bool canCloseNotification() const override;
public Q_SLOTS:
virtual void slotInitialize() override;
void slotNotify(Snore::Notification notification) override;
void slotRegisterApplication(const Snore::Application &application) override;
void slotCloseNotification(Snore::Notification notification) override;

View File

@ -6,13 +6,10 @@
#include <QSystemTrayIcon>
using namespace Snore;
bool TrayIconNotifer::deinitialize()
void TrayIconNotifer::slotInitialize()
{
if (SnoreBackend::deinitialize()) {
m_currentlyDisplaying = false;
return true;
}
return false;
m_currentlyDisplaying = false;
emit initialisationFinished(true);
}
bool TrayIconNotifer::canCloseNotification() const

View File

@ -17,15 +17,15 @@ class TrayIconNotifer: public Snore::SnoreBackend
public:
TrayIconNotifer() = default;
~TrayIconNotifer() = default;
virtual bool deinitialize() override;
virtual bool canCloseNotification() const override;
public Q_SLOTS:
void slotNotify(Snore::Notification notification);
void slotCloseNotification(Snore::Notification notification);
void slotRegisterApplication(const Snore::Application &application);
void slotDeregisterApplication(const Snore::Application &application);
void slotInitialize() override;
void slotNotify(Snore::Notification notification) override;
void slotCloseNotification(Snore::Notification notification) override;
void slotRegisterApplication(const Snore::Application &application) override;
void slotDeregisterApplication(const Snore::Application &application) override;
private:
QSystemTrayIcon *trayIcon(const Snore::Application &app);

View File

@ -29,37 +29,36 @@
using namespace Snore;
bool FreedesktopFrontend::initialize()
void FreedesktopFrontend::slotInitialize()
{
if (!SnoreFrontend::initialize()) {
return false;
}
m_adaptor = new NotificationsAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();
if (dbus.registerService(QLatin1String("org.freedesktop.Notifications"))) {
if (dbus.registerObject(QLatin1String("/org/freedesktop/Notifications"), this)) {
return true;
} else {
snoreDebug(SNORE_WARNING) << "Failed to initialize" << name() << "failed to register object";
}
} else {
snoreDebug(SNORE_WARNING) << "Failed to initialize" << name() << "failed to register service";
}
return false;
emit initialisationFinished(true);
}
bool FreedesktopFrontend::deinitialize()
void FreedesktopFrontend::setEnabled(bool enabled)
{
if (SnoreFrontend::deinitialize()) {
if (enabled == isEnabled()) {
return;
}
SnoreFrontend::setEnabled(enabled);
if (enabled) {
m_adaptor = new NotificationsAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();
if (dbus.registerService(QLatin1String("org.freedesktop.Notifications"))) {
if (!dbus.registerObject(QLatin1String("/org/freedesktop/Notifications"), this)) {
snoreDebug(SNORE_WARNING) << "Failed to initialize" << name() << "failed to register object";
emit initialisationFinished(false);
}
} else {
snoreDebug(SNORE_WARNING) << "Failed to initialize" << name() << "failed to register service";
emit initialisationFinished(false);
}
} else {
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.unregisterService(QLatin1String("org.freedesktop.Notifications"));
dbus.unregisterObject(QLatin1String("/org/freedesktop/Notifications"));
m_adaptor->deleteLater();
m_adaptor = nullptr;
return true;
}
return false;
}
void FreedesktopFrontend::slotActionInvoked(Notification notification)

View File

@ -31,8 +31,8 @@ class FreedesktopFrontend : public Snore::SnoreFrontend
public:
FreedesktopFrontend() = default;
~FreedesktopFrontend() = default;
bool initialize() override;
bool deinitialize() override;
void setEnabled(bool enabled) override;
uint Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int timeout);
void CloseNotification(uint id);
@ -45,6 +45,7 @@ Q_SIGNALS:
void ActionInvoked(uint id, const QString &actionKey);
public Q_SLOTS:
void slotInitialize() override;
void slotActionInvoked(Snore::Notification notification) override;
void slotNotificationClosed(Snore::Notification notification) override;

View File

@ -44,27 +44,22 @@ PushoverFrontend::PushoverFrontend()
});
}
bool PushoverFrontend::initialize()
void PushoverFrontend::slotInitialize()
{
if (!SnoreFrontend::initialize()) {
return false;
}
connectToService();
return true;
emit initialisationFinished(true);
}
bool PushoverFrontend::deinitialize()
void PushoverFrontend::setEnabled(bool enabled)
{
if (SnoreFrontend::deinitialize()) {
if (m_socket) {
m_socket->close();
m_socket->deleteLater();
}
return true;
if (enabled == isEnabled()) {
return;
}
SnoreFrontend::setEnabled(enabled);
if (enabled) {
connectToService();
} else {
disconnectService();
}
return false;
}
PluginSettingsWidget *PushoverFrontend::settingsWidget()
@ -194,6 +189,14 @@ void PushoverFrontend::connectToService()
m_socket->open(QUrl::fromEncoded("wss://client.pushover.net/push"));
}
void PushoverFrontend::disconnectService()
{
if (m_socket) {
m_socket->close();
m_socket->deleteLater();
}
}
void PushoverFrontend::registerDevice(const QString &secret, const QString &deviceName)
{
QNetworkRequest request(QUrl(QLatin1String("https://api.pushover.net/1/devices.json")));

View File

@ -34,8 +34,8 @@ class PushoverFrontend : public Snore::SnoreFrontend
public:
PushoverFrontend();
~PushoverFrontend() = default;
bool initialize() override;
bool deinitialize() override;
void setEnabled(bool enabled) override;
Snore::PluginSettingsWidget *settingsWidget() override;
@ -49,6 +49,7 @@ protected:
void setDefaultSettings() override;
public Q_SLOTS:
void slotInitialize() override;
void slotActionInvoked(Snore::Notification notification);
Q_SIGNALS:
@ -65,6 +66,7 @@ private:
QString device();
void connectToService();
void disconnectService();
void registerDevice(const QString &secret, const QString &deviceName);
void getMessages();

View File

@ -27,34 +27,41 @@
#include <iostream>
using namespace Snore;
bool SnarlNetworkFrontend::initialize()
SnarlNetworkFrontend::SnarlNetworkFrontend():
parser(new Parser(this))
{
}
SnarlNetworkFrontend::~SnarlNetworkFrontend()
{
delete parser;
}
void SnarlNetworkFrontend::slotInitialize()
{
if (!SnoreFrontend::initialize()) {
return false;
}
parser = new Parser(this);
tcpServer = new QTcpServer(this);
if (!tcpServer->listen(QHostAddress::Any, port)) {
snoreDebug(SNORE_DEBUG) << "The port is already used";
return false;
emit initialisationFinished(false);
} else {
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(handleConnection()));
std::cout << "The Snarl Network Protokoll is developed for Snarl <http://www.fullphat.net/>" << std::endl;
}
return true;
emit initialisationFinished(true);
}
bool SnarlNetworkFrontend::deinitialize()
void SnarlNetworkFrontend::setEnabled(bool enabled)
{
if (SnoreFrontend::deinitialize()) {
parser->deleteLater();
parser = NULL;
tcpServer->deleteLater();
tcpServer = NULL;
return true;
if (enabled == isEnabled()) {
return;
}
return false;
SnoreFrontend::setEnabled(enabled);
if (enabled) {
connect(tcpServer, &QTcpServer::newConnection, this, SnarlNetworkFrontend::handleConnection);
} else {
disconnect(tcpServer, &QTcpServer::newConnection, this, SnarlNetworkFrontend::handleConnection);
}
}
void SnarlNetworkFrontend::slotActionInvoked(Snore::Notification notification)

View File

@ -35,12 +35,13 @@ public:
static const int port = 9887;
public:
SnarlNetworkFrontend() = default;
~SnarlNetworkFrontend() = default;
virtual bool initialize() override;
virtual bool deinitialize() override;
SnarlNetworkFrontend();
~SnarlNetworkFrontend();
void setEnabled(bool enabled) override;
public Q_SLOTS:
void slotInitialize() override;
void slotActionInvoked(Snore::Notification notification) override;
void slotNotificationClosed(Snore::Notification notification) override;

View File

@ -59,6 +59,11 @@ void NotifyMyAndroid::slotNotify(Notification notification)
}
void NotifyMyAndroid::slotInitialize()
{
emit initialisationFinished(true);
}
PluginSettingsWidget *NotifyMyAndroid::settingsWidget()
{
return new NotifyMyAndroidSettings(this);

View File

@ -37,6 +37,7 @@ protected:
void setDefaultSettings() override;
public Q_SLOTS:
void slotInitialize() override;
void slotNotify(Snore::Notification notification) override;
private:

View File

@ -120,6 +120,11 @@ void Pushover::slotNotify(Notification notification)
}
void Pushover::slotInitialize()
{
emit initialisationFinished(true);
}
PluginSettingsWidget *Pushover::settingsWidget()
{
return new PushoverSettings(this);

View File

@ -37,6 +37,7 @@ protected:
void setDefaultSettings() override;
public Q_SLOTS:
void slotInitialize() override;
void slotNotify(Snore::Notification notification) override;
private:

View File

@ -34,10 +34,10 @@ Sound::Sound():
});
}
bool Sound::initialize()
void Sound::slotInitialize()
{
m_player->setVolume(settingsValue(QLatin1String("Volume")).toInt());
return SnoreSecondaryBackend::initialize();
emit initialisationFinished(true);
}
PluginSettingsWidget *Sound::settingsWidget()

View File

@ -31,14 +31,13 @@ public:
Sound();
~Sound() = default;
virtual bool initialize() override;
Snore::PluginSettingsWidget *settingsWidget() override;
protected:
void setDefaultSettings() override;
public Q_SLOTS:
void slotInitialize() override;
void slotNotificationDisplayed(Snore::Notification notification) override;
private:
QMediaPlayer *m_player;

View File

@ -77,6 +77,11 @@ void Toasty::slotNotify(Notification notification)
}
void Toasty::slotInitialize()
{
emit initialisationFinished(true);
}
PluginSettingsWidget *Toasty::settingsWidget()
{
return new ToastySettings(this);

View File

@ -37,6 +37,7 @@ protected:
void setDefaultSettings() override;
public Q_SLOTS:
void slotInitialize() override;
void slotNotify(Snore::Notification notification) override;
private: