Make UEFI boot-platform build again
[haiku.git] / src / servers / mail / DefaultNotifier.cpp
blob66aebf8cf297ad4e7c148be3c0e02798fb98c69f
1 /*
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.
6 */
9 #include "DefaultNotifier.h"
11 #include <Catalog.h>
12 #include <IconUtils.h>
13 #include <MailDaemon.h>
14 #include <Roster.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),
27 fIsInbound(inbound),
28 fErrorWindow(errorWindow),
29 fNotification(B_PROGRESS_NOTIFICATION),
30 fShowMode(showMode),
31 fTotalItems(0),
32 fItemsDone(0),
33 fTotalSize(0),
34 fSizeDone(0)
36 BString desc(fIsInbound ? B_TRANSLATE("Fetching mail for %name")
37 : B_TRANSLATE("Sending mail for %name"));
38 desc.ReplaceFirst("%name", fAccountName);
40 BString identifier;
41 identifier << accountName << inbound;
42 // Two windows for each acocunt : one for sending and the other for
43 // receiving mails
44 fNotification.SetMessageID(identifier);
45 fNotification.SetGroup(B_TRANSLATE("Mail status"));
46 fNotification.SetTitle(desc);
48 app_info info;
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()
62 BMailNotifier*
63 DefaultNotifier::Clone()
65 return new DefaultNotifier(fAccountName, fIsInbound, fErrorWindow,
66 fShowMode);
70 void
71 DefaultNotifier::ShowError(const char* error)
73 fErrorWindow->AddError(B_WARNING_ALERT, error, fAccountName);
77 void
78 DefaultNotifier::ShowMessage(const char* message)
80 fErrorWindow->AddError(B_INFO_ALERT, message, fAccountName);
84 void
85 DefaultNotifier::SetTotalItems(uint32 items)
87 fTotalItems = items;
88 BString progress;
89 progress << fItemsDone << "/" << fTotalItems;
90 fNotification.SetContent(progress);
94 void
95 DefaultNotifier::SetTotalItemsSize(uint64 size)
97 fTotalSize = size;
98 fNotification.SetProgress(fSizeDone / (float)fTotalSize);
102 void
103 DefaultNotifier::ReportProgress(uint32 messages, uint64 bytes,
104 const char* message)
106 fSizeDone += bytes;
107 if (fTotalSize > 0)
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);
113 } else {
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;
122 BString progress;
123 progress << message << "\t";
125 if (fTotalItems > 0)
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);
138 void
139 DefaultNotifier::ResetProgress(const char* message)
141 fNotification.SetProgress(0);
142 if (message != NULL)
143 fNotification.SetTitle(message);
144 _NotifyIfAllowed();
148 void
149 DefaultNotifier::_NotifyIfAllowed(int timeout)
151 int32 flag;
152 if (fIsInbound)
153 flag = B_MAIL_SHOW_STATUS_WINDOW_WHEN_ACTIVE;
154 else
155 flag = B_MAIL_SHOW_STATUS_WINDOW_WHEN_SENDING;
157 if ((fShowMode & flag) != 0)
158 fNotification.Send(timeout);