message.cpp
1 //------------------------------------------------------------------------------
2 // message.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; 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 }