diff options
| author | Kevin Smith <git@kismith.co.uk> | 2010-10-05 18:24:02 (GMT) | 
|---|---|---|
| committer | Kevin Smith <git@kismith.co.uk> | 2010-10-05 18:24:02 (GMT) | 
| commit | bfeca3cc938e325bf2cc2d9105c719feb1fe28ee (patch) | |
| tree | 8089a181b678912432f0ae4a61759b92566c62fb | |
| parent | 6cdd48b30526761f5c6365496e30580ed3bd8a82 (diff) | |
| download | swift-contrib-bfeca3cc938e325bf2cc2d9105c719feb1fe28ee.zip swift-contrib-bfeca3cc938e325bf2cc2d9105c719feb1fe28ee.tar.bz2 | |
Create 'Enable notifications' menu on Linux.
I've not actually tested this on Linux...
Resolves: #594
| -rw-r--r-- | SwifTools/Notifier/Notifier.h | 2 | ||||
| -rw-r--r-- | Swift/Controllers/EventNotifier.cpp | 18 | ||||
| -rw-r--r-- | Swift/Controllers/EventNotifier.h | 8 | ||||
| -rw-r--r-- | Swift/Controllers/MainController.cpp | 2 | ||||
| -rw-r--r-- | Swift/Controllers/UIEvents/ToggleNotificationsUIEvent.h | 19 | ||||
| -rw-r--r-- | Swift/QtUI/QtLoginWindow.cpp | 16 | ||||
| -rw-r--r-- | Swift/QtUI/QtLoginWindow.h | 2 | 
7 files changed, 64 insertions, 3 deletions
| diff --git a/SwifTools/Notifier/Notifier.h b/SwifTools/Notifier/Notifier.h index ad9b324..76d6382 100644 --- a/SwifTools/Notifier/Notifier.h +++ b/SwifTools/Notifier/Notifier.h @@ -33,6 +33,8 @@ namespace Swift {  				enabled = b;  			} +			bool getEnabled() {return enabled;} +  		private:  			virtual void doShowMessage(  				Type type, diff --git a/Swift/Controllers/EventNotifier.cpp b/Swift/Controllers/EventNotifier.cpp index 7a293b6..7743d6f 100644 --- a/Swift/Controllers/EventNotifier.cpp +++ b/Swift/Controllers/EventNotifier.cpp @@ -16,11 +16,17 @@  #include "Swift/Controllers/XMPPEvents/MessageEvent.h"  #include "Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h"  #include "Swift/Controllers/XMPPEvents/ErrorEvent.h" +#include "Swift/Controllers/UIEvents/UIEventStream.h" +#include "Swift/Controllers/UIEvents/ToggleNotificationsUIEvent.h" +#include "Swiften/Settings/SettingsProvider.h"  namespace Swift { -EventNotifier::EventNotifier(EventController* eventController, Notifier* notifier, AvatarManager* avatarManager, NickResolver* nickResolver) : eventController(eventController), notifier(notifier), avatarManager(avatarManager), nickResolver(nickResolver) { +EventNotifier::EventNotifier(EventController* eventController, Notifier* notifier, AvatarManager* avatarManager, NickResolver* nickResolver, UIEventStream* uiEvents, SettingsProvider* settings) : eventController(eventController), notifier(notifier), avatarManager(avatarManager), nickResolver(nickResolver), uiEvents(uiEvents), settings(settings) {  	eventController->onEventQueueEventAdded.connect(boost::bind(&EventNotifier::handleEventAdded, this, _1)); +	bool enabled = settings->getBoolSetting("showNotifications", true); +	notifier->setEnabled(enabled); +	uiEvents->send(boost::shared_ptr<ToggleNotificationsUIEvent>(new ToggleNotificationsUIEvent(enabled)));  }  EventNotifier::~EventNotifier() { @@ -49,4 +55,14 @@ void EventNotifier::handleNotificationActivated(JID jid) {  	onNotificationActivated(jid);  } +void EventNotifier::handleUIEvent(boost::shared_ptr<UIEvent> event) { +	boost::shared_ptr<ToggleNotificationsUIEvent> notificationsEvent = boost::dynamic_pointer_cast<ToggleNotificationsUIEvent>(event); +	if (notificationsEvent) { +		bool enabled = notificationsEvent->getEnabled(); +		if (enabled != notifier->getEnabled()) { +			notifier->setEnabled(enabled); +			settings->storeBool("showNotifications", enabled); +		} +	} +}  } diff --git a/Swift/Controllers/EventNotifier.h b/Swift/Controllers/EventNotifier.h index 8b4dc23..ae01f24 100644 --- a/Swift/Controllers/EventNotifier.h +++ b/Swift/Controllers/EventNotifier.h @@ -11,6 +11,7 @@  #include "SwifTools/Notifier/Notifier.h"  #include "Swiften/Base/boost_bsignals.h"  #include "Swift/Controllers/XMPPEvents/StanzaEvent.h" +#include "Swift/Controllers/UIEvents/UIEvent.h"  #include "Swiften/JID/JID.h"  namespace Swift { @@ -19,10 +20,12 @@ namespace Swift {  	class AvatarManager;  	class NickResolver;  	class JID; +	class UIEventStream; +	class SettingsProvider;  	class EventNotifier {  		public: -			EventNotifier(EventController* eventController, Notifier* notifier, AvatarManager* avatarManager, NickResolver* nickResolver); +			EventNotifier(EventController* eventController, Notifier* notifier, AvatarManager* avatarManager, NickResolver* nickResolver, UIEventStream* uiEvents, SettingsProvider* settings);  			~EventNotifier();  			boost::signal<void (const JID&)> onNotificationActivated; @@ -30,11 +33,14 @@ namespace Swift {  		private:  			void handleEventAdded(boost::shared_ptr<StanzaEvent>);  			void handleNotificationActivated(JID jid); +			void handleUIEvent(boost::shared_ptr<UIEvent> event);  		private:  			EventController* eventController;  			Notifier* notifier;  			AvatarManager* avatarManager;  			NickResolver* nickResolver; +			UIEventStream* uiEvents; +			SettingsProvider* settings;  	};  } diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index 3cf2907..ed28c52 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -402,7 +402,7 @@ 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_ = new EventNotifier(eventController_, notifier_, avatarManager_, nickResolver_, uiEventStream_, settings_);  		eventNotifier_->onNotificationActivated.connect(boost::bind(&MainController::handleNotificationClicked, this, _1));  		client_->onDataRead.connect(boost::bind(  				&XMLConsoleController::handleDataRead, xmlConsoleController_, _1)); diff --git a/Swift/Controllers/UIEvents/ToggleNotificationsUIEvent.h b/Swift/Controllers/UIEvents/ToggleNotificationsUIEvent.h new file mode 100644 index 0000000..0f7acc8 --- /dev/null +++ b/Swift/Controllers/UIEvents/ToggleNotificationsUIEvent.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swift/Controllers/UIEvents/UIEvent.h" + +namespace Swift { +	class ToggleNotificationsUIEvent : public UIEvent { +		public: +			ToggleNotificationsUIEvent(bool enable) : enabled_(enable) {}; +			bool getEnabled() {return enabled_;}; +		private: +			bool enabled_; +	}; +} diff --git a/Swift/QtUI/QtLoginWindow.cpp b/Swift/QtUI/QtLoginWindow.cpp index 655e3b9..83a6ba0 100644 --- a/Swift/QtUI/QtLoginWindow.cpp +++ b/Swift/QtUI/QtLoginWindow.cpp @@ -24,6 +24,7 @@  #include "Swift/Controllers/UIEvents/UIEventStream.h"  #include "Swift/Controllers/UIEvents/RequestXMLConsoleUIEvent.h"  #include "Swift/Controllers/UIEvents/ToggleSoundsUIEvent.h" +#include "Swift/Controllers/UIEvents/ToggleNotificationsUIEvent.h"  #include "Swiften/Base/Platform.h"  #include "QtAboutWidget.h" @@ -149,6 +150,14 @@ QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream) : QMainWindow() {  	connect(toggleSoundsAction_, SIGNAL(toggled(bool)), SLOT(handleToggleSounds(bool)));  	generalMenu_->addAction(toggleSoundsAction_); +	toggleNotificationsAction_ = new QAction(tr("Show Notifications"), this); +	toggleNotificationsAction_->setCheckable(true); +	toggleNotificationsAction_->setChecked(true); +	connect(toggleNotificationsAction_, SIGNAL(toggled(bool)), SLOT(handleToggleNotifications(bool))); +#ifdef SWIFTEN_PLATFORM_LINUX +	generalMenu_->addAction(toggleNotificationsAction_); +#endif +  	QAction* quitAction = new QAction("Quit", this);  	connect(quitAction, SIGNAL(triggered()), SLOT(handleQuit())); @@ -164,6 +173,10 @@ void QtLoginWindow::handleUIEvent(boost::shared_ptr<UIEvent> event) {  	if (soundEvent) {  		toggleSoundsAction_->setChecked(soundEvent->getEnabled());  	} +	boost::shared_ptr<ToggleNotificationsUIEvent> notificationsEvent = boost::dynamic_pointer_cast<ToggleNotificationsUIEvent>(event); +	if (notificationsEvent) { +		toggleNotificationsAction_->setChecked(notificationsEvent->getEnabled()); +	}  }  /** @@ -298,6 +311,9 @@ void QtLoginWindow::handleToggleSounds(bool enabled) {  	uiEventStream_->send(boost::shared_ptr<ToggleSoundsUIEvent>(new ToggleSoundsUIEvent(enabled)));  } +void QtLoginWindow::handleToggleNotifications(bool enabled) { +	uiEventStream_->send(boost::shared_ptr<ToggleNotificationsUIEvent>(new ToggleNotificationsUIEvent(enabled))); +}  void QtLoginWindow::handleQuit() {  	QApplication::quit(); diff --git a/Swift/QtUI/QtLoginWindow.h b/Swift/QtUI/QtLoginWindow.h index c84033a..d9484b7 100644 --- a/Swift/QtUI/QtLoginWindow.h +++ b/Swift/QtUI/QtLoginWindow.h @@ -48,6 +48,7 @@ namespace Swift {  			void handleQuit();  			void handleShowXMLConsole();  			void handleToggleSounds(bool enabled); +			void handleToggleNotifications(bool enabled);  			void handleAbout();  			void bringToFront();  			void handleUsernameTextChanged(); @@ -75,6 +76,7 @@ namespace Swift {  			QMenu* generalMenu_;  			QMenu* toolsMenu_;  			QAction* toggleSoundsAction_; +			QAction* toggleNotificationsAction_;  			UIEventStream* uiEventStream_;  			QPointer<QtAboutWidget> aboutDialog_;  	}; | 
 Swift
 Swift