fixed some horrible api stuff

This commit is contained in:
Patrick von Reth 2014-01-12 12:22:32 +01:00
parent 3f9e56c9ed
commit 39a622acfe
7 changed files with 53 additions and 20 deletions

View File

@ -27,10 +27,26 @@
using namespace Snore;
int Notification::DefaultTimeout = 10;
int Notification::m_defaultTimeout = 10;
int NotificationData::notificationMetaID = qRegisterMetaType<Notification>();
Notification::Action::Action(int id, QString name):
m_id(id),
m_name(name)
{
}
QString Notification::Action::name() const
{
return m_name;
}
int Notification::Action::id() const
{
return m_id;
}
Notification::Notification () :
d(NULL)
{
@ -132,8 +148,7 @@ const NotificationEnums::Prioritys::prioritys &Notification::priority() const
void Notification::addAction(Notification::Action *a)
{
qDebug()<<"Added notification"<<a->id<<a->name;
d->m_actions.insert(a->id,a);
d->m_actions.insert(a->id(),a);
}
@ -169,6 +184,16 @@ NotificationData *Notification::data()
{
return d.data();
}
int Notification::defaultTimeout()
{
return m_defaultTimeout;
}
void Notification::setDefaultTimeout(int defaultTimeout)
{
m_defaultTimeout = defaultTimeout;
}
QDataStream &operator<< ( QDataStream &stream, const Notification &noti )
{
@ -179,7 +204,7 @@ QDataStream &operator<< ( QDataStream &stream, const Notification &noti )
QDataStream &operator<< ( QDataStream &stream, const Notification::Action &a)
{
stream<<a.id<<a.id;
stream << a.id() << a.name();
return stream;
}

View File

@ -36,15 +36,19 @@ class NotificationData;
class SNORE_EXPORT Notification
{
friend class NotificationData;
public:
static int DefaultTimeout;
class Action
class SNORE_EXPORT Action
{
public:
Action(int id,QString name):id(id),name(name){}
int id;
QString name;
Action(int id,QString name);
int id() const;
QString name() const;
private:
int m_id;
QString m_name;
};
@ -87,9 +91,14 @@ public:
NotificationData *data();
static int defaultTimeout();
static void setDefaultTimeout(int defaultTimeout);
private:
QExplicitlySharedDataPointer<NotificationData> d;
static int m_defaultTimeout;
};

View File

@ -32,7 +32,7 @@ namespace Snore{
class SNORE_EXPORT NotificationData : public QSharedData
{
friend class Notification;
public:
NotificationData ( const QString &application,const QString &alert,const QString &title,const QString &text,const Icon &icon,
int timeout,NotificationEnums::Prioritys::prioritys priority );
@ -41,6 +41,8 @@ public:
void setActionInvoked ( Notification::Action *action );
void setActionInvoked ( const int &actionID);
private:
Q_DISABLE_COPY(NotificationData)
uint m_id;
uint m_updateID;
@ -61,9 +63,6 @@ public:
static uint m_idCount;
static int notificationMetaID;
private:
Q_DISABLE_COPY(NotificationData)
};
}

View File

@ -226,7 +226,7 @@ void SnarlBackend::slotNotify(Notification notification){
priority);
foreach(const Notification::Action *a, notification.actions()){
snarlInterface->AddAction(id,a->name.toUtf8().constData(),QString("@").append(QString::number(a->id)).toUtf8().constData());
snarlInterface->AddAction(id,a->name().toUtf8().constData(),QString("@").append(QString::number(a->id())).toUtf8().constData());
}
m_idMap[notification.id()] = id;
qDebug() << "snarl" << id << notification.id();

View File

@ -32,7 +32,7 @@ bool TrayIconNotifer::init(SnoreCore *snore){
void TrayIconNotifer::slotNotify( Notification notification )
{
m_notificationQue.append(notification);
if(m_lastNotify.elapsed()> Notification::DefaultTimeout * 1000){
if(m_lastNotify.elapsed()> Notification::defaultTimeout() * 1000){
displayNotification();
}
}

View File

@ -57,7 +57,7 @@ bool FreedesktopFrontend::init(SnoreCore *snore){
void FreedesktopFrontend::actionInvoked(Notification notification) {
if(notification.actionInvoked())
{
emit ActionInvoked(notification.id(),QString::number(notification.actionInvoked()->id));
emit ActionInvoked(notification.id(),QString::number(notification.actionInvoked()->id()));
}
}
@ -99,7 +99,7 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
priotity = NotificationEnums::Prioritys::prioritys(hints["urgency"].toInt()-1);
}
Notification noti(app_name,"DBus Alert",summary,body,icon,timeout==-1?Notification::DefaultTimeout:timeout/1000,priotity);
Notification noti(app_name,"DBus Alert",summary,body,icon,timeout==-1?Notification::defaultTimeout():timeout/1000,priotity);
if(replaces_id != 0)
{
noti.setUpdateID(replaces_id);

View File

@ -56,9 +56,9 @@ bool SnarlNetworkFrontend::init(SnoreCore *snore){
void SnarlNetworkFrontend::actionInvoked(Notification notification){
//TODO:fix callback
SnarlNotification sn=notifications.value(notification.id());
if(notification.actionInvoked()->id == 1 )
if(notification.actionInvoked()->id() == 1 )
callback(sn,"SNP/1.1/304/Notification acknowledged/");
else if(notification.actionInvoked()->id == 2)
else if(notification.actionInvoked()->id() == 2)
callback(sn,"SNP/1.1/302/Notification cancelled/");
}
void SnarlNetworkFrontend::notificationClosed(Notification notification){