message.cpp
1 //------------------------------------------------------------------------------
2 // message.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "message.h"
24 
25 QString StaticMessages::getMessage(unsigned messageType)
26 {
27  switch (messageType)
28  {
30  return tr("You have been banned from master server.");
31  default:
32  return QString("%1 IS NOT A VALID ERROR MESSAGE! FIX THIS!").arg(messageType);
33  }
34 }
35 
36 DClass<Message>
37 {
38  public:
39  QString content;
40  unsigned timestamp;
41  unsigned type;
42 };
43 
44 DPointered(Message)
45 
47 {
48  construct();
49  d->type = Type::IGNORE_TYPE;
50 }
51 
52 Message::Message(unsigned type)
53 {
54  construct();
55  d->type = type;
56 }
57 
58 Message::Message(unsigned type, const QString &content)
59 {
60  construct();
61  d->content = content;
62  d->type = type;
63 }
64 
65 Message::Message(const Message &other)
66 {
67  d = other.d;
68 }
69 
70 Message &Message::operator=(const Message &other)
71 {
72  d = other.d;
73  return *this;
74 }
75 
76 Message::~Message()
77 {
78 }
79 
80 void Message::construct()
81 {
82  qRegisterMetaType<Message>("Message");
83  d->type = Type::IGNORE_TYPE;
84  d->timestamp = QDateTime::currentDateTime().toTime_t();
85 }
86 
87 QString Message::contents() const
88 {
89  if (isCustom())
90  {
91  return d->content;
92  }
93  else
94  {
96  }
97 }
98 
99 bool Message::isCustom() const
100 {
102 }
103 
104 bool Message::isError() const
105 {
106  return type() >= Type::CUSTOM_ERROR;
107 }
108 
109 bool Message::isIgnore() const
110 {
111  return type() == Type::IGNORE_TYPE;
112 }
113 
115 {
116  return (type() >= Type::CUSTOM_INFORMATION) && (type() < Type::CUSTOM_ERROR);
117 }
118 
119 unsigned Message::timestamp() const
120 {
121  return d->timestamp;
122 }
123 
124 unsigned Message::type() const
125 {
126  return d->type;
127 }
128 
Message()
'Null' message object, returns true on isIgnore().
Message object used to pass messages throughout the Doomseeker's system.
Definition: message.h:62
bool isInformation() const
True if type() is equal to or greater than CUSTOM_INFORMATION, and lesser than CUSTOM_ERROR.
Definition: message.cpp:114
bool isError() const
True if type() is equal to or greater than CUSTOM_ERROR.
Definition: message.cpp:104
bool isIgnore() const
True for 'Null' messages.
Definition: message.cpp:109
unsigned timestamp() const
Generation time in seconds since UTC epoch.
Definition: message.cpp:119
static const unsigned IGNORE_TYPE
'Null' Message object; ignore it.
Definition: message.h:81
static const unsigned BANNED_FROM_MASTERSERVER
Information indicating that current player is banned from given server.
Definition: message.h:110
bool isCustom() const
True if type() equals to CUSTOM_INFORMATION or CUSTOM_ERROR.
Definition: message.cpp:99
static QString getMessage(unsigned messageType)
Gets static string for a Message::Type.
Definition: message.cpp:25
static const unsigned CUSTOM_ERROR
Programmer-defined error message.
Definition: message.h:105
static const unsigned CUSTOM_INFORMATION
Programmer-defined information message, not an error.
Definition: message.h:89
unsigned type() const
Message::Type.
Definition: message.cpp:124
QString contents() const
Customized displayable contents of this Message.
Definition: message.cpp:87