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 the 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 #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
85  d->timestamp = QDateTime::currentDateTime().toSecsSinceEpoch();
86 #else
87  d->timestamp = QDateTime::currentDateTime().toTime_t();
88 #endif
89 }
90 
91 QString Message::contents() const
92 {
93  if (isCustom())
94  {
95  return d->content;
96  }
97  else
98  {
100  }
101 }
102 
103 bool Message::isCustom() const
104 {
106 }
107 
108 bool Message::isError() const
109 {
110  return type() >= Type::CUSTOM_ERROR;
111 }
112 
113 bool Message::isIgnore() const
114 {
115  return type() == Type::IGNORE_TYPE;
116 }
117 
119 {
120  return (type() >= Type::CUSTOM_INFORMATION) && (type() < Type::CUSTOM_ERROR);
121 }
122 
123 unsigned Message::timestamp() const
124 {
125  return d->timestamp;
126 }
127 
128 unsigned Message::type() const
129 {
130  return d->type;
131 }