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 ExportKDE3Bookmarks::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 3"));
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));
285 ////////////////////////////////////////////////////////////////////////
286 void ExportKDE4Bookmarks::doExport()
288 MapEditor *me=model->getMapEditor();
292 dia.showCancelButton (true);
293 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
294 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE 4"));
295 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
296 if (dia.exec()==QDialog::Accepted)
298 me->exportXML(tmpDir.path(),false);
301 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
302 p.setOutputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
303 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
306 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
307 QProcess *proc= new QProcess ;
309 if (!proc->waitForStarted())
311 QMessageBox::warning(0,
312 QObject::tr("Warning"),
313 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
320 ////////////////////////////////////////////////////////////////////////
321 void ExportFirefoxBookmarks::doExport()
323 MapEditor *me=model->getMapEditor();
327 dia.showCancelButton (true);
328 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
329 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
330 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
331 if (dia.exec()==QDialog::Accepted)
333 me->exportXML(tmpDir.path(),false);
337 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
338 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
339 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
342 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
343 QProcess *proc = new QProcess( );
344 proc->addArgument(ub);
346 if ( !proc->start() )
348 QMessageBox::warning(0,
349 QObject::tr("Warning"),
350 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
359 ////////////////////////////////////////////////////////////////////////
360 void ExportTaskjuggler::doExport()
362 MapEditor *me=model->getMapEditor();
365 me->exportXML(tmpDir.path(),false);
368 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
369 p.setOutputFile (outputFile);
370 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
376 ////////////////////////////////////////////////////////////////////////
377 void ExportLaTeX::doExport()
379 // Exports a map to a LaTex file.
380 // This file needs to be included
381 // or inported into a LaTex document
382 // it will not add a preamble, or anything
383 // that makes a full LaTex document.
384 QFile file (outputFile);
385 if ( !file.open( QIODevice::WriteOnly ) ) {
386 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
387 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
390 QTextStream ts( &file ); // use LANG decoding here...
391 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
393 // Main loop over all branches
395 // QString curIndent("");
400 if (!bo->hasHiddenExportParent() )
402 if (bo->getDepth()==0);
403 else if (bo->getDepth()==1) {
404 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
406 else if (bo->getDepth()==2) {
407 ts << ("\\section{" + bo->getHeading()+ "}\n");
409 else if (bo->getDepth()==3) {
410 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
412 else if (bo->getDepth()==4) {
413 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
416 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
419 // If necessary, write note
420 if (!bo->getNote().isEmpty()) {
421 ts << (bo->getNoteASCII());
430 ////////////////////////////////////////////////////////////////////////
436 ExportOO::~ExportOO()
440 QString ExportOO::buildList (BranchObj *current)
446 bo=current->getFirstBranch();
449 if (!bo->hasHiddenExportParent() )
452 r+="<text:list text:style-name=\"vym-list\">\n";
455 r+="<text:list-item><text:p >";
456 r+=quotemeta(bo->getHeading());
457 // If necessary, write note
458 if (!bo->getNote().isEmpty())
459 r+=bo->getNoteOpenDoc();
461 r+=buildList (bo); // recursivly add deeper branches
462 r+="</text:list-item>\n";
464 bo=current->getBranchNum(i);
473 void ExportOO::exportPresentation()
477 MapCenterObj *firstMCO=(MapCenterObj*)model->first();
480 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("No objects in map!"));
484 // Insert new content
485 // FIXME add extra title in mapinfo for vym 1.13.x
486 content.replace ("<!-- INSERT TITLE -->",quotemeta(firstMCO->getHeading()));
487 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(model->getAuthor()));
492 BranchObj *sectionBO;
497 int mapcenters=model->countMapCenters();
499 // useSections already has been set in setConfigFile
503 sectionBO=firstMCO->getFirstBranch();
506 while (sectionBO && !sectionBO->hasHiddenExportParent() )
510 // Add page with section title
511 onePage=sectionTemplate;
512 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
514 pagesBO=sectionBO->getFirstBranch();
517 //i=-2; // only use inner loop to
518 // turn mainbranches into pages
519 //sectionBO=firstMCO;
524 while (pagesBO && !pagesBO->hasHiddenExportParent() )
526 // Add page with list of items
527 onePage=pageTemplate;
528 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
529 list=buildList (pagesBO);
530 onePage.replace ("<!-- INSERT LIST -->", list);
532 if (pagesBO!=sectionBO)
535 pagesBO=((BranchObj*)pagesBO->getParObj())->getBranchNum(j);
537 pagesBO=NULL; // We are already iterating over the sectionBOs
541 sectionBO=model->getMapCenterNum (i);
543 sectionBO=firstMCO->getBranchNum (i);
546 content.replace ("<!-- INSERT PAGES -->",allPages);
548 // Write modified content
549 QFile f (contentFile);
550 if ( !f.open( QIODevice::WriteOnly ) )
552 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
553 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
561 // zip tmpdir to destination
562 zipDir (tmpDir,outputFile);
565 bool ExportOO::setConfigFile (const QString &cf)
568 int i=cf.findRev ("/");
569 if (i>=0) configDir=cf.left(i);
571 set.readSettings(configFile);
574 templateDir=configDir+"/"+set.readEntry ("Template");
576 QDir d (templateDir);
579 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
584 contentTemplateFile=templateDir+"content-template.xml";
585 contentFile=tmpDir.path()+"/content.xml";
586 pageTemplateFile=templateDir+"page-template.xml";
587 sectionTemplateFile=templateDir+"section-template.xml";
589 if (model->countMapCenters()>1 ||set.readEntry("useSections").contains("yes"))
592 // Copy template to tmpdir
593 system ("cp -r "+templateDir+"* "+tmpDir.path());
595 // Read content-template
596 if (!loadStringFromDisk (contentTemplateFile,content))
598 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
602 // Read page-template
603 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
605 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
609 // Read section-template
610 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
612 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));