chaned update stuff

This commit is contained in:
Patrick von Reth 2014-01-19 17:43:23 +01:00
parent 7e0d97a960
commit 9000ab5ad0
10 changed files with 85 additions and 50 deletions

View File

@ -43,6 +43,11 @@ Notification::Notification(const Application &application, const Alert &alert, c
} }
Notification::Notification(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, NotificationEnums::Prioritys::prioritys priority):
d(new NotificationData(old,title,text,icon,timeout,priority))
{
}
Notification::Notification ( const Notification &other ) : Notification::Notification ( const Notification &other ) :
d(other.d) d(other.d)
{ {
@ -73,11 +78,6 @@ const int &Notification::timeout() const
return d->m_timeout; return d->m_timeout;
} }
void Notification::setNotificationToReplace(const Notification &n)
{
d->m_toReplace = n;
}
Notification Notification::notificationToReplace() const Notification Notification::notificationToReplace() const
{ {
return d->m_toReplace; return d->m_toReplace;

View File

@ -41,6 +41,8 @@ class SNORE_EXPORT Notification
public: public:
Notification(); Notification();
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(), NotificationEnums::Prioritys::prioritys priority = NotificationEnums::Prioritys::NORMAL );
explicit Notification(const Notification &old,const QString &title,const QString &text,const Icon &icon,int timeout = defaultTimeout(), NotificationEnums::Prioritys::prioritys priority = NotificationEnums::Prioritys::NORMAL );
Notification(const Notification &other ); Notification(const Notification &other );
Notification &operator=(const Notification &other); Notification &operator=(const Notification &other);
~Notification(); ~Notification();
@ -50,7 +52,6 @@ public:
//0 means sticky //0 means sticky
const int &timeout() const; const int &timeout() const;
void setNotificationToReplace(const Notification &n);
Notification notificationToReplace() const; Notification notificationToReplace() const;
bool isUpdate() const; bool isUpdate() const;

View File

@ -48,6 +48,23 @@ NotificationData::NotificationData (const Snore::Application &application, const
qDebug()<< "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; qDebug()<< "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):
m_id ( old.id() ),
m_timeout( timeout ),
m_source( NULL),
m_application ( old.application()),
m_alert( old.alert() ),
m_title( title ),
m_text( text ),
m_icon( icon ),
m_priority(priority),
m_closeReason(NotificationEnums::CloseReasons::NONE),
m_toReplace(old)
{
notificationCount++;
qDebug()<< "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id;
}
NotificationData::~NotificationData() NotificationData::~NotificationData()
{ {
if(!m_timeoutTimer.isNull()) if(!m_timeoutTimer.isNull())

View File

@ -40,6 +40,9 @@ public:
NotificationData ( const Application &application,const Alert &alert,const QString &title,const QString &text,const Icon &icon, NotificationData ( const Application &application,const Alert &alert,const QString &title,const QString &text,const Icon &icon,
int timeout,NotificationEnums::Prioritys::prioritys priority ); int timeout,NotificationEnums::Prioritys::prioritys priority );
NotificationData(const Notification &old,const QString &title,const QString &text,const Icon &icon,int timeout, NotificationEnums::Prioritys::prioritys priority);
~NotificationData(); ~NotificationData();
void setSource(class SnoreFrontend *source); void setSource(class SnoreFrontend *source);

View File

@ -121,7 +121,7 @@ bool SnoreSecondaryBackend::supportsRichtext()
Snore::Notification SnoreBackend::getActiveNotificationByID(uint id) Snore::Notification SnoreBackend::getActiveNotificationByID(uint id)
{ {
return m_activeNotifications[id]; return m_activeNotifications.value(id);
} }
bool SnoreBackend::canCloseNotification() bool SnoreBackend::canCloseNotification()
@ -146,7 +146,7 @@ void SnoreBackend::slotDeregisterApplication(const Application &application)
void SnoreBackend::addActiveNotification(Notification n) void SnoreBackend::addActiveNotification(Notification n)
{ {
m_activeNotifications[n.id()] = n; m_activeNotifications.insert(n.id(), n);
} }

View File

@ -68,17 +68,7 @@ public:
Notification notification; Notification notification;
if(msg->lParam != 0) if(msg->lParam != 0)
{ {
uint notificationID = 0; notification = m_snarl->snore()->getActiveNotificationByID(m_snarl->m_idMap[ msg->lParam]);
for(QHash<uint,LONG32>::iterator it = m_snarl->m_idMap.begin();it != m_snarl->m_idMap.end();++it)
{
if(it.value() == msg->lParam)
{
notificationID = it.key();
break;
}
}
notification = m_snarl->snore()->getActiveNotificationByID(notificationID);
qDebug()<<"recived a Snarl callback id:"<<notificationID<< "|" << msg->lParam <<"action:"<<action<<"data:"<<data;
} }
NotificationEnums::CloseReasons::closeReasons reason = NotificationEnums::CloseReasons::NONE; NotificationEnums::CloseReasons::closeReasons reason = NotificationEnums::CloseReasons::NONE;
@ -229,9 +219,10 @@ void SnarlBackend::slotNotify(Notification notification){
break; break;
} }
ULONG32 id = 0;
if(!notification.isUpdate()) if(!notification.isUpdate())
{ {
ULONG32 id = snarlInterface->Notify(notification.alert().name().toUtf8().constData(), id = snarlInterface->Notify(notification.alert().name().toUtf8().constData(),
Snore::toPlainText(notification.title()).toUtf8().constData(), Snore::toPlainText(notification.title()).toUtf8().constData(),
Snore::toPlainText(notification.text()).toUtf8().constData(), Snore::toPlainText(notification.text()).toUtf8().constData(),
notification.timeout(), notification.timeout(),
@ -243,14 +234,14 @@ void SnarlBackend::slotNotify(Notification notification){
{ {
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; m_idMap[id] = notification.id();
startTimeout(notification); notification.hints().setPrivateValue(this, "id", id);
} }
else else
{ {
//update message //update message
snarlInterface->Update(m_idMap[notification.notificationToReplace().id()], id = notification.notificationToReplace().hints().privateValue(this, "id").toUInt();
snarlInterface->Update(id,
notification.alert().name().toUtf8().constData(), notification.alert().name().toUtf8().constData(),
Snore::toPlainText(notification.title()).toUtf8().constData(), Snore::toPlainText(notification.title()).toUtf8().constData(),
Snore::toPlainText(notification.text()).toUtf8().constData(), Snore::toPlainText(notification.text()).toUtf8().constData(),
@ -258,10 +249,11 @@ void SnarlBackend::slotNotify(Notification notification){
notification.icon().isLocalFile()?notification.icon().localUrl().toUtf8().constData():0, notification.icon().isLocalFile()?notification.icon().localUrl().toUtf8().constData():0,
!notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0, !notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0,
priority); priority);
m_idMap[notification.id()] = m_idMap[notification.notificationToReplace().id()];
startTimeout(notification);
} }
notification.hints().setPrivateValue(this, "id", id);
startTimeout(notification);//if dnd or away snarl does not timeout atomatically
} }
void SnarlBackend::slotCloseNotification(Notification notification) void SnarlBackend::slotCloseNotification(Notification notification)
@ -271,5 +263,5 @@ void SnarlBackend::slotCloseNotification(Notification notification)
qDebug() << Q_FUNC_INFO << "Unknown apllication: " << notification.application().name(); qDebug() << Q_FUNC_INFO << "Unknown apllication: " << notification.application().name();
return; return;
} }
m_applications.value(notification.application().name())->Hide(m_idMap.take(notification.id())); m_applications.value(notification.application().name())->Hide(notification.hints().privateValue(this, "id").toUInt());
} }

View File

@ -47,7 +47,7 @@ public slots:
void slotCloseNotification(Snore::Notification notification); void slotCloseNotification(Snore::Notification notification);
private: private:
QHash<uint,LONG32> m_idMap; QHash<LONG32,uint> m_idMap;
}; };

View File

@ -126,10 +126,14 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
priotity = NotificationEnums::Prioritys::prioritys(hints["urgency"].toInt()-1); priotity = NotificationEnums::Prioritys::prioritys(hints["urgency"].toInt()-1);
} }
Notification noti(app, *app.alerts().begin(), summary, body, icon, timeout==-1?Notification::defaultTimeout():timeout/1000, priotity); Notification noti;
if(replaces_id != 0) if(replaces_id != 0 && snore()->getActiveNotificationByID(replaces_id).isValid())
{ {
noti.setNotificationToReplace(snore()->getActiveNotificationByID(replaces_id)); noti = Notification(snore()->getActiveNotificationByID(replaces_id),summary, body, icon, timeout==-1?Notification::defaultTimeout():timeout/1000, priotity);
}
else
{
noti = Notification(app, *app.alerts().begin(), summary, body, icon, timeout==-1?Notification::defaultTimeout():timeout/1000, priotity);
} }
noti.data()->setSource(this); noti.data()->setSource(this);
for(int i = 0;i < actions.length(); i+=2) for(int i = 0;i < actions.length(); i+=2)

View File

@ -30,8 +30,11 @@
using namespace Snore; using namespace Snore;
TrayIcon::TrayIcon(): TrayIcon::TrayIcon():
m_trayIcon(new QSystemTrayIcon(QIcon(":/root/snore.png"))) m_trayIcon(new QSystemTrayIcon(QIcon(":/root/snore.png"))),
m_app("SnoreNotify Test", Icon(":/root/snore.png")),
m_alert("Default")
{ {
m_app.addAlert(m_alert);
} }
void TrayIcon::initConextMenu(SnoreCore *snore) void TrayIcon::initConextMenu(SnoreCore *snore)
@ -85,12 +88,25 @@ void TrayIcon::setPrimaryBackend(){
void TrayIcon::slotTestNotification() void TrayIcon::slotTestNotification()
{ {
const Application &app = m_snore->d()->defaultApplication();
m_snore->registerApplication(app); if(!m_snore->aplications().contains(m_app.name()))
Notification n(app, *app.alerts().begin(), "Hello World", "This is Snore", Icon(":/root/snore.png")); {
n.addAction(Action(1,"Test Action")); m_snore->registerApplication(m_app);
m_snore->broadcastNotification(n); }
m_snore->broadcastNotification(Notification(app, *app.alerts().begin(), "Hello World", "This is Snore, color test", Icon("http://jweatherwatch.googlecode.com/svn/trunk/iconset/04.png"))); m_noti = Notification(m_app, m_alert, "Hello World", "This is Snore", Icon(":/root/snore.png"));
// m_snore->deregisterApplication(app); m_noti.addAction(Action(1,"Test Action"));
m_snore->broadcastNotification(m_noti);
QTimer::singleShot(m_noti.timeout()/2*1000,this,SLOT(sloutUpdateTestNotification()));
// m_snore->deregisterApplication(app);
}
void TrayIcon::sloutUpdateTestNotification()
{
Notification update(m_noti, "Hello World", "This is Snore, color test", Icon("http://jweatherwatch.googlecode.com/svn/trunk/iconset/04.png"));
m_snore->broadcastNotification(update);
m_noti = Notification();
} }

View File

@ -21,10 +21,8 @@
#define TRAYICON_H #define TRAYICON_H
#include <QtCore> #include <QtCore>
#include "core/snore.h"
namespace Snore{
class SnoreCore;
}
class TrayIcon:public QObject class TrayIcon:public QObject
{ {
@ -39,12 +37,16 @@ private:
class QSystemTrayIcon *m_trayIcon; class QSystemTrayIcon *m_trayIcon;
class QMenu *m_trayMenu; class QMenu *m_trayMenu;
class QList<class QAction*> m_backendActions; class QList<class QAction*> m_backendActions;
class Snore::SnoreCore *m_snore; Snore::SnoreCore *m_snore;
Snore::Application m_app;
Snore::Alert m_alert;
Snore::Notification m_noti;
public slots: public slots:
void setPrimaryBackend(); void setPrimaryBackend();
void slotTestNotification(); void slotTestNotification();
void sloutUpdateTestNotification();
}; };
#endif // TRAYICON_H #endif // TRAYICON_H