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
This commit is contained in:
Adrien Destugues 2011-11-01 19:25:40 +00:00
parent c0691021f7
commit 244a545018
4 changed files with 48 additions and 21 deletions

View File

@ -19,6 +19,7 @@
#include <Entry.h>
#include <FindDirectory.h>
#include <fs_index.h>
#include <IconUtils.h>
#include <NodeMonitor.h>
#include <Notification.h>
#include <Path.h>
@ -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(

View File

@ -112,6 +112,7 @@ private:
ErrorLogWindow* fErrorLogWindow;
BNotification* fNotification;
uint32 fNotifyMode;
};

View File

@ -4,7 +4,10 @@
* Distributed under the terms of the MIT License.
*/
#include <Catalog.h>
#include <IconUtils.h>
#include <MailDaemon.h>
#include <Roster.h>
#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);
}

View File

@ -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;