From 5f2223669320e5114b89f7a19595c5fdc07048e1 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Tue, 21 Jan 2014 09:56:11 +0100 Subject: [PATCH] removed the horrible enum header --- src/core/notification/notification.cpp | 8 +-- src/core/notification/notification.h | 30 ++++++++--- src/core/notification/notification_p.cpp | 10 ++-- src/core/notification/notification_p.h | 13 +++-- src/core/notification/notificationenums.h | 51 ------------------- src/core/plugins/snorebackend.cpp | 8 +-- src/core/plugins/snorebackend.h | 4 +- src/core/snore.cpp | 2 +- src/core/snore.h | 2 +- src/plugins/backends/growl/growl.cpp | 10 ++-- src/plugins/backends/snarl/snarl.cpp | 16 +++--- .../backends/snoretoast/snoretoast.cpp | 8 +-- .../backends/trayicon/trayiconnotifer.cpp | 2 +- .../freedesktopnotificationfrontend.cpp | 9 ++-- .../frontends/snarlnetwork/snarlnetwork.cpp | 2 +- 15 files changed, 71 insertions(+), 104 deletions(-) delete mode 100644 src/core/notification/notificationenums.h diff --git a/src/core/notification/notification.cpp b/src/core/notification/notification.cpp index 5877fb6..0f3716e 100644 --- a/src/core/notification/notification.cpp +++ b/src/core/notification/notification.cpp @@ -37,13 +37,13 @@ Notification::Notification () : { } -Notification::Notification(const Application &application, const Alert &alert, const QString &title, const QString &text, const Icon &icon, int timeout, NotificationEnums::Prioritys::prioritys priority): +Notification::Notification(const Application &application, const Alert &alert, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority): d(new NotificationData(application,alert,title,text,icon,timeout,priority)) { } -Notification::Notification(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, NotificationEnums::Prioritys::prioritys priority): +Notification::Notification(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority): d(new NotificationData(old,title,text,icon,timeout,priority)) { } @@ -119,7 +119,7 @@ bool Notification::isSticky() const } -NotificationEnums::Prioritys::prioritys Notification::priority() const +Notification::Prioritys Notification::priority() const { return d->m_priority; } @@ -135,7 +135,7 @@ const QHash &Notification::actions() const return d->m_actions; } -const NotificationEnums::CloseReasons::closeReasons &Notification::closeReason(){ +const Notification::CloseReasons &Notification::closeReason(){ return d->m_closeReason; } diff --git a/src/core/notification/notification.h b/src/core/notification/notification.h index 1b03a10..72e5bea 100644 --- a/src/core/notification/notification.h +++ b/src/core/notification/notification.h @@ -21,7 +21,6 @@ #define NOTIFICATION_H #include "../snore_exports.h" #include "icon.h" -#include "notificationenums.h" #include "notificationaction.h" #include "../hint.h" #include "../application.h" @@ -46,6 +45,22 @@ class SNORE_EXPORT Notification { friend class NotificationData; public: + enum CloseReason + { + NONE = 0x0, + TIMED_OUT = 0x1, + DISMISSED = 0x2, + CLOSED = 0x4 + }; + Q_DECLARE_FLAGS(CloseReasons, CloseReason) + + enum Priority{ + LOW = -1, + NORMAL = 0, + HIGH = +1 + }; + Q_DECLARE_FLAGS(Prioritys, Priority) + Notification(); /** * Creates a new Notification. @@ -57,7 +72,7 @@ public: * @param timeout the timeout * @param priority the priority */ - explicit Notification(const Application &application,const Alert &alert,const QString &title,const QString &text,const Icon &icon,int timeout = defaultTimeout(), NotificationEnums::Prioritys::prioritys priority = NotificationEnums::Prioritys::NORMAL ); + explicit Notification(const Application &application,const Alert &alert,const QString &title,const QString &text,const Icon &icon,int timeout = defaultTimeout(), Notification::Prioritys priority = Notification::NORMAL ); /** * Creates and update Notification replacing an existing Notification @@ -68,7 +83,7 @@ public: * @param timeout the timeout * @param priority the piority */ - explicit Notification(const Notification &old,const QString &title,const QString &text,const Icon &icon,int timeout = defaultTimeout(), NotificationEnums::Prioritys::prioritys priority = NotificationEnums::Prioritys::NORMAL ); + explicit Notification(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout = defaultTimeout(), Snore::Notification::Prioritys priority = Notification::NORMAL ); /** * The copy constructor @@ -142,7 +157,7 @@ public: * Some backends support priorities to indicate the urgency of the Notification * @return the priority */ - NotificationEnums::Prioritys::prioritys priority() const; + Notification::Prioritys priority() const; /** * @@ -162,7 +177,7 @@ public: * * @return the close reason */ - const NotificationEnums::CloseReasons::closeReasons &closeReason(); + const Notification::CloseReasons &closeReason(); /** * @@ -224,9 +239,12 @@ private: }; } - Q_DECLARE_METATYPE(Snore::Notification) +Q_DECLARE_OPERATORS_FOR_FLAGS(Snore::Notification::CloseReasons) + +Q_DECLARE_OPERATORS_FOR_FLAGS(Snore::Notification::Prioritys) + QDataStream &operator<< ( QDataStream & stream, const Snore::Notification & noti ); inline QDebug operator<< ( QDebug debug, const Snore::Notification ¬i ) diff --git a/src/core/notification/notification_p.cpp b/src/core/notification/notification_p.cpp index 0a6d861..642484e 100644 --- a/src/core/notification/notification_p.cpp +++ b/src/core/notification/notification_p.cpp @@ -33,7 +33,7 @@ uint NotificationData::notificationCount = 0; uint NotificationData::m_idCount = 1; NotificationData::NotificationData (const Snore::Application &application, const Snore::Alert &alert, const QString &title, const QString &text, const Icon &icon, - int timeout, NotificationEnums::Prioritys::prioritys priority ): + int timeout, Notification::Prioritys priority ): m_id ( m_idCount++ ), m_timeout( timeout ), m_source( NULL), @@ -43,13 +43,13 @@ NotificationData::NotificationData (const Snore::Application &application, const m_text( text ), m_icon( icon ), m_priority(priority), - m_closeReason(NotificationEnums::CloseReasons::NONE) + m_closeReason(Notification::NONE) { notificationCount++; snoreDebug( SNORE_DEBUG ) << "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; } -Snore::NotificationData::NotificationData(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, NotificationEnums::Prioritys::prioritys priority): +Snore::NotificationData::NotificationData(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority): m_id ( old.id() ), m_timeout( timeout ), m_source( NULL), @@ -59,7 +59,7 @@ Snore::NotificationData::NotificationData(const Notification &old, const QString m_text( text ), m_icon( icon ), m_priority(priority), - m_closeReason(NotificationEnums::CloseReasons::NONE), + m_closeReason(Notification::NONE), m_toReplace(old) { notificationCount++; @@ -97,7 +97,7 @@ SnoreFrontend *NotificationData::source() const return m_source; } -void NotificationData::setCloseReason(const NotificationEnums::CloseReasons::closeReasons &r) +void NotificationData::setCloseReason(Snore::Notification::CloseReasons r) { m_closeReason = r; } diff --git a/src/core/notification/notification_p.h b/src/core/notification/notification_p.h index 84828d3..7c1570f 100644 --- a/src/core/notification/notification_p.h +++ b/src/core/notification/notification_p.h @@ -23,7 +23,6 @@ #include "icon.h" #include "notification.h" -#include "notificationenums.h" #include "../hint.h" #include @@ -38,9 +37,9 @@ class SNORE_EXPORT NotificationData : public QSharedData friend class Notification; public: NotificationData ( const Application &application,const Alert &alert,const QString &title,const QString &text,const Icon &icon, - int timeout,NotificationEnums::Prioritys::prioritys priority ); + int timeout,Notification::Prioritys priority ); - NotificationData(const Notification &old,const QString &title,const QString &text,const Icon &icon,int timeout, NotificationEnums::Prioritys::prioritys priority); + NotificationData(const Notification &old,const QString &title,const QString &text,const Icon &icon,int timeout, Notification::Prioritys priority); ~NotificationData(); @@ -52,7 +51,7 @@ public: void setActionInvoked( const int &actionID); - void setCloseReason(const NotificationEnums::CloseReasons::closeReasons &r); + void setCloseReason(Notification::CloseReasons r); QTimer *timeoutTimer(); @@ -62,14 +61,14 @@ private: uint m_id; uint m_updateID; int m_timeout; - SnoreFrontend *m_source; + SnoreFrontend *m_source; Application m_application; Alert m_alert; QString m_title; QString m_text; Icon m_icon; - NotificationEnums::Prioritys::prioritys m_priority; - NotificationEnums::CloseReasons::closeReasons m_closeReason; + Notification::Prioritys m_priority; + Notification::CloseReasons m_closeReason; Action m_actionInvoked; QHash m_actions; Hint m_hints; diff --git a/src/core/notification/notificationenums.h b/src/core/notification/notificationenums.h deleted file mode 100644 index b70b3d0..0000000 --- a/src/core/notification/notificationenums.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - 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 NOTIFICATIONENUMS_H -#define NOTIFICATIONENUMS_H - -#include - -namespace Snore{ -namespace NotificationEnums{ - -namespace Prioritys{ -enum priority{ - LOW = -1, - NORMAL = 0, - HIGH = +1 -}; -Q_DECLARE_FLAGS(prioritys, priority) -Q_DECLARE_OPERATORS_FOR_FLAGS(prioritys) -} -namespace CloseReasons{ -enum closeReason -{ - NONE = 0, - TIMED_OUT, - DISMISSED, - CLOSED -}; -Q_DECLARE_FLAGS(closeReasons, closeReason) -Q_DECLARE_OPERATORS_FOR_FLAGS(closeReasons) -} -} -} -#endif // NOTIFICATIONENUMS_H diff --git a/src/core/plugins/snorebackend.cpp b/src/core/plugins/snorebackend.cpp index 46181c1..fc9f4ea 100644 --- a/src/core/plugins/snorebackend.cpp +++ b/src/core/plugins/snorebackend.cpp @@ -67,7 +67,7 @@ bool SnoreBackend::initialize( SnoreCore *snore ) } -void SnoreBackend::requestCloseNotification ( Notification notification,NotificationEnums::CloseReasons::closeReasons reason ) +void SnoreBackend::requestCloseNotification (Notification notification, Notification::CloseReasons reason ) { if(canCloseNotification()) { @@ -75,7 +75,7 @@ void SnoreBackend::requestCloseNotification ( Notification notification,Notifica } } -void SnoreBackend::closeNotification(Notification n, NotificationEnums::CloseReasons::closeReasons reason) +void SnoreBackend::closeNotification(Notification n, Notification::CloseReasons reason) { if(!n.isValid()) { @@ -156,7 +156,7 @@ bool SnoreBackend::deinitialize() { foreach(Notification n,m_activeNotifications) { - requestCloseNotification(n, NotificationEnums::CloseReasons::DISMISSED); + requestCloseNotification(n, Notification::DISMISSED); } @@ -200,6 +200,6 @@ void SnoreBackend::notificationTimedOut() if(n.isValid()) { snoreDebug( SNORE_DEBUG ) << n; - snore()->requestCloseNotification(n,NotificationEnums::CloseReasons::TIMED_OUT); + snore()->requestCloseNotification(n,Notification::TIMED_OUT); } } diff --git a/src/core/plugins/snorebackend.h b/src/core/plugins/snorebackend.h index 0c75df1..b69ca58 100644 --- a/src/core/plugins/snorebackend.h +++ b/src/core/plugins/snorebackend.h @@ -39,7 +39,7 @@ public: virtual bool initialize(SnoreCore *snore); virtual bool deinitialize(); - void requestCloseNotification( Snore::Notification notification,NotificationEnums::CloseReasons::closeReasons reason ); + void requestCloseNotification( Snore::Notification notification,Notification::CloseReasons reason ); Snore::Notification getActiveNotificationByID(uint id); @@ -61,7 +61,7 @@ private slots: protected: void startTimeout(Notification ¬ification); - void closeNotification(Snore::Notification,Snore::NotificationEnums::CloseReasons::closeReasons); + void closeNotification(Snore::Notification,Snore::Notification::CloseReasons); void setSupportsRichtext(bool b); private: diff --git a/src/core/snore.cpp b/src/core/snore.cpp index 418eac6..e5ec47a 100644 --- a/src/core/snore.cpp +++ b/src/core/snore.cpp @@ -251,7 +251,7 @@ Notification SnoreCore::getActiveNotificationByID(uint id) return d->m_notificationBackend->getActiveNotificationByID(id); } -void SnoreCore::requestCloseNotification(Notification n, NotificationEnums::CloseReasons::closeReasons r) +void SnoreCore::requestCloseNotification(Notification n, Notification::CloseReasons r) { Q_D(SnoreCore); d->m_notificationBackend->requestCloseNotification(n,r); diff --git a/src/core/snore.h b/src/core/snore.h index 262ecb6..c2e6c22 100644 --- a/src/core/snore.h +++ b/src/core/snore.h @@ -158,7 +158,7 @@ public: * Try to close a Notification if the backend supports the action. * @see SnoreBackend::canCloseNotification */ - void requestCloseNotification(Notification,NotificationEnums::CloseReasons::closeReasons); + void requestCloseNotification(Notification,Notification::CloseReasons); /** * diff --git a/src/plugins/backends/growl/growl.cpp b/src/plugins/backends/growl/growl.cpp index f6befe1..f230a52 100644 --- a/src/plugins/backends/growl/growl.cpp +++ b/src/plugins/backends/growl/growl.cpp @@ -49,7 +49,7 @@ bool Growl::initialize(SnoreCore *snore) { const Application &app = snore->d()->defaultApplication(); m_defaultGNTP = new gntp(app.name().toUtf8().constData(), app.icon().localUrl().toUtf8().constData()); - + std::vector alerts; alerts.push_back(app.alerts().begin()->name().toUtf8().constData()); try @@ -144,18 +144,18 @@ void Growl::gntpCallback(const int &id,const std::string &reason,const std::stri { // snoreDebug( SNORE_DEBUG ) << id << QString(reason.c_str()) << QString(data.c_str()); Notification n = s_instance->snore()->getActiveNotificationByID(id); - NotificationEnums::CloseReasons::closeReasons r = NotificationEnums::CloseReasons::NONE; + Notification::CloseReasons r = Notification::NONE; if(reason == "TIMEDOUT") { - r = NotificationEnums::CloseReasons::TIMED_OUT; + r = Notification::TIMED_OUT; } else if(reason == "CLOSED") { - r = NotificationEnums::CloseReasons::DISMISSED; + r = Notification::DISMISSED; } else if(reason == "CLICK") { - r = NotificationEnums::CloseReasons::CLOSED; + r = Notification::CLOSED; s_instance->snore()->d()->notificationActionInvoked(n); } s_instance->closeNotification(n,r); diff --git a/src/plugins/backends/snarl/snarl.cpp b/src/plugins/backends/snarl/snarl.cpp index 7868ef7..7c7c6c6 100644 --- a/src/plugins/backends/snarl/snarl.cpp +++ b/src/plugins/backends/snarl/snarl.cpp @@ -71,13 +71,13 @@ public: notification = m_snarl->snore()->getActiveNotificationByID(m_snarl->m_idMap[ msg->lParam]); } - NotificationEnums::CloseReasons::closeReasons reason = NotificationEnums::CloseReasons::NONE; + Notification::CloseReasons reason = Notification::NONE; switch(action){ case SnarlEnums::CallbackInvoked: - reason = NotificationEnums::CloseReasons::CLOSED; + reason = Notification::CLOSED; break; case SnarlEnums::NotifyAction: - reason = NotificationEnums::CloseReasons::CLOSED; + reason = Notification::CLOSED; if(notification.isValid()) { notification.data()->setActionInvoked(data); @@ -85,10 +85,10 @@ public: } break; case SnarlEnums::CallbackClosed: - reason = NotificationEnums::CloseReasons::DISMISSED; + reason = Notification::DISMISSED; break; case SnarlEnums::CallbackTimedOut: - reason = NotificationEnums::CloseReasons::TIMED_OUT; + reason = Notification::TIMED_OUT; break; //away stuff case SnarlEnums::SnarlUserAway: @@ -209,13 +209,13 @@ void SnarlBackend::slotNotify(Notification notification){ Snarl::V42::SnarlEnums::MessagePriority priority = Snarl::V42::SnarlEnums::PriorityUndefined; switch(notification.priority()) { - case NotificationEnums::Prioritys::LOW: + case Notification::LOW: priority = Snarl::V42::SnarlEnums::PriorityLow; break; - case NotificationEnums::Prioritys::NORMAL: + case Notification::NORMAL: priority = Snarl::V42::SnarlEnums::PriorityNormal; break; - case NotificationEnums::Prioritys::HIGH: + case Notification::HIGH: priority = Snarl::V42::SnarlEnums::PriorityHigh; break; } diff --git a/src/plugins/backends/snoretoast/snoretoast.cpp b/src/plugins/backends/snoretoast/snoretoast.cpp index fed7ad9..c19c6a0 100644 --- a/src/plugins/backends/snoretoast/snoretoast.cpp +++ b/src/plugins/backends/snoretoast/snoretoast.cpp @@ -100,22 +100,22 @@ void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus) return; } - NotificationEnums::CloseReasons::closeReason reason = NotificationEnums::CloseReasons::CLOSED; + Notification::CloseReasons reason = Notification::CLOSED; switch(code) { case 0: - reason = NotificationEnums::CloseReasons::CLOSED; + reason = Notification::CLOSED; snore()->d()->notificationActionInvoked(n); break; case 1: //hidden; break; case 2: - reason = NotificationEnums::CloseReasons::DISMISSED; + reason = Notification::DISMISSED; break; case 3: - reason = NotificationEnums::CloseReasons::TIMED_OUT; + reason = Notification::TIMED_OUT; break; case -1: //failed diff --git a/src/plugins/backends/trayicon/trayiconnotifer.cpp b/src/plugins/backends/trayicon/trayiconnotifer.cpp index 19fda10..bacc229 100644 --- a/src/plugins/backends/trayicon/trayiconnotifer.cpp +++ b/src/plugins/backends/trayicon/trayiconnotifer.cpp @@ -87,7 +87,7 @@ void TrayIconNotifer::actionInvoked() if(n.isValid()) { snore()->d()->notificationActionInvoked(n); - closeNotification(n,NotificationEnums::CloseReasons::CLOSED); + closeNotification(n,Notification::CLOSED); m_currentlyDisplaying = false; displayNotification(); } diff --git a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp index 433ba82..18a6fd9 100644 --- a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp +++ b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp @@ -93,7 +93,7 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id, { Icon icon; Application app; - NotificationEnums::Prioritys::prioritys priotity = NotificationEnums::Prioritys::NORMAL; + Notification::Prioritys priotity = Notification::NORMAL; if(hints.contains("image_data")) { @@ -123,8 +123,9 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id, app = snore()->aplications()[app_name]; } - if (hints.contains("urgency")) { - priotity = NotificationEnums::Prioritys::prioritys(hints["urgency"].toInt()-1); + if (hints.contains("urgency")) + { + priotity = Notification::Prioritys(hints["urgency"].toInt()-1); } Notification noti; @@ -153,7 +154,7 @@ void FreedesktopFrontend::CloseNotification(uint id) Notification noti = snore()->getActiveNotificationByID(id); if(noti.isValid()) { - snore()->requestCloseNotification(noti,NotificationEnums::CloseReasons::TIMED_OUT); + snore()->requestCloseNotification(noti,Notification::TIMED_OUT); } } diff --git a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp index 5e76763..3f52f9f 100644 --- a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp +++ b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp @@ -84,7 +84,7 @@ void SnarlNetworkFrontend::actionInvoked(Snore::Notification notification) } void SnarlNetworkFrontend::notificationClosed(Snore::Notification notification) { - if(notification.closeReason() == NotificationEnums::CloseReasons::TIMED_OUT) + if(notification.closeReason() == Notification::TIMED_OUT) { callback(notification, "SNP/1.1/303/Notification timed out/"); }