3 #include "linkablemapobj.h"
5 #include "mainwindow.h"
6 #include "warningdialog.h"
9 extern Main *mainWindow;
10 extern QDir vymBaseDir;
11 extern QString vymName;
13 ExportBase::ExportBase()
17 tmpDir.setPath (makeTmpDir(ok,"vym-export"));
18 if (!tmpDir.exists() || !ok)
19 QMessageBox::critical( 0, QObject::tr( "Error" ),
20 QObject::tr("Couldn't access temporary directory\n"));
24 ExportBase::~ExportBase()
30 void ExportBase::setDir(const QDir &d)
35 void ExportBase::setFile (const QString &p)
40 QString ExportBase::getFile ()
45 void ExportBase::setModel(VymModel *m)
50 void ExportBase::setCaption (const QString &s)
55 void ExportBase::addFilter(const QString &s)
60 bool ExportBase::execDialog()
62 //MapEditor *me=model.getMapEditor(); FIXME needed?
63 // if (model->mapCenters.count() && me)
65 QFileDialog *fd=new QFileDialog( 0, caption);
66 fd->setFilter (filter);
67 fd->setCaption(caption);
68 fd->setMode( QFileDialog::AnyFile );
72 if ( fd->exec() == QDialog::Accepted )
74 if (QFile (fd->selectedFile()).exists() )
76 QMessageBox mb( vymName,
77 QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
79 QMessageBox::Yes | QMessageBox::Default,
80 QMessageBox::Cancel | QMessageBox::Escape,
82 mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
83 mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
87 case QMessageBox::Yes:
90 case QMessageBox::Cancel:
96 outputFile=fd->selectedFile();
104 bool ExportBase::canceled()
109 QString ExportBase::getSectionString(BranchObj *bostart)
111 // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
113 BranchObj *bo=bostart;
114 int depth=bo->getDepth();
117 r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
118 bo=(BranchObj*)(bo->getParObj());
119 depth=bo->getDepth();
127 ////////////////////////////////////////////////////////////////////////
128 ExportASCII::ExportASCII()
130 filter="TXT (*.txt)";
131 caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
134 void ExportASCII::doExport()
136 QFile file (outputFile);
137 if ( !file.open( QIODevice::WriteOnly ) )
139 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
142 QTextStream ts( &file ); // use LANG decoding here...
144 // Main loop over all branches
154 for (i=0;i<bo->getDepth()-1;i++) curIndent+= indentPerDepth;
156 if (!bo->hasHiddenExportParent() )
158 switch (bo->getDepth())
161 ts << underline (bo->getHeading(),QString("="));
166 ts << (underline (getSectionString(bo) + bo->getHeading(), QString("-") ) );
171 ts << (curIndent + "* " + bo->getHeading());
175 ts << (curIndent + "- " + bo->getHeading());
179 ts << (curIndent + "- " + bo->getHeading());
184 // If necessary, write note
185 if (!bo->getNote().isEmpty())
188 s=bo->getNoteASCII( curIndent, 80);
197 QString ExportASCII::underline (const QString &text, const QString &line)
199 QString r=text + "\n";
200 for (int j=0;j<text.length();j++) r+=line;
205 ////////////////////////////////////////////////////////////////////////
206 void ExportCSV::doExport()
208 QFile file (outputFile);
209 if ( !file.open( QIODevice::WriteOnly ) )
211 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
214 QTextStream ts( &file ); // use LANG decoding here...
217 ts << "\"Note\"" <<endl;
219 // Main loop over all branches
221 QString curIndent("");
227 if (!bo->hasHiddenExportParent() )
229 // If necessary, write note
230 if (!bo->getNote().isEmpty())
232 s =bo->getNoteASCII();
233 s=s.replace ("\n","\n"+curIndent);
234 ts << ("\""+s+"\",");
239 for (i=0;i<bo->getDepth();i++) curIndent+= "\"\",";
242 ts << curIndent << "\"" << bo->getHeading()<<"\""<<endl;
251 ////////////////////////////////////////////////////////////////////////
252 void ExportKDEBookmarks::doExport()
254 MapEditor *me=model->getMapEditor();
258 dia.showCancelButton (true);
259 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
260 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
261 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
262 if (dia.exec()==QDialog::Accepted)
264 me->exportXML(tmpDir.path(),false);
267 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
268 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
269 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
272 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
273 QProcess *proc= new QProcess ;
275 if (!proc->waitForStarted())
277 QMessageBox::warning(0,
278 QObject::tr("Warning"),
279 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
286 ////////////////////////////////////////////////////////////////////////
287 void ExportFirefoxBookmarks::doExport()
289 MapEditor *me=model->getMapEditor();
293 dia.showCancelButton (true);
294 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
295 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
296 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
297 if (dia.exec()==QDialog::Accepted)
299 me->exportXML(tmpDir.path(),false);
303 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
304 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
305 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
308 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
309 QProcess *proc = new QProcess( );
310 proc->addArgument(ub);
312 if ( !proc->start() )
314 QMessageBox::warning(0,
315 QObject::tr("Warning"),
316 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
325 ////////////////////////////////////////////////////////////////////////
326 void ExportTaskjuggler::doExport()
328 MapEditor *me=model->getMapEditor();
331 me->exportXML(tmpDir.path(),false);
334 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
335 p.setOutputFile (outputFile);
336 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
342 ////////////////////////////////////////////////////////////////////////
343 void ExportLaTeX::doExport()
345 // Exports a map to a LaTex file.
346 // This file needs to be included
347 // or inported into a LaTex document
348 // it will not add a preamble, or anything
349 // that makes a full LaTex document.
350 QFile file (outputFile);
351 if ( !file.open( QIODevice::WriteOnly ) ) {
352 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
353 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
356 QTextStream ts( &file ); // use LANG decoding here...
357 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
359 // Main loop over all branches
361 // QString curIndent("");
366 if (!bo->hasHiddenExportParent() )
368 if (bo->getDepth()==0);
369 else if (bo->getDepth()==1) {
370 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
372 else if (bo->getDepth()==2) {
373 ts << ("\\section{" + bo->getHeading()+ "}\n");
375 else if (bo->getDepth()==3) {
376 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
378 else if (bo->getDepth()==4) {
379 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
382 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
385 // If necessary, write note
386 if (!bo->getNote().isEmpty()) {
387 ts << (bo->getNoteASCII());
396 ////////////////////////////////////////////////////////////////////////
402 ExportOO::~ExportOO()
406 QString ExportOO::buildList (BranchObj *current)
412 bo=current->getFirstBranch();
415 if (!bo->hasHiddenExportParent() )
418 r+="<text:list text:style-name=\"vym-list\">\n";
421 r+="<text:list-item><text:p >";
422 r+=quotemeta(bo->getHeading());
423 // If necessary, write note
424 if (!bo->getNote().isEmpty())
425 r+=bo->getNoteOpenDoc();
427 r+=buildList (bo); // recursivly add deeper branches
428 r+="</text:list-item>\n";
430 bo=current->getBranchNum(i);
439 void ExportOO::exportPresentation()
443 /* FIXME not adapted to multiple mapCenters yet
444 // Insert new content
445 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
446 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
451 BranchObj *sectionBO=mapCenter->getFirstBranch();
457 while (sectionBO && !sectionBO->hasHiddenExportParent() )
461 // Add page with section title
462 onePage=sectionTemplate;
463 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
467 i=-2; // only use inner loop to
468 // turn mainbranches into pages
473 pagesBO=sectionBO->getFirstBranch();
475 while (pagesBO && !pagesBO->hasHiddenExportParent() )
477 // Add page with list of items
478 onePage=pageTemplate;
479 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
480 list=buildList (pagesBO);
481 onePage.replace ("<!-- INSERT LIST -->", list);
484 pagesBO=sectionBO->getBranchNum(j);
487 sectionBO=mapCenter->getBranchNum(i);
490 content.replace ("<!-- INSERT PAGES -->",allPages);
492 // Write modified content
493 QFile f (contentFile);
494 if ( !f.open( QIODevice::WriteOnly ) )
496 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
497 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
505 // zip tmpdir to destination
506 zipDir (tmpDir,outputFile);
510 bool ExportOO::setConfigFile (const QString &cf)
513 int i=cf.findRev ("/");
514 if (i>=0) configDir=cf.left(i);
516 set.readSettings(configFile);
519 templateDir=configDir+"/"+set.readEntry ("Template");
521 QDir d (templateDir);
524 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
529 contentTemplateFile=templateDir+"content-template.xml";
530 contentFile=tmpDir.path()+"/content.xml";
531 pageTemplateFile=templateDir+"page-template.xml";
532 sectionTemplateFile=templateDir+"section-template.xml";
534 if (set.readEntry("useSections").contains("yes"))
537 // Copy template to tmpdir
538 system ("cp -r "+templateDir+"* "+tmpDir.path());
540 // Read content-template
541 if (!loadStringFromDisk (contentTemplateFile,content))
543 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
547 // Read page-template
548 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
550 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
554 // Read section-template
555 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
557 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));