hopefully finally fixed the crash caused by using the same notification id twice, caused by the freedesktop notification frontend trying to update a existing notification
This commit is contained in:
parent
aec4dd4d84
commit
01b47fd6a7
|
@ -35,19 +35,16 @@ SnoreIcon::SnoreIcon() :
|
|||
SnoreIcon::SnoreIcon(const QImage &img):
|
||||
d(new SnoreIconData(img))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SnoreIcon::SnoreIcon(const QString &url):
|
||||
d(new SnoreIconData(url))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SnoreIcon::SnoreIcon(const SnoreIcon &other):
|
||||
d(other.d)
|
||||
{
|
||||
qDebug() << *this;
|
||||
}
|
||||
|
||||
SnoreIcon::~SnoreIcon()
|
||||
|
@ -55,7 +52,6 @@ SnoreIcon::~SnoreIcon()
|
|||
|
||||
}
|
||||
|
||||
|
||||
const QImage &SnoreIcon::image() const{
|
||||
if(d->m_img.isNull()){
|
||||
d->m_img = QImage(d->m_url);
|
||||
|
@ -72,7 +68,7 @@ QString SnoreIcon::localUrl()const{
|
|||
}
|
||||
else
|
||||
{
|
||||
d->m_localUrl = QString("%1%2.png").arg(SnoreCore::snoreTMP(), hash(), ".png");
|
||||
d->m_localUrl = QString("%1%2.png").arg(SnoreCore::snoreTMP(), hash());
|
||||
image().save(d->m_localUrl ,"PNG");
|
||||
hasedImages[hash()] = d->m_localUrl;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace Snore{
|
|||
|
||||
int Notification::notificationMetaID = qRegisterMetaType<Notification>();
|
||||
|
||||
QAtomicInt Notification::notificationCount = 0;
|
||||
uint Notification::notificationCount = 0;
|
||||
|
||||
|
||||
uint Notification::m_idCount;
|
||||
|
@ -54,8 +54,8 @@ Notification::Notification () :
|
|||
{
|
||||
}
|
||||
|
||||
Notification::Notification ( const QString &application, const QString &alert, const QString &title, const QString &text, const SnoreIcon &icon, int timeout, uint id,NotificationEnums::Prioritys::prioritys priority ):
|
||||
d(new NotificationData(application,alert,title,text,icon,timeout,id,priority))
|
||||
Notification::Notification ( const QString &application, const QString &alert, const QString &title, const QString &text, const SnoreIcon &icon, int timeout,NotificationEnums::Prioritys::prioritys priority ):
|
||||
d(new NotificationData(application,alert,title,text,icon,timeout,priority))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,16 @@ const int &Notification::timeout() const
|
|||
return d->m_timeout;
|
||||
}
|
||||
|
||||
void Notification::setUpdateID(uint id)
|
||||
{
|
||||
d->m_updateID = id;
|
||||
}
|
||||
|
||||
const uint &Notification::updateID() const
|
||||
{
|
||||
return d->m_updateID;
|
||||
}
|
||||
|
||||
const Notification::Action *Notification::actionInvoked() const
|
||||
{
|
||||
return d->m_actionInvoked;
|
||||
|
@ -195,8 +205,9 @@ QDataStream &operator<< ( QDataStream &stream, const Notification::Action &a)
|
|||
return stream;
|
||||
}
|
||||
|
||||
Snore::Notification::Notification::NotificationData::NotificationData(const QString &application, const QString &alert, const QString &title, const QString &text, const SnoreIcon &icon, int timeout, uint id, NotificationEnums::Prioritys::prioritys priority):
|
||||
m_id ( id == 0 ?m_idCount++:id),
|
||||
Snore::Notification::Notification::NotificationData::NotificationData(const QString &application, const QString &alert, const QString &title, const QString &text, const SnoreIcon &icon, int timeout, NotificationEnums::Prioritys::prioritys priority):
|
||||
m_id ( m_idCount++ ),
|
||||
m_updateID(0),
|
||||
m_timeout ( timeout ),
|
||||
m_source ( NULL),
|
||||
m_application ( application ),
|
||||
|
@ -207,13 +218,13 @@ Snore::Notification::Notification::NotificationData::NotificationData(const QStr
|
|||
m_priority(priority),
|
||||
m_closeReason(NotificationEnums::CloseReasons::NONE)
|
||||
{
|
||||
notificationCount.ref();
|
||||
notificationCount++;
|
||||
qDebug()<< "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id;
|
||||
}
|
||||
|
||||
Snore::Notification::Notification::NotificationData::~NotificationData()
|
||||
{
|
||||
notificationCount.deref();
|
||||
notificationCount--;
|
||||
qDebug() << "Deleting Notification: ActiveNotifications" << notificationCount << "id" << m_id;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
|
||||
public:
|
||||
Notification ();
|
||||
Notification (const QString &application,const QString &alert,const QString &title,const QString &text,const SnoreIcon &icon,int timeout=10,uint id = 0, NotificationEnums::Prioritys::prioritys priority = NotificationEnums::Prioritys::NORMAL );
|
||||
Notification (const QString &application,const QString &alert,const QString &title,const QString &text,const SnoreIcon &icon,int timeout=10, NotificationEnums::Prioritys::prioritys priority = NotificationEnums::Prioritys::NORMAL );
|
||||
Notification ( const Notification &other );
|
||||
~Notification();
|
||||
|
||||
|
@ -54,6 +54,9 @@ public:
|
|||
//0 means sticky
|
||||
const int &timeout() const;
|
||||
|
||||
void setUpdateID(uint id);
|
||||
const uint &updateID() const;
|
||||
|
||||
const Action* actionInvoked() const;
|
||||
void setSource(class SnoreFrontend *source);
|
||||
class SnoreFrontend *source() const;
|
||||
|
@ -89,12 +92,13 @@ private:
|
|||
|
||||
public:
|
||||
NotificationData ( const QString &application,const QString &alert,const QString &title,const QString &text,const SnoreIcon &icon,
|
||||
int timeout,uint id,NotificationEnums::Prioritys::prioritys priority );
|
||||
int timeout,NotificationEnums::Prioritys::prioritys priority );
|
||||
|
||||
|
||||
~NotificationData();
|
||||
|
||||
uint m_id;
|
||||
uint m_updateID;
|
||||
int m_timeout;
|
||||
Notification::Action *m_actionInvoked;
|
||||
SnoreFrontend *m_source;
|
||||
|
@ -111,7 +115,7 @@ private:
|
|||
};
|
||||
|
||||
QExplicitlySharedDataPointer<NotificationData> d;
|
||||
static QAtomicInt notificationCount;
|
||||
static uint notificationCount;
|
||||
static int notificationMetaID;
|
||||
|
||||
};
|
||||
|
|
|
@ -66,7 +66,11 @@ void SnoreBackend::requestCloseNotification ( Notification notification,Notifica
|
|||
|
||||
void SnoreBackend::closeNotification(Notification n, NotificationEnums::CloseReasons::closeReasons reason)
|
||||
{
|
||||
qDebug() << __func__ << n;
|
||||
if(!n.isValid())
|
||||
{
|
||||
qWarning() << "Closing a notification a second time, this should not heappen";
|
||||
return;
|
||||
}
|
||||
if(m_activeNotifications.contains(n.id()))
|
||||
{
|
||||
m_activeNotifications.remove(n.id());
|
||||
|
|
|
@ -203,7 +203,7 @@ void SnarlBackend::slotNotify(Notification notification){
|
|||
break;
|
||||
}
|
||||
|
||||
if(!m_idMap.contains(notification.id())){
|
||||
if(notification.updateID() == 0){
|
||||
ULONG32 id = snarlInterface->Notify(notification.alert().toUtf8().constData(),
|
||||
Notification::toPlainText(notification.title()).toUtf8().constData(),
|
||||
Notification::toPlainText(notification.text()).toUtf8().constData(),
|
||||
|
@ -216,10 +216,11 @@ void SnarlBackend::slotNotify(Notification notification){
|
|||
snarlInterface->AddAction(id,a->name.toUtf8().constData(),QString("@").append(QString::number(a->id)).toUtf8().constData());
|
||||
}
|
||||
m_idMap[notification.id()] = id;
|
||||
startTimeout(notification.id(),notification.timeout());
|
||||
|
||||
}else{
|
||||
//update message
|
||||
snarlInterface->Update(m_idMap[notification.id()],
|
||||
snarlInterface->Update(m_idMap[notification.updateID()],
|
||||
notification.alert().toUtf8().constData(),
|
||||
Notification::toPlainText(notification.title()).toUtf8().constData(),
|
||||
Notification::toPlainText(notification.text()).toUtf8().constData(),
|
||||
|
@ -227,8 +228,9 @@ void SnarlBackend::slotNotify(Notification notification){
|
|||
notification.icon().isLocalFile()?notification.icon().localUrl().toUtf8().constData():0,
|
||||
!notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0,
|
||||
priority);
|
||||
startTimeout(notification.updateID(),notification.timeout());
|
||||
}
|
||||
startTimeout(notification.id(),notification.timeout());
|
||||
|
||||
}
|
||||
|
||||
void SnarlBackend::slotCloseNotification(Notification notification)
|
||||
|
|
|
@ -86,13 +86,11 @@ void SnoreToast::slotNotify(Notification notification)
|
|||
p->start("SnoreToast", arguements);
|
||||
|
||||
p->setProperty("SNORE_NOTIFICATION_ID",notification.id());
|
||||
qDebug() << notification.id();
|
||||
}
|
||||
|
||||
void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus)
|
||||
{
|
||||
QProcess *p = qobject_cast<QProcess*>(sender());
|
||||
qDebug() << p->property("SNORE_NOTIFICATION_ID").toUInt();
|
||||
Notification n = getActiveNotificationByID(p->property("SNORE_NOTIFICATION_ID").toUInt());
|
||||
|
||||
NotificationEnums::CloseReasons::closeReason reason = NotificationEnums::CloseReasons::CLOSED;
|
||||
|
@ -118,6 +116,7 @@ void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus)
|
|||
break;
|
||||
case -1:
|
||||
//failed
|
||||
qWarning() << "SnoreToast failed to display " << n;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ void FreedesktopFrontend::actionInvoked(Notification notification) {
|
|||
|
||||
void FreedesktopFrontend::notificationClosed(Notification notification) {
|
||||
|
||||
qDebug()<<"Closing Dbus notification"<<notification.id()<<"reason:"<<(int)notification.closeReason();
|
||||
qDebug()<<"Closing Dbus notification"<<notification<<"reason:"<<(int)notification.closeReason();
|
||||
emit NotificationClosed(notification.id(),notification.closeReason());
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,6 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
|
|||
const QString &app_icon, const QString &summary, const QString &body,
|
||||
const QStringList &actions, const QVariantMap &hints, int timeout)
|
||||
{
|
||||
qDebug()<<app_name<<summary<<body<<app_icon<<timeout;
|
||||
SnoreIcon icon;
|
||||
NotificationEnums::Prioritys::prioritys priotity = NotificationEnums::Prioritys::NORMAL;
|
||||
|
||||
|
@ -97,7 +96,11 @@ 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,replaces_id,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);
|
||||
}
|
||||
noti.setSource(this);
|
||||
for(int i = 0;i < actions.length(); i+=2){
|
||||
noti.addAction(new Notification::Action(actions.at(i).toInt(),actions.at(i+1)));
|
||||
|
|
Loading…
Reference in New Issue