22#include <tdemessagebox.h>
23#include <kgenericfactory.h>
24#include <KoFilterChain.h>
26#include <kspread_doc.h>
27#include <kspread_sheet.h>
28#include <kspread_cell.h>
29#include <kspread_map.h>
31#include <qproimport.h>
33#include <qproformula.h>
34#include <qpro/stream.h>
35#include <qpro/record_factory.h>
38using namespace KSpread;
40typedef KGenericFactory<QpImport, KoFilter> TQPROImportFactory;
41K_EXPORT_COMPONENT_FACTORY( libqproimport, TQPROImportFactory(
"kofficefilters" ) )
45QpTableList::QpTableList()
47 for(
int lIdx=0; lIdx<cNameCnt; ++lIdx )
53QpTableList::~QpTableList()
60QpTableList::table(
unsigned pIdx, Sheet* pTable)
64 cTable[pIdx] = pTable;
69QpTableList::table(
unsigned pIdx)
71 return (pIdx < cNameCnt ? cTable[pIdx] : 0);
77QpImport::QpImport( KoFilter*,
const char*,
const TQStringList& )
84QpImport::InitTableName(
int pIdx, TQString& pResult)
88 pResult = (char)(
'A' + pIdx);
92 pResult = (char)(
'A' -1 + pIdx / 26);
93 pResult += (char)(
'A' + pIdx % 26);
97KoFilter::ConversionStatus QpImport::convert(
const TQCString& from,
const TQCString& to )
101 KoDocument* document = m_chain->outputDocument();
103 return KoFilter::StupidError;
105 kdDebug(30523) <<
"here we go... " << document->className() << endl;
107 if( !::tqt_cast<const KSpread::Doc *>( document ) )
109 kdWarning(30501) <<
"document isn't a KSpread::Doc but a " << document->className() << endl;
110 return KoFilter::NotImplemented;
112 if(from!=
"application/x-quattropro" || to!=
"application/x-kspread")
114 kdWarning(30501) <<
"Invalid mimetypes " << from <<
" " << to << endl;
115 return KoFilter::NotImplemented;
118 kdDebug(30523) <<
"...still here..." << endl;
121 Doc *ksdoc=(Doc*)document;
123 if(ksdoc->mimeType()!=
"application/x-kspread")
125 kdWarning(30501) <<
"Invalid document mimetype " << ksdoc->mimeType() << endl;
126 return KoFilter::NotImplemented;
129 QpIStream lIn( TQFile::encodeName(m_chain->inputFile()) );
133 KMessageBox::sorry( 0L, i18n(
"QPRO filter cannot open input file - please report.") );
134 return KoFilter::FileNotFound;
141 emit sigProgress(value);
143 QpRecFactory lFactory(lIn);
144 QpTableList lTableNames;
145 TQP_UINT8 lPageIdx = 0;
148 QpRecBop* lRecBop = 0;
149 QpRecIntegerCell* lRecInt = 0;
150 QpRecFloatingPointCell* lRecFloat = 0;
151 QpRecFormulaCell* lRecFormula = 0;
152 QpRecLabelCell* lRecLabel = 0;
153 QpRecPageName* lRecPageName = 0;
158 lRec = lFactory.nextRecord();
160 switch( lRec->type() )
163 lRecBop = (QpRecBop*)lRec;
164 lPageIdx = lRecBop->pageIndex();
167 table=lTableNames.table(lPageIdx);
171 table=ksdoc->map()->addNewSheet();
173 table->setSheetName( lTableNames.name(lPageIdx)
176 lTableNames.table(lPageIdx, table);
181 lRecInt = (QpRecIntegerCell*)lRec;
182 field.setNum( lRecInt->integer() );
184 table->setText( lRecInt->row()+1, ((
unsigned)lRecInt->column())+1, field,
false );
188 lRecFormula = (QpRecFormulaCell*)lRec;
190 Formula lAnswer(*lRecFormula, lTableNames);
192 char* lFormula = lAnswer.formula();
200 for(
unsigned lIdx=0; lIdx<lTableNames.cNameCnt; ++lIdx)
202 if(lTableNames.allocated(lIdx) && (lTableNames.table(lIdx) == 0) )
207 Sheet* lNewTable=ksdoc->map()->addNewSheet();
210 lNewTable->setSheetName( lTableNames.name(lIdx)
213 lTableNames.table(lIdx, lNewTable);
217 table->setText( lRecFormula->row()+1, lRecFormula->column()+1, field,
false );
220 case QpFloatingPointCell:
221 lRecFloat = (QpRecFloatingPointCell*)lRec;
222 field.setNum( lRecFloat->value() );
223 table->setText( lRecFloat->row()+1, lRecFloat->column()+1, field,
false );
227 lRecLabel = (QpRecLabelCell*)lRec;
229 field += lRecLabel->label();
230 table->setText( lRecLabel->row()+1, lRecLabel->column()+1, field,
false );
234 lRecPageName = (QpRecPageName*)lRec;
236 if( lTableNames.allocated(lPageIdx) && lTableNames.table(lPageIdx) )
238 lTableNames.table(lPageIdx)->setSheetName( lRecPageName->pageName()
241 lTableNames.name(lPageIdx, lRecPageName->pageName());
246 KMessageBox::sorry( 0L, i18n(
"Unable to open password protected files.\n"
247 "The password algorithm has not been published")
249 return KoFilter::NotImplemented;
256 emit sigProgress(100);
260 return KoFilter::StupidError;
263#include <qproimport.moc>