kmail

filehtmlwriter.cpp
1/*
2 filehtmlwriter.cpp
3
4 This file is part of KMail, the KDE mail client.
5 Copyright (c) 2003 Marc Mutz <mutz@kde.org>
6
7 KMail is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License, version 2, as
9 published by the Free Software Foundation.
10
11 KMail is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20 In addition, as a special exception, the copyright holders give
21 permission to link the code of this program with any edition of
22 the TQt library by Trolltech AS, Norway (or with modified versions
23 of TQt that use the same license as TQt), and distribute linked
24 combinations including the two. You must obey the GNU General
25 Public License in all respects for all of the code used other than
26 TQt. If you modify this file, you may extend this exception to
27 your version of the file, but you are not obligated to do so. If
28 you do not wish to do so, delete this exception statement from
29 your version.
30*/
31
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36#include "filehtmlwriter.h"
37
38#include <kdebug.h>
39
40
41namespace KMail {
42
43 FileHtmlWriter::FileHtmlWriter( const TQString & filename )
44 : HtmlWriter(),
45 mFile( filename.isEmpty() ? TQString( "filehtmlwriter.out" ) : filename )
46 {
47 mStream.setEncoding( TQTextStream::UnicodeUTF8 );
48 }
49
50 FileHtmlWriter::~FileHtmlWriter() {
51 if ( mFile.isOpen() ) {
52 kdWarning( 5006 ) << "FileHtmlWriter: file still open!" << endl;
53 mStream.unsetDevice();
54 mFile.close();
55 }
56 }
57
58 void FileHtmlWriter::begin( const TQString & css ) {
59 openOrWarn();
60 if ( !css.isEmpty() )
61 write( "<!-- CSS Definitions \n" + css + "-->\n" );
62 }
63
64 void FileHtmlWriter::end() {
65 flush();
66 mStream.unsetDevice();
67 mFile.close();
68 }
69
70 void FileHtmlWriter::reset() {
71 if ( mFile.isOpen() ) {
72 mStream.unsetDevice();
73 mFile.close();
74 }
75 }
76
77 void FileHtmlWriter::write( const TQString & str ) {
78 mStream << str;
79 flush();
80 }
81
82 void FileHtmlWriter::queue( const TQString & str ) {
83 write( str );
84 }
85
86 void FileHtmlWriter::flush() {
87 mFile.flush();
88 }
89
90 void FileHtmlWriter::openOrWarn() {
91 if ( mFile.isOpen() ) {
92 kdWarning( 5006 ) << "FileHtmlWriter: file still open!" << endl;
93 mStream.unsetDevice();
94 mFile.close();
95 }
96 if ( !mFile.open( IO_WriteOnly ) )
97 kdWarning( 5006 ) << "FileHtmlWriter: Cannot open file " << mFile.name() << endl;
98 else
99 mStream.setDevice( &mFile );
100 }
101
102 void FileHtmlWriter::embedPart( const TQCString & contentId, const TQString & url ) {
103 mStream << "<!-- embedPart(contentID=" << contentId << ", url=" << url << ") -->" << endl;
104 flush();
105 }
106
107
108} // namespace KMail
folderdiaquotatab.h
Definition: aboutdata.cpp:40