| [2280] | 1 | /* | 
|---|
|  | 2 | *   ORXONOX - the hottest 3D action shooter ever to exist | 
|---|
|  | 3 | *                    > www.orxonox.net < | 
|---|
|  | 4 | * | 
|---|
|  | 5 | * | 
|---|
|  | 6 | *   License notice: | 
|---|
|  | 7 | * | 
|---|
|  | 8 | *   This program is free software; you can redistribute it and/or | 
|---|
|  | 9 | *   modify it under the terms of the GNU General Public License | 
|---|
|  | 10 | *   as published by the Free Software Foundation; either version 2 | 
|---|
|  | 11 | *   of the License, or (at your option) any later version. | 
|---|
|  | 12 | * | 
|---|
|  | 13 | *   This program is distributed in the hope that it will be useful, | 
|---|
|  | 14 | *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 15 | *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See thes | 
|---|
|  | 16 | *   GNU General Public License for more details. | 
|---|
|  | 17 | * | 
|---|
|  | 18 | *   You should have received a copy of the GNU General Public License | 
|---|
|  | 19 | *   along with this program; if not, write to the Free Software | 
|---|
|  | 20 | *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
|---|
|  | 21 | * | 
|---|
|  | 22 | *   Author: | 
|---|
|  | 23 | *      Damian 'Mozork' Frick | 
|---|
|  | 24 | *   Co-authors: | 
|---|
|  | 25 | *      ... | 
|---|
|  | 26 | * | 
|---|
|  | 27 | */ | 
|---|
|  | 28 |  | 
|---|
| [2911] | 29 | /** | 
|---|
| [3196] | 30 | @file | 
|---|
| [2911] | 31 | @brief Implementation of the Notification class. | 
|---|
|  | 32 | */ | 
|---|
|  | 33 |  | 
|---|
| [2280] | 34 | #include "Notification.h" | 
|---|
|  | 35 |  | 
|---|
|  | 36 | #include "core/CoreIncludes.h" | 
|---|
|  | 37 | #include "NotificationManager.h" | 
|---|
|  | 38 |  | 
|---|
| [2435] | 39 | namespace orxonox | 
|---|
|  | 40 | { | 
|---|
| [2911] | 41 |  | 
|---|
|  | 42 | /** | 
|---|
|  | 43 | @brief | 
|---|
|  | 44 | Default constructor. Initializes the object. | 
|---|
|  | 45 | */ | 
|---|
| [2280] | 46 | Notification::Notification(BaseObject* creator) : BaseObject(creator) | 
|---|
|  | 47 | { | 
|---|
| [3196] | 48 | RegisterObject(Notification); | 
|---|
| [2911] | 49 | this->initialize(); | 
|---|
| [2280] | 50 | } | 
|---|
|  | 51 |  | 
|---|
| [2911] | 52 | /** | 
|---|
|  | 53 | @brief | 
|---|
|  | 54 | Constructor. Creates a Notification with the input message. | 
|---|
|  | 55 | @param message | 
|---|
|  | 56 | The message of the Notification. | 
|---|
|  | 57 | */ | 
|---|
| [2994] | 58 | Notification::Notification(const std::string & message) : BaseObject(NULL) | 
|---|
| [2280] | 59 | { | 
|---|
|  | 60 | this->message_ = message; | 
|---|
|  | 61 | } | 
|---|
|  | 62 |  | 
|---|
| [2911] | 63 | /** | 
|---|
|  | 64 | @brief | 
|---|
|  | 65 | Destructor. | 
|---|
|  | 66 | */ | 
|---|
| [2280] | 67 | Notification::~Notification() | 
|---|
|  | 68 | { | 
|---|
|  | 69 | } | 
|---|
|  | 70 |  | 
|---|
| [2911] | 71 | /** | 
|---|
|  | 72 | @brief | 
|---|
|  | 73 | Registers the object and sets some default values. | 
|---|
|  | 74 | */ | 
|---|
| [2280] | 75 | void Notification::initialize(void) | 
|---|
|  | 76 | { | 
|---|
|  | 77 | this->message_ = ""; | 
|---|
| [2911] | 78 | this->sender_ = NotificationManager::NONE; | 
|---|
| [2280] | 79 | this->sent_ = false; | 
|---|
|  | 80 | } | 
|---|
|  | 81 |  | 
|---|
| [2911] | 82 | /** | 
|---|
|  | 83 | @brief | 
|---|
|  | 84 | Sends the Notification to the Notificationmanager, with sender NetificationManager::NONE. | 
|---|
|  | 85 | @return | 
|---|
|  | 86 | Returns true if successful. | 
|---|
|  | 87 | */ | 
|---|
| [2280] | 88 | bool Notification::send(void) | 
|---|
|  | 89 | { | 
|---|
| [2911] | 90 | return this->send(NotificationManager::NONE); | 
|---|
| [2280] | 91 | } | 
|---|
|  | 92 |  | 
|---|
| [2911] | 93 | /** | 
|---|
|  | 94 | @brief | 
|---|
|  | 95 | Sends the Notification to the Notificationmanager, which then in turn distributes it to the different NotificationQueues. | 
|---|
|  | 96 | @param sender | 
|---|
|  | 97 | The sender the Notification was sent by. Used by the NotificationManager to distributes the notification to the correct NotificationQueues. | 
|---|
|  | 98 | @return | 
|---|
|  | 99 | Returns true if successful. | 
|---|
|  | 100 | */ | 
|---|
|  | 101 | bool Notification::send(const std::string & sender) | 
|---|
| [2280] | 102 | { | 
|---|
| [2911] | 103 | this->sender_ = sender; | 
|---|
|  | 104 | bool successful = NotificationManager::getInstance().registerNotification(this); | 
|---|
|  | 105 | if(!successful) | 
|---|
| [2280] | 106 | return false; | 
|---|
| [2911] | 107 | this->sent_ = true; | 
|---|
|  | 108 |  | 
|---|
|  | 109 | COUT(3) << "Notification \"" << this->getMessage() << "\" sent." << std::endl; | 
|---|
|  | 110 |  | 
|---|
| [2435] | 111 | return true; | 
|---|
| [2280] | 112 | } | 
|---|
|  | 113 |  | 
|---|
| [2911] | 114 | /** | 
|---|
|  | 115 | @brief | 
|---|
|  | 116 | Sets the message of the notification. | 
|---|
|  | 117 | @param message | 
|---|
|  | 118 | The message to be set. | 
|---|
|  | 119 | @return | 
|---|
|  | 120 | Returns true if successful. | 
|---|
|  | 121 | */ | 
|---|
| [2280] | 122 | bool Notification::setMessage(const std::string & message) | 
|---|
|  | 123 | { | 
|---|
| [2911] | 124 | if(this->isSent()) //!< The message cannot be changed if the message has already been sent. | 
|---|
| [2280] | 125 | return false; | 
|---|
| [2435] | 126 | this->message_ = message; | 
|---|
|  | 127 | return true; | 
|---|
| [2280] | 128 | } | 
|---|
| [2911] | 129 |  | 
|---|
| [2280] | 130 | } | 
|---|