~ubuntu-branches/ubuntu/natty/kadu/natty

« back to all changes in this revision

Viewing changes to kadu-core/message.h

  • Committer: Package Import Robot
  • Author(s): Kiszel Kristóf
  • Date: 2010-07-21 15:24:54 UTC
  • mfrom: (0.6.1) (0.5.1) (1.4.1) (22.1.2 maverick)
  • Revision ID: package-import@ubuntu.com-20100721152454-vttqle18lovfudni
Tags: 0.6.5.4.ds1-3ubuntu2
Remove libqt4-webkit-dev from build-depends and add
libqtwebkit-dev for qtwebkit transition

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *                                                                         *
 
3
 *   This program is free software; you can redistribute it and/or modify  *
 
4
 *   it under the terms of the GNU General Public License as published by  *
 
5
 *   the Free Software Foundation; either version 2 of the License, or     *
 
6
 *   (at your option) any later version.                                   *
 
7
 *                                                                         *
 
8
 ***************************************************************************/
 
9
 
 
10
#ifndef MESSAGE_H
 
11
#define MESSAGE_H
 
12
 
 
13
#include <QtCore/QList>
 
14
#include <QtCore/QRegExp>
 
15
#include <QtGui/QColor>
 
16
 
 
17
#include "protocol.h"
 
18
 
 
19
#include "exports.h"
 
20
 
 
21
class QTextDocument;
 
22
 
 
23
/**
 
24
 * \class MessagePart
 
25
 * \brief Part of message that has text and formatting (or an image)
 
26
 *
 
27
 * This class represents a part of message - text with formatting or an image.
 
28
 * Each \see Message is constructed from a series of message parts.
 
29
 *
 
30
 * Method isImage is used to distinguish image-parts from text-parts.
 
31
 *
 
32
 * There are two kinds of image parts:
 
33
 * <ul>
 
34
 *   <li>not-yet-received image parts -
 
35
 *       they contains informations about sender of image, and image size and crc32
 
36
 *       (used with Gadu-Gadu protocol to assign incoming images with messages).
 
37
 *   </li>
 
38
 *   <li>received image parts -
 
39
 *       they contains only local image path
 
40
 *   </li>
 
41
 * </ul>
 
42
 * @TODO: refactor
 
43
 */
 
44
class MessagePart
 
45
{
 
46
        bool Image;
 
47
        UinType ImageSender;
 
48
        int ImageSize;
 
49
        int ImageCrc32;
 
50
 
 
51
        QString Content;
 
52
        bool Bold;
 
53
        bool Italic;
 
54
        bool Underline;
 
55
        QColor Color;
 
56
 
 
57
        QString ImagePath;
 
58
 
 
59
public:
 
60
        /**
 
61
         * Creates text message part with formatting.
 
62
         * @arg content content of message
 
63
         * @arg bold if true, the whole part is presented with bold font
 
64
         * @arg italic if true, the whole part is presented with italic font
 
65
         * @arg underline if true, the whole part is presented with underline font
 
66
         * @arg color color of whole part
 
67
         */
 
68
        MessagePart(const QString &content, bool bold, bool italic, bool underline, QColor color);
 
69
 
 
70
        /**
 
71
         * Creates image message part. All informations are used to
 
72
         * assign an image to this part, when the real image is received from sender.
 
73
         *
 
74
         * @arg imageSender sender of the image
 
75
         * @arg imageSize size of the image
 
76
         * @arg imageCrc32 crc32 of the image
 
77
         */
 
78
        MessagePart(UinType imageSender, int imageSize, int imageCrc32);
 
79
 
 
80
        /**
 
81
         * Creates image message part.
 
82
         * @arg imagePath local image path
 
83
         */
 
84
        MessagePart(const QString &imagePath);
 
85
        virtual ~MessagePart();
 
86
 
 
87
        bool isImage() const { return Image; }
 
88
        bool isEmpty() const { return !Image && Content.isEmpty(); }
 
89
 
 
90
        QString content() const { return Content; }
 
91
        bool bold() const { return Bold; }
 
92
        bool italic() const { return Italic; }
 
93
        bool underline() const { return Underline; }
 
94
        QColor color() const { return Color; }
 
95
 
 
96
        QString imagePath() const { return ImagePath; }
 
97
 
 
98
        /**
 
99
         * Converts message part to HTML - either formatted text or image.
 
100
         * @return HTML representation of message parh.
 
101
         */
 
102
        QString toHtml() const;
 
103
 
 
104
};
 
105
 
 
106
/**
 
107
 * \class Message
 
108
 * \brief Rich message (incoming or outcoming).
 
109
 *
 
110
 * This class represens incoming or outgoing message. Some protocols (like GG) uses its own
 
111
 * formatting, so this class acts like abstraction over all used formatting methods in Kadu.
 
112
 *
 
113
 * Message is splited into parts (\see MessagePart) - each part can contain text and formatting or an image.
 
114
 *
 
115
 * Each message has an <code>id</code> field that is used by protocols to store its message sequental number.
 
116
 */
 
117
class KADUAPI Message
 
118
{
 
119
        static QRegExp ImageRegExp;
 
120
        static void parseImages(Message &message, const QString &messageString, bool b, bool i, bool u, QColor color);
 
121
 
 
122
        QList<MessagePart> Parts;
 
123
        int Id;
 
124
 
 
125
public:
 
126
        /**
 
127
         * Creates an empty message.
 
128
         */
 
129
        Message();
 
130
 
 
131
        /**
 
132
         * Creates a message with one, non-formatted text part.
 
133
         *
 
134
         * @arg messageString content of new message
 
135
         */
 
136
        Message(const QString &messageString);
 
137
 
 
138
        virtual ~Message();
 
139
 
 
140
        /**
 
141
         * Creates a message from given HTML document. The bold, italic, underline and
 
142
         * color formatting are preserved and stored into result object.
 
143
         * It also extracts images and inserts in into message.
 
144
         *
 
145
         * @arg messageDocument HTML document to parse
 
146
         * @return Message representation of HTML document
 
147
         */
 
148
        static Message parse(const QTextDocument *messageDocument);
 
149
 
 
150
        /**
 
151
         * Returns all parts that composes this message.
 
152
         * @return All parts that composes this message.
 
153
         */
 
154
        QList<MessagePart> parts() const;
 
155
 
 
156
        /**
 
157
         * Append a new part to message.
 
158
         * @arg part New part to append.
 
159
         */
 
160
        void append(MessagePart part);
 
161
 
 
162
        /**
 
163
         * Append a new part to message.
 
164
         * @arg part New part to append.
 
165
         */
 
166
        Message & operator << (MessagePart part);
 
167
 
 
168
        void setId(int id) { Id = id; }
 
169
        int id() { return Id; }
 
170
 
 
171
        /**
 
172
         * Returns true if message does not have any parts or if all parts are empty.
 
173
         * @return True if message is empty.
 
174
         */
 
175
        bool isEmpty() const;
 
176
 
 
177
        /**
 
178
         * Returns message content, without formatting or images.
 
179
         * @return Plain message content.
 
180
         */
 
181
        QString toPlain() const;
 
182
 
 
183
        /**
 
184
         * Converts message to HTML, with formatting and images. Resulting code is
 
185
         * not a full HTML page - only the content.
 
186
         * @return HTML representation of message.
 
187
         */
 
188
        QString toHtml() const;
 
189
 
 
190
};
 
191
 
 
192
#endif // MESSAGE_H