improve SnorePlugin::setEnabled

This commit is contained in:
Patrick von Reth 2015-07-13 21:49:33 +02:00
parent 24bfc9e50b
commit 7d0f7584fd
26 changed files with 136 additions and 169 deletions

View File

@ -35,7 +35,7 @@ SnorePlugin::SnorePlugin()
if (thread() != qApp->thread()) { if (thread() != qApp->thread()) {
snoreDebug(SNORE_WARNING) << "Plugin initialized in wrong 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; snoreDebug(SNORE_DEBUG) << "Plugin:" << name() << "initialized" << b;
Q_ASSERT_X(!(b && m_initialized), Q_FUNC_INFO, "Plugin initialized multiple times."); Q_ASSERT_X(!(b && m_initialized), Q_FUNC_INFO, "Plugin initialized multiple times.");
if (!b) { if (!b) {
@ -119,6 +119,10 @@ void SnorePlugin::setDefaultSettings()
void SnorePlugin::setEnabled(bool enabled) void SnorePlugin::setEnabled(bool enabled)
{ {
Q_ASSERT_X(!enabled || isInitialized(), Q_FUNC_INFO, "Plugin not initialized"); Q_ASSERT_X(!enabled || isInitialized(), Q_FUNC_INFO, "Plugin not initialized");
if (enabled != m_enabled) {
emit enabledChanged(enabled);
}
m_enabled = enabled; m_enabled = enabled;
} }

View File

@ -53,7 +53,7 @@ public:
SnorePlugin(); SnorePlugin();
virtual ~SnorePlugin(); virtual ~SnorePlugin();
virtual void setEnabled(bool enabled); void setEnabled(bool enabled);
void enable(); void enable();
void disable(); void disable();
@ -84,7 +84,8 @@ public:
virtual PluginSettingsWidget *settingsWidget(); virtual PluginSettingsWidget *settingsWidget();
Q_SIGNALS: Q_SIGNALS:
void initialisationFinished(bool initialized); void initializeChanged(bool initialized);
void enabledChanged(bool enabled);
public Q_SLOTS: public Q_SLOTS:
virtual void slotInitialize() = 0; virtual void slotInitialize() = 0;

View File

@ -29,40 +29,37 @@
using namespace Snore; 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() SnoreBackend::~SnoreBackend()
{ {
snoreDebug(SNORE_DEBUG) << "Deleting" << name(); 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) void SnoreBackend::requestCloseNotification(Notification notification, Notification::CloseReasons reason)
{ {
if (canCloseNotification() && notification.isValid()) { if (canCloseNotification() && notification.isValid()) {
@ -90,26 +87,24 @@ void SnoreBackend::slotCloseNotification(Notification notification)
Q_UNUSED(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() SnoreSecondaryBackend::~SnoreSecondaryBackend()
{ {
snoreDebug(SNORE_DEBUG) << "Deleting" << name(); 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) void SnoreSecondaryBackend::slotNotify(Notification)
{ {

View File

@ -31,11 +31,9 @@ class SNORE_EXPORT SnoreBackend : public SnorePlugin
Q_OBJECT Q_OBJECT
Q_INTERFACES(Snore::SnorePlugin) Q_INTERFACES(Snore::SnorePlugin)
public: public:
SnoreBackend() = default; SnoreBackend();
virtual ~SnoreBackend(); virtual ~SnoreBackend();
virtual void setEnabled(bool enabled) override;
void requestCloseNotification(Snore::Notification notification, Notification::CloseReasons reason); void requestCloseNotification(Snore::Notification notification, Notification::CloseReasons reason);
virtual bool canCloseNotification() const; virtual bool canCloseNotification() const;
@ -72,11 +70,9 @@ class SNORE_EXPORT SnoreSecondaryBackend : public SnorePlugin
Q_OBJECT Q_OBJECT
Q_INTERFACES(Snore::SnorePlugin Snore::SnorePlugin) Q_INTERFACES(Snore::SnorePlugin Snore::SnorePlugin)
public: public:
SnoreSecondaryBackend() = default; SnoreSecondaryBackend();
virtual ~SnoreSecondaryBackend(); virtual ~SnoreSecondaryBackend();
virtual void setEnabled(bool enabled) override;
public Q_SLOTS: public Q_SLOTS:
virtual void slotNotify(Snore::Notification notification); virtual void slotNotify(Snore::Notification notification);
virtual void slotNotificationDisplayed(Snore::Notification notification); virtual void slotNotificationDisplayed(Snore::Notification notification);

View File

@ -21,26 +21,24 @@
using namespace Snore; 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() SnoreFrontend::~SnoreFrontend()
{ {
snoreDebug(SNORE_DEBUG) << "Deleting" << name(); 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) void SnoreFrontend::slotActionInvoked(Notification)
{ {

View File

@ -31,11 +31,9 @@ class SNORE_EXPORT SnoreFrontend: public SnorePlugin
Q_OBJECT Q_OBJECT
Q_INTERFACES(Snore::SnorePlugin) Q_INTERFACES(Snore::SnorePlugin)
public: public:
SnoreFrontend() = default; SnoreFrontend();
virtual ~SnoreFrontend(); virtual ~SnoreFrontend();
virtual void setEnabled(bool enabled) override;
public Q_SLOTS: public Q_SLOTS:
virtual void slotActionInvoked(Snore::Notification notification); virtual void slotActionInvoked(Snore::Notification notification);
virtual void slotNotificationClosed(Snore::Notification notification); virtual void slotNotificationClosed(Snore::Notification notification);

View File

@ -84,7 +84,7 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
case SnorePlugin::SECONDARY_BACKEND: case SnorePlugin::SECONDARY_BACKEND:
case SnorePlugin::FRONTEND: case SnorePlugin::FRONTEND:
case SnorePlugin::PLUGIN: case SnorePlugin::PLUGIN:
connect(plugin, &SnorePlugin::initialisationFinished, [plugin](bool initialized) { connect(plugin, &SnorePlugin::initializeChanged, [plugin](bool initialized) {
if (initialized) { if (initialized) {
plugin->setEnabled(plugin->settingsValue(QLatin1String("Enabled"), LOCAL_SETTING).toBool()); plugin->setEnabled(plugin->settingsValue(QLatin1String("Enabled"), LOCAL_SETTING).toBool());
} }
@ -95,7 +95,7 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
continue; continue;
} }
connect(plugin, &SnorePlugin::initialisationFinished, [d, plugin](bool initialized) { connect(plugin, &SnorePlugin::initializeChanged, [d, plugin](bool initialized) {
if (!initialized) { if (!initialized) {
//TODO: improve //TODO: improve
d->m_pluginNames[plugin->type()].removeAll(plugin->name()); d->m_pluginNames[plugin->type()].removeAll(plugin->name());

View File

@ -93,7 +93,7 @@ bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
if (m_notificationBackend) { if (m_notificationBackend) {
m_notificationBackend->disable(); m_notificationBackend->disable();
} }
connect(b, &SnoreBackend::initialisationFinished, [this, b](bool initialized) { connect(b, &SnoreBackend::initializeChanged, [this, b](bool initialized) {
if (!initialized) { if (!initialized) {
slotInitPrimaryNotificationBackend(); slotInitPrimaryNotificationBackend();
} }

View File

@ -10,6 +10,20 @@
using namespace Snore; 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() void FreedesktopBackend::slotInitialize()
{ {
m_interface = new org::freedesktop::Notifications(QLatin1String("org.freedesktop.Notifications"), m_interface = new org::freedesktop::Notifications(QLatin1String("org.freedesktop.Notifications"),
@ -19,23 +33,7 @@ void FreedesktopBackend::slotInitialize()
reply.waitForFinished(); reply.waitForFinished();
QStringList caps = reply.value(); QStringList caps = reply.value();
m_supportsRichtext = caps.contains(QLatin1String("body-markup")); m_supportsRichtext = caps.contains(QLatin1String("body-markup"));
emit initialisationFinished(true); emit initializeChanged(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);
}
} }
bool FreedesktopBackend::canCloseNotification() const bool FreedesktopBackend::canCloseNotification() const

View File

@ -9,11 +9,9 @@ class FreedesktopBackend: public Snore::SnoreBackend
Q_INTERFACES(Snore::SnoreBackend) Q_INTERFACES(Snore::SnoreBackend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json") Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json")
public: public:
FreedesktopBackend() = default; FreedesktopBackend();
~FreedesktopBackend() = default; ~FreedesktopBackend() = default;
void setEnabled(bool enabled) override;
bool canCloseNotification() const override; bool canCloseNotification() const override;
bool canUpdateNotification() const override; bool canUpdateNotification() const override;

View File

@ -65,7 +65,7 @@ GrowlBackend::~GrowlBackend()
void GrowlBackend::slotInitialize() 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) void GrowlBackend::slotRegisterApplication(const Application &application)

View File

@ -32,6 +32,7 @@ public:
~OSXNotificationCenter(); ~OSXNotificationCenter();
public Q_SLOTS: public Q_SLOTS:
void slotInitialize() override;
void slotNotify(Snore::Notification notification) override; void slotNotify(Snore::Notification notification) override;
}; };

View File

@ -125,7 +125,7 @@ void SnarlBackend::slotInitialize()
{ {
SnarlInterface *snarlInterface = new SnarlInterface(); SnarlInterface *snarlInterface = new SnarlInterface();
emit initialisationFinished(snarlInterface->IsSnarlRunning()); emit initializeChanged(snarlInterface->IsSnarlRunning());
delete snarlInterface; delete snarlInterface;
} }

View File

@ -123,7 +123,7 @@ void SnoreNotifier::slotInitialize()
slotCloseNotification(notification); slotCloseNotification(notification);
}); });
} }
emit initialisationFinished(true); emit initializeChanged(true);
} }
bool SnoreNotifier::canCloseNotification() const bool SnoreNotifier::canCloseNotification() const

View File

@ -18,9 +18,9 @@ void SnoreToast::slotInitialize()
{ {
if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8) { if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8) {
snoreDebug(SNORE_DEBUG) << "SnoreToast does not work on windows" << QSysInfo::windowsVersion(); 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 bool SnoreToast::canCloseNotification() const
@ -134,7 +134,7 @@ QProcess *SnoreToast::createProcess(Notification noti)
if (noti.isValid()) { if (noti.isValid()) {
closeNotification(noti, Notification::NONE); closeNotification(noti, Notification::NONE);
} }
emit initialisationFinished(false); emit initializeChanged(false);
p->deleteLater(); p->deleteLater();
}); });
connect(qApp, &QApplication::aboutToQuit, p, &QProcess::kill); connect(qApp, &QApplication::aboutToQuit, p, &QProcess::kill);

View File

@ -9,7 +9,7 @@ using namespace Snore;
void TrayIconNotifer::slotInitialize() void TrayIconNotifer::slotInitialize()
{ {
m_currentlyDisplaying = false; m_currentlyDisplaying = false;
emit initialisationFinished(true); emit initializeChanged(true);
} }
bool TrayIconNotifer::canCloseNotification() const bool TrayIconNotifer::canCloseNotification() const

View File

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

View File

@ -29,11 +29,9 @@ class FreedesktopFrontend : public Snore::SnoreFrontend
Q_INTERFACES(Snore::SnoreFrontend) Q_INTERFACES(Snore::SnoreFrontend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationFrontend/1.0" FILE "plugin.json") Q_PLUGIN_METADATA(IID "org.Snore.NotificationFrontend/1.0" FILE "plugin.json")
public: public:
FreedesktopFrontend() = default; FreedesktopFrontend();
~FreedesktopFrontend() = default; ~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); 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); void CloseNotification(uint id);

View File

@ -42,24 +42,18 @@ PushoverFrontend::PushoverFrontend()
connect(this, &PushoverFrontend::error, [this](QString error) { connect(this, &PushoverFrontend::error, [this](QString error) {
m_errorMessage = error; m_errorMessage = error;
}); });
connect(this, &PushoverFrontend::enabledChanged, [this](bool enabled) {
if (enabled) {
connectToService();
} else {
disconnectService();
}
});
} }
void PushoverFrontend::slotInitialize() void PushoverFrontend::slotInitialize()
{ {
emit initialisationFinished(true); emit initializeChanged(true);
}
void PushoverFrontend::setEnabled(bool enabled)
{
if (enabled == isEnabled()) {
return;
}
SnoreFrontend::setEnabled(enabled);
if (enabled) {
connectToService();
} else {
disconnectService();
}
} }
PluginSettingsWidget *PushoverFrontend::settingsWidget() PluginSettingsWidget *PushoverFrontend::settingsWidget()

View File

@ -35,8 +35,6 @@ public:
PushoverFrontend(); PushoverFrontend();
~PushoverFrontend() = default; ~PushoverFrontend() = default;
void setEnabled(bool enabled) override;
Snore::PluginSettingsWidget *settingsWidget() override; Snore::PluginSettingsWidget *settingsWidget() override;
void login(const QString &email, const QString &password, const QString &deviceName); void login(const QString &email, const QString &password, const QString &deviceName);

View File

@ -30,7 +30,13 @@ using namespace Snore;
SnarlNetworkFrontend::SnarlNetworkFrontend(): SnarlNetworkFrontend::SnarlNetworkFrontend():
parser(new Parser(this)) 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() SnarlNetworkFrontend::~SnarlNetworkFrontend()
@ -43,25 +49,11 @@ void SnarlNetworkFrontend::slotInitialize()
tcpServer = new QTcpServer(this); tcpServer = new QTcpServer(this);
if (!tcpServer->listen(QHostAddress::Any, port)) { if (!tcpServer->listen(QHostAddress::Any, port)) {
snoreDebug(SNORE_DEBUG) << "The port is already used"; snoreDebug(SNORE_DEBUG) << "The port is already used";
emit initialisationFinished(false); emit initializeChanged(false);
} else { } else {
std::cout << "The Snarl Network Protokoll is developed for Snarl <http://www.fullphat.net/>" << std::endl; std::cout << "The Snarl Network Protokoll is developed for Snarl <http://www.fullphat.net/>" << std::endl;
} }
emit initialisationFinished(true); emit initializeChanged(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);
}
} }
void SnarlNetworkFrontend::slotActionInvoked(Snore::Notification notification) void SnarlNetworkFrontend::slotActionInvoked(Snore::Notification notification)

View File

@ -38,8 +38,6 @@ public:
SnarlNetworkFrontend(); SnarlNetworkFrontend();
~SnarlNetworkFrontend(); ~SnarlNetworkFrontend();
void setEnabled(bool enabled) override;
public Q_SLOTS: public Q_SLOTS:
void slotInitialize() override; void slotInitialize() override;
void slotActionInvoked(Snore::Notification notification) override; void slotActionInvoked(Snore::Notification notification) override;

View File

@ -61,7 +61,7 @@ void NotifyMyAndroid::slotNotify(Notification notification)
void NotifyMyAndroid::slotInitialize() void NotifyMyAndroid::slotInitialize()
{ {
emit initialisationFinished(true); emit initializeChanged(true);
} }
PluginSettingsWidget *NotifyMyAndroid::settingsWidget() PluginSettingsWidget *NotifyMyAndroid::settingsWidget()

View File

@ -122,7 +122,7 @@ void Pushover::slotNotify(Notification notification)
void Pushover::slotInitialize() void Pushover::slotInitialize()
{ {
emit initialisationFinished(true); emit initializeChanged(true);
} }
PluginSettingsWidget *Pushover::settingsWidget() PluginSettingsWidget *Pushover::settingsWidget()

View File

@ -37,7 +37,7 @@ Sound::Sound():
void Sound::slotInitialize() void Sound::slotInitialize()
{ {
m_player->setVolume(settingsValue(QLatin1String("Volume")).toInt()); m_player->setVolume(settingsValue(QLatin1String("Volume")).toInt());
emit initialisationFinished(true); emit initializeChanged(true);
} }
PluginSettingsWidget *Sound::settingsWidget() PluginSettingsWidget *Sound::settingsWidget()

View File

@ -79,7 +79,7 @@ void Toasty::slotNotify(Notification notification)
void Toasty::slotInitialize() void Toasty::slotInitialize()
{ {
emit initialisationFinished(true); emit initializeChanged(true);
} }
PluginSettingsWidget *Toasty::settingsWidget() PluginSettingsWidget *Toasty::settingsWidget()