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
28de9dcd41SStephan AßmusBNotification::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{
376aa05872SBrian Hill	team_info teamInfo;
386aa05872SBrian Hill	get_team_info(B_CURRENT_TEAM, &teamInfo);
396aa05872SBrian Hill	app_info appInfo;
406aa05872SBrian Hill	be_roster->GetRunningAppInfo(teamInfo.team, &appInfo);
418636e31aSAugustin Cavalier
421416521fSAdrien Destugues	int32 iconSize = B_LARGE_ICON;
431416521fSAdrien Destugues	fBitmap = new BBitmap(BRect(0, 0, iconSize - 1, iconSize - 1), 0, B_RGBA32);
441416521fSAdrien Destugues	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
58279ca67dSAdrien DestuguesBNotification::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
130de9dcd41SStephan AßmusBNotification::~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/*! \brief Returns initialization status.
144279ca67dSAdrien Destugues */
145279ca67dSAdrien Destuguesstatus_t
146279ca67dSAdrien DestuguesBNotification::InitCheck() const
147279ca67dSAdrien Destugues{
148279ca67dSAdrien Destugues	return fInitStatus;
149279ca67dSAdrien Destugues}
150279ca67dSAdrien Destugues
151279ca67dSAdrien Destugues
152279ca67dSAdrien Destugues/*! \brief Returns a new BNotification object from @archive.
153279ca67dSAdrien Destugues
154279ca67dSAdrien Destugues	Returns a new BNotification object, allocated by new and created
155279ca67dSAdrien Destugues	with the version of the constructor that takes BMessage archive.
156279ca67dSAdrien Destugues	However, if the message doesn't contain an archived data for a
157279ca67dSAdrien Destugues	BNotification object, this method returns NULL.
158279ca67dSAdrien Destugues
159279ca67dSAdrien Destugues	\return BNotification object from @archive or NULL if it doesn't
160279ca67dSAdrien Destugues			contain a valid BNotification object.
161279ca67dSAdrien Destugues*/
162279ca67dSAdrien DestuguesBArchivable*
163279ca67dSAdrien DestuguesBNotification::Instantiate(BMessage* archive)
164279ca67dSAdrien Destugues{
165279ca67dSAdrien Destugues	if (validate_instantiation(archive, "BNotification"))
166279ca67dSAdrien Destugues		return new(std::nothrow) BNotification(archive);
167279ca67dSAdrien Destugues
168279ca67dSAdrien Destugues	return NULL;
169279ca67dSAdrien Destugues}
170279ca67dSAdrien Destugues
171279ca67dSAdrien Destugues
172279ca67dSAdrien Destugues/*! \brief Archives the BNotification in the BMessages @archive.
173279ca67dSAdrien Destugues
174279ca67dSAdrien Destugues	\sa BArchivable::Archive(), Instantiate() static function.
17533570266SRyan Leavengood	\return
176279ca67dSAdrien Destugues	- \c B_OK: Everything went fine.
177279ca67dSAdrien Destugues	- \c Other errors: Archiving has failed.
178279ca67dSAdrien Destugues*/
179279ca67dSAdrien Destuguesstatus_t
180279ca67dSAdrien DestuguesBNotification::Archive(BMessage* archive, bool deep) const
181279ca67dSAdrien Destugues{
182279ca67dSAdrien Destugues	status_t status = BArchivable::Archive(archive, deep);
183279ca67dSAdrien Destugues
1846aa05872SBrian Hill	if (status == B_OK)
1856aa05872SBrian Hill		status = archive->AddString("_appname", fSourceName);
1866aa05872SBrian Hill
1876aa05872SBrian Hill	if (status == B_OK)
1886aa05872SBrian Hill		status = archive->AddString("_signature", fSourceSignature);
1896aa05872SBrian Hill
190279ca67dSAdrien Destugues	if (status == B_OK)
191279ca67dSAdrien Destugues		status = archive->AddInt32("_type", (int32)fType);
192279ca67dSAdrien Destugues
193279ca67dSAdrien Destugues	if (status == B_OK && Group() != NULL)
194279ca67dSAdrien Destugues		status = archive->AddString("_group", Group());
195279ca67dSAdrien Destugues
196279ca67dSAdrien Destugues	if (status == B_OK && Title() != NULL)
197279ca67dSAdrien Destugues		status = archive->AddString("_title", Title());
198279ca67dSAdrien Destugues
199279ca67dSAdrien Destugues	if (status == B_OK && Content() != NULL)
200279ca67dSAdrien Destugues		status = archive->AddString("_content", Content());
201279ca67dSAdrien Destugues
202279ca67dSAdrien Destugues	if (status == B_OK && MessageID() != NULL)
203279ca67dSAdrien Destugues		status = archive->AddString("_messageID", MessageID());
204279ca67dSAdrien Destugues
205279ca67dSAdrien Destugues	if (status == B_OK && Type() == B_PROGRESS_NOTIFICATION)
206279ca67dSAdrien Destugues		status = archive->AddFloat("_progress", Progress());
207279ca67dSAdrien Destugues
208279ca67dSAdrien Destugues	if (status == B_OK && OnClickApp() != NULL)
209279ca67dSAdrien Destugues		status = archive->AddString("_onClickApp", OnClickApp());
210279ca67dSAdrien Destugues
211279ca67dSAdrien Destugues	if (status == B_OK && OnClickFile() != NULL)
212279ca67dSAdrien Destugues		status = archive->AddRef("_onClickFile", OnClickFile());
213279ca67dSAdrien Destugues
214279ca67dSAdrien Destugues	if (status == B_OK) {
215279ca67dSAdrien Destugues		for (int32 i = 0; i < CountOnClickRefs(); i++) {
216279ca67dSAdrien Destugues			status = archive->AddRef("_onClickRef", OnClickRefAt(i));
217279ca67dSAdrien Destugues			if (status != B_OK)
218279ca67dSAdrien Destugues				break;
219279ca67dSAdrien Destugues		}
220279ca67dSAdrien Destugues	}
221279ca67dSAdrien Destugues
222279ca67dSAdrien Destugues	if (status == B_OK) {
223279ca67dSAdrien Destugues		for (int32 i = 0; i < CountOnClickArgs(); i++) {
224279ca67dSAdrien Destugues			status = archive->AddString("_onClickArgv", OnClickArgAt(i));
225279ca67dSAdrien Destugues			if (status != B_OK)
226279ca67dSAdrien Destugues				break;
227279ca67dSAdrien Destugues		}
228279ca67dSAdrien Destugues	}
229279ca67dSAdrien Destugues
230279ca67dSAdrien Destugues	if (status == B_OK) {
231279ca67dSAdrien Destugues		const BBitmap* icon = Icon();
232279ca67dSAdrien Destugues		if (icon != NULL) {
233279ca67dSAdrien Destugues			BMessage iconArchive;
234279ca67dSAdrien Destugues			status = icon->Archive(&iconArchive);
235279ca67dSAdrien Destugues			if (status == B_OK)
236279ca67dSAdrien Destugues				archive->AddMessage("_icon", &iconArchive);
237279ca67dSAdrien Destugues		}
238279ca67dSAdrien Destugues	}
239279ca67dSAdrien Destugues
240279ca67dSAdrien Destugues	return status;
241279ca67dSAdrien Destugues}
242279ca67dSAdrien Destugues
243279ca67dSAdrien Destugues
2446aa05872SBrian Hill/*! \brief Returns source application signature.
2456aa05872SBrian Hill
2466aa05872SBrian Hill	\return Source application signature.
2476aa05872SBrian Hill*/
2486aa05872SBrian Hillconst char*
2496aa05872SBrian HillBNotification::SourceSignature() const
2506aa05872SBrian Hill{
2516aa05872SBrian Hill	return fSourceSignature;
2526aa05872SBrian Hill}
2536aa05872SBrian Hill
2546aa05872SBrian Hill
2556aa05872SBrian Hill/*! \brief Returns source application name.
2566aa05872SBrian Hill
2576aa05872SBrian Hill	\return Source application name.
2586aa05872SBrian Hill*/
2596aa05872SBrian Hillconst char*
2606aa05872SBrian HillBNotification::SourceName() const
2616aa05872SBrian Hill{
2626aa05872SBrian Hill	return fSourceName;
2636aa05872SBrian Hill}
2646aa05872SBrian Hill
2656aa05872SBrian Hill
266279ca67dSAdrien Destugues/*! \brief Notification's type.
267279ca67dSAdrien Destugues
268279ca67dSAdrien Destugues	\return A value of the notification_type enum that represents
269279ca67dSAdrien Destugues			notification type.
270279ca67dSAdrien Destugues*/
271de9dcd41SStephan Aßmusnotification_type
272de9dcd41SStephan AßmusBNotification::Type() const
273de9dcd41SStephan Aßmus{
274de9dcd41SStephan Aßmus	return fType;
275de9dcd41SStephan Aßmus}
276de9dcd41SStephan Aßmus
277de9dcd41SStephan Aßmus
278279ca67dSAdrien Destugues/*! \brief Returns notification's group.
279279ca67dSAdrien Destugues
280279ca67dSAdrien Destugues	\return Notification's group.
281279ca67dSAdrien Destugues*/
282de9dcd41SStephan Aßmusconst char*
283279ca67dSAdrien DestuguesBNotification::Group() const
284de9dcd41SStephan Aßmus{
285279ca67dSAdrien Destugues	if (fGroup == "")
286279ca67dSAdrien Destugues		return NULL;
287279ca67dSAdrien Destugues	return fGroup;
288de9dcd41SStephan Aßmus}
289de9dcd41SStephan Aßmus
290de9dcd41SStephan Aßmus
291279ca67dSAdrien Destugues/*! \brief Sets notification's group.
292279ca67dSAdrien Destugues
293279ca67dSAdrien Destugues	Notifications can be grouped together setting the same group.
294279ca67dSAdrien Destugues*/
295de9dcd41SStephan Aßmusvoid
296279ca67dSAdrien DestuguesBNotification::SetGroup(const BString& group)
297de9dcd41SStephan Aßmus{
298279ca67dSAdrien Destugues	fGroup = group;
299de9dcd41SStephan Aßmus}
300de9dcd41SStephan Aßmus
301de9dcd41SStephan Aßmus
302279ca67dSAdrien Destugues/*! \brief Returns notification's title.
303279ca67dSAdrien Destugues
304279ca67dSAdrien Destugues	\return Notification's title.
305279ca67dSAdrien Destugues*/
306de9dcd41SStephan Aßmusconst char*
307de9dcd41SStephan AßmusBNotification::Title() const
308de9dcd41SStephan Aßmus{
309279ca67dSAdrien Destugues	if (fTitle == "")
310279ca67dSAdrien Destugues		return NULL;
311de9dcd41SStephan Aßmus	return fTitle;
312de9dcd41SStephan Aßmus}
313de9dcd41SStephan Aßmus
314de9dcd41SStephan Aßmus
315279ca67dSAdrien Destugues/*! \brief Set notification's title.
316279ca67dSAdrien Destugues*/
317de9dcd41SStephan Aßmusvoid
318908967a1SStephan AßmusBNotification::SetTitle(const BString& title)
319de9dcd41SStephan Aßmus{
320f33637d9SStephan Aßmus	fTitle = title;
321de9dcd41SStephan Aßmus}
322de9dcd41SStephan Aßmus
323de9dcd41SStephan Aßmus
324279ca67dSAdrien Destugues/*! \brief Returns notification's message.
325279ca67dSAdrien Destugues
326279ca67dSAdrien Destugues	\return Notification's message.
327279ca67dSAdrien Destugues*/
328de9dcd41SStephan Aßmusconst char*
329de9dcd41SStephan AßmusBNotification::Content() const
330de9dcd41SStephan Aßmus{
331279ca67dSAdrien Destugues	if (fContent == "")
332279ca67dSAdrien Destugues		return NULL;
333de9dcd41SStephan Aßmus	return fContent;
334de9dcd41SStephan Aßmus}
335de9dcd41SStephan Aßmus
336de9dcd41SStephan Aßmus
337279ca67dSAdrien Destugues/*! \brief Sets notification's message.
338279ca67dSAdrien Destugues*/
339de9dcd41SStephan Aßmusvoid
340908967a1SStephan AßmusBNotification::SetContent(const BString& content)
341de9dcd41SStephan Aßmus{
342f33637d9SStephan Aßmus	fContent = content;
343de9dcd41SStephan Aßmus}
344de9dcd41SStephan Aßmus
345de9dcd41SStephan Aßmus
346279ca67dSAdrien Destugues/*! \brief Returns notification's message identifier.
347279ca67dSAdrien Destugues
348279ca67dSAdrien Destugues	\return Notification's message identifier.
349279ca67dSAdrien Destugues*/
350de9dcd41SStephan Aßmusconst char*
351de9dcd41SStephan AßmusBNotification::MessageID() const
352de9dcd41SStephan Aßmus{
353279ca67dSAdrien Destugues	if (fID == "")
354279ca67dSAdrien Destugues		return NULL;
355de9dcd41SStephan Aßmus	return fID;
356de9dcd41SStephan Aßmus}
357de9dcd41SStephan Aßmus
358de9dcd41SStephan Aßmus
359279ca67dSAdrien Destugues/*! \brief Sets notification's message identifier.
360279ca67dSAdrien Destugues*/
361de9dcd41SStephan Aßmusvoid
362908967a1SStephan AßmusBNotification::SetMessageID(const BString& id)
363de9dcd41SStephan Aßmus{
364f33637d9SStephan Aßmus	fID = id;
365de9dcd41SStephan Aßmus}
366de9dcd41SStephan Aßmus
367de9dcd41SStephan Aßmus
368279ca67dSAdrien Destugues/*! \brief Returns progress information.
369279ca67dSAdrien Destugues
370279ca67dSAdrien Destugues	If notification's type is \c B_PROGRESS_NOTIFICATION, returns a value
371279ca67dSAdrien Destugues	between 0.0 and 1.0 that represent progress percentage.
372279ca67dSAdrien Destugues
373279ca67dSAdrien Destugues	If notification's type is not \c B_PROGRESS_NOTIFICATION, returns -1.
374279ca67dSAdrien Destugues
375279ca67dSAdrien Destugues	\return Percentage if notification's type is B_PROGRESS_NOTIFICATION
376279ca67dSAdrien Destugues			or otherwise -1.
377279ca67dSAdrien Destugues*/
378de9dcd41SStephan Aßmusfloat
379de9dcd41SStephan AßmusBNotification::Progress() const
380de9dcd41SStephan Aßmus{
381279ca67dSAdrien Destugues	if (fType != B_PROGRESS_NOTIFICATION)
382279ca67dSAdrien Destugues		return -1;
383de9dcd41SStephan Aßmus	return fProgress;
384de9dcd41SStephan Aßmus}
385de9dcd41SStephan Aßmus
386de9dcd41SStephan Aßmus
387279ca67dSAdrien Destugues/*! \brief Sets progress information.
388279ca67dSAdrien Destugues
389279ca67dSAdrien Destugues	Sets progress percentage, this information will be used only
390279ca67dSAdrien Destugues	if notification's type is \c B_PROGRESS_NOTIFICATION.
391279ca67dSAdrien Destugues
392279ca67dSAdrien Destugues	The value of @progress must be between 0.0 and 1.0.
393279ca67dSAdrien Destugues*/
394de9dcd41SStephan Aßmusvoid
395de9dcd41SStephan AßmusBNotification::SetProgress(float progress)
396de9dcd41SStephan Aßmus{
397279ca67dSAdrien Destugues	if (progress < 0)
398279ca67dSAdrien Destugues		fProgress = 0;
399279ca67dSAdrien Destugues	else if (progress > 1)
400279ca67dSAdrien Destugues		fProgress = 1;
401279ca67dSAdrien Destugues	else
402279ca67dSAdrien Destugues		fProgress = progress;
403de9dcd41SStephan Aßmus}
404de9dcd41SStephan Aßmus
405de9dcd41SStephan Aßmus
406de9dcd41SStephan Aßmusconst char*
407de9dcd41SStephan AßmusBNotification::OnClickApp() const
408de9dcd41SStephan Aßmus{
409279ca67dSAdrien Destugues	if (fApp == "")
410279ca67dSAdrien Destugues		return NULL;
411de9dcd41SStephan Aßmus	return fApp;
412de9dcd41SStephan Aßmus}
413de9dcd41SStephan Aßmus
414de9dcd41SStephan Aßmus
415de9dcd41SStephan Aßmusvoid
416908967a1SStephan AßmusBNotification::SetOnClickApp(const BString& app)
417de9dcd41SStephan Aßmus{
418f33637d9SStephan Aßmus	fApp = app;
419de9dcd41SStephan Aßmus}
420de9dcd41SStephan Aßmus
421de9dcd41SStephan Aßmus
422f33637d9SStephan Aßmusconst entry_ref*
423de9dcd41SStephan AßmusBNotification::OnClickFile() const
424de9dcd41SStephan Aßmus{
425de9dcd41SStephan Aßmus	return fFile;
426de9dcd41SStephan Aßmus}
427de9dcd41SStephan Aßmus
428de9dcd41SStephan Aßmus
429f33637d9SStephan Aßmusstatus_t
430de9dcd41SStephan AßmusBNotification::SetOnClickFile(const entry_ref* file)
431de9dcd41SStephan Aßmus{
432f33637d9SStephan Aßmus	delete fFile;
433f33637d9SStephan Aßmus
434f33637d9SStephan Aßmus	if (file != NULL) {
435f33637d9SStephan Aßmus		fFile = new(std::nothrow) entry_ref(*file);
436f33637d9SStephan Aßmus		if (fFile == NULL)
437f33637d9SStephan Aßmus			return B_NO_MEMORY;
438f33637d9SStephan Aßmus	} else
439f33637d9SStephan Aßmus		fFile = NULL;
440f33637d9SStephan Aßmus
441f33637d9SStephan Aßmus	return B_OK;
442de9dcd41SStephan Aßmus}
443de9dcd41SStephan Aßmus
444de9dcd41SStephan Aßmus
445f33637d9SStephan Aßmusstatus_t
446f33637d9SStephan AßmusBNotification::AddOnClickRef(const entry_ref* ref)
447de9dcd41SStephan Aßmus{
448f33637d9SStephan Aßmus	if (ref == NULL)
449f33637d9SStephan Aßmus		return B_BAD_VALUE;
450f33637d9SStephan Aßmus
451908967a1SStephan Aßmus	entry_ref* clonedRef = new(std::nothrow) entry_ref(*ref);
452908967a1SStephan Aßmus	if (clonedRef == NULL || !fRefs.AddItem(clonedRef))
453908967a1SStephan Aßmus		return B_NO_MEMORY;
454908967a1SStephan Aßmus
455908967a1SStephan Aßmus	return B_OK;
456de9dcd41SStephan Aßmus}
457de9dcd41SStephan Aßmus
458de9dcd41SStephan Aßmus
459f33637d9SStephan Aßmusint32
460f33637d9SStephan AßmusBNotification::CountOnClickRefs() const
461de9dcd41SStephan Aßmus{
462f33637d9SStephan Aßmus	return fRefs.CountItems();
463de9dcd41SStephan Aßmus}
464de9dcd41SStephan Aßmus
465de9dcd41SStephan Aßmus
466f33637d9SStephan Aßmusconst entry_ref*
467f33637d9SStephan AßmusBNotification::OnClickRefAt(int32 index) const
468de9dcd41SStephan Aßmus{
4698636e31aSAugustin Cavalier	return (entry_ref*)fRefs.ItemAt(index);
470de9dcd41SStephan Aßmus}
471de9dcd41SStephan Aßmus
472de9dcd41SStephan Aßmus
473f33637d9SStephan Aßmusstatus_t
474908967a1SStephan AßmusBNotification::AddOnClickArg(const BString& arg)
475f33637d9SStephan Aßmus{
476908967a1SStephan Aßmus	char* clonedArg = strdup(arg.String());
477f33637d9SStephan Aßmus	if (clonedArg == NULL || !fArgv.AddItem(clonedArg))
478f33637d9SStephan Aßmus		return B_NO_MEMORY;
479f33637d9SStephan Aßmus
480f33637d9SStephan Aßmus	return B_OK;
481de9dcd41SStephan Aßmus}
482de9dcd41SStephan Aßmus
483de9dcd41SStephan Aßmus
484f33637d9SStephan Aßmusint32
485f33637d9SStephan AßmusBNotification::CountOnClickArgs() const
486f33637d9SStephan Aßmus{
487f33637d9SStephan Aßmus	return fArgv.CountItems();
488f33637d9SStephan Aßmus}
489f33637d9SStephan Aßmus
490f33637d9SStephan Aßmus
491f33637d9SStephan Aßmusconst char*
492f33637d9SStephan AßmusBNotification::OnClickArgAt(int32 index) const
493f33637d9SStephan Aßmus{
494f33637d9SStephan Aßmus	return (char*)fArgv.ItemAt(index);
495f33637d9SStephan Aßmus}
496f33637d9SStephan Aßmus
497f33637d9SStephan Aßmus
498279ca67dSAdrien Destugues/*! \brief Notification's icon.
499279ca67dSAdrien Destugues
500279ca67dSAdrien Destugues	\return Notification's icon.
501279ca67dSAdrien Destugues*/
502f33637d9SStephan Aßmusconst BBitmap*
503de9dcd41SStephan AßmusBNotification::Icon() const
504de9dcd41SStephan Aßmus{
505de9dcd41SStephan Aßmus	return fBitmap;
506de9dcd41SStephan Aßmus}
507de9dcd41SStephan Aßmus
508de9dcd41SStephan Aßmus
509279ca67dSAdrien Destugues/*! \brief Sets notification's icon.
510279ca67dSAdrien Destugues
511279ca67dSAdrien Destugues	Sets notification's icon.
51258844015SJessica Hamilton	This method does not assume ownership of @icon.
513279ca67dSAdrien Destugues
514279ca67dSAdrien Destugues	\param icon Icon
515279ca67dSAdrien Destugues	\return
516279ca67dSAdrien Destugues	- \c B_OK: Everything went fine.
517279ca67dSAdrien Destugues	- \c B_NO_MEMORY: Allocation of @icon copy has failed.
518279ca67dSAdrien Destugues	- \c Other errors: Creation of @icon copy failed for some reason.
519279ca67dSAdrien Destugues*/
520f33637d9SStephan Aßmusstatus_t
521f33637d9SStephan AßmusBNotification::SetIcon(const BBitmap* icon)
522de9dcd41SStephan Aßmus{
523f33637d9SStephan Aßmus	delete fBitmap;
524f33637d9SStephan Aßmus
525f33637d9SStephan Aßmus	if (icon != NULL) {
526f33637d9SStephan Aßmus		fBitmap = new(std::nothrow) BBitmap(icon);
527f33637d9SStephan Aßmus		if (fBitmap == NULL)
528f33637d9SStephan Aßmus			return B_NO_MEMORY;
529f33637d9SStephan Aßmus		return fBitmap->InitCheck();
530f33637d9SStephan Aßmus	}
531f33637d9SStephan Aßmus
532f33637d9SStephan Aßmus	fBitmap = NULL;
533f33637d9SStephan Aßmus	return B_OK;
534de9dcd41SStephan Aßmus}
535279ca67dSAdrien Destugues
536279ca67dSAdrien Destugues
537279ca67dSAdrien Destugues/*! \brief Sends a notification to the notification_server.
538279ca67dSAdrien Destugues
539279ca67dSAdrien Destugues	The notification is delivered asynchronously to the notification_server,
540279ca67dSAdrien Destugues	which will display it according to its settings and filters.
541279ca67dSAdrien Destugues
542279ca67dSAdrien Destugues	\param timeout Microseconds after the message fades out.
543279ca67dSAdrien Destugues	\return
544279ca67dSAdrien Destugues	- \c B_OK: Everything went fine.
545279ca67dSAdrien Destugues	- \c B_BAD_PORT_ID: A connection to notification_server could not be
546279ca67dSAdrien Destugues	  established or the server is not up and running anymore.
547279ca67dSAdrien Destugues	- \c Other errors: Building the message from the notification failed.
548279ca67dSAdrien Destugues*/
549279ca67dSAdrien Destuguesstatus_t
550279ca67dSAdrien DestuguesBNotification::Send(bigtime_t timeout)
551279ca67dSAdrien Destugues{
552279ca67dSAdrien Destugues	BMessage msg(kNotificationMessage);
553279ca67dSAdrien Destugues
554279ca67dSAdrien Destugues	// Archive notification
555279ca67dSAdrien Destugues	status_t ret = Archive(&msg);
556279ca67dSAdrien Destugues
557279ca67dSAdrien Destugues	// Custom time out
558279ca67dSAdrien Destugues	if (ret == B_OK && timeout > 0)
559279ca67dSAdrien Destugues		ret = msg.AddInt64("timeout", timeout);
560279ca67dSAdrien Destugues
561279ca67dSAdrien Destugues	// Send message
562279ca67dSAdrien Destugues	if (ret == B_OK) {
563279ca67dSAdrien Destugues		BMessenger server(kNotificationServerSignature);
564279ca67dSAdrien Destugues		ret = server.SendMessage(&msg);
565279ca67dSAdrien Destugues	}
566279ca67dSAdrien Destugues
567279ca67dSAdrien Destugues	return ret;
568279ca67dSAdrien Destugues}
5698856b518SBrian Hill
5708856b518SBrian Hill
5718856b518SBrian Hillvoid BNotification::_ReservedNotification1() {}
5728856b518SBrian Hillvoid BNotification::_ReservedNotification2() {}
5738856b518SBrian Hillvoid BNotification::_ReservedNotification3() {}
5748856b518SBrian Hillvoid BNotification::_ReservedNotification4() {}
5758856b518SBrian Hillvoid BNotification::_ReservedNotification5() {}
5768856b518SBrian Hillvoid BNotification::_ReservedNotification6() {}
5778856b518SBrian Hillvoid BNotification::_ReservedNotification7() {}
5788856b518SBrian Hillvoid BNotification::_ReservedNotification8() {}
579