[haiku-commits] r36958 - in haiku/trunk: headers/os/app src/kits/app

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 27 May 2010 23:13:11 +0200 (CEST)

Author: stippi
Date: 2010-05-27 23:13:11 +0200 (Thu, 27 May 2010)
New Revision: 36958
Changeset: http://dev.haiku-os.org/changeset/36958/haiku

Modified:
   haiku/trunk/headers/os/app/Notification.h
   haiku/trunk/src/kits/app/Notification.cpp
Log:
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().


Modified: haiku/trunk/headers/os/app/Notification.h
===================================================================
--- haiku/trunk/headers/os/app/Notification.h   2010-05-27 20:42:53 UTC (rev 
36957)
+++ haiku/trunk/headers/os/app/Notification.h   2010-05-27 21:13:11 UTC (rev 
36958)
@@ -30,32 +30,31 @@
                        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;
 

Modified: haiku/trunk/src/kits/app/Notification.cpp
===================================================================
--- haiku/trunk/src/kits/app/Notification.cpp   2010-05-27 20:42:53 UTC (rev 
36957)
+++ haiku/trunk/src/kits/app/Notification.cpp   2010-05-27 21:13:11 UTC (rev 
36958)
@@ -56,7 +56,7 @@
 
 
 void
-BNotification::SetApplication(const char* app)
+BNotification::SetApplication(const BString& app)
 {
        fAppName = app;
 }
@@ -70,7 +70,7 @@
 
 
 void
-BNotification::SetTitle(const char* title)
+BNotification::SetTitle(const BString& title)
 {
        fTitle = title;
 }
@@ -84,7 +84,7 @@
 
 
 void
-BNotification::SetContent(const char* content)
+BNotification::SetContent(const BString& content)
 {
        fContent = content;
 }
@@ -98,7 +98,7 @@
 
 
 void
-BNotification::SetMessageID(const char* id)
+BNotification::SetMessageID(const BString& id)
 {
        fID = id;
 }
@@ -126,7 +126,7 @@
 
 
 void
-BNotification::SetOnClickApp(const char* app)
+BNotification::SetOnClickApp(const BString& app)
 {
        fApp = app;
 }
@@ -161,7 +161,11 @@
        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 @@
 
 
 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;
 


Other related posts:

  • » [haiku-commits] r36958 - in haiku/trunk: headers/os/app src/kits/app - superstippi