1a72f3582SNiels Sascha Reedijk/* 202e45e32SNiels Sascha Reedijk * Copyright 2019-2020 Haiku, Inc. All rights reserved. 3a72f3582SNiels Sascha Reedijk * Distributed under the terms of the MIT License. 4a72f3582SNiels Sascha Reedijk * 5a72f3582SNiels Sascha Reedijk * Authors: 6a72f3582SNiels Sascha Reedijk * Niels Sascha Reedijk, niels.reedijk@gmail.com 7a72f3582SNiels Sascha Reedijk * 8a72f3582SNiels Sascha Reedijk * Corresponds to: 9a72f3582SNiels Sascha Reedijk * headers/os/app/Notification.h hrev51445 10a72f3582SNiels Sascha Reedijk * src/kits/app/Notification.cpp hrev52287 11a72f3582SNiels Sascha Reedijk */ 12a72f3582SNiels Sascha Reedijk 13a72f3582SNiels Sascha Reedijk 14a72f3582SNiels Sascha Reedijk /*! 15a72f3582SNiels Sascha Reedijk \file Notification.h 16a72f3582SNiels Sascha Reedijk \ingroup app 17a72f3582SNiels Sascha Reedijk \ingroup libbe 18a72f3582SNiels Sascha Reedijk \brief Provides BNotification class and the notification_type enum. 19a72f3582SNiels Sascha Reedijk*/ 20a72f3582SNiels Sascha Reedijk 21a72f3582SNiels Sascha Reedijk 22a72f3582SNiels Sascha Reedijk///// notification_type enum ///// 23a72f3582SNiels Sascha Reedijk 24a72f3582SNiels Sascha Reedijk 25a72f3582SNiels Sascha Reedijk/*! 26a72f3582SNiels Sascha Reedijk \enum notification_type 2702e45e32SNiels Sascha Reedijk \brief Visual style of the notification. 28a72f3582SNiels Sascha Reedijk 29a72f3582SNiels Sascha Reedijk \since Haiku R1 30a72f3582SNiels Sascha Reedijk*/ 31a72f3582SNiels Sascha Reedijk 32a72f3582SNiels Sascha Reedijk 33a72f3582SNiels Sascha Reedijk/*! 34a72f3582SNiels Sascha Reedijk \var notification_type::B_INFORMATION_NOTIFICATION 3502e45e32SNiels Sascha Reedijk \brief Information type 3602e45e32SNiels Sascha Reedijk 3702e45e32SNiels Sascha Reedijk This will have the notification appear with a grey side bar. 3802e45e32SNiels Sascha Reedijk 3902e45e32SNiels Sascha Reedijk \image html notification_information_type.png 40a72f3582SNiels Sascha Reedijk 41a72f3582SNiels Sascha Reedijk \since Haiku R1 42a72f3582SNiels Sascha Reedijk*/ 43a72f3582SNiels Sascha Reedijk 44a72f3582SNiels Sascha Reedijk 45a72f3582SNiels Sascha Reedijk/*! 46a72f3582SNiels Sascha Reedijk \var notification_type::B_IMPORTANT_NOTIFICATION 4702e45e32SNiels Sascha Reedijk \brief Important type 4802e45e32SNiels Sascha Reedijk 4902e45e32SNiels Sascha Reedijk This will have the notification appear with a blue side bar. 5002e45e32SNiels Sascha Reedijk 5102e45e32SNiels Sascha Reedijk \image html notification_important_type.png 52a72f3582SNiels Sascha Reedijk 53a72f3582SNiels Sascha Reedijk \since Haiku R1 54a72f3582SNiels Sascha Reedijk*/ 55a72f3582SNiels Sascha Reedijk 56a72f3582SNiels Sascha Reedijk 57a72f3582SNiels Sascha Reedijk/*! 58a72f3582SNiels Sascha Reedijk \var notification_type::B_ERROR_NOTIFICATION 5902e45e32SNiels Sascha Reedijk \brief Error type 6002e45e32SNiels Sascha Reedijk 6102e45e32SNiels Sascha Reedijk This will have the notification appear with a red side bar. 6202e45e32SNiels Sascha Reedijk 6302e45e32SNiels Sascha Reedijk \image html notification_error_type.png 64a72f3582SNiels Sascha Reedijk 65a72f3582SNiels Sascha Reedijk \since Haiku R1 66a72f3582SNiels Sascha Reedijk*/ 67a72f3582SNiels Sascha Reedijk 68a72f3582SNiels Sascha Reedijk 69a72f3582SNiels Sascha Reedijk/*! 70a72f3582SNiels Sascha Reedijk \var notification_type::B_PROGRESS_NOTIFICATION 7102e45e32SNiels Sascha Reedijk \brief Progress type 7202e45e32SNiels Sascha Reedijk 7302e45e32SNiels Sascha Reedijk This will have the notification appear with a progress bar. 7402e45e32SNiels Sascha Reedijk 7502e45e32SNiels Sascha Reedijk \image html notification_progress_type.png 76a72f3582SNiels Sascha Reedijk 77a72f3582SNiels Sascha Reedijk \since Haiku R1 78a72f3582SNiels Sascha Reedijk*/ 79a72f3582SNiels Sascha Reedijk 80a72f3582SNiels Sascha Reedijk 81a72f3582SNiels Sascha Reedijk///// BNotification class ///// 82a72f3582SNiels Sascha Reedijk 83a72f3582SNiels Sascha Reedijk 84a72f3582SNiels Sascha Reedijk/*! 85a72f3582SNiels Sascha Reedijk \class BNotification 86a8081885SNiels Sascha Reedijk \ingroup app 87a8081885SNiels Sascha Reedijk \ingroup libbe 8802e45e32SNiels Sascha Reedijk \brief Construct system-default notifications to be displayed to the user. 8902e45e32SNiels Sascha Reedijk 9002e45e32SNiels Sascha Reedijk Haiku provides a notification system that allows you to display messages to 9102e45e32SNiels Sascha Reedijk the user. There is quite some flexibility in how the message is presented. 9202e45e32SNiels Sascha Reedijk You may use this class to build and send the notification. The properties 9302e45e32SNiels Sascha Reedijk you can set are: 9402e45e32SNiels Sascha Reedijk - The \link BNotification::BNotification() type of notification\endlink, 9502e45e32SNiels Sascha Reedijk which can be an information message, a warning, an error, or a progress 9602e45e32SNiels Sascha Reedijk message. 9702e45e32SNiels Sascha Reedijk - The \link BNotification::SetGroup() group\endlink, which allows you to 9802e45e32SNiels Sascha Reedijk organize notification display into different categories. 9902e45e32SNiels Sascha Reedijk - A \link BNotification::SetTitle() title\endlink, which is a distinct 10002e45e32SNiels Sascha Reedijk text element at the top of a notification view. 10102e45e32SNiels Sascha Reedijk - The \link BNotification::SetContent() content\endlink, which is the text 10202e45e32SNiels Sascha Reedijk message that is shown to the user. 10302e45e32SNiels Sascha Reedijk - A \link BNotification::SetMessageID() message identifier\endlink that 10402e45e32SNiels Sascha Reedijk allows you to modify the contents of a message that is being displayed, 10502e45e32SNiels Sascha Reedijk which is particularly useful for progress notifications. 10602e45e32SNiels Sascha Reedijk - For progress notifications, the 10702e45e32SNiels Sascha Reedijk \link BNotification::SetProgress() percentage of completion\endlink can be 10802e45e32SNiels Sascha Reedijk set. 10902e45e32SNiels Sascha Reedijk - By default the notification uses the application's icon, but you may 11002e45e32SNiels Sascha Reedijk set an \link BNotification::SetIcon() alternative icon\endlink. 11102e45e32SNiels Sascha Reedijk - Finally there are a few ways you can configure the actions that happen 11202e45e32SNiels Sascha Reedijk when a user clicks the notification. More on that below. 11302e45e32SNiels Sascha Reedijk 11402e45e32SNiels Sascha Reedijk For example, with the following code, you may display a notification: 11502e45e32SNiels Sascha Reedijk 11602e45e32SNiels Sascha Reedijk \code{.cpp} 11702e45e32SNiels Sascha Reedijk BNotification notification(B_PROGRESS_NOTIFICATION); 11802e45e32SNiels Sascha Reedijk notification.SetGroup("Group"); 11902e45e32SNiels Sascha Reedijk notification.SetTitle("Title"); 12002e45e32SNiels Sascha Reedijk notification.SetContent("This is the content"); 121*683d891aSAdrien Destugues notification.SetMessageID("mainwindow_progress"); 12202e45e32SNiels Sascha Reedijk notification.SetProgress(0.5); 12302e45e32SNiels Sascha Reedijk notification.Send(); 12402e45e32SNiels Sascha Reedijk \endcode 12502e45e32SNiels Sascha Reedijk 12602e45e32SNiels Sascha Reedijk \image html notification_intro.png 12702e45e32SNiels Sascha Reedijk 12802e45e32SNiels Sascha Reedijk Note that in the previous code example, we set a 12902e45e32SNiels Sascha Reedijk \link BNotification::SetMessageID message identifier\endlink, which will 13002e45e32SNiels Sascha Reedijk allow to update the notification when we have progressed. The use would be: 13102e45e32SNiels Sascha Reedijk 13202e45e32SNiels Sascha Reedijk \code{.cpp} 13302e45e32SNiels Sascha Reedijk // After sending the notification, you retain ownership so that you can update it 13402e45e32SNiels Sascha Reedijk notification.SetProgress(0.7); 13502e45e32SNiels Sascha Reedijk 13602e45e32SNiels Sascha Reedijk // In order to display the update, you send it again 13702e45e32SNiels Sascha Reedijk notification.Send(); 13802e45e32SNiels Sascha Reedijk \endcode 13902e45e32SNiels Sascha Reedijk 14002e45e32SNiels Sascha Reedijk Furthermore, it is possible to support some form of follow-up action, when 14102e45e32SNiels Sascha Reedijk the user clicks the notification. First of all, you need to choose whether 14202e45e32SNiels Sascha Reedijk you want to \link BNotification::SetOnClickApp() open a specific 14302e45e32SNiels Sascha Reedijk application\endlink, or whether you want to 14402e45e32SNiels Sascha Reedijk \link BNotification::SetOnClickFile() open a specific file\endlink and have 14502e45e32SNiels Sascha Reedijk the system determine which application fits that. Additionally, you may 14602e45e32SNiels Sascha Reedijk specify \link BNotification::AddOnClickArg() command line arguments\endlink 14702e45e32SNiels Sascha Reedijk or pass additional \link BNotification::AddOnClickRef() file 14802e45e32SNiels Sascha Reedijk references\endlink for the receiving application to process. 14902e45e32SNiels Sascha Reedijk 15002e45e32SNiels Sascha Reedijk Finally, a note about the \c notification_server and how it groups and 15102e45e32SNiels Sascha Reedijk handles messages coming from your application. The system is aware of the 15202e45e32SNiels Sascha Reedijk source of the notifications, and identifies your application by it's 15302e45e32SNiels Sascha Reedijk signature. That means that the identification of your application is 15402e45e32SNiels Sascha Reedijk consistent, even if it is restarted, or if you have multiple instances 15502e45e32SNiels Sascha Reedijk running. This impacts the \link BNotification::SetGroup() grouping\endlink 15602e45e32SNiels Sascha Reedijk functionality and the \link BNotification::SetMessageID() message 15702e45e32SNiels Sascha Reedijk updating\endlink functionality. If you have an application that can have 15802e45e32SNiels Sascha Reedijk multiple instances, you will need to make sure that you properly manage 15902e45e32SNiels Sascha Reedijk your group names and identifiers if you want to keep things separate. 160a72f3582SNiels Sascha Reedijk 161a72f3582SNiels Sascha Reedijk \since Haiku R1 162a72f3582SNiels Sascha Reedijk*/ 163a72f3582SNiels Sascha Reedijk 164a72f3582SNiels Sascha Reedijk 165a72f3582SNiels Sascha Reedijk/*! 166a72f3582SNiels Sascha Reedijk \fn BNotification::BNotification(notification_type type) 16702e45e32SNiels Sascha Reedijk \brief Construct an empty message, with the specified \a type. 16802e45e32SNiels Sascha Reedijk 16902e45e32SNiels Sascha Reedijk The type influences the style of the notification view. See the 17002e45e32SNiels Sascha Reedijk \ref notification_type enumerator for details. 171a72f3582SNiels Sascha Reedijk 172a72f3582SNiels Sascha Reedijk \since Haiku R1 173a72f3582SNiels Sascha Reedijk*/ 174a72f3582SNiels Sascha Reedijk 175a72f3582SNiels Sascha Reedijk 176a72f3582SNiels Sascha Reedijk/*! 177a72f3582SNiels Sascha Reedijk \fn BNotification::BNotification(BMessage* archive) 17802e45e32SNiels Sascha Reedijk \brief Construct a notification from an archive. 179a72f3582SNiels Sascha Reedijk 180a72f3582SNiels Sascha Reedijk \since Haiku R1 181a72f3582SNiels Sascha Reedijk*/ 182a72f3582SNiels Sascha Reedijk 183a72f3582SNiels Sascha Reedijk 184a72f3582SNiels Sascha Reedijk/*! 185a72f3582SNiels Sascha Reedijk \fn virtual BNotification::~BNotification() 18602e45e32SNiels Sascha Reedijk \brief Frees all resources associated with the object. 187a72f3582SNiels Sascha Reedijk 188a72f3582SNiels Sascha Reedijk \since Haiku R1 189a72f3582SNiels Sascha Reedijk*/ 190a72f3582SNiels Sascha Reedijk 191a72f3582SNiels Sascha Reedijk 192a72f3582SNiels Sascha Reedijk/*! 193a72f3582SNiels Sascha Reedijk \fn status_t BNotification::InitCheck() const 19402e45e32SNiels Sascha Reedijk \brief Returns the status of the constructor. 195a72f3582SNiels Sascha Reedijk 196a72f3582SNiels Sascha Reedijk \since Haiku R1 197a72f3582SNiels Sascha Reedijk*/ 198a72f3582SNiels Sascha Reedijk 199a72f3582SNiels Sascha Reedijk 200a72f3582SNiels Sascha Reedijk/*! 201a72f3582SNiels Sascha Reedijk \fn static BArchivable* BNotification::Instantiate(BMessage* archive) 20202e45e32SNiels Sascha Reedijk \brief Returns a new BNotification object from \a archive. 20302e45e32SNiels Sascha Reedijk 20402e45e32SNiels Sascha Reedijk This class implements the archiving API, and as such, you can 20502e45e32SNiels Sascha Reedijk build a new BNotification object from a previously created 20602e45e32SNiels Sascha Reedijk BMessage archive. However, if the message doesn't contain an archived data 20702e45e32SNiels Sascha Reedijk for a BNotification object, this method returns \c NULL. 20802e45e32SNiels Sascha Reedijk 20902e45e32SNiels Sascha Reedijk \returns BNotification object from \a archive or \c NULL if it doesn't 21002e45e32SNiels Sascha Reedijk contain a valid BNotification object. 211a72f3582SNiels Sascha Reedijk 212a72f3582SNiels Sascha Reedijk \since Haiku R1 213a72f3582SNiels Sascha Reedijk*/ 214a72f3582SNiels Sascha Reedijk 215a72f3582SNiels Sascha Reedijk 216a72f3582SNiels Sascha Reedijk/*! 217a72f3582SNiels Sascha Reedijk \fn virtual status_t BNotification::Archive(BMessage* archive, 218a72f3582SNiels Sascha Reedijk bool deep = true) const 21902e45e32SNiels Sascha Reedijk \brief Archives the BNotification in the \c archive. 22002e45e32SNiels Sascha Reedijk 22102e45e32SNiels Sascha Reedijk \see BArchivable::Archive(), Instantiate() static function. 22202e45e32SNiels Sascha Reedijk \returns \c B_OK: if everything went fine, or other errors that describe why 22302e45e32SNiels Sascha Reedijk archiving has failed. 224a72f3582SNiels Sascha Reedijk 225a72f3582SNiels Sascha Reedijk \since Haiku R1 226a72f3582SNiels Sascha Reedijk*/ 227a72f3582SNiels Sascha Reedijk 228a72f3582SNiels Sascha Reedijk 229a72f3582SNiels Sascha Reedijk/*! 230a72f3582SNiels Sascha Reedijk \fn const char* BNotification::SourceSignature() const 23102e45e32SNiels Sascha Reedijk \brief Returns signature of the application where the notification 23202e45e32SNiels Sascha Reedijk originated. 23302e45e32SNiels Sascha Reedijk 23402e45e32SNiels Sascha Reedijk When you build your own notifications, this will contain the signature of 23502e45e32SNiels Sascha Reedijk the current application. If you receive notifications from other 23602e45e32SNiels Sascha Reedijk applications, it will include theirs. 23702e45e32SNiels Sascha Reedijk 23802e45e32SNiels Sascha Reedijk \returns Signature of the source application. 239a72f3582SNiels Sascha Reedijk 240a72f3582SNiels Sascha Reedijk \since Haiku R1 241a72f3582SNiels Sascha Reedijk*/ 242a72f3582SNiels Sascha Reedijk 243a72f3582SNiels Sascha Reedijk 244a72f3582SNiels Sascha Reedijk/*! 245a72f3582SNiels Sascha Reedijk \fn const char* BNotification::SourceName() const 24602e45e32SNiels Sascha Reedijk \brief Returns the name of the application where the notification 24702e45e32SNiels Sascha Reedijk originated. 24802e45e32SNiels Sascha Reedijk 24902e45e32SNiels Sascha Reedijk When you build your own notifications, this will contain the name of 25002e45e32SNiels Sascha Reedijk the current application. If you receive notifications from other 25102e45e32SNiels Sascha Reedijk applications, it will include theirs. 25202e45e32SNiels Sascha Reedijk 25302e45e32SNiels Sascha Reedijk \returns Name of the source application. 254a72f3582SNiels Sascha Reedijk 255a72f3582SNiels Sascha Reedijk \since Haiku R1 256a72f3582SNiels Sascha Reedijk*/ 257a72f3582SNiels Sascha Reedijk 258a72f3582SNiels Sascha Reedijk 259a72f3582SNiels Sascha Reedijk/*! 260a72f3582SNiels Sascha Reedijk \fn notification_type BNotification::Type() const 26102e45e32SNiels Sascha Reedijk \brief Returns the type of the notification. 26202e45e32SNiels Sascha Reedijk 26302e45e32SNiels Sascha Reedijk \returns A value of the \c notification_type enum that represents 26402e45e32SNiels Sascha Reedijk notification type. 265a72f3582SNiels Sascha Reedijk 266a72f3582SNiels Sascha Reedijk \since Haiku R1 267a72f3582SNiels Sascha Reedijk*/ 268a72f3582SNiels Sascha Reedijk 269a72f3582SNiels Sascha Reedijk 270a72f3582SNiels Sascha Reedijk/*! 271a72f3582SNiels Sascha Reedijk \fn const char* BNotification::Group() const 27202e45e32SNiels Sascha Reedijk \brief Returns the group of the notification. 27302e45e32SNiels Sascha Reedijk 27402e45e32SNiels Sascha Reedijk \see BNotification::SetGroup() for more information about groups. 27502e45e32SNiels Sascha Reedijk 27602e45e32SNiels Sascha Reedijk \returns The string of the notification's group. 277a72f3582SNiels Sascha Reedijk 278a72f3582SNiels Sascha Reedijk \since Haiku R1 279a72f3582SNiels Sascha Reedijk*/ 280a72f3582SNiels Sascha Reedijk 281a72f3582SNiels Sascha Reedijk 282a72f3582SNiels Sascha Reedijk/*! 283a72f3582SNiels Sascha Reedijk \fn void BNotification::SetGroup(const BString& group) 28402e45e32SNiels Sascha Reedijk \brief Set a group for the notifcation. 28502e45e32SNiels Sascha Reedijk 28602e45e32SNiels Sascha Reedijk The default behaviour of the \c notification_server is group the visible 28702e45e32SNiels Sascha Reedijk notifications per running application, and then in order in which they have 28802e45e32SNiels Sascha Reedijk been received. There may be situations where you want to override that 28902e45e32SNiels Sascha Reedijk behavior and group related notifications. When you set a group name, the 29002e45e32SNiels Sascha Reedijk \c notification_server will create a box with the \c group name as label, 29102e45e32SNiels Sascha Reedijk and insert all related notifications in that box. 29202e45e32SNiels Sascha Reedijk 29302e45e32SNiels Sascha Reedijk \image html notification_group.png 294a72f3582SNiels Sascha Reedijk 295a72f3582SNiels Sascha Reedijk \since Haiku R1 296a72f3582SNiels Sascha Reedijk*/ 297a72f3582SNiels Sascha Reedijk 298a72f3582SNiels Sascha Reedijk 299a72f3582SNiels Sascha Reedijk/*! 300a72f3582SNiels Sascha Reedijk \fn const char* BNotification::Title() const 30102e45e32SNiels Sascha Reedijk \brief Returns the title of the notification. 30202e45e32SNiels Sascha Reedijk 30302e45e32SNiels Sascha Reedijk \returns The title of the notification as a string. 304a72f3582SNiels Sascha Reedijk 305a72f3582SNiels Sascha Reedijk \since Haiku R1 306a72f3582SNiels Sascha Reedijk*/ 307a72f3582SNiels Sascha Reedijk 308a72f3582SNiels Sascha Reedijk 309a72f3582SNiels Sascha Reedijk/*! 310a72f3582SNiels Sascha Reedijk \fn void BNotification::SetTitle(const BString& title) 31102e45e32SNiels Sascha Reedijk \brief Set a title for the notification. 312a72f3582SNiels Sascha Reedijk 313a72f3582SNiels Sascha Reedijk \since Haiku R1 314a72f3582SNiels Sascha Reedijk*/ 315a72f3582SNiels Sascha Reedijk 316a72f3582SNiels Sascha Reedijk 317a72f3582SNiels Sascha Reedijk/*! 318a72f3582SNiels Sascha Reedijk \fn const char* BNotification::Content() const 31902e45e32SNiels Sascha Reedijk \brief Returns the message of the notification. 32002e45e32SNiels Sascha Reedijk 32102e45e32SNiels Sascha Reedijk \returns The message of the notification as a string. 322a72f3582SNiels Sascha Reedijk 323a72f3582SNiels Sascha Reedijk \since Haiku R1 324a72f3582SNiels Sascha Reedijk*/ 325a72f3582SNiels Sascha Reedijk 326a72f3582SNiels Sascha Reedijk 327a72f3582SNiels Sascha Reedijk/*! 328a72f3582SNiels Sascha Reedijk \fn void BNotification::SetContent(const BString& content) 32902e45e32SNiels Sascha Reedijk \brief Set a message for the notification. 330a72f3582SNiels Sascha Reedijk 331a72f3582SNiels Sascha Reedijk \since Haiku R1 332a72f3582SNiels Sascha Reedijk*/ 333a72f3582SNiels Sascha Reedijk 334a72f3582SNiels Sascha Reedijk 335a72f3582SNiels Sascha Reedijk/*! 336a72f3582SNiels Sascha Reedijk \fn const char* BNotification::MessageID() const 33702e45e32SNiels Sascha Reedijk \brief Returns the identifier of the notification. 33802e45e32SNiels Sascha Reedijk 33902e45e32SNiels Sascha Reedijk \see BNotification::SetMessageID() for the purpose of having an identifier. 34002e45e32SNiels Sascha Reedijk 34102e45e32SNiels Sascha Reedijk \returns The identifier of the notification as a string. 342a72f3582SNiels Sascha Reedijk 343a72f3582SNiels Sascha Reedijk \since Haiku R1 344a72f3582SNiels Sascha Reedijk*/ 345a72f3582SNiels Sascha Reedijk 346a72f3582SNiels Sascha Reedijk 347a72f3582SNiels Sascha Reedijk/*! 348a72f3582SNiels Sascha Reedijk \fn void BNotification::SetMessageID(const BString& id) 34902e45e32SNiels Sascha Reedijk \brief Sets notification's message identifier. 35002e45e32SNiels Sascha Reedijk 35102e45e32SNiels Sascha Reedijk If you want to update the contents of an existing notification, you can 35202e45e32SNiels Sascha Reedijk set a identifier for this message. When you send a new or updated message 35302e45e32SNiels Sascha Reedijk with the same identifier, the \c notification_server will update the 35402e45e32SNiels Sascha Reedijk existing message with the new content. 35502e45e32SNiels Sascha Reedijk 35602e45e32SNiels Sascha Reedijk In order to effectively use this feature, you will have to make sure the 35702e45e32SNiels Sascha Reedijk identifier is unique within the current application. 358a72f3582SNiels Sascha Reedijk 359a72f3582SNiels Sascha Reedijk \since Haiku R1 360a72f3582SNiels Sascha Reedijk*/ 361a72f3582SNiels Sascha Reedijk 362a72f3582SNiels Sascha Reedijk 363a72f3582SNiels Sascha Reedijk/*! 364a72f3582SNiels Sascha Reedijk \fn float BNotification::Progress() const 36502e45e32SNiels Sascha Reedijk \brief Returns the progress for the notification. 36602e45e32SNiels Sascha Reedijk 36702e45e32SNiels Sascha Reedijk \see BNotification::SetProgress() for more information about this value. 36802e45e32SNiels Sascha Reedijk 36902e45e32SNiels Sascha Reedijk \returns A value between 0.0 and 1.0 if notification's type is 37002e45e32SNiels Sascha Reedijk \c B_PROGRESS_NOTIFICATION, or otherwise -1. 371a72f3582SNiels Sascha Reedijk 372a72f3582SNiels Sascha Reedijk \since Haiku R1 373a72f3582SNiels Sascha Reedijk*/ 374a72f3582SNiels Sascha Reedijk 375a72f3582SNiels Sascha Reedijk 376a72f3582SNiels Sascha Reedijk/*! 377a72f3582SNiels Sascha Reedijk \fn void BNotification::SetProgress(float progress) 37802e45e32SNiels Sascha Reedijk \brief Sets progress information. 37902e45e32SNiels Sascha Reedijk 38002e45e32SNiels Sascha Reedijk When you are building a notification of the type \c B_PROGRESS_NOTIFICATION 38102e45e32SNiels Sascha Reedijk the notification view will show a progress bar and a label that 38202e45e32SNiels Sascha Reedijk expresses the progress in a percentage. Using this method you can set 38302e45e32SNiels Sascha Reedijk what the bar and label express. 38402e45e32SNiels Sascha Reedijk 38502e45e32SNiels Sascha Reedijk The valid range is between 0.0 and 1.0. If \c progress is lower than 0.0 38602e45e32SNiels Sascha Reedijk (i.e. negative), the value will be set to 0.0. If it is higher than 1.0, 38702e45e32SNiels Sascha Reedijk it will be set to 1.0. 388a72f3582SNiels Sascha Reedijk 389a72f3582SNiels Sascha Reedijk \since Haiku R1 390a72f3582SNiels Sascha Reedijk*/ 391a72f3582SNiels Sascha Reedijk 392a72f3582SNiels Sascha Reedijk 393a72f3582SNiels Sascha Reedijk/*! 394a72f3582SNiels Sascha Reedijk \fn const char* BNotification::OnClickApp() const 39502e45e32SNiels Sascha Reedijk \brief Returns the signature of the application that will be called when 39602e45e32SNiels Sascha Reedijk the notification is clicked. 39702e45e32SNiels Sascha Reedijk 39802e45e32SNiels Sascha Reedijk \see More information about this property in BNotification::SetOnClickApp(). 399a72f3582SNiels Sascha Reedijk 400a72f3582SNiels Sascha Reedijk \since Haiku R1 401a72f3582SNiels Sascha Reedijk*/ 402a72f3582SNiels Sascha Reedijk 403a72f3582SNiels Sascha Reedijk 404a72f3582SNiels Sascha Reedijk/*! 405a72f3582SNiels Sascha Reedijk \fn void BNotification::SetOnClickApp(const BString& app) 40602e45e32SNiels Sascha Reedijk \brief Set which application should be called when the notification is 40702e45e32SNiels Sascha Reedijk clicked by the user. 40802e45e32SNiels Sascha Reedijk 40902e45e32SNiels Sascha Reedijk The value \c app should be a valid application signature, for example 41002e45e32SNiels Sascha Reedijk \c 'application/x-vnd.Haiku-StyledEdit'. 41102e45e32SNiels Sascha Reedijk 41202e45e32SNiels Sascha Reedijk Using this property has precedence on when BNotification::SetOnClickFile() 41302e45e32SNiels Sascha Reedijk is used. If you want interacting with the notification opening a specific 41402e45e32SNiels Sascha Reedijk file, then you should use this method in combination with 41502e45e32SNiels Sascha Reedijk BNotification::AddOnClickRef(). 41602e45e32SNiels Sascha Reedijk 41702e45e32SNiels Sascha Reedijk \see Additional actions and parameters can be set through 41802e45e32SNiels Sascha Reedijk BNotification::SetOnClickFile(), BNotification::AddOnClickRef() 41902e45e32SNiels Sascha Reedijk and BNotification::AddOnClickArg(). 420a72f3582SNiels Sascha Reedijk 421a72f3582SNiels Sascha Reedijk \since Haiku R1 422a72f3582SNiels Sascha Reedijk*/ 423a72f3582SNiels Sascha Reedijk 424a72f3582SNiels Sascha Reedijk 425a72f3582SNiels Sascha Reedijk/*! 426a72f3582SNiels Sascha Reedijk \fn const entry_ref* BNotification::OnClickFile() const 42702e45e32SNiels Sascha Reedijk \brief Returns the reference to the file that will be opened when the 42802e45e32SNiels Sascha Reedijk notification is clicked. 42902e45e32SNiels Sascha Reedijk 43002e45e32SNiels Sascha Reedijk \see More information about this property in BNotification::SetOnClickFile(). 431a72f3582SNiels Sascha Reedijk 432a72f3582SNiels Sascha Reedijk \since Haiku R1 433a72f3582SNiels Sascha Reedijk*/ 434a72f3582SNiels Sascha Reedijk 435a72f3582SNiels Sascha Reedijk 436a72f3582SNiels Sascha Reedijk/*! 437a72f3582SNiels Sascha Reedijk \fn status_t BNotification::SetOnClickFile(const entry_ref* file) 43802e45e32SNiels Sascha Reedijk \brief Set which file should be opened when the notification is 43902e45e32SNiels Sascha Reedijk clicked by the user. 44002e45e32SNiels Sascha Reedijk 44102e45e32SNiels Sascha Reedijk The file will be opened by the default application for this file type. 44202e45e32SNiels Sascha Reedijk 44302e45e32SNiels Sascha Reedijk You cannot use this action in combination with 44402e45e32SNiels Sascha Reedijk BNotification::SetOnClickApp(). If you use this way of setting an action, 44502e45e32SNiels Sascha Reedijk this action will be ignored. 44602e45e32SNiels Sascha Reedijk 44702e45e32SNiels Sascha Reedijk \see Additional actions and parameters can be set through 44802e45e32SNiels Sascha Reedijk BNotification::SetOnClickApp(), BNotification::AddOnClickRef() 44902e45e32SNiels Sascha Reedijk and BNotification::AddOnClickArg(). 450a72f3582SNiels Sascha Reedijk 451a72f3582SNiels Sascha Reedijk \since Haiku R1 452a72f3582SNiels Sascha Reedijk*/ 453a72f3582SNiels Sascha Reedijk 454a72f3582SNiels Sascha Reedijk 455a72f3582SNiels Sascha Reedijk/*! 456a72f3582SNiels Sascha Reedijk \fn status_t BNotification::AddOnClickRef(const entry_ref* ref) 45702e45e32SNiels Sascha Reedijk \brief Add a \c ref to the list of arguments passed when a user clicks the 45802e45e32SNiels Sascha Reedijk notification. 45902e45e32SNiels Sascha Reedijk 46002e45e32SNiels Sascha Reedijk This method allows you to construct a list of refs, that will be sent to 46102e45e32SNiels Sascha Reedijk the application specified by BNotification::AddOnClickApp(), or the one 46202e45e32SNiels Sascha Reedijk that is associated with BNotification::AddOnClickFile(). The refs will be 46302e45e32SNiels Sascha Reedijk handled by the application's BApplication::RefsReceived() hook method. 464a72f3582SNiels Sascha Reedijk 465a72f3582SNiels Sascha Reedijk \since Haiku R1 466a72f3582SNiels Sascha Reedijk*/ 467a72f3582SNiels Sascha Reedijk 468a72f3582SNiels Sascha Reedijk 469a72f3582SNiels Sascha Reedijk/*! 470a72f3582SNiels Sascha Reedijk \fn int32 BNotification::CountOnClickRefs() const 47102e45e32SNiels Sascha Reedijk \brief Returns the number of refs to be passed when the user clicks on 47202e45e32SNiels Sascha Reedijk the notification. 47302e45e32SNiels Sascha Reedijk 47402e45e32SNiels Sascha Reedijk \see BNotification::AddOnClickRef() 475a72f3582SNiels Sascha Reedijk 476a72f3582SNiels Sascha Reedijk \since Haiku R1 477a72f3582SNiels Sascha Reedijk*/ 478a72f3582SNiels Sascha Reedijk 479a72f3582SNiels Sascha Reedijk 480a72f3582SNiels Sascha Reedijk/*! 481a72f3582SNiels Sascha Reedijk \fn const entry_ref* BNotification::OnClickRefAt(int32 index) const 48202e45e32SNiels Sascha Reedijk \brief Returns the ref that is stored at \c index. 48302e45e32SNiels Sascha Reedijk 48402e45e32SNiels Sascha Reedijk \see BNotification::AddOnClickRef() 485a72f3582SNiels Sascha Reedijk 486a72f3582SNiels Sascha Reedijk \since Haiku R1 487a72f3582SNiels Sascha Reedijk*/ 488a72f3582SNiels Sascha Reedijk 489a72f3582SNiels Sascha Reedijk 490a72f3582SNiels Sascha Reedijk/*! 491a72f3582SNiels Sascha Reedijk \fn status_t BNotification::AddOnClickArg(const BString& arg) 49202e45e32SNiels Sascha Reedijk \brief Add to a list of arguments that are passed to an application when 49302e45e32SNiels Sascha Reedijk the user clicks on the notification. 49402e45e32SNiels Sascha Reedijk 49502e45e32SNiels Sascha Reedijk This method allows you to construct a list of arguments, that will be sent 49602e45e32SNiels Sascha Reedijk to the application specified by BNotification::AddOnClickApp(), or the one 49702e45e32SNiels Sascha Reedijk that is associated with BNotification::AddOnClickFile(). The args will be 49802e45e32SNiels Sascha Reedijk handled by the application's BApplication::ArgvReceived() hook method. 499a72f3582SNiels Sascha Reedijk 500a72f3582SNiels Sascha Reedijk \since Haiku R1 501a72f3582SNiels Sascha Reedijk*/ 502a72f3582SNiels Sascha Reedijk 503a72f3582SNiels Sascha Reedijk 504a72f3582SNiels Sascha Reedijk/*! 505a72f3582SNiels Sascha Reedijk \fn int32 BNotification::CountOnClickArgs() const 50602e45e32SNiels Sascha Reedijk \brief Returns the number of args to be passed when the user clicks on 50702e45e32SNiels Sascha Reedijk the notification. 50802e45e32SNiels Sascha Reedijk 50902e45e32SNiels Sascha Reedijk \see BNotification::AddOnClickArg() 510a72f3582SNiels Sascha Reedijk 511a72f3582SNiels Sascha Reedijk \since Haiku R1 512a72f3582SNiels Sascha Reedijk*/ 513a72f3582SNiels Sascha Reedijk 514a72f3582SNiels Sascha Reedijk 515a72f3582SNiels Sascha Reedijk/*! 516a72f3582SNiels Sascha Reedijk \fn const char* BNotification::OnClickArgAt(int32 index) const 51702e45e32SNiels Sascha Reedijk \brief Returns the arg that is stored at \c index. 518a72f3582SNiels Sascha Reedijk 51902e45e32SNiels Sascha Reedijk \see BNotification::AddOnClickArg() 520a72f3582SNiels Sascha Reedijk \since Haiku R1 521a72f3582SNiels Sascha Reedijk*/ 522a72f3582SNiels Sascha Reedijk 523a72f3582SNiels Sascha Reedijk 524a72f3582SNiels Sascha Reedijk/*! 525a72f3582SNiels Sascha Reedijk \fn const BBitmap* BNotification::Icon() const 52602e45e32SNiels Sascha Reedijk \brief Returns the icon for the notification. 52702e45e32SNiels Sascha Reedijk 52802e45e32SNiels Sascha Reedijk \see BNotification::SetIcon() for more information on this property. 52902e45e32SNiels Sascha Reedijk 53002e45e32SNiels Sascha Reedijk \return Returns a borrowed unchangeable reference to the icon. 531a72f3582SNiels Sascha Reedijk 532a72f3582SNiels Sascha Reedijk \since Haiku R1 533a72f3582SNiels Sascha Reedijk*/ 534a72f3582SNiels Sascha Reedijk 535a72f3582SNiels Sascha Reedijk 536a72f3582SNiels Sascha Reedijk/*! 537a72f3582SNiels Sascha Reedijk \fn status_t BNotification::SetIcon(const BBitmap* icon) 53802e45e32SNiels Sascha Reedijk \brief Set the icon of the notification. 53902e45e32SNiels Sascha Reedijk 54002e45e32SNiels Sascha Reedijk Set the icon for the notification. By default, the application icon is 54102e45e32SNiels Sascha Reedijk used. This method makes a copy of the \a icon. 54202e45e32SNiels Sascha Reedijk 54302e45e32SNiels Sascha Reedijk \param icon The icon that should be displayed with the notification. 54402e45e32SNiels Sascha Reedijk \returns \c B_OK if everything went fine, \c B_NO_MEMORY when the \a icon 54502e45e32SNiels Sascha Reedijk could not be copied, or another error if something else went 54602e45e32SNiels Sascha Reedijk wrong. 547a72f3582SNiels Sascha Reedijk 548a72f3582SNiels Sascha Reedijk \since Haiku R1 549a72f3582SNiels Sascha Reedijk*/ 550a72f3582SNiels Sascha Reedijk 551a72f3582SNiels Sascha Reedijk 552a72f3582SNiels Sascha Reedijk/*! 553a72f3582SNiels Sascha Reedijk \fn status_t BNotification::Send(bigtime_t timeout = -1) 55402e45e32SNiels Sascha Reedijk \brief Send the notification to the notification_server. 55502e45e32SNiels Sascha Reedijk 55602e45e32SNiels Sascha Reedijk The notification is delivered asynchronously to the notification_server, 55702e45e32SNiels Sascha Reedijk which will display it according to its settings and filters. 55802e45e32SNiels Sascha Reedijk 55902e45e32SNiels Sascha Reedijk After sending, you retain ownership of the notification. The advantage is 56002e45e32SNiels Sascha Reedijk that you can re-use the notification at a later moment, or use the object to 56102e45e32SNiels Sascha Reedijk update the notification. See BNotification::SetMessageID() about updating 56202e45e32SNiels Sascha Reedijk displayed notifications. If you allocate the notification on the heap, be 56302e45e32SNiels Sascha Reedijk sure to free the memory. 56402e45e32SNiels Sascha Reedijk 56502e45e32SNiels Sascha Reedijk \param timeout The \a timeout in microsecond that the notification should 56602e45e32SNiels Sascha Reedijk be displayed. If you want to use the default timing, use the default 56702e45e32SNiels Sascha Reedijk argument or pass \c -1. 56802e45e32SNiels Sascha Reedijk \returns \c B_OK if everything went fine, \c B_BAD_PORT_ID if there was a 56902e45e32SNiels Sascha Reedijk problem connecting to the \c notification_server, or any other 57002e45e32SNiels Sascha Reedijk errors if something went wrong transmitting the notification. 571a72f3582SNiels Sascha Reedijk 572a72f3582SNiels Sascha Reedijk \since Haiku R1 573a72f3582SNiels Sascha Reedijk*/ 574