refactored notification

This commit is contained in:
Patrick von Reth 2014-01-11 17:44:47 +01:00
parent 38242655f0
commit a43234f115
7 changed files with 106 additions and 43 deletions

View File

@ -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

View File

@ -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
)

View File

@ -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::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 &noti )
{
stream << "Title: " << noti.title() << " Text: " << noti.text() << " ID: " << noti.id() ;

View File

@ -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:

View File

@ -0,0 +1,68 @@
/*
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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 <http://www.gnu.org/licenses/>.
*/
#include "notification/notification_p.h"
#include "notification/icon.h"
#include "../hint.h"
#include <QSharedData>
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];
}

View File

@ -1,43 +1,45 @@
/*
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 2013-2014 Patrick von Reth <vonreth@kde.org>
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 <http://www.gnu.org/licenses/>.
*/
#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 <QSharedData>
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;

View File

@ -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 <QtCore>
#include <QtDebug>
@ -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;