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());
236 ExportOO::~ExportOO()
240 QString ExportOO::buildList (BranchObj *current)
246 bo=current->getFirstBranch();
250 r+="<text:list text:style-name=\"L4\">\n";
253 r+="<text:list-item><text:p >";
254 r+=quotemeta(bo->getHeading());
255 // If necessary, write note
256 if (!bo->getNote().isEmpty())
257 r+=bo->getNoteOpenDoc();
259 r+=buildList (bo); // recursivly add deeper branches
260 r+="</text:list-item>\n";
262 bo=current->getBranchNum(i);
270 void ExportOO::exportPresentation()
274 // Insert new content
275 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
276 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
281 BranchObj *sectionBO=mapCenter->getFirstBranch();
291 // Add page with section title
292 onePage=sectionTemplate;
293 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
297 i=-2; // only use inner loop to
298 // turn mainbranches into pages
303 pagesBO=sectionBO->getFirstBranch();
307 // Add page with list of items
308 onePage=pageTemplate;
309 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
310 list=buildList (pagesBO);
311 onePage.replace ("<!-- INSERT LIST -->", list);
314 pagesBO=sectionBO->getBranchNum(j);
317 sectionBO=mapCenter->getBranchNum(i);
320 content.replace ("<!-- INSERT PAGES -->",allPages);
322 // Write modified content
323 QFile f (contentFile);
324 if ( !f.open( IO_WriteOnly ) )
326 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
327 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
335 // zip tmpdir to destination
336 zipDir (tmpDir,outputFile);
339 bool ExportOO::setConfigFile (const QString &cf)
342 int i=cf.findRev ("/");
343 if (i>=0) configDir=cf.left(i);
345 set.readSettings(configFile);
348 templateDir=configDir+"/"+set.readEntry ("Template");
350 QDir d (templateDir);
353 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
358 contentTemplateFile=templateDir+"content-template.xml";
359 contentFile=tmpDir.path()+"/content.xml";
360 pageTemplateFile=templateDir+"page-template.xml";
361 sectionTemplateFile=templateDir+"section-template.xml";
363 if (set.readEntry("useSections").contains("yes"))
366 // Copy template to tmpdir
367 system ("cp -r "+templateDir+"* "+tmpDir.path());
369 // Read content-template
370 if (!loadStringFromDisk (contentTemplateFile,content))
372 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
376 // Read page-template
377 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
379 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
383 // Read section-template
384 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
386 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));