1.1 --- a/exports.cpp Mon Sep 12 19:52:51 2005 +0000
1.2 +++ b/exports.cpp Tue Jan 03 09:44:41 2006 +0000
1.3 @@ -1,27 +1,28 @@
1.4 #include "exports.h"
1.5 +#include "file.h"
1.6 +#include "linkablemapobj.h"
1.7 +#include "misc.h"
1.8 +#include "texteditor.h"
1.9 +#include "mainwindow.h"
1.10
1.11 -#include <qregexp.h>
1.12 +extern Main *mainWindow;
1.13
1.14 -#include "linkablemapobj.h"
1.15 -#include "texteditor.h"
1.16 -
1.17 -
1.18 -Export::Export()
1.19 +ExportBase::ExportBase()
1.20 {
1.21 indentPerDepth=" ";
1.22 }
1.23
1.24 -void Export::setPath (const QString &p)
1.25 +void ExportBase::setPath (const QString &p)
1.26 {
1.27 filepath=p;
1.28 }
1.29
1.30 -void Export::setMapCenter(MapCenterObj *mc)
1.31 +void ExportBase::setMapCenter(MapCenterObj *mc)
1.32 {
1.33 mapCenter=mc;
1.34 }
1.35
1.36 -QString Export::getSectionString(BranchObj *bostart)
1.37 +QString ExportBase::getSectionString(BranchObj *bostart)
1.38 {
1.39 QString r;
1.40 BranchObj *bo=bostart;
1.41 @@ -38,13 +39,13 @@
1.42 return r + " ";
1.43 }
1.44
1.45 -void Export::exportMap()
1.46 +void ExportBase::exportXML()
1.47 {
1.48 QFile file (filepath);
1.49 if ( !file.open( IO_WriteOnly ) )
1.50 {
1.51 // FIXME experimental, testing
1.52 - cout << "Export::exportMap couldn't open "<<filepath<<endl;
1.53 + cout << "ExportBase::exportXML couldn't open "<<filepath<<endl;
1.54 return;
1.55 }
1.56 QTextStream ts( &file ); // use LANG decoding here...
1.57 @@ -91,7 +92,7 @@
1.58
1.59 // Exports a map to a LaTex file. This file needs to be included or inported into a LaTex document
1.60 // it will not add a preamble, or anything that makes a full LaTex document.
1.61 -void Export::exportLaTeX()
1.62 +void ExportLaTeX::exportLaTeX()
1.63 {
1.64 QFile file (filepath);
1.65 if ( !file.open( IO_WriteOnly ) ) {
1.66 @@ -137,81 +138,183 @@
1.67 file.close();
1.68 }
1.69
1.70 -#include "settings.h"
1.71 +ExportOO::ExportOO()
1.72 +{
1.73 + // Create tmpdir and set paths
1.74 + tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
1.75 + templateDir="oo-test/suse-template/";
1.76 + contentTemplateFile=templateDir+"content-template.xml";
1.77 + contentFile=tmpDir.path()+"/content.xml";
1.78 + pageTemplateFile=templateDir+"page-template.xml";
1.79 + chapterTemplateFile=templateDir+"chapter-template.xml";
1.80
1.81 -void Export::exportOOPresentation()
1.82 -{
1.83 - QString templateDir="oo-test/suse-template/";
1.84 - QString templateContent="content.xml";
1.85 - QString tmpDir="/tmp/vym-ootest/";
1.86 - QString header="";
1.87 -
1.88 -
1.89 - // Create tmpdir
1.90 - // TODO
1.91 -
1.92 + outputFile=tmpDir.currentDirPath()+"/out.odp";
1.93 +
1.94 // Copy template to tmpdir
1.95 - // TODO
1.96 -
1.97 + system ("cp -r "+templateDir+"* "+tmpDir.path());
1.98 +
1.99
1.100 // Read content-template
1.101 - // TODO
1.102 - QString content;
1.103 - if (!loadStringFromDisk (templateDir+templateContent,content))
1.104 + if (!loadStringFromDisk (contentTemplateFile,content))
1.105 {
1.106 - qWarning ("Export::exportOOPresentation() Couldn't load from "+templateDir+templateContent);
1.107 + qWarning ("Export::exportOOPresentation() Couldn't load from "+contentTemplateFile);
1.108 return;
1.109 }
1.110
1.111 + // Read page-template
1.112 + QString pageTemplate;
1.113 + if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
1.114 + {
1.115 + qWarning ("Export::exportOOPresentation() Couldn't load from "+pageTemplateFile);
1.116 + return;
1.117 + }
1.118 +
1.119 + // Read chapter-template
1.120 + QString chapterTemplate;
1.121 + if (!loadStringFromDisk (chapterTemplateFile,chapterTemplate))
1.122 + {
1.123 + qWarning ("Export::exportOOPresentation() Couldn't load from "+chapterTemplateFile);
1.124 + return;
1.125 + }
1.126 +}
1.127
1.128 - // Walk through map
1.129 - QString s;
1.130 - QString actIndent("");
1.131 - uint j;
1.132 - int i;
1.133 - BranchObj *bo;
1.134 - bo=mapCenter->first();
1.135 - while (bo)
1.136 - {
1.137 - // Make indentstring
1.138 - for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
1.139 +ExportOO::~ExportOO()
1.140 +{
1.141 + // Remove tmpdir
1.142 + //FIXME removeDir (tmpDir);
1.143 + cout << "tmpDir="<<tmpDir.path()<<endl;
1.144 +}
1.145
1.146 - // Write heading
1.147 - // write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n");
1.148 - if (bo->getDepth()==0)
1.149 - {
1.150 - s+= (bo->getHeading()+ "\n");
1.151 - for (j=0;j<bo->getHeading().length();j++) s+="=";
1.152 - s+= "\n";
1.153 - } else if (bo->getDepth()==1)
1.154 - s+= ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
1.155 - else if (bo->getDepth()==2)
1.156 - s+= (actIndent + " o " + bo->getHeading()+ "\n");
1.157 - else
1.158 - s+ (actIndent + " - " + bo->getHeading()+ "\n");
1.159 -
1.160 - /*
1.161 - // If necessary, write note
1.162 - if (!bo->getNote().isEmpty())
1.163 - {
1.164 - s =textConvertToASCII(bo->getNote());
1.165 - s=s.replace ("\n","\n"+actIndent);
1.166 - ts << (s+"\n\n");
1.167 - }
1.168 - */
1.169 - bo=bo->next();
1.170 - actIndent="";
1.171 - }
1.172 +QString ExportOO::buildList (BranchObj *current)
1.173 +{
1.174 + QString r;
1.175 + BranchObj *bo;
1.176 + int i=0;
1.177 + bo=current->getFirstBranch();
1.178 + if (bo)
1.179 + {
1.180 + // Start list
1.181 + r+="<text:list>\n";
1.182 + while (bo)
1.183 + {
1.184 + r+="<text:list-item><text:p text:style-name=\"P7\">\n "+
1.185 + bo->getHeading()+
1.186 + "\n</text:p></text:list-item>\n";
1.187 + }
1.188 + r+="</text:list>\n";
1.189 + }
1.190 + return r;
1.191 +}
1.192
1.193 +QString ExportOO::walkPages (BranchObj *current)
1.194 +{
1.195 + //FIXME Denkfehler: mit current anfangen, nicht mit
1.196 + // Kind von current. Sonst erwisch ich nur jede 2. Depth
1.197 + //
1.198 +
1.199 +
1.200 + QString r;
1.201 + BranchObj *bo;
1.202 + int i=0;
1.203 + bo=current->getFirstBranch();
1.204 + while(bo)
1.205 + {
1.206 + r+=quotemeta(bo->getHeading())+"\n";
1.207 + if (bo->getFirstBranch())
1.208 + r+=walkPages (bo->getFirstBranch());
1.209 + i++;
1.210 + bo=current->getBranchNum (i);
1.211 + }
1.212 + return r;
1.213 +}
1.214 +
1.215 +
1.216 +void ExportOO::exportPresentation()
1.217 +{
1.218 + QString allPages=walkPages (mapCenter);
1.219 +
1.220 + cout << allPages<<endl;
1.221
1.222 // Insert new content
1.223 - // TODO
1.224 - cout <<"\n\ns="<<s<<endl;
1.225 - content.replace ("<!--INSERT PAGES HERE-->",s);
1.226 - cout << "ExportOO: content=\n"<<content<<endl;
1.227 + content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
1.228 + content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
1.229 + content.replace ("<!-- INSERT PAGES -->",allPages);
1.230 +
1.231 + // Write modified content
1.232 + QFile f (contentFile);
1.233 + if ( !f.open( IO_WriteOnly ) )
1.234 + {
1.235 + mainWindow->statusMessage(QString(QObject::tr("Could not write to %1")).arg(outputFile));
1.236 + return;
1.237 + }
1.238 +
1.239 + QTextStream t( &f );
1.240 + t << content;
1.241 + f.close();
1.242 +
1.243 + mainWindow->statusMessage( QString( QObject::tr("Map exported as %1")).arg( outputFile));
1.244 +
1.245
1.246 // zip tmpdir to destination
1.247 - // TODO
1.248 + zipDir (tmpDir,outputFile);
1.249
1.250 + /* FIXME not needed
1.251 + QString onePage;
1.252 + QString allPages;
1.253 + QString heading;
1.254 +
1.255 +
1.256 + // Walk through chapters (mainbranches)
1.257 + QString s;
1.258 +
1.259 + QString list;
1.260 + BranchObj *bo;
1.261 + BranchObj *boLastPage=NULL;
1.262 + bo=mapCenter->first();
1.263 + int depth;
1.264 + int lastDepth=-1;
1.265 + int basePageDepth=2;
1.266 + while (bo)
1.267 + {
1.268 + depth=bo->getDepth();
1.269 + heading=quotemeta(bo->getHeading());
1.270 + if (depth>1)
1.271 + {
1.272 + if (depth==basePageDepth)
1.273 + {
1.274 + // Start a new page containing a heading and a list
1.275 + if (boLastPage==NULL)
1.276 + {
1.277 + // Start new single page
1.278 + boLastPage=bo;
1.279 + onePage=pageTemplate;
1.280 + onePage.replace ("<!-- INSERT PAGE HEADING -->", heading);
1.281 + list="";
1.282 + } else
1.283 + {
1.284 + // Finish last page, start new one
1.285 + onePage.replace ("<!-- INSERT LIST -->", list);
1.286 + boLastPage=bo;
1.287 + allPages+=onePage;
1.288 + onePage=pageTemplate;
1.289 + onePage.replace ("<!-- INSERT PAGE HEADING -->", heading);
1.290 + list="";
1.291 + }
1.292 + } else
1.293 + {
1.294 + if (lastDepth==depth-1)
1.295 + // entering deeper branches, new list
1.296 + list+="<text:list>";
1.297 + // Just add heading to list on current page
1.298 + list+="<text:list-item><text:p text:style-name=\"P7\">"+heading+"</text:p></text:list-item>\n";
1.299 + if (lastDepth==depth+1)
1.300 + // returning from deeper branches, finish list
1.301 + list+="</text:list>";
1.302 + }
1.303 + }
1.304 + lastDepth=depth;
1.305 + bo=bo->next();
1.306 + }
1.307 +*/
1.308 }
1.309