26#include <tdetempfile.h>
28#include <KoFilterManager.h>
40KoEmbeddingFilter::~KoEmbeddingFilter()
42 if ( m_partStack.count() != 1 )
43 kdWarning() <<
"Someone messed with the part stack" << endl;
44 delete m_partStack.pop();
47int KoEmbeddingFilter::lruPartIndex()
const
49 return m_partStack.top()->m_lruPartIndex;
57 url.setPath( TQString(
"dummy.%1" ).arg( extension ) );
58 KMimeType::Ptr m( KMimeType::findByURL( url, 0,
true,
true ) );
64 m_partStack.push(
new PartState() );
70 ++( m_partStack.top()->m_lruPartIndex );
73 tempIn.setAutoDelete(
true );
74 savePartContents( tempIn.file() );
75 tempIn.file()->close();
78 status = manager->
exp0rt( TQString(), to );
83 PartReference ref( lruPartIndex(), to );
84 m_partStack.top()->m_partReferences.insert( key.isEmpty() ? TQString::number( lruPartIndex() ) : key, ref );
86 return lruPartIndex();
91 filterChainEnterDirectory( TQString::number( ++( m_partStack.top()->m_lruPartIndex ) ) );
92 PartReference ref( lruPartIndex(), mimeType );
93 m_partStack.top()->m_partReferences.insert( key, ref );
94 m_partStack.push(
new PartState() );
99 if ( m_partStack.count() == 1 ) {
100 kdError( 30500 ) <<
"You're trying to endInternalEmbedding more often than you started it" << endl;
103 delete m_partStack.pop();
104 filterChainLeaveDirectory();
109 TQMapConstIterator<TQString, PartReference> it = m_partStack.top()->m_partReferences.find( key );
110 if ( it == m_partStack.top()->m_partReferences.end() )
112 return it.data().m_index;
117 TQMapConstIterator<TQString, PartReference> it = m_partStack.top()->m_partReferences.find( key );
118 if ( it == m_partStack.top()->m_partReferences.end() )
120 return it.data().m_mimeType;
123KoEmbeddingFilter::PartReference::PartReference(
int index,
const TQCString& mimeType ) :
124 m_index( index ), m_mimeType( mimeType )
128bool KoEmbeddingFilter::PartReference::isValid()
const
130 return m_index != 1 && !m_mimeType.isEmpty();
133KoEmbeddingFilter::PartState::PartState() : m_lruPartIndex( 0 )
137void KoEmbeddingFilter::savePartContents( TQIODevice* )
141void KoEmbeddingFilter::filterChainEnterDirectory(
const TQString& directory )
const
143 m_chain->enterDirectory( directory );
146void KoEmbeddingFilter::filterChainLeaveDirectory()
const
151#include <KoFilter.moc>
int embedPart(const TQCString &from, TQCString &to, KoFilter::ConversionStatus &status, const TQString &key=TQString())
Embed some document using an external filter (i.e.
static TQString mimeTypeByExtension(const TQString &extension)
A static helper method to determine the mimetype via the file extension.
int internalPartReference(const TQString &key) const
Query the internal part map for the reference of the part matching the given key.
TQCString internalPartMimeType(const TQString &key) const
Query the internal part map for the mimetype of the part matching the given key.
KoEmbeddingFilter()
Constructs a filter.
void endInternalEmbedding()
This method signals the end of an internal embedding session.
void startInternalEmbedding(const TQString &key, const TQCString &mimeType)
Method to perform "internal" embedding of parts in olefilter-style.
The class managing all the filters.
KoFilter::ConversionStatus exp0rt(const TQString &url, TQCString &mimeType)
Exports the given file/document to the specified URL/mimetype.
KoFilterChain * m_chain
Use this pointer to access all information about input/output during the conversion.
ConversionStatus
This enum is used to signal the return state of your filter.
KoFilter()
This is the constructor your filter has to call, obviously.