9 #include "branchitem.h"
11 #include "linkablemapobj.h"
13 #include "mainwindow.h"
14 #include "warningdialog.h"
16 #include "vymprocess.h"
19 extern Main *mainWindow;
20 extern QDir vymBaseDir;
21 extern QString flagsPath;
22 extern QString vymName;
23 extern QString vymVersion;
24 extern QString vymHome;
25 extern Settings settings;
26 extern QDir lastExportDir;
28 ExportBase::ExportBase()
33 ExportBase::ExportBase(VymModel *m)
39 ExportBase::~ExportBase()
44 // Remember current directory
45 lastExportDir = QDir(dirPath);
48 void ExportBase::init()
51 exportName = "unnamed";
54 tmpDir.setPath (makeTmpDir(ok,"vym-export"));
55 if (!tmpDir.exists() || !ok)
56 QMessageBox::critical( 0, QObject::tr( "Error" ),
57 QObject::tr("Couldn't access temporary directory\n"));
59 defaultDirPath = lastExportDir.absolutePath();
60 dirPath = defaultDirPath;
63 void ExportBase::setDirPath (const QString &s)
67 // Otherwise lastExportDir is used, which defaults to current dir
70 QString ExportBase::getDirPath()
75 void ExportBase::setFilePath (const QString &s)
80 if (!filePath.contains("/"))
82 filePath=lastExportDir.absolutePath() + "/" + filePath;
86 QString ExportBase::getFilePath ()
88 if (!filePath.isEmpty())
91 return dirPath + "/" + model->getMapName() + extension;
94 QString ExportBase::getMapName ()
96 QString fn=basename(filePath);
97 return fn.left(fn.lastIndexOf("."));
100 void ExportBase::setModel(VymModel *m)
105 void ExportBase::setWindowTitle (const QString &s)
110 void ExportBase::setName (const QString &s)
115 QString ExportBase::getName ()
120 void ExportBase::addFilter(const QString &s)
125 void ExportBase::setListTasks(bool b)
130 bool ExportBase::execDialog()
132 QString fn=QFileDialog::getSaveFileName(
138 QFileDialog::DontConfirmOverwrite);
142 if (QFile (fn).exists() )
145 dia.showCancelButton (true);
146 dia.setCaption(QObject::tr("Warning: Overwriting file"));
147 dia.setText(QObject::tr("Exporting to %1 will overwrite the existing file:\n%2").arg(exportName).arg(fn));
148 dia.setShowAgainName("/exports/overwrite/" + exportName);
149 if (!(dia.exec()==QDialog::Accepted))
155 dirPath=fn.left(fn.lastIndexOf ("/"));
162 bool ExportBase::canceled()
167 void ExportBase::setLastCommand( const QString &s)
172 void ExportBase::completeExport(QString args)
176 // Add at least filepath as argument. exportName is added anyway
177 command = QString("export%1(\"%2\")").arg(exportName).arg(filePath);
178 // new syntax: command = QString("vym.currentMap().exportMap(\"%1\",\"%2\")").arg(exportName).arg(filePath);
180 command = QString("export%1(%2)").arg(exportName).arg(args);
181 // new syntax: command = QString("vym.currentMap().exportMap(\"%1\",%2)").arg(exportName).arg(args);
183 settings.setLocalValue ( model->getFilePath(), "/export/last/exportPath", filePath);
184 settings.setLocalValue ( model->getFilePath(), "/export/last/command", command);
185 settings.setLocalValue ( model->getFilePath(), "/export/last/description", exportName);
187 // Trigger saving of export command if it has changed
188 if (model && (lastCommand != command) ) model->setChanged();
190 mainWindow->statusMessage(QString("Exported as %1: %2").arg(exportName).arg(filePath));
193 QString ExportBase::getSectionString(TreeItem *start)
195 // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
198 int depth=ti->depth();
201 r=QString("%1").arg(1+ti->num(),0,10)+"." + r;
211 QString ExportBase::indent (const int &n, bool useBullet)
214 for (int i=0; i<n; i++) s += indentPerDepth;
215 if (useBullet && s.length() >= 2 && bulletPoints.count() > n)
216 s.replace( s.length() - 2, 1, bulletPoints.at(n) );
220 ////////////////////////////////////////////////////////////////////////
224 filter="TXT (*.txt);;All (* *.*)";
225 caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
227 bulletPoints.clear();
228 for (int i=0; i<10; i++)
232 void ExportAO::doExport()
234 QFile file (filePath);
235 if ( !file.open( QIODevice::WriteOnly ) )
237 QMessageBox::critical (0, QObject::tr("Critical Export Error"), QObject::tr("Could not export as AO to %1").arg(filePath));
238 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
242 settings.setLocalValue ( model->getFilePath(), "/export/last/command","exportAO");
243 settings.setLocalValue ( model->getFilePath(), "/export/last/description","A&O report");
245 QTextStream ts( &file );
246 ts.setCodec("UTF-8");
248 // Main loop over all branches
254 BranchItem *cur=NULL;
255 BranchItem *prev=NULL;
257 model->nextBranch (cur,prev);
261 QString colString="";
263 QString statusString ="";
266 if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
269 curIndent=indent(cur->depth()-4,true);
271 if (!cur->hasHiddenExportParent() )
273 col=cur->getHeadingColor();
274 if (col==QColor (255,0,0))
276 else if (col==QColor (217,81,0))
278 else if (col==QColor (0,85,0))
280 else if (cur->depth()==4)
285 noColString=QString(" ").repeated(colString.length() );
288 switch (cur->depth())
290 case 0: break; // Mapcenter (Ignored)
291 case 1: break; // Mainbranch "Archive" (Ignored)
292 case 2: // Title: "Current week number..."
294 ts << underline ( cur->getHeadingPlain(), QString("=") );
297 case 3: // Headings: "Achievement", "Bonus", "Objective", ...
299 ts << underline ( cur->getHeadingPlain(), "-");
302 default: // depth 4 and higher are the items we need to know
303 Task *task=cur->getTask();
306 // Task status overrides other flags
307 switch ( task->getStatus() )
309 case Task::NotStarted:
310 statusString="[NOT STARTED]";
313 statusString="[WIP]";
316 statusString="[DONE]";
321 if (cur->hasActiveStandardFlag ("hook-green") )
322 statusString="[DONE]";
323 else if (cur->hasActiveStandardFlag ("wip"))
324 statusString="[WIP]";
325 else if (cur->hasActiveStandardFlag ("cross-red"))
326 statusString="[NOT STARTED]";
332 line += cur->getHeadingPlain();
334 // Pad line width before status
335 i = 80 - line.length() - statusString.length() -1;
336 for (int j=0; j<i; j++) line += " ";
337 line += " " + statusString + "\n";
341 // If necessary, write URL
342 if (!cur->getURL().isEmpty())
343 ts << noColString << indent(cur->depth()-4, false) + cur->getURL() + "\n";
345 // If necessary, write note
346 if (!cur->isNoteEmpty())
348 curIndent = noColString + indent(cur->depth()-4,false) + "| ";
349 s=cur->getNoteASCII( curIndent, 80);
356 model->nextBranch(cur,prev);
362 QString ExportAO::underline (const QString &text, const QString &line)
364 QString r=text + "\n";
365 for (int j=0;j<text.length();j++) r+=line;
370 ////////////////////////////////////////////////////////////////////////
371 ExportASCII::ExportASCII()
373 exportName = "ASCII";
374 filter = "TXT (*.txt);;All (* *.*)";
375 caption = vymName + " -" + QObject::tr("Export as ASCII");
378 void ExportASCII::doExport()
380 QFile file (filePath);
381 if ( !file.open( QIODevice::WriteOnly ) )
383 QMessageBox::critical (0, QObject::tr("Critical Export Error"), QObject::tr("Could not export as ASCII to %1").arg(filePath));
384 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
387 QTextStream ts( &file );
388 ts.setCodec("UTF-8");
390 // Main loop over all branches
395 BranchItem *cur=NULL;
396 BranchItem *prev=NULL;
402 model->nextBranch (cur,prev);
405 if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
407 // Insert newline after previous list
408 if ( cur->depth() < lastDepth ) ts << "\n";
412 for (i=1;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
414 if (!cur->hasHiddenExportParent() )
416 //qDebug() << "ExportASCII:: "<<curIndent.toStdString()<<cur->getHeadingPlain().toStdString();
419 switch (cur->depth())
422 ts << underline (cur->getHeadingPlain(),QString("="));
427 ts << (underline (getSectionString(cur) + cur->getHeadingPlain(), QString("-") ) );
432 ts << (curIndent + "* " + cur->getHeadingPlain());
437 ts << (curIndent + "- " + cur->getHeadingPlain());
442 ts << (curIndent + "- " + cur->getHeadingPlain());
448 // If there is a task, save it for potential later display
449 if (listTasks && cur->getTask() )
451 tasks.append( QString("[%1]: %2").arg(cur->getTask()->getStatusString()).arg(cur->getHeadingPlain() ) );
454 // If necessary, write URL
455 if (!cur->getURL().isEmpty())
456 ts << (curIndent + dashIndent + cur->getURL()) +"\n";
458 // If necessary, write vymlink
459 if (!cur->getVymLink().isEmpty())
460 ts << (curIndent + dashIndent + cur->getVymLink()) +" (vym mindmap)\n";
462 // If necessary, write note
463 if (!cur->isNoteEmpty())
465 // curIndent +=" | ";
466 // Only indent for bullet points
467 if (cur->depth() > 2) curIndent +=" ";
468 ts << '\n' + cur->getNoteASCII(curIndent, 80) ;
470 lastDepth = cur->depth();
473 model->nextBranch(cur,prev);
478 ts << "\n\nTasks\n-----\n\n";
481 foreach (QString t, tasks)
483 ts << " - " << t << "\n";
488 QString listTasksString = listTasks ? "true" : "false";
489 completeExport( QString("\"%1\",%2").arg(filePath).arg(listTasksString) );
492 QString ExportASCII::underline (const QString &text, const QString &line)
494 QString r=text + "\n";
495 for (int j=0;j<text.length();j++) r+=line;
500 ////////////////////////////////////////////////////////////////////////
501 ExportCSV::ExportCSV()
504 filter="CSV (*.csv);;All (* *.*)";
505 caption=vymName+ " -" +QObject::tr("Export as CSV");
508 void ExportCSV::doExport()
510 QFile file (filePath);
511 if ( !file.open( QIODevice::WriteOnly ) )
513 QMessageBox::critical (0, QObject::tr("Critical Export Error"), QObject::tr("Could not export as CSV to %1").arg(filePath));
514 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
517 QTextStream ts( &file );
518 ts.setCodec("UTF-8");
521 ts << "\"Note\"" <<endl;
523 // Main loop over all branches
525 QString curIndent("");
527 BranchItem *cur=NULL;
528 BranchItem *prev=NULL;
529 model->nextBranch (cur,prev);
532 if (!cur->hasHiddenExportParent() )
534 // If necessary, write note
535 if (!cur->isNoteEmpty())
537 s =cur->getNoteASCII();
538 s=s.replace ("\n","\n"+curIndent);
539 ts << ("\""+s+"\",");
544 for (i=0;i<cur->depth();i++) curIndent+= "\"\",";
547 ts << curIndent << "\"" << cur->getHeadingPlain()<<"\""<<endl;
550 model->nextBranch(cur,prev);
557 ////////////////////////////////////////////////////////////////////////
558 void ExportKDE4Bookmarks::doExport()
561 dia.showCancelButton (true);
562 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE 4"));
563 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
564 dia.setShowAgainName("/exports/overwrite/KDE4Bookmarks");
565 if (dia.exec()==QDialog::Accepted)
567 model->exportXML("",tmpDir.path(),false);
570 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
571 p.setOutputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
572 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
575 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
576 QProcess *proc= new QProcess ;
578 if (!proc->waitForStarted())
580 QMessageBox::warning(0,
581 QObject::tr("Warning"),
582 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
587 ////////////////////////////////////////////////////////////////////////
588 void ExportFirefoxBookmarks::doExport()
591 dia.showCancelButton (true);
592 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
593 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
594 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
595 if (dia.exec()==QDialog::Accepted)
597 model->exportXML("",tmpDir.path(),false);
601 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
602 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
603 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
606 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
607 QProcess *proc = new QProcess( );
608 proc->addArgument(ub);
610 if ( !proc->start() )
612 QMessageBox::warning(0,
613 QObject::tr("Warning"),
614 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
621 ////////////////////////////////////////////////////////////////////////
622 ExportHTML::ExportHTML():ExportBase()
627 ExportHTML::ExportHTML(VymModel *m):ExportBase(m)
632 void ExportHTML::init()
639 QString ExportHTML::getBranchText(BranchItem *current)
645 LinkableMapObj *lmo = current->getLMO();
648 hr = ((BranchObj*)lmo)->getBBoxHeading();
649 vis = lmo->isVisibleObj();
652 QString id = model->getSelectString(current);
653 if (dia.useTextColor)
654 col = QString("style='color:%1'").arg(current->getHeadingColor().name());
655 QString s = QString("<span class='vym-branch-%1' %2 id='%3'>")
656 .arg(current->depth())
659 QString url = current->getURL();
660 QString heading = quotemeta(current->getHeadingPlain());
664 if (dia.useTaskFlags)
666 Task *task = current->getTask();
669 QString taskName = task->getIconString();
670 taskFlags += QString("<img src=\"flags/flag-%1.png\" alt=\"%2\">")
672 .arg(QObject::tr("Flag: %1","Alt tag in HTML export").arg(taskName));
678 if (dia.useUserFlags)
680 foreach (QString flag, current->activeStandardFlagNames())
681 userFlags += QString("<img src=\"flags/flag-%1.png\" alt=\"%2\">")
683 .arg(QObject::tr("Flag: %1","Alt tag in HTML export").arg(flag));
688 if (dia.useNumbering) number = getSectionString(current) + " ";
693 s += QString ("<a href=\"%1\">%2<img src=\"flags/flag-url.png\" alt=\"%3\"></a>")
695 .arg(number + taskFlags + heading + userFlags)
696 .arg(QObject::tr("Flag: url","Alt tag in HTML export"));
698 QRectF fbox = current->getBBoxURLFlag ();
700 imageMap += QString(" <area shape='rect' coords='%1,%2,%3,%4' href='%5' alt='%6'>\n")
701 .arg(fbox.left() - offset.x())
702 .arg(fbox.top() - offset.y())
703 .arg(fbox.right() - offset.x())
704 .arg(fbox.bottom() - offset.y())
706 .arg(QObject::tr("External link: %1","Alt tag in HTML export").arg(heading));
708 s += number + taskFlags + heading + userFlags;
713 if (vis && dia.includeMapImage)
714 imageMap += QString(" <area shape='rect' coords='%1,%2,%3,%4' href='#%5' alt='%6'>\n")
715 .arg(hr.left() - offset.x())
716 .arg(hr.top() - offset.y())
717 .arg(hr.right() - offset.x())
718 .arg(hr.bottom() - offset.y())
722 // Include images experimental
723 if (dia.includeImages)
725 int imageCount = current->imageCount();
728 for (int i=0; i< imageCount; i++)
730 image = current->getImageNum(i);
731 imagePath = "image-" + image->getUuid().toString() + ".png";
732 image->save( dirPath + "/" + imagePath, "PNG");
733 s += "</br><img src=\"" + imagePath;
734 s += "\" alt=\"" + QObject::tr("Image: %1","Alt tag in HTML export").arg(image->getOriginalFilename());
740 if (!current->isNoteEmpty())
742 VymNote note = current->getNote();
744 if (note.isRichText())
748 re.setMinimal (true);
749 if (current->getNote().getFontHint() == "fixed")
750 n.replace(re,"<p class=\"vym-fixed-note-paragraph\">");
752 n.replace(re,"<p class=\"vym-note-paragraph\">");
754 re.setPattern("</?html>");
757 re.setPattern("</?head.*>");
760 re.setPattern("</?body.*>");
763 re.setPattern("</?meta.*>");
766 re.setPattern("<style.*>.*</style>");
769 //re.setPattern("<!DOCTYPE.*>");
774 n = current->getNoteASCII().replace ("<","<").replace (">",">");
775 n.replace("\n","<br/>");
776 if (current->getNote().getFontHint()=="fixed")
777 n = "<pre>" + n + "</pre>";
779 s += "\n<table class=\"vym-note\"><tr><td class=\"vym-note-flag\">\n<td>\n" + n + "\n</td></tr></table>\n";
786 QString ExportHTML::buildList (BranchItem *current)
793 BranchItem *bi = current->getFirstBranch();
795 QString ind = "\n" + indent(current->depth() + 1, false);
797 QString sectionBegin;
802 switch (current->depth() + 1)
817 sectionBegin = "<ul " + QString("class=\"vym-list-ul-%1\"").arg(current->depth() + 1) +">";
818 sectionEnd = "</ul>";
824 if (bi && !bi->hasHiddenExportParent() && !bi->isHidden() )
826 r += ind + sectionBegin;
829 if (!bi->hasHiddenExportParent() && !bi->isHidden())
832 r += ind + itemBegin;
833 r += getBranchText (bi);
835 if (itemBegin.startsWith("<h") )
836 r += itemEnd + buildList (bi);
838 r += buildList (bi) + itemEnd;
841 bi = current->getBranchNum(i);
843 r += ind + sectionEnd;
849 QString ExportHTML::createTOC()
853 toc += "<table class=\"vym-toc\">\n";
854 toc += "<tr><td class=\"vym-toc-title\">\n";
855 toc += QObject::tr("Contents:","Used in HTML export");
857 toc += "</td></tr>\n";
859 BranchItem *cur = NULL;
860 BranchItem *prev = NULL;
861 model->nextBranch(cur, prev);
864 if (!cur->hasHiddenExportParent() && !cur->hasScrolledParent() )
866 if (dia.useNumbering) number = getSectionString(cur);
867 toc += QString("<div class=\"vym-toc-branch-%1\">").arg(cur->depth());
868 toc += QString("<a href=\"#%1\"> %2 %3</a></br>\n")
869 .arg(model->getSelectString(cur))
871 .arg(quotemeta( cur->getHeadingPlain() ));
874 model->nextBranch(cur,prev);
876 toc += "</td></tr>\n";
881 void ExportHTML::doExport(bool useDialog)
883 // Setup dialog and read settings
884 dia.setMapName (model->getMapName());
885 dia.setFilePath (model->getFilePath());
888 if (dirPath != defaultDirPath)
889 dia.setDirectory(dirPath);
893 if (dia.exec()!=QDialog::Accepted) return;
897 // Check, if warnings should be used before overwriting
898 // the output directory
899 if (dia.getDir().exists() && dia.getDir().count()>0)
902 warn.showCancelButton (true);
903 warn.setText(QString(
904 "The directory %1 is not empty.\n"
905 "Do you risk to overwrite some of its contents?").arg(dia.getDir().absolutePath() ));
906 warn.setCaption("Warning: Directory not empty");
907 warn.setShowAgainName("mainwindow/export-XML-overwrite-dir");
909 if (warn.exec()!=QDialog::Accepted)
911 mainWindow->statusMessage(QString(QObject::tr("Export aborted.")));
916 dirPath=dia.getDir().absolutePath();
917 filePath=getFilePath();
922 cssSrc=dia.getCssSrc();
923 cssDst=dirPath + "/" + basename(dia.getCssDst());
924 if (cssSrc.isEmpty() )
926 QMessageBox::critical( 0,
927 QObject:: tr( "Critical" ),
928 QObject::tr("Could not find stylesheet %1").arg(cssSrc));
933 if (dst.exists() ) dst.remove();
935 if (!src.copy(cssDst))
937 QMessageBox::critical (0,
938 QObject::tr( "Error","ExportHTML" ),
939 QObject::tr("Could not copy\n%1 to\n%2","ExportHTML").arg(cssSrc).arg(cssDst));
945 QDir flagsDst(dia.getDir().absolutePath() + "/flags");
946 if (!flagsDst.exists())
948 if (!dia.getDir().mkdir("flags"))
950 QMessageBox::critical( 0,
951 QObject::tr( "Critical" ),
952 QObject::tr("Trying to create directory for flags:") + "\n\n" +
953 QObject::tr("Could not create %1").arg(flagsDst.absolutePath()));
958 QDir flagsSrc(flagsPath); // FIXME-3 don't use flagsPath as source anymore, but copy required flags directly from memory
959 if (!copyDir(flagsSrc, flagsDst, true))
961 QMessageBox::critical( 0,
962 QObject::tr( "Critical" ),
963 QObject::tr("Could not copy %1 to %2").arg(flagsSrc.absolutePath()).arg(flagsDst.absolutePath()));
967 // Open file for writing
968 QFile file (filePath);
969 if ( !file.open( QIODevice::WriteOnly ) )
971 QMessageBox::critical (0,
972 QObject::tr("Critical Export Error"),
973 QObject::tr("Trying to save HTML file:") + "\n\n"+
974 QObject::tr("Could not write %1").arg(filePath));
975 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
978 QTextStream ts( &file );
979 ts.setCodec("UTF-8");
981 // Hide stuff during export
982 model->setExportMode (true);
986 ts << "\n<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"> ";
987 ts << "\n<meta name=\"generator=\" content=\" vym - view your mind - " + vymVersion + " - " + vymHome + "\">";
988 ts << "\n<meta name=\"author\" content=\"" + quotemeta(model->getAuthor()) + "\"> ";
989 ts << "\n<meta name=\"description\" content=\"" + quotemeta(model->getComment()) + "\"> ";
990 ts << "\n<link rel='stylesheet' id='css.stylesheet' href='" << basename(cssDst) << "' />\n";
991 QString title=model->getTitle();
992 if (title.isEmpty()) title=model->getMapName();
993 ts << "\n<head><title>" + quotemeta(title) + "</title></head>";
997 // (be careful: this resets Export mode, so call before exporting branches)
998 if (dia.includeMapImage)
1000 QString mapName = getMapName();
1001 ts << "<center><img src=\"" << mapName << ".png\"";
1002 ts << "alt=\"" << QObject::tr("Image of map: %1.vym","Alt tag in HTML export").arg(mapName) << "\"";
1003 ts << " usemap='#imagemap'></center>\n";
1004 offset = model->exportImage (dirPath + "/" + mapName + ".png", false, "PNG");
1007 // Include table of contents
1008 if (dia.useTOC) ts << createTOC();
1010 // Main loop over all mapcenters
1011 ts << buildList(model->getRootItem()) << "\n";
1014 ts << "<map name='imagemap'>\n" + imageMap + "</map>\n";
1018 ts << "<table class=\"vym-footer\"> \n\
1020 <td class=\"vym-footerL\">" + filePath + "</td> \n\
1021 <td class=\"vym-footerC\">" + model->getDate() + "</td> \n\
1022 <td class=\"vym-footerR\"> <a href='" + vymHome + "'>vym " + vymVersion + "</a></td> \n\
1025 ts << "</body></html>";
1028 if (!dia.postscript.isEmpty())
1031 p.runScript (dia.postscript,dirPath + "/" + filePath);
1034 completeExport( QString("\"%1\",\"%2\"").arg(dirPath).arg(filePath));
1037 model->setExportMode (false);
1040 ////////////////////////////////////////////////////////////////////////
1041 void ExportTaskjuggler::doExport()
1043 model->exportXML("",tmpDir.path(),false);
1046 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
1047 p.setOutputFile (filePath);
1048 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
1054 ////////////////////////////////////////////////////////////////////////
1055 ExportOrgMode::ExportOrgMode()
1057 exportName="OrgMode";
1058 filter="org-mode (*.org);;All (* *.*)";
1061 void ExportOrgMode::doExport()
1063 // Exports a map to an org-mode file.
1064 // This file needs to be read
1065 // by EMACS into an org mode buffer
1066 QFile file (filePath);
1067 if ( !file.open( QIODevice::WriteOnly ) )
1069 QMessageBox::critical (0, QObject::tr("Critical Export Error"), QObject::tr("Could not export as OrgMode to %1").arg(filePath));
1070 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
1073 QTextStream ts( &file );
1074 ts.setCodec("UTF-8");
1076 // Main loop over all branches
1079 BranchItem *cur=NULL;
1080 BranchItem *prev=NULL;
1081 model->nextBranch(cur,prev);
1084 if (!cur->hasHiddenExportParent() )
1086 for(i=0;i<=cur->depth();i++)
1088 ts << (" " + cur->getHeadingPlain()+ "\n");
1089 // If necessary, write note
1090 if (!cur->isNoteEmpty())
1092 ts << (cur->getNoteASCII());
1096 model->nextBranch(cur,prev);
1103 ////////////////////////////////////////////////////////////////////////
1104 ExportLaTeX::ExportLaTeX()
1107 filter="LaTeX files (*.tex);;All (* *.*)";
1109 // Note: key in hash on left side is the regular expression, which
1110 // will be replaced by string on right side
1111 // E.g. a literal $ will be replaced by \$
1123 QString ExportLaTeX::escapeLaTeX(const QString &s)
1128 rx.setMinimal(true);
1130 foreach (QString p,esc.keys() )
1133 r.replace (rx, esc[p] );
1138 void ExportLaTeX::doExport()
1140 // Exports a map to a LaTex file.
1141 // This file needs to be included
1142 // or inported into a LaTex document
1143 // it will not add a preamble, or anything
1144 // that makes a full LaTex document.
1145 QFile file (filePath);
1146 if ( !file.open( QIODevice::WriteOnly ) ) {
1147 QMessageBox::critical (
1149 QObject::tr("Critical Export Error"),
1150 QObject::tr("Could not export as LaTeX to %1").arg(filePath));
1151 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
1154 QTextStream ts( &file );
1155 ts.setCodec("UTF-8");
1157 // Read default section names
1158 QStringList sectionNames;
1166 for (int i=0; i<6; i++)
1167 sectionNames.replace(i,settings.value(
1168 QString("/export/latex/sectionName-%1").arg(i),sectionNames.at(i)).toString() );
1170 // Main loop over all branches
1172 BranchItem *cur=NULL;
1173 BranchItem *prev=NULL;
1174 model->nextBranch(cur,prev);
1177 if (!cur->hasHiddenExportParent() )
1180 s=escapeLaTeX (cur->getHeadingPlain() );
1181 if ( sectionNames.at(d).isEmpty() || d>=sectionNames.count() )
1186 << sectionNames.at(d)
1192 // If necessary, write note
1193 if (!cur->isNoteEmpty()) {
1194 ts << (cur->getNoteASCII());
1198 model->nextBranch(cur,prev);
1205 ////////////////////////////////////////////////////////////////////////
1206 ExportOO::ExportOO()
1208 exportName="Impress";
1209 filter="LibreOffice Impress (*.odp);;All (* *.*)";
1210 caption=vymName+ " -" +QObject::tr("Export as LibreOffice Impress presentation");
1214 ExportOO::~ExportOO()
1218 QString ExportOO::buildList (TreeItem *current)
1223 BranchItem *bi=current->getFirstBranch();
1227 r+="<text:list text:style-name=\"vym-list\">\n";
1230 if (!bi->hasHiddenExportParent() )
1232 r += "<text:list-item><text:p >";
1233 r += quotemeta(bi->getHeadingPlain());
1234 // If necessary, write note
1235 if (! bi->isNoteEmpty())
1236 r += "<text:line-break/>" + bi->getNoteASCII();
1238 r += buildList (bi); // recursivly add deeper branches
1239 r += "</text:list-item>\n";
1242 bi = current->getBranchNum(i);
1244 r += "</text:list>\n";
1250 void ExportOO::exportPresentation()
1254 BranchItem *firstMCO=(BranchItem*)(model->getRootItem()->getFirstBranch());
1257 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("No objects in map!"));
1261 // Insert new content
1262 // FIXME add extra title in mapinfo for vym 1.13.x
1263 content.replace ("<!-- INSERT TITLE -->",quotemeta(firstMCO->getHeadingPlain()));
1264 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(model->getAuthor()));
1269 BranchItem *sectionBI;
1271 BranchItem *pagesBI;
1274 int mapcenters=model->getRootItem()->branchCount();
1276 // useSections already has been set in setConfigFile
1280 sectionBI=firstMCO->getFirstBranch();
1283 while (sectionBI && !sectionBI->hasHiddenExportParent() )
1287 // Add page with section title
1288 onePage=sectionTemplate;
1289 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBI->getHeadingPlain() ) );
1291 pagesBI=sectionBI->getFirstBranch();
1294 //i=-2; // only use inner loop to
1295 // turn mainbranches into pages
1296 //sectionBI=firstMCO;
1301 while (pagesBI && !pagesBI->hasHiddenExportParent() )
1303 // Add page with list of items
1304 onePage=pageTemplate;
1305 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBI->getHeadingPlain() ) );
1306 list=buildList (pagesBI);
1307 onePage.replace ("<!-- INSERT LIST -->", list);
1309 if (pagesBI!=sectionBI)
1312 pagesBI=((BranchItem*)pagesBI->parent())->getBranchNum(j);
1314 pagesBI=NULL; // We are already iterating over the sectionBIs
1318 sectionBI=model->getRootItem()->getBranchNum (i);
1320 sectionBI=firstMCO->getBranchNum (i);
1323 content.replace ("<!-- INSERT PAGES -->",allPages);
1325 // Write modified content
1326 QFile f (contentFile);
1327 if ( !f.open( QIODevice::WriteOnly ) )
1329 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
1330 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
1334 QTextStream t( &f );
1335 t.setCodec("UTF-8");
1339 // zip tmpdir to destination
1340 zipDir (tmpDir,filePath);
1342 completeExport(QString("\"%1\", \"%2\"").arg(filePath).arg(configFile) );
1345 bool ExportOO::setConfigFile (const QString &cf)
1348 int i=cf.lastIndexOf ("/");
1349 if (i>=0) configDir=cf.left(i);
1352 if (!set.readSettings(configFile))
1354 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Couldn't read settings from \"%1\"").arg(configFile));
1359 templateDir=configDir+"/"+set.value ("Template");
1361 QDir d (templateDir);
1364 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.value ("Template")).arg(configFile));
1369 contentTemplateFile = templateDir + "content-template.xml";
1370 pageTemplateFile = templateDir + "page-template.xml";
1371 sectionTemplateFile = templateDir + "section-template.xml";
1372 contentFile = tmpDir.path() + "/content.xml";
1374 if (set.value("useSections").contains("yes"))
1377 // Copy template to tmpdir
1378 copyDir (templateDir,tmpDir);
1380 // Read content-template
1381 if (!loadStringFromDisk (contentTemplateFile,content))
1383 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
1387 // Read page-template
1388 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
1390 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
1394 // Read section-template
1395 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
1397 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));