3 #include "branchitem.h"
5 #include "linkablemapobj.h"
7 #include "mainwindow.h"
8 #include "warningdialog.h"
11 extern Main *mainWindow;
12 extern QDir vymBaseDir;
13 extern QString vymName;
15 ExportBase::ExportBase()
20 ExportBase::ExportBase(VymModel *m)
26 ExportBase::~ExportBase()
32 void ExportBase::init()
36 tmpDir.setPath (makeTmpDir(ok,"vym-export"));
37 if (!tmpDir.exists() || !ok)
38 QMessageBox::critical( 0, QObject::tr( "Error" ),
39 QObject::tr("Couldn't access temporary directory\n"));
43 void ExportBase::setDir(const QDir &d)
48 void ExportBase::setFile (const QString &p)
53 QString ExportBase::getFile ()
58 void ExportBase::setModel(VymModel *m)
63 void ExportBase::setCaption (const QString &s)
68 void ExportBase::addFilter(const QString &s)
73 bool ExportBase::execDialog()
76 QFileDialog *fd=new QFileDialog( 0, caption);
77 fd->setFilter (filter);
78 fd->setCaption(caption);
79 fd->setMode( QFileDialog::AnyFile );
83 if ( fd->exec() == QDialog::Accepted )
85 if (QFile (fd->selectedFile()).exists() )
87 QMessageBox mb( vymName,
88 QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
90 QMessageBox::Yes | QMessageBox::Default,
91 QMessageBox::Cancel | QMessageBox::Escape,
93 mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
94 mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
98 case QMessageBox::Yes:
101 case QMessageBox::Cancel:
107 outputFile=fd->selectedFile();
115 bool ExportBase::canceled()
120 QString ExportBase::getSectionString(TreeItem *start)
122 // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
125 int depth=ti->depth();
128 r=QString("%1").arg(1+ti->num(),0,10)+"." + r;
138 ////////////////////////////////////////////////////////////////////////
141 filter="TXT (*.txt)";
142 caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
145 void ExportAO::doExport()
147 QFile file (outputFile);
148 if ( !file.open( QIODevice::WriteOnly ) )
150 qWarning ("ExportAO::doExport couldn't open "+outputFile);
153 QTextStream ts( &file ); // use LANG decoding here...
155 // Main loop over all branches
159 BranchItem *cur=NULL;
160 BranchItem *prev=NULL;
165 cur=model->nextBranch (cur,prev);
168 if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
172 for (i=0;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
174 if (!cur->hasHiddenExportParent() )
176 col=cur->getHeadingColor();
177 if (col==QColor (255,0,0))
179 else if (col==QColor (217,81,0))
181 else if (col==QColor (0,85,0))
185 switch (cur->depth())
188 //ts << underline (cur->getHeading(),QString("="));
193 //ts << (underline ( cur->getHeading(), QString("-") ) );
196 case 2: // Main heading
198 ts << underline ( cur->getHeading(), QString("=") );
201 case 3: // Achievement, Bonus, Objective ...
203 ts << underline ( cur->getHeading(), "-");
206 case 4: // That's the item we need to know
207 //ts << (curIndent + "* " + colString+" "+ cur->getHeading());
208 ts << colString+" "+ cur->getHeading();
209 if (cur->isActiveStandardFlag ("hook-green"))
211 else if (cur->isActiveStandardFlag ("wip"))
213 else if (cur->isActiveStandardFlag ("cross-red"))
214 ts << " [NOT STARTED] ";
218 ts << (curIndent + "- " + cur->getHeading());
223 // If necessary, write note
224 if (!cur->getNoteObj().isEmpty())
227 s=cur->getNoteASCII( curIndent, 80);
232 cur=model->nextBranch(cur,prev);
237 QString ExportAO::underline (const QString &text, const QString &line)
239 QString r=text + "\n";
240 for (int j=0;j<text.length();j++) r+=line;
245 ////////////////////////////////////////////////////////////////////////
246 ExportASCII::ExportASCII()
248 filter="TXT (*.txt)";
249 caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
252 void ExportASCII::doExport()
254 QFile file (outputFile);
255 if ( !file.open( QIODevice::WriteOnly ) )
257 qWarning ("ExportASCII::doExport couldn't open "+outputFile);
260 QTextStream ts( &file ); // use LANG decoding here...
262 // Main loop over all branches
266 BranchItem *cur=NULL;
267 BranchItem *prev=NULL;
269 cur=model->nextBranch (cur,prev);
272 if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
276 for (i=1;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
278 if (!cur->hasHiddenExportParent() )
280 //std::cout << "ExportASCII:: "<<curIndent.toStdString()<<cur->getHeading().toStdString()<<std::endl;
281 switch (cur->depth())
284 ts << underline (cur->getHeading(),QString("="));
289 ts << (underline (getSectionString(cur) + cur->getHeading(), QString("-") ) );
294 ts << (curIndent + "* " + cur->getHeading());
298 ts << (curIndent + "- " + cur->getHeading());
302 ts << (curIndent + "- " + cur->getHeading());
307 // If necessary, write note
308 if (!cur->getNoteObj().isEmpty())
311 s=cur->getNoteASCII( curIndent, 80);
316 cur=model->nextBranch(cur,prev);
321 QString ExportASCII::underline (const QString &text, const QString &line)
323 QString r=text + "\n";
324 for (int j=0;j<text.length();j++) r+=line;
329 ////////////////////////////////////////////////////////////////////////
330 void ExportCSV::doExport()
332 QFile file (outputFile);
333 if ( !file.open( QIODevice::WriteOnly ) )
335 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
338 QTextStream ts( &file ); // use LANG decoding here...
341 ts << "\"Note\"" <<endl;
343 // Main loop over all branches
345 QString curIndent("");
347 BranchObj *bo; //FIXME-3 still needed?
348 BranchItem *cur=NULL;
349 BranchItem *prev=NULL;
350 cur=model->nextBranch (cur,prev);
353 bo=(BranchObj*)(cur->getLMO());
355 if (!cur->hasHiddenExportParent() )
357 // If necessary, write note
358 if (!cur->getNoteObj().isEmpty())
360 s =cur->getNoteASCII();
361 s=s.replace ("\n","\n"+curIndent);
362 ts << ("\""+s+"\",");
367 for (i=0;i<cur->depth();i++) curIndent+= "\"\",";
370 ts << curIndent << "\"" << cur->getHeading()<<"\""<<endl;
373 cur=model->nextBranch(cur,prev);
379 ////////////////////////////////////////////////////////////////////////
380 void ExportKDE3Bookmarks::doExport()
383 dia.showCancelButton (true);
384 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
385 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE 3"));
386 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
387 if (dia.exec()==QDialog::Accepted)
389 model->exportXML(tmpDir.path(),false);
392 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
393 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
394 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
397 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
398 QProcess *proc= new QProcess ;
400 if (!proc->waitForStarted())
402 QMessageBox::warning(0,
403 QObject::tr("Warning"),
404 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
409 ////////////////////////////////////////////////////////////////////////
410 void ExportKDE4Bookmarks::doExport()
413 dia.showCancelButton (true);
414 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE 4"));
415 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
416 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
417 if (dia.exec()==QDialog::Accepted)
419 model->exportXML(tmpDir.path(),false);
422 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
423 p.setOutputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
424 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
427 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
428 QProcess *proc= new QProcess ;
430 if (!proc->waitForStarted())
432 QMessageBox::warning(0,
433 QObject::tr("Warning"),
434 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
439 ////////////////////////////////////////////////////////////////////////
440 void ExportFirefoxBookmarks::doExport()
443 dia.showCancelButton (true);
444 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
445 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
446 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
447 if (dia.exec()==QDialog::Accepted)
449 model->exportXML(tmpDir.path(),false);
453 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
454 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
455 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
458 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
459 QProcess *proc = new QProcess( );
460 proc->addArgument(ub);
462 if ( !proc->start() )
464 QMessageBox::warning(0,
465 QObject::tr("Warning"),
466 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
473 ////////////////////////////////////////////////////////////////////////
474 ExportHTML::ExportHTML():ExportBase()
479 ExportHTML::ExportHTML(VymModel *m):ExportBase(m)
484 void ExportHTML::init()
486 singularDelimiter=": ";
491 if (model &&model->getMapEditor())
492 offset=model->getMapEditor()->getTotalBBox().topLeft();
495 QString ExportHTML::getBranchText(BranchItem *current)
501 LinkableMapObj *lmo=current->getLMO();
504 hr=((BranchObj*)lmo)->getBBoxHeading();
505 if (lmo->isVisibleObj()) vis=true;
508 QString id=model->getSelectString(current);
510 col=QString("style='color:%1'").arg(current->getHeadingColor().name());
511 QString s=QString("<span class='vym-branch%1' %2 id='%3'>")
512 .arg(current->depth())
515 QString url=current->getURL();
518 s+=QString ("<a href=\"%1\">").arg(url);
519 s+=QString ("<img src=\"flags/flag-url-16x16.png\">%1</a>").arg(quotemeta(current->getHeading()));
522 QRectF fbox=current->getBBoxFlag ("system-url");
524 imageMap+=QString(" <area shape='rect' coords='%1,%2,%3,%4' href='%5'>\n")
525 .arg(fbox.left()-offset.x())
526 .arg(fbox.top()-offset.y())
527 .arg(fbox.right()-offset.x())
528 .arg(fbox.bottom()-offset.y())
531 s+=quotemeta(current->getHeading());
535 imageMap+=QString(" <area shape='rect' coords='%1,%2,%3,%4' href='#%5'>\n")
536 .arg(hr.left()-offset.x())
537 .arg(hr.top()-offset.y())
538 .arg(hr.right()-offset.x())
539 .arg(hr.bottom()-offset.y())
543 if (!current->getNoteObj().isEmpty())
544 s+="<table border=1><tr><td>"+current->getNote()+"</td></tr></table>";
551 QString ExportHTML::buildList (BranchItem *current)
556 BranchItem *bi=current->getFirstBranch();
558 // Only add itemized list, if we have more than one subitem.
559 // For only one subitem, just add a separator to keep page more compact
560 bool noSingularsHere=false;
561 if (current->branchCount()<2 && noSingulars) noSingularsHere=true;
565 if (!noSingularsHere)
568 r+=singularDelimiter;
572 if (!bi->hasHiddenExportParent() )
574 if (!noSingularsHere) r+="<li>";
575 r+=getBranchText (bi);
576 if (!bi->getURL().isEmpty() && frameURLs && noSingularsHere)
577 // Add frame, if we have subitems to an URL
578 r+="<table border=1><tr><td>"+buildList (bi)+"</td></tr></table>"; // recursivly add deeper branches
580 r+=buildList (bi); // recursivly add deeper branches
581 if (!noSingularsHere) r+="</li>";
585 bi=current->getBranchNum(i);
588 if (!noSingularsHere) r+="</ul>\n";
593 void ExportHTML::doExport()
595 QFile file (outputFile);
596 if ( !file.open( QIODevice::WriteOnly ) )
598 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
599 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
602 QTextStream ts( &file ); // use LANG decoding here...
603 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
606 ts<<"<html><title>"+model->getMapName()<<"</title><body>";
607 ts<<" <link rel='stylesheet' id='css.stylesheet' href='vym.css' />\n";
610 ts<<"<center><img src=\""<<model->getMapName()<<".png\" usemap='#imagemap'></center>\n";
613 // Main loop over all mapcenters
615 TreeItem *rootItem=model->getRootItem();
617 for (int i=0; i<rootItem->branchCount(); i++)
619 bi=rootItem->getBranchNum(i);
620 if (!bi->hasHiddenExportParent())
622 ts<<getBranchText (bi);
628 ts<<"<map name='imagemap'>\n"+imageMap+"</map>\n";
632 ts<<"<table class=\"vym-footer\"> \n\
634 <td class=\"vym-footerL\">"+model->getFileName()+"</td> \n\
635 <td class=\"vym-footerC\">"+model->getDate()+"</td> \n\
636 <td class=\"vym-footerR\"> vym "+model->getVersion()+"</td> \n\
639 ts<<"</body></html>";
643 ////////////////////////////////////////////////////////////////////////
644 void ExportTaskjuggler::doExport()
646 model->exportXML(tmpDir.path(),false);
649 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
650 p.setOutputFile (outputFile);
651 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
655 ////////////////////////////////////////////////////////////////////////
656 void ExportLaTeX::doExport()
658 // Exports a map to a LaTex file.
659 // This file needs to be included
660 // or inported into a LaTex document
661 // it will not add a preamble, or anything
662 // that makes a full LaTex document.
663 QFile file (outputFile);
664 if ( !file.open( QIODevice::WriteOnly ) ) {
665 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
666 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
669 QTextStream ts( &file ); // use LANG decoding here...
670 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
672 // Main loop over all branches
674 // QString curIndent("");
677 BranchItem *cur=NULL;
678 BranchItem *prev=NULL;
679 model->nextBranch(cur,prev);
682 bo=(BranchObj*)(cur->getLMO());
684 if (!cur->hasHiddenExportParent() )
686 switch (cur->depth() )
690 ts << ("\\chapter{" + cur->getHeading()+ "}\n");
693 ts << ("\\section{" + cur->getHeading()+ "}\n");
696 ts << ("\\subsection{" + cur->getHeading()+ "}\n");
699 ts << ("\\subsubsection{" + cur->getHeading()+ "}\n");
702 ts << ("\\paragraph*{" + cur->getHeading()+ "}\n");
705 // If necessary, write note
706 if (!cur->getNoteObj().isEmpty()) {
707 ts << (cur->getNoteASCII());
711 cur=model->nextBranch(cur,prev);
716 ////////////////////////////////////////////////////////////////////////
722 ExportOO::~ExportOO()
726 QString ExportOO::buildList (TreeItem *current)
731 BranchItem *bi=current->getFirstBranch();
735 r+="<text:list text:style-name=\"vym-list\">\n";
738 if (!bi->hasHiddenExportParent() )
740 r+="<text:list-item><text:p >";
741 r+=quotemeta(bi->getHeading());
742 // If necessary, write note
743 if (!bi->getNoteObj().isEmpty())
744 r+=bi->getNoteOpenDoc();
746 r+=buildList (bi); // recursivly add deeper branches
747 r+="</text:list-item>\n";
750 bi=current->getBranchNum(i);
758 void ExportOO::exportPresentation()
762 BranchItem *firstMCO=(BranchItem*)(model->getRootItem()->getFirstBranch());
765 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("No objects in map!"));
769 // Insert new content
770 // FIXME add extra title in mapinfo for vym 1.13.x
771 content.replace ("<!-- INSERT TITLE -->",quotemeta(firstMCO->getHeading()));
772 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(model->getAuthor()));
777 BranchItem *sectionBI;
782 int mapcenters=model->getRootItem()->branchCount();
784 // useSections already has been set in setConfigFile
788 sectionBI=firstMCO->getFirstBranch();
791 while (sectionBI && !sectionBI->hasHiddenExportParent() )
795 // Add page with section title
796 onePage=sectionTemplate;
797 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBI->getHeading() ) );
799 pagesBI=sectionBI->getFirstBranch();
802 //i=-2; // only use inner loop to
803 // turn mainbranches into pages
804 //sectionBI=firstMCO;
809 while (pagesBI && !pagesBI->hasHiddenExportParent() )
811 // Add page with list of items
812 onePage=pageTemplate;
813 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBI->getHeading() ) );
814 list=buildList (pagesBI);
815 onePage.replace ("<!-- INSERT LIST -->", list);
817 if (pagesBI!=sectionBI)
820 pagesBI=((BranchItem*)pagesBI->parent())->getBranchNum(j);
822 pagesBI=NULL; // We are already iterating over the sectionBIs
826 sectionBI=model->getRootItem()->getBranchNum (i);
828 sectionBI=firstMCO->getBranchNum (i);
831 content.replace ("<!-- INSERT PAGES -->",allPages);
833 // Write modified content
834 QFile f (contentFile);
835 if ( !f.open( QIODevice::WriteOnly ) )
837 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
838 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
846 // zip tmpdir to destination
847 zipDir (tmpDir,outputFile);
850 bool ExportOO::setConfigFile (const QString &cf)
853 int i=cf.findRev ("/");
854 if (i>=0) configDir=cf.left(i);
856 set.readSettings(configFile);
859 templateDir=configDir+"/"+set.readEntry ("Template");
861 QDir d (templateDir);
864 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
869 contentTemplateFile=templateDir+"content-template.xml";
870 contentFile=tmpDir.path()+"/content.xml";
871 pageTemplateFile=templateDir+"page-template.xml";
872 sectionTemplateFile=templateDir+"section-template.xml";
874 if (set.readEntry("useSections").contains("yes"))
877 // Copy template to tmpdir
878 system ("cp -r "+templateDir+"* "+tmpDir.path());
880 // Read content-template
881 if (!loadStringFromDisk (contentTemplateFile,content))
883 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
887 // Read page-template
888 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
890 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
894 // Read section-template
895 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
897 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));