Doomseeker
   
  • Doomseeker
  • Wadseeker
  • Download
  • Tracker
  • Git
  • Docs
  • Main Page
  • Classes
  • Files
  • File List
  • File Members

src/core/serverapi/message.h

00001 //------------------------------------------------------------------------------
00002 // message.h
00003 //------------------------------------------------------------------------------
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00018 // 02110-1301, USA.
00019 //
00020 //------------------------------------------------------------------------------
00021 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
00022 //------------------------------------------------------------------------------
00023 #ifndef __DS_MESSAGE_H_
00024 #define __DS_MESSAGE_H_
00025 
00026 #include "global.h"
00027 #include <QDateTime>
00028 #include <QMetaType>
00029 #include <QString>
00030 
00041 class MAIN_EXPORT Message : public QObject
00042 {
00043         Q_OBJECT
00044 
00045         public:
00046                 class Types
00047                 {
00048                         public:
00049                                 static const unsigned IGNORE_TYPE = 0;
00050 
00051                                 static const unsigned CUSTOM_INFORMATION = 1;
00052 
00053                                 static const unsigned CUSTOM_ERROR = 0x7fffffff;
00054                                 static const unsigned BANNED_FROM_MASTERSERVER = CUSTOM_ERROR + 1;
00055                 };
00056 
00061                 static Message      customError(const QString& content)
00062                 {
00063                         return Message(Types::CUSTOM_ERROR, content);
00064                 }
00065 
00070                 static Message      customInformation(const QString& content)
00071                 {
00072                         return Message(Types::CUSTOM_INFORMATION, content);
00073                 }
00074 
00075                 static QString      getStringBasingOnType(unsigned type);
00076 
00077                 static bool         isCustom(unsigned type)
00078                 {
00079                         return type == Types::CUSTOM_ERROR || type == Types::CUSTOM_INFORMATION;
00080                 }
00081 
00082                 static bool                     isError(unsigned type)
00083                 {
00084                         return type >= Types::CUSTOM_ERROR;
00085                 }
00086 
00087                 static bool                     isIgnore(unsigned type)
00088                 {
00089                         return type == Types::IGNORE_TYPE;
00090                 }
00091 
00092                 static bool                     isInformation(unsigned type)
00093                 {
00094                         return (type >= Types::CUSTOM_INFORMATION) && (type < Types::CUSTOM_ERROR);
00095                 }
00096 
00097                 Message()
00098                 {
00099                         construct();
00100                         this->_type = Types::IGNORE_TYPE;
00101                 }
00102 
00103                 ~Message() {}
00104 
00105                 Message(const Message& other)
00106                 {
00107                         copy(other);
00108                 }
00109 
00110                 Message(unsigned type)
00111                 {
00112                         construct();
00113                         this->_type = type;
00114                 }
00115 
00116                 Message(unsigned type, const QString& content)
00117                 {
00118                         construct();
00119                         this->content = content;
00120                         this->_type = type;
00121                 }
00122 
00123                 Message& operator=(const Message& other)
00124                 {
00125                         if (this != &other)
00126                         {
00127                                 copy(other);
00128                         }
00129 
00130                         return *this;
00131                 }
00132 
00133                 const QString&  contents() const
00134                 {
00135                         return content;
00136                 }
00137 
00138                 QString             getStringBasingOnType() const
00139                 {
00140                         return getStringBasingOnType(_type);
00141                 }
00142 
00143                 bool            isCustom() const
00144                 {
00145                         return isCustom(_type);
00146                 }
00147 
00148                 bool                    isError() const
00149                 {
00150                         return isError(_type);
00151                 }
00152 
00153                 bool                    isIgnore() const
00154                 {
00155                         return isIgnore(_type);
00156                 }
00157 
00158                 bool                    isInformation() const
00159                 {
00160                         return isInformation(_type);
00161                 }
00162 
00163                 unsigned        timestamp() const
00164                 {
00165                         return _timestamp;
00166                 }
00167 
00168                 unsigned        type() const
00169                 {
00170                         return _type;
00171                 }
00172 
00173         private:
00174                 QString                 content;
00175                 unsigned        _timestamp;
00176                 unsigned                _type;
00177 
00178                 void            copy(const Message& other)
00179                 {
00180                         this->content = other.content;
00181                         this->_timestamp = other._timestamp;
00182                         this->_type = other._type;
00183                 }
00184 
00185                 void            construct();
00186 };
00187 
00188 Q_DECLARE_METATYPE(Message)
00189 
00190 #endif
   
Doomseeker © 2009-2024 The Doomseeker Team