~ubuntu-branches/ubuntu/utopic/libmsn/utopic

« back to all changes in this revision

Viewing changes to msn/message.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-12-10 20:20:14 UTC
  • Revision ID: james.westby@ubuntu.com-20081210202014-bqgd3j5qn04ro9xr
Tags: upstream-4.0~beta1svn77
ImportĀ upstreamĀ versionĀ 4.0~beta1svn77

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __msn_message_h__
 
2
#define __msn_message_h__
 
3
 
 
4
/*
 
5
 * message.h
 
6
 * libmsn
 
7
 *
 
8
 * Created by Mark Rowe on Wed Mar 17 2004.
 
9
 * Refactored by Tiago Salem Herrmann on 08/2007.
 
10
 * Copyright (c) 2004 Mark Rowe. All rights reserved.
 
11
 * Copyright (c) 2007 Tiago Salem Herrmann. All rights reserved
 
12
 *
 
13
 * This program is free software; you can redistribute it and/or modify
 
14
 * it under the terms of the GNU General Public License as published by
 
15
 * the Free Software Foundation; either version 2 of the License, or
 
16
 * (at your option) any later version.
 
17
 *
 
18
 * This program is distributed in the hope that it will be useful,
 
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
 * GNU General Public License for more details.
 
22
 *
 
23
 * You should have received a copy of the GNU General Public License
 
24
 * along with this program; if not, write to the Free Software
 
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
26
 */
 
27
 
 
28
#include <string>
 
29
#include <map>
 
30
#include <vector>
 
31
#include <stdexcept>
 
32
 
 
33
#include "libmsn_export.h"
 
34
 
 
35
#ifdef _MSC_VER
 
36
#pragma warning( disable : 4290 )
 
37
#endif
 
38
 
 
39
namespace MSN 
 
