chanegd update code

This commit is contained in:
Patrick von Reth 2014-01-19 13:57:46 +01:00
parent 9163753039
commit a54da391b8
10 changed files with 42 additions and 34 deletions

View File

@ -9,7 +9,7 @@ include(GNUInstallDirs)
#######################################################################
option(WITH_WITH_KDE "Try to build with KDE support if availibe" ON)
option(WITH_KDE "Try to build with KDE support if availibe" ON)
option(WITH_FREEDESKTOP_FRONTEND "Build the freedesktop frontend" OFF)
option(WITH_GROWL_BACKEND "Build the Growl backend" ON)
option(WITH_SNORE_DEAMON "Build the Snore deamon, which redirects notifications" OFF)
@ -19,7 +19,7 @@ set(SNORE_VERSION_MAJOR 0)
set(SNORE_VERSION_MINOR 5)
set(SNORE_VERSION_SUFFIX "pre")
if(WITH_WITH_KDE)
if(WITH_KDE)
find_package(KDE4)
endif()

View File

@ -73,14 +73,19 @@ const int &Notification::timeout() const
return d->m_timeout;
}
void Notification::setUpdateID(uint id)
void Notification::setNotificationToReplace(const Notification &n)
{
d->m_updateID = id;
d->m_toReplace = n;
}
uint Notification::updateID() const
Notification Notification::notificationToReplace() const
{
return d->m_updateID;
return d->m_toReplace;
}
bool Notification::isUpdate() const
{
return d->m_toReplace.isValid();
}
const Action &Notification::actionInvoked() const

View File

@ -50,8 +50,9 @@ public:
//0 means sticky
const int &timeout() const;
void setUpdateID(uint id);
uint updateID() const;
void setNotificationToReplace(const Notification &n);
Notification notificationToReplace() const;
bool isUpdate() const;
const Action &actionInvoked() const;
const Application &application() const;

View File

@ -34,7 +34,6 @@ uint NotificationData::m_idCount = 1;
NotificationData::NotificationData (const Snore::Application &application, const Snore::Alert &alert, const QString &title, const QString &text, const Icon &icon,
int timeout, NotificationEnums::Prioritys::prioritys priority ):
m_id ( m_idCount++ ),
m_updateID((uint)-1),
m_timeout( timeout ),
m_source( NULL),
m_application ( application ),

View File

@ -66,6 +66,7 @@ private:
Action m_actionInvoked;
QHash<int,Action> m_actions;
Hint m_hints;
Notification m_toReplace;

View File

@ -41,7 +41,7 @@ QString Action::name() const
bool Action::isValid() const
{
return m_name.isNull();
return !m_name.isNull();
}
int Action::id() const

View File

@ -75,9 +75,14 @@ void SnorePlugin::startTimeout(Notification &notification)
}
uint id = notification.id();
QTimer *timer = myQVariantCast<QTimer*>(notification.hints().privateValue(this, "timeout"));
if(notification.updateID() != (uint)-1)
if(notification.isUpdate())
{
id = notification.updateID();
id = notification.notificationToReplace().id();
QTimer *old = myQVariantCast<QTimer*>(notification.notificationToReplace().hints().privateValue(this, "timeout"));
if(old)
{
old->deleteLater();
}
}
if(timer)
{

View File

@ -88,6 +88,7 @@ void SnoreBackend::closeNotification(Notification n, NotificationEnums::CloseRea
}
n.data()->setCloseReason(reason);
slotCloseNotification(n);
qDebug() << Q_FUNC_INFO << n;
emit notificationClosed(n);
}

View File

@ -17,11 +17,12 @@ Q_EXPORT_PLUGIN2 ( freedesktopnotificationbackend,FreedesktopBackend )
FreedesktopBackend::FreedesktopBackend () :
SnoreBackend ( "FreedesktopNotification_Backend",true,true)
SnoreBackend ( "FreedesktopNotification",true,true)
{
}
bool FreedesktopBackend::initialize(SnoreCore *snore){
bool FreedesktopBackend::initialize(SnoreCore *snore)
{
m_interface = new org::freedesktop::Notifications( "org.freedesktop.Notifications", "/org/freedesktop/Notifications",
QDBusConnection::sessionBus(), this );
@ -74,11 +75,10 @@ void FreedesktopBackend::slotNotify ( Notification noti )
}
uint updateId = 0;
if(noti.updateID() != 0)
if(noti.isUpdate())
{
updateId = m_snoreIdMap[noti.updateID()];
m_dbusIdMap[updateId] = noti.id();
m_snoreIdMap[noti.id()] = updateId;
updateId = noti.notificationToReplace().id();
m_dbusIdMap.take(updateId);
}
QString title = QString("%1 - %2").arg(noti.application().name(), noti.title());
@ -91,14 +91,16 @@ void FreedesktopBackend::slotNotify ( Notification noti )
QDBusPendingReply<uint> id = m_interface->Notify(noti.application().name(), updateId, "", title,
body, actions, hints, noti.sticky()?-1:noti.timeout()*1000);
if(noti.updateID() == 0)
{
id.waitForFinished();
m_snoreIdMap[noti.id()] = id.value();
m_dbusIdMap[id.value()] = noti.id();
}
id.waitForFinished();
noti.hints().setPrivateValue(this, "id", id.value());
m_dbusIdMap[id.value()] = noti.id();
qDebug() << Q_FUNC_INFO << noti.id() << "|" << id.value();
}
void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &actionID){
void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &actionID)
{
qDebug() << Q_FUNC_INFO << id << m_dbusIdMap[id];
Notification noti = getActiveNotificationByID(m_dbusIdMap[id]);
if(!noti.isValid())
{
@ -110,12 +112,8 @@ void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &action
void FreedesktopBackend::slotCloseNotification ( Notification notification )
{
if(!m_snoreIdMap.contains(notification.id()))
{
return;
}
uint id = m_snoreIdMap.take(notification.id());
m_dbusIdMap.remove(id);
uint id = notification.hints().privateValue(this, "id").toUInt();
qDebug() << Q_FUNC_INFO << notification.id() << id;
m_interface->CloseNotification(id);
}
@ -124,7 +122,7 @@ void FreedesktopBackend::slotCloseNotification ( Notification notification )
void FreedesktopBackend::slotNotificationClosed ( const uint &id,const uint &reason )
{
NotificationEnums::CloseReasons::closeReasons closeReason = NotificationEnums::CloseReasons::closeReasons(reason);
qDebug() << Q_FUNC_INFO << "Closed" << id << "|" << closeReason << reason;
qDebug() << Q_FUNC_INFO << id << "|" << closeReason << reason;
if(id == 0)
{
return;
@ -132,7 +130,6 @@ void FreedesktopBackend::slotNotificationClosed ( const uint &id,const uint &rea
Notification noti = getActiveNotificationByID(m_dbusIdMap.take(id));
if(noti.isValid())
{
m_snoreIdMap.remove(noti.id());
closeNotification(noti, closeReason);
}
}

View File

@ -24,7 +24,6 @@ public slots:
private:
org::freedesktop::Notifications* m_interface;
QHash<uint,uint> m_dbusIdMap;
QHash<uint,uint> m_snoreIdMap;
};