00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
#ifdef HAVE_CONFIG_H
00033
#include <config.h>
00034
#endif
00035
00036
#include "filehtmlwriter.h"
00037
00038
#include <kdebug.h>
00039
00040
00041
namespace KMail {
00042
00043 FileHtmlWriter::FileHtmlWriter(
const QString & filename )
00044 : HtmlWriter(),
00045 mFile( filename.isEmpty() ?
QString(
"filehtmlwriter.out" ) : filename )
00046 {
00047 mStream.setEncoding( QTextStream::UnicodeUTF8 );
00048 }
00049
00050 FileHtmlWriter::~FileHtmlWriter() {
00051
if ( mFile.isOpen() ) {
00052 kdWarning( 5006 ) <<
"FileHtmlWriter: file still open!" << endl;
00053 mStream.unsetDevice();
00054 mFile.close();
00055 }
00056 }
00057
00058
void FileHtmlWriter::begin(
const QString & css ) {
00059 openOrWarn();
00060
if ( !css.isEmpty() )
00061 write(
"<!-- CSS Definitions \n" + css +
"-->\n" );
00062 }
00063
00064
void FileHtmlWriter::end() {
00065 flush();
00066 mStream.unsetDevice();
00067 mFile.close();
00068 }
00069
00070
void FileHtmlWriter::reset() {
00071
if ( mFile.isOpen() ) {
00072 mStream.unsetDevice();
00073 mFile.close();
00074 }
00075 }
00076
00077
void FileHtmlWriter::write(
const QString & str ) {
00078 mStream << str;
00079 flush();
00080 }
00081
00082
void FileHtmlWriter::queue(
const QString & str ) {
00083 write( str );
00084 }
00085
00086
void FileHtmlWriter::flush() {
00087 mFile.flush();
00088 }
00089
00090
void FileHtmlWriter::openOrWarn() {
00091
if ( mFile.isOpen() ) {
00092 kdWarning( 5006 ) <<
"FileHtmlWriter: file still open!" << endl;
00093 mStream.unsetDevice();
00094 mFile.close();
00095 }
00096
if ( !mFile.open( IO_WriteOnly ) )
00097 kdWarning( 5006 ) <<
"FileHtmlWriter: Cannot open file " << mFile.name() << endl;
00098
else
00099 mStream.setDevice( &mFile );
00100 }
00101
00102
00103
00104 }