/** Copyright 2019-2020 Haiku, Inc. All rights reserved.* Distributed under the terms of the MIT License.** Authors:* Niels Sascha Reedijk, niels.reedijk@gmail.com** Corresponds to:* headers/os/app/Notification.h hrev51445* src/kits/app/Notification.cpp hrev52287*//*!\file Notification.h\ingroup app\ingroup libbe\brief Provides BNotification class and the notification_type enum.*////// notification_type enum //////*!\enum notification_type\brief Visual style of the notification.\since Haiku R1*//*!\var notification_type::B_INFORMATION_NOTIFICATION\brief Information typeThis will have the notification appear with a grey side bar.\image html notification_information_type.png\since Haiku R1*//*!\var notification_type::B_IMPORTANT_NOTIFICATION\brief Important typeThis will have the notification appear with a blue side bar.\image html notification_important_type.png\since Haiku R1*//*!\var notification_type::B_ERROR_NOTIFICATION\brief Error typeThis will have the notification appear with a red side bar.\image html notification_error_type.png\since Haiku R1*//*!\var notification_type::B_PROGRESS_NOTIFICATION\brief Progress typeThis will have the notification appear with a progress bar.\image html notification_progress_type.png\since Haiku R1*////// BNotification class //////*!\class BNotification\ingroup app\ingroup libbe\brief Construct system-default notifications to be displayed to the user.Haiku provides a notification system that allows you to display messages tothe user. There is quite some flexibility in how the message is presented.You may use this class to build and send the notification. The propertiesyou can set are:- The \link BNotification::BNotification() type of notification\endlink,which can be an information message, a warning, an error, or a progressmessage.- The \link BNotification::SetGroup() group\endlink, which allows you toorganize notification display into different categories.- A \link BNotification::SetTitle() title\endlink, which is a distincttext element at the top of a notification view.- The \link BNotification::SetContent() content\endlink, which is the textmessage that is shown to the user.- A \link BNotification::SetMessageID() message identifier\endlink thatallows you to modify the contents of a message that is being displayed,which is particularly useful for progress notifications.- For progress notifications, the\link BNotification::SetProgress() percentage of completion\endlink can beset.- By default the notification uses the application's icon, but you mayset an \link BNotification::SetIcon() alternative icon\endlink.- Finally there are a few ways you can configure the actions that happenwhen a user clicks the notification. More on that below.For example, with the following code, you may display a notification:\code{.cpp}BNotification notification(B_PROGRESS_NOTIFICATION);notification.SetGroup("Group");notification.SetTitle("Title");notification.SetContent("This is the content");notification.SetMessageID("mainwindow_progress");notification.SetProgress(0.5);notification.Send();\endcode\image html notification_intro.pngNote that in the previous code example, we set a\link BNotification::SetMessageID message identifier\endlink, which willallow to update the notification when we have progressed. The use would be:\code{.cpp}// After sending the notification, you retain ownership so that you can update itnotification.SetProgress(0.7);// In order to display the update, you send it againnotification.Send();\endcodeFurthermore, it is possible to support some form of follow-up action, whenthe user clicks the notification. First of all, you need to choose whetheryou want to \link BNotification::SetOnClickApp() open a specificapplication\endlink, or whether you want to\link BNotification::SetOnClickFile() open a specific file\endlink and havethe system determine which application fits that. Additionally, you mayspecify \link BNotification::AddOnClickArg() command line arguments\endlinkor pass additional \link BNotification::AddOnClickRef() filereferences\endlink for the receiving application to process.Finally, a note about the \c notification_server and how it groups andhandles messages coming from your application. The system is aware of thesource of the notifications, and identifies your application by it'ssignature. That means that the identification of your application isconsistent, even if it is restarted, or if you have multiple instancesrunning. This impacts the \link BNotification::SetGroup() grouping\endlinkfunctionality and the \link BNotification::SetMessageID() messageupdating\endlink functionality. If you have an application that can havemultiple instances, you will need to make sure that you properly manageyour group names and identifiers if you want to keep things separate.\since Haiku R1*//*!\fn BNotification::BNotification(notification_type type)\brief Construct an empty message, with the specified \a type.The type influences the style of the notification view. See the\ref notification_type enumerator for details.\since Haiku R1*//*!\fn BNotification::BNotification(BMessage* archive)\brief Construct a notification from an archive.\since Haiku R1*//*!\fn virtual BNotification::~BNotification()\brief Frees all resources associated with the object.\since Haiku R1*//*!\fn status_t BNotification::InitCheck() const\brief Returns the status of the constructor.\since Haiku R1*//*!\fn static BArchivable* BNotification::Instantiate(BMessage* archive)\brief Returns a new BNotification object from \a archive.This class implements the archiving API, and as such, you canbuild a new BNotification object from a previously createdBMessage archive. However, if the message doesn't contain an archived datafor a BNotification object, this method returns \c NULL.\returns BNotification object from \a archive or \c NULL if it doesn'tcontain a valid BNotification object.\since Haiku R1*//*!\fn virtual status_t BNotification::Archive(BMessage* archive,bool deep = true) const\brief Archives the BNotification in the \c archive.\see BArchivable::Archive(), Instantiate() static function.\returns \c B_OK: if everything went fine, or other errors that describe whyarchiving has failed.\since Haiku R1*//*!\fn const char* BNotification::SourceSignature() const\brief Returns signature of the application where the notificationoriginated.When you build your own notifications, this will contain the signature ofthe current application. If you receive notifications from otherapplications, it will include theirs.\returns Signature of the source application.\since Haiku R1*//*!\fn const char* BNotification::SourceName() const\brief Returns the name of the application where the notificationoriginated.When you build your own notifications, this will contain the name ofthe current application. If you receive notifications from otherapplications, it will include theirs.\returns Name of the source application.\since Haiku R1*//*!\fn notification_type BNotification::Type() const\brief Returns the type of the notification.\returns A value of the \c notification_type enum that representsnotification type.\since Haiku R1*//*!\fn const char* BNotification::Group() const\brief Returns the group of the notification.\see BNotification::SetGroup() for more information about groups.\returns The string of the notification's group.\since Haiku R1*//*!\fn void BNotification::SetGroup(const BString& group)\brief Set a group for the notifcation.The default behaviour of the \c notification_server is group the visiblenotifications per running application, and then in order in which they havebeen received. There may be situations where you want to override thatbehavior and group related notifications. When you set a group name, the\c notification_server will create a box with the \c group name as label,and insert all related notifications in that box.\image html notification_group.png\since Haiku R1*//*!\fn const char* BNotification::Title() const\brief Returns the title of the notification.\returns The title of the notification as a string.\since Haiku R1*//*!\fn void BNotification::SetTitle(const BString& title)\brief Set a title for the notification.\since Haiku R1*//*!\fn const char* BNotification::Content() const\brief Returns the message of the notification.\returns The message of the notification as a string.\since Haiku R1*//*!\fn void BNotification::SetContent(const BString& content)\brief Set a message for the notification.\since Haiku R1*//*!\fn const char* BNotification::MessageID() const\brief Returns the identifier of the notification.\see BNotification::SetMessageID() for the purpose of having an identifier.\returns The identifier of the notification as a string.\since Haiku R1*//*!\fn void BNotification::SetMessageID(const BString& id)\brief Sets notification's message identifier.If you want to update the contents of an existing notification, you canset a identifier for this message. When you send a new or updated messagewith the same identifier, the \c notification_server will update theexisting message with the new content.In order to effectively use this feature, you will have to make sure theidentifier is unique within the current application.\since Haiku R1*//*!\fn float BNotification::Progress() const\brief Returns the progress for the notification.\see BNotification::SetProgress() for more information about this value.\returns A value between 0.0 and 1.0 if notification's type is\c B_PROGRESS_NOTIFICATION, or otherwise -1.\since Haiku R1*//*!\fn void BNotification::SetProgress(float progress)\brief Sets progress information.When you are building a notification of the type \c B_PROGRESS_NOTIFICATIONthe notification view will show a progress bar and a label thatexpresses the progress in a percentage. Using this method you can setwhat the bar and label express.The valid range is between 0.0 and 1.0. If \c progress is lower than 0.0(i.e. negative), the value will be set to 0.0. If it is higher than 1.0,it will be set to 1.0.\since Haiku R1*//*!\fn const char* BNotification::OnClickApp() const\brief Returns the signature of the application that will be called whenthe notification is clicked.\see More information about this property in BNotification::SetOnClickApp().\since Haiku R1*//*!\fn void BNotification::SetOnClickApp(const BString& app)\brief Set which application should be called when the notification isclicked by the user.The value \c app should be a valid application signature, for example\c 'application/x-vnd.Haiku-StyledEdit'.Using this property has precedence on when BNotification::SetOnClickFile()is used. If you want interacting with the notification opening a specificfile, then you should use this method in combination withBNotification::AddOnClickRef().\see Additional actions and parameters can be set throughBNotification::SetOnClickFile(), BNotification::AddOnClickRef()and BNotification::AddOnClickArg().\since Haiku R1*//*!\fn const entry_ref* BNotification::OnClickFile() const\brief Returns the reference to the file that will be opened when thenotification is clicked.\see More information about this property in BNotification::SetOnClickFile().\since Haiku R1*//*!\fn status_t BNotification::SetOnClickFile(const entry_ref* file)\brief Set which file should be opened when the notification isclicked by the user.The file will be opened by the default application for this file type.You cannot use this action in combination withBNotification::SetOnClickApp(). If you use this way of setting an action,this action will be ignored.\see Additional actions and parameters can be set throughBNotification::SetOnClickApp(), BNotification::AddOnClickRef()and BNotification::AddOnClickArg().\since Haiku R1*//*!\fn status_t BNotification::AddOnClickRef(const entry_ref* ref)\brief Add a \c ref to the list of arguments passed when a user clicks thenotification.This method allows you to construct a list of refs, that will be sent tothe application specified by BNotification::AddOnClickApp(), or the onethat is associated with BNotification::AddOnClickFile(). The refs will behandled by the application's BApplication::RefsReceived() hook method.\since Haiku R1*//*!\fn int32 BNotification::CountOnClickRefs() const\brief Returns the number of refs to be passed when the user clicks onthe notification.\see BNotification::AddOnClickRef()\since Haiku R1*//*!\fn const entry_ref* BNotification::OnClickRefAt(int32 index) const\brief Returns the ref that is stored at \c index.\see BNotification::AddOnClickRef()\since Haiku R1*//*!\fn status_t BNotification::AddOnClickArg(const BString& arg)\brief Add to a list of arguments that are passed to an application whenthe user clicks on the notification.This method allows you to construct a list of arguments, that will be sentto the application specified by BNotification::AddOnClickApp(), or the onethat is associated with BNotification::AddOnClickFile(). The args will behandled by the application's BApplication::ArgvReceived() hook method.\since Haiku R1*//*!\fn int32 BNotification::CountOnClickArgs() const\brief Returns the number of args to be passed when the user clicks onthe notification.\see BNotification::AddOnClickArg()\since Haiku R1*//*!\fn const char* BNotification::OnClickArgAt(int32 index) const\brief Returns the arg that is stored at \c index.\see BNotification::AddOnClickArg()\since Haiku R1*//*!\fn const BBitmap* BNotification::Icon() const\brief Returns the icon for the notification.\see BNotification::SetIcon() for more information on this property.\return Returns a borrowed unchangeable reference to the icon.\since Haiku R1*//*!\fn status_t BNotification::SetIcon(const BBitmap* icon)\brief Set the icon of the notification.Set the icon for the notification. By default, the application icon isused. This method makes a copy of the \a icon.\param icon The icon that should be displayed with the notification.\returns \c B_OK if everything went fine, \c B_NO_MEMORY when the \a iconcould not be copied, or another error if something else wentwrong.\since Haiku R1*//*!\fn status_t BNotification::Send(bigtime_t timeout = -1)\brief Send the notification to the notification_server.The notification is delivered asynchronously to the notification_server,which will display it according to its settings and filters.After sending, you retain ownership of the notification. The advantage isthat you can re-use the notification at a later moment, or use the object toupdate the notification. See BNotification::SetMessageID() about updatingdisplayed notifications. If you allocate the notification on the heap, besure to free the memory.\param timeout The \a timeout in microsecond that the notification shouldbe displayed. If you want to use the default timing, use the defaultargument or pass \c -1.\returns \c B_OK if everything went fine, \c B_BAD_PORT_ID if there was aproblem connecting to the \c notification_server, or any othererrors if something went wrong transmitting the notification.\since Haiku R1*/