filters

KSpreadLeader.cc

00001 /*
00002 This file is part of the KDE project
00003 Copyright (C) 2002 Fred Malabre <fmalabre@yahoo.com>
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Library General Public
00007 License as published by the Free Software Foundation; either
00008 version 2 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Library General Public License for more details.
00014 
00015 You should have received a copy of the GNU Library General Public License
00016 along with this library; see the file COPYING.LIB.  If not, write to
00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "KSpreadLeader.h"
00022 
00023 using namespace KSpread;
00024 
00025 Leader::Leader(KoFilterChain *filterChain) {
00026     m_worker = NULL;
00027     m_filterChain = filterChain;
00028 }
00029 
00030 
00031 Leader::Leader(KoFilterChain *filterChain, KSpreadBaseWorker *newWorker) {
00032     m_worker = newWorker;
00033     m_filterChain = filterChain;
00034 }
00035 
00036 
00037 Leader::~Leader() {
00038 }
00039 
00040 
00041 KSpreadBaseWorker *Leader::getWorker() const {
00042     return m_worker;
00043 }
00044 
00045 
00046 void Leader::setWorker(KSpreadBaseWorker *newWorker) {
00047     m_worker = newWorker;
00048 }
00049 
00050 
00051 KoFilter::ConversionStatus Leader::convert() {
00052     KoFilter::ConversionStatus status;
00053 
00054     // Validate the filter chain and the worker
00055     if (!m_filterChain) {
00056         kdWarning(30508) << "koFilterChain is NULL!" << endl;
00057         return KoFilter::StupidError;
00058     }
00059     if (!m_worker) {
00060         kdWarning(30508) << "the KSpreadWorker is NULL!" << endl;
00061         return KoFilter::StupidError;
00062     }
00063 
00064     // Gather data about the filter itself
00065     KSpreadFilterProperty docProperty;
00066     docProperty["outputfile"] = m_filterChain->outputFile();
00067     status = m_worker->startDocument(docProperty);
00068     if (status != KoFilter::OK)
00069         return status;
00070 
00071     // Get the document in memory
00072     KSpreadDoc *document = (KSpreadDoc *) m_filterChain->inputDocument();
00073     if (!document) {
00074         kdWarning(30508) << "the KSpreadDoc is NULL!" << endl;
00075         return KoFilter::StupidError;
00076     }
00077     if ( !::qt_cast<const KSpread::Doc *>( document ) ) {
00078         kdWarning(30508) << "the document is not a KSpreadDoc!" << endl;
00079         return KoFilter::StupidError;
00080     }
00081     if (document->mimeType() != "application/x-kspread") {
00082         kdWarning(30508) << "the mime type document is not application/x-kspread!" << endl;
00083         return KoFilter::StupidError;
00084     }
00085     KoDocumentInfo *info = document->documentInfo();
00086     if (!document) {
00087         kdWarning(30508) << "the KoDocumentInfo is NULL!" << endl;
00088         return KoFilter::StupidError;
00089     }
00090 
00091     // Gather data about the document info
00092     status = doInfo(info);
00093     if (status != KoFilter::OK)
00094         return status;
00095 
00096     // Gather data about the spread book
00097     status = doSpreadBook(document);
00098     if (status != KoFilter::OK)
00099         return status;
00100 
00101     // Gather data about the spread sheet
00102     KSpreadSheet *spreadSheet = document->map()->firstTable();
00103     while (spreadSheet != 0) {
00104         status = doSpreadSheet(spreadSheet);
00105         if (status != KoFilter::OK)
00106             return status;
00107 
00108         // Gather data about the cell
00109         for (int row = 1; row <= m_maxCellRow; ++row) {
00110             for (int column = 1; column <= m_maxCellColumn; ++column) {
00111                 Cell*spreadCell = spreadSheet->cellAt(column, row);
00112                 status = doSpreadCell(spreadCell, column, row);
00113                 if (status != KoFilter::OK)
00114                     return status;
00115             }
00116         }
00117 
00118         spreadSheet = document->map()->nextTable();
00119     }
00120 
00121     return status;
00122 }
00123 
00124 
00125 KoFilter::ConversionStatus Leader::doInfo(KoDocumentInfo *info) {
00126     KoFilter::ConversionStatus status;
00127 
00128 #if 0 // this was never used, it's been removed now
00129     // Gather data about the document log
00130     KSpreadFilterProperty docInfoLogProperty;
00131     KoDocumentInfoLog *infoLog = (KoDocumentInfoLog *) info->page("log");
00132     docInfoLogProperty["oldlog"] = infoLog->oldLog();
00133     docInfoLogProperty["newlog"] = infoLog->newLog();
00134     status = m_worker->startInfoLog(docInfoLogProperty);
00135     if (status != KoFilter::OK)
00136         return status;
00137 #endif
00138 
00139     // Gather data about the document author
00140     KSpreadFilterProperty docInfoAuthorProperty;
00141     KoDocumentInfoAuthor *infoAuthor = (KoDocumentInfoAuthor *) info->page("author");
00142     docInfoAuthorProperty["fullname"] = infoAuthor->fullName();
00143     docInfoAuthorProperty["initial"] = infoAuthor->initial();
00144     docInfoAuthorProperty["title"] = infoAuthor->title();
00145     docInfoAuthorProperty["company"] = infoAuthor->company();
00146     docInfoAuthorProperty["email"] = infoAuthor->email();
00147     docInfoAuthorProperty["telephone"] = infoAuthor->telephone();
00148     docInfoAuthorProperty["fax"] = infoAuthor->fax();
00149     docInfoAuthorProperty["country"] = infoAuthor->country();
00150     docInfoAuthorProperty["postalcode"] = infoAuthor->postalCode();
00151     docInfoAuthorProperty["city"] = infoAuthor->city();
00152     docInfoAuthorProperty["street"] = infoAuthor->street();
00153     status = m_worker->startInfoAuthor(docInfoAuthorProperty);
00154     if (status != KoFilter::OK)
00155         return status;
00156 
00157     // Gather data about the document about
00158     KSpreadFilterProperty docInfoAboutProperty;
00159     KoDocumentInfoAbout *infoAbout = (KoDocumentInfoAbout *) info->page("about");
00160     docInfoAboutProperty["title"] = infoAbout->title();
00161     docInfoAboutProperty["author"] = infoAbout->abstract();
00162     status = m_worker->startInfoAbout(docInfoAboutProperty);
00163     return status;
00164 }
00165 
00166 
00167 KoFilter::ConversionStatus Leader::doSpreadBook(KSpreadDoc *document) {
00168     KSpreadFilterProperty docSpreadBookProperty;
00169     docSpreadBookProperty["spreadsheetcount"] = QString::number(document->map()->count());
00170     docSpreadBookProperty["decimalsymbol"] = document->locale()->decimalSymbol();
00171     docSpreadBookProperty["thousandsseparator"] = document->locale()->thousandsSeparator();
00172     docSpreadBookProperty["currencysymbol"] = document->locale()->currencySymbol();
00173     docSpreadBookProperty["monetarydecimalsymbol"] = document->locale()->monetaryDecimalSymbol();
00174     docSpreadBookProperty["monetarythousandsseparator"] = document->locale()->monetaryThousandsSeparator();
00175     docSpreadBookProperty["positivesign"] = document->locale()->positiveSign();
00176     docSpreadBookProperty["negativesign"] = document->locale()->negativeSign();
00177     docSpreadBookProperty["fracdigits"] = QString::number(document->locale()->fracDigits());
00178     docSpreadBookProperty["positiveprefixcurrencysymbol"] = (document->locale()->positivePrefixCurrencySymbol()==0?"false":"true");
00179     docSpreadBookProperty["negativeprefixcurrencysymbol"] = (document->locale()->negativePrefixCurrencySymbol()==0?"false":"true");
00180     docSpreadBookProperty["use12clock"] = (document->locale()->use12Clock()==0?"false":"true");
00181     docSpreadBookProperty["weekstartsmonday"] = (document->locale()->weekStartsMonday()==0?"false":"true");
00182     docSpreadBookProperty["weekstartday"] = QString::number(document->locale()->weekStartDay());
00183     docSpreadBookProperty["language"] = document->locale()->language();
00184     docSpreadBookProperty["country"] = document->locale()->country();
00185     docSpreadBookProperty["encoding"] = document->locale()->encoding();
00186     docSpreadBookProperty["dateformat"] = document->locale()->dateFormat();
00187     docSpreadBookProperty["dateformatshort"] = document->locale()->dateFormatShort();
00188     docSpreadBookProperty["timeformat"] = document->locale()->timeFormat();
00189     docSpreadBookProperty["defaultlanguage"] = KLocale::defaultLanguage();
00190     docSpreadBookProperty["defaultcountry"] = KLocale::defaultCountry();
00191     docSpreadBookProperty["defaultgridpencolorname"] = document->defaultGridPen().color().name();
00192     docSpreadBookProperty["defaultgridpencolorred"] = QString::number(document->defaultGridPen().color().red());
00193     docSpreadBookProperty["defaultgridpencolorgreen"] = QString::number(document->defaultGridPen().color().green());
00194     docSpreadBookProperty["defaultgridpencolorblue"] = QString::number(document->defaultGridPen().color().blue());
00195     docSpreadBookProperty["defaultgridpenwidth"] = QString::number(document->defaultGridPen().width());
00196     docSpreadBookProperty["showverticalscrollbar"] = (document->getShowVerticalScrollBar()==0?"false":"true");
00197     docSpreadBookProperty["showhorizontalscrollbar"] = (document->getShowHorizontalScrollBar()==0?"false":"true");
00198     docSpreadBookProperty["showcolheader"] = (document->getShowColHeader()==0?"false":"true");
00199     docSpreadBookProperty["showrowheader"] = (document->getShowRowHeader()==0?"false":"true");
00200     docSpreadBookProperty["indentvalue"] = QString::number(document->getIndentValue());
00201     docSpreadBookProperty["movetovalue"] = QString::number(document->getMoveToValue());
00202     docSpreadBookProperty["showmessageerror"] = (document->getShowMessageError()==0?"false":"true");
00203     docSpreadBookProperty["showtabbar"] = (document->getShowTabBar()==0?"false":"true");
00204     docSpreadBookProperty["pagebordercolorname"] = document->pageBorderColor().name();
00205     docSpreadBookProperty["pagebordercolorred"] = QString::number(document->pageBorderColor().red());
00206     docSpreadBookProperty["pagebordercolorgreen"] = QString::number(document->pageBorderColor().green());
00207     docSpreadBookProperty["pagebordercolorblue"] = QString::number(document->pageBorderColor().blue());
00208     docSpreadBookProperty["showcommentindicator"] = (document->getShowCommentIndicator()==0?"false":"true");
00209     docSpreadBookProperty["showformulabar"] = (document->getShowFormulaBar()==0?"false":"true");
00210     docSpreadBookProperty["dontcheckupperword"] = (document->dontCheckUpperWord()==0?"false":"true");
00211     docSpreadBookProperty["dontchecktitlecase"] = (document->dontCheckTitleCase()==0?"false":"true");
00212     docSpreadBookProperty["showstatusbar"] = (document->getShowStatusBar()==0?"false":"true");
00213     docSpreadBookProperty["unitname"] = document->getUnitName();
00214     docSpreadBookProperty["syntaxversion"] = QString::number(document->syntaxVersion());
00215     return m_worker->startSpreadBook(docSpreadBookProperty);
00216 }
00217 
00218 
00219 KoFilter::ConversionStatus Leader::doSpreadSheet(KSpreadSheet *spreadSheet) {
00220     KSpreadFilterProperty docSpreadSheetProperty;
00221     docSpreadSheetProperty["name"] = spreadSheet->tableName();
00222     docSpreadSheetProperty["sizemaxx"] = QString::number(spreadSheet->sizeMaxX());
00223     docSpreadSheetProperty["sizemaxy"] = QString::number(spreadSheet->sizeMaxY());
00224     docSpreadSheetProperty["showgrid"] = (spreadSheet->getShowGrid()==0?"false":"true");
00225     docSpreadSheetProperty["showformula"] = (spreadSheet->getShowFormula()==0?"false":"true");
00226     docSpreadSheetProperty["showformulaindicator"] = (spreadSheet->getShowFormulaIndicator()==0?"false":"true");
00227     docSpreadSheetProperty["lcmode"] = (spreadSheet->getLcMode()==0?"false":"true");
00228     docSpreadSheetProperty["autocalc"] = (spreadSheet->getAutoCalc()==0?"false":"true");
00229     docSpreadSheetProperty["showcolumnnumber"] = (spreadSheet->getShowColumnNumber()==0?"false":"true");
00230     docSpreadSheetProperty["hidezero"] = (spreadSheet->getHideZero()==0?"false":"true");
00231     docSpreadSheetProperty["firstletterupper"] = (spreadSheet->getFirstLetterUpper()==0?"false":"true");
00232     docSpreadSheetProperty["ishidden"] = (spreadSheet->isHidden()==0?"false":"true");
00233     docSpreadSheetProperty["showpageborders"] = (spreadSheet->isShowPageBorders()==0?"false":"true");
00234     docSpreadSheetProperty["printablewidth"] = QString::number(spreadSheet->printableWidth());
00235     docSpreadSheetProperty["printableheight"] = QString::number(spreadSheet->printableHeight());
00236     docSpreadSheetProperty["paperwidth"] = QString::number(spreadSheet->paperWidth());
00237     docSpreadSheetProperty["paperheight"] = QString::number(spreadSheet->paperHeight());
00238     docSpreadSheetProperty["leftborder"] = QString::number(spreadSheet->leftBorder());
00239     docSpreadSheetProperty["rightborder"] = QString::number(spreadSheet->rightBorder());
00240     docSpreadSheetProperty["topborder"] = QString::number(spreadSheet->topBorder());
00241     docSpreadSheetProperty["bottomborder"] = QString::number(spreadSheet->bottomBorder());
00242     docSpreadSheetProperty["headleft"] = spreadSheet->headLeft();
00243     docSpreadSheetProperty["headmid"] = spreadSheet->headMid();
00244     docSpreadSheetProperty["headright"] = spreadSheet->headRight();
00245     docSpreadSheetProperty["footleft"] = spreadSheet->footLeft();
00246     docSpreadSheetProperty["footmid"] = spreadSheet->footMid();
00247     docSpreadSheetProperty["footright"] = spreadSheet->footRight();
00248     docSpreadSheetProperty["orientation"] = spreadSheet->orientationString();
00249     docSpreadSheetProperty["paperformat"] = spreadSheet->paperFormatString();
00250     docSpreadSheetProperty["printgrid"] = (spreadSheet->getPrintGrid()==0?"false":"true");
00251     docSpreadSheetProperty["printcomment"] = (spreadSheet->getPrintCommentIndicator()==0?"false":"true");
00252     docSpreadSheetProperty["printformula"] = (spreadSheet->getPrintFormulaIndicator()==0?"false":"true");
00253     updateMaxCells(spreadSheet);
00254     docSpreadSheetProperty["maxcellrow"] = QString::number(m_maxCellRow);
00255     docSpreadSheetProperty["maxcellcolumn"] = QString::number(m_maxCellColumn);
00256     return m_worker->startSpreadSheet(docSpreadSheetProperty);
00257 }
00258 
00259 
00260 KoFilter::ConversionStatus Leader::doSpreadCell(Cell*spreadCell, int column, int row) {
00261     KSpreadFilterProperty docSpreadCellProperty;
00262     docSpreadCellProperty["column"] = QString::number(column);
00263     docSpreadCellProperty["row"] = QString::number(row);
00264     docSpreadCellProperty["width"] = QString::number(spreadCell->dblWidth());
00265     docSpreadCellProperty["height"] = QString::number(spreadCell->dblHeight());
00266     docSpreadCellProperty["empty"] = (spreadCell->isEmpty()==0?"false":"true");
00267     if (!spreadCell->isEmpty()) {
00268         docSpreadCellProperty["text"] = spreadCell->text();
00269         docSpreadCellProperty["strouttext"] = spreadCell->strOutText();
00270         docSpreadCellProperty["action"] = spreadCell->action();
00271         docSpreadCellProperty["date"] = (spreadCell->isDate()==0?"false":"true");
00272         docSpreadCellProperty["time"] = (spreadCell->isTime()==0?"false":"true");
00273         docSpreadCellProperty["textwidth"] = QString::number(spreadCell->textWidth());
00274         docSpreadCellProperty["textheight"] = QString::number(spreadCell->textHeight());
00275         docSpreadCellProperty["forceextracells"] = (spreadCell->isForceExtraCells()==0?"false":"true");
00276         docSpreadCellProperty["mergedxcells"] = QString::number(spreadCell->mergedXCells());
00277         docSpreadCellProperty["mergedycells"] = QString::number(spreadCell->mergedYCells());
00278         docSpreadCellProperty["extraxcells"] = QString::number(spreadCell->extraXCells());
00279         docSpreadCellProperty["extraycells"] = QString::number(spreadCell->extraYCells());
00280         docSpreadCellProperty["extrawidth"] = QString::number(spreadCell->extraWidth());
00281         docSpreadCellProperty["extraheight"] = QString::number(spreadCell->extraHeight());
00282         docSpreadCellProperty["formula"] = (spreadCell->isFormula()==0?"false":"true");
00283         docSpreadCellProperty["haserror"] = (spreadCell->hasError()==0?"false":"true");
00284         docSpreadCellProperty["alignx"] = QString::number(spreadCell->defineAlignX());
00285         docSpreadCellProperty["name"] = spreadCell->name();
00286         docSpreadCellProperty["fullname"] = spreadCell->fullName();
00287         docSpreadCellProperty["content"] = QString::number(spreadCell->content());
00288         docSpreadCellProperty["style"] = QString::number(spreadCell->style());
00289         docSpreadCellProperty["valuedate"] = spreadCell->valueDate().toString();
00290         docSpreadCellProperty["valuetime"] = spreadCell->valueTime().toString();
00291         docSpreadCellProperty["leftborderwidth"] = QString::number(spreadCell->leftBorderPen(column, row).width());
00292         docSpreadCellProperty["leftbordercolorname"] = spreadCell->leftBorderPen(column, row).color().name();
00293         docSpreadCellProperty["leftbordercolorred"] = QString::number(spreadCell->leftBorderPen(column, row).color().red());
00294         docSpreadCellProperty["leftbordercolorgreen"] = QString::number(spreadCell->leftBorderPen(column, row).color().green());
00295         docSpreadCellProperty["leftbordercolorblue"] = QString::number(spreadCell->leftBorderPen(column, row).color().blue());
00296         docSpreadCellProperty["topborderwidth"] = QString::number(spreadCell->topBorderPen(column, row).width());
00297         docSpreadCellProperty["topbordercolorname"] = spreadCell->topBorderPen(column, row).color().name();
00298         docSpreadCellProperty["topbordercolorred"] = QString::number(spreadCell->topBorderPen(column, row).color().red());
00299         docSpreadCellProperty["topbordercolorgreen"] = QString::number(spreadCell->topBorderPen(column, row).color().green());
00300         docSpreadCellProperty["topbordercolorblue"] = QString::number(spreadCell->topBorderPen(column, row).color().blue());
00301         docSpreadCellProperty["rightborderwidth"] = QString::number(spreadCell->rightBorderPen(column, row).width());
00302         docSpreadCellProperty["rightbordercolorname"] = spreadCell->rightBorderPen(column, row).color().name();
00303         docSpreadCellProperty["rightbordercolorred"] = QString::number(spreadCell->rightBorderPen(column, row).color().red());
00304         docSpreadCellProperty["rightbordercolorgreen"] = QString::number(spreadCell->rightBorderPen(column, row).color().green());
00305         docSpreadCellProperty["rightbordercolorblue"] = QString::number(spreadCell->rightBorderPen(column, row).color().blue());
00306         docSpreadCellProperty["bottomborderwidth"] = QString::number(spreadCell->bottomBorderPen(column, row).width());
00307         docSpreadCellProperty["bottombordercolorname"] = spreadCell->bottomBorderPen(column, row).color().name();
00308         docSpreadCellProperty["bottombordercolorred"] = QString::number(spreadCell->bottomBorderPen(column, row).color().red());
00309         docSpreadCellProperty["bottombordercolorgreen"] = QString::number(spreadCell->bottomBorderPen(column, row).color().green());
00310         docSpreadCellProperty["bottombordercolorblue"] = QString::number(spreadCell->bottomBorderPen(column, row).color().blue());
00311         docSpreadCellProperty["bgcolorname"] = spreadCell->bgColor(column, row).name();
00312         docSpreadCellProperty["bgcolorred"] = QString::number(spreadCell->bgColor(column, row).red());
00313         docSpreadCellProperty["bgcolorgreen"] = QString::number(spreadCell->bgColor(column, row).green());
00314         docSpreadCellProperty["bgcolorblue"] = QString::number(spreadCell->bgColor(column, row).blue());
00315         docSpreadCellProperty["bgbrushstyle"] = QString::number(spreadCell->backGroundBrush(column, row).style());
00316         docSpreadCellProperty["valueempty"] = (spreadCell->value().isEmpty()==0?"false":"true");
00317         docSpreadCellProperty["valueboolean"] = (spreadCell->value().isBoolean()==0?"false":"true");
00318         docSpreadCellProperty["valueinteger"] = (spreadCell->value().isInteger()==0?"false":"true");
00319         docSpreadCellProperty["valuefloat"] = (spreadCell->value().isFloat()==0?"false":"true");
00320         docSpreadCellProperty["valuenumber"] = (spreadCell->value().isNumber()==0?"false":"true");
00321         docSpreadCellProperty["valuestring"] = (spreadCell->value().isString()==0?"false":"true");
00322         docSpreadCellProperty["valueerror"] = (spreadCell->value().isError()==0?"false":"true");
00323         docSpreadCellProperty["valueasboolean"] = (spreadCell->value().asBoolean()==0?"false":"true");
00324         docSpreadCellProperty["valueasinteger"] = QString::number(spreadCell->value().asInteger());
00325         docSpreadCellProperty["valueasfloat"] = QString::number(spreadCell->value().asFloat());
00326         docSpreadCellProperty["valueasstring"] = spreadCell->value().asString();
00327         docSpreadCellProperty["valueasdatetime"] = spreadCell->value().asDateTime().toString();
00328         docSpreadCellProperty["valueaserror"] = spreadCell->value().errorMessage();
00329     }
00330     return m_worker->startSpreadCell(docSpreadCellProperty);
00331 }
00332 
00333 
00334 void Leader::updateMaxCells(KSpreadSheet *spreadSheet) {
00335     m_maxCellColumn = 0;
00336     m_maxCellRow = 0;
00337 
00338     int maxColumn = spreadSheet->maxColumn();
00339     int maxRow = spreadSheet->maxRow();
00340 
00341     // Go through all the SpreadSheet to find out the minimum rectangle of cells
00342     // Maybe we should have something which does that in the KSpreadSheet class,
00343     // it would be easy to keep track of this each time a new Cellis instanciated.
00344     for (int row = 1; row < maxRow; ++row) {
00345         bool usedColumn = FALSE;
00346         for (int column = 1; column < maxColumn; ++column) {
00347             Cell*cell = spreadSheet->cellAt(column, row);
00348             if (!cell->isDefault() && !cell->isEmpty()) {
00349                 if (column > m_maxCellColumn) {
00350                     m_maxCellColumn = column;
00351                 }
00352                 usedColumn = TRUE;
00353             }
00354         }
00355         if (usedColumn) {
00356             m_maxCellRow = row;
00357         }
00358     }
00359 }
KDE Home | KDE Accessibility Home | Description of Access Keys