cleanup the frontend code

This commit is contained in:
Patrick von Reth 2015-04-18 13:58:10 +02:00
parent a60047587b
commit 2dcde7b37a
12 changed files with 42 additions and 42 deletions

View File

@ -33,7 +33,6 @@ NotificationData::NotificationData(const Snore::Application &application, const
int timeout, Notification::Prioritys priority):
m_id(m_idCount++),
m_timeout(timeout),
m_source(NULL),
m_application(application),
m_alert(alert),
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):
m_id(m_idCount++),
m_timeout(timeout),
m_source(NULL),
m_application(old.application()),
m_alert(old.alert()),
m_title(title),
@ -79,16 +77,6 @@ void NotificationData::setActionInvoked(const int &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)
{
m_closeReason = r;

View File

@ -41,9 +41,6 @@ public:
~NotificationData();
void setSource(class SnoreFrontend *source);
class SnoreFrontend *source() const;
void setActionInvoked(const Action &action);
void setActionInvoked(const int &actionID);
@ -57,7 +54,6 @@ private:
uint m_id;
uint m_updateID;
int m_timeout;
SnoreFrontend *m_source;
Application m_application;
Alert m_alert;
QString m_title;

View File

@ -189,6 +189,7 @@ bool SnoreBackend::deinitialize()
void SnoreBackend::startTimeout(Notification &notification)
{
if (thread() != QThread::currentThread()) {
snoreDebug(SNORE_WARNING) << "Plugin timeout in wrong thread.";
metaObject()->invokeMethod(this, "startTimeout", Qt::QueuedConnection, Q_ARG(Notification, notification));
return;
}

View File

@ -19,8 +19,7 @@
#include "snorefrontend.h"
#include "../snore.h"
namespace Snore
{
using namespace Snore;
SnoreFrontend::SnoreFrontend(const QString &name) :
SnorePlugin(name)
@ -33,4 +32,22 @@ SnoreFrontend::~SnoreFrontend()
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;
}

View File

@ -33,8 +33,13 @@ class SNORE_EXPORT SnoreFrontend: public SnorePlugin
public:
SnoreFrontend(const QString &name);
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;
};
}

View File

@ -59,13 +59,10 @@ Application SnoreCorePrivate::defaultApplication()
return m_defaultApp;
}
void SnoreCorePrivate::notificationActionInvoked(Notification notification) const
void SnoreCorePrivate::notificationActionInvoked(Notification notification)
{
Q_Q(const SnoreCore);
emit const_cast<SnoreCore *>(q)->actionInvoked(notification);
if (notification.data()->source()) {
notification.data()->source()->actionInvoked(notification);
}
Q_Q(SnoreCore);
emit q->actionInvoked(notification);
}
bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
@ -219,10 +216,6 @@ void SnoreCorePrivate::slotNotificationClosed(Notification n)
{
Q_Q(SnoreCore);
emit q->notificationClosed(n);
if (n.data()->source()) {
//TODO: drop source and use signal aswell
n.data()->source()->notificationClosed(n);
}
}
void SnoreCorePrivate::slotAboutToQuit()

View File

@ -49,7 +49,7 @@ public:
~SnoreCorePrivate();
Application defaultApplication();
void notificationActionInvoked(Notification notification) const;
void notificationActionInvoked(Notification notification);
bool setBackendIfAvailible(const QString &backend);

View File

@ -68,14 +68,14 @@ bool FreedesktopFrontend::deinitialize()
return false;
}
void FreedesktopFrontend::actionInvoked(Notification notification)
void FreedesktopFrontend::slotActionInvoked(Notification notification)
{
if (notification.actionInvoked().isValid()) {
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());
}
@ -124,7 +124,6 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
} else {
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) {
noti.addAction(Action(actions.at(i).toInt(), actions.at(i + 1)));
}

View File

@ -34,9 +34,6 @@ public:
virtual bool initialize() 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);
void CloseNotification(uint id);
@ -47,6 +44,10 @@ signals:
void NotificationClosed(uint id, uint reason);
void ActionInvoked(uint id, const QString &actionKey);
public slots:
void slotActionInvoked(Snore::Notification notification) override;
void slotNotificationClosed(Snore::Notification notification) override;
private:
Snore::Alert m_alert;
Snore::Icon m_icon;

View File

@ -116,7 +116,6 @@ void Parser::parse(Notification &sNotification, const QString &msg, QTcpSocket *
break;
}
sNotification = Notification(app, alert, title, text, icon, timeout);
sNotification.data()->setSource(snarl);
sNotification.hints().setPrivateValue(snarl, "clientSocket", client);
break;
}

View File

@ -62,13 +62,13 @@ bool SnarlNetworkFrontend::deinitialize()
return false;
}
void SnarlNetworkFrontend::actionInvoked(Snore::Notification notification)
void SnarlNetworkFrontend::slotActionInvoked(Snore::Notification notification)
{
snoreDebug(SNORE_DEBUG) << notification.closeReason();
callback(notification, "SNP/1.1/304/Notification acknowledged/");
}
void SnarlNetworkFrontend::notificationClosed(Snore::Notification notification)
void SnarlNetworkFrontend::slotNotificationClosed(Snore::Notification notification)
{
switch (notification.closeReason()) {
case Notification::TIMED_OUT:

View File

@ -40,8 +40,9 @@ public:
virtual bool initialize() override;
virtual bool deinitialize() override;
void actionInvoked(Snore::Notification notification) override;
void notificationClosed(Snore::Notification notification) override;
public slots:
void slotActionInvoked(Snore::Notification notification) override;
void slotNotificationClosed(Snore::Notification notification) override;
private slots:
void handleConnection();