moved action to its own class

This commit is contained in:
Patrick von Reth 2014-01-14 10:22:07 +01:00
parent 6d5b7a7b76
commit a6138dc85b
10 changed files with 120 additions and 69 deletions

View File

@ -1,6 +1,7 @@
set ( SnoreNotify_SRCS ${SnoreNotify_SRCS}
notification/notification.cpp
notification/notification_p.cpp
notification/notificationaction.cpp
notification/icon.cpp
notification/icon_p.cpp
PARENT_SCOPE)
@ -8,6 +9,7 @@ set ( SnoreNotify_SRCS ${SnoreNotify_SRCS}
set ( Notification_HDR
notification.h
notification_p.h
notificationaction.h
icon.h
notificationenums.h
)

View File

@ -31,40 +31,6 @@ int Notification::m_defaultTimeout = 10;
int NotificationData::notificationMetaID = qRegisterMetaType<Notification>();
Notification::Action::Action():
m_id(-1)
{
}
Notification::Action::Action(int id, QString name):
m_id(id),
m_name(name)
{
}
Notification::Action::Action(const Notification::Action &other):
m_id(other.id()),
m_name(other.name())
{
}
QString Notification::Action::name() const
{
return m_name;
}
bool Notification::Action::isValid() const
{
return m_name.isNull();
}
int Notification::Action::id() const
{
return m_id;
}
Notification::Notification () :
d(NULL)
@ -117,7 +83,7 @@ const uint &Notification::updateID() const
return d->m_updateID;
}
const Notification::Action &Notification::actionInvoked() const
const Action &Notification::actionInvoked() const
{
return d->m_actionInvoked;
}
@ -157,13 +123,13 @@ const NotificationEnums::Prioritys::prioritys &Notification::priority() const
return d->m_priority;
}
void Notification::addAction(const Notification::Action &a)
void Notification::addAction(const Action &a)
{
d->m_actions.insert(a.id(),a);
}
const QHash<int, Notification::Action> &Notification::actions() const
const QHash<int, Action> &Notification::actions() const
{
return d->m_actions;
}
@ -208,9 +174,4 @@ QDataStream &operator<< ( QDataStream &stream, const Notification &noti )
}
QDataStream &operator<< ( QDataStream &stream, const Notification::Action &a)
{
stream << a.id() << a.name();
return stream;
}

View File

@ -22,6 +22,7 @@
#include "../snore_exports.h"
#include "icon.h"
#include "notificationenums.h"
#include "notificationaction.h"
#include "../hint.h"
#include "../application.h"
@ -37,24 +38,6 @@ class NotificationData;
class SNORE_EXPORT Notification
{
friend class NotificationData;
public:
class SNORE_EXPORT Action
{
public:
Action();
Action(int id,QString name);
Action(const Action &other);
int id() const;
QString name() const;
bool isValid() const;
private:
int m_id;
QString m_name;
};
public:
Notification();
explicit Notification(const Application &application,const Alert &alert,const QString &title,const QString &text,const Icon &icon,int timeout=10, NotificationEnums::Prioritys::prioritys priority = NotificationEnums::Prioritys::NORMAL );
@ -121,5 +104,5 @@ inline QDebug operator<< ( QDebug debug, const Snore::Notification &noti )
return debug.maybeSpace();
}
QDataStream &operator<< ( QDataStream & stream, const Snore::Notification::Action & action);
#endif // NOTIFICATION_H

View File

@ -56,7 +56,7 @@ NotificationData::~NotificationData()
}
void NotificationData::setActionInvoked (const Snore::Notification::Action &action )
void NotificationData::setActionInvoked (const Snore::Action &action )
{
m_actionInvoked = action;
}

View File

@ -42,7 +42,7 @@ public:
void setSource(class SnoreFrontend *source);
class SnoreFrontend *source() const;
void setActionInvoked( const Notification::Action &action );
void setActionInvoked( const Action &action );
void setActionInvoked( const int &actionID);
@ -62,8 +62,8 @@ private:
Icon m_icon;
NotificationEnums::Prioritys::prioritys m_priority;
NotificationEnums::CloseReasons::closeReasons m_closeReason;
Notification::Action m_actionInvoked;
QHash<int,Notification::Action> m_actions;
Action m_actionInvoked;
QHash<int,Action> m_actions;
Hint m_hints;

View File

@ -0,0 +1,56 @@
/*
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 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 "notificationaction.h"
using namespace Snore;
Action::Action():
m_id(-1)
{
}
Action::Action(int id, QString name):
m_id(id),
m_name(name)
{
}
QString Action::name() const
{
return m_name;
}
bool Action::isValid() const
{
return m_name.isNull();
}
int Action::id() const
{
return m_id;
}
QDataStream &operator<< ( QDataStream &stream, const Action &a)
{
stream << a.id() << a.name();
return stream;
}

View File

@ -0,0 +1,48 @@
/*
SnoreNotify is a Notification Framework based on Qt
Copyright (C) 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 NOTIFICATIONACTION_H
#define NOTIFICATIONACTION_H
#include "../snore_exports.h"
#include <QDataStream>
namespace Snore
{
class SNORE_EXPORT Action
{
public:
Action();
Action(int id,QString name);
int id() const;
QString name() const;
bool isValid() const;
private:
int m_id;
QString m_name;
};
}
QDataStream &operator<< ( QDataStream & stream, const Snore::Action &action);
#endif // NOTIFICATIONACTION_H

View File

@ -220,7 +220,8 @@ void SnarlBackend::slotNotify(Notification notification){
break;
}
if(notification.updateID() == 0){
if(notification.updateID() == 0)
{
ULONG32 id = snarlInterface->Notify(notification.alert().name().toUtf8().constData(),
Snore::toPlainText(notification.title()).toUtf8().constData(),
Snore::toPlainText(notification.text()).toUtf8().constData(),
@ -229,7 +230,7 @@ void SnarlBackend::slotNotify(Notification notification){
!notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0,
priority);
foreach(const Notification::Action &a, notification.actions())
foreach(const Action &a, notification.actions())
{
snarlInterface->AddAction(id,a.name().toUtf8().constData(),QString("@").append(QString::number(a.id())).toUtf8().constData());
}

View File

@ -115,7 +115,7 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
noti.data()->setSource(this);
for(int i = 0;i < actions.length(); i+=2)
{
noti.addAction(Notification::Action(actions.at(i).toInt(),actions.at(i+1)));
noti.addAction(Action(actions.at(i).toInt(),actions.at(i+1)));
}
snore()->broadcastNotification(noti);

View File

@ -88,7 +88,7 @@ void TrayIcon::slotTestNotification()
const Application &app = m_snore->d()->defaultApplication();
m_snore->registerApplication(app);
Notification n(app, *app.alerts().begin(), "Hello World", "This is Snore", Icon(":/root/snore.png"));
n.addAction(Notification::Action(1,"Test Action"));
n.addAction(Action(1,"Test Action"));
m_snore->broadcastNotification(n);
m_snore->deregisterApplication(app);
}