40
{
 
41
    
 
42
    /** This class represents an MSN message
 
43
     *
 
44
     *  It may or may not represent an @e instant @e message.
 
45
     *
 
46
     *  @todo  Complete read/write support for formatting messages.
 
47
     */
 
48
    class LIBMSN_EXPORT Message
 
49
    {
 
50
public:
 
51
        enum FontEffects
 
52
        {
 
53
            BOLD_FONT = 1,
 
54
            ITALIC_FONT = 2,
 
55
            UNDERLINE_FONT = 4,
 
56
            STRIKETHROUGH_FONT = 8
 
57
        };
 
58
        
 
59
        enum CharacterSet
 
60
        {
 
61
            ANSI_CHARSET = 0x00,
 
62
            DEFAULT_CHARSET = 0x01,
 
63
            SYMBOL_CHARSET = 0x02,
 
64
            MAC_CHARSET = 0x4d,
 
65
            SHIFTJIS_CHARSET = 0x80,
 
66
            HANGEUL_CHARSET = 0x81,
 
67
            JOHAB_CHARSET = 0x82,
 
68
            GB2312_CHARSET = 0x86,
 
69
            CHINESEBIG5_CHARSET = 0x88,
 
70
            GREEK_CHARSET = 0xa1,
 
71
            TURKISH_CHARSET = 0xa2,
 
72
            VIETNAMESE_CHARSET = 0xa3,
 
73
            HEBREW_CHARSET = 0xb1,
 
74
            ARABIC_CHARSET = 0xb2,
 
75
            BALTIC_CHARSET = 0xba,
 
76
            RUSSIAN_CHARSET_DEFAULT = 0xcc,
 
77
            THAI_CHARSET = 0xde,
 
78
            EASTEUROPE_CHARSET = 0xee,
 
79
            OEM_DEFAULT = 0xff
 
80
        };
 
81
        
 
82
        enum FontFamily
 
83
        {
 
84
            FF_DONTCARE = 0,
 
85
            FF_ROMAN = 1,
 
86
            FF_SWISS = 2,
 
87
            FF_MODERN = 3,
 
88
            FF_SCRIPT = 4,
 
89
            FF_DECORATIVE = 5
 
90
        };
 
91
        
 
92
        enum FontPitch
 
93
        {
 
94
            DEFAULT_PITCH = 0,
 
95
            FIXED_PITCH = 1,
 
96
            VARIABLE_PITCH = 2
 
97
        };
 
98
        
 
99
        class Headers
 
100
        {
 
101
public:
 
102
            Headers(const std::string & rawContents_) : rawContents(rawContents_) {};
 
103
            Headers() : rawContents("") {};
 
104
            std::string asString() const;
 
105
            std::string operator[](const std::string header) const;
 
106
            void setHeader(const std::string header, const std::string value);
 
107
 
 
108
private:
 
109
            std::string rawContents;
 
110
        };
 
111
 
 
112
private:
 
113
        std::string body;
 
114
        Message::Headers header;
 
115
 
 
116
public:
 
117
        /** Create a message with the specified @a body and @a mimeHeader.
 
118
         */
 
119
        Message(std::string body, std::string mimeHeader="MIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\n\r\n");
 
120
        
 
121
        /** Convert the Message into a string.
 
122
         *
 
123
         *  This returns a string containing the MIME headers separated from the
 
124
         *  message body by a blank line.
 
125
         */
 
126
        std::string asString() const;
 
127
        
 
128
        /** Return the value of the MIME header named @a header.
 
129
         *
 
130
         *  @return  The value of the MIME header if present, or "" if not found.
 
131
         */ 
 
132
        std::string operator[](const std::string header) const;
 
133
        void setHeader(const std::string name, const std::string value) { header.setHeader(name, value); };
 
134
        
 
135
        /** Return the body portion of this Message.
 
136
         */
 
137
        std::string getBody() const { return body; };
 
138
        
 
139
        /** Return the font name used in this Message.
 
140
         *
 
141
         *  @return  The font name used for this Message, or "" if none specified.
 
142
         */
 
143
        std::string getFontName() const;
 
144
        
 
145
        /** Set font name for use in this Message.
 
146
         */
 
147
        void setFontName(const std::string & fontName);
 
148
        
 
149
        /** Get the color used in this Message.
 
150
         */
 
151
        std::vector<int> getColor() const;
 
152
        std::string getColorAsHTMLString() const;
 
153
        
 
154
        /** Set the color used in this Message.
 
155
         */
 
156
        void setColor(std::vector<int> color);
 
157
        void setColor(std::string color);
 
158
        void setColor(int red, int green, int blue);
 
159
        
 
160
        /** Return the font effects used in this Message.
 
161
         *
 
162
         *  @return An integer that is a bitwise-or of Message::FontEffects members.
 
163
         */
 
164
        int getFontEffects() const;
 
165
        
 
166
        /** Set the font effects for use in this Message.
 
167
         *
 
168
         *  @param fontEffects Bitwise-or of Message::FontEffects members.
 
169
         */
 
170
        void setFontEffects(int fontEffects);
 
171
        
 
172
        /** Return the character set that the font uses in this Message.
 
173
         */
 
174
        CharacterSet getFontCharacterSet() const;
 
175
        
 
176
        /** Set the character set that the font should use for this Message.
 
177
         */
 
178
        void setFontCharacterSet(CharacterSet cs);
 
179
        
 
180
        /** Return the font family used in this Message.
 
181
         */
 
182
        FontFamily getFontFamily() const;
 
183
        
 
184
        /** Return the font pitch used in this Message.
 
185
         */
 
186
        FontPitch getFontPitch() const;
 
187
        
 
188
        /** Set the font family and pitch to be used for this Message.
 
189
         */
 
190
        void setFontFamilyAndPitch(Message::FontFamily fontFamily, Message::FontPitch fontPitch);
 
191
        
 
192
        /** Is the Message to be right-aligned?
 
193
         */
 
194
        bool isRightAligned() const;
 
195
 
 
196
private:
 
197
        std::map<std::string, std::string> getFormatInfo() const throw (std::runtime_error);
 
198
        void setFormatInfo(std::map<std::string, std::string> & info);
 
199
    };
 
200
    
 
201
}
 
202
#endif