From 8362bf63dea22bbf6736609b0f49c152f975eb63 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 20 Jan 2010 01:29:50 +0000 Subject: Added old abandoned KDE3 version of koffice git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- filters/kspread/dbase/Makefile.am | 17 ++ filters/kspread/dbase/dbase.cpp | 251 +++++++++++++++++++++ filters/kspread/dbase/dbase.h | 67 ++++++ filters/kspread/dbase/dbaseimport.cc | 181 +++++++++++++++ filters/kspread/dbase/dbaseimport.h | 38 ++++ filters/kspread/dbase/kspread_dbase_import.desktop | 65 ++++++ filters/kspread/dbase/status.html | 164 ++++++++++++++ filters/kspread/dbase/test/birth.dbf | Bin 0 -> 134 bytes filters/kspread/dbase/test/browser.dbf | Bin 0 -> 167 bytes filters/kspread/dbase/test/stability.dbf | Bin 0 -> 161 bytes 10 files changed, 783 insertions(+) create mode 100644 filters/kspread/dbase/Makefile.am create mode 100644 filters/kspread/dbase/dbase.cpp create mode 100644 filters/kspread/dbase/dbase.h create mode 100644 filters/kspread/dbase/dbaseimport.cc create mode 100644 filters/kspread/dbase/dbaseimport.h create mode 100644 filters/kspread/dbase/kspread_dbase_import.desktop create mode 100644 filters/kspread/dbase/status.html create mode 100755 filters/kspread/dbase/test/birth.dbf create mode 100644 filters/kspread/dbase/test/browser.dbf create mode 100755 filters/kspread/dbase/test/stability.dbf (limited to 'filters/kspread/dbase') diff --git a/filters/kspread/dbase/Makefile.am b/filters/kspread/dbase/Makefile.am new file mode 100644 index 00000000..29322ab4 --- /dev/null +++ b/filters/kspread/dbase/Makefile.am @@ -0,0 +1,17 @@ +####### General stuff + +INCLUDES= -I$(srcdir) $(KOFFICE_INCLUDES) $(all_includes) + +####### Files + +kde_module_LTLIBRARIES = libdbaseimport.la + +libdbaseimport_la_SOURCES = dbaseimport.cc dbase.cpp +libdbaseimport_la_LIBADD = $(KOFFICE_LIBS) +libdbaseimport_la_LDFLAGS = -module $(KDE_PLUGIN) +noinst_HEADERS = dbaseimport.h dbase.h + +METASOURCES = AUTO + +service_DATA = kspread_dbase_import.desktop +servicedir = $(kde_servicesdir) diff --git a/filters/kspread/dbase/dbase.cpp b/filters/kspread/dbase/dbase.cpp new file mode 100644 index 00000000..67780f33 --- /dev/null +++ b/filters/kspread/dbase/dbase.cpp @@ -0,0 +1,251 @@ +/* This file is part of the KDE project + Copyright (C) 2002 by Thomas Franke and Andreas Pietzowski + 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 +#include +#include +#include +#include +#include + +#include + +DBase::DBase(): m_recordCount( 0 ) +{ + fields.setAutoDelete( true ); +} + +DBase::~DBase() +{ + fields.clear(); + close(); +} + + // Headerdefinition in dBASE + // + // Type char Content + // + // unsigned char version 0 dBASE-Version (3) + // unsigned char last_update[3] 1-3 Date of last update + // unsigned long records 4-7 Number of records + // unsigned short header_length 8-9 headerlength + // unsigned short record_length 10-11 recordlength + // unsigned char reserved[20] 12-31 reserverd info from dBase + // + +bool DBase::load( const QString& filename ) +{ + + m_file.setName( filename ); + if( !m_file.open(IO_ReadOnly) ) + return false; + + m_stream.setDevice( &m_file ); + m_stream.setByteOrder( QDataStream::LittleEndian ); + + unsigned filesize = m_file.size(); + + // read dBASE version + Q_UINT8 ver; + m_stream >> ver; + m_version = ver & 0x7f; // bit 7: has memo ? + + // only dBASE V.3 is supported + if ( m_version != 3 ) + return false; + + // date of last update + Q_UINT8 y, m, d; + m_stream >> y >> m >> d; + // because dBASE saves 102 instead of 2002 (very Y2K-save ;-) + m_lastUpdate.setYMD( y+1900, m, d ); + + // check for valid date + if( !m_lastUpdate.isValid() ) return false; + + // number of records + Q_UINT32 norec; + m_stream >> norec; + m_recordCount = norec; + + // header-length + Q_UINT16 header_length; + m_stream >> header_length; + m_headerLength = header_length; + + // record-length + Q_UINT16 record_length; + m_stream >> record_length; + m_recordLength = record_length; + + // read the remaining chars + Q_UINT8 dummy; + for (int foo = 0; foo < 20; ++foo) + m_stream >> dummy; + + // size of file must match + if( filesize < m_headerLength + m_recordLength * m_recordCount ) + return false; + + // Now read the headers of the columns and their type + + // Type char Content + // + // unsigned char field_name[11] 0-10 Fieldname + // unsigned char field_type 11 Fieldtype + // unsigned long field_address 12-15 Fielddataaddress + // unsigned char field_length 16 Fieldlength + // unsigned char field_decimals 17 decimals + // unsigned char reserved[14] 18-31 reserved for internal dBASE-stuff + + fields.clear(); + for( unsigned i = 1; i < m_headerLength/32; ++i ) + { + DBaseField* field = new DBaseField; + + // columnn-name + Q_UINT8 colname[12]; + for ( int j = 0; j < 11; ++j) + m_stream >> colname[j]; + colname[11] = '\0'; + field->name = QString( (const char*) &colname[0] ); + + // type of column + Q_UINT8 coltype; + m_stream >> coltype; + switch( coltype ) + { + case 'C': field->type = DBaseField::Character; break; + case 'N': field->type = DBaseField::Numeric; break; + case 'D': field->type = DBaseField::Date; break; + case 'M': field->type = DBaseField::Memo; break; + case 'L': field->type = DBaseField::Logical; break; + default: field->type = DBaseField::Unknown; break; + } + + // fileddataaddress + Q_UINT32 addr; + m_stream >> addr; + + // columnlength + Q_UINT8 colsize; + m_stream >> colsize; + field->length = colsize; + + // decimals + Q_UINT8 decimals; + m_stream >> decimals; + field->decimals = decimals; + + // read remaining chars + Q_UINT8 dummy; + for ( int foo = 0; foo < 14; ++foo ) + m_stream >> dummy; + + // now append + fields.append( field ); + } + + // set the index to the first record + m_stream.device()->at( m_headerLength ); + + return true; +} + +QStringList DBase::readRecord( unsigned recno ) +{ + QStringList result; + + // out of range ? return empty strings + if( recno >= m_recordCount ) + { + for( unsigned i=0; iat( filepos ); + + // first char == '*' means the record is deleted + // so we just skip it + Q_UINT8 delmarker; + m_stream >> delmarker; + if( delmarker == 0x2a ) + return result; + + // load it + for( unsigned i=0; itype ) + { + // Numeric or Character + case DBaseField::Numeric: + case DBaseField::Character: + { + QString str; + Q_UINT8 ch; + for( unsigned j=0; jlength; j++ ) + { m_stream >> ch; str += QChar(ch); } + result.append( str ); + } break; + + // Logical + case DBaseField::Logical: + { + Q_UINT8 ch; + m_stream >> ch; + switch( ch ) + { + case 'Y': case 'y': case 'T': case 't': result.append( "True" ); break; + case 'N': case 'n': case 'F': case 'f': result.append( "False" ); break; + default: result.append( "" ); break; + } + } break; + + // Date, stored as YYYYMMDD + // Note: convert it to YYYY-MM-DD + case DBaseField::Date: + { + QString str; + Q_UINT8 ch; + for( unsigned j=0; jlength; j++ ) + { m_stream >> ch; str += QChar(ch); } + str.insert( 6, '-' ); + str.insert( 4, '-' ); + result.append( str ); + } break; + + // Unknown/Unimplemented + case DBaseField::Unknown: + case DBaseField::Memo: + default: + result.append( "" ); // unknown + break; + } + + return result; +} + +void DBase::close() +{ + if( m_file.isOpen() ) m_file.close(); +} diff --git a/filters/kspread/dbase/dbase.h b/filters/kspread/dbase/dbase.h new file mode 100644 index 00000000..022d2ba1 --- /dev/null +++ b/filters/kspread/dbase/dbase.h @@ -0,0 +1,67 @@ +/* This file is part of the KDE project + Copyright (C) 2002 by Thomas Franke and Andreas Pietzowski + 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. +*/ + +#ifndef DBASE_H +#define DBASE_H + +#include +#include +#include +#include +#include + +class DBaseField +{ + public: + QString name; + enum { Unknown, Character, Date, Numeric, Logical, Memo } type; + unsigned length; + unsigned decimals; +}; + +class DBase +{ + + public: + DBase(); + ~DBase(); + + QPtrList fields; + + bool load( const QString& filename ); + QStringList readRecord( unsigned recno ); + void close(); + + unsigned recordCount(){ return m_recordCount; } + int version(){ return m_version; } + QDate lastUpdate(){ return m_lastUpdate; } + + private: + + QFile m_file; + QDataStream m_stream; + int m_version; + QDate m_lastUpdate; + unsigned m_recordCount; + unsigned m_headerLength; + unsigned m_recordLength; +}; + +#endif diff --git a/filters/kspread/dbase/dbaseimport.cc b/filters/kspread/dbase/dbaseimport.cc new file mode 100644 index 00000000..1c167cd0 --- /dev/null +++ b/filters/kspread/dbase/dbaseimport.cc @@ -0,0 +1,181 @@ +/* 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 ( QObject*, const char*, const QStringList& ) + : KoFilter() +{ +} + +KoFilter::ConversionStatus DBaseImport::convert( const QCString& from, const QCString& to ) +{ + if (to != "application/x-kspread" || from != "application/x-dbase") + return KoFilter::NotImplemented; + + QString 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; + } + + QString 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 + QFont font = KoGlobal::defaultFont(); + + // define columns + QFontMetrics 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 ) + { + QCString 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 ) + { + QCString cstring = documentInfo.utf8(); + cstring.prepend( "\n" ); + + out->writeBlock( (const char*) cstring, cstring.length() ); + } + + return KoFilter::OK; +} diff --git a/filters/kspread/dbase/dbaseimport.h b/filters/kspread/dbase/dbaseimport.h new file mode 100644 index 00000000..b51a7138 --- /dev/null +++ b/filters/kspread/dbase/dbaseimport.h @@ -0,0 +1,38 @@ +/* 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. +*/ + +#ifndef __DBASEIMPORT_H +#define __DBASEIMPORT_H + +#include +#include + +class DBaseImport : public KoFilter { + + Q_OBJECT + +public: + + DBaseImport ( QObject *parent, const char* name, const QStringList& ); + virtual ~DBaseImport() {} + + virtual KoFilter::ConversionStatus convert( const QCString& from, const QCString& to ); +}; + +#endif // __DBASEIMPORT_H diff --git a/filters/kspread/dbase/kspread_dbase_import.desktop b/filters/kspread/dbase/kspread_dbase_import.desktop new file mode 100644 index 00000000..610edd2f --- /dev/null +++ b/filters/kspread/dbase/kspread_dbase_import.desktop @@ -0,0 +1,65 @@ +[Desktop Entry] +Type=Service +Name=KSpread dBASE Import Filter +Name[bg]=Филтър за импортиране от dBASE в KSpread +Name[br]=Sil enporzh dBASE evit KSpread +Name[ca]=Filtre d'importació dBASE per a KSpread +Name[cs]=Importní filtr dBASE pro KSpread +Name[cy]=Hidlen Fewnforio dBASE Kspread +Name[da]=KSpread dBASE-importfilter +Name[de]=KSpread dBASE-Importfilter +Name[el]=Φίλτρο εισαγωγής dBASE του KSpread +Name[eo]=dBASE-importfiltrilo por KSpread +Name[es]=Filtro de importación de dBase para KSpread +Name[et]=KSpreadi dBASE'i impordifilter +Name[eu]=KSpread-en dBASE inportaziorako iragazkia +Name[fa]=پالایۀ واردات KSpread dBASE +Name[fi]=KSpread dBASE tuontisuodin +Name[fr]=Filtre d'importation dBASE de Kspread +Name[fy]=KSpread dBASE Ymportfilter +Name[ga]=Scagaire Iompórtála dBASE le haghaidh KSpread +Name[gl]=Filtro de Importación de dBASE para KSpread +Name[he]=מסנן ייבוא מ־dBASE ל־KSpread +Name[hi]=के-स्प्रेड डीबेस आयात छननी +Name[hr]=KSpread dBASE filtar uvoza +Name[hu]=KSpread dBASE importszűrő +Name[is]=KSpread dBASE innflutningssía +Name[it]=Filtro di importazione dBASE per KSpread +Name[ja]=KSpread dBASE インポートフィルタ +Name[km]=តម្រង​នាំចូល dBASE សម្រាប់ KSpread +Name[lo]= ຕົວຕອງການນຳເຂົ້າ dBase ຂອງກະດາດຄຳນວນ K +Name[lt]=KSpread dBASE importavimo filtras +Name[lv]=KSpread dBASE importa filtrs +Name[ms]=Penapis Import KSpread dBASE +Name[mt]=Filtru għall-importazzjoni ta' dBase ġo KSpread +Name[nb]=dBASE-importfilter for KSpread +Name[nds]=dBASE-Importfilter för KSpread +Name[ne]=केडीई स्प्रिेड डिबेस आयात फिल्टर +Name[nl]=KSpread dBASE Importfilter +Name[nn]=dBASE-importfilter for KSpread +Name[pl]=Filtr importu formatu dBASE do KSpread +Name[pt]=Filtro de Importação de dBase para o KSpread +Name[pt_BR]=Filtro de importação KSpread - dBASE +Name[ru]=Фильтр импорта файлов dBASE в KSpread +Name[se]=KSpread:a dBASE-sisafievrridansilli +Name[sk]=dBase filter pre import do KSpread +Name[sl]=Uvozni filter dBASE za KSpread +Name[sr]=KSpread-ов филтер за увоз из dBASE-а +Name[sr@Latn]=KSpread-ov filter za uvoz iz dBASE-a +Name[sv]=Kspread dBASE-importfilter +Name[ta]=Kspread dbase இறக்குமதி வடிகட்டி +Name[tg]=Филтри Воридоти KSpread dBASE +Name[th]=ตัวกรองการนำเข้า dBase ของกระดาษคำนวณ K +Name[tr]=KSpread dBASE Alma Filtresi +Name[uk]=Фільтр імпорту dBASE для KSpread +Name[uz]=KSpread dBASE import filteri +Name[uz@cyrillic]=KSpread dBASE импорт филтери +Name[wa]=Passete dBASE d' intrêye po KSpread +Name[xh]=Isihluzi Sokurhweba se KSpread dBASE +Name[zh_CN]=KSpread dBASE 导入过滤器 +Name[zh_TW]=KSpread dBASE 匯入過濾程式 +X-KDE-Export=application/x-kspread +X-KDE-Import=application/x-dbase +X-KDE-Weight=1 +X-KDE-Library=libdbaseimport +ServiceTypes=KOfficeFilter diff --git a/filters/kspread/dbase/status.html b/filters/kspread/dbase/status.html new file mode 100644 index 00000000..561cf26e --- /dev/null +++ b/filters/kspread/dbase/status.html @@ -0,0 +1,164 @@ + + + + + KOffice filters status: dBASE + + +  + +
+
+

+ KOffice filters status:   dBASE +

+
+ +
+ + + Import | + Export + + +


+
+ +Up +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ Import dBASE for KSpread
+
+
+
Last update27 Mar 2002
FeaturesCan import dBASE document
+ Only support dBASE 3
Todo + Support for Memo field +
History-
Authors + Ariya Hidayat +
Links + http://community.borland.com/article/0,1410,15838,00.html
+ dBASE DBF file format
+ XBase +file format description
+ dbflib: another xbase library
+
Progress report -
+
+
+Up + +


+ +
+


+ + +
+ +
+ +Up +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
Export KSpread to dBASE

+
+
Last update?
Features?
Todo?
History-
Authors + Ariya Hidayat +
Links-
Progress report ---
+
+
+Up + + + diff --git a/filters/kspread/dbase/test/birth.dbf b/filters/kspread/dbase/test/birth.dbf new file mode 100755 index 00000000..f836c7a4 Binary files /dev/null and b/filters/kspread/dbase/test/birth.dbf differ diff --git a/filters/kspread/dbase/test/browser.dbf b/filters/kspread/dbase/test/browser.dbf new file mode 100644 index 00000000..38aab826 Binary files /dev/null and b/filters/kspread/dbase/test/browser.dbf differ diff --git a/filters/kspread/dbase/test/stability.dbf b/filters/kspread/dbase/test/stability.dbf new file mode 100755 index 00000000..d4d3554d Binary files /dev/null and b/filters/kspread/dbase/test/stability.dbf differ -- cgit v1.2.1