From 244a545018686eccc1cc9ccf9bb8880a5426accf Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Tue, 1 Nov 2011 19:25:40 +0000 Subject: [PATCH] Mail daemon notifications, round 2: * Use the proper identifier for each notification window : 2 per account for sending/receiving, and a global one to show the "n message received" message. * Use the mail daemon icon on the windows instead of the default ones * Shuffle the text in the windows a bit so it makes more sense * Use the settings from the mail preflet for showing or not the window. The meaning of "always" changes a bit, since it is not possible to have a "forever" timeout with the notification server (and that would be rather annoying). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43077 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/mail/MailDaemon.cpp | 27 +++++++++++++++--------- src/servers/mail/MailDaemon.h | 1 + src/servers/mail/Notifier.cpp | 37 ++++++++++++++++++++++++--------- src/servers/mail/Notifier.h | 4 +++- 4 files changed, 48 insertions(+), 21 deletions(-) diff --git a/src/servers/mail/MailDaemon.cpp b/src/servers/mail/MailDaemon.cpp index 0505e790b0..ebc03c81fb 100644 --- a/src/servers/mail/MailDaemon.cpp +++ b/src/servers/mail/MailDaemon.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -150,8 +151,6 @@ MailDaemonApp::ReadyToRun() fNewMessages = 0; while (roster.GetNextVolume(&volume) == B_OK) { - //{char name[255];volume.GetName(name);printf("Volume: %s\n",name);} - BQuery* query = new BQuery; query->SetTarget(this); @@ -192,8 +191,16 @@ MailDaemonApp::ReadyToRun() fCentralBeep = false; fNotification = new BNotification(B_INFORMATION_NOTIFICATION); - fNotification->SetApplication("Mail daemon"); + fNotification->SetApplication(B_TRANSLATE("Mail status")); fNotification->SetTitle(string); + fNotification->SetMessageID("daemon_status"); + + app_info info; + be_roster->GetAppInfo(B_MAIL_DAEMON_SIGNATURE, &info); + BBitmap icon(BRect(0, 0, 32, 32), B_RGBA32); + BNode node(&info.ref); + BIconUtils::GetVectorIcon(&node, "BEOS:ICON", &icon); + fNotification->SetIcon(&icon); fLEDAnimation = new LEDAnimation; SetPulseRate(1000000); @@ -203,8 +210,6 @@ MailDaemonApp::ReadyToRun() void MailDaemonApp::RefsReceived(BMessage* message) { - be_roster->Notify(*fNotification, 3); - entry_ref ref; for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) { BNode node(&ref); @@ -260,12 +265,12 @@ MailDaemonApp::MessageReceived(BMessage* msg) break; case kMsgSetStatusWindowMode: // when to show the status window - {/* + { int32 mode; if (msg->FindInt32("ShowStatusWindow", &mode) == B_OK) - fMailStatusWindow->SetShowCriterion(mode); + fNotifyMode = mode; break; - */} + } case kMsgMarkMessageAsRead: { @@ -384,6 +389,8 @@ MailDaemonApp::MessageReceived(BMessage* msg) string << B_TRANSLATE("No new messages."); fNotification->SetTitle(string.String()); + if (fNotifyMode != B_MAIL_SHOW_STATUS_WINDOW_NEVER) + be_roster->Notify(*fNotification); break; } @@ -645,7 +652,7 @@ MailDaemonApp::_InitAccount(BMailAccountSettings& settings) } if (account.inboundProtocol) { DefaultNotifier* notifier = new DefaultNotifier(settings.Name(), true, - fErrorLogWindow); + fErrorLogWindow, fNotifyMode); account.inboundProtocol->SetMailNotifier(notifier); account.inboundThread = new InboundProtocolThread( @@ -662,7 +669,7 @@ MailDaemonApp::_InitAccount(BMailAccountSettings& settings) } if (account.outboundProtocol) { DefaultNotifier* notifier = new DefaultNotifier(settings.Name(), false, - fErrorLogWindow); + fErrorLogWindow, fNotifyMode); account.outboundProtocol->SetMailNotifier(notifier); account.outboundThread = new OutboundProtocolThread( diff --git a/src/servers/mail/MailDaemon.h b/src/servers/mail/MailDaemon.h index 016f3793ef..a740cd571d 100644 --- a/src/servers/mail/MailDaemon.h +++ b/src/servers/mail/MailDaemon.h @@ -112,6 +112,7 @@ private: ErrorLogWindow* fErrorLogWindow; BNotification* fNotification; + uint32 fNotifyMode; }; diff --git a/src/servers/mail/Notifier.cpp b/src/servers/mail/Notifier.cpp index a5f59da2d9..c0c0b37066 100644 --- a/src/servers/mail/Notifier.cpp +++ b/src/servers/mail/Notifier.cpp @@ -4,7 +4,10 @@ * Distributed under the terms of the MIT License. */ + #include +#include +#include #include #include "Notifier.h" @@ -15,12 +18,13 @@ DefaultNotifier::DefaultNotifier(const char* accountName, bool inbound, - ErrorLogWindow* errorWindow) + ErrorLogWindow* errorWindow, uint32& showMode) : fAccountName(accountName), fIsInbound(inbound), fErrorWindow(errorWindow), fNotification(B_PROGRESS_NOTIFICATION), + fShowMode(showMode), fTotalItems(0), fItemsDone(0), fTotalSize(0), @@ -34,10 +38,19 @@ DefaultNotifier::DefaultNotifier(const char* accountName, bool inbound, desc.ReplaceFirst("%name", fAccountName); BString identifier; - identifier << (int)this; - // This should get us an unique value for each notifier running + identifier << accountName << inbound; + // Two windows for each acocunt : one for sending and the other for + // receiving mails fNotification.SetMessageID(identifier); - fNotification.SetApplication("Mail daemon"); + fNotification.SetApplication(B_TRANSLATE("Mail Status")); + fNotification.SetTitle(desc); + + app_info info; + be_roster->GetAppInfo(B_MAIL_DAEMON_SIGNATURE, &info); + BBitmap icon(BRect(0, 0, 32, 32), B_RGBA32); + BNode node(&info.ref); + BIconUtils::GetVectorIcon(&node, "BEOS:ICON", &icon); + fNotification.SetIcon(&icon); } @@ -49,7 +62,7 @@ DefaultNotifier::~DefaultNotifier() MailNotifier* DefaultNotifier::Clone() { - return new DefaultNotifier(fAccountName, fIsInbound, fErrorWindow); + return new DefaultNotifier(fAccountName, fIsInbound, fErrorWindow, fShowMode); } @@ -98,19 +111,23 @@ DefaultNotifier::ReportProgress(int bytes, int messages, const char* message) } fItemsDone += messages; + BString progress; + + progress << message << "\t"; + if (fTotalItems > 0) progress << fItemsDone << "/" << fTotalItems; fNotification.SetContent(progress); - if (message != NULL) - fNotification.SetTitle(message); - int timeout = 0; // Default timeout if (fItemsDone == fTotalItems && fTotalItems != 0) timeout = 1; // We're done, make the window go away faster - be_roster->Notify(fNotification, timeout); + + if ((!fIsInbound && fShowMode | B_MAIL_SHOW_STATUS_WINDOW_WHEN_SENDING) + || (fIsInbound && fShowMode | B_MAIL_SHOW_STATUS_WINDOW_WHEN_ACTIVE)) + be_roster->Notify(fNotification, timeout); } @@ -119,6 +136,6 @@ DefaultNotifier::ResetProgress(const char* message) { fNotification.SetProgress(0); if (message != NULL) - fNotification.SetContent(message); + fNotification.SetTitle(message); be_roster->Notify(fNotification, 0); } diff --git a/src/servers/mail/Notifier.h b/src/servers/mail/Notifier.h index 72d077c620..d00e9d69ab 100644 --- a/src/servers/mail/Notifier.h +++ b/src/servers/mail/Notifier.h @@ -19,7 +19,8 @@ class DefaultNotifier : public MailNotifier { public: DefaultNotifier(const char* accountName, - bool inbound, ErrorLogWindow* errorWindow); + bool inbound, ErrorLogWindow* errorWindow, + uint32& showMode); ~DefaultNotifier(); MailNotifier* Clone(); @@ -38,6 +39,7 @@ private: bool fIsInbound; ErrorLogWindow* fErrorWindow; BNotification fNotification; + uint32& fShowMode; int fTotalItems; int fItemsDone;