diff --git a/src/libsnore/plugins/plugins.cpp b/src/libsnore/plugins/plugins.cpp index 9549916..2700665 100644 --- a/src/libsnore/plugins/plugins.cpp +++ b/src/libsnore/plugins/plugins.cpp @@ -35,7 +35,7 @@ SnorePlugin::SnorePlugin() if (thread() != qApp->thread()) { snoreDebug(SNORE_WARNING) << "Plugin initialized in wrong thread."; } - connect(this, &SnorePlugin::initialisationFinished, [this](bool b) { + connect(this, &SnorePlugin::initializeChanged, [this](bool b) { snoreDebug(SNORE_DEBUG) << "Plugin:" << name() << "initialized" << b; Q_ASSERT_X(!(b && m_initialized), Q_FUNC_INFO, "Plugin initialized multiple times."); if (!b) { @@ -119,6 +119,10 @@ void SnorePlugin::setDefaultSettings() void SnorePlugin::setEnabled(bool enabled) { Q_ASSERT_X(!enabled || isInitialized(), Q_FUNC_INFO, "Plugin not initialized"); + + if (enabled != m_enabled) { + emit enabledChanged(enabled); + } m_enabled = enabled; } diff --git a/src/libsnore/plugins/plugins.h b/src/libsnore/plugins/plugins.h index e463c0f..cd88e00 100644 --- a/src/libsnore/plugins/plugins.h +++ b/src/libsnore/plugins/plugins.h @@ -53,7 +53,7 @@ public: SnorePlugin(); virtual ~SnorePlugin(); - virtual void setEnabled(bool enabled); + void setEnabled(bool enabled); void enable(); void disable(); @@ -84,7 +84,8 @@ public: virtual PluginSettingsWidget *settingsWidget(); Q_SIGNALS: - void initialisationFinished(bool initialized); + void initializeChanged(bool initialized); + void enabledChanged(bool enabled); public Q_SLOTS: virtual void slotInitialize() = 0; diff --git a/src/libsnore/plugins/snorebackend.cpp b/src/libsnore/plugins/snorebackend.cpp index 28fa60d..f4a36d3 100644 --- a/src/libsnore/plugins/snorebackend.cpp +++ b/src/libsnore/plugins/snorebackend.cpp @@ -29,40 +29,37 @@ using namespace Snore; +SnoreBackend::SnoreBackend() +{ + connect(this, &SnoreSecondaryBackend::enabledChanged, [this](bool enabled) { + if (enabled) { + 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); + + for (const Application &a : SnoreCore::instance().aplications()) { + slotRegisterApplication(a); + } + } else { + for (const Application &a : SnoreCore::instance().aplications()) { + slotDeregisterApplication(a); + } + disconnect(SnoreCorePrivate::instance(), &SnoreCorePrivate::applicationRegistered, this, &SnoreBackend::slotRegisterApplication); + disconnect(SnoreCorePrivate::instance(), &SnoreCorePrivate::applicationDeregistered, this, &SnoreBackend::slotDeregisterApplication); + + disconnect(this, &SnoreBackend::notificationClosed, SnoreCorePrivate::instance(), &SnoreCorePrivate::slotNotificationClosed); + disconnect(SnoreCorePrivate::instance(), &SnoreCorePrivate::notify, this, &SnoreBackend::slotNotify); + } + }); +} + SnoreBackend::~SnoreBackend() { snoreDebug(SNORE_DEBUG) << "Deleting" << name(); } -void SnoreBackend::setEnabled(bool enabled) -{ - 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(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()) { - slotRegisterApplication(a); - } - } else { - for (const Application &a : SnoreCore::instance().aplications()) { - slotDeregisterApplication(a); - } - disconnect(SnoreCorePrivate::instance(), &SnoreCorePrivate::applicationRegistered, this, &SnoreBackend::slotRegisterApplication); - disconnect(SnoreCorePrivate::instance(), &SnoreCorePrivate::applicationDeregistered, this, &SnoreBackend::slotDeregisterApplication); - - disconnect(this, &SnoreBackend::notificationClosed, SnoreCorePrivate::instance(), &SnoreCorePrivate::slotNotificationClosed); - disconnect(SnoreCorePrivate::instance(), &SnoreCorePrivate::notify, this, &SnoreBackend::slotNotify); - - } -} - void SnoreBackend::requestCloseNotification(Notification notification, Notification::CloseReasons reason) { if (canCloseNotification() && notification.isValid()) { @@ -90,26 +87,24 @@ void SnoreBackend::slotCloseNotification(Notification notification) Q_UNUSED(notification) } +SnoreSecondaryBackend::SnoreSecondaryBackend() +{ + connect(this, &SnoreSecondaryBackend::enabledChanged, [this](bool 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); + } + }); +} + SnoreSecondaryBackend::~SnoreSecondaryBackend() { snoreDebug(SNORE_DEBUG) << "Deleting" << name(); } -void SnoreSecondaryBackend::setEnabled(bool enabled) -{ - if (enabled == isEnabled()) { - return; - } - 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); - } -} - void SnoreSecondaryBackend::slotNotify(Notification) { diff --git a/src/libsnore/plugins/snorebackend.h b/src/libsnore/plugins/snorebackend.h index 34aa035..9eb6753 100644 --- a/src/libsnore/plugins/snorebackend.h +++ b/src/libsnore/plugins/snorebackend.h @@ -31,11 +31,9 @@ class SNORE_EXPORT SnoreBackend : public SnorePlugin Q_OBJECT Q_INTERFACES(Snore::SnorePlugin) public: - SnoreBackend() = default; + SnoreBackend(); virtual ~SnoreBackend(); - virtual void setEnabled(bool enabled) override; - void requestCloseNotification(Snore::Notification notification, Notification::CloseReasons reason); virtual bool canCloseNotification() const; @@ -72,11 +70,9 @@ class SNORE_EXPORT SnoreSecondaryBackend : public SnorePlugin Q_OBJECT Q_INTERFACES(Snore::SnorePlugin Snore::SnorePlugin) public: - SnoreSecondaryBackend() = default; + SnoreSecondaryBackend(); virtual ~SnoreSecondaryBackend(); - virtual void setEnabled(bool enabled) override; - public Q_SLOTS: virtual void slotNotify(Snore::Notification notification); virtual void slotNotificationDisplayed(Snore::Notification notification); diff --git a/src/libsnore/plugins/snorefrontend.cpp b/src/libsnore/plugins/snorefrontend.cpp index 2f33c26..ff66d34 100644 --- a/src/libsnore/plugins/snorefrontend.cpp +++ b/src/libsnore/plugins/snorefrontend.cpp @@ -21,26 +21,24 @@ using namespace Snore; +SnoreFrontend::SnoreFrontend() +{ + connect(this, &SnoreFrontend::enabledChanged, [this](bool 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); + } + }); +} + SnoreFrontend::~SnoreFrontend() { snoreDebug(SNORE_DEBUG) << "Deleting" << name(); } -void SnoreFrontend::setEnabled(bool enabled) -{ - if (enabled == isEnabled()) { - return; - } - 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); - } -} - void SnoreFrontend::slotActionInvoked(Notification) { diff --git a/src/libsnore/plugins/snorefrontend.h b/src/libsnore/plugins/snorefrontend.h index abb22b5..88cc27f 100644 --- a/src/libsnore/plugins/snorefrontend.h +++ b/src/libsnore/plugins/snorefrontend.h @@ -31,11 +31,9 @@ class SNORE_EXPORT SnoreFrontend: public SnorePlugin Q_OBJECT Q_INTERFACES(Snore::SnorePlugin) public: - SnoreFrontend() = default; + SnoreFrontend(); virtual ~SnoreFrontend(); - virtual void setEnabled(bool enabled) override; - public Q_SLOTS: virtual void slotActionInvoked(Snore::Notification notification); virtual void slotNotificationClosed(Snore::Notification notification); diff --git a/src/libsnore/snore.cpp b/src/libsnore/snore.cpp index 4ead36a..1ad208f 100644 --- a/src/libsnore/snore.cpp +++ b/src/libsnore/snore.cpp @@ -84,7 +84,7 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types) case SnorePlugin::SECONDARY_BACKEND: case SnorePlugin::FRONTEND: case SnorePlugin::PLUGIN: - connect(plugin, &SnorePlugin::initialisationFinished, [plugin](bool initialized) { + connect(plugin, &SnorePlugin::initializeChanged, [plugin](bool initialized) { if (initialized) { plugin->setEnabled(plugin->settingsValue(QLatin1String("Enabled"), LOCAL_SETTING).toBool()); } @@ -95,7 +95,7 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types) continue; } - connect(plugin, &SnorePlugin::initialisationFinished, [d, plugin](bool initialized) { + connect(plugin, &SnorePlugin::initializeChanged, [d, plugin](bool initialized) { if (!initialized) { //TODO: improve d->m_pluginNames[plugin->type()].removeAll(plugin->name()); diff --git a/src/libsnore/snore_p.cpp b/src/libsnore/snore_p.cpp index a0cfd02..6a019ba 100644 --- a/src/libsnore/snore_p.cpp +++ b/src/libsnore/snore_p.cpp @@ -93,7 +93,7 @@ bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend) if (m_notificationBackend) { m_notificationBackend->disable(); } - connect(b, &SnoreBackend::initialisationFinished, [this, b](bool initialized) { + connect(b, &SnoreBackend::initializeChanged, [this, b](bool initialized) { if (!initialized) { slotInitPrimaryNotificationBackend(); } diff --git a/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp b/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp index b78b84a..da5c2ad 100644 --- a/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp +++ b/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp @@ -10,6 +10,20 @@ using namespace Snore; +FreedesktopBackend::FreedesktopBackend() +{ + connect(this, &SnoreSecondaryBackend::enabledChanged, [this](bool 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); + + } + }); +} + void FreedesktopBackend::slotInitialize() { m_interface = new org::freedesktop::Notifications(QLatin1String("org.freedesktop.Notifications"), @@ -19,23 +33,7 @@ void FreedesktopBackend::slotInitialize() reply.waitForFinished(); QStringList caps = reply.value(); m_supportsRichtext = caps.contains(QLatin1String("body-markup")); - emit initialisationFinished(true); -} - -void FreedesktopBackend::setEnabled(bool enabled) -{ - 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); - - } + emit initializeChanged(true); } bool FreedesktopBackend::canCloseNotification() const diff --git a/src/plugins/backends/freedesktop/freedesktopnotification_backend.h b/src/plugins/backends/freedesktop/freedesktopnotification_backend.h index 2444580..8b4fb93 100644 --- a/src/plugins/backends/freedesktop/freedesktopnotification_backend.h +++ b/src/plugins/backends/freedesktop/freedesktopnotification_backend.h @@ -9,11 +9,9 @@ class FreedesktopBackend: public Snore::SnoreBackend Q_INTERFACES(Snore::SnoreBackend) Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json") public: - FreedesktopBackend() = default; + FreedesktopBackend(); ~FreedesktopBackend() = default; - void setEnabled(bool enabled) override; - bool canCloseNotification() const override; bool canUpdateNotification() const override; diff --git a/src/plugins/backends/growl/growlbackend.cpp b/src/plugins/backends/growl/growlbackend.cpp index ef5b315..8f08406 100644 --- a/src/plugins/backends/growl/growlbackend.cpp +++ b/src/plugins/backends/growl/growlbackend.cpp @@ -65,7 +65,7 @@ GrowlBackend::~GrowlBackend() void GrowlBackend::slotInitialize() { - emit initialisationFinished(Growl::isRunning(GROWL_TCP, settingsValue(QLatin1String("Host")).toString().toUtf8().constData())); + emit initializeChanged(Growl::isRunning(GROWL_TCP, settingsValue(QLatin1String("Host")).toString().toUtf8().constData())); } void GrowlBackend::slotRegisterApplication(const Application &application) diff --git a/src/plugins/backends/osxnotificationcenter/osxnotificationcenter.h b/src/plugins/backends/osxnotificationcenter/osxnotificationcenter.h index 48f6690..7f12e5c 100644 --- a/src/plugins/backends/osxnotificationcenter/osxnotificationcenter.h +++ b/src/plugins/backends/osxnotificationcenter/osxnotificationcenter.h @@ -32,6 +32,7 @@ public: ~OSXNotificationCenter(); public Q_SLOTS: + void slotInitialize() override; void slotNotify(Snore::Notification notification) override; }; diff --git a/src/plugins/backends/snarl/snarl.cpp b/src/plugins/backends/snarl/snarl.cpp index 2247ca1..259029e 100644 --- a/src/plugins/backends/snarl/snarl.cpp +++ b/src/plugins/backends/snarl/snarl.cpp @@ -125,7 +125,7 @@ void SnarlBackend::slotInitialize() { SnarlInterface *snarlInterface = new SnarlInterface(); - emit initialisationFinished(snarlInterface->IsSnarlRunning()); + emit initializeChanged(snarlInterface->IsSnarlRunning()); delete snarlInterface; } diff --git a/src/plugins/backends/snore/snorenotifier.cpp b/src/plugins/backends/snore/snorenotifier.cpp index 9adc062..4c6a44a 100644 --- a/src/plugins/backends/snore/snorenotifier.cpp +++ b/src/plugins/backends/snore/snorenotifier.cpp @@ -123,7 +123,7 @@ void SnoreNotifier::slotInitialize() slotCloseNotification(notification); }); } - emit initialisationFinished(true); + emit initializeChanged(true); } bool SnoreNotifier::canCloseNotification() const diff --git a/src/plugins/backends/snoretoast/snoretoast.cpp b/src/plugins/backends/snoretoast/snoretoast.cpp index 5afdcd9..eb62b4e 100644 --- a/src/plugins/backends/snoretoast/snoretoast.cpp +++ b/src/plugins/backends/snoretoast/snoretoast.cpp @@ -18,9 +18,9 @@ void SnoreToast::slotInitialize() { if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8) { snoreDebug(SNORE_DEBUG) << "SnoreToast does not work on windows" << QSysInfo::windowsVersion(); - emit initialisationFinished(false); + emit initializeChanged(false); } - emit initialisationFinished(true); + emit initializeChanged(true); } bool SnoreToast::canCloseNotification() const @@ -134,7 +134,7 @@ QProcess *SnoreToast::createProcess(Notification noti) if (noti.isValid()) { closeNotification(noti, Notification::NONE); } - emit initialisationFinished(false); + emit initializeChanged(false); p->deleteLater(); }); connect(qApp, &QApplication::aboutToQuit, p, &QProcess::kill); diff --git a/src/plugins/backends/trayicon/trayiconnotifer.cpp b/src/plugins/backends/trayicon/trayiconnotifer.cpp index bd4d815..7bb1909 100644 --- a/src/plugins/backends/trayicon/trayiconnotifer.cpp +++ b/src/plugins/backends/trayicon/trayiconnotifer.cpp @@ -9,7 +9,7 @@ using namespace Snore; void TrayIconNotifer::slotInitialize() { m_currentlyDisplaying = false; - emit initialisationFinished(true); + emit initializeChanged(true); } bool TrayIconNotifer::canCloseNotification() const diff --git a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp index 2ab4524..c3f45ba 100644 --- a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp +++ b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp @@ -29,36 +29,34 @@ using namespace Snore; -void FreedesktopFrontend::slotInitialize() +FreedesktopFrontend::FreedesktopFrontend() { - emit initialisationFinished(true); -} - -void FreedesktopFrontend::setEnabled(bool enabled) -{ - 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); + connect(this, &FreedesktopFrontend::enabledChanged, [this](bool 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 initializeChanged(false); + } + } else { + snoreDebug(SNORE_WARNING) << "Failed to initialize" << name() << "failed to register service"; + emit initializeChanged(false); } } else { - snoreDebug(SNORE_WARNING) << "Failed to initialize" << name() << "failed to register service"; - emit initialisationFinished(false); + QDBusConnection dbus = QDBusConnection::sessionBus(); + dbus.unregisterService(QLatin1String("org.freedesktop.Notifications")); + dbus.unregisterObject(QLatin1String("/org/freedesktop/Notifications")); + m_adaptor->deleteLater(); + m_adaptor = nullptr; } - } else { - QDBusConnection dbus = QDBusConnection::sessionBus(); - dbus.unregisterService(QLatin1String("org.freedesktop.Notifications")); - dbus.unregisterObject(QLatin1String("/org/freedesktop/Notifications")); - m_adaptor->deleteLater(); - m_adaptor = nullptr; - } + }); +} + +void FreedesktopFrontend::slotInitialize() +{ + emit initializeChanged(true); } void FreedesktopFrontend::slotActionInvoked(Notification notification) diff --git a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.h b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.h index f9a6e79..a15a91f 100644 --- a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.h +++ b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.h @@ -29,11 +29,9 @@ class FreedesktopFrontend : public Snore::SnoreFrontend Q_INTERFACES(Snore::SnoreFrontend) Q_PLUGIN_METADATA(IID "org.Snore.NotificationFrontend/1.0" FILE "plugin.json") public: - FreedesktopFrontend() = default; + FreedesktopFrontend(); ~FreedesktopFrontend() = default; - 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); diff --git a/src/plugins/frontends/pushover/pushover_frontend.cpp b/src/plugins/frontends/pushover/pushover_frontend.cpp index 3f6f085..a9aa54c 100644 --- a/src/plugins/frontends/pushover/pushover_frontend.cpp +++ b/src/plugins/frontends/pushover/pushover_frontend.cpp @@ -42,24 +42,18 @@ PushoverFrontend::PushoverFrontend() connect(this, &PushoverFrontend::error, [this](QString error) { m_errorMessage = error; }); + connect(this, &PushoverFrontend::enabledChanged, [this](bool enabled) { + if (enabled) { + connectToService(); + } else { + disconnectService(); + } + }); } void PushoverFrontend::slotInitialize() { - emit initialisationFinished(true); -} - -void PushoverFrontend::setEnabled(bool enabled) -{ - if (enabled == isEnabled()) { - return; - } - SnoreFrontend::setEnabled(enabled); - if (enabled) { - connectToService(); - } else { - disconnectService(); - } + emit initializeChanged(true); } PluginSettingsWidget *PushoverFrontend::settingsWidget() diff --git a/src/plugins/frontends/pushover/pushover_frontend.h b/src/plugins/frontends/pushover/pushover_frontend.h index 46fe221..d1b5da7 100644 --- a/src/plugins/frontends/pushover/pushover_frontend.h +++ b/src/plugins/frontends/pushover/pushover_frontend.h @@ -35,8 +35,6 @@ public: PushoverFrontend(); ~PushoverFrontend() = default; - void setEnabled(bool enabled) override; - Snore::PluginSettingsWidget *settingsWidget() override; void login(const QString &email, const QString &password, const QString &deviceName); diff --git a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp index 463db9c..2826ca0 100644 --- a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp +++ b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp @@ -30,7 +30,13 @@ using namespace Snore; SnarlNetworkFrontend::SnarlNetworkFrontend(): parser(new Parser(this)) { - + connect(this, &SnarlNetworkFrontend::enabledChanged, [this](bool enabled) { + if (enabled) { + connect(tcpServer, &QTcpServer::newConnection, this, SnarlNetworkFrontend::handleConnection); + } else { + disconnect(tcpServer, &QTcpServer::newConnection, this, SnarlNetworkFrontend::handleConnection); + } + }); } SnarlNetworkFrontend::~SnarlNetworkFrontend() @@ -43,25 +49,11 @@ void SnarlNetworkFrontend::slotInitialize() tcpServer = new QTcpServer(this); if (!tcpServer->listen(QHostAddress::Any, port)) { snoreDebug(SNORE_DEBUG) << "The port is already used"; - emit initialisationFinished(false); + emit initializeChanged(false); } else { std::cout << "The Snarl Network Protokoll is developed for Snarl " << std::endl; } - emit initialisationFinished(true); -} - -void SnarlNetworkFrontend::setEnabled(bool enabled) -{ - if (enabled == isEnabled()) { - return; - } - SnoreFrontend::setEnabled(enabled); - if (enabled) { - connect(tcpServer, &QTcpServer::newConnection, this, SnarlNetworkFrontend::handleConnection); - } else { - disconnect(tcpServer, &QTcpServer::newConnection, this, SnarlNetworkFrontend::handleConnection); - } - + emit initializeChanged(true); } void SnarlNetworkFrontend::slotActionInvoked(Snore::Notification notification) diff --git a/src/plugins/frontends/snarlnetwork/snarlnetwork.h b/src/plugins/frontends/snarlnetwork/snarlnetwork.h index 8d35793..ea730b8 100644 --- a/src/plugins/frontends/snarlnetwork/snarlnetwork.h +++ b/src/plugins/frontends/snarlnetwork/snarlnetwork.h @@ -38,8 +38,6 @@ public: SnarlNetworkFrontend(); ~SnarlNetworkFrontend(); - void setEnabled(bool enabled) override; - public Q_SLOTS: void slotInitialize() override; void slotActionInvoked(Snore::Notification notification) override; diff --git a/src/plugins/secondary_backends/nma/nma.cpp b/src/plugins/secondary_backends/nma/nma.cpp index 682e481..4262924 100644 --- a/src/plugins/secondary_backends/nma/nma.cpp +++ b/src/plugins/secondary_backends/nma/nma.cpp @@ -61,7 +61,7 @@ void NotifyMyAndroid::slotNotify(Notification notification) void NotifyMyAndroid::slotInitialize() { - emit initialisationFinished(true); + emit initializeChanged(true); } PluginSettingsWidget *NotifyMyAndroid::settingsWidget() diff --git a/src/plugins/secondary_backends/pushover/pushover.cpp b/src/plugins/secondary_backends/pushover/pushover.cpp index 7846260..86bd498 100644 --- a/src/plugins/secondary_backends/pushover/pushover.cpp +++ b/src/plugins/secondary_backends/pushover/pushover.cpp @@ -122,7 +122,7 @@ void Pushover::slotNotify(Notification notification) void Pushover::slotInitialize() { - emit initialisationFinished(true); + emit initializeChanged(true); } PluginSettingsWidget *Pushover::settingsWidget() diff --git a/src/plugins/secondary_backends/sound/sound.cpp b/src/plugins/secondary_backends/sound/sound.cpp index 56fa03f..f5cd835 100644 --- a/src/plugins/secondary_backends/sound/sound.cpp +++ b/src/plugins/secondary_backends/sound/sound.cpp @@ -37,7 +37,7 @@ Sound::Sound(): void Sound::slotInitialize() { m_player->setVolume(settingsValue(QLatin1String("Volume")).toInt()); - emit initialisationFinished(true); + emit initializeChanged(true); } PluginSettingsWidget *Sound::settingsWidget() diff --git a/src/plugins/secondary_backends/toasty/toasty.cpp b/src/plugins/secondary_backends/toasty/toasty.cpp index c629ba2..bfbd9f0 100644 --- a/src/plugins/secondary_backends/toasty/toasty.cpp +++ b/src/plugins/secondary_backends/toasty/toasty.cpp @@ -79,7 +79,7 @@ void Toasty::slotNotify(Notification notification) void Toasty::slotInitialize() { - emit initialisationFinished(true); + emit initializeChanged(true); } PluginSettingsWidget *Toasty::settingsWidget()