message.h
1 //------------------------------------------------------------------------------
2 // message.h
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 #ifndef __DS_MESSAGE_H_
24 #define __DS_MESSAGE_H_
25 
26 #include "dptr.h"
27 #include "global.h"
28 #include <QDateTime>
29 #include <QMetaType>
30 #include <QObject>
31 #include <QString>
32 
33 class StaticMessages : public QObject
34 {
35  Q_OBJECT
36 
37 public:
44  static QString getMessage(unsigned messageType);
45 };
46 
63 class MAIN_EXPORT Message
64 {
65 public:
76  class Type
77  {
78  public:
82  static const unsigned IGNORE_TYPE = 0;
83 
90  static const unsigned CUSTOM_INFORMATION = 1;
94  static const unsigned CANCELLED = 2;
98  static const unsigned SUCCESSFUL = 3;
99 
106  static const unsigned CUSTOM_ERROR = 0x7fffffff;
111  static const unsigned BANNED_FROM_MASTERSERVER = CUSTOM_ERROR + 1;
117  static const unsigned GAME_NOT_FOUND_BUT_CAN_BE_INSTALLED = CUSTOM_ERROR + 2;
118  };
119 
123  static Message customError(const QString &content)
124  {
125  return Message(Type::CUSTOM_ERROR, content);
126  }
127 
131  static Message customInformation(const QString &content)
132  {
133  return Message(Type::CUSTOM_INFORMATION, content);
134  }
135 
139  Message();
146  Message(unsigned type);
153  Message(unsigned type, const QString &content);
154  Message(const Message &other);
155  Message &operator=(const Message &other);
156  virtual ~Message();
157 
161  QString contents() const;
162 
166  bool isCustom() const;
170  bool isError() const;
174  bool isIgnore() const;
179  bool isInformation() const;
180 
184  unsigned timestamp() const;
188  unsigned type() const;
189 
190 private:
191  DPtr<Message> d;
192 
193  void construct();
194 };
195 
196 Q_DECLARE_METATYPE(Message)
197 
198 #endif