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 | |
---|
29 | /** |
---|
30 | @file Notification.cc |
---|
31 | @brief Implementation of the Notification class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "Notification.h" |
---|
35 | |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "util/Exception.h" |
---|
38 | |
---|
39 | #include "NotificationManager.h" |
---|
40 | |
---|
41 | namespace orxonox |
---|
42 | { |
---|
43 | |
---|
44 | /** |
---|
45 | @brief |
---|
46 | Default constructor. Initializes the object. |
---|
47 | */ |
---|
48 | Notification::Notification(BaseObject* creator) : BaseObject(creator) |
---|
49 | { |
---|
50 | this->initialize(); |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | @brief |
---|
55 | Constructor. Creates a Notification with the input message. |
---|
56 | @param message |
---|
57 | The message of the Notification. |
---|
58 | */ |
---|
59 | Notification::Notification(const std::string & message) : BaseObject(NULL) |
---|
60 | { |
---|
61 | this->message_ = message; |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
65 | @brief |
---|
66 | Destructor. |
---|
67 | */ |
---|
68 | Notification::~Notification() |
---|
69 | { |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | @brief |
---|
74 | Registers the object and sets some default values. |
---|
75 | */ |
---|
76 | void Notification::initialize(void) |
---|
77 | { |
---|
78 | RegisterObject(Notification); |
---|
79 | |
---|
80 | this->message_ = ""; |
---|
81 | this->sender_ = NotificationManager::NONE; |
---|
82 | this->sent_ = false; |
---|
83 | } |
---|
84 | |
---|
85 | /** |
---|
86 | @brief |
---|
87 | Sends the Notification to the Notificationmanager, with sender NetificationManager::NONE. |
---|
88 | @return |
---|
89 | Returns true if successful. |
---|
90 | */ |
---|
91 | bool Notification::send(void) |
---|
92 | { |
---|
93 | return this->send(NotificationManager::NONE); |
---|
94 | } |
---|
95 | |
---|
96 | /** |
---|
97 | @brief |
---|
98 | Sends the Notification to the Notificationmanager, which then in turn distributes it to the different NotificationQueues. |
---|
99 | @param sender |
---|
100 | The sender the Notification was sent by. Used by the NotificationManager to distributes the notification to the correct NotificationQueues. |
---|
101 | @return |
---|
102 | Returns true if successful. |
---|
103 | */ |
---|
104 | bool Notification::send(const std::string & sender) |
---|
105 | { |
---|
106 | this->sender_ = sender; |
---|
107 | bool successful = NotificationManager::getInstance().registerNotification(this); |
---|
108 | if(!successful) |
---|
109 | return false; |
---|
110 | this->sent_ = true; |
---|
111 | |
---|
112 | COUT(3) << "Notification \"" << this->getMessage() << "\" sent." << std::endl; |
---|
113 | |
---|
114 | return true; |
---|
115 | } |
---|
116 | |
---|
117 | /** |
---|
118 | @brief |
---|
119 | Sets the message of the notification. |
---|
120 | @param message |
---|
121 | The message to be set. |
---|
122 | @return |
---|
123 | Returns true if successful. |
---|
124 | */ |
---|
125 | bool Notification::setMessage(const std::string & message) |
---|
126 | { |
---|
127 | if(this->isSent()) //!< The message cannot be changed if the message has already been sent. |
---|
128 | return false; |
---|
129 | this->message_ = message; |
---|
130 | return true; |
---|
131 | } |
---|
132 | |
---|
133 | } |
---|