From 9a457c621bd75a9929cc0616b7659dba2945fdac Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Thu, 18 Jun 2009 21:34:41 +0100 Subject: System Tray We need to have a look at the icons somewhat, but these will do for the second. diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index ff53450..e9177f8 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -17,6 +17,8 @@ #include "Swift/Controllers/MUCController.h" #include "Swift/Controllers/NickResolver.h" #include "Swift/Controllers/RosterController.h" +#include "Swift/Controllers/SystemTray.h" +#include "Swift/Controllers/SystemTrayController.h" #include "Swift/Controllers/XMPPRosterController.h" #include "Swiften/Base/foreach.h" #include "Swiften/Base/String.h" @@ -40,13 +42,14 @@ static const String CLIENT_NODE = "http://swift.im"; typedef std::pair JIDChatControllerPair; typedef std::pair JIDMUCControllerPair; -MainController::MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, TreeWidgetFactory *treeWidgetFactory, SettingsProvider *settings, Application* application) +MainController::MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, TreeWidgetFactory *treeWidgetFactory, SettingsProvider *settings, Application* application, SystemTray* systemTray) : client_(NULL), chatWindowFactory_(chatWindowFactory), mainWindowFactory_(mainWindowFactory), loginWindowFactory_(loginWindowFactory), treeWidgetFactory_(treeWidgetFactory), settings_(settings), xmppRosterController_(NULL), rosterController_(NULL), loginWindow_(NULL), clientVersionResponder_(NULL), nickResolver_(NULL), discoResponder_(NULL), serverDiscoInfo_(new DiscoInfo()), presenceOracle_(NULL) { application_ = application; eventController_ = new EventController(); eventController_->onEventQueueLengthChange.connect(boost::bind(&MainController::handleEventQueueLengthChange, this, _1)); + systemTrayController_ = new SystemTrayController(eventController_, systemTray); loginWindow_ = loginWindowFactory_->createLoginWindow(settings->getStringSetting("jid"), settings->getStringSetting("pass"), settings->getStringSetting("certificate")); loginWindow_->onLoginRequest.connect(boost::bind(&MainController::handleLoginRequest, this, _1, _2, _3, _4)); } @@ -65,6 +68,7 @@ MainController::~MainController() { delete presenceOracle_; delete nickResolver_; delete client_; + delete systemTrayController_; } void MainController::handleConnected() { diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h index e09d4fa..8b3a702 100644 --- a/Swift/Controllers/MainController.h +++ b/Swift/Controllers/MainController.h @@ -37,10 +37,12 @@ namespace Swift { class TreeWidgetFactory; class MUCController; class PresenceOracle; + class SystemTray; + class SystemTrayController; class MainController { public: - MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, TreeWidgetFactory* treeWidgetFactory, SettingsProvider *settings, Application* application); + MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, TreeWidgetFactory* treeWidgetFactory, SettingsProvider *settings, Application* application, SystemTray* systemTray); ~MainController(); @@ -79,6 +81,7 @@ namespace Swift { std::map chatControllers_; boost::shared_ptr serverDiscoInfo_; PresenceOracle* presenceOracle_; + SystemTrayController* systemTrayController_; }; } #endif diff --git a/Swift/Controllers/Makefile.inc b/Swift/Controllers/Makefile.inc index ff3192e..1a6ab4e 100644 --- a/Swift/Controllers/Makefile.inc +++ b/Swift/Controllers/Makefile.inc @@ -6,7 +6,8 @@ SWIFT_CONTROLLERS_SOURCES += \ Swift/Controllers/RosterController.cpp \ Swift/Controllers/XMPPRosterController.cpp \ Swift/Controllers/MUCController.cpp \ - Swift/Controllers/EventController.cpp + Swift/Controllers/EventController.cpp \ + Swift/Controllers/SystemTrayController.cpp include Swift/Controllers/UnitTest/Makefile.inc diff --git a/Swift/Controllers/SystemTray.h b/Swift/Controllers/SystemTray.h new file mode 100644 index 0000000..89ae614 --- /dev/null +++ b/Swift/Controllers/SystemTray.h @@ -0,0 +1,9 @@ +#pragma once + +namespace Swift { + class SystemTray { + public: + virtual ~SystemTray(){}; + virtual void setUnreadMessages(bool some) = 0; + }; +} diff --git a/Swift/Controllers/SystemTrayController.cpp b/Swift/Controllers/SystemTrayController.cpp new file mode 100644 index 0000000..8caf79a --- /dev/null +++ b/Swift/Controllers/SystemTrayController.cpp @@ -0,0 +1,21 @@ +#include "Swift/Controllers/SystemTrayController.h" + +#include + +#include "Swift/Controllers/EventController.h" +#include "Swift/Controllers/SystemTray.h" + +namespace Swift { + +SystemTrayController::SystemTrayController(EventController* eventController, SystemTray* systemTray) { + eventController_ = eventController; + systemTray_ = systemTray; + eventController_->onEventQueueLengthChange.connect(boost::bind(&SystemTrayController::handleEventQueueLengthChange, this, _1)); +} + +void SystemTrayController::handleEventQueueLengthChange(int length) { + systemTray_->setUnreadMessages(length > 0 ? true : false); +} + + +} diff --git a/Swift/Controllers/SystemTrayController.h b/Swift/Controllers/SystemTrayController.h new file mode 100644 index 0000000..1c6d270 --- /dev/null +++ b/Swift/Controllers/SystemTrayController.h @@ -0,0 +1,14 @@ +#pragma once + +namespace Swift { + class EventController; + class SystemTray; + class SystemTrayController { + public: + SystemTrayController(EventController* eventController, SystemTray* systemTray); + private: + void handleEventQueueLengthChange(int length); + EventController* eventController_; + SystemTray* systemTray_; + }; +} diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp index b8b45a1..6aab3b4 100644 --- a/Swift/QtUI/QtSwift.cpp +++ b/Swift/QtUI/QtSwift.cpp @@ -4,6 +4,7 @@ #include "QtChatWindowFactory.h" #include "QtMainWindowFactory.h" #include "QtTreeWidgetFactory.h" +#include "QtSystemTray.h" #include @@ -22,12 +23,13 @@ QtSwift::QtSwift() : chatWindowFactory_(new QtChatWindowFactory(treeWidgetFactory_)), rosterWindowFactory_(new QtMainWindowFactory(treeWidgetFactory_)), loginWindowFactory_(new QtLoginWindowFactory()) { + systemTray_ = new QtSystemTray(); QCoreApplication::setApplicationName("Swift"); QCoreApplication::setOrganizationName("Swift"); QCoreApplication::setOrganizationDomain("swift.im"); settings_ = new QtSettingsProvider(); application_ = new PlatformApplication("Swift"); - mainController_ = new MainController(chatWindowFactory_, rosterWindowFactory_, loginWindowFactory_, treeWidgetFactory_, settings_, application_); + mainController_ = new MainController(chatWindowFactory_, rosterWindowFactory_, loginWindowFactory_, treeWidgetFactory_, settings_, application_, systemTray_); } QtSwift::~QtSwift() { @@ -38,6 +40,7 @@ QtSwift::~QtSwift() { delete mainController_; delete settings_; delete application_; + delete systemTray_; } } diff --git a/Swift/QtUI/QtSwift.h b/Swift/QtUI/QtSwift.h index 5bfd62c..5c6656a 100644 --- a/Swift/QtUI/QtSwift.h +++ b/Swift/QtUI/QtSwift.h @@ -15,7 +15,8 @@ namespace Swift { class QtMainWindowFactory; class QtLoginWindowFactory; class QtTreeWidgetFactory; - + class QtSystemTray; + class QtSwift : public QObject { Q_OBJECT public: @@ -29,6 +30,7 @@ namespace Swift { QtLoginWindowFactory *loginWindowFactory_; QtMainEventLoop clientMainThreadCaller_; QtSettingsProvider *settings_; + QtSystemTray* systemTray_; Application* application_; }; } diff --git a/Swift/QtUI/QtSystemTray.cpp b/Swift/QtUI/QtSystemTray.cpp new file mode 100644 index 0000000..b22da6b --- /dev/null +++ b/Swift/QtUI/QtSystemTray.cpp @@ -0,0 +1,21 @@ +#include "Swift/QtUI/QtSystemTray.h" + +#include +#include +#include + +namespace Swift { +QtSystemTray::QtSystemTray() : standardIcon_(":icons/tray-standard.png"), newMessageIcon_(":icons/new-chat.png") { + trayIcon_ = new QSystemTrayIcon(standardIcon_); + trayIcon_->show(); +} + +QtSystemTray::~QtSystemTray() { + delete trayIcon_; +} + +void QtSystemTray::setUnreadMessages(bool some) { + trayIcon_->setIcon(some ? newMessageIcon_ : standardIcon_); +} + +} \ No newline at end of file diff --git a/Swift/QtUI/QtSystemTray.h b/Swift/QtUI/QtSystemTray.h new file mode 100644 index 0000000..40cc540 --- /dev/null +++ b/Swift/QtUI/QtSystemTray.h @@ -0,0 +1,20 @@ +#pragma once + +#include "Swift/Controllers/SystemTray.h" + +#include + +class QIcon; + +namespace Swift { + class QtSystemTray : public SystemTray { + public: + QtSystemTray(); + ~QtSystemTray(); + void setUnreadMessages(bool some); + private: + QSystemTrayIcon* trayIcon_; + QIcon standardIcon_; + QIcon newMessageIcon_; + }; +} diff --git a/Swift/QtUI/Swift.pro b/Swift/QtUI/Swift.pro index fbf5537..6221fa8 100644 --- a/Swift/QtUI/Swift.pro +++ b/Swift/QtUI/Swift.pro @@ -60,6 +60,7 @@ HEADERS += \ QtTreeWidgetItem.h \ QtChatView.h \ QtChatTabs.h \ + QtSystemTray.h \ QtTabbable.h \ ChatSnippet.h \ MessageSnippet.h \ @@ -80,6 +81,7 @@ SOURCES += \ QtTreeWidget.cpp \ QtChatView.cpp \ QtChatTabs.cpp \ + QtSystemTray.cpp \ ChatSnippet.cpp \ MessageSnippet.cpp \ SystemMessageSnippet.cpp diff --git a/Swift/QtUI/Swift.qrc b/Swift/QtUI/Swift.qrc index 2db382e..4e3b9df 100644 --- a/Swift/QtUI/Swift.qrc +++ b/Swift/QtUI/Swift.qrc @@ -5,5 +5,7 @@ ../../resources/icons/certificate.png ../../resources/icons/error.png ../../resources/icons/avatar.png + ../../resources/icons/tray-standard.png + ../../resources/icons/new-chat.png diff --git a/resources/icons/new-chat.png b/resources/icons/new-chat.png new file mode 100644 index 0000000..ca79895 Binary files /dev/null and b/resources/icons/new-chat.png differ diff --git a/resources/icons/tray-standard.png b/resources/icons/tray-standard.png new file mode 100644 index 0000000..00374a6 Binary files /dev/null and b/resources/icons/tray-standard.png differ -- cgit v0.10.2-6-g49f6