34 #include "tdehtmlparthtmlwriter.h"
37 #include <tdehtml_part.h>
38 #include <tdehtmlview.h>
40 #include <dom/dom_string.h>
41 #include <dom/html_document.h>
42 #include <dom/html_image.h>
43 #include <dom/html_misc.h>
49 KHtmlPartHtmlWriter::KHtmlPartHtmlWriter( TDEHTMLPart * part,
50 TQObject * parent,
const char * name )
51 : TQObject( parent, name ), HtmlWriter(),
52 mHtmlPart( part ), mHtmlTimer( 0,
"mHtmlTimer" ), mState( Ended )
55 connect( &mHtmlTimer, TQ_SIGNAL(timeout()), TQ_SLOT(slotWriteNextHtmlChunk()) );
58 KHtmlPartHtmlWriter::~KHtmlPartHtmlWriter() {
62 void KHtmlPartHtmlWriter::begin(
const TQString & css ) {
63 if ( mState != Ended ) {
64 kdWarning( 5006 ) <<
"KHtmlPartHtmlWriter: begin() called on non-ended session!" << endl;
68 mEmbeddedPartMap.clear();
71 mHtmlPart->view()->setUpdatesEnabled(
false );
72 mHtmlPart->view()->viewport()->setUpdatesEnabled(
false );
73 static_cast<TQScrollView *
>(mHtmlPart->widget())->ensureVisible( 0, 0 );
75 mHtmlPart->begin( KURL(
"file:/" ) );
77 mHtmlPart->setUserStyleSheet( css );
81 void KHtmlPartHtmlWriter::end() {
82 kdWarning( mState != Begun, 5006 ) <<
"KHtmlPartHtmlWriter: end() called on non-begun or queued session!" << endl;
87 mHtmlPart->view()->viewport()->setUpdatesEnabled(
true );
88 mHtmlPart->view()->setUpdatesEnabled(
true );
89 mHtmlPart->view()->viewport()->repaint(
false );
93 void KHtmlPartHtmlWriter::reset() {
94 if ( mState != Ended ) {
103 void KHtmlPartHtmlWriter::write(
const TQString & str ) {
104 kdWarning( mState != Begun, 5006 ) <<
"KHtmlPartHtmlWriter: write() called in Ended or Queued state!" << endl;
105 mHtmlPart->write( str );
108 void KHtmlPartHtmlWriter::queue(
const TQString & str ) {
109 static const uint chunksize = 16384;
110 for ( uint pos = 0 ; pos < str.length() ; pos += chunksize )
111 mHtmlQueue.push_back( str.mid( pos, chunksize ) );
115 void KHtmlPartHtmlWriter::flush() {
116 slotWriteNextHtmlChunk();
119 void KHtmlPartHtmlWriter::slotWriteNextHtmlChunk() {
120 if ( mHtmlQueue.empty() ) {
124 mHtmlPart->write( mHtmlQueue.front() );
125 mHtmlQueue.pop_front();
126 mHtmlTimer.start( 0,
true );
130 void KHtmlPartHtmlWriter::embedPart(
const TQCString & contentId,
131 const TQString & contentURL ) {
132 mEmbeddedPartMap[TQString(contentId)] = contentURL;
135 void KHtmlPartHtmlWriter::resolveCidUrls()
137 DOM::HTMLDocument document = mHtmlPart->htmlDocument();
138 DOM::HTMLCollection images = document.images();
139 for ( DOM::Node node = images.firstItem(); !node.isNull(); node = images.nextItem() ) {
140 DOM::HTMLImageElement image( node );
141 KURL url( image.src().string() );
142 if ( url.protocol() ==
"cid" ) {
143 EmbeddedPartMap::const_iterator it = mEmbeddedPartMap.find( url.path() );
144 if ( it != mEmbeddedPartMap.end() ) {
145 kdDebug(5006) <<
"Replacing " << url.prettyURL() <<
" by " << it.data() << endl;
146 image.setSrc( it.data() );
154 #include "tdehtmlparthtmlwriter.moc"