make webinterface translatable. there are around 20 short strings, all with context...
[kdenetwork.git] / kopete / libkopete / kopetemessage.h
blob46e6b3ed490c0d8acf3d0f6001c2d218f5dca79b
1 /*
2 kopetemessage.h - Base class for Kopete messages
4 Copyright (c) 2002-2003 by Martijn Klingens <klingens@kde.org>
5 Copyright (c) 2002-2004 by Olivier Goffart <ogoffart@kde.org>
6 Copyright (c) 2006-2007 by Charles Connell <charles@connells.org>
7 Copyright (c) 2007 by Michaël Larouche <larouche@kde.org>
9 Kopete (c) 2002-2007 by the Kopete developers <kopete-devel@kde.org>
11 *************************************************************************
12 * *
13 * This library is free software; you can redistribute it and/or *
14 * modify it under the terms of the GNU Lesser General Public *
15 * License as published by the Free Software Foundation; either *
16 * version 2 of the License, or (at your option) any later version. *
17 * *
18 *************************************************************************
21 #ifndef __KOPETE_MESSAGE_H__
22 #define __KOPETE_MESSAGE_H__
24 #include <QtCore/QSharedData>
25 #include <QtCore/QList>
26 #include <QtCore/Qt>
28 #include "kopete_export.h"
30 class QByteArray;
31 class QColor;
32 class QDateTime;
33 class QFont;
34 class QTextCodec;
35 class QTextDocument;
36 class QStringList;
38 namespace Kopete {
41 class ChatSession;
42 class Contact;
45 /**
46 * @brief Representation of a message in Kopete
48 * @author Martijn Klingens <klingens@kde.org>
49 * @author Olivier Goffart <ogoffart@kde.org>
50 * @author Charles Connell <charles@connells.org>
51 * @author Michaël Larouche <larouche@kde.org>
53 * Message represents any kind of messages shown on a chat view.
54 * The message may contain a simple plain text string, or a rich text HTML
55 * message. Also, Message can use a QTextDocument to structure the message.
57 * Message in plain text can however have a color or a specific font. You can
58 * set color with setForegroundColor() and setBackgroundColor() and change the font
59 * with setFont()
61 * Message have a direction from where the message come from. By default, the direction
62 * is Internal but it is strongly advised to set the direction explicitly.
64 * @section plainMessage Creating a plain text message
65 * @code
66 Kopete::Message newMessage(sourceContact, destionationContact);
67 newMessage.setPlainBody( QString("A plain text message") );
68 newMessage.setDirection( Kopete::Message::Inbound );
69 * @endcode
71 * @section richTextMessage Creating a complete rich text message
72 * @code
73 Kopete::Message richTextMessage(sourceContact, destinationContactList);
74 richTextMessage.setTimestamp( QDateTime::currentDateTime() );
75 richTextMessage.setDirection( Kopete::Message::Outbound );
76 richTextMessage.setSubjet( QString("Kopete API documentation thread") );
77 richTextMessage.setHtmlBody( QString("<b>A bold text</b>") );
78 * @endcode
80 class KOPETE_EXPORT Message
82 public:
83 /**
84 * Direction of a message.
86 enum MessageDirection
88 Inbound = 0, ///< Message is from the chat partner
89 Outbound = 1, ///< Message sent by the user
90 Internal= 2 ///< (Default) Message which are not sent via the network. This is just a notification a plugin can show in a chat view
93 /**
94 * Specifies the type of the message.
96 enum MessageType
98 TypeNormal, ///< A typical message
99 TypeAction ///< An IRC-style action.
103 * Specifies the type of notification that will be sent with this message
105 enum MessageImportance
107 Low = 0, ///< almost no notifications. automatically used in groupChat
108 Normal = 1, ///< Default notification, for normal message
109 Highlight = 2 ///< Highlight notification, for most important messages, which require particular attentions.
113 * Constructs a new empty message
115 explicit Message();
118 * Deref and clean private object if refcount == 0
120 ~Message();
123 * @brief Constructs a new message with a from and to contact
125 * This constructor is a convience of the constructor who
126 * take a list of contacts for destination
127 * @param fromKC Contact who send the message
128 * @param toKC Contact which the message is destined.
130 explicit Message( const Contact *fromKC, const Contact *toKC );
132 * @brief Constructs a new message with many contacts as the destination.
133 * @param fromKC Contact who send the message
134 * @param contacts List of Contact to send the message
136 explicit Message( const Contact *fromKC, const QList<Contact*> &contacts);
139 * Copy constructor.
140 * Just adds a reference, doesn't actually copy.
142 Message( const Message &other );
145 * Assignment operator
146 * Just like the copy constructor it just refs and doesn't copy.
148 Message & operator=( const Message &other );
151 * @brief Accessor method for the timestamp of the message
152 * @return The message's timestamp
154 QDateTime timestamp() const;
157 * @brief Set the message timestamp
158 * @param timestamp timestamp as QDateTime. By default the current date and time.
160 void setTimestamp(const QDateTime &timestamp);
163 * @brief Accessor method for the Contact that sent this message
164 * @return The Contact who sent this message
166 const Contact * from() const;
169 * @brief Accessor method for the Contacts that this message was sent to
170 * @return Pointer list of the Contacts this message was sent to
172 QList<Contact*> to() const;
175 * @brief Accessor method for the message type
176 * @return The type of the message
177 * @see MessageType
179 MessageType type() const;
182 * @brief Set message type
183 * @param type The type of the message
184 * @see MessageType
186 void setType(MessageType type);
189 * @brief Accessor method for the preferred plugin
190 * If null, Kopete will use the user's preferred plugin.
191 * @return The preferred plugin
193 QString requestedPlugin() const;
196 * @brief Set a view plugin which will display the message
198 * This is used mostly by Jabber plugin to select between
199 * the email window or the chat window depending of the
200 * type of message.
201 * @param requesedPlugin View plugin name
203 void setRequestedPlugin(const QString &requestedPlugin);
206 * @brief Accessor method for the foreground color
207 * @return The message's foreground color
209 QColor foregroundColor() const;
212 * @brief Accessor method for the background color of the message
213 * @return The message's background color
215 QColor backgroundColor() const;
218 * @brief Accesssor method for the direction of the text based on what language it is in
219 * @return The message text's direction
221 bool isRightToLeft() const;
224 * @brief Accessor method for the font of the message
225 * @return The message's font
227 QFont font() const;
230 * @brief Accessor method for the subject of the message
231 * @return The message subject
233 QString subject() const;
236 * @brief Set message subject
237 * @param subject Message's subject
239 void setSubject(const QString &subject);
242 * @brief Accessor method for the body of the message
243 * This is used internaly, to modify it make a copy of it with QTextDocument::clone()
244 * @return The message body
246 const QTextDocument *body() const;
249 * @brief Accessor method for the format of the message
250 * @return The message format
252 Qt::TextFormat format() const;
255 * @brief Accessor method for the direction of the message
256 * @return The message direction
258 MessageDirection direction() const;
261 * @brief Set the message direction
262 * @param direction The message direction
263 * @see MessageDirection
265 void setDirection(MessageDirection direction);
268 * @brief Accessor method for the importance
269 * @see setImportance
270 * @return The message importance (low/normal/highlight)
272 MessageImportance importance() const;
275 * @brief Set the importance.
276 * @see importance and @see MessageImportance
277 * @param importance The message importance to set
279 void setImportance(MessageImportance importance);
282 * @brief Sets the foreground color for the message
283 * @see foregroundColor
284 * @param color The color
286 void setForegroundColor( const QColor &color );
289 * @brief Sets the background color for the message
290 * @see backgroundColor
291 * @param color The color
293 void setBackgroundColor( const QColor &color );
296 * @brief Sets the font for the message
297 * @see font
298 * @param font The font
300 void setFont( const QFont &font );
303 * @brief Sets the body of the message
305 * @param body The body, intpreted as plain text
307 void setPlainBody( const QString &body);
310 * @brief Sets the body of the message
312 * @param body The body, interpreted as HTML
314 void setHtmlBody( const QString &body);
317 * @brief Sets the body of the message
318 * The format is changed to RichText automatically
319 * @param body The body
321 void setBody( const QTextDocument *body);
324 * @brief Get the message body back as plain text
325 * @return The message body as plain text
327 QString plainBody() const;
330 * @brief Get the message body as escaped (X)HTML format.
331 * That means every HTML special char (\>, \<, \&, ...) is escaped to the HTML entity (\&lt;, \&gt;, ...)
332 * and newlines (\\n) are converted to \<br /\>
333 * Just because you set an HTML body doesn't mean you'll get the same string back here, but it will
334 * be equivalent in meaning
335 * @return The message body as escaped text
337 QString escapedBody() const;
340 * @brief Get the message body as parsed HTML with Emoticons, and URL parsed
341 * This should be ready to be shown in the chatwindow.
342 * @return The HTML and Emoticon parsed message body
344 QString parsedBody() const;
347 * Get the related message manager.
348 * If it is not set, returns 0L.
350 * The @ref ChatSession is only set if the message is already passed by the manager.
351 * We should trust this only in aboutToSend/aboutToReceive signals
353 ChatSession *manager() const ;
356 * @brief Set the messagemanager for this message.
357 * Should be only used by the manager itself. @see manager
358 * @param manager The chat session
360 void setManager(ChatSession * manager);
363 * @brief Enables the use of a background for a message
364 * @param enable A flag to indicate if the background should be enabled or disabled.
366 void setBackgroundOverride( bool enable );
369 * @brief Enables the use of a foreground for a message
370 * @param enable A flag to indicate if the foreground should be enabled or disabled.
372 void setForegroundOverride( bool enable );
375 * @brief Enables the use of a RTF formatting for a message
376 * @param enable A flag to indicate if the RTF formatting should be enabled or disabled.
378 void setRichTextOverride( bool enable );
381 * @brief Return HTML style attribute for this message.
382 * @return A string formatted like this: "style=attr"
384 QString getHtmlStyleAttribute() const;
387 * @return The list of classes
388 * Class are used to give different notification on a message. They are also used in the chatwindow as an HTML class
390 QStringList classes() const;
393 * @brief Add a class
394 * @see classes
395 * @param class class to add
397 void addClass(const QString& classe);
400 * @brief Set the classes
401 * @see classes
402 * @param classes The new classes
404 void setClasses(const QStringList &classes);
406 public: /* static helpers */
409 * Unescapes a string, removing XML entity references and returns a plain text.
411 * Note that this method is *VERY* expensive when called on rich text bodies,
412 * use with care!
415 static QString unescape( const QString &xml );
418 * @brief Transform a plaintext message into HTML.
419 * it escape main entity like &gt; &lt; add some &lt;br /&gt; or &amp;nbsp;
421 static QString escape( const QString & );
423 #if 0
424 //candidate for removal!
426 * Helper function to decode a string. Whatever returned here is *nearly guaranteed* to
427 * be parseable by the XML engine.
429 * @param message The string you are trying to decode
430 * @param providedCodec A codec you want to try to decode with
431 * @param success Optional pointer to a bool you want updated on success. "Success"
432 * is defined as a successful decoding using either UTF8 or the codec you
433 * provided. If a guess has to be taken, success will be false.
434 * @return The decoded string
437 static QString decodeString( const QByteArray &message,
438 const QTextCodec *providedCodec = 0L, bool *success = 0L );
439 #endif
441 private:
442 class Private;
443 QSharedDataPointer<Private> d;
446 * Called internally by @ref setBody() and the constructor
447 * Basically @ref setBody() without detach
448 * @internal
450 void doSetBody( const QString &body, Qt::TextFormat format = Qt::PlainText );
453 * Called internally by @ref setBody() and the constructor
454 * Basically @ref setBody() without detach
455 * @internal
457 void doSetBody (const QTextDocument *body, Qt::TextFormat format = Qt::PlainText);
460 * Called internally in rich text handling
461 * @internal
463 static QString parseLinks( const QString &message, Qt::TextFormat format );
468 #endif
470 // vim: set noet ts=4 sts=4 sw=4: