/* 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 #include #include #include typedef KGenericFactory DBaseImportFactory; K_EXPORT_COMPONENT_FACTORY( libdbaseimport, DBaseImportFactory( "kofficefilters" ) ) DBaseImport::DBaseImport ( TQObject*, const char*, const TQStringList& ) : KoFilter() { } KoFilter::ConversionStatus DBaseImport::convert( const TQCString& from, const TQCString& to ) { if (to != "application/x-kspread" || from != "application/x-dbase") return KoFilter::NotImplemented; TQString inputFile = m_chain->inputFile(); DBase dbase; bool result = dbase.load( inputFile ); if( dbase.version() !=3 ) { KMessageBox::sorry( 0, i18n("File format is not supported.") ); return KoFilter::NotImplemented; } if( !result ) { KMessageBox::sorry( 0, i18n("Could not read from file." ) ); return KoFilter::StupidError; } TQString root, documentInfo; root = "\n"; root += "\n"; root += "\n"; root += "\n"; root += "\n"; root += "\n"; root += "\n"; root += "\n"; root += "\n"; root += "\n"; // KOffice default font TQFont font = KoGlobal::defaultFont(); // define columns TQFontMetrics fm( font ); for( unsigned i=0; ilength, dbase.fields.at(i)->name.length()); double w = POINT_TO_MM( fm.maxWidth() * mw ); root += "\n"; } // define rows double h = POINT_TO_MM( 5 + fm.height() + fm.leading() ); for( unsigned j=0; j\n"; } // field names come as first row for( unsigned i=0; i\n"; root += ""; root += ""; root += "\n"; root += "" + dbase.fields.at(i)->name + "\n"; } // process all records unsigned row = 1; for( unsigned j=0; j\n"; root += ""; root += ""; root += "\n"; root += "" + rec[i] + "\n"; } } } dbase.close(); root += "
\n"; root += "
\n"; root += "
"; // prepare storage KoStoreDevice* out=m_chain->storageFile( "root", KoStore::Write ); // store output document if( out ) { TQCString cstring = root.utf8(); cstring.prepend( "\n" ); out->writeBlock( (const char*) cstring, cstring.length() ); } // 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; }