1 #include <qfiledialog.h>
2 #include <qmessagebox.h>
6 #include "linkablemapobj.h"
8 #include "mainwindow.h"
11 extern Main *mainWindow;
12 extern QDir vymBaseDir;
15 ExportBase::ExportBase()
19 tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
22 ExportBase::~ExportBase()
28 void ExportBase::setDir(const QString &p)
33 void ExportBase::setFile (const QString &p)
38 void ExportBase::setMapCenter(MapCenterObj *mc)
43 void ExportBase::setCaption (const QString &s)
48 void ExportBase::addFilter(const QString &s)
53 bool ExportBase::execDialog()
55 if (mapCenter && mapCenter->getMapEditor())
57 QFileDialog *fd=new QFileDialog( mapCenter->getMapEditor(), caption);
58 fd->addFilter (filter);
59 fd->setCaption(caption);
60 fd->setMode( QFileDialog::AnyFile );
63 if ( fd->exec() == QDialog::Accepted )
65 if (QFile (fd->selectedFile()).exists() )
67 QMessageBox mb( __VYM,
68 QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
70 QMessageBox::Yes | QMessageBox::Default,
71 QMessageBox::Cancel | QMessageBox::Escape,
72 QMessageBox::NoButton );
73 mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
74 mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
78 case QMessageBox::Yes:
81 case QMessageBox::Cancel:
87 outputFile=fd->selectedFile();
94 QString ExportBase::getSectionString(BranchObj *bostart)
96 // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
98 BranchObj *bo=bostart;
99 int depth=bo->getDepth();
102 r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
103 bo=(BranchObj*)(bo->getParObj());
104 depth=bo->getDepth();
112 void ExportASCII::doExport()
114 QFile file (outputFile);
115 if ( !file.open( IO_WriteOnly ) )
117 // FIXME experimental, testing
118 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
121 QTextStream ts( &file ); // use LANG decoding here...
123 // Main loop over all branches
125 QString actIndent("");
129 bo=mapCenter->first();
133 for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
135 if (bo->getDepth()==0)
137 ts << (bo->getHeading()+ "\n");
138 for (j=0;j<bo->getHeading().length();j++) ts<<"=";
140 } else if (bo->getDepth()==1)
141 ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
142 else if (bo->getDepth()==2)
143 ts << (actIndent + " o " + bo->getHeading()+ "\n");
145 ts << (actIndent + " - " + bo->getHeading()+ "\n");
147 // If necessary, write note
148 if (!bo->getNote().isEmpty())
150 s =bo->getNoteASCII();
151 s=s.replace ("\n","\n"+actIndent);
161 void ExportTaskjuggler::doExport()
164 if (mapCenter) me=mapCenter->getMapEditor();
167 me->exportXML(tmpDir.path());
169 cout << "tmpDir="<<tmpDir.path()<<endl;
172 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
173 p.setOutputFile (outputFile);
174 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
180 void ExportLaTeX::doExport()
182 // Exports a map to a LaTex file.
183 // This file needs to be included
184 // or inported into a LaTex document
185 // it will not add a preamble, or anything
186 // that makes a full LaTex document.
187 QFile file (outputFile);
188 if ( !file.open( IO_WriteOnly ) ) {
189 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
190 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
193 QTextStream ts( &file ); // use LANG decoding here...
194 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
196 // Main loop over all branches
198 // QString actIndent("");
201 bo=mapCenter->first();
203 if (bo->getDepth()==0);
204 else if (bo->getDepth()==1) {
205 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
207 else if (bo->getDepth()==2) {
208 ts << ("\\section{" + bo->getHeading()+ "}\n");
210 else if (bo->getDepth()==3) {
211 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
213 else if (bo->getDepth()==4) {
214 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
217 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
220 // If necessary, write note
221 if (!bo->getNote().isEmpty()) {
222 ts << (bo->getNoteASCII());
234 skipPageFlag="cross-red";
237 ExportOO::~ExportOO()
241 QString ExportOO::buildList (BranchObj *current)
247 bo=current->getFirstBranch();
251 r+="<text:list text:style-name=\"vym-list\">\n";
254 if (!bo->isActiveFlag (skipPageFlag))
256 r+="<text:list-item><text:p >";
257 r+=quotemeta(bo->getHeading());
258 // If necessary, write note
259 if (!bo->getNote().isEmpty())
260 r+=bo->getNoteOpenDoc();
262 r+=buildList (bo); // recursivly add deeper branches
263 r+="</text:list-item>\n";
266 bo=current->getBranchNum(i);
274 void ExportOO::exportPresentation()
278 // Insert new content
279 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
280 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
285 BranchObj *sectionBO=mapCenter->getFirstBranch();
295 // Add page with section title
296 onePage=sectionTemplate;
297 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
301 i=-2; // only use inner loop to
302 // turn mainbranches into pages
307 pagesBO=sectionBO->getFirstBranch();
311 // Add page with list of items
312 if (!pagesBO->isActiveFlag (skipPageFlag))
314 onePage=pageTemplate;
315 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
316 list=buildList (pagesBO);
317 onePage.replace ("<!-- INSERT LIST -->", list);
321 pagesBO=sectionBO->getBranchNum(j);
324 sectionBO=mapCenter->getBranchNum(i);
327 content.replace ("<!-- INSERT PAGES -->",allPages);
329 // Write modified content
330 QFile f (contentFile);
331 if ( !f.open( IO_WriteOnly ) )
333 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
334 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
342 // zip tmpdir to destination
343 zipDir (tmpDir,outputFile);
346 bool ExportOO::setConfigFile (const QString &cf)
349 int i=cf.findRev ("/");
350 if (i>=0) configDir=cf.left(i);
352 set.readSettings(configFile);
355 templateDir=configDir+"/"+set.readEntry ("Template");
357 QDir d (templateDir);
360 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
365 contentTemplateFile=templateDir+"content-template.xml";
366 contentFile=tmpDir.path()+"/content.xml";
367 pageTemplateFile=templateDir+"page-template.xml";
368 sectionTemplateFile=templateDir+"section-template.xml";
370 if (set.readEntry("useSections").contains("yes"))
373 // Copy template to tmpdir
374 system ("cp -r "+templateDir+"* "+tmpDir.path());
376 // Read content-template
377 if (!loadStringFromDisk (contentTemplateFile,content))
379 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
383 // Read page-template
384 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
386 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
390 // Read section-template
391 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
393 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));