diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-09-15 19:46:15 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-09-15 19:46:15 (GMT) |
commit | d0367c8477ad2e9993ed5ea6acb2444f21f8f971 (patch) | |
tree | a528dd7725271179e8245ef3875e03aedde23738 /Swift | |
parent | 8e5d1a11824d7a0900feb44ed5b5464d8d94ab2a (diff) | |
download | swift-d0367c8477ad2e9993ed5ea6acb2444f21f8f971.zip swift-d0367c8477ad2e9993ed5ea6acb2444f21f8f971.tar.bz2 |
Added EventNotifier.
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/Controllers/EventNotifier.cpp | 52 | ||||
-rw-r--r-- | Swift/Controllers/EventNotifier.h | 40 | ||||
-rw-r--r-- | Swift/Controllers/MainController.cpp | 6 | ||||
-rw-r--r-- | Swift/Controllers/MainController.h | 2 | ||||
-rw-r--r-- | Swift/Controllers/PresenceNotifier.cpp | 3 | ||||
-rw-r--r-- | Swift/Controllers/SConscript | 1 |
6 files changed, 101 insertions, 3 deletions
diff --git a/Swift/Controllers/EventNotifier.cpp b/Swift/Controllers/EventNotifier.cpp new file mode 100644 index 0000000..09ad1da --- /dev/null +++ b/Swift/Controllers/EventNotifier.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swift/Controllers/EventNotifier.h" + +#include <boost/bind.hpp> + +#include "Swift/Controllers/EventController.h" +#include "SwifTools/Notifier/Notifier.h" +#include "Swiften/Avatars/AvatarManager.h" +#include "Swift/Controllers/NickResolver.h" +#include "Swiften/JID/JID.h" +#include "Swiften/Events/MessageEvent.h" +#include "Swiften/Events/SubscriptionRequestEvent.h" +#include "Swiften/Events/ErrorEvent.h" + +namespace Swift { + +EventNotifier::EventNotifier(EventController* eventController, Notifier* notifier, AvatarManager* avatarManager, NickResolver* nickResolver) : eventController(eventController), notifier(notifier), avatarManager(avatarManager), nickResolver(nickResolver) { + eventController->onEventQueueEventAdded.connect(boost::bind(&EventNotifier::handleEventAdded, this, _1)); +} + +EventNotifier::~EventNotifier() { + eventController->onEventQueueEventAdded.disconnect(boost::bind(&EventNotifier::handleEventAdded, this, _1)); +} + +void EventNotifier::handleEventAdded(boost::shared_ptr<StanzaEvent> event) { + if (boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event)) { + JID jid = messageEvent->getStanza()->getFrom(); + String title = nickResolver->jidToNick(jid); + notifier->showMessage(Notifier::IncomingMessage, title, messageEvent->getStanza()->getBody(), avatarManager->getAvatarPath(jid), boost::bind(&EventNotifier::handleNotificationActivated, this, jid)); + } + else if(boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event)) { + JID jid = subscriptionEvent->getJID(); + String title = ""; + String message = nickResolver->jidToNick(jid) + " wants to add you to his/her roster"; + notifier->showMessage(Notifier::SystemMessage, title, message, boost::filesystem::path(), boost::function<void()>()); + } + else if(boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event)) { + notifier->showMessage(Notifier::SystemMessage, "Error", errorEvent->getText(), boost::filesystem::path(), boost::function<void()>()); + } +} + + +void EventNotifier::handleNotificationActivated(JID jid) { + onNotificationActivated(jid); +} + +} diff --git a/Swift/Controllers/EventNotifier.h b/Swift/Controllers/EventNotifier.h new file mode 100644 index 0000000..49c2c6c --- /dev/null +++ b/Swift/Controllers/EventNotifier.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include "SwifTools/Notifier/Notifier.h" +#include "Swiften/Base/boost_bsignals.h" +#include "Swiften/Events/StanzaEvent.h" +#include "Swiften/JID/JID.h" + +namespace Swift { + class EventController; + class Notifier; + class AvatarManager; + class NickResolver; + class JID; + + class EventNotifier { + public: + EventNotifier(EventController* eventController, Notifier* notifier, AvatarManager* avatarManager, NickResolver* nickResolver); + ~EventNotifier(); + + boost::signal<void (const JID&)> onNotificationActivated; + + private: + void handleEventAdded(boost::shared_ptr<StanzaEvent>); + void handleNotificationActivated(JID jid); + + private: + EventController* eventController; + Notifier* notifier; + AvatarManager* avatarManager; + NickResolver* nickResolver; + }; +} diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index f7f2155..11001b3 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -38,6 +38,7 @@ #include "Swiften/Roster/XMPPRosterController.h" #include "Swift/Controllers/UIEvents/UIEventStream.h" #include "Swift/Controllers/PresenceNotifier.h" +#include "Swift/Controllers/EventNotifier.h" #include "SwifTools/Dock/Dock.h" #include "Swiften/Base/foreach.h" #include "Swiften/Base/String.h" @@ -107,6 +108,7 @@ MainController::MainController( capsManager_ = NULL; entityCapsManager_ = NULL; presenceNotifier_ = NULL; + eventNotifier_ = NULL; nickResolver_ = NULL; rosterController_ = NULL; xmppRosterController_ = NULL; @@ -197,6 +199,8 @@ void MainController::resetClient() { chatsManager_ = NULL; delete rosterController_; rosterController_ = NULL; + delete eventNotifier_; + eventNotifier_ = NULL; delete presenceNotifier_; presenceNotifier_ = NULL; delete entityCapsManager_; @@ -394,6 +398,8 @@ void MainController::performLoginFromCachedCredentials() { entityCapsManager_ = new EntityCapsManager(capsManager_, client_); presenceNotifier_ = new PresenceNotifier(client_, notifier_, mucRegistry_, avatarManager_, nickResolver_, presenceOracle_, &timerFactory_); presenceNotifier_->onNotificationActivated.connect(boost::bind(&MainController::handleNotificationClicked, this, _1)); + eventNotifier_ = new EventNotifier(eventController_, notifier_, avatarManager_, nickResolver_); + eventNotifier_->onNotificationActivated.connect(boost::bind(&MainController::handleNotificationClicked, this, _1)); client_->onDataRead.connect(boost::bind( &XMLConsoleController::handleDataRead, xmlConsoleController_, _1)); client_->onDataWritten.connect(boost::bind( diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h index df12a17..63a6063 100644 --- a/Swift/Controllers/MainController.h +++ b/Swift/Controllers/MainController.h @@ -57,6 +57,7 @@ namespace Swift { class Notifier; class PresenceOracle; class PresenceNotifier; + class EventNotifier; class SystemTray; class SystemTrayController; class SoundEventController; @@ -140,6 +141,7 @@ namespace Swift { Dock* dock_; Notifier* notifier_; PresenceNotifier* presenceNotifier_; + EventNotifier* eventNotifier_; XMPPRosterController* xmppRosterController_; RosterController* rosterController_; EventController* eventController_; diff --git a/Swift/Controllers/PresenceNotifier.cpp b/Swift/Controllers/PresenceNotifier.cpp index 74cb4b0..466262d 100644 --- a/Swift/Controllers/PresenceNotifier.cpp +++ b/Swift/Controllers/PresenceNotifier.cpp @@ -86,9 +86,6 @@ void PresenceNotifier::handleStanzaChannelAvailableChanged(bool available) { void PresenceNotifier::showNotification(const JID& jid, Notifier::Type type) { String name = nickResolver->jidToNick(jid); - if (name.isEmpty()) { - name = jid.toBare().toString(); - } String title = name + " (" + getStatusType(jid) + ")"; String message = getStatusMessage(jid); notifier->showMessage(type, title, message, avatarManager->getAvatarPath(jid), boost::bind(&PresenceNotifier::handleNotificationActivated, this, jid)); diff --git a/Swift/Controllers/SConscript b/Swift/Controllers/SConscript index 41461bd..1a850b1 100644 --- a/Swift/Controllers/SConscript +++ b/Swift/Controllers/SConscript @@ -36,6 +36,7 @@ if env["SCONS_STAGE"] == "build" : "XMLConsoleController.cpp", "StatusTracker.cpp", "PresenceNotifier.cpp", + "EventNotifier.cpp", "UIEvents/UIEvent.cpp", "UIInterfaces/XMLConsoleWidget.cpp", "UIInterfaces/ChatListWindow.cpp", |