# HG changeset patch # User insilmaril # Date 1138115388 0 # Node ID 97e0bd468439471e32139c317df79901c607202e # Parent 2747c4145c71ba5495c6cf7198d9b6afd7d163d3 Introduced basic export to Open Document format diff -r 2747c4145c71 -r 97e0bd468439 exports.cpp --- a/exports.cpp Tue Jan 24 15:09:48 2006 +0000 +++ b/exports.cpp Tue Jan 24 15:09:48 2006 +0000 @@ -79,7 +79,7 @@ // If necessary, write note if (!bo->getNote().isEmpty()) { - s =textConvertToASCII(bo->getNote()); + s =bo->getNoteASCII(); s=s.replace ("\n","\n"+actIndent); ts << (s+"\n\n"); } @@ -90,10 +90,13 @@ file.close(); } -// Exports a map to a LaTex file. This file needs to be included or inported into a LaTex document -// it will not add a preamble, or anything that makes a full LaTex document. void ExportLaTeX::exportLaTeX() { + // Exports a map to a LaTex file. + // This file needs to be included + // or inported into a LaTex document + // it will not add a preamble, or anything + // that makes a full LaTex document. QFile file (filepath); if ( !file.open( IO_WriteOnly ) ) { // FIXME @@ -129,7 +132,7 @@ // If necessary, write note if (!bo->getNote().isEmpty()) { - ts << (textConvertToASCII(bo->getNote())); + ts << (bo->getNoteASCII()); ts << ("\n"); } @@ -142,102 +145,103 @@ { // Create tmpdir and set paths tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX")); - templateDir="oo-test/suse-template/"; + templateDir="exports/novell/template/"; contentTemplateFile=templateDir+"content-template.xml"; contentFile=tmpDir.path()+"/content.xml"; pageTemplateFile=templateDir+"page-template.xml"; chapterTemplateFile=templateDir+"chapter-template.xml"; - outputFile=tmpDir.currentDirPath()+"/out.odp"; - - // Copy template to tmpdir - system ("cp -r "+templateDir+"* "+tmpDir.path()); - - - // Read content-template - if (!loadStringFromDisk (contentTemplateFile,content)) - { - qWarning ("Export::exportOOPresentation() Couldn't load from "+contentTemplateFile); - return; - } - - // Read page-template - QString pageTemplate; - if (!loadStringFromDisk (pageTemplateFile,pageTemplate)) - { - qWarning ("Export::exportOOPresentation() Couldn't load from "+pageTemplateFile); - return; - } - - // Read chapter-template - QString chapterTemplate; - if (!loadStringFromDisk (chapterTemplateFile,chapterTemplate)) - { - qWarning ("Export::exportOOPresentation() Couldn't load from "+chapterTemplateFile); - return; - } + outputFile=tmpDir.currentDirPath()+"/test.odp"; } ExportOO::~ExportOO() { // Remove tmpdir - //FIXME removeDir (tmpDir); - cout << "tmpDir="<getFirstBranch(); if (bo) { // Start list - r+="\n"; + r+="\n"; while (bo) { - r+="\n "+ - bo->getHeading()+ - "\n\n"; + r+=""; + r+=quotemeta(bo->getHeading()); + // If necessary, write note + if (!bo->getNote().isEmpty()) + r+=bo->getNoteOpenDoc(); + r+=""; + r+=buildList (bo); // recursivly add deeper branches + r+="\n"; + i++; + bo=current->getBranchNum(i); } r+="\n"; } return r; } -QString ExportOO::walkPages (BranchObj *current) -{ - //FIXME Denkfehler: mit current anfangen, nicht mit - // Kind von current. Sonst erwisch ich nur jede 2. Depth - // - - - QString r; - BranchObj *bo; - int i=0; - bo=current->getFirstBranch(); - while(bo) - { - r+=quotemeta(bo->getHeading())+"\n"; - if (bo->getFirstBranch()) - r+=walkPages (bo->getFirstBranch()); - i++; - bo=current->getBranchNum (i); - } - return r; -} - void ExportOO::exportPresentation() { - QString allPages=walkPages (mapCenter); + QString allPages; - cout << allPages<",quotemeta(mapCenter->getHeading())); content.replace ("",quotemeta(mapCenter->getAuthor())); + + QString onePage; + QString list; + + BranchObj *chapterBO=mapCenter->getFirstBranch(); + int i=0; + BranchObj *pagesBO; + int j=0; + + // Walk chapters + while (chapterBO) + { + if (useChapters) + { + // Add page with chapter title + onePage=chapterTemplate; + onePage.replace ("", quotemeta(chapterBO->getHeading() ) ); + allPages+=onePage; + } else + { + i=-2; // only use inner loop to + // turn mainbranches into pages + chapterBO=mapCenter; + } + + // Walk mainpages + pagesBO=chapterBO->getFirstBranch(); + j=0; + while (pagesBO) + { + // Add page with list of items + onePage=pageTemplate; + onePage.replace ("", quotemeta (pagesBO->getHeading() ) ); + list=buildList (pagesBO); + onePage.replace ("", list); + allPages+=onePage; + j++; + pagesBO=chapterBO->getBranchNum(j); + } + i++; + chapterBO=mapCenter->getBranchNum(i); + } + content.replace ("",allPages); // Write modified content @@ -252,69 +256,54 @@ t << content; f.close(); - mainWindow->statusMessage( QString( QObject::tr("Map exported as %1")).arg( outputFile)); - - // zip tmpdir to destination zipDir (tmpDir,outputFile); - - /* FIXME not needed - QString onePage; - QString allPages; - QString heading; - - - // Walk through chapters (mainbranches) - QString s; - - QString list; - BranchObj *bo; - BranchObj *boLastPage=NULL; - bo=mapCenter->first(); - int depth; - int lastDepth=-1; - int basePageDepth=2; - while (bo) - { - depth=bo->getDepth(); - heading=quotemeta(bo->getHeading()); - if (depth>1) - { - if (depth==basePageDepth) - { - // Start a new page containing a heading and a list - if (boLastPage==NULL) - { - // Start new single page - boLastPage=bo; - onePage=pageTemplate; - onePage.replace ("", heading); - list=""; - } else - { - // Finish last page, start new one - onePage.replace ("", list); - boLastPage=bo; - allPages+=onePage; - onePage=pageTemplate; - onePage.replace ("", heading); - list=""; - } - } else - { - if (lastDepth==depth-1) - // entering deeper branches, new list - list+=""; - // Just add heading to list on current page - list+=""+heading+"\n"; - if (lastDepth==depth+1) - // returning from deeper branches, finish list - list+=""; - } - } - lastDepth=depth; - bo=bo->next(); - } -*/ } +void ExportOO::setConfigFile (const QString &cf) +{ + configFile=cf; + int i=cf.findRev ("/"); + if (i>=0) configDir=cf.left(i); + SimpleSettings set; + set.readSettings(configFile); + + // set paths + templateDir=configDir+"/"+set.readEntry ("Template"); + + //FIXME check if templateDir is really set, otherwise abort + + contentTemplateFile=templateDir+"content-template.xml"; + contentFile=tmpDir.path()+"/content.xml"; + pageTemplateFile=templateDir+"page-template.xml"; + chapterTemplateFile=templateDir+"chapter-template.xml"; + + outputFile=tmpDir.currentDirPath()+"/test.odp"; + + // Copy template to tmpdir + system ("cp -r "+templateDir+"* "+tmpDir.path()); + + + // Read content-template + if (!loadStringFromDisk (contentTemplateFile,content)) + { + qWarning ("Export::exportOO() Couldn't load from "+contentTemplateFile); + return; + } + + // Read page-template + if (!loadStringFromDisk (pageTemplateFile,pageTemplate)) + { + qWarning ("Export::exportOO() Couldn't load from "+pageTemplateFile); + return; + } + + // Read chapter-template + if (!loadStringFromDisk (chapterTemplateFile,chapterTemplate)) + { + qWarning ("Export::exportOO() Couldn't load from "+chapterTemplateFile); + return; + } + +} + diff -r 2747c4145c71 -r 97e0bd468439 exports.h --- a/exports.h Tue Jan 24 15:09:48 2006 +0000 +++ b/exports.h Tue Jan 24 15:09:48 2006 +0000 @@ -10,7 +10,7 @@ //using namespace std; -///////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////// class ExportBase { @@ -31,25 +31,27 @@ QString indentPerDepth; }; -///////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////// class ExportLaTeX:public ExportBase { public: void exportLaTeX(); }; -///////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////// class ExportOO:public ExportBase { public: ExportOO(); ~ExportOO(); void exportPresentation(); + void setConfigFile (const QString &); private: QString buildList (BranchObj*); - QString walkPages (BranchObj*); QDir tmpDir; bool useChapters; + QString configFile; + QString configDir; QString templateDir; QString content; QString contentTemplate;