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 =curIndent + bo->getNoteASCII( curIndent, 80);
189 s=s.replace ("\n","\n"+curIndent);
190 ts << QString (s+"\n");
198 QString ExportASCII::underline (const QString &text, const QString &line)
200 QString r=text + "\n";
201 for (int j=0;j<text.length();j++) r+=line;
206 ////////////////////////////////////////////////////////////////////////
207 void ExportCSV::doExport()
209 QFile file (outputFile);
210 if ( !file.open( QIODevice::WriteOnly ) )
212 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
215 QTextStream ts( &file ); // use LANG decoding here...
218 ts << "\"Note\"" <<endl;
220 // Main loop over all branches
222 QString curIndent("");
228 if (!bo->hasHiddenExportParent() )
230 // If necessary, write note
231 if (!bo->getNote().isEmpty())
233 s =bo->getNoteASCII();
234 s=s.replace ("\n","\n"+curIndent);
235 ts << ("\""+s+"\",");
240 for (i=0;i<bo->getDepth();i++) curIndent+= "\"\",";
243 ts << curIndent << "\"" << bo->getHeading()<<"\""<<endl;
252 ////////////////////////////////////////////////////////////////////////
253 void ExportKDEBookmarks::doExport()
255 MapEditor *me=model->getMapEditor();
259 dia.showCancelButton (true);
260 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
261 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
262 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
263 if (dia.exec()==QDialog::Accepted)
265 me->exportXML(tmpDir.path(),false);
268 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
269 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
270 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
273 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
274 QProcess *proc= new QProcess ;
276 if (!proc->waitForStarted())
278 QMessageBox::warning(0,
279 QObject::tr("Warning"),
280 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
287 ////////////////////////////////////////////////////////////////////////
288 void ExportFirefoxBookmarks::doExport()
290 MapEditor *me=model->getMapEditor();
294 dia.showCancelButton (true);
295 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
296 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
297 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
298 if (dia.exec()==QDialog::Accepted)
300 me->exportXML(tmpDir.path(),false);
304 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
305 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
306 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
309 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
310 QProcess *proc = new QProcess( );
311 proc->addArgument(ub);
313 if ( !proc->start() )
315 QMessageBox::warning(0,
316 QObject::tr("Warning"),
317 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
326 ////////////////////////////////////////////////////////////////////////
327 void ExportTaskjuggler::doExport()
329 MapEditor *me=model->getMapEditor();
332 me->exportXML(tmpDir.path(),false);
335 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
336 p.setOutputFile (outputFile);
337 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
343 ////////////////////////////////////////////////////////////////////////
344 void ExportLaTeX::doExport()
346 // Exports a map to a LaTex file.
347 // This file needs to be included
348 // or inported into a LaTex document
349 // it will not add a preamble, or anything
350 // that makes a full LaTex document.
351 QFile file (outputFile);
352 if ( !file.open( QIODevice::WriteOnly ) ) {
353 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
354 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
357 QTextStream ts( &file ); // use LANG decoding here...
358 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
360 // Main loop over all branches
362 // QString curIndent("");
367 if (!bo->hasHiddenExportParent() )
369 if (bo->getDepth()==0);
370 else if (bo->getDepth()==1) {
371 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
373 else if (bo->getDepth()==2) {
374 ts << ("\\section{" + bo->getHeading()+ "}\n");
376 else if (bo->getDepth()==3) {
377 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
379 else if (bo->getDepth()==4) {
380 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
383 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
386 // If necessary, write note
387 if (!bo->getNote().isEmpty()) {
388 ts << (bo->getNoteASCII());
397 ////////////////////////////////////////////////////////////////////////
403 ExportOO::~ExportOO()
407 QString ExportOO::buildList (BranchObj *current)
413 bo=current->getFirstBranch();
416 if (!bo->hasHiddenExportParent() )
419 r+="<text:list text:style-name=\"vym-list\">\n";
422 r+="<text:list-item><text:p >";
423 r+=quotemeta(bo->getHeading());
424 // If necessary, write note
425 if (!bo->getNote().isEmpty())
426 r+=bo->getNoteOpenDoc();
428 r+=buildList (bo); // recursivly add deeper branches
429 r+="</text:list-item>\n";
431 bo=current->getBranchNum(i);
440 void ExportOO::exportPresentation()
444 /* FIXME not adapted to multiple mapCenters yet
445 // Insert new content
446 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
447 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
452 BranchObj *sectionBO=mapCenter->getFirstBranch();
458 while (sectionBO && !sectionBO->hasHiddenExportParent() )
462 // Add page with section title
463 onePage=sectionTemplate;
464 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
468 i=-2; // only use inner loop to
469 // turn mainbranches into pages
474 pagesBO=sectionBO->getFirstBranch();
476 while (pagesBO && !pagesBO->hasHiddenExportParent() )
478 // Add page with list of items
479 onePage=pageTemplate;
480 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
481 list=buildList (pagesBO);
482 onePage.replace ("<!-- INSERT LIST -->", list);
485 pagesBO=sectionBO->getBranchNum(j);
488 sectionBO=mapCenter->getBranchNum(i);
491 content.replace ("<!-- INSERT PAGES -->",allPages);
493 // Write modified content
494 QFile f (contentFile);
495 if ( !f.open( QIODevice::WriteOnly ) )
497 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
498 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
506 // zip tmpdir to destination
507 zipDir (tmpDir,outputFile);
511 bool ExportOO::setConfigFile (const QString &cf)
514 int i=cf.findRev ("/");
515 if (i>=0) configDir=cf.left(i);
517 set.readSettings(configFile);
520 templateDir=configDir+"/"+set.readEntry ("Template");
522 QDir d (templateDir);
525 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
530 contentTemplateFile=templateDir+"content-template.xml";
531 contentFile=tmpDir.path()+"/content.xml";
532 pageTemplateFile=templateDir+"page-template.xml";
533 sectionTemplateFile=templateDir+"section-template.xml";
535 if (set.readEntry("useSections").contains("yes"))
538 // Copy template to tmpdir
539 system ("cp -r "+templateDir+"* "+tmpDir.path());
541 // Read content-template
542 if (!loadStringFromDisk (contentTemplateFile,content))
544 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
548 // Read page-template
549 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
551 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
555 // Read section-template
556 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
558 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));