summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/daemon/NotificationsService.cpp116
-rw-r--r--src/daemon/NotificationsService.h2
-rw-r--r--src/daemon/NotifyWidget.cpp111
-rw-r--r--src/daemon/NotifyWidget.h25
4 files changed, 172 insertions, 82 deletions
diff --git a/src/daemon/NotificationsService.cpp b/src/daemon/NotificationsService.cpp
index 4201643..07cd3bf 100644
--- a/src/daemon/NotificationsService.cpp
+++ b/src/daemon/NotificationsService.cpp
@@ -42,14 +42,14 @@ NotificationsService::NotificationsService(TQT_DBusConnection &conn)
NotificationsService::~NotificationsService()
{
- notificationMap.clear();
+ mNotificationMap.clear();
}
void NotificationsService::closeNotifyWidget(TQ_UINT32 id, TQ_UINT32 reason) {
- if (notificationMap[id]) {
- notificationMap[id]->close();
- notificationMap.remove(id);
+ if (mNotificationMap[id]) {
+ mNotificationMap[id]->close();
+ mNotificationMap.remove(id);
}
if ( !emitNotificationClosed(id, reason) ) {
@@ -109,103 +109,113 @@ void NotificationsService::NotifyAsync(
const TQMap<TQString, TQT_DBusVariant>& hints,
TQ_INT32 timeout)
{
- TQ_UINT32 nId=id;
-// if (nId != 0 && !notificationMap.contains(nId))
+ TQ_UINT32 nId = id;
+// if (nId != 0 && !mNotificationMap.contains(nId))
// tqDebug("Requested id %i is not valid", nId);
- bool found = notificationMap.contains(nId);
- if (nId == 0 || !notificationMap.contains(nId)) // new notification
+ if (nId == 0 || !mNotificationMap.contains(nId)) // new notification
{
nId = ++mNotificationId;
- notificationMap[nId] = new NotifyWidget(0, app_name.ascii(), nId);
- notificationMap[nId]->setMinimumSize(200, 40);
- connect(notificationMap[nId], TQ_SIGNAL(notificationClosed(TQ_UINT32, TQ_UINT32)),
+ mNotificationMap[nId] = new NotifyWidget(0, app_name.ascii(), nId);
+ mNotificationMap[nId]->setMinimumSize(200, 40);
+
+ connect(mNotificationMap[nId], TQ_SIGNAL(notificationClosed(TQ_UINT32, TQ_UINT32)),
this, TQ_SLOT(closeNotifyWidget(TQ_UINT32, TQ_UINT32)));
}
+ if (!icon.isEmpty()) {
+ if (!mNotificationMap[nId]->setIcon(icon))
+ tqDebug("There was an error setting the icon");
+ }
+
if(!hints.empty())
{
TQString errStr;
TQMap<TQString, TQT_DBusVariant>::const_iterator it;
for ( it = hints.begin(); it != hints.end(); ++it ) {
bool ok = true;
- if(it.key().latin1()=="category")
+// tqDebug("Processing hint %s", it.key().latin1());
+ if(it.key()=="category")
{
- notificationMap[nId]->setCategory(it.data().value.toString(&ok));
+ mNotificationMap[nId]->setCategory(it.data().value.toString(&ok));
if(!ok) errStr += " category";
}
- else if (it.key().latin1()=="image-path")
+ else if (it.key()=="image-path" || it.key()=="image_path")
{
- notificationMap[nId]->setImage(it.data().value.toString(&ok));
+ mNotificationMap[nId]->setImage(it.data().value.toString(&ok));
if(!ok) errStr += " image-path";
}
- else if (it.key().latin1()=="image-data" || it.key().latin1()=="image_data" || it.key().latin1()=="icon_data")
+ else if (it.key()=="image-data" || it.key()=="image_data" || it.key()=="icon_data")
{
- notificationMap[nId]->setImageData(it.data().value.toTQValueList(&ok));
+ mNotificationMap[nId]->setImageData(it.data().value.toStruct(&ok));
if(!ok) errStr += " image-data";
}
- else if (it.key().latin1()=="sound-file")
+ else if (it.key()=="sound-file")
{
- notificationMap[nId]->setSoundFile(it.data().value.toString(&ok));
+ mNotificationMap[nId]->setSoundFile(it.data().value.toString(&ok));
if(!ok) errStr += " sound-file";
}
- else if (it.key().latin1()=="sound-name")
+ else if (it.key()=="sound-name")
{
- notificationMap[nId]->setSoundName(it.data().value.toString(&ok));
+ mNotificationMap[nId]->setSoundName(it.data().value.toString(&ok));
if(!ok) errStr += " sound-name";
}
- else if (it.key().latin1()=="suppress-sound")
+ else if (it.key()=="suppress-sound")
{
- notificationMap[nId]->setSuppressSound(it.data().value.toBool(&ok));
+ mNotificationMap[nId]->setSuppressSound(it.data().value.toBool(&ok));
if(!ok) errStr += " suppress-sound";
}
- else if (it.key().latin1()=="transient")
+ else if (it.key()=="resident")
+ {
+ mNotificationMap[nId]->setResident(it.data().value.toBool(&ok));
+ if(!ok) errStr += " resident";
+ }
+ else if (it.key()=="transient")
{
- notificationMap[nId]->setTransient(it.data().value.toBool(&ok));
+ mNotificationMap[nId]->setTransient(it.data().value.toBool(&ok));
if(!ok) errStr += " transient";
}
- else if (it.key().latin1()=="urgency")
+ else if (it.key()=="urgency")
{
- notificationMap[nId]->setUrgency(it.data().value.toUInt16(&ok));
+ mNotificationMap[nId]->setUrgency(it.data().value.toByte(&ok));
if(!ok) errStr += " urgency";
}
- else if (it.key().latin1()=="sender-pid")
+ else if (it.key()=="sender-pid")
{
- notificationMap[nId]->setSenderPid(it.data().value.toUInt64(&ok));
+ mNotificationMap[nId]->setSenderPid(it.data().value.toInt64(&ok));
if(!ok) errStr += " sender-pid";
}
}
if(! errStr.isNull() )
- tqDebug("There was an error converting some of the hint values:" + errStr);
- }
-
- notificationMap[nId]->setFrameStyle( TQFrame::NoFrame );
-// notificationMap[nId]->setPaletteBackgroundColor(TQt::black);
-// notificationMap[nId]->setPaletteForegroundColor(TQt::white);
-
- if (icon.isEmpty() || ! notificationMap[nId]->setIcon(icon)) {
- notificationMap[nId]->setTextFormat(TQt::RichText);
- notificationMap[nId]->setText("<b>" + app_name + ": " + summary + "</b><p>" + body + "</p>");
+ tqDebug("There was an error converting some of the hint values: " + errStr);
}
- notificationMap[nId]->setActions(actions);
- notificationMap[nId]->setTimeout(timeout);
- notificationMap[nId]->adjustSize();
- notificationMap[nId]->raise();
- notificationMap[nId]->show();
- notificationMap[nId]->setActiveWindow();
+ else
+ tqDebug("hints is empty ");
+
+ mNotificationMap[nId]->setText("<b>" + app_name + ": " + summary + "</b><p>" + body + "</p>");
+ mNotificationMap[nId]->setActions(actions);
+ if(mNotificationMap[nId]->isTransient() && timeout == 0)
+ timeout = -1; // use server defined timeout (transient bypasses persistence on the server)
+ if(mNotificationMap[nId]->isResident() && timeout != 0)
+ timeout = 0; // resident takes advantage of persistence)
+ mNotificationMap[nId]->setTimeout(timeout);
+ mNotificationMap[nId]->adjustSize();
+ mNotificationMap[nId]->raise();
+ mNotificationMap[nId]->show();
+ mNotificationMap[nId]->setActiveWindow();
// make sure we display the new notification above the older one
// and if we reach the top of the screen we start at the bottom
TQDesktopWidget *d = TQApplication::desktop();
- if (notificationMap.contains(nId-1) && notificationMap[nId-1] != 0) {
- TQPoint pos = notificationMap[nId-1]->pos();
- if(pos.y()-notificationMap[nId-1]->height() < 0)
- pos.setY(d->height()-notificationMap[nId]->height());
- pos.setX(d->width()-notificationMap[nId]->width());
- notificationMap[nId]->move(pos.x(),pos.y()-notificationMap[nId-1]->height());
+ if (mNotificationMap.contains(nId-1) && mNotificationMap[nId-1] != 0) {
+ TQPoint pos = mNotificationMap[nId-1]->pos();
+ if(pos.y()-mNotificationMap[nId-1]->height() < 0)
+ pos.setY(d->height()-mNotificationMap[nId]->height());
+ pos.setX(d->width()-mNotificationMap[nId]->width());
+ mNotificationMap[nId]->move(pos.x(),pos.y()-mNotificationMap[nId-1]->height());
} else {
- notificationMap[nId]->move( d->width()-notificationMap[nId]->width(),
- d->height()-notificationMap[nId]->height());
+ mNotificationMap[nId]->move( d->width()-mNotificationMap[nId]->width(),
+ d->height()-mNotificationMap[nId]->height());
}
NotifyAsyncReply(asyncCallId, nId);
diff --git a/src/daemon/NotificationsService.h b/src/daemon/NotificationsService.h
index ff44691..5c439a7 100644
--- a/src/daemon/NotificationsService.h
+++ b/src/daemon/NotificationsService.h
@@ -78,7 +78,7 @@ protected:
private:
TQT_DBusConnection *mConnection;
TQ_UINT32 mNotificationId;
- TQMap<TQ_UINT32, NotifyWidget*> notificationMap;
+ TQMap<TQ_UINT32, NotifyWidget*> mNotificationMap;
};
#endif /* NOTIFICATIONSSERVICE_H_ */
diff --git a/src/daemon/NotifyWidget.cpp b/src/daemon/NotifyWidget.cpp
index bbad479..d780957 100644
--- a/src/daemon/NotifyWidget.cpp
+++ b/src/daemon/NotifyWidget.cpp
@@ -23,6 +23,7 @@
#include <kdebug.h>
#include <tqtimer.h>
#include <tqdbusvariant.h>
+#include <tqlayout.h>
#include "NotifyWidget.h"
#include "NotificationsService.h"
@@ -31,7 +32,10 @@
#define EXPTIMEOUT 15000 //msec
NotifyWidget::NotifyWidget(TQWidget *parent, const char *name, TQ_INT32 id )
- : TQLabel( parent, name, WStyle_Customize | TQt::WStyle_StaysOnTop | TQt::WStyle_NoBorder),
+ : TQWidget( parent, name, WStyle_Customize | TQt::WStyle_StaysOnTop | TQt::WStyle_NoBorder),
+ mIconLabel(nullptr),
+ mImageLabel(nullptr),
+ mTextLabel(nullptr),
mName(TQString(name)),
mId(id),
mUrgency(0),
@@ -43,12 +47,42 @@ NotifyWidget::NotifyWidget(TQWidget *parent, const char *name, TQ_INT32 id )
// TODO: give the user an option to configure if he/she wants to have
// the notification fading away from down to top
// TQTimer::singleShot(100, this, TQ_SLOT(fadeAway()));
+ mIconLabel = new TQLabel(this);
+ mIconLabel->setFrameStyle( TQFrame::NoFrame );
+ mImageLabel = new TQLabel(this);
+ mImageLabel->setFrameStyle( TQFrame::NoFrame );
+ mTextLabel = new TQLabel(this);
+ mTextLabel->setTextFormat(TQt::RichText);
+ mTextLabel->setFrameStyle( TQFrame::NoFrame );
+// TODO: give the user an option to configure the background
+// mImageLabel[nId]->setPaletteBackgroundColor(TQt::black);
+// mImageLabel[nId]->setPaletteForegroundColor(TQt::white);
+// mTextLabel[nId]->setPaletteBackgroundColor(TQt::black);
+// mTextLabel[nId]->setPaletteForegroundColor(TQt::white);
+
+ TQBoxLayout* hLayout = new TQHBoxLayout(this);
+ TQBoxLayout* vLayout = new TQVBoxLayout();
+ vLayout->addWidget(mIconLabel);
+ vLayout->addWidget(mImageLabel);
+ vLayout->setAlignment(TQt::AlignTop);
+ vLayout->setAlignment(TQt::AlignCenter);
+ hLayout->addLayout(vLayout);
+ hLayout->addWidget(mTextLabel);
+ hLayout->setAlignment(TQt::AlignTop);
+// hLayout->setSpacing(5);
+
mTimer = new TQTimer( this );
connect( mTimer, TQ_SIGNAL(timeout()), this, TQ_SLOT(slotTimeout()) );
}
NotifyWidget::~NotifyWidget()
{
+ if(mIconLabel)
+ delete mIconLabel;
+ if(mImageLabel)
+ delete mImageLabel;
+ if(mTextLabel)
+ delete mTextLabel;
if(mTimer)
delete mTimer;
}
@@ -63,12 +97,12 @@ void NotifyWidget::setAutoMask(bool b)
}
bool NotifyWidget::setIcon(const TQString& icon) {
- mIcon = icon;
TQPixmap pixmap;
- if ( pixmap.load(mIcon) ) {
- this->setPixmap(pixmap);
+ if ( pixmap.load(icon) ) {
+ mIconLabel->setPixmap(pixmap);
+ mIconLabel->setAlignment(TQLabel::AlignTop);
+ mIconLabel->setMargin(3);
} else {
- tqDebug("Could not load notification icon");
return false;
}
return true;
@@ -104,26 +138,43 @@ void NotifyWidget::setPersistence(bool p) {
}
void NotifyWidget::setImage(const TQString& i) {
- mIcon = i;
+ TQPixmap myImage(i); // Load the image
+ mImageLabel->setPixmap(myImage);
+// mImageLabel->setAlignment(TQt::AlignCenter); // Use TQt namespace for alignment
+ mImageLabel->setAlignment(TQLabel::AlignTop);
+ mImageLabel->setMargin(3);
}
+
void NotifyWidget::setImageData(const TQValueList<TQT_DBusData>& data) {
- int x = data[0].toInt32();
- int y = data[1].toInt32();
- int r = data[2].toInt32(); // rowstride
- int a = data[3].toBool(); // alpha
- int b = data[4].toInt32(); // bits per sample
- int c = data[5].toInt32(); // channels
+// tqDebug("Processing ImageData");
+ TQ_UINT32 x = data[0].toUInt32(); // width
+ TQ_UINT32 y = data[1].toUInt32(); // height
+ TQ_UINT32 r = data[2].toUInt32(); // rowstride
+ bool a = data[3].toBool(); // has alpha
+ TQ_UINT32 b = data[4].toUInt32(); // bits per sample
+ TQ_UINT32 c = data[5].toUInt32(); // channels
TQValueList<TQT_DBusData> v = data[6].toTQValueList(); // image bytes
-// int w, int h, int depth, int numColors = 0, Endian bitOrder = IgnoreEndian
- mImageData = TQPixmap(x,y);
- TQByteArray i;
+
+// tqDebug(" Width : %i", x);
+// tqDebug(" Height: %i", y);
+// tqDebug(" Rowstride: %i", r);
+// tqDebug(" Has alpha: %i", a);
+// tqDebug("Bits per sample: %i", b);
+// tqDebug(" Channels: %i", c);
+// tqDebug(" data size: %li", v.size());
+
+ TQ_UINT32 i = 0;
+ TQMemArray<char> cList(v.size());
TQValueList<TQT_DBusData>::Iterator it;
- TQ_UINT32 count;
for ( it = v.begin(); it != v.end(); ++it )
- i[count++]=(*it).toByte();
- mImageData.loadFromData(i);
- setPixmap(mImageData);
+ cList[i++] = (*it).toByte();
+ mImageData = TQImage( x, y, b, c);
+ mImageData.loadFromData(cList);
+ mImageData.setAlphaBuffer(a);
+ mImageLabel->setPixmap(TQPixmap(mImageData));
+ mImageLabel->setAlignment(TQLabel::AlignTop);
+ mImageLabel->setMargin(3);
}
void NotifyWidget::setSoundFile(const TQString& f) {
@@ -138,16 +189,28 @@ void NotifyWidget::setSuppressSound(bool s) {
mSuppressSound = s;
}
+void NotifyWidget::setResident(bool r) {
+ mResident = r;
+}
+
+bool NotifyWidget::isResident() {
+ return mResident;
+}
+
void NotifyWidget::setTransient(bool t) {
mTransient = t;
}
-void NotifyWidget::setUrgency(TQ_UINT16 l) {
+bool NotifyWidget::isTransient() {
+ return mTransient;
+}
+
+void NotifyWidget::setUrgency(TQ_UINT8 l) {
mUrgency = l;
}
-void NotifyWidget::setSenderPid(TQ_UINT64 p) {
+void NotifyWidget::setSenderPid(TQ_INT64 p) {
mSenderPid = p;
}
@@ -161,6 +224,12 @@ void NotifyWidget::setTimeout(TQ_INT32 t) {
}
}
+void NotifyWidget::setText(TQString t)
+{
+ mTextLabel->setText(t);
+ mTextLabel->setAlignment(TQLabel::AlignTop);
+}
+
void NotifyWidget::mousePressEvent( TQMouseEvent *e )
{
if (e->button() == TQMouseEvent::LeftButton)
diff --git a/src/daemon/NotifyWidget.h b/src/daemon/NotifyWidget.h
index 9927d61..d80c154 100644
--- a/src/daemon/NotifyWidget.h
+++ b/src/daemon/NotifyWidget.h
@@ -25,12 +25,12 @@
#include <tqlabel.h>
#include <tqtextedit.h>
-#include <tqpixmap.h>
+#include <tqimage.h>
#include <tqdbusvariant.h>
//class NotificationsService;
-class NotifyWidget: public TQLabel
+class NotifyWidget: public TQWidget
{
TQ_OBJECT
@@ -87,9 +87,12 @@ Categories are in class.specific form. class specifies the generic type of notif
void setSoundFile(const TQString&);
void setSoundName(const TQString&);
void setSuppressSound(bool);
+ void setResident(bool);
+ bool isResident();
void setTransient(bool);
- void setUrgency(TQ_UINT16);
- void setSenderPid(TQ_UINT64);
+ bool isTransient();
+ void setUrgency(TQ_UINT8);
+ void setSenderPid(TQ_INT64);
/**
* The timeout time in milliseconds since the display of the notification at which the notification should automatically close.
@@ -99,6 +102,11 @@ If -1, the notification's expiration time is dependent on the notification serve
If 0, the notification never expires.
*/
void setTimeout(TQ_INT32 t);
+
+ /**
+ * Set the text of the notification
+ */
+ void setText(TQString);
/**
* DBus signals
* 1. org.freedesktop.Notifications.NotificationClosed is implemented
@@ -125,20 +133,23 @@ private slots:
void slotFadeAway();
private:
+ TQLabel* mIconLabel;
+ TQLabel* mImageLabel;
+ TQLabel* mTextLabel;
TQString mName;
TQ_INT32 mId;
- TQString mIcon;
TQStringList mActions; // not implemented
TQString mCategory; // not implemented
TQTimer *mTimer;
TQ_UINT16 mUrgency;
- TQPixmap mImageData;
+ TQImage mImageData;
TQString mSoundFile;
TQString mSoundName;
bool mPersistence;
bool mSuppressSound;
+ bool mResident;
bool mTransient;
- TQ_UINT64 mSenderPid;
+ TQ_INT64 mSenderPid;
};