Reuse the same native notification popup on Linux. Fixes issue #118

This commit is contained in:
David Sansome 2010-03-29 20:08:32 +00:00
parent 48632b5fc0
commit d68c61ff25
2 changed files with 16 additions and 8 deletions

View File

@ -29,13 +29,12 @@ class OSDPretty;
class QDBusPendingCallWatcher; class QDBusPendingCallWatcher;
#ifdef Q_WS_X11 #ifdef Q_WS_X11
#include <QDBusArgument> # include <QDBusArgument>
#include <boost/scoped_ptr.hpp> # include <boost/scoped_ptr.hpp>
#include "notification.h" # include "notification.h"
QDBusArgument& operator<< (QDBusArgument& arg, const QImage& image);
const QDBusArgument& operator>> (const QDBusArgument& arg, QImage& image);
QDBusArgument& operator<< (QDBusArgument& arg, const QImage& image);
const QDBusArgument& operator>> (const QDBusArgument& arg, QImage& image);
#endif #endif
class OSD : public QObject { class OSD : public QObject {
@ -97,6 +96,7 @@ class OSD : public QObject {
#ifdef Q_WS_X11 #ifdef Q_WS_X11
boost::scoped_ptr<org::freedesktop::Notifications> interface_; boost::scoped_ptr<org::freedesktop::Notifications> interface_;
uint notification_id_;
#endif #endif
private slots: private slots:
void CallFinished(QDBusPendingCallWatcher* watcher); void CallFinished(QDBusPendingCallWatcher* watcher);

View File

@ -59,6 +59,8 @@ void OSD::Init() {
if (!interface_->isValid()) { if (!interface_->isValid()) {
qWarning() << "Error connecting to notifications service."; qWarning() << "Error connecting to notifications service.";
} }
notification_id_ = 0;
} }
bool OSD::SupportsNativeNotifications() { bool OSD::SupportsNativeNotifications() {
@ -73,7 +75,7 @@ void OSD::ShowMessageNative(const QString& summary, const QString& message,
const QString& icon) { const QString& icon) {
QDBusPendingReply<uint> reply = interface_->Notify( QDBusPendingReply<uint> reply = interface_->Notify(
QCoreApplication::applicationName(), QCoreApplication::applicationName(),
0, notification_id_,
icon, icon,
summary, summary,
message, message,
@ -93,7 +95,7 @@ void OSD::ShowMessageNative(const QString& summary, const QString& message,
} }
QDBusPendingReply<uint> reply = interface_->Notify( QDBusPendingReply<uint> reply = interface_->Notify(
QCoreApplication::applicationName(), QCoreApplication::applicationName(),
0, notification_id_,
QString(), QString(),
summary, summary,
message, message,
@ -111,5 +113,11 @@ void OSD::CallFinished(QDBusPendingCallWatcher* watcher) {
QDBusPendingReply<uint> reply = *watcher; QDBusPendingReply<uint> reply = *watcher;
if (reply.isError()) { if (reply.isError()) {
qWarning() << "Error sending notification" << reply.error(); qWarning() << "Error sending notification" << reply.error();
return;
}
uint id = reply.value();
if (id != 0) {
notification_id_ = id;
} }
} }