/* This file is part of the KDE project Copyright (C) 2002 Ariya Hidayat This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #ifdef HAVE_UNISTD_H #include #endif #include #include #include #include #include #include #include #include #include #include "palmdocimport.h" #include "palmdoc.h" typedef KGenericFactory PalmDocImportFactory; K_EXPORT_COMPONENT_FACTORY( libpalmdocimport, PalmDocImportFactory( "kofficefilters" ) ) PalmDocImport::PalmDocImport( KoFilter *, const char *, const TQStringList& ): KoFilter() { } KoFilter::ConversionStatus PalmDocImport::convert( const TQCString& from, const TQCString& to ) { // check for proper conversion if( to!= "application/x-kword" || from != "application/vnd.palm" ) return KoFilter::NotImplemented; PalmDoc doc; TQString inputFile( m_chain->inputFile() ); doc.load( inputFile.latin1() ); if( doc.result() == PalmDoc::InvalidFormat ) return KoFilter::NotImplemented; if( doc.result() == PalmDoc::ReadError ) return KoFilter::FileNotFound; TQString root = processPlainDocument( doc.text() ); // prepare storage KoStoreDevice *out=m_chain->storageFile( "root", KoStore::Write ); if( out ) { TQCString cstring = root.utf8(); cstring.prepend( "\n" ); out->writeBlock( (const char*) cstring, cstring.length() ); } TQString docTitle = doc.name(); if( docTitle.isEmpty() ) { TQFileInfo info( inputFile ); docTitle = info.baseName(); } TQString documentInfo = processDocumentInfo( docTitle ); // store document info out = m_chain->storageFile( "documentinfo.xml", KoStore::Write ); if( out ) { TQCString cstring = documentInfo.utf8(); cstring.prepend( "\n" ); out->writeBlock( (const char*) cstring, cstring.length() ); } return KoFilter::OK; } TQString PalmDocImport::processPlainParagraph( TQString text ) { TQString formats, layout, result; // specify FORMAT (just empty element) formats.append ( " \n" ); formats.append ( " \n" ); TQFont font = KoGlobal::defaultFont(); TQString fontFamily = font.family(); double fontSize = font.pointSizeFloat(); // default LAYOUT layout.append( "\n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( " \n" ); layout.append( "\n" ); // encode text for XML-ness text.replace( '&', "&" ); text.replace( '<', "<" ); text.replace( '>', ">" ); text.replace( '"', """ ); text.replace( '\'', "'" ); // construct the result.append( "\n" ); result.append( "" + text + "\n" ); result.append( "\n"); result.append( formats ); result.append( "\n"); result.append( layout ); result.append( "\n" ); return result; } TQString PalmDocImport::processPlainDocument( TQString plaindoc ) { TQString prolog, content, epilog; TQStringList paragraphs; paragraphs = TQStringList::split( "\n\n", plaindoc, TRUE ); for( unsigned int i = 0; i < paragraphs.count(); i++ ) { TQString text = paragraphs[i]; text.replace( '\n', ' ' ); content.append( processPlainParagraph( text ) ); } prolog = "\n"; prolog.append( "\n"); prolog.append( "\n" ); prolog.append( " \n" ); prolog.append( "\n" ); prolog.append( "\n" ); prolog.append( "\n" ); prolog.append( "\n" ); prolog.append( "\n" ); epilog = "\n"; epilog.append( "\n" ); epilog.append( "\n" ); return prolog + content + epilog; } TQString PalmDocImport::processDocumentInfo( const TQString &title ) { TQString documentInfo; documentInfo = "\n"; documentInfo += "\n"; documentInfo += "\n"; documentInfo += "\n"; documentInfo += "\n"; documentInfo += "\n"; documentInfo += "\n"; documentInfo += "\n"; documentInfo += "\n"; documentInfo += "\n"; documentInfo += "\n"; documentInfo += "\n"; documentInfo += "" + title + "\n"; documentInfo += "\n"; documentInfo += ""; return documentInfo; } #include "palmdocimport.moc"