1 /* 2 Kopete Oscar Protocol 3 oscarmessage.h - Oscar Message Object 4 5 Copyright (c) 2005 Matt Rogers <mattr@kde.org> 6 Copyright (c) 2005 Conrad Hoffmann <conrausch@gmx.de> 7 Copyright (c) 2005 Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net> 8 Copyright (c) 2006-2007 Roman Jarosz <kedgedev@centrum.cz> 9 10 Kopete (c) 2002-2007 by the Kopete developers <kopete-devel@kde.org> 11 12 ************************************************************************* 13 * * 14 * This library is free software; you can redistribute it and/or * 15 * modify it under the terms of the GNU Lesser General Public * 16 * License as published by the Free Software Foundation; either * 17 * version 2 of the License, or (at your option) any later version. * 18 * * 19 ************************************************************************* 20 */ 21 22 #ifndef _OSCARMESSAGE_H_ 23 #define _OSCARMESSAGE_H_ 24 25 #include <QDateTime> 26 #include <QSharedDataPointer> 27 28 #include "liboscar_export.h" 29 #include "oscartypes.h" 30 31 class QTextCodec; 32 33 namespace Oscar 34 { 35 36 class MessagePlugin; 37 38 /** 39 * This class is responsible for holding all the details 40 * of a message and includes the following: 41 * \li channel ( type ) 42 * \li encoding 43 */ 44 45 namespace MessageType 46 { 47 enum { 48 Unknown = 0x00, // Unknown 49 Plain = 0x01, // Plain text (simple) message 50 Chat = 0x02, // Chat request message 51 File = 0x03, // File request / file ok message 52 Url = 0x04, // URL message (0xFE formatted) 53 AuthRequest = 0x06, // Authorization request message (0xFE formatted) 54 AuthDeny = 0x07, // Authorization denied message (0xFE formatted) 55 AuthGranted = 0x08, // Authorization given message (empty) 56 Server = 0x09, // Message from OSCAR server (0xFE formatted) 57 Added = 0x0C, // "You-were-added" message (0xFE formatted) 58 WebPager = 0x0D, // Web pager message (0xFE formatted) 59 EmailExpress = 0x0E, // Email express message (0xFE formatted) 60 ContactList = 0x13, // Contact list message 61 Plugin = 0x1A, // Plugin message described by text string 62 AutoAway = 0xE8, // Auto away message 63 AutoBusy = 0xE9, // Auto occupied message 64 AutoNA = 0xEA, // Auto not available message 65 AutoDND = 0xEB, // Auto do not disturb message 66 AutoFFC = 0xEC // Auto free for chat message 67 }; 68 } 69 70 class LIBOSCAR_EXPORT Message 71 { 72 public: 73 74 enum { 75 Normal = 0x0000, 76 AutoResponse = 0x0001, 77 WWP = 0x0002, 78 EMail = 0x0004, 79 ChatRoom = 0x0008, 80 Request = 0x0100, 81 StatusMessageRequest = 0x0200 82 }; 83 84 enum Encoding { 85 UserDefined, 86 ASCII, 87 LATIN1, 88 UTF8, 89 UCS2 90 }; 91 92 Message(); 93 94 // Message( Encoding messageEncoding, const QByteArray& messageText, int channel, int properties, QDateTime timestamp ); 95 // Message( Encoding messageEncoding, const QString& messageText, int channel, int properties, QDateTime timestamp, QTextCodec* codec = 0 ); 96 97 Message( const Message& m ); 98 Message& operator=( const Message& m ); 99 ~Message(); 100 101 /** Get the sender of the message */ 102 QString sender() const; 103 104 /** Set the sender of the message */ 105 void setSender( const QString& sender ); 106 107 /** Get the receiver of the message */ 108 QString receiver() const; 109 110 /** Set the receiver of the message */ 111 void setReceiver( const QString& receiver); 112 113 /** get the message text */ 114 QString text( QTextCodec* codec ) const; 115 116 /** get best encoding for text */ 117 static Message::Encoding encodingForText( const QString& newText, bool allowUCS2 = false ); 118 119 /** set the message text */ 120 void setText( Encoding newEncoding, const QString& newText, QTextCodec* codec = 0); 121 122 /** get the message text as a bytearray for decoding */ 123 QByteArray textArray() const; 124 125 /** set the message text as a bytearray for decoding */ 126 void setTextArray( const QByteArray& newTextArray ); 127 128 /** get the message properties */ 129 int properties() const; 130 131 /** ask about a specific property */ 132 bool hasProperty( int prop ) const; 133 134 /** add a property to the message */ 135 void addProperty( int prop ); 136 137 /** get the channel ( NOT type ) of the message */ 138 int channel() const; 139 140 /** set the channel ( NOT type ) of the message */ 141 void setChannel( int newChannel ); 142 143 /** get the timestamp of the message */ 144 QDateTime timestamp() const; 145 146 /** set the timestamp of the message */ 147 void setTimestamp( QDateTime ts ); 148 149 /** get the ICBM cookie of the message */ 150 QByteArray icbmCookie() const; 151 152 /** set the ICBM cookie of the message */ 153 void setIcbmCookie( const QByteArray& cookie ); 154 155 /** get the protocol version (channel 2 messages only) */ 156 int protocolVersion() const; 157 158 /** prepare for handling of different protocol versions */ 159 void setProtocolVersion( int version ); 160 161 /** get the channel 2 counter value of the message */ 162 int channel2Counter() const; // channel 2 message have an additional counter whose value needs be kept in a request response 163 164 /** set the channel 2 counter value */ 165 void setChannel2Counter( int value ); 166 167 /** get the message (content) type */ 168 int messageType() const; 169 170 /** set the message (content) type */ 171 void setMessageType( int type ); 172 173 /** get the request type (req/cancel/accept) */ 174 int requestType() const; 175 176 /** set the request type (req/cancel/accept) */ 177 void setRequestType( int type ); 178 179 /** get the port */ 180 int port() const; 181 182 /** set the port (for transfer requests) */ 183 void setPort( int port ); 184 185 /** get the proxy ip*/ 186 QByteArray proxy() const; 187 188 /** set the proxy ip (for transfer requests) */ 189 void setProxy( QByteArray proxy ); 190 191 /** get the request # */ 192 int requestNumber() const; 193 194 /** set the request # (for transfer requests) */ 195 void setRequestNumber( int n ); 196 197 /** get the file name */ 198 QString fileName() const; 199 200 /** get file(s) size */ 201 DWORD filesSize() const; 202 203 /** get file count */ 204 WORD fileCount() const; 205 206 /** set the file name (for transfer requests) */ 207 void setFileName( const QString &name ); 208 209 /** set file(s) size (for transfer requests)*/ 210 void setFilesSize( DWORD size ); 211 212 /** set file count (for transfer requests)*/ 213 void setFileCount( WORD count ); 214 215 /** get the exchange for the chat room this message is for */ 216 Oscar::WORD exchange() const; 217 218 /** set the exchange for the chat room this message is for */ 219 void setExchange( Oscar::WORD ); 220 221 /** get the chat room that this message is for */ 222 QString chatRoom() const; 223 224 /** set the chat room that this message is for */ 225 void setChatRoom( const QString& ); 226 227 /** get the message encoding */ 228 Encoding encoding() const; 229 230 /** set the message encoding */ 231 void setEncoding( Encoding newEncoding ); 232 233 /** get the message plugin */ 234 MessagePlugin* plugin() const; 235 236 /** set the message plugin 237 * The message deletes old plugin when a new plugin is set. 238 */ 239 void setPlugin( MessagePlugin* plugin ); 240 241 /** Get the id of the message */ 242 uint id() const; 243 244 /** Set the id of the message */ 245 void setId( uint id ); 246 247 operator bool() const; 248 249 private: 250 class MessagePrivate; 251 QSharedDataPointer<MessagePrivate> d; 252 253 }; 254 255 } 256 257 #endif 258