message.h
1 //------------------------------------------------------------------------------
2 // message.h
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 #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 <QString>
31 
32 class StaticMessages : public QObject
33 {
34  Q_OBJECT
35 
36  public:
43  static QString getMessage(unsigned messageType);
44 };
45 
62 class MAIN_EXPORT Message
63 {
64  public:
75  class Type
76  {
77  public:
81  static const unsigned IGNORE_TYPE = 0;
82 
89  static const unsigned CUSTOM_INFORMATION = 1;
93  static const unsigned CANCELLED = 2;
97  static const unsigned SUCCESSFUL = 3;
98 
105  static const unsigned CUSTOM_ERROR = 0x7fffffff;
110  static const unsigned BANNED_FROM_MASTERSERVER = CUSTOM_ERROR + 1;
116  static const unsigned GAME_NOT_FOUND_BUT_CAN_BE_INSTALLED = CUSTOM_ERROR + 2;
117  };
118 
122  static Message customError(const QString& content)
123  {
124  return Message(Type::CUSTOM_ERROR, content);
125  }
126 
130  static Message customInformation(const QString& content)
131  {
132  return Message(Type::CUSTOM_INFORMATION, content);
133  }
134 
138  Message();
145  Message(unsigned type);
152  Message(unsigned type, const QString &content);
153  Message(const Message &other);
154  Message &operator=(const Message &other);
155  virtual ~Message();
156 
160  QString contents() const;
161 
165  bool isCustom() const;
169  bool isError() const;
173  bool isIgnore() const;
178  bool isInformation() const;
179 
183  unsigned timestamp() const;
187  unsigned type() const;
188 
189  private:
190  DPtr<Message> d;
191 
192  void construct();
193 };
194 
195 Q_DECLARE_METATYPE(Message)
196 
197 #endif
Message object used to pass messages throughout the Doomseeker's system.
Definition: message.h:62
One of possible, Doomseeker recognizable error types.
Definition: message.h:75
static QString getMessage(unsigned messageType)
Gets static string for a Message::Type.
Definition: message.cpp:25
static Message customInformation(const QString &content)
Convenience method. Sets type to Type::CUSTOM_INFORMATION.
Definition: message.h:130
static Message customError(const QString &content)
Convenience method. Sets type to Type::CUSTOM_ERROR.
Definition: message.h:122