1 #include <qfiledialog.h>
2 #include <qmessagebox.h>
7 #include "linkablemapobj.h"
9 #include "mainwindow.h"
10 #include "warningdialog.h"
13 extern Main *mainWindow;
14 extern QDir vymBaseDir;
17 ExportBase::ExportBase()
21 tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
24 ExportBase::~ExportBase()
30 void ExportBase::setDir(const QString &p)
35 void ExportBase::setFile (const QString &p)
40 void ExportBase::setMapCenter(MapCenterObj *mc)
45 void ExportBase::setCaption (const QString &s)
50 void ExportBase::addFilter(const QString &s)
55 bool ExportBase::execDialog()
57 if (mapCenter && mapCenter->getMapEditor())
59 QFileDialog *fd=new QFileDialog( mapCenter->getMapEditor(), caption);
60 fd->addFilter (filter);
61 fd->setCaption(caption);
62 fd->setMode( QFileDialog::AnyFile );
65 if ( fd->exec() == QDialog::Accepted )
67 if (QFile (fd->selectedFile()).exists() )
69 QMessageBox mb( __VYM,
70 QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
72 QMessageBox::Yes | QMessageBox::Default,
73 QMessageBox::Cancel | QMessageBox::Escape,
74 QMessageBox::NoButton );
75 mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
76 mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
80 case QMessageBox::Yes:
83 case QMessageBox::Cancel:
89 outputFile=fd->selectedFile();
96 QString ExportBase::getSectionString(BranchObj *bostart)
98 // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
100 BranchObj *bo=bostart;
101 int depth=bo->getDepth();
104 r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
105 bo=(BranchObj*)(bo->getParObj());
106 depth=bo->getDepth();
115 ////////////////////////////////////////////////////////////////////////
116 void ExportASCII::doExport()
118 QFile file (outputFile);
119 if ( !file.open( IO_WriteOnly ) )
121 // FIXME experimental, testing
122 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
125 QTextStream ts( &file ); // use LANG decoding here...
127 // Main loop over all branches
129 QString actIndent("");
133 bo=mapCenter->first();
137 for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
139 if (bo->getDepth()==0)
141 ts << (bo->getHeading()+ "\n");
142 for (j=0;j<bo->getHeading().length();j++) ts<<"=";
144 } else if (bo->getDepth()==1)
145 ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
146 else if (bo->getDepth()==2)
147 ts << (actIndent + " o " + bo->getHeading()+ "\n");
149 ts << (actIndent + " - " + bo->getHeading()+ "\n");
151 // If necessary, write note
152 if (!bo->getNote().isEmpty())
154 s =bo->getNoteASCII();
155 s=s.replace ("\n","\n"+actIndent);
164 ////////////////////////////////////////////////////////////////////////
165 void ExportKDEBookmarks::doExport()
168 if (mapCenter) me=mapCenter->getMapEditor();
172 dia.setCancelButton (true);
173 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
174 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
175 dia.setShowAgainName("/vym/warnings/overwriteKDEBookmarks");
176 if (dia.exec()==QDialog::Accepted)
178 me->exportXML(tmpDir.path());
181 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
182 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
183 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
186 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
187 QProcess *proc = new QProcess( );
188 proc->addArgument(ub);
190 if ( !proc->start() )
192 QMessageBox::warning(0,
193 QObject::tr("Warning"),
194 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
203 ////////////////////////////////////////////////////////////////////////
204 void ExportFirefoxBookmarks::doExport()
207 if (mapCenter) me=mapCenter->getMapEditor();
211 dia.setCancelButton (true);
212 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
213 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
214 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
215 if (dia.exec()==QDialog::Accepted)
217 me->exportXML(tmpDir.path());
221 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
222 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
223 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
226 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
227 QProcess *proc = new QProcess( );
228 proc->addArgument(ub);
230 if ( !proc->start() )
232 QMessageBox::warning(0,
233 QObject::tr("Warning"),
234 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
243 ////////////////////////////////////////////////////////////////////////
244 void ExportTaskjuggler::doExport()
247 if (mapCenter) me=mapCenter->getMapEditor();
250 me->exportXML(tmpDir.path());
252 cout << "tmpDir="<<tmpDir.path()<<endl;
255 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
256 p.setOutputFile (outputFile);
257 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
263 ////////////////////////////////////////////////////////////////////////
264 void ExportLaTeX::doExport()
266 // Exports a map to a LaTex file.
267 // This file needs to be included
268 // or inported into a LaTex document
269 // it will not add a preamble, or anything
270 // that makes a full LaTex document.
271 QFile file (outputFile);
272 if ( !file.open( IO_WriteOnly ) ) {
273 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
274 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
277 QTextStream ts( &file ); // use LANG decoding here...
278 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
280 // Main loop over all branches
282 // QString actIndent("");
285 bo=mapCenter->first();
287 if (bo->getDepth()==0);
288 else if (bo->getDepth()==1) {
289 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
291 else if (bo->getDepth()==2) {
292 ts << ("\\section{" + bo->getHeading()+ "}\n");
294 else if (bo->getDepth()==3) {
295 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
297 else if (bo->getDepth()==4) {
298 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
301 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
304 // If necessary, write note
305 if (!bo->getNote().isEmpty()) {
306 ts << (bo->getNoteASCII());
314 ////////////////////////////////////////////////////////////////////////
320 ExportOO::~ExportOO()
324 QString ExportOO::buildList (BranchObj *current)
330 bo=current->getFirstBranch();
334 r+="<text:list text:style-name=\"vym-list\">\n";
337 r+="<text:list-item><text:p >";
338 r+=quotemeta(bo->getHeading());
339 // If necessary, write note
340 if (!bo->getNote().isEmpty())
341 r+=bo->getNoteOpenDoc();
343 r+=buildList (bo); // recursivly add deeper branches
344 r+="</text:list-item>\n";
346 bo=current->getBranchNum(i);
354 void ExportOO::exportPresentation()
358 // Insert new content
359 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
360 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
365 BranchObj *sectionBO=mapCenter->getFirstBranch();
375 // Add page with section title
376 onePage=sectionTemplate;
377 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
381 i=-2; // only use inner loop to
382 // turn mainbranches into pages
387 pagesBO=sectionBO->getFirstBranch();
391 // Add page with list of items
392 onePage=pageTemplate;
393 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
394 list=buildList (pagesBO);
395 onePage.replace ("<!-- INSERT LIST -->", list);
398 pagesBO=sectionBO->getBranchNum(j);
401 sectionBO=mapCenter->getBranchNum(i);
404 content.replace ("<!-- INSERT PAGES -->",allPages);
406 // Write modified content
407 QFile f (contentFile);
408 if ( !f.open( IO_WriteOnly ) )
410 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
411 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
419 // zip tmpdir to destination
420 zipDir (tmpDir,outputFile);
423 bool ExportOO::setConfigFile (const QString &cf)
426 int i=cf.findRev ("/");
427 if (i>=0) configDir=cf.left(i);
429 set.readSettings(configFile);
432 templateDir=configDir+"/"+set.readEntry ("Template");
434 QDir d (templateDir);
437 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
442 contentTemplateFile=templateDir+"content-template.xml";
443 contentFile=tmpDir.path()+"/content.xml";
444 pageTemplateFile=templateDir+"page-template.xml";
445 sectionTemplateFile=templateDir+"section-template.xml";
447 if (set.readEntry("useSections").contains("yes"))
450 // Copy template to tmpdir
451 system ("cp -r "+templateDir+"* "+tmpDir.path());
453 // Read content-template
454 if (!loadStringFromDisk (contentTemplateFile,content))
456 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
460 // Read page-template
461 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
463 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
467 // Read section-template
468 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
470 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));