1 #include <qmessagebox.h>
5 #include "linkablemapobj.h"
7 #include "mainwindow.h"
9 extern Main *mainWindow;
11 ExportBase::ExportBase()
16 void ExportBase::setDir(const QString &p)
21 void ExportBase::setFile (const QString &p)
26 void ExportBase::setMapCenter(MapCenterObj *mc)
31 QString ExportBase::getSectionString(BranchObj *bostart)
33 // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
35 BranchObj *bo=bostart;
36 int depth=bo->getDepth();
39 r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
40 bo=(BranchObj*)(bo->getParObj());
49 void ExportBase::exportXML()
51 QFile file (outputFile);
52 if ( !file.open( IO_WriteOnly ) )
54 // FIXME experimental, testing
55 cout << "ExportBase::exportXML couldn't open "<<outputFile<<endl;
58 QTextStream ts( &file ); // use LANG decoding here...
60 // Main loop over all branches
62 QString actIndent("");
66 bo=mapCenter->first();
70 for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
72 if (bo->getDepth()==0)
74 ts << (bo->getHeading()+ "\n");
75 for (j=0;j<bo->getHeading().length();j++) ts<<"=";
77 } else if (bo->getDepth()==1)
78 ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
79 else if (bo->getDepth()==2)
80 ts << (actIndent + " o " + bo->getHeading()+ "\n");
82 ts << (actIndent + " - " + bo->getHeading()+ "\n");
84 // If necessary, write note
85 if (!bo->getNote().isEmpty())
87 s =bo->getNoteASCII();
88 s=s.replace ("\n","\n"+actIndent);
98 void ExportLaTeX::exportLaTeX()
100 // Exports a map to a LaTex file.
101 // This file needs to be included
102 // or inported into a LaTex document
103 // it will not add a preamble, or anything
104 // that makes a full LaTex document.
105 QFile file (outputFile);
106 if ( !file.open( IO_WriteOnly ) ) {
107 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
108 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
111 QTextStream ts( &file ); // use LANG decoding here...
112 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
114 // Main loop over all branches
116 // QString actIndent("");
119 bo=mapCenter->first();
121 if (bo->getDepth()==0);
122 else if (bo->getDepth()==1) {
123 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
125 else if (bo->getDepth()==2) {
126 ts << ("\\section{" + bo->getHeading()+ "}\n");
128 else if (bo->getDepth()==3) {
129 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
131 else if (bo->getDepth()==4) {
132 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
135 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
138 // If necessary, write note
139 if (!bo->getNote().isEmpty()) {
140 ts << (bo->getNoteASCII());
153 tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
156 ExportOO::~ExportOO()
162 QString ExportOO::buildList (BranchObj *current)
168 bo=current->getFirstBranch();
172 r+="<text:list text:style-name=\"L4\">\n";
175 r+="<text:list-item><text:p >";
176 r+=quotemeta(bo->getHeading());
177 // If necessary, write note
178 if (!bo->getNote().isEmpty())
179 r+=bo->getNoteOpenDoc();
181 r+=buildList (bo); // recursivly add deeper branches
182 r+="</text:list-item>\n";
184 bo=current->getBranchNum(i);
192 void ExportOO::exportPresentation()
196 // Insert new content
197 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
198 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
203 BranchObj *sectionBO=mapCenter->getFirstBranch();
213 // Add page with section title
214 onePage=sectionTemplate;
215 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
219 i=-2; // only use inner loop to
220 // turn mainbranches into pages
225 pagesBO=sectionBO->getFirstBranch();
229 // Add page with list of items
230 onePage=pageTemplate;
231 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
232 list=buildList (pagesBO);
233 onePage.replace ("<!-- INSERT LIST -->", list);
236 pagesBO=sectionBO->getBranchNum(j);
239 sectionBO=mapCenter->getBranchNum(i);
242 content.replace ("<!-- INSERT PAGES -->",allPages);
244 // Write modified content
245 QFile f (contentFile);
246 if ( !f.open( IO_WriteOnly ) )
248 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
249 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
257 // zip tmpdir to destination
258 zipDir (tmpDir,outputFile);
261 bool ExportOO::setConfigFile (const QString &cf)
264 int i=cf.findRev ("/");
265 if (i>=0) configDir=cf.left(i);
267 set.readSettings(configFile);
270 templateDir=configDir+"/"+set.readEntry ("Template");
272 QDir d (templateDir);
275 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
280 contentTemplateFile=templateDir+"content-template.xml";
281 contentFile=tmpDir.path()+"/content.xml";
282 pageTemplateFile=templateDir+"page-template.xml";
283 sectionTemplateFile=templateDir+"section-template.xml";
285 if (set.readEntry("useSections").contains("yes"))
288 // Copy template to tmpdir
289 system ("cp -r "+templateDir+"* "+tmpDir.path());
291 // Read content-template
292 if (!loadStringFromDisk (contentTemplateFile,content))
294 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
298 // Read page-template
299 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
301 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
305 // Read section-template
306 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
308 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));