1a72f3582SNiels Sascha Reedijk/* 2*02e45e32SNiels 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 27*02e45e32SNiels 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 35*02e45e32SNiels Sascha Reedijk \brief Information type 36*02e45e32SNiels Sascha Reedijk 37*02e45e32SNiels Sascha Reedijk This will have the notification appear with a grey side bar. 38*02e45e32SNiels Sascha Reedijk 39*02e45e32SNiels 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 47*02e45e32SNiels Sascha Reedijk \brief Important type 48*02e45e32SNiels Sascha Reedijk 49*02e45e32SNiels Sascha Reedijk This will have the notification appear with a blue side bar. 50*02e45e32SNiels Sascha Reedijk 51*02e45e32SNiels 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 59*02e45e32SNiels Sascha Reedijk \brief Error type 60*02e45e32SNiels Sascha Reedijk 61*02e45e32SNiels Sascha Reedijk This will have the notification appear with a red side bar. 62*02e45e32SNiels Sascha Reedijk 63*02e45e32SNiels 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 71*02e45e32SNiels Sascha Reedijk \brief Progress type 72*02e45e32SNiels Sascha Reedijk 73*02e45e32SNiels Sascha Reedijk This will have the notification appear with a progress bar. 74*02e45e32SNiels Sascha Reedijk 75*02e45e32SNiels 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 86*02e45e32SNiels Sascha Reedijk \brief Construct system-default notifications to be displayed to the user. 87*02e45e32SNiels Sascha Reedijk 88*02e45e32SNiels Sascha Reedijk Haiku provides a notification system that allows you to display messages to 89*02e45e32SNiels Sascha Reedijk the user. There is quite some flexibility in how the message is presented. 90*02e45e32SNiels Sascha Reedijk You may use this class to build and send the notification. The properties 91*02e45e32SNiels Sascha Reedijk you can set are: 92*02e45e32SNiels Sascha Reedijk - The \link BNotification::BNotification() type of notification\endlink, 93*02e45e32SNiels Sascha Reedijk which can be an information message, a warning, an error, or a progress 94*02e45e32SNiels Sascha Reedijk message. 95*02e45e32SNiels Sascha Reedijk - The \link BNotification::SetGroup() group\endlink, which allows you to 96*02e45e32SNiels Sascha Reedijk organize notification display into different categories. 97*02e45e32SNiels Sascha Reedijk - A \link BNotification::SetTitle() title\endlink, which is a distinct 98*02e45e32SNiels Sascha Reedijk text element at the top of a notification view. 99*02e45e32SNiels Sascha Reedijk - The \link BNotification::SetContent() content\endlink, which is the text 100*02e45e32SNiels Sascha Reedijk message that is shown to the user. 101*02e45e32SNiels Sascha Reedijk - A \link BNotification::SetMessageID() message identifier\endlink that 102*02e45e32SNiels Sascha Reedijk allows you to modify the contents of a message that is being displayed, 103*02e45e32SNiels Sascha Reedijk which is particularly useful for progress notifications. 104*02e45e32SNiels Sascha Reedijk - For progress notifications, the 105*02e45e32SNiels Sascha Reedijk \link BNotification::SetProgress() percentage of completion\endlink can be 106*02e45e32SNiels Sascha Reedijk set. 107*02e45e32SNiels Sascha Reedijk - By default the notification uses the application's icon, but you may 108*02e45e32SNiels Sascha Reedijk set an \link BNotification::SetIcon() alternative icon\endlink. 109*02e45e32SNiels Sascha Reedijk - Finally there are a few ways you can configure the actions that happen 110*02e45e32SNiels Sascha Reedijk when a user clicks the notification. More on that below. 111*02e45e32SNiels Sascha Reedijk 112*02e45e32SNiels Sascha Reedijk For example, with the following code, you may display a notification: 113*02e45e32SNiels Sascha Reedijk 114*02e45e32SNiels Sascha Reedijk \code{.cpp} 115*02e45e32SNiels Sascha Reedijk BNotification notification(B_PROGRESS_NOTIFICATION); 116*02e45e32SNiels Sascha Reedijk notification.SetGroup("Group"); 117*02e45e32SNiels Sascha Reedijk notification.SetTitle("Title"); 118*02e45e32SNiels Sascha Reedijk notification.SetContent("This is the content"); 119*02e45e32SNiels Sascha Reedijk notification.SetMessageID("mainwindow_progress") 120*02e45e32SNiels Sascha Reedijk notification.SetProgress(0.5); 121*02e45e32SNiels Sascha Reedijk notification.Send(); 122*02e45e32SNiels Sascha Reedijk \endcode 123*02e45e32SNiels Sascha Reedijk 124*02e45e32SNiels Sascha Reedijk \p 125*02e45e32SNiels Sascha Reedijk 126*02e45e32SNiels Sascha Reedijk \image html notification_intro.png 127*02e45e32SNiels Sascha Reedijk 128*02e45e32SNiels Sascha Reedijk Note that in the previous code example, we set a 129*02e45e32SNiels Sascha Reedijk \link BNotification::SetMessageID message identifier\endlink, which will 130*02e45e32SNiels Sascha Reedijk allow to update the notification when we have progressed. The use would be: 131*02e45e32SNiels Sascha Reedijk 132*02e45e32SNiels Sascha Reedijk \code{.cpp} 133*02e45e32SNiels Sascha Reedijk // After sending the notification, you retain ownership so that you can update it 134*02e45e32SNiels Sascha Reedijk notification.SetProgress(0.7); 135*02e45e32SNiels Sascha Reedijk 136*02e45e32SNiels Sascha Reedijk // In order to display the update, you send it again 137*02e45e32SNiels Sascha Reedijk notification.Send(); 138*02e45e32SNiels Sascha Reedijk \endcode 139*02e45e32SNiels Sascha Reedijk 140*02e45e32SNiels Sascha Reedijk Furthermore, it is possible to support some form of follow-up action, when 141*02e45e32SNiels Sascha Reedijk the user clicks the notification. First of all, you need to choose whether 142*02e45e32SNiels Sascha Reedijk you want to \link BNotification::SetOnClickApp() open a specific 143*02e45e32SNiels Sascha Reedijk application\endlink, or whether you want to 144*02e45e32SNiels Sascha Reedijk \link BNotification::SetOnClickFile() open a specific file\endlink and have 145*02e45e32SNiels Sascha Reedijk the system determine which application fits that. Additionally, you may 146*02e45e32SNiels Sascha Reedijk specify \link BNotification::AddOnClickArg() command line arguments\endlink 147*02e45e32SNiels Sascha Reedijk or pass additional \link BNotification::AddOnClickRef() file 148*02e45e32SNiels Sascha Reedijk references\endlink for the receiving application to process. 149*02e45e32SNiels Sascha Reedijk 150*02e45e32SNiels Sascha Reedijk Finally, a note about the \c notification_server and how it groups and 151*02e45e32SNiels Sascha Reedijk handles messages coming from your application. The system is aware of the 152*02e45e32SNiels Sascha Reedijk source of the notifications, and identifies your application by it's 153*02e45e32SNiels Sascha Reedijk signature. That means that the identification of your application is 154*02e45e32SNiels Sascha Reedijk consistent, even if it is restarted, or if you have multiple instances 155*02e45e32SNiels Sascha Reedijk running. This impacts the \link BNotification::SetGroup() grouping\endlink 156*02e45e32SNiels Sascha Reedijk functionality and the \link BNotification::SetMessageID() message 157*02e45e32SNiels Sascha Reedijk updating\endlink functionality. If you have an application that can have 158*02e45e32SNiels Sascha Reedijk multiple instances, you will need to make sure that you properly manage 159*02e45e32SNiels 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) 167*02e45e32SNiels Sascha Reedijk \brief Construct an empty message, with the specified \a type. 168*02e45e32SNiels Sascha Reedijk 169*02e45e32SNiels Sascha Reedijk The type influences the style of the notification view. See the 170*02e45e32SNiels 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) 178*02e45e32SNiels 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() 186*02e45e32SNiels 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 194*02e45e32SNiels 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) 202*02e45e32SNiels Sascha Reedijk \brief Returns a new BNotification object from \a archive. 203*02e45e32SNiels Sascha Reedijk 204*02e45e32SNiels Sascha Reedijk This class implements the archiving API, and as such, you can 205*02e45e32SNiels Sascha Reedijk build a new BNotification object from a previously created 206*02e45e32SNiels Sascha Reedijk BMessage archive. However, if the message doesn't contain an archived data 207*02e45e32SNiels Sascha Reedijk for a BNotification object, this method returns \c NULL. 208*02e45e32SNiels Sascha Reedijk 209*02e45e32SNiels Sascha Reedijk \returns BNotification object from \a archive or \c NULL if it doesn't 210*02e45e32SNiels 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 219*02e45e32SNiels Sascha Reedijk \brief Archives the BNotification in the \c archive. 220*02e45e32SNiels Sascha Reedijk 221*02e45e32SNiels Sascha Reedijk \see BArchivable::Archive(), Instantiate() static function. 222*02e45e32SNiels Sascha Reedijk \returns \c B_OK: if everything went fine, or other errors that describe why 223*02e45e32SNiels 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 231*02e45e32SNiels Sascha Reedijk \brief Returns signature of the application where the notification 232*02e45e32SNiels Sascha Reedijk originated. 233*02e45e32SNiels Sascha Reedijk 234*02e45e32SNiels Sascha Reedijk When you build your own notifications, this will contain the signature of 235*02e45e32SNiels Sascha Reedijk the current application. If you receive notifications from other 236*02e45e32SNiels Sascha Reedijk applications, it will include theirs. 237*02e45e32SNiels Sascha Reedijk 238*02e45e32SNiels 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 246*02e45e32SNiels Sascha Reedijk \brief Returns the name of the application where the notification 247*02e45e32SNiels Sascha Reedijk originated. 248*02e45e32SNiels Sascha Reedijk 249*02e45e32SNiels Sascha Reedijk When you build your own notifications, this will contain the name of 250*02e45e32SNiels Sascha Reedijk the current application. If you receive notifications from other 251*02e45e32SNiels Sascha Reedijk applications, it will include theirs. 252*02e45e32SNiels Sascha Reedijk 253*02e45e32SNiels 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 261*02e45e32SNiels Sascha Reedijk \brief Returns the type of the notification. 262*02e45e32SNiels Sascha Reedijk 263*02e45e32SNiels Sascha Reedijk \returns A value of the \c notification_type enum that represents 264*02e45e32SNiels 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 272*02e45e32SNiels Sascha Reedijk \brief Returns the group of the notification. 273*02e45e32SNiels Sascha Reedijk 274*02e45e32SNiels Sascha Reedijk \see BNotification::SetGroup() for more information about groups. 275*02e45e32SNiels Sascha Reedijk 276*02e45e32SNiels 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) 284*02e45e32SNiels Sascha Reedijk \brief Set a group for the notifcation. 285*02e45e32SNiels Sascha Reedijk 286*02e45e32SNiels Sascha Reedijk The default behaviour of the \c notification_server is group the visible 287*02e45e32SNiels Sascha Reedijk notifications per running application, and then in order in which they have 288*02e45e32SNiels Sascha Reedijk been received. There may be situations where you want to override that 289*02e45e32SNiels Sascha Reedijk behavior and group related notifications. When you set a group name, the 290*02e45e32SNiels Sascha Reedijk \c notification_server will create a box with the \c group name as label, 291*02e45e32SNiels Sascha Reedijk and insert all related notifications in that box. 292*02e45e32SNiels Sascha Reedijk 293*02e45e32SNiels 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 301*02e45e32SNiels Sascha Reedijk \brief Returns the title of the notification. 302*02e45e32SNiels Sascha Reedijk 303*02e45e32SNiels 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) 311*02e45e32SNiels 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 319*02e45e32SNiels Sascha Reedijk \brief Returns the message of the notification. 320*02e45e32SNiels Sascha Reedijk 321*02e45e32SNiels 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) 329*02e45e32SNiels 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 337*02e45e32SNiels Sascha Reedijk \brief Returns the identifier of the notification. 338*02e45e32SNiels Sascha Reedijk 339*02e45e32SNiels Sascha Reedijk \see BNotification::SetMessageID() for the purpose of having an identifier. 340*02e45e32SNiels Sascha Reedijk 341*02e45e32SNiels 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) 349*02e45e32SNiels Sascha Reedijk \brief Sets notification's message identifier. 350*02e45e32SNiels Sascha Reedijk 351*02e45e32SNiels Sascha Reedijk If you want to update the contents of an existing notification, you can 352*02e45e32SNiels Sascha Reedijk set a identifier for this message. When you send a new or updated message 353*02e45e32SNiels Sascha Reedijk with the same identifier, the \c notification_server will update the 354*02e45e32SNiels Sascha Reedijk existing message with the new content. 355*02e45e32SNiels Sascha Reedijk 356*02e45e32SNiels Sascha Reedijk In order to effectively use this feature, you will have to make sure the 357*02e45e32SNiels 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 365*02e45e32SNiels Sascha Reedijk \brief Returns the progress for the notification. 366*02e45e32SNiels Sascha Reedijk 367*02e45e32SNiels Sascha Reedijk \see BNotification::SetProgress() for more information about this value. 368*02e45e32SNiels Sascha Reedijk 369*02e45e32SNiels Sascha Reedijk \returns A value between 0.0 and 1.0 if notification's type is 370*02e45e32SNiels 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) 378*02e45e32SNiels Sascha Reedijk \brief Sets progress information. 379*02e45e32SNiels Sascha Reedijk 380*02e45e32SNiels Sascha Reedijk When you are building a notification of the type \c B_PROGRESS_NOTIFICATION 381*02e45e32SNiels Sascha Reedijk the notification view will show a progress bar and a label that 382*02e45e32SNiels Sascha Reedijk expresses the progress in a percentage. Using this method you can set 383*02e45e32SNiels Sascha Reedijk what the bar and label express. 384*02e45e32SNiels Sascha Reedijk 385*02e45e32SNiels Sascha Reedijk The valid range is between 0.0 and 1.0. If \c progress is lower than 0.0 386*02e45e32SNiels Sascha Reedijk (i.e. negative), the value will be set to 0.0. If it is higher than 1.0, 387*02e45e32SNiels 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 395*02e45e32SNiels Sascha Reedijk \brief Returns the signature of the application that will be called when 396*02e45e32SNiels Sascha Reedijk the notification is clicked. 397*02e45e32SNiels Sascha Reedijk 398*02e45e32SNiels 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) 406*02e45e32SNiels Sascha Reedijk \brief Set which application should be called when the notification is 407*02e45e32SNiels Sascha Reedijk clicked by the user. 408*02e45e32SNiels Sascha Reedijk 409*02e45e32SNiels Sascha Reedijk The value \c app should be a valid application signature, for example 410*02e45e32SNiels Sascha Reedijk \c 'application/x-vnd.Haiku-StyledEdit'. 411*02e45e32SNiels Sascha Reedijk 412*02e45e32SNiels Sascha Reedijk Using this property has precedence on when BNotification::SetOnClickFile() 413*02e45e32SNiels Sascha Reedijk is used. If you want interacting with the notification opening a specific 414*02e45e32SNiels Sascha Reedijk file, then you should use this method in combination with 415*02e45e32SNiels Sascha Reedijk BNotification::AddOnClickRef(). 416*02e45e32SNiels Sascha Reedijk 417*02e45e32SNiels Sascha Reedijk \see Additional actions and parameters can be set through 418*02e45e32SNiels Sascha Reedijk BNotification::SetOnClickFile(), BNotification::AddOnClickRef() 419*02e45e32SNiels 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 427*02e45e32SNiels Sascha Reedijk \brief Returns the reference to the file that will be opened when the 428*02e45e32SNiels Sascha Reedijk notification is clicked. 429*02e45e32SNiels Sascha Reedijk 430*02e45e32SNiels 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) 438*02e45e32SNiels Sascha Reedijk \brief Set which file should be opened when the notification is 439*02e45e32SNiels Sascha Reedijk clicked by the user. 440*02e45e32SNiels Sascha Reedijk 441*02e45e32SNiels Sascha Reedijk The file will be opened by the default application for this file type. 442*02e45e32SNiels Sascha Reedijk 443*02e45e32SNiels Sascha Reedijk You cannot use this action in combination with 444*02e45e32SNiels Sascha Reedijk BNotification::SetOnClickApp(). If you use this way of setting an action, 445*02e45e32SNiels Sascha Reedijk this action will be ignored. 446*02e45e32SNiels Sascha Reedijk 447*02e45e32SNiels Sascha Reedijk \see Additional actions and parameters can be set through 448*02e45e32SNiels Sascha Reedijk BNotification::SetOnClickApp(), BNotification::AddOnClickRef() 449*02e45e32SNiels 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) 457*02e45e32SNiels Sascha Reedijk \brief Add a \c ref to the list of arguments passed when a user clicks the 458*02e45e32SNiels Sascha Reedijk notification. 459*02e45e32SNiels Sascha Reedijk 460*02e45e32SNiels Sascha Reedijk This method allows you to construct a list of refs, that will be sent to 461*02e45e32SNiels Sascha Reedijk the application specified by BNotification::AddOnClickApp(), or the one 462*02e45e32SNiels Sascha Reedijk that is associated with BNotification::AddOnClickFile(). The refs will be 463*02e45e32SNiels 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 471*02e45e32SNiels Sascha Reedijk \brief Returns the number of refs to be passed when the user clicks on 472*02e45e32SNiels Sascha Reedijk the notification. 473*02e45e32SNiels Sascha Reedijk 474*02e45e32SNiels 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 482*02e45e32SNiels Sascha Reedijk \brief Returns the ref that is stored at \c index. 483*02e45e32SNiels Sascha Reedijk 484*02e45e32SNiels 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) 492*02e45e32SNiels Sascha Reedijk \brief Add to a list of arguments that are passed to an application when 493*02e45e32SNiels Sascha Reedijk the user clicks on the notification. 494*02e45e32SNiels Sascha Reedijk 495*02e45e32SNiels Sascha Reedijk This method allows you to construct a list of arguments, that will be sent 496*02e45e32SNiels Sascha Reedijk to the application specified by BNotification::AddOnClickApp(), or the one 497*02e45e32SNiels Sascha Reedijk that is associated with BNotification::AddOnClickFile(). The args will be 498*02e45e32SNiels 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 506*02e45e32SNiels Sascha Reedijk \brief Returns the number of args to be passed when the user clicks on 507*02e45e32SNiels Sascha Reedijk the notification. 508*02e45e32SNiels Sascha Reedijk 509*02e45e32SNiels 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 517*02e45e32SNiels Sascha Reedijk \brief Returns the arg that is stored at \c index. 518a72f3582SNiels Sascha Reedijk 519*02e45e32SNiels 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 526*02e45e32SNiels Sascha Reedijk \brief Returns the icon for the notification. 527*02e45e32SNiels Sascha Reedijk 528*02e45e32SNiels Sascha Reedijk \see BNotification::SetIcon() for more information on this property. 529*02e45e32SNiels Sascha Reedijk 530*02e45e32SNiels 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) 538*02e45e32SNiels Sascha Reedijk \brief Set the icon of the notification. 539*02e45e32SNiels Sascha Reedijk 540*02e45e32SNiels Sascha Reedijk Set the icon for the notification. By default, the application icon is 541*02e45e32SNiels Sascha Reedijk used. This method makes a copy of the \a icon. 542*02e45e32SNiels Sascha Reedijk 543*02e45e32SNiels Sascha Reedijk \param icon The icon that should be displayed with the notification. 544*02e45e32SNiels Sascha Reedijk \returns \c B_OK if everything went fine, \c B_NO_MEMORY when the \a icon 545*02e45e32SNiels Sascha Reedijk could not be copied, or another error if something else went 546*02e45e32SNiels 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) 554*02e45e32SNiels Sascha Reedijk \brief Send the notification to the notification_server. 555*02e45e32SNiels Sascha Reedijk 556*02e45e32SNiels Sascha Reedijk The notification is delivered asynchronously to the notification_server, 557*02e45e32SNiels Sascha Reedijk which will display it according to its settings and filters. 558*02e45e32SNiels Sascha Reedijk 559*02e45e32SNiels Sascha Reedijk After sending, you retain ownership of the notification. The advantage is 560*02e45e32SNiels Sascha Reedijk that you can re-use the notification at a later moment, or use the object to 561*02e45e32SNiels Sascha Reedijk update the notification. See BNotification::SetMessageID() about updating 562*02e45e32SNiels Sascha Reedijk displayed notifications. If you allocate the notification on the heap, be 563*02e45e32SNiels Sascha Reedijk sure to free the memory. 564*02e45e32SNiels Sascha Reedijk 565*02e45e32SNiels Sascha Reedijk \param timeout The \a timeout in microsecond that the notification should 566*02e45e32SNiels Sascha Reedijk be displayed. If you want to use the default timing, use the default 567*02e45e32SNiels Sascha Reedijk argument or pass \c -1. 568*02e45e32SNiels Sascha Reedijk \returns \c B_OK if everything went fine, \c B_BAD_PORT_ID if there was a 569*02e45e32SNiels Sascha Reedijk problem connecting to the \c notification_server, or any other 570*02e45e32SNiels Sascha Reedijk errors if something went wrong transmitting the notification. 571a72f3582SNiels Sascha Reedijk 572a72f3582SNiels Sascha Reedijk \since Haiku R1 573a72f3582SNiels Sascha Reedijk*/ 574