Construct system-default notifications to be displayed to the user. More...
Inherits BArchivable.
Public Member Functions | |
BNotification (BMessage *archive) | |
Construct a notification from an archive. | |
BNotification (notification_type type) | |
Construct an empty message, with the specified type. | |
virtual | ~BNotification () |
Frees all resources associated with the object. | |
status_t | AddOnClickArg (const BString &arg) |
Add to a list of arguments that are passed to an application when the user clicks on the notification. | |
status_t | AddOnClickRef (const entry_ref *ref) |
Add a ref to the list of arguments passed when a user clicks the notification. | |
virtual status_t | Archive (BMessage *archive, bool deep=true) const |
Archives the BNotification in the archive . | |
const char * | Content () const |
Returns the message of the notification. | |
int32 | CountOnClickArgs () const |
Returns the number of args to be passed when the user clicks on the notification. | |
int32 | CountOnClickRefs () const |
Returns the number of refs to be passed when the user clicks on the notification. | |
const char * | Group () const |
Returns the group of the notification. | |
const BBitmap * | Icon () const |
Returns the icon for the notification. | |
status_t | InitCheck () const |
Returns the status of the constructor. | |
const char * | MessageID () const |
Returns the identifier of the notification. | |
const char * | OnClickApp () const |
Returns the signature of the application that will be called when the notification is clicked. | |
const char * | OnClickArgAt (int32 index) const |
Returns the arg that is stored at index . | |
const entry_ref * | OnClickFile () const |
Returns the reference to the file that will be opened when the notification is clicked. | |
const entry_ref * | OnClickRefAt (int32 index) const |
Returns the ref that is stored at index . | |
float | Progress () const |
Returns the progress for the notification. | |
status_t | Send (bigtime_t timeout=-1) |
Send the notification to the notification_server. | |
void | SetContent (const BString &content) |
Set a message for the notification. | |
void | SetGroup (const BString &group) |
Set a group for the notifcation. | |
status_t | SetIcon (const BBitmap *icon) |
Set the icon of the notification. | |
void | SetMessageID (const BString &id) |
Sets notification's message identifier. | |
void | SetOnClickApp (const BString &app) |
Set which application should be called when the notification is clicked by the user. | |
status_t | SetOnClickFile (const entry_ref *file) |
Set which file should be opened when the notification is clicked by the user. | |
void | SetProgress (float progress) |
Sets progress information. | |
void | SetTitle (const BString &title) |
Set a title for the notification. | |
const char * | SourceName () const |
Returns the name of the application where the notification originated. | |
const char * | SourceSignature () const |
Returns signature of the application where the notification originated. | |
const char * | Title () const |
Returns the title of the notification. | |
notification_type | Type () const |
Returns the type of the notification. | |
Public Member Functions inherited from BArchivable | |
BArchivable () | |
Constructor. Does nothing. | |
BArchivable (BMessage *from) | |
Constructor. Does important behind-the-scenes work in the unarchiving process. | |
virtual | ~BArchivable () |
Destructor. Does nothing. | |
virtual status_t | AllArchived (BMessage *archive) const |
Method relating to the use of BArchiver . | |
virtual status_t | AllUnarchived (const BMessage *archive) |
Method relating to the use of BUnarchiver . | |
virtual status_t | Archive (BMessage *into, bool deep=true) const |
Archive the object into a BMessage. | |
virtual status_t | Perform (perform_code d, void *arg) |
Perform some action (Internal method defined for binary compatibility purposes). | |
Static Public Member Functions | |
static BArchivable * | Instantiate (BMessage *archive) |
Returns a new BNotification object from archive. | |
Static Public Member Functions inherited from BArchivable | |
static BArchivable * | Instantiate (BMessage *archive) |
Static member to restore objects from messages. | |
Construct system-default notifications to be displayed to the user.
Haiku provides a notification system that allows you to display messages to the user. There is quite some flexibility in how the message is presented. You may use this class to build and send the notification. The properties you can set are:
For example, with the following code, you may display a notification:
Note that in the previous code example, we set a message identifier, which will allow to update the notification when we have progressed. The use would be:
Furthermore, it is possible to support some form of follow-up action, when the user clicks the notification. First of all, you need to choose whether you want to open a specific application, or whether you want to open a specific file and have the system determine which application fits that. Additionally, you may specify command line arguments or pass additional file references for the receiving application to process.
Finally, a note about the notification_server
and how it groups and handles messages coming from your application. The system is aware of the source of the notifications, and identifies your application by it's signature. That means that the identification of your application is consistent, even if it is restarted, or if you have multiple instances running. This impacts the grouping functionality and the message updating functionality. If you have an application that can have multiple instances, you will need to make sure that you properly manage your group names and identifiers if you want to keep things separate.
BNotification::BNotification | ( | notification_type | type | ) |
Construct an empty message, with the specified type.
The type influences the style of the notification view. See the notification_type enumerator for details.
BNotification::BNotification | ( | BMessage * | archive | ) |
Construct a notification from an archive.
|
virtual |
Frees all resources associated with the object.
Add to a list of arguments that are passed to an application when the user clicks on the notification.
This method allows you to construct a list of arguments, that will be sent to the application specified by BNotification::AddOnClickApp(), or the one that is associated with BNotification::AddOnClickFile(). The args will be handled by the application's BApplication::ArgvReceived() hook method.
Add a ref
to the list of arguments passed when a user clicks the notification.
This method allows you to construct a list of refs, that will be sent to the application specified by BNotification::AddOnClickApp(), or the one that is associated with BNotification::AddOnClickFile(). The refs will be handled by the application's BApplication::RefsReceived() hook method.
Archives the BNotification in the archive
.
B_OK:
if everything went fine, or other errors that describe why archiving has failed.Reimplemented from BArchivable.
const char * BNotification::Content | ( | ) | const |
Returns the message of the notification.
int32 BNotification::CountOnClickArgs | ( | ) | const |
Returns the number of args to be passed when the user clicks on the notification.
int32 BNotification::CountOnClickRefs | ( | ) | const |
Returns the number of refs to be passed when the user clicks on the notification.
const char * BNotification::Group | ( | ) | const |
Returns the group of the notification.
const BBitmap * BNotification::Icon | ( | ) | const |
Returns the icon for the notification.
status_t BNotification::InitCheck | ( | ) | const |
Returns the status of the constructor.
|
static |
Returns a new BNotification object from archive.
This class implements the archiving API, and as such, you can build a new BNotification object from a previously created BMessage archive. However, if the message doesn't contain an archived data for a BNotification object, this method returns NULL
.
NULL
if it doesn't contain a valid BNotification object.const char * BNotification::MessageID | ( | ) | const |
Returns the identifier of the notification.
const char * BNotification::OnClickApp | ( | ) | const |
Returns the signature of the application that will be called when the notification is clicked.
const char * BNotification::OnClickArgAt | ( | int32 | index | ) | const |
const entry_ref * BNotification::OnClickFile | ( | ) | const |
Returns the reference to the file that will be opened when the notification is clicked.
float BNotification::Progress | ( | ) | const |
Returns the progress for the notification.
B_PROGRESS_NOTIFICATION
, or otherwise -1.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 is that you can re-use the notification at a later moment, or use the object to update the notification. See BNotification::SetMessageID() about updating displayed notifications. If you allocate the notification on the heap, be sure to free the memory.
timeout | The timeout in microsecond that the notification should be displayed. If you want to use the default timing, use the default argument or pass -1 . |
B_OK
if everything went fine, B_BAD_PORT_ID
if there was a problem connecting to the notification_server
, or any other errors if something went wrong transmitting the notification.void BNotification::SetContent | ( | const BString & | content | ) |
Set a message for the notification.
void BNotification::SetGroup | ( | const BString & | group | ) |
Set a group for the notifcation.
The default behaviour of the notification_server
is group the visible notifications per running application, and then in order in which they have been received. There may be situations where you want to override that behavior and group related notifications. When you set a group name, the notification_server
will create a box with the group
name as label, and insert all related notifications in that box.
Set the icon of the notification.
Set the icon for the notification. By default, the application icon is used. This method makes a copy of the icon.
icon | The icon that should be displayed with the notification. |
B_OK
if everything went fine, B_NO_MEMORY
when the icon could not be copied, or another error if something else went wrong.void BNotification::SetMessageID | ( | const BString & | id | ) |
Sets notification's message identifier.
If you want to update the contents of an existing notification, you can set a identifier for this message. When you send a new or updated message with the same identifier, the notification_server
will update the existing message with the new content.
In order to effectively use this feature, you will have to make sure the identifier is unique within the current application.
void BNotification::SetOnClickApp | ( | const BString & | app | ) |
Set which application should be called when the notification is clicked by the user.
The value app
should be a valid application signature, for example '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 specific file, then you should use this method in combination with BNotification::AddOnClickRef().
Set which file should be opened when the notification is clicked by the user.
The file will be opened by the default application for this file type.
You cannot use this action in combination with BNotification::SetOnClickApp(). If you use this way of setting an action, this action will be ignored.
void BNotification::SetProgress | ( | float | progress | ) |
Sets progress information.
When you are building a notification of the type B_PROGRESS_NOTIFICATION
the notification view will show a progress bar and a label that expresses the progress in a percentage. Using this method you can set what the bar and label express.
The valid range is between 0.0 and 1.0. If 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.
void BNotification::SetTitle | ( | const BString & | title | ) |
Set a title for the notification.
const char * BNotification::SourceName | ( | ) | const |
Returns the name of the application where the notification originated.
When you build your own notifications, this will contain the name of the current application. If you receive notifications from other applications, it will include theirs.
const char * BNotification::SourceSignature | ( | ) | const |
Returns signature of the application where the notification originated.
When you build your own notifications, this will contain the signature of the current application. If you receive notifications from other applications, it will include theirs.
const char * BNotification::Title | ( | ) | const |
Returns the title of the notification.
notification_type BNotification::Type | ( | ) | const |
Returns the type of the notification.
notification_type
enum that represents notification type.