From 49eb1758fe84a5d55f99a62703a1a21f4f4b2566 Mon Sep 17 00:00:00 2001
From: tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>
Date: Tue, 18 Oct 2011 00:13:32 +0000
Subject: Add stack to kdbusdaemon

git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kdbusnotification@1259341 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
---
 src/daemon/daemon.cpp | 46 +++++++++++++++++++++++++++++++++++++++-------
 src/daemon/daemon.h   |  7 +++++++
 2 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp
index c0768d3..a0b1454 100644
--- a/src/daemon/daemon.cpp
+++ b/src/daemon/daemon.cpp
@@ -29,11 +29,11 @@
 #include <tqpixmap.h>
 #include <tqtimer.h>
 #include <knotifyclient.h>
-#include <kpassivepopup.h>
 #include <kaboutdata.h>
 #include <kcmdlineargs.h>
 #include <klocale.h>
 #include <kapplication.h>
+#include <kiconloader.h>
 #include <kglobalsettings.h>
 
 #include <stdlib.h>
@@ -47,6 +47,13 @@ NotifierContainer* GTKNotifierContainer = NULL;
 void real_handleGTKMain();
 
 NotifierContainer::NotifierContainer() : TQWidget() {
+	mPopupList.clear();
+
+	// Determine bottom of desktop
+	TQPoint cursorPos = TQCursor::pos();
+	TQRect r = KGlobalSettings::desktopGeometry(cursorPos);
+	mTopOfStack = r.height();
+	mRightOfStack = r.width();
 }
 
 NotifierContainer::~NotifierContainer() {
@@ -58,7 +65,11 @@ void NotifierContainer::handleGTKMain() {
 
 void NotifierContainer::displayMessage(TQString title, TQString message, TQString icon, int x, int y) {
 	TQPixmap px;
-	px.load( icon );
+	KIconLoader* il = KGlobal::iconLoader();
+	px = il->loadIcon( icon, KIcon::NoGroup );
+// 	if (px.isNull()) {
+// 		px = il->loadIcon( "gnome_apps", KIcon::NoGroup );
+// 	}
 
 	KPassivePopup *pop = new KPassivePopup( KPassivePopup::Boxed, this, "" );
 	pop->setAutoDelete( true );
@@ -66,13 +77,21 @@ void NotifierContainer::displayMessage(TQString title, TQString message, TQStrin
 	pop->setTimeout( -1 );
 	TQPoint leftCorner( x, y);
 	if (leftCorner.isNull()) {
-		// FIXME: This should stack the popups on top of each other...
-		TQPoint cursorPos = TQCursor::pos();
+		if (mPopupList.isEmpty()) {
+			// Determine bottom of desktop
+			TQPoint cursorPos = TQCursor::pos();
+			TQRect r = KGlobalSettings::desktopGeometry(cursorPos);
+			mTopOfStack = r.height();
+			mRightOfStack = r.width();
+		}
 		TQSize popupSize = pop->tqsizeHint();
-		TQRect r = KGlobalSettings::desktopGeometry(cursorPos);
-		leftCorner.setX(r.width()-popupSize.width());
-		leftCorner.setY(r.height()-popupSize.height());
+		mTopOfStack = mTopOfStack-popupSize.height();
+		if (mTopOfStack < 0) mTopOfStack = 0;
+		leftCorner.setX(mRightOfStack-popupSize.width());
+		leftCorner.setY(mTopOfStack);
 	}
+	connect(pop, SIGNAL(hidden(KPassivePopup*)), this, SLOT(popupClosed(KPassivePopup*)));
+	mPopupList.append(pop);
 	pop->show(leftCorner);
 
 	processEvents();
@@ -82,6 +101,19 @@ void NotifierContainer::processEvents() {
 	tqApp->processEvents();
 }
 
+void NotifierContainer::popupClosed(KPassivePopup* popup) {
+	// Remove the popup from our list of popups
+	mPopupList.remove(popup);
+
+	if (mPopupList.isEmpty()) {
+		// Determine bottom of desktop
+		TQPoint cursorPos = TQCursor::pos();
+		TQRect r = KGlobalSettings::desktopGeometry(cursorPos);
+		mTopOfStack = r.height();
+		mRightOfStack = r.width();
+	}
+}
+
 #undef signals
 
 #include <dbus/dbus.h>
diff --git a/src/daemon/daemon.h b/src/daemon/daemon.h
index c0bc6fc..0839490 100644
--- a/src/daemon/daemon.h
+++ b/src/daemon/daemon.h
@@ -23,6 +23,7 @@
 #define NOTIFY_DAEMON_H
 
 #include <tqwidget.h>
+#include <kpassivepopup.h>
 
 class NotifierContainer : public TQWidget
 {
@@ -38,6 +39,12 @@ public:
 
 public slots:
 	void handleGTKMain();
+	void popupClosed(KPassivePopup*);
+
+private:
+	TQPtrList<KPassivePopup> mPopupList;
+	long mTopOfStack;
+	long mRightOfStack;
 };
 
 #include <glib.h>
-- 
cgit v1.2.3

