1 #include <qmessagebox.h>
5 #include "linkablemapobj.h"
7 #include "texteditor.h"
8 #include "mainwindow.h"
10 extern Main *mainWindow;
12 ExportBase::ExportBase()
17 void ExportBase::setPath (const QString &p)
22 void ExportBase::setMapCenter(MapCenterObj *mc)
27 QString ExportBase::getSectionString(BranchObj *bostart)
30 BranchObj *bo=bostart;
31 int depth=bo->getDepth();
34 r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
35 bo=(BranchObj*)(bo->getParObj());
44 void ExportBase::exportXML()
46 QFile file (filepath);
47 if ( !file.open( IO_WriteOnly ) )
49 // FIXME experimental, testing
50 cout << "ExportBase::exportXML couldn't open "<<filepath<<endl;
53 QTextStream ts( &file ); // use LANG decoding here...
55 // Main loop over all branches
57 QString actIndent("");
61 bo=mapCenter->first();
65 for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
68 // write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n");
69 if (bo->getDepth()==0)
71 ts << (bo->getHeading()+ "\n");
72 for (j=0;j<bo->getHeading().length();j++) ts<<"=";
74 } else if (bo->getDepth()==1)
75 ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
76 else if (bo->getDepth()==2)
77 ts << (actIndent + " o " + bo->getHeading()+ "\n");
79 ts << (actIndent + " - " + bo->getHeading()+ "\n");
81 // If necessary, write note
82 if (!bo->getNote().isEmpty())
84 s =bo->getNoteASCII();
85 s=s.replace ("\n","\n"+actIndent);
95 void ExportLaTeX::exportLaTeX()
97 // Exports a map to a LaTex file.
98 // This file needs to be included
99 // or inported into a LaTex document
100 // it will not add a preamble, or anything
101 // that makes a full LaTex document.
102 QFile file (filepath);
103 if ( !file.open( IO_WriteOnly ) ) {
105 cout << "Export::exportMap couldn't open "<<filepath<<endl;
108 QTextStream ts( &file ); // use LANG decoding here...
109 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
111 // Main loop over all branches
113 // QString actIndent("");
116 bo=mapCenter->first();
118 if (bo->getDepth()==0);
119 else if (bo->getDepth()==1) {
120 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
122 else if (bo->getDepth()==2) {
123 ts << ("\\section{" + bo->getHeading()+ "}\n");
125 else if (bo->getDepth()==3) {
126 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
128 else if (bo->getDepth()==4) {
129 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
132 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
135 // If necessary, write note
136 if (!bo->getNote().isEmpty()) {
137 ts << (bo->getNoteASCII());
149 tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
152 ExportOO::~ExportOO()
158 QString ExportOO::buildList (BranchObj *current)
164 bo=current->getFirstBranch();
168 r+="<text:list text:style-name=\"L4\">\n";
171 r+="<text:list-item><text:p >";
172 r+=quotemeta(bo->getHeading());
173 // If necessary, write note
174 if (!bo->getNote().isEmpty())
175 r+=bo->getNoteOpenDoc();
177 r+=buildList (bo); // recursivly add deeper branches
178 r+="</text:list-item>\n";
180 bo=current->getBranchNum(i);
188 void ExportOO::exportPresentation()
192 bool useSections=true;
194 // Insert new content
195 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
196 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
201 BranchObj *sectionBO=mapCenter->getFirstBranch();
211 // Add page with section title
212 onePage=sectionTemplate;
213 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
217 i=-2; // only use inner loop to
218 // turn mainbranches into pages
223 pagesBO=sectionBO->getFirstBranch();
227 // Add page with list of items
228 onePage=pageTemplate;
229 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
230 list=buildList (pagesBO);
231 onePage.replace ("<!-- INSERT LIST -->", list);
234 pagesBO=sectionBO->getBranchNum(j);
237 sectionBO=mapCenter->getBranchNum(i);
240 content.replace ("<!-- INSERT PAGES -->",allPages);
242 // Write modified content
243 QFile f (contentFile);
244 if ( !f.open( IO_WriteOnly ) )
246 mainWindow->statusMessage(QString(QObject::tr("Could not write to %1")).arg(outputFile));
254 // zip tmpdir to destination
255 zipDir (tmpDir,outputFile);
258 bool ExportOO::setConfigFile (const QString &cf)
261 int i=cf.findRev ("/");
262 if (i>=0) configDir=cf.left(i);
264 set.readSettings(configFile);
267 templateDir=configDir+"/"+set.readEntry ("Template");
269 QDir d (templateDir);
272 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
277 contentTemplateFile=templateDir+"content-template.xml";
278 contentFile=tmpDir.path()+"/content.xml";
279 pageTemplateFile=templateDir+"page-template.xml";
280 sectionTemplateFile=templateDir+"section-template.xml";
282 outputFile=tmpDir.currentDirPath()+"/vym-out.odp";
284 // Copy template to tmpdir
285 system ("cp -r "+templateDir+"* "+tmpDir.path());
287 // Read content-template
288 if (!loadStringFromDisk (contentTemplateFile,content))
290 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
294 // Read page-template
295 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
297 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
301 // Read section-template
302 if (!loadStringFromDisk (sectionTemplateFile,sectionTemplate))
304 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));