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::setDir(const QString &p)
22 void ExportBase::setFile (const QString &p)
27 void ExportBase::setMapCenter(MapCenterObj *mc)
32 QString ExportBase::getSectionString(BranchObj *bostart)
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;
73 // write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n");
74 if (bo->getDepth()==0)
76 ts << (bo->getHeading()+ "\n");
77 for (j=0;j<bo->getHeading().length();j++) ts<<"=";
79 } else if (bo->getDepth()==1)
80 ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
81 else if (bo->getDepth()==2)
82 ts << (actIndent + " o " + bo->getHeading()+ "\n");
84 ts << (actIndent + " - " + bo->getHeading()+ "\n");
86 // If necessary, write note
87 if (!bo->getNote().isEmpty())
89 s =bo->getNoteASCII();
90 s=s.replace ("\n","\n"+actIndent);
100 void ExportLaTeX::exportLaTeX()
102 // Exports a map to a LaTex file.
103 // This file needs to be included
104 // or inported into a LaTex document
105 // it will not add a preamble, or anything
106 // that makes a full LaTex document.
107 QFile file (outputFile);
108 if ( !file.open( IO_WriteOnly ) ) {
110 cout << "Export::exportMap couldn't open "<<outputFile<<endl;
113 QTextStream ts( &file ); // use LANG decoding here...
114 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
116 // Main loop over all branches
118 // QString actIndent("");
121 bo=mapCenter->first();
123 if (bo->getDepth()==0);
124 else if (bo->getDepth()==1) {
125 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
127 else if (bo->getDepth()==2) {
128 ts << ("\\section{" + bo->getHeading()+ "}\n");
130 else if (bo->getDepth()==3) {
131 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
133 else if (bo->getDepth()==4) {
134 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
137 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
140 // If necessary, write note
141 if (!bo->getNote().isEmpty()) {
142 ts << (bo->getNoteASCII());
155 tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
158 ExportOO::~ExportOO()
164 QString ExportOO::buildList (BranchObj *current)
170 bo=current->getFirstBranch();
174 r+="<text:list text:style-name=\"L4\">\n";
177 r+="<text:list-item><text:p >";
178 r+=quotemeta(bo->getHeading());
179 // If necessary, write note
180 if (!bo->getNote().isEmpty())
181 r+=bo->getNoteOpenDoc();
183 r+=buildList (bo); // recursivly add deeper branches
184 r+="</text:list-item>\n";
186 bo=current->getBranchNum(i);
194 void ExportOO::exportPresentation()
198 // Insert new content
199 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
200 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
205 BranchObj *sectionBO=mapCenter->getFirstBranch();
215 // Add page with section title
216 onePage=sectionTemplate;
217 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
221 i=-2; // only use inner loop to
222 // turn mainbranches into pages
227 pagesBO=sectionBO->getFirstBranch();
231 // Add page with list of items
232 onePage=pageTemplate;
233 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
234 list=buildList (pagesBO);
235 onePage.replace ("<!-- INSERT LIST -->", list);
238 pagesBO=sectionBO->getBranchNum(j);
241 sectionBO=mapCenter->getBranchNum(i);
244 content.replace ("<!-- INSERT PAGES -->",allPages);
246 // Write modified content
247 QFile f (contentFile);
248 if ( !f.open( IO_WriteOnly ) )
250 mainWindow->statusMessage(QString(QObject::tr("Could not write to %1")).arg(contentFile));
258 // zip tmpdir to destination
259 zipDir (tmpDir,outputFile);
262 bool ExportOO::setConfigFile (const QString &cf)
265 int i=cf.findRev ("/");
266 if (i>=0) configDir=cf.left(i);
268 set.readSettings(configFile);
271 templateDir=configDir+"/"+set.readEntry ("Template");
273 QDir d (templateDir);
276 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
281 contentTemplateFile=templateDir+"content-template.xml";
282 contentFile=tmpDir.path()+"/content.xml";
283 pageTemplateFile=templateDir+"page-template.xml";
284 sectionTemplateFile=templateDir+"section-template.xml";
286 if (set.readEntry("useSections").contains("yes"))
289 // Copy template to tmpdir
290 system ("cp -r "+templateDir+"* "+tmpDir.path());
292 // Read content-template
293 if (!loadStringFromDisk (contentTemplateFile,content))
295 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
299 // Read page-template
300 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
302 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
306 // Read section-template
307 if (!loadStringFromDisk (sectionTemplateFile,sectionTemplate))
309 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));