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 =textConvertToASCII(bo->getNote());
83 s=s.replace ("\n","\n"+actIndent);
93 // Exports a map to a LaTex file. This file needs to be included or inported into a LaTex document
94 // it will not add a preamble, or anything that makes a full LaTex document.
95 void ExportLaTeX::exportLaTeX()
97 QFile file (filepath);
98 if ( !file.open( IO_WriteOnly ) ) {
100 cout << "Export::exportMap couldn't open "<<filepath<<endl;
103 QTextStream ts( &file ); // use LANG decoding here...
104 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
106 // Main loop over all branches
108 // QString actIndent("");
111 bo=mapCenter->first();
113 if (bo->getDepth()==0);
114 else if (bo->getDepth()==1) {
115 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
117 else if (bo->getDepth()==2) {
118 ts << ("\\section{" + bo->getHeading()+ "}\n");
120 else if (bo->getDepth()==3) {
121 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
123 else if (bo->getDepth()==4) {
124 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
127 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
130 // If necessary, write note
131 if (!bo->getNote().isEmpty()) {
132 ts << (textConvertToASCII(bo->getNote()));
143 // Create tmpdir and set paths
144 tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
145 templateDir="oo-test/suse-template/";
146 contentTemplateFile=templateDir+"content-template.xml";
147 contentFile=tmpDir.path()+"/content.xml";
148 pageTemplateFile=templateDir+"page-template.xml";
149 chapterTemplateFile=templateDir+"chapter-template.xml";
151 outputFile=tmpDir.currentDirPath()+"/out.odp";
153 // Copy template to tmpdir
154 system ("cp -r "+templateDir+"* "+tmpDir.path());
157 // Read content-template
158 if (!loadStringFromDisk (contentTemplateFile,content))
160 qWarning ("Export::exportOOPresentation() Couldn't load from "+contentTemplateFile);
164 // Read page-template
165 QString pageTemplate;
166 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
168 qWarning ("Export::exportOOPresentation() Couldn't load from "+pageTemplateFile);
172 // Read chapter-template
173 QString chapterTemplate;
174 if (!loadStringFromDisk (chapterTemplateFile,chapterTemplate))
176 qWarning ("Export::exportOOPresentation() Couldn't load from "+chapterTemplateFile);
181 ExportOO::~ExportOO()
184 //FIXME removeDir (tmpDir);
185 cout << "tmpDir="<<tmpDir.path()<<endl;
188 QString ExportOO::buildList (BranchObj *current)
193 bo=current->getFirstBranch();
200 r+="<text:list-item><text:p text:style-name=\"P7\">\n "+
202 "\n</text:p></text:list-item>\n";
209 QString ExportOO::walkPages (BranchObj *current)
211 //FIXME Denkfehler: mit current anfangen, nicht mit
212 // Kind von current. Sonst erwisch ich nur jede 2. Depth
219 bo=current->getFirstBranch();
222 r+=quotemeta(bo->getHeading())+"\n";
223 if (bo->getFirstBranch())
224 r+=walkPages (bo->getFirstBranch());
226 bo=current->getBranchNum (i);
232 void ExportOO::exportPresentation()
234 QString allPages=walkPages (mapCenter);
236 cout << allPages<<endl;
238 // Insert new content
239 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
240 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
241 content.replace ("<!-- INSERT PAGES -->",allPages);
243 // Write modified content
244 QFile f (contentFile);
245 if ( !f.open( IO_WriteOnly ) )
247 mainWindow->statusMessage(QString(QObject::tr("Could not write to %1")).arg(outputFile));
255 mainWindow->statusMessage( QString( QObject::tr("Map exported as %1")).arg( outputFile));
258 // zip tmpdir to destination
259 zipDir (tmpDir,outputFile);
267 // Walk through chapters (mainbranches)
272 BranchObj *boLastPage=NULL;
273 bo=mapCenter->first();
279 depth=bo->getDepth();
280 heading=quotemeta(bo->getHeading());
283 if (depth==basePageDepth)
285 // Start a new page containing a heading and a list
286 if (boLastPage==NULL)
288 // Start new single page
290 onePage=pageTemplate;
291 onePage.replace ("<!-- INSERT PAGE HEADING -->", heading);
295 // Finish last page, start new one
296 onePage.replace ("<!-- INSERT LIST -->", list);
299 onePage=pageTemplate;
300 onePage.replace ("<!-- INSERT PAGE HEADING -->", heading);
305 if (lastDepth==depth-1)
306 // entering deeper branches, new list
308 // Just add heading to list on current page
309 list+="<text:list-item><text:p text:style-name=\"P7\">"+heading+"</text:p></text:list-item>\n";
310 if (lastDepth==depth+1)
311 // returning from deeper branches, finish list
312 list+="</text:list>";