From a43234f11536351a9a477d0efa9d612d222197fd Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Sat, 11 Jan 2014 17:44:47 +0100 Subject: [PATCH] refactored notification --- src/core/CMakeLists.txt | 1 + src/core/notification/CMakeLists.txt | 2 + src/core/notification/notification.cpp | 19 ++----- src/core/notification/notification.h | 4 +- src/core/notification/notification_p.cpp | 68 ++++++++++++++++++++++++ src/core/notification/notification_p.h | 52 +++++++++--------- src/plugins/backends/snarl/snarl.cpp | 3 +- 7 files changed, 106 insertions(+), 43 deletions(-) create mode 100644 src/core/notification/notification_p.cpp diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index d1c347e..2327e27 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -23,6 +23,7 @@ set ( SnoreNotify_SRCS ${SnoreNotify_SRCS} set ( SnoreNotify_HDR ${SnoreNotify_HDR} snore.h + snore_p.h application.h hint.h snore_exports.h diff --git a/src/core/notification/CMakeLists.txt b/src/core/notification/CMakeLists.txt index 2a6d29e..5be5b6b 100644 --- a/src/core/notification/CMakeLists.txt +++ b/src/core/notification/CMakeLists.txt @@ -1,10 +1,12 @@ set ( SnoreNotify_SRCS ${SnoreNotify_SRCS} notification/notification.cpp + notification/notification_p.cpp notification/icon.cpp PARENT_SCOPE) set ( Notification_HDR notification.h + notification_p.h icon.h notificationenums.h ) diff --git a/src/core/notification/notification.cpp b/src/core/notification/notification.cpp index 52af01a..1491083 100644 --- a/src/core/notification/notification.cpp +++ b/src/core/notification/notification.cpp @@ -29,10 +29,6 @@ using namespace Snore; int Notification::DefaultTimeout = 10; -uint NotificationData::notificationCount = 0; - -uint NotificationData::m_idCount = 1; - int NotificationData::notificationMetaID = qRegisterMetaType(); Notification::Notification () : @@ -90,16 +86,6 @@ const Notification::Action *Notification::actionInvoked() const return d->m_actionInvoked; } -void Notification::setActionInvoked ( Action *action ) -{ - d->m_actionInvoked = action; -} - -void Notification::setActionInvoked ( const int &id) -{ - d->m_actionInvoked = d->m_actions[id]; -} - void Notification::setSource(SnoreFrontend *source){ d->m_source = source; } @@ -179,6 +165,11 @@ bool Notification::isValid() const return d; } +NotificationData *Notification::data() +{ + return d.data(); +} + QDataStream &operator<< ( QDataStream &stream, const Notification ¬i ) { stream << "Title: " << noti.title() << " Text: " << noti.text() << " ID: " << noti.id() ; diff --git a/src/core/notification/notification.h b/src/core/notification/notification.h index f35ae12..615db1d 100644 --- a/src/core/notification/notification.h +++ b/src/core/notification/notification.h @@ -84,9 +84,7 @@ public: bool isValid() const; - //protected://TODO::make only accesable from a backend - void setActionInvoked ( Action *action ); - void setActionInvoked ( const int &actionID); + NotificationData *data(); private: diff --git a/src/core/notification/notification_p.cpp b/src/core/notification/notification_p.cpp new file mode 100644 index 0000000..22ba140 --- /dev/null +++ b/src/core/notification/notification_p.cpp @@ -0,0 +1,68 @@ +/* + SnoreNotify is a Notification Framework based on Qt + Copyright (C) 2013-2014 Patrick von Reth + + + SnoreNotify is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SnoreNotify is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with SnoreNotify. If not, see . +*/ + + + +#include "notification/notification_p.h" +#include "notification/icon.h" +#include "../hint.h" + +#include + +using namespace Snore; + +uint NotificationData::notificationCount = 0; + +uint NotificationData::m_idCount = 1; + +NotificationData::NotificationData ( const QString &application,const QString &alert,const QString &title,const QString &text,const Icon &icon, + int timeout,NotificationEnums::Prioritys::prioritys priority ): + m_id ( m_idCount++ ), + m_updateID(0), + m_timeout ( timeout ), + m_source ( NULL), + m_application ( application ), + m_alert ( alert ), + m_title ( title ), + m_text ( text ), + m_icon ( icon ), + m_priority(priority), + m_closeReason(NotificationEnums::CloseReasons::NONE), + m_actionInvoked( NULL ) +{ + notificationCount++; + qDebug()<< "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; +} + +NotificationData::~NotificationData() +{ + notificationCount--; + qDebug() << "Deleting Notification: ActiveNotifications" << notificationCount << "id" << m_id; +} + + +void NotificationData::setActionInvoked ( Notification::Action *action ) +{ + m_actionInvoked = action; +} + +void NotificationData::setActionInvoked ( const int &id) +{ + m_actionInvoked = m_actions[id]; +} diff --git a/src/core/notification/notification_p.h b/src/core/notification/notification_p.h index 0940ca8..9774bbb 100644 --- a/src/core/notification/notification_p.h +++ b/src/core/notification/notification_p.h @@ -1,43 +1,45 @@ +/* + SnoreNotify is a Notification Framework based on Qt + Copyright (C) 2013-2014 Patrick von Reth + + + SnoreNotify is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SnoreNotify is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with SnoreNotify. If not, see . +*/ + #ifndef NOTIFICATIONDATA_H #define NOTIFICATIONDATA_H -#include "notification/icon.h" -#include "notification/notificationenums.h" +#include "icon.h" +#include "notification.h" +#include "notificationenums.h" #include "../hint.h" #include namespace Snore{ -class NotificationData : public QSharedData +class SNORE_EXPORT NotificationData : public QSharedData { public: NotificationData ( const QString &application,const QString &alert,const QString &title,const QString &text,const Icon &icon, - int timeout,NotificationEnums::Prioritys::prioritys priority ): - m_id ( m_idCount++ ), - m_updateID(0), - m_timeout ( timeout ), - m_source ( NULL), - m_application ( application ), - m_alert ( alert ), - m_title ( title ), - m_text ( text ), - m_icon ( icon ), - m_priority(priority), - m_closeReason(NotificationEnums::CloseReasons::NONE), - m_actionInvoked( NULL ) - { - notificationCount++; - qDebug()<< "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; - } + int timeout,NotificationEnums::Prioritys::prioritys priority ); - ~NotificationData() - { - notificationCount--; - qDebug() << "Deleting Notification: ActiveNotifications" << notificationCount << "id" << m_id; - } + ~NotificationData(); + void setActionInvoked ( Notification::Action *action ); + void setActionInvoked ( const int &actionID); uint m_id; diff --git a/src/plugins/backends/snarl/snarl.cpp b/src/plugins/backends/snarl/snarl.cpp index 0772fa0..31e4352 100644 --- a/src/plugins/backends/snarl/snarl.cpp +++ b/src/plugins/backends/snarl/snarl.cpp @@ -23,6 +23,7 @@ #include "core/snore_p.h" #include "core/plugins/plugins.h" #include "core/plugins/snorebackend.h" +#include "core/notification/notification_p.h" #include #include @@ -88,7 +89,7 @@ public: reason = NotificationEnums::CloseReasons::CLOSED; if(notification.isValid()) { - notification.setActionInvoked(data); + notification.data()->setActionInvoked(data); m_snarl->snore()->d()->notificationActionInvoked(notification); } break;