1de9dcd41SStephan Aßmus /*
26aa05872SBrian Hill * Copyright 2010-2017, Haiku, Inc. All Rights Reserved.
3de9dcd41SStephan Aßmus * Distributed under the terms of the MIT License.
4de9dcd41SStephan Aßmus *
5de9dcd41SStephan Aßmus * Authors:
6de9dcd41SStephan Aßmus * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
7279ca67dSAdrien Destugues * Stephan Aßmus, superstippi@gmx.de
86aa05872SBrian Hill * Brian Hill, supernova@tycho.email
9de9dcd41SStephan Aßmus */
10de9dcd41SStephan Aßmus
11f33637d9SStephan Aßmus
12f33637d9SStephan Aßmus #include <Notification.h>
13f33637d9SStephan Aßmus
14f33637d9SStephan Aßmus #include <new>
15f33637d9SStephan Aßmus
16de9dcd41SStephan Aßmus #include <stdlib.h>
17de9dcd41SStephan Aßmus #include <string.h>
18de9dcd41SStephan Aßmus
19279ca67dSAdrien Destugues #include <notification/Notifications.h>
20279ca67dSAdrien Destugues
21de9dcd41SStephan Aßmus #include <Bitmap.h>
22de9dcd41SStephan Aßmus #include <Message.h>
231416521fSAdrien Destugues #include <NodeInfo.h>
246aa05872SBrian Hill #include <Path.h>
251416521fSAdrien Destugues #include <Roster.h>
26de9dcd41SStephan Aßmus
27de9dcd41SStephan Aßmus
BNotification(notification_type type)28de9dcd41SStephan Aßmus BNotification::BNotification(notification_type type)
29de9dcd41SStephan Aßmus :
30279ca67dSAdrien Destugues BArchivable(),
31279ca67dSAdrien Destugues fInitStatus(B_OK),
32de9dcd41SStephan Aßmus fType(type),
33279ca67dSAdrien Destugues fProgress(0.f),
34de9dcd41SStephan Aßmus fFile(NULL),
35de9dcd41SStephan Aßmus fBitmap(NULL)
36de9dcd41SStephan Aßmus {
371416521fSAdrien Destugues team_info teamInfo;
381416521fSAdrien Destugues get_team_info(B_CURRENT_TEAM, &teamInfo);
391416521fSAdrien Destugues app_info appInfo;
401416521fSAdrien Destugues be_roster->GetRunningAppInfo(teamInfo.team, &appInfo);
416aa05872SBrian Hill
426aa05872SBrian Hill int32 iconSize = B_LARGE_ICON;
436aa05872SBrian Hill fBitmap = new BBitmap(BRect(0, 0, iconSize - 1, iconSize - 1), 0, B_RGBA32);
446aa05872SBrian Hill if (fBitmap) {
451416521fSAdrien Destugues if (BNodeInfo::GetTrackerIcon(&appInfo.ref, fBitmap,
461416521fSAdrien Destugues icon_size(iconSize)) != B_OK) {
471416521fSAdrien Destugues delete fBitmap;
481416521fSAdrien Destugues fBitmap = NULL;
491416521fSAdrien Destugues }
501416521fSAdrien Destugues }
516aa05872SBrian Hill fSourceSignature = appInfo.signature;
526aa05872SBrian Hill BPath path(&appInfo.ref);
536aa05872SBrian Hill if (path.InitCheck() == B_OK)
546aa05872SBrian Hill fSourceName = path.Leaf();
55de9dcd41SStephan Aßmus }
56de9dcd41SStephan Aßmus
577c3d316bSAdrien Destugues
BNotification(BMessage * archive)58279ca67dSAdrien Destugues BNotification::BNotification(BMessage* archive)
59279ca67dSAdrien Destugues :
60279ca67dSAdrien Destugues BArchivable(archive),
61279ca67dSAdrien Destugues fInitStatus(B_OK),
62279ca67dSAdrien Destugues fProgress(0.0f),
63279ca67dSAdrien Destugues fFile(NULL),
64279ca67dSAdrien Destugues fBitmap(NULL)
65279ca67dSAdrien Destugues {
666aa05872SBrian Hill BString appName;
676aa05872SBrian Hill if (archive->FindString("_appname", &appName) == B_OK)
686aa05872SBrian Hill fSourceName = appName;
696aa05872SBrian Hill
706aa05872SBrian Hill BString signature;
716aa05872SBrian Hill if (archive->FindString("_signature", &signature) == B_OK)
726aa05872SBrian Hill fSourceSignature = signature;
736aa05872SBrian Hill
74279ca67dSAdrien Destugues int32 type;
75279ca67dSAdrien Destugues if (archive->FindInt32("_type", &type) == B_OK)
76279ca67dSAdrien Destugues fType = (notification_type)type;
77279ca67dSAdrien Destugues else
78279ca67dSAdrien Destugues fInitStatus = B_ERROR;
79279ca67dSAdrien Destugues
80279ca67dSAdrien Destugues BString group;
81279ca67dSAdrien Destugues if (archive->FindString("_group", &group) == B_OK)
82279ca67dSAdrien Destugues SetGroup(group);
83279ca67dSAdrien Destugues
84279ca67dSAdrien Destugues BString title;
85279ca67dSAdrien Destugues if (archive->FindString("_title", &title) == B_OK)
86279ca67dSAdrien Destugues SetTitle(title);
87279ca67dSAdrien Destugues
88279ca67dSAdrien Destugues BString content;
89279ca67dSAdrien Destugues if (archive->FindString("_content", &content) == B_OK)
90279ca67dSAdrien Destugues SetContent(content);
91279ca67dSAdrien Destugues
92279ca67dSAdrien Destugues BString messageID;
93279ca67dSAdrien Destugues if (archive->FindString("_messageID", &messageID) == B_OK)
94279ca67dSAdrien Destugues SetMessageID(messageID);
95279ca67dSAdrien Destugues
96279ca67dSAdrien Destugues float progress;
97279ca67dSAdrien Destugues if (type == B_PROGRESS_NOTIFICATION
98279ca67dSAdrien Destugues && archive->FindFloat("_progress", &progress) == B_OK)
99279ca67dSAdrien Destugues SetProgress(progress);
100279ca67dSAdrien Destugues
101279ca67dSAdrien Destugues BString onClickApp;
102279ca67dSAdrien Destugues if (archive->FindString("_onClickApp", &onClickApp) == B_OK)
103279ca67dSAdrien Destugues SetOnClickApp(onClickApp);
104279ca67dSAdrien Destugues
105279ca67dSAdrien Destugues entry_ref onClickFile;
106279ca67dSAdrien Destugues if (archive->FindRef("_onClickFile", &onClickFile) == B_OK)
107279ca67dSAdrien Destugues SetOnClickFile(&onClickFile);
108279ca67dSAdrien Destugues
10933570266SRyan Leavengood entry_ref onClickRef;
11033570266SRyan Leavengood int32 index = 0;
11133570266SRyan Leavengood while (archive->FindRef("_onClickRef", index++, &onClickRef) == B_OK)
11233570266SRyan Leavengood AddOnClickRef(&onClickRef);
11333570266SRyan Leavengood
11433570266SRyan Leavengood BString onClickArgv;
11533570266SRyan Leavengood index = 0;
11633570266SRyan Leavengood while (archive->FindString("_onClickArgv", index++, &onClickArgv) == B_OK)
11733570266SRyan Leavengood AddOnClickArg(onClickArgv);
11833570266SRyan Leavengood
119279ca67dSAdrien Destugues status_t ret = B_OK;
120279ca67dSAdrien Destugues BMessage icon;
121279ca67dSAdrien Destugues if ((ret = archive->FindMessage("_icon", &icon)) == B_OK) {
122279ca67dSAdrien Destugues BBitmap bitmap(&icon);
123279ca67dSAdrien Destugues ret = bitmap.InitCheck();
124279ca67dSAdrien Destugues if (ret == B_OK)
125279ca67dSAdrien Destugues ret = SetIcon(&bitmap);
126279ca67dSAdrien Destugues }
127279ca67dSAdrien Destugues }
128279ca67dSAdrien Destugues
129de9dcd41SStephan Aßmus
~BNotification()130de9dcd41SStephan Aßmus BNotification::~BNotification()
131de9dcd41SStephan Aßmus {
132f33637d9SStephan Aßmus delete fFile;
133f33637d9SStephan Aßmus delete fBitmap;
134de9dcd41SStephan Aßmus
135f33637d9SStephan Aßmus for (int32 i = fRefs.CountItems() - 1; i >= 0; i--)
136f33637d9SStephan Aßmus delete (entry_ref*)fRefs.ItemAtFast(i);
137f33637d9SStephan Aßmus
138f33637d9SStephan Aßmus for (int32 i = fArgv.CountItems() - 1; i >= 0; i--)
139f33637d9SStephan Aßmus free(fArgv.ItemAtFast(i));
140de9dcd41SStephan Aßmus }
141de9dcd41SStephan Aßmus
142de9dcd41SStephan Aßmus
143279ca67dSAdrien Destugues status_t
InitCheck() const144279ca67dSAdrien Destugues BNotification::InitCheck() const
145279ca67dSAdrien Destugues {
146279ca67dSAdrien Destugues return fInitStatus;
147279ca67dSAdrien Destugues }
148279ca67dSAdrien Destugues
149279ca67dSAdrien Destugues
150279ca67dSAdrien Destugues BArchivable*
Instantiate(BMessage * archive)151279ca67dSAdrien Destugues BNotification::Instantiate(BMessage* archive)
152279ca67dSAdrien Destugues {
153279ca67dSAdrien Destugues if (validate_instantiation(archive, "BNotification"))
154279ca67dSAdrien Destugues return new(std::nothrow) BNotification(archive);
155279ca67dSAdrien Destugues
156279ca67dSAdrien Destugues return NULL;
157279ca67dSAdrien Destugues }
158279ca67dSAdrien Destugues
159279ca67dSAdrien Destugues
160279ca67dSAdrien Destugues status_t
Archive(BMessage * archive,bool deep) const161279ca67dSAdrien Destugues BNotification::Archive(BMessage* archive, bool deep) const
162279ca67dSAdrien Destugues {
163279ca67dSAdrien Destugues status_t status = BArchivable::Archive(archive, deep);
164279ca67dSAdrien Destugues
165279ca67dSAdrien Destugues if (status == B_OK)
1666aa05872SBrian Hill status = archive->AddString("_appname", fSourceName);
1676aa05872SBrian Hill
1686aa05872SBrian Hill if (status == B_OK)
1696aa05872SBrian Hill status = archive->AddString("_signature", fSourceSignature);
1706aa05872SBrian Hill
1716aa05872SBrian Hill if (status == B_OK)
172279ca67dSAdrien Destugues status = archive->AddInt32("_type", (int32)fType);
173279ca67dSAdrien Destugues
174279ca67dSAdrien Destugues if (status == B_OK && Group() != NULL)
175279ca67dSAdrien Destugues status = archive->AddString("_group", Group());
176279ca67dSAdrien Destugues
177279ca67dSAdrien Destugues if (status == B_OK && Title() != NULL)
178279ca67dSAdrien Destugues status = archive->AddString("_title", Title());
179279ca67dSAdrien Destugues
180279ca67dSAdrien Destugues if (status == B_OK && Content() != NULL)
181279ca67dSAdrien Destugues status = archive->AddString("_content", Content());
182279ca67dSAdrien Destugues
183279ca67dSAdrien Destugues if (status == B_OK && MessageID() != NULL)
184279ca67dSAdrien Destugues status = archive->AddString("_messageID", MessageID());
185279ca67dSAdrien Destugues
186279ca67dSAdrien Destugues if (status == B_OK && Type() == B_PROGRESS_NOTIFICATION)
187279ca67dSAdrien Destugues status = archive->AddFloat("_progress", Progress());
188279ca67dSAdrien Destugues
189279ca67dSAdrien Destugues if (status == B_OK && OnClickApp() != NULL)
190279ca67dSAdrien Destugues status = archive->AddString("_onClickApp", OnClickApp());
191279ca67dSAdrien Destugues
192279ca67dSAdrien Destugues if (status == B_OK && OnClickFile() != NULL)
193279ca67dSAdrien Destugues status = archive->AddRef("_onClickFile", OnClickFile());
194279ca67dSAdrien Destugues
195279ca67dSAdrien Destugues if (status == B_OK) {
196279ca67dSAdrien Destugues for (int32 i = 0; i < CountOnClickRefs(); i++) {
197279ca67dSAdrien Destugues status = archive->AddRef("_onClickRef", OnClickRefAt(i));
198279ca67dSAdrien Destugues if (status != B_OK)
199279ca67dSAdrien Destugues break;
200279ca67dSAdrien Destugues }
201279ca67dSAdrien Destugues }
202279ca67dSAdrien Destugues
203279ca67dSAdrien Destugues if (status == B_OK) {
204279ca67dSAdrien Destugues for (int32 i = 0; i < CountOnClickArgs(); i++) {
205279ca67dSAdrien Destugues status = archive->AddString("_onClickArgv", OnClickArgAt(i));
206279ca67dSAdrien Destugues if (status != B_OK)
207279ca67dSAdrien Destugues break;
208279ca67dSAdrien Destugues }
209279ca67dSAdrien Destugues }
210279ca67dSAdrien Destugues
211279ca67dSAdrien Destugues if (status == B_OK) {
212279ca67dSAdrien Destugues const BBitmap* icon = Icon();
213279ca67dSAdrien Destugues if (icon != NULL) {
214279ca67dSAdrien Destugues BMessage iconArchive;
215279ca67dSAdrien Destugues status = icon->Archive(&iconArchive);
216279ca67dSAdrien Destugues if (status == B_OK)
217279ca67dSAdrien Destugues archive->AddMessage("_icon", &iconArchive);
218279ca67dSAdrien Destugues }
219279ca67dSAdrien Destugues }
220279ca67dSAdrien Destugues
221279ca67dSAdrien Destugues return status;
222279ca67dSAdrien Destugues }
223279ca67dSAdrien Destugues
224279ca67dSAdrien Destugues
2256aa05872SBrian Hill const char*
SourceSignature() const2266aa05872SBrian Hill BNotification::SourceSignature() const
2276aa05872SBrian Hill {
2286aa05872SBrian Hill return fSourceSignature;
2296aa05872SBrian Hill }
2306aa05872SBrian Hill
2316aa05872SBrian Hill
2326aa05872SBrian Hill const char*
SourceName() const2336aa05872SBrian Hill BNotification::SourceName() const
2346aa05872SBrian Hill {
2356aa05872SBrian Hill return fSourceName;
2366aa05872SBrian Hill }
2376aa05872SBrian Hill
2386aa05872SBrian Hill
239de9dcd41SStephan Aßmus notification_type
Type() const240de9dcd41SStephan Aßmus BNotification::Type() const
241de9dcd41SStephan Aßmus {
242de9dcd41SStephan Aßmus return fType;
243de9dcd41SStephan Aßmus }
244de9dcd41SStephan Aßmus
245de9dcd41SStephan Aßmus
246de9dcd41SStephan Aßmus const char*
Group() const247279ca67dSAdrien Destugues BNotification::Group() const
248de9dcd41SStephan Aßmus {
249279ca67dSAdrien Destugues if (fGroup == "")
250279ca67dSAdrien Destugues return NULL;
251279ca67dSAdrien Destugues return fGroup;
252de9dcd41SStephan Aßmus }
253de9dcd41SStephan Aßmus
254de9dcd41SStephan Aßmus
255de9dcd41SStephan Aßmus void
SetGroup(const BString & group)256279ca67dSAdrien Destugues BNotification::SetGroup(const BString& group)
257de9dcd41SStephan Aßmus {
258279ca67dSAdrien Destugues fGroup = group;
259de9dcd41SStephan Aßmus }
260de9dcd41SStephan Aßmus
261de9dcd41SStephan Aßmus
262de9dcd41SStephan Aßmus const char*
Title() const263de9dcd41SStephan Aßmus BNotification::Title() const
264de9dcd41SStephan Aßmus {
265279ca67dSAdrien Destugues if (fTitle == "")
266279ca67dSAdrien Destugues return NULL;
267de9dcd41SStephan Aßmus return fTitle;
268de9dcd41SStephan Aßmus }
269de9dcd41SStephan Aßmus
270de9dcd41SStephan Aßmus
271de9dcd41SStephan Aßmus void
SetTitle(const BString & title)272908967a1SStephan Aßmus BNotification::SetTitle(const BString& title)
273de9dcd41SStephan Aßmus {
274f33637d9SStephan Aßmus fTitle = title;
275de9dcd41SStephan Aßmus }
276de9dcd41SStephan Aßmus
277de9dcd41SStephan Aßmus
278de9dcd41SStephan Aßmus const char*
Content() const279de9dcd41SStephan Aßmus BNotification::Content() const
280de9dcd41SStephan Aßmus {
281279ca67dSAdrien Destugues if (fContent == "")
282279ca67dSAdrien Destugues return NULL;
283de9dcd41SStephan Aßmus return fContent;
284de9dcd41SStephan Aßmus }
285de9dcd41SStephan Aßmus
286de9dcd41SStephan Aßmus
287de9dcd41SStephan Aßmus void
SetContent(const BString & content)288908967a1SStephan Aßmus BNotification::SetContent(const BString& content)
289de9dcd41SStephan Aßmus {
290f33637d9SStephan Aßmus fContent = content;
291de9dcd41SStephan Aßmus }
292de9dcd41SStephan Aßmus
293de9dcd41SStephan Aßmus
294de9dcd41SStephan Aßmus const char*
MessageID() const295de9dcd41SStephan Aßmus BNotification::MessageID() const
296de9dcd41SStephan Aßmus {
297279ca67dSAdrien Destugues if (fID == "")
298279ca67dSAdrien Destugues return NULL;
299de9dcd41SStephan Aßmus return fID;
300de9dcd41SStephan Aßmus }
301de9dcd41SStephan Aßmus
302de9dcd41SStephan Aßmus
303de9dcd41SStephan Aßmus void
SetMessageID(const BString & id)304908967a1SStephan Aßmus BNotification::SetMessageID(const BString& id)
305de9dcd41SStephan Aßmus {
306f33637d9SStephan Aßmus fID = id;
307de9dcd41SStephan Aßmus }
308de9dcd41SStephan Aßmus
309de9dcd41SStephan Aßmus
310de9dcd41SStephan Aßmus float
Progress() const311de9dcd41SStephan Aßmus BNotification::Progress() const
312de9dcd41SStephan Aßmus {
313279ca67dSAdrien Destugues if (fType != B_PROGRESS_NOTIFICATION)
314279ca67dSAdrien Destugues return -1;
315de9dcd41SStephan Aßmus return fProgress;
316de9dcd41SStephan Aßmus }
317de9dcd41SStephan Aßmus
318de9dcd41SStephan Aßmus
319de9dcd41SStephan Aßmus void
SetProgress(float progress)320de9dcd41SStephan Aßmus BNotification::SetProgress(float progress)
321de9dcd41SStephan Aßmus {
322279ca67dSAdrien Destugues if (progress < 0)
323279ca67dSAdrien Destugues fProgress = 0;
324279ca67dSAdrien Destugues else if (progress > 1)
325279ca67dSAdrien Destugues fProgress = 1;
326279ca67dSAdrien Destugues else
327de9dcd41SStephan Aßmus fProgress = progress;
328de9dcd41SStephan Aßmus }
329de9dcd41SStephan Aßmus
330de9dcd41SStephan Aßmus
331de9dcd41SStephan Aßmus const char*
OnClickApp() const332de9dcd41SStephan Aßmus BNotification::OnClickApp() const
333de9dcd41SStephan Aßmus {
334279ca67dSAdrien Destugues if (fApp == "")
335279ca67dSAdrien Destugues return NULL;
336de9dcd41SStephan Aßmus return fApp;
337de9dcd41SStephan Aßmus }
338de9dcd41SStephan Aßmus
339de9dcd41SStephan Aßmus
340de9dcd41SStephan Aßmus void
SetOnClickApp(const BString & app)341908967a1SStephan Aßmus BNotification::SetOnClickApp(const BString& app)
342de9dcd41SStephan Aßmus {
343f33637d9SStephan Aßmus fApp = app;
344de9dcd41SStephan Aßmus }
345de9dcd41SStephan Aßmus
346de9dcd41SStephan Aßmus
347f33637d9SStephan Aßmus const entry_ref*
OnClickFile() const348de9dcd41SStephan Aßmus BNotification::OnClickFile() const
349de9dcd41SStephan Aßmus {
350de9dcd41SStephan Aßmus return fFile;
351de9dcd41SStephan Aßmus }
352de9dcd41SStephan Aßmus
353de9dcd41SStephan Aßmus
354f33637d9SStephan Aßmus status_t
SetOnClickFile(const entry_ref * file)355de9dcd41SStephan Aßmus BNotification::SetOnClickFile(const entry_ref* file)
356de9dcd41SStephan Aßmus {
357f33637d9SStephan Aßmus delete fFile;
358f33637d9SStephan Aßmus
359f33637d9SStephan Aßmus if (file != NULL) {
360f33637d9SStephan Aßmus fFile = new(std::nothrow) entry_ref(*file);
361f33637d9SStephan Aßmus if (fFile == NULL)
362f33637d9SStephan Aßmus return B_NO_MEMORY;
363f33637d9SStephan Aßmus } else
364f33637d9SStephan Aßmus fFile = NULL;
365f33637d9SStephan Aßmus
366f33637d9SStephan Aßmus return B_OK;
367de9dcd41SStephan Aßmus }
368de9dcd41SStephan Aßmus
369de9dcd41SStephan Aßmus
370f33637d9SStephan Aßmus status_t
AddOnClickRef(const entry_ref * ref)371de9dcd41SStephan Aßmus BNotification::AddOnClickRef(const entry_ref* ref)
372de9dcd41SStephan Aßmus {
373f33637d9SStephan Aßmus if (ref == NULL)
374f33637d9SStephan Aßmus return B_BAD_VALUE;
375f33637d9SStephan Aßmus
376908967a1SStephan Aßmus entry_ref* clonedRef = new(std::nothrow) entry_ref(*ref);
377908967a1SStephan Aßmus if (clonedRef == NULL || !fRefs.AddItem(clonedRef))
378908967a1SStephan Aßmus return B_NO_MEMORY;
379908967a1SStephan Aßmus
380908967a1SStephan Aßmus return B_OK;
381de9dcd41SStephan Aßmus }
382de9dcd41SStephan Aßmus
383de9dcd41SStephan Aßmus
384f33637d9SStephan Aßmus int32
CountOnClickRefs() const385f33637d9SStephan Aßmus BNotification::CountOnClickRefs() const
386de9dcd41SStephan Aßmus {
387f33637d9SStephan Aßmus return fRefs.CountItems();
388de9dcd41SStephan Aßmus }
389de9dcd41SStephan Aßmus
390de9dcd41SStephan Aßmus
391f33637d9SStephan Aßmus const entry_ref*
OnClickRefAt(int32 index) const392f33637d9SStephan Aßmus BNotification::OnClickRefAt(int32 index) const
393f33637d9SStephan Aßmus {
394*8636e31aSAugustin Cavalier return (entry_ref*)fRefs.ItemAt(index);
395f33637d9SStephan Aßmus }
396f33637d9SStephan Aßmus
397f33637d9SStephan Aßmus
398f33637d9SStephan Aßmus status_t
AddOnClickArg(const BString & arg)399908967a1SStephan Aßmus BNotification::AddOnClickArg(const BString& arg)
400f33637d9SStephan Aßmus {
401908967a1SStephan Aßmus char* clonedArg = strdup(arg.String());
402f33637d9SStephan Aßmus if (clonedArg == NULL || !fArgv.AddItem(clonedArg))
403f33637d9SStephan Aßmus return B_NO_MEMORY;
404f33637d9SStephan Aßmus
405f33637d9SStephan Aßmus return B_OK;
406de9dcd41SStephan Aßmus }
407de9dcd41SStephan Aßmus
408de9dcd41SStephan Aßmus
409f33637d9SStephan Aßmus int32
CountOnClickArgs() const410f33637d9SStephan Aßmus BNotification::CountOnClickArgs() const
411f33637d9SStephan Aßmus {
412f33637d9SStephan Aßmus return fArgv.CountItems();
413f33637d9SStephan Aßmus }
414f33637d9SStephan Aßmus
415f33637d9SStephan Aßmus
416f33637d9SStephan Aßmus const char*
OnClickArgAt(int32 index) const417f33637d9SStephan Aßmus BNotification::OnClickArgAt(int32 index) const
418f33637d9SStephan Aßmus {
419f33637d9SStephan Aßmus return (char*)fArgv.ItemAt(index);
420f33637d9SStephan Aßmus }
421f33637d9SStephan Aßmus
422f33637d9SStephan Aßmus
423f33637d9SStephan Aßmus const BBitmap*
Icon() const424de9dcd41SStephan Aßmus BNotification::Icon() const
425de9dcd41SStephan Aßmus {
426de9dcd41SStephan Aßmus return fBitmap;
427de9dcd41SStephan Aßmus }
428de9dcd41SStephan Aßmus
429de9dcd41SStephan Aßmus
430f33637d9SStephan Aßmus status_t
SetIcon(const BBitmap * icon)431f33637d9SStephan Aßmus BNotification::SetIcon(const BBitmap* icon)
432de9dcd41SStephan Aßmus {
433f33637d9SStephan Aßmus delete fBitmap;
434f33637d9SStephan Aßmus
435f33637d9SStephan Aßmus if (icon != NULL) {
436f33637d9SStephan Aßmus fBitmap = new(std::nothrow) BBitmap(icon);
437f33637d9SStephan Aßmus if (fBitmap == NULL)
438f33637d9SStephan Aßmus return B_NO_MEMORY;
439f33637d9SStephan Aßmus return fBitmap->InitCheck();
440f33637d9SStephan Aßmus }
441f33637d9SStephan Aßmus
442f33637d9SStephan Aßmus fBitmap = NULL;
443f33637d9SStephan Aßmus return B_OK;
444de9dcd41SStephan Aßmus }
445279ca67dSAdrien Destugues
446279ca67dSAdrien Destugues
447279ca67dSAdrien Destugues status_t
Send(bigtime_t timeout)448279ca67dSAdrien Destugues BNotification::Send(bigtime_t timeout)
449279ca67dSAdrien Destugues {
450279ca67dSAdrien Destugues BMessage msg(kNotificationMessage);
451279ca67dSAdrien Destugues
452279ca67dSAdrien Destugues // Archive notification
453279ca67dSAdrien Destugues status_t ret = Archive(&msg);
454279ca67dSAdrien Destugues
455279ca67dSAdrien Destugues // Custom time out
456279ca67dSAdrien Destugues if (ret == B_OK && timeout > 0)
457279ca67dSAdrien Destugues ret = msg.AddInt64("timeout", timeout);
458279ca67dSAdrien Destugues
459279ca67dSAdrien Destugues // Send message
460279ca67dSAdrien Destugues if (ret == B_OK) {
461279ca67dSAdrien Destugues BMessenger server(kNotificationServerSignature);
462279ca67dSAdrien Destugues ret = server.SendMessage(&msg);
463279ca67dSAdrien Destugues }
464279ca67dSAdrien Destugues
465279ca67dSAdrien Destugues return ret;
466279ca67dSAdrien Destugues }
4678856b518SBrian Hill
4688856b518SBrian Hill
_ReservedNotification1()4698856b518SBrian Hill void BNotification::_ReservedNotification1() {}
_ReservedNotification2()4708856b518SBrian Hill void BNotification::_ReservedNotification2() {}
_ReservedNotification3()4718856b518SBrian Hill void BNotification::_ReservedNotification3() {}
_ReservedNotification4()4728856b518SBrian Hill void BNotification::_ReservedNotification4() {}
_ReservedNotification5()4738856b518SBrian Hill void BNotification::_ReservedNotification5() {}
_ReservedNotification6()4748856b518SBrian Hill void BNotification::_ReservedNotification6() {}
_ReservedNotification7()4758856b518SBrian Hill void BNotification::_ReservedNotification7() {}
_ReservedNotification8()4768856b518SBrian Hill void BNotification::_ReservedNotification8() {}
477