From 18c39e032395ee49796d330905caea4e28ef5608 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Fri, 28 Aug 2009 17:53:45 +0100
Subject: Show the hidden roster on system tray click.


diff --git a/Swift/QtUI/QtLoginWindowFactory.cpp b/Swift/QtUI/QtLoginWindowFactory.cpp
index 5d63ebc..c150892 100644
--- a/Swift/QtUI/QtLoginWindowFactory.cpp
+++ b/Swift/QtUI/QtLoginWindowFactory.cpp
@@ -3,8 +3,9 @@
 
 namespace Swift {
 
-QtLoginWindowFactory::QtLoginWindowFactory(QSplitter* splitter) {
+QtLoginWindowFactory::QtLoginWindowFactory(QSplitter* splitter, QtSystemTray* systemTray) : QObject() {
 	splitter_ = splitter;
+	systemTray_ = systemTray;
 }
 
 LoginWindow* QtLoginWindowFactory::createLoginWindow(const String& defaultJID, const String& defaultPassword, const String& defaultCertificate) {
@@ -12,6 +13,7 @@ LoginWindow* QtLoginWindowFactory::createLoginWindow(const String& defaultJID, c
 	if (splitter_) {
 		splitter_->insertWidget(0, window);
 	}
+	connect(systemTray_, SIGNAL(clicked()), window, SLOT(show()));
 	return window;
 }
 }
diff --git a/Swift/QtUI/QtLoginWindowFactory.h b/Swift/QtUI/QtLoginWindowFactory.h
index 617851e..7513ab6 100644
--- a/Swift/QtUI/QtLoginWindowFactory.h
+++ b/Swift/QtUI/QtLoginWindowFactory.h
@@ -2,16 +2,19 @@
 #define SWIFT_QtLoginWindowFactory_H
 
 #include "Swift/Controllers/LoginWindowFactory.h"
+#include "Swift/QtUI/QtSystemTray.h"
 
 #include <QSplitter>
 
 namespace Swift {
-	class QtLoginWindowFactory : public LoginWindowFactory{
+	class QtLoginWindowFactory : public QObject, public LoginWindowFactory {
+		Q_OBJECT
 		public:
-			QtLoginWindowFactory(QSplitter* splitter);
+			QtLoginWindowFactory(QSplitter* splitter, QtSystemTray* systemTray);
 			LoginWindow* createLoginWindow(const String& defaultJID, const String& defaultPassword, const String& defaultCertificate);
 		private:
 			QSplitter* splitter_;
+			QtSystemTray* systemTray_;
 	};
 }
 
diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp
index 00efc17..90742a5 100644
--- a/Swift/QtUI/QtSwift.cpp
+++ b/Swift/QtUI/QtSwift.cpp
@@ -27,10 +27,10 @@ QtSwift::QtSwift(bool netbookMode) {
 		splitter_ = NULL;
 	}
 	treeWidgetFactory_ = new QtTreeWidgetFactory(); 
-	loginWindowFactory_ = new QtLoginWindowFactory(splitter_);
-	rosterWindowFactory_ = new QtMainWindowFactory(treeWidgetFactory_);
-	chatWindowFactory_ = new QtChatWindowFactory(treeWidgetFactory_, splitter_);
 	systemTray_ = new QtSystemTray();
+	loginWindowFactory_ = new QtLoginWindowFactory(splitter_, systemTray_);
+	chatWindowFactory_ = new QtChatWindowFactory(treeWidgetFactory_, splitter_);
+	rosterWindowFactory_ = new QtMainWindowFactory(treeWidgetFactory_);
 	soundPlayer_ = new QtSoundPlayer();
 	QCoreApplication::setApplicationName("Swift");
 	QCoreApplication::setOrganizationName("Swift");
diff --git a/Swift/QtUI/QtSystemTray.cpp b/Swift/QtUI/QtSystemTray.cpp
index f1c8e27..e85f13f 100644
--- a/Swift/QtUI/QtSystemTray.cpp
+++ b/Swift/QtUI/QtSystemTray.cpp
@@ -5,8 +5,9 @@
 #include <QResource>
 
 namespace Swift {
-QtSystemTray::QtSystemTray() : standardIcon_(":icons/tray-standard.png"), newMessageIcon_(":icons/new-chat.png") {
+QtSystemTray::QtSystemTray() : QObject(), standardIcon_(":icons/tray-standard.png"), newMessageIcon_(":icons/new-chat.png") {
 	trayIcon_ = new QSystemTrayIcon(standardIcon_);
+	connect(trayIcon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(handleIconActivated(QSystemTrayIcon::ActivationReason)));
 	trayIcon_->show();
 }
 
@@ -18,4 +19,9 @@ void QtSystemTray::setUnreadMessages(bool some) {
 	trayIcon_->setIcon(some ? newMessageIcon_ : standardIcon_);
 }
 
+void QtSystemTray::handleIconActivated(QSystemTrayIcon::ActivationReason reason) {
+	if (reason == QSystemTrayIcon::Trigger) {
+		emit clicked();
+	}
+}
 }
diff --git a/Swift/QtUI/QtSystemTray.h b/Swift/QtUI/QtSystemTray.h
index 40cc540..4ef55d9 100644
--- a/Swift/QtUI/QtSystemTray.h
+++ b/Swift/QtUI/QtSystemTray.h
@@ -7,11 +7,16 @@
 class QIcon;
 
 namespace Swift {
-	class QtSystemTray : public SystemTray {
+	class QtSystemTray : public QObject, public SystemTray {
+		Q_OBJECT
 		public:
 			QtSystemTray();
 			~QtSystemTray();
 			void setUnreadMessages(bool some);
+		signals:
+			void clicked();
+		private slots:
+			void handleIconActivated(QSystemTrayIcon::ActivationReason reason);
 		private:
 			QSystemTrayIcon* trayIcon_;
 			QIcon standardIcon_;
-- 
cgit v0.10.2-6-g49f6