From c868a4d587ea8ebbdbe5ef4ccc525af9811acbf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Tue, 21 Dec 2010 21:19:13 +0100 Subject: Revert to SnarlNotifier on Windows. Use balloons as a fallback. diff --git a/SwifTools/Dock/WindowsDock.h b/SwifTools/Dock/WindowsDock.h new file mode 100644 index 0000000..dc298da --- /dev/null +++ b/SwifTools/Dock/WindowsDock.h @@ -0,0 +1,42 @@ +/* + * 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 +#include + +#include "SwifTools/Dock/Dock.h" +#include "SwifTools/Notifier/Notifier.h" + +namespace Swift { + class WindowsDock : public Dock { + public: + WindowsDock(QSystemTrayIcon* tray, Notifier* notifier) : tray(tray), notifier(notifier) {} + + virtual void setNumberOfPendingMessages(int i) { + if (notifier->isAvailable()) { + return; + } + + if (i > 0) { + std::string message = boost::lexical_cast(i) + " new message"; + if (i > 1) { + message += "s"; + } + message += " received."; + tray->showMessage("New messages", message.c_str(), QSystemTrayIcon::NoIcon); + } + else { + tray->showMessage("", "", QSystemTrayIcon::NoIcon, 0); + } + } + + private: + QSystemTrayIcon* tray; + Notifier* notifier; + }; +} diff --git a/SwifTools/Notifier/Notifier.h b/SwifTools/Notifier/Notifier.h index b7c705e..a8424bf 100644 --- a/SwifTools/Notifier/Notifier.h +++ b/SwifTools/Notifier/Notifier.h @@ -28,6 +28,10 @@ namespace Swift { const boost::filesystem::path& picture, boost::function callback) = 0; + virtual bool isAvailable() const { + return true; + } + protected: String typeToString(Type type); static std::vector getAllTypes(); diff --git a/SwifTools/Notifier/SnarlNotifier.cpp b/SwifTools/Notifier/SnarlNotifier.cpp index 9e82340..709128b 100644 --- a/SwifTools/Notifier/SnarlNotifier.cpp +++ b/SwifTools/Notifier/SnarlNotifier.cpp @@ -33,6 +33,11 @@ SnarlNotifier::~SnarlNotifier() { } } +bool SnarlNotifier::isAvailable() const { + return false; +} + + void SnarlNotifier::showMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picture, boost::function callback) { int timeout = (type == IncomingMessage || type == SystemMessage) ? DEFAULT_MESSAGE_NOTIFICATION_TIMEOUT_SECONDS : DEFAULT_STATUS_NOTIFICATION_TIMEOUT_SECONDS; int notificationID = snarl.EZNotify( diff --git a/SwifTools/Notifier/SnarlNotifier.h b/SwifTools/Notifier/SnarlNotifier.h index 8470326..d03882a 100644 --- a/SwifTools/Notifier/SnarlNotifier.h +++ b/SwifTools/Notifier/SnarlNotifier.h @@ -20,6 +20,7 @@ namespace Swift { ~SnarlNotifier(); virtual void showMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picture, boost::function callback); + virtual bool isAvailable() const; private: void handleMessageReceived(MSG* message); diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp index 7717b77..ef87aab 100644 --- a/Swift/QtUI/QtSwift.cpp +++ b/Swift/QtUI/QtSwift.cpp @@ -36,7 +36,7 @@ #include "SwifTools/Notifier/GrowlNotifier.h" #elif defined(HAVE_SNARL) #include "QtWin32NotifierWindow.h" -#include "SwifTools/Notifier/GNTPNotifier.h" +#include "SwifTools/Notifier/SnarlNotifier.h" #elif defined(SWIFTEN_PLATFORM_LINUX) #include "FreeDesktopNotifier.h" #else @@ -44,6 +44,8 @@ #endif #if defined(SWIFTEN_PLATFORM_MACOSX) #include "SwifTools/Dock/MacOSXDock.h" +#elif defined(SWIFTEN_PLATFORM_WINDOWS) +#include "SwifTools/Dock/WindowsDock.h" #else #include "SwifTools/Dock/NullDock.h" #endif @@ -105,15 +107,23 @@ QtSwift::QtSwift(po::variables_map options) : networkFactories_(&clientMainThrea #if defined(HAVE_GROWL) notifier_ = new GrowlNotifier(SWIFT_APPLICATION_NAME); #elif defined(HAVE_SNARL) - notifier_ = new GNTPNotifier(SWIFT_APPLICATION_NAME, applicationPathProvider_->getResourcePath("/images/logo-icon-128.png"), networkFactories_.getConnectionFactory()); + notifierWindow_ = new QtWin32NotifierWindow(); + notifier_ = new SnarlNotifier(SWIFT_APPLICATION_NAME, notifierWindow_, applicationPathProvider_->getResourcePath("/images/logo-icon-32.png")); #elif defined(SWIFTEN_PLATFORM_LINUX) notifier_ = new FreeDesktopNotifier(SWIFT_APPLICATION_NAME); #else notifier_ = new NullNotifier(); #endif + // Ugly, because the dock depends on the tray, but the temporary + // multi-account hack creates one tray per account. + QtSystemTray* systemTray = new QtSystemTray(); + systemTrays_.push_back(systemTray); + #if defined(SWIFTEN_PLATFORM_MACOSX) dock_ = new MacOSXDock(&cocoaApplication_); +#elif defined(SWIFTEN_PLATFORM_WINDOWS) + dock_ = new WindowsDock(systemTray->getQSystemTrayIcon(), notifier_); #else dock_ = new NullDock(); #endif @@ -123,9 +133,11 @@ QtSwift::QtSwift(po::variables_map options) : networkFactories_(&clientMainThrea } for (int i = 0; i < numberOfAccounts; i++) { - QtSystemTray* systemTray = new QtSystemTray(); - systemTrays_.push_back(systemTray); - QtUIFactory* uiFactory = new QtUIFactory(settings_, tabs_, splitter_, systemTray, chatWindowFactory_, startMinimized); + if (i > 0) { + // Don't add the first tray (see note above) + systemTrays_.push_back(new QtSystemTray()); + } + QtUIFactory* uiFactory = new QtUIFactory(settings_, tabs_, splitter_, systemTrays_[i], chatWindowFactory_, startMinimized); uiFactories_.push_back(uiFactory); MainController* mainController = new MainController( &clientMainThreadCaller_, @@ -152,6 +164,9 @@ QtSwift::QtSwift(po::variables_map options) : networkFactories_(&clientMainThrea QtSwift::~QtSwift() { delete notifier_; +#if defined(HAVE_SNARL) + delete notifierWindow_; +#endif delete autoUpdater_; foreach (QtUIFactory* factory, uiFactories_) { delete factory; diff --git a/Swift/QtUI/QtSwift.h b/Swift/QtUI/QtSwift.h index f241fd0..b674802 100644 --- a/Swift/QtUI/QtSwift.h +++ b/Swift/QtUI/QtSwift.h @@ -71,5 +71,8 @@ namespace Swift { #if defined(SWIFTEN_PLATFORM_MACOSX) CocoaApplication cocoaApplication_; #endif +#if defined(HAVE_SNARL) + Win32NotifierWindow* notifierWindow_; +#endif }; } diff --git a/Swift/QtUI/QtSystemTray.h b/Swift/QtUI/QtSystemTray.h index a49357e..cc7321b 100644 --- a/Swift/QtUI/QtSystemTray.h +++ b/Swift/QtUI/QtSystemTray.h @@ -22,6 +22,10 @@ namespace Swift { void setUnreadMessages(bool some); void setStatusType(StatusShow::Type type); void setConnecting(); + QSystemTrayIcon* getQSystemTrayIcon() { + return trayIcon_; + } + signals: void clicked(); private slots: -- cgit v0.10.2-6-g49f6