insilmaril@0: #include "exports.h" insilmaril@171: #include "file.h" insilmaril@171: #include "linkablemapobj.h" insilmaril@171: #include "misc.h" insilmaril@171: #include "texteditor.h" insilmaril@171: #include "mainwindow.h" insilmaril@0: insilmaril@171: extern Main *mainWindow; insilmaril@131: insilmaril@171: ExportBase::ExportBase() insilmaril@0: { insilmaril@0: indentPerDepth=" "; insilmaril@0: } insilmaril@0: insilmaril@171: void ExportBase::setPath (const QString &p) insilmaril@0: { insilmaril@0: filepath=p; insilmaril@0: } insilmaril@0: insilmaril@171: void ExportBase::setMapCenter(MapCenterObj *mc) insilmaril@0: { insilmaril@0: mapCenter=mc; insilmaril@0: } insilmaril@0: insilmaril@171: QString ExportBase::getSectionString(BranchObj *bostart) insilmaril@163: { insilmaril@163: QString r; insilmaril@163: BranchObj *bo=bostart; insilmaril@163: int depth=bo->getDepth(); insilmaril@163: while (depth>0) insilmaril@163: { insilmaril@163: r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r; insilmaril@163: bo=(BranchObj*)(bo->getParObj()); insilmaril@163: depth=bo->getDepth(); insilmaril@163: } insilmaril@163: if (r.isEmpty()) insilmaril@163: return r; insilmaril@163: else insilmaril@163: return r + " "; insilmaril@163: } insilmaril@163: insilmaril@171: void ExportBase::exportXML() insilmaril@0: { insilmaril@0: QFile file (filepath); insilmaril@0: if ( !file.open( IO_WriteOnly ) ) insilmaril@0: { insilmaril@131: // FIXME experimental, testing insilmaril@171: cout << "ExportBase::exportXML couldn't open "<first(); insilmaril@0: while (bo) insilmaril@0: { insilmaril@0: // Make indentstring insilmaril@0: for (i=0;igetDepth();i++) actIndent+= indentPerDepth; insilmaril@0: insilmaril@0: // Write heading insilmaril@0: // write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n"); insilmaril@131: if (bo->getDepth()==0) insilmaril@131: { insilmaril@131: ts << (bo->getHeading()+ "\n"); insilmaril@160: for (j=0;jgetHeading().length();j++) ts<<"="; insilmaril@131: ts << "\n"; insilmaril@131: } else if (bo->getDepth()==1) insilmaril@131: ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n"); insilmaril@131: else if (bo->getDepth()==2) insilmaril@131: ts << (actIndent + " o " + bo->getHeading()+ "\n"); insilmaril@0: else insilmaril@0: ts << (actIndent + " - " + bo->getHeading()+ "\n"); insilmaril@0: insilmaril@0: // If necessary, write note insilmaril@0: if (!bo->getNote().isEmpty()) insilmaril@0: { insilmaril@131: s =textConvertToASCII(bo->getNote()); insilmaril@131: s=s.replace ("\n","\n"+actIndent); insilmaril@131: ts << (s+"\n\n"); insilmaril@0: } insilmaril@0: insilmaril@0: bo=bo->next(); insilmaril@0: actIndent=""; insilmaril@0: } insilmaril@0: file.close(); insilmaril@0: } insilmaril@0: insilmaril@163: // Exports a map to a LaTex file. This file needs to be included or inported into a LaTex document insilmaril@163: // it will not add a preamble, or anything that makes a full LaTex document. insilmaril@171: void ExportLaTeX::exportLaTeX() insilmaril@0: { insilmaril@163: QFile file (filepath); insilmaril@163: if ( !file.open( IO_WriteOnly ) ) { insilmaril@163: // FIXME insilmaril@163: cout << "Export::exportMap couldn't open "<first(); insilmaril@163: while (bo) { insilmaril@163: if (bo->getDepth()==0); insilmaril@163: else if (bo->getDepth()==1) { insilmaril@163: ts << ("\\chapter{" + bo->getHeading()+ "}\n"); insilmaril@163: } insilmaril@163: else if (bo->getDepth()==2) { insilmaril@163: ts << ("\\section{" + bo->getHeading()+ "}\n"); insilmaril@163: } insilmaril@163: else if (bo->getDepth()==3) { insilmaril@163: ts << ("\\subsection{" + bo->getHeading()+ "}\n"); insilmaril@163: } insilmaril@163: else if (bo->getDepth()==4) { insilmaril@163: ts << ("\\subsubsection{" + bo->getHeading()+ "}\n"); insilmaril@163: } insilmaril@163: else { insilmaril@163: ts << ("\\paragraph*{" + bo->getHeading()+ "}\n"); insilmaril@163: } insilmaril@163: insilmaril@163: // If necessary, write note insilmaril@163: if (!bo->getNote().isEmpty()) { insilmaril@163: ts << (textConvertToASCII(bo->getNote())); insilmaril@163: ts << ("\n"); insilmaril@163: } insilmaril@163: insilmaril@163: bo=bo->next(); insilmaril@163: } insilmaril@163: file.close(); insilmaril@0: } insilmaril@0: insilmaril@171: ExportOO::ExportOO() insilmaril@171: { insilmaril@171: // Create tmpdir and set paths insilmaril@171: tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX")); insilmaril@171: templateDir="oo-test/suse-template/"; insilmaril@171: contentTemplateFile=templateDir+"content-template.xml"; insilmaril@171: contentFile=tmpDir.path()+"/content.xml"; insilmaril@171: pageTemplateFile=templateDir+"page-template.xml"; insilmaril@171: chapterTemplateFile=templateDir+"chapter-template.xml"; insilmaril@163: insilmaril@171: outputFile=tmpDir.currentDirPath()+"/out.odp"; insilmaril@171: insilmaril@163: // Copy template to tmpdir insilmaril@171: system ("cp -r "+templateDir+"* "+tmpDir.path()); insilmaril@171: insilmaril@163: insilmaril@163: // Read content-template insilmaril@171: if (!loadStringFromDisk (contentTemplateFile,content)) insilmaril@163: { insilmaril@171: qWarning ("Export::exportOOPresentation() Couldn't load from "+contentTemplateFile); insilmaril@163: return; insilmaril@163: } insilmaril@163: insilmaril@171: // Read page-template insilmaril@171: QString pageTemplate; insilmaril@171: if (!loadStringFromDisk (pageTemplateFile,pageTemplate)) insilmaril@171: { insilmaril@171: qWarning ("Export::exportOOPresentation() Couldn't load from "+pageTemplateFile); insilmaril@171: return; insilmaril@171: } insilmaril@171: insilmaril@171: // Read chapter-template insilmaril@171: QString chapterTemplate; insilmaril@171: if (!loadStringFromDisk (chapterTemplateFile,chapterTemplate)) insilmaril@171: { insilmaril@171: qWarning ("Export::exportOOPresentation() Couldn't load from "+chapterTemplateFile); insilmaril@171: return; insilmaril@171: } insilmaril@171: } insilmaril@163: insilmaril@171: ExportOO::~ExportOO() insilmaril@171: { insilmaril@171: // Remove tmpdir insilmaril@171: //FIXME removeDir (tmpDir); insilmaril@171: cout << "tmpDir="<getFirstBranch(); insilmaril@171: if (bo) insilmaril@171: { insilmaril@171: // Start list insilmaril@171: r+="\n"; insilmaril@171: while (bo) insilmaril@171: { insilmaril@171: r+="\n "+ insilmaril@171: bo->getHeading()+ insilmaril@171: "\n\n"; insilmaril@171: } insilmaril@171: r+="\n"; insilmaril@171: } insilmaril@171: return r; insilmaril@171: } insilmaril@163: insilmaril@171: QString ExportOO::walkPages (BranchObj *current) insilmaril@171: { insilmaril@171: //FIXME Denkfehler: mit current anfangen, nicht mit insilmaril@171: // Kind von current. Sonst erwisch ich nur jede 2. Depth insilmaril@171: // insilmaril@171: insilmaril@171: insilmaril@171: QString r; insilmaril@171: BranchObj *bo; insilmaril@171: int i=0; insilmaril@171: bo=current->getFirstBranch(); insilmaril@171: while(bo) insilmaril@171: { insilmaril@171: r+=quotemeta(bo->getHeading())+"\n"; insilmaril@171: if (bo->getFirstBranch()) insilmaril@171: r+=walkPages (bo->getFirstBranch()); insilmaril@171: i++; insilmaril@171: bo=current->getBranchNum (i); insilmaril@171: } insilmaril@171: return r; insilmaril@171: } insilmaril@171: insilmaril@171: insilmaril@171: void ExportOO::exportPresentation() insilmaril@171: { insilmaril@171: QString allPages=walkPages (mapCenter); insilmaril@171: insilmaril@171: cout << allPages<",quotemeta(mapCenter->getHeading())); insilmaril@171: content.replace ("",quotemeta(mapCenter->getAuthor())); insilmaril@171: content.replace ("",allPages); insilmaril@171: insilmaril@171: // Write modified content insilmaril@171: QFile f (contentFile); insilmaril@171: if ( !f.open( IO_WriteOnly ) ) insilmaril@171: { insilmaril@171: mainWindow->statusMessage(QString(QObject::tr("Could not write to %1")).arg(outputFile)); insilmaril@171: return; insilmaril@171: } insilmaril@171: insilmaril@171: QTextStream t( &f ); insilmaril@171: t << content; insilmaril@171: f.close(); insilmaril@171: insilmaril@171: mainWindow->statusMessage( QString( QObject::tr("Map exported as %1")).arg( outputFile)); insilmaril@171: insilmaril@163: insilmaril@163: // zip tmpdir to destination insilmaril@171: zipDir (tmpDir,outputFile); insilmaril@163: insilmaril@171: /* FIXME not needed insilmaril@171: QString onePage; insilmaril@171: QString allPages; insilmaril@171: QString heading; insilmaril@171: insilmaril@171: insilmaril@171: // Walk through chapters (mainbranches) insilmaril@171: QString s; insilmaril@171: insilmaril@171: QString list; insilmaril@171: BranchObj *bo; insilmaril@171: BranchObj *boLastPage=NULL; insilmaril@171: bo=mapCenter->first(); insilmaril@171: int depth; insilmaril@171: int lastDepth=-1; insilmaril@171: int basePageDepth=2; insilmaril@171: while (bo) insilmaril@171: { insilmaril@171: depth=bo->getDepth(); insilmaril@171: heading=quotemeta(bo->getHeading()); insilmaril@171: if (depth>1) insilmaril@171: { insilmaril@171: if (depth==basePageDepth) insilmaril@171: { insilmaril@171: // Start a new page containing a heading and a list insilmaril@171: if (boLastPage==NULL) insilmaril@171: { insilmaril@171: // Start new single page insilmaril@171: boLastPage=bo; insilmaril@171: onePage=pageTemplate; insilmaril@171: onePage.replace ("", heading); insilmaril@171: list=""; insilmaril@171: } else insilmaril@171: { insilmaril@171: // Finish last page, start new one insilmaril@171: onePage.replace ("", list); insilmaril@171: boLastPage=bo; insilmaril@171: allPages+=onePage; insilmaril@171: onePage=pageTemplate; insilmaril@171: onePage.replace ("", heading); insilmaril@171: list=""; insilmaril@171: } insilmaril@171: } else insilmaril@171: { insilmaril@171: if (lastDepth==depth-1) insilmaril@171: // entering deeper branches, new list insilmaril@171: list+=""; insilmaril@171: // Just add heading to list on current page insilmaril@171: list+=""+heading+"\n"; insilmaril@171: if (lastDepth==depth+1) insilmaril@171: // returning from deeper branches, finish list insilmaril@171: list+=""; insilmaril@171: } insilmaril@171: } insilmaril@171: lastDepth=depth; insilmaril@171: bo=bo->next(); insilmaril@171: } insilmaril@171: */ insilmaril@163: } insilmaril@163: