3 #include "linkablemapobj.h"
5 #include "texteditor.h"
6 #include "mainwindow.h"
8 extern Main *mainWindow;
10 ExportBase::ExportBase()
15 void ExportBase::setPath (const QString &p)
20 void ExportBase::setMapCenter(MapCenterObj *mc)
25 QString ExportBase::getSectionString(BranchObj *bostart)
28 BranchObj *bo=bostart;
29 int depth=bo->getDepth();
32 r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
33 bo=(BranchObj*)(bo->getParObj());
42 void ExportBase::exportXML()
44 QFile file (filepath);
45 if ( !file.open( IO_WriteOnly ) )
47 // FIXME experimental, testing
48 cout << "ExportBase::exportXML couldn't open "<<filepath<<endl;
51 QTextStream ts( &file ); // use LANG decoding here...
53 // Main loop over all branches
55 QString actIndent("");
59 bo=mapCenter->first();
63 for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
66 // write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n");
67 if (bo->getDepth()==0)
69 ts << (bo->getHeading()+ "\n");
70 for (j=0;j<bo->getHeading().length();j++) ts<<"=";
72 } else if (bo->getDepth()==1)
73 ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
74 else if (bo->getDepth()==2)
75 ts << (actIndent + " o " + bo->getHeading()+ "\n");
77 ts << (actIndent + " - " + bo->getHeading()+ "\n");
79 // If necessary, write note
80 if (!bo->getNote().isEmpty())
82 s =bo->getNoteASCII();
83 s=s.replace ("\n","\n"+actIndent);
93 void ExportLaTeX::exportLaTeX()
95 // Exports a map to a LaTex file.
96 // This file needs to be included
97 // or inported into a LaTex document
98 // it will not add a preamble, or anything
99 // that makes a full LaTex document.
100 QFile file (filepath);
101 if ( !file.open( IO_WriteOnly ) ) {
103 cout << "Export::exportMap couldn't open "<<filepath<<endl;
106 QTextStream ts( &file ); // use LANG decoding here...
107 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
109 // Main loop over all branches
111 // QString actIndent("");
114 bo=mapCenter->first();
116 if (bo->getDepth()==0);
117 else if (bo->getDepth()==1) {
118 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
120 else if (bo->getDepth()==2) {
121 ts << ("\\section{" + bo->getHeading()+ "}\n");
123 else if (bo->getDepth()==3) {
124 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
126 else if (bo->getDepth()==4) {
127 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
130 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
133 // If necessary, write note
134 if (!bo->getNote().isEmpty()) {
135 ts << (bo->getNoteASCII());
146 // Create tmpdir and set paths
147 tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
148 templateDir="exports/novell/template/";
149 contentTemplateFile=templateDir+"content-template.xml";
150 contentFile=tmpDir.path()+"/content.xml";
151 pageTemplateFile=templateDir+"page-template.xml";
152 chapterTemplateFile=templateDir+"chapter-template.xml";
154 outputFile=tmpDir.currentDirPath()+"/test.odp";
157 ExportOO::~ExportOO()
163 QString ExportOO::buildList (BranchObj *current)
169 bo=current->getFirstBranch();
173 r+="<text:list text:style-name=\"L4\">\n";
176 r+="<text:list-item><text:p >";
177 r+=quotemeta(bo->getHeading());
178 // If necessary, write note
179 if (!bo->getNote().isEmpty())
180 r+=bo->getNoteOpenDoc();
182 r+=buildList (bo); // recursivly add deeper branches
183 r+="</text:list-item>\n";
185 bo=current->getBranchNum(i);
193 void ExportOO::exportPresentation()
197 bool useChapters=true;
199 // Insert new content
200 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
201 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
206 BranchObj *chapterBO=mapCenter->getFirstBranch();
216 // Add page with chapter title
217 onePage=chapterTemplate;
218 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(chapterBO->getHeading() ) );
222 i=-2; // only use inner loop to
223 // turn mainbranches into pages
228 pagesBO=chapterBO->getFirstBranch();
232 // Add page with list of items
233 onePage=pageTemplate;
234 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
235 list=buildList (pagesBO);
236 onePage.replace ("<!-- INSERT LIST -->", list);
239 pagesBO=chapterBO->getBranchNum(j);
242 chapterBO=mapCenter->getBranchNum(i);
245 content.replace ("<!-- INSERT PAGES -->",allPages);
247 // Write modified content
248 QFile f (contentFile);
249 if ( !f.open( IO_WriteOnly ) )
251 mainWindow->statusMessage(QString(QObject::tr("Could not write to %1")).arg(outputFile));
259 // zip tmpdir to destination
260 zipDir (tmpDir,outputFile);
263 void ExportOO::setConfigFile (const QString &cf)
266 int i=cf.findRev ("/");
267 if (i>=0) configDir=cf.left(i);
269 set.readSettings(configFile);
272 templateDir=configDir+"/"+set.readEntry ("Template");
274 //FIXME check if templateDir is really set, otherwise abort
276 contentTemplateFile=templateDir+"content-template.xml";
277 contentFile=tmpDir.path()+"/content.xml";
278 pageTemplateFile=templateDir+"page-template.xml";
279 chapterTemplateFile=templateDir+"chapter-template.xml";
281 outputFile=tmpDir.currentDirPath()+"/test.odp";
283 // Copy template to tmpdir
284 system ("cp -r "+templateDir+"* "+tmpDir.path());
287 // Read content-template
288 if (!loadStringFromDisk (contentTemplateFile,content))
290 qWarning ("Export::exportOO() Couldn't load from "+contentTemplateFile);
294 // Read page-template
295 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
297 qWarning ("Export::exportOO() Couldn't load from "+pageTemplateFile);
301 // Read chapter-template
302 if (!loadStringFromDisk (chapterTemplateFile,chapterTemplate))
304 qWarning ("Export::exportOO() Couldn't load from "+chapterTemplateFile);