From 908967a199bb9fa6af6bf22584d79e3f776b9f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Thu, 27 May 2010 21:13:11 +0000 Subject: [PATCH] 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 --- headers/os/app/Notification.h | 13 ++++++------- src/kits/app/Notification.cpp | 34 ++++++++++++---------------------- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/headers/os/app/Notification.h b/headers/os/app/Notification.h index 05e925503d..22d61ab522 100644 --- a/headers/os/app/Notification.h +++ b/headers/os/app/Notification.h @@ -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; diff --git a/src/kits/app/Notification.cpp b/src/kits/app/Notification.cpp index 07c4dcc1b8..90c4f14689 100644 --- a/src/kits/app/Notification.cpp +++ b/src/kits/app/Notification.cpp @@ -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;