cleanup the frontend code
This commit is contained in:
parent
a60047587b
commit
2dcde7b37a
|
@ -33,7 +33,6 @@ NotificationData::NotificationData(const Snore::Application &application, const
|
||||||
int timeout, Notification::Prioritys priority):
|
int timeout, Notification::Prioritys priority):
|
||||||
m_id(m_idCount++),
|
m_id(m_idCount++),
|
||||||
m_timeout(timeout),
|
m_timeout(timeout),
|
||||||
m_source(NULL),
|
|
||||||
m_application(application),
|
m_application(application),
|
||||||
m_alert(alert),
|
m_alert(alert),
|
||||||
m_title(title),
|
m_title(title),
|
||||||
|
@ -49,7 +48,6 @@ NotificationData::NotificationData(const Snore::Application &application, const
|
||||||
Snore::NotificationData::NotificationData(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority):
|
Snore::NotificationData::NotificationData(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority):
|
||||||
m_id(m_idCount++),
|
m_id(m_idCount++),
|
||||||
m_timeout(timeout),
|
m_timeout(timeout),
|
||||||
m_source(NULL),
|
|
||||||
m_application(old.application()),
|
m_application(old.application()),
|
||||||
m_alert(old.alert()),
|
m_alert(old.alert()),
|
||||||
m_title(title),
|
m_title(title),
|
||||||
|
@ -79,16 +77,6 @@ void NotificationData::setActionInvoked(const int &id)
|
||||||
m_actionInvoked = m_actions[id];
|
m_actionInvoked = m_actions[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationData::setSource(SnoreFrontend *source)
|
|
||||||
{
|
|
||||||
m_source = source;
|
|
||||||
}
|
|
||||||
|
|
||||||
SnoreFrontend *NotificationData::source() const
|
|
||||||
{
|
|
||||||
return m_source;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotificationData::setCloseReason(Snore::Notification::CloseReasons r)
|
void NotificationData::setCloseReason(Snore::Notification::CloseReasons r)
|
||||||
{
|
{
|
||||||
m_closeReason = r;
|
m_closeReason = r;
|
||||||
|
|
|
@ -41,9 +41,6 @@ public:
|
||||||
|
|
||||||
~NotificationData();
|
~NotificationData();
|
||||||
|
|
||||||
void setSource(class SnoreFrontend *source);
|
|
||||||
class SnoreFrontend *source() const;
|
|
||||||
|
|
||||||
void setActionInvoked(const Action &action);
|
void setActionInvoked(const Action &action);
|
||||||
void setActionInvoked(const int &actionID);
|
void setActionInvoked(const int &actionID);
|
||||||
|
|
||||||
|
@ -57,7 +54,6 @@ private:
|
||||||
uint m_id;
|
uint m_id;
|
||||||
uint m_updateID;
|
uint m_updateID;
|
||||||
int m_timeout;
|
int m_timeout;
|
||||||
SnoreFrontend *m_source;
|
|
||||||
Application m_application;
|
Application m_application;
|
||||||
Alert m_alert;
|
Alert m_alert;
|
||||||
QString m_title;
|
QString m_title;
|
||||||
|
|
|
@ -189,6 +189,7 @@ bool SnoreBackend::deinitialize()
|
||||||
void SnoreBackend::startTimeout(Notification ¬ification)
|
void SnoreBackend::startTimeout(Notification ¬ification)
|
||||||
{
|
{
|
||||||
if (thread() != QThread::currentThread()) {
|
if (thread() != QThread::currentThread()) {
|
||||||
|
snoreDebug(SNORE_WARNING) << "Plugin timeout in wrong thread.";
|
||||||
metaObject()->invokeMethod(this, "startTimeout", Qt::QueuedConnection, Q_ARG(Notification, notification));
|
metaObject()->invokeMethod(this, "startTimeout", Qt::QueuedConnection, Q_ARG(Notification, notification));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
#include "snorefrontend.h"
|
#include "snorefrontend.h"
|
||||||
#include "../snore.h"
|
#include "../snore.h"
|
||||||
|
|
||||||
namespace Snore
|
using namespace Snore;
|
||||||
{
|
|
||||||
|
|
||||||
SnoreFrontend::SnoreFrontend(const QString &name) :
|
SnoreFrontend::SnoreFrontend(const QString &name) :
|
||||||
SnorePlugin(name)
|
SnorePlugin(name)
|
||||||
|
@ -33,4 +32,22 @@ SnoreFrontend::~SnoreFrontend()
|
||||||
snoreDebug(SNORE_DEBUG) << "Deleting" << name();
|
snoreDebug(SNORE_DEBUG) << "Deleting" << name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SnoreFrontend::initialize()
|
||||||
|
{
|
||||||
|
if (!SnorePlugin::initialize()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
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()) {
|
||||||
|
disconnect(&SnoreCore::instance(), &SnoreCore::notificationClosed, this, &SnoreFrontend::slotNotificationClosed);
|
||||||
|
disconnect(&SnoreCore::instance(), &SnoreCore::actionInvoked, this, &SnoreFrontend::slotActionInvoked);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,13 @@ class SNORE_EXPORT SnoreFrontend: public SnorePlugin
|
||||||
public:
|
public:
|
||||||
SnoreFrontend(const QString &name);
|
SnoreFrontend(const QString &name);
|
||||||
virtual ~SnoreFrontend();
|
virtual ~SnoreFrontend();
|
||||||
virtual void actionInvoked(Snore::Notification notification) = 0;
|
|
||||||
virtual void notificationClosed(Snore::Notification notification) = 0;
|
virtual bool initialize() override;
|
||||||
|
virtual bool deinitialize() override;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void slotActionInvoked(Snore::Notification notification) = 0;
|
||||||
|
virtual void slotNotificationClosed(Snore::Notification notification) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,13 +59,10 @@ Application SnoreCorePrivate::defaultApplication()
|
||||||
return m_defaultApp;
|
return m_defaultApp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnoreCorePrivate::notificationActionInvoked(Notification notification) const
|
void SnoreCorePrivate::notificationActionInvoked(Notification notification)
|
||||||
{
|
{
|
||||||
Q_Q(const SnoreCore);
|
Q_Q(SnoreCore);
|
||||||
emit const_cast<SnoreCore *>(q)->actionInvoked(notification);
|
emit q->actionInvoked(notification);
|
||||||
if (notification.data()->source()) {
|
|
||||||
notification.data()->source()->actionInvoked(notification);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
|
bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
|
||||||
|
@ -219,10 +216,6 @@ void SnoreCorePrivate::slotNotificationClosed(Notification n)
|
||||||
{
|
{
|
||||||
Q_Q(SnoreCore);
|
Q_Q(SnoreCore);
|
||||||
emit q->notificationClosed(n);
|
emit q->notificationClosed(n);
|
||||||
if (n.data()->source()) {
|
|
||||||
//TODO: drop source and use signal aswell
|
|
||||||
n.data()->source()->notificationClosed(n);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnoreCorePrivate::slotAboutToQuit()
|
void SnoreCorePrivate::slotAboutToQuit()
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
~SnoreCorePrivate();
|
~SnoreCorePrivate();
|
||||||
Application defaultApplication();
|
Application defaultApplication();
|
||||||
|
|
||||||
void notificationActionInvoked(Notification notification) const;
|
void notificationActionInvoked(Notification notification);
|
||||||
|
|
||||||
bool setBackendIfAvailible(const QString &backend);
|
bool setBackendIfAvailible(const QString &backend);
|
||||||
|
|
||||||
|
|
|
@ -68,14 +68,14 @@ bool FreedesktopFrontend::deinitialize()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreedesktopFrontend::actionInvoked(Notification notification)
|
void FreedesktopFrontend::slotActionInvoked(Notification notification)
|
||||||
{
|
{
|
||||||
if (notification.actionInvoked().isValid()) {
|
if (notification.actionInvoked().isValid()) {
|
||||||
emit ActionInvoked(notification.id(), QString::number(notification.actionInvoked().id()));
|
emit ActionInvoked(notification.id(), QString::number(notification.actionInvoked().id()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreedesktopFrontend::notificationClosed(Notification notification)
|
void FreedesktopFrontend::slotNotificationClosed(Notification notification)
|
||||||
{
|
{
|
||||||
emit NotificationClosed(notification.id(), notification.closeReason());
|
emit NotificationClosed(notification.id(), notification.closeReason());
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,6 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
|
||||||
} else {
|
} else {
|
||||||
noti = Notification(app, *app.alerts().begin(), summary, body, icon, timeout == -1 ? Notification::defaultTimeout() : timeout / 1000, priotity);
|
noti = Notification(app, *app.alerts().begin(), summary, body, icon, timeout == -1 ? Notification::defaultTimeout() : timeout / 1000, priotity);
|
||||||
}
|
}
|
||||||
noti.data()->setSource(this);
|
|
||||||
for (int i = 0; i < actions.length(); i += 2) {
|
for (int i = 0; i < actions.length(); i += 2) {
|
||||||
noti.addAction(Action(actions.at(i).toInt(), actions.at(i + 1)));
|
noti.addAction(Action(actions.at(i).toInt(), actions.at(i + 1)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,6 @@ public:
|
||||||
virtual bool initialize() override;
|
virtual bool initialize() override;
|
||||||
virtual bool deinitialize() override;
|
virtual bool deinitialize() override;
|
||||||
|
|
||||||
void actionInvoked(Snore::Notification notification) override;
|
|
||||||
void notificationClosed(Snore::Notification notification) 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);
|
||||||
|
|
||||||
|
@ -47,6 +44,10 @@ signals:
|
||||||
void NotificationClosed(uint id, uint reason);
|
void NotificationClosed(uint id, uint reason);
|
||||||
void ActionInvoked(uint id, const QString &actionKey);
|
void ActionInvoked(uint id, const QString &actionKey);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void slotActionInvoked(Snore::Notification notification) override;
|
||||||
|
void slotNotificationClosed(Snore::Notification notification) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Snore::Alert m_alert;
|
Snore::Alert m_alert;
|
||||||
Snore::Icon m_icon;
|
Snore::Icon m_icon;
|
||||||
|
|
|
@ -116,7 +116,6 @@ void Parser::parse(Notification &sNotification, const QString &msg, QTcpSocket *
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sNotification = Notification(app, alert, title, text, icon, timeout);
|
sNotification = Notification(app, alert, title, text, icon, timeout);
|
||||||
sNotification.data()->setSource(snarl);
|
|
||||||
sNotification.hints().setPrivateValue(snarl, "clientSocket", client);
|
sNotification.hints().setPrivateValue(snarl, "clientSocket", client);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,13 +62,13 @@ bool SnarlNetworkFrontend::deinitialize()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnarlNetworkFrontend::actionInvoked(Snore::Notification notification)
|
void SnarlNetworkFrontend::slotActionInvoked(Snore::Notification notification)
|
||||||
{
|
{
|
||||||
snoreDebug(SNORE_DEBUG) << notification.closeReason();
|
snoreDebug(SNORE_DEBUG) << notification.closeReason();
|
||||||
callback(notification, "SNP/1.1/304/Notification acknowledged/");
|
callback(notification, "SNP/1.1/304/Notification acknowledged/");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnarlNetworkFrontend::notificationClosed(Snore::Notification notification)
|
void SnarlNetworkFrontend::slotNotificationClosed(Snore::Notification notification)
|
||||||
{
|
{
|
||||||
switch (notification.closeReason()) {
|
switch (notification.closeReason()) {
|
||||||
case Notification::TIMED_OUT:
|
case Notification::TIMED_OUT:
|
||||||
|
|
|
@ -40,8 +40,9 @@ public:
|
||||||
virtual bool initialize() override;
|
virtual bool initialize() override;
|
||||||
virtual bool deinitialize() override;
|
virtual bool deinitialize() override;
|
||||||
|
|
||||||
void actionInvoked(Snore::Notification notification) override;
|
public slots:
|
||||||
void notificationClosed(Snore::Notification notification) override;
|
void slotActionInvoked(Snore::Notification notification) override;
|
||||||
|
void slotNotificationClosed(Snore::Notification notification) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleConnection();
|
void handleConnection();
|
||||||
|
|
Loading…
Reference in New Issue