Improved the BNotification API after suggestions from Karsten, thanks! Using

cosnt BString& instead of const char* could potentially save copying the string,
although in most use cases, it will probably ammount to the same thing. It may
provide more flexibility later on, like for example when BString knows its
encoding or something similar. Removed superfluous second version of
AddOnClickRef().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36958 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2010-05-27 21:13:11 +00:00
parent 8984ae973b
commit 908967a199
2 changed files with 18 additions and 29 deletions

View File

@ -30,32 +30,31 @@ public:
notification_type Type() const;
const char* Application() const;
void SetApplication(const char* app);
void SetApplication(const BString& app);
const char* Title() const;
void SetTitle(const char* title);
void SetTitle(const BString& title);
const char* Content() const;
void SetContent(const char* content);
void SetContent(const BString& content);
const char* MessageID() const;
void SetMessageID(const char* id);
void SetMessageID(const BString& id);
float Progress() const;
void SetProgress(float progress);
const char* OnClickApp() const;
void SetOnClickApp(const char* app);
void SetOnClickApp(const BString& app);
const entry_ref* OnClickFile() const;
status_t SetOnClickFile(const entry_ref* file);
status_t AddOnClickRef(const entry_ref* ref);
status_t AddOnClickRef(const entry_ref& ref);
int32 CountOnClickRefs() const;
const entry_ref* OnClickRefAt(int32 index) const;
status_t AddOnClickArg(const char* arg);
status_t AddOnClickArg(const BString& arg);
int32 CountOnClickArgs() const;
const char* OnClickArgAt(int32 index) const;

View File

@ -56,7 +56,7 @@ BNotification::Application() const
void
BNotification::SetApplication(const char* app)
BNotification::SetApplication(const BString& app)
{
fAppName = app;
}
@ -70,7 +70,7 @@ BNotification::Title() const
void
BNotification::SetTitle(const char* title)
BNotification::SetTitle(const BString& title)
{
fTitle = title;
}
@ -84,7 +84,7 @@ BNotification::Content() const
void
BNotification::SetContent(const char* content)
BNotification::SetContent(const BString& content)
{
fContent = content;
}
@ -98,7 +98,7 @@ BNotification::MessageID() const
void
BNotification::SetMessageID(const char* id)
BNotification::SetMessageID(const BString& id)
{
fID = id;
}
@ -126,7 +126,7 @@ BNotification::OnClickApp() const
void
BNotification::SetOnClickApp(const char* app)
BNotification::SetOnClickApp(const BString& app)
{
fApp = app;
}
@ -161,7 +161,11 @@ BNotification::AddOnClickRef(const entry_ref* ref)
if (ref == NULL)
return B_BAD_VALUE;
return AddOnClickRef(*ref);
entry_ref* clonedRef = new(std::nothrow) entry_ref(*ref);
if (clonedRef == NULL || !fRefs.AddItem(clonedRef))
return B_NO_MEMORY;
return B_OK;
}
@ -180,23 +184,9 @@ BNotification::OnClickRefAt(int32 index) const
status_t
BNotification::AddOnClickRef(const entry_ref& ref)
BNotification::AddOnClickArg(const BString& arg)
{
entry_ref* clonedRef = new(std::nothrow) entry_ref(ref);
if (clonedRef == NULL || !fRefs.AddItem(clonedRef))
return B_NO_MEMORY;
return B_OK;
}
status_t
BNotification::AddOnClickArg(const char* arg)
{
if (arg == NULL)
return B_BAD_VALUE;
char* clonedArg = strdup(arg);
char* clonedArg = strdup(arg.String());
if (clonedArg == NULL || !fArgv.AddItem(clonedArg))
return B_NO_MEMORY;