2 * Copyright 2011-2012, Haiku, Inc. All rights reserved.
3 * Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
5 * Distributed under the terms of the MIT License.
9 #include "DefaultNotifier.h"
12 #include <IconUtils.h>
13 #include <MailDaemon.h>
16 #include <MailPrivate.h>
19 #undef B_TRANSLATION_CONTEXT
20 #define B_TRANSLATION_CONTEXT "Notifier"
23 DefaultNotifier::DefaultNotifier(const char* accountName
, bool inbound
,
24 ErrorLogWindow
* errorWindow
, uint32 showMode
)
26 fAccountName(accountName
),
28 fErrorWindow(errorWindow
),
29 fNotification(B_PROGRESS_NOTIFICATION
),
36 BString
desc(fIsInbound
? B_TRANSLATE("Fetching mail for %name")
37 : B_TRANSLATE("Sending mail for %name"));
38 desc
.ReplaceFirst("%name", fAccountName
);
41 identifier
<< accountName
<< inbound
;
42 // Two windows for each acocunt : one for sending and the other for
44 fNotification
.SetMessageID(identifier
);
45 fNotification
.SetGroup(B_TRANSLATE("Mail status"));
46 fNotification
.SetTitle(desc
);
49 be_roster
->GetAppInfo(B_MAIL_DAEMON_SIGNATURE
, &info
);
50 BBitmap
icon(BRect(0, 0, 32, 32), B_RGBA32
);
51 BNode
node(&info
.ref
);
52 BIconUtils::GetVectorIcon(&node
, "BEOS:ICON", &icon
);
53 fNotification
.SetIcon(&icon
);
57 DefaultNotifier::~DefaultNotifier()
63 DefaultNotifier::Clone()
65 return new DefaultNotifier(fAccountName
, fIsInbound
, fErrorWindow
,
71 DefaultNotifier::ShowError(const char* error
)
73 fErrorWindow
->AddError(B_WARNING_ALERT
, error
, fAccountName
);
78 DefaultNotifier::ShowMessage(const char* message
)
80 fErrorWindow
->AddError(B_INFO_ALERT
, message
, fAccountName
);
85 DefaultNotifier::SetTotalItems(uint32 items
)
89 progress
<< fItemsDone
<< "/" << fTotalItems
;
90 fNotification
.SetContent(progress
);
95 DefaultNotifier::SetTotalItemsSize(uint64 size
)
98 fNotification
.SetProgress(fSizeDone
/ (float)fTotalSize
);
103 DefaultNotifier::ReportProgress(uint32 messages
, uint64 bytes
,
108 fNotification
.SetProgress(fSizeDone
/ (float)fTotalSize
);
109 else if (fTotalItems
> 0) {
110 // No size information available
111 // Report progress in terms of message count instead
112 fNotification
.SetProgress(fItemsDone
/ (float)fTotalItems
);
114 // No message count information either
115 // TODO: we should use a B_INFORMATION_NOTIFICATION here, but it is not
116 // possible to change the BNotification type after creating it...
117 fNotification
.SetProgress(0);
120 fItemsDone
+= messages
;
123 progress
<< message
<< "\t";
126 progress
<< fItemsDone
<< "/" << fTotalItems
;
128 fNotification
.SetContent(progress
);
130 int timeout
= 0; // Default timeout
131 if (fItemsDone
== fTotalItems
&& fTotalItems
!= 0)
132 timeout
= 1; // We're done, make the window go away faster
134 _NotifyIfAllowed(timeout
);
139 DefaultNotifier::ResetProgress(const char* message
)
141 fNotification
.SetProgress(0);
143 fNotification
.SetTitle(message
);
149 DefaultNotifier::_NotifyIfAllowed(int timeout
)
153 flag
= B_MAIL_SHOW_STATUS_WINDOW_WHEN_ACTIVE
;
155 flag
= B_MAIL_SHOW_STATUS_WINDOW_WHEN_SENDING
;
157 if ((fShowMode
& flag
) != 0)
158 fNotification
.Send(timeout
);