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()
19 tmpDir.setPath (makeTmpDir(ok,"vym-export"));
20 if (!tmpDir.exists() || !ok)
21 QMessageBox::critical( 0, QObject::tr( "Error" ),
22 QObject::tr("Couldn't access temporary directory\n"));
26 ExportBase::~ExportBase()
32 void ExportBase::setDir(const QDir &d)
37 void ExportBase::setFile (const QString &p)
42 QString ExportBase::getFile ()
47 void ExportBase::setModel(VymModel *m)
52 void ExportBase::setCaption (const QString &s)
57 void ExportBase::addFilter(const QString &s)
62 bool ExportBase::execDialog()
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(TreeItem *start)
111 // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
114 int depth=ti->depth();
117 r=QString("%1").arg(1+ti->num(),0,10)+"." + r;
127 ////////////////////////////////////////////////////////////////////////
130 filter="TXT (*.txt)";
131 caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
134 void ExportAO::doExport()
136 QFile file (outputFile);
137 if ( !file.open( QIODevice::WriteOnly ) )
139 qWarning ("ExportAO::doExport couldn't open "+outputFile);
142 QTextStream ts( &file ); // use LANG decoding here...
144 // Main loop over all branches
148 BranchItem *cur=NULL;
149 BranchItem *prev=NULL;
154 cur=model->nextBranch (cur,prev);
157 if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
161 for (i=0;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
163 if (!cur->hasHiddenExportParent() )
165 col=cur->getHeadingColor();
166 if (col==QColor (255,0,0))
168 else if (col==QColor (217,81,0))
170 else if (col==QColor (0,85,0))
174 switch (cur->depth())
177 //ts << underline (cur->getHeading(),QString("="));
182 //ts << (underline ( cur->getHeading(), QString("-") ) );
185 case 2: // Main heading
187 ts << underline ( cur->getHeading(), QString("=") );
190 case 3: // Achievement, Bonus, Objective ...
191 ts << underline ( cur->getHeading(), "-");
194 case 4: // That's the item we need to know
195 ts << (curIndent + "* " + colString+" "+ cur->getHeading());
196 if (cur->isActiveStandardFlag ("hook-green"))
198 else if (cur->isActiveStandardFlag ("clock"))
200 else if (cur->isActiveStandardFlag ("cross-red"))
201 ts << " [NOT STARTED] ";
205 ts << (curIndent + "- " + cur->getHeading());
210 // If necessary, write note
211 if (!cur->getNoteObj().isEmpty())
214 s=cur->getNoteASCII( curIndent, 80);
219 cur=model->nextBranch(cur,prev);
224 QString ExportAO::underline (const QString &text, const QString &line)
226 QString r=text + "\n";
227 for (int j=0;j<text.length();j++) r+=line;
232 ////////////////////////////////////////////////////////////////////////
233 ExportASCII::ExportASCII()
235 filter="TXT (*.txt)";
236 caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
239 void ExportASCII::doExport()
241 QFile file (outputFile);
242 if ( !file.open( QIODevice::WriteOnly ) )
244 qWarning ("ExportASCII::doExport couldn't open "+outputFile);
247 QTextStream ts( &file ); // use LANG decoding here...
249 // Main loop over all branches
253 BranchItem *cur=NULL;
254 BranchItem *prev=NULL;
256 cur=model->nextBranch (cur,prev);
259 if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
263 for (i=0;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
265 if (!cur->hasHiddenExportParent() )
267 //std::cout << "ExportASCII:: "<<curIndent.toStdString()<<cur->getHeading().toStdString()<<std::endl;
268 switch (cur->depth())
271 ts << underline (cur->getHeading(),QString("="));
276 ts << (underline (getSectionString(cur) + cur->getHeading(), QString("-") ) );
281 ts << (curIndent + "* " + cur->getHeading());
285 ts << (curIndent + "- " + cur->getHeading());
289 ts << (curIndent + "- " + cur->getHeading());
294 // If necessary, write note
295 if (!cur->getNoteObj().isEmpty())
298 s=cur->getNoteASCII( curIndent, 80);
303 cur=model->nextBranch(cur,prev);
308 QString ExportASCII::underline (const QString &text, const QString &line)
310 QString r=text + "\n";
311 for (int j=0;j<text.length();j++) r+=line;
316 ////////////////////////////////////////////////////////////////////////
317 void ExportCSV::doExport()
319 QFile file (outputFile);
320 if ( !file.open( QIODevice::WriteOnly ) )
322 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
325 QTextStream ts( &file ); // use LANG decoding here...
328 ts << "\"Note\"" <<endl;
330 // Main loop over all branches
332 QString curIndent("");
334 BranchObj *bo; //FIXME-3 still needed?
335 BranchItem *cur=NULL;
336 BranchItem *prev=NULL;
337 cur=model->nextBranch (cur,prev);
340 bo=(BranchObj*)(cur->getLMO());
342 if (!cur->hasHiddenExportParent() )
344 // If necessary, write note
345 if (!cur->getNoteObj().isEmpty())
347 s =cur->getNoteASCII();
348 s=s.replace ("\n","\n"+curIndent);
349 ts << ("\""+s+"\",");
354 for (i=0;i<cur->depth();i++) curIndent+= "\"\",";
357 ts << curIndent << "\"" << cur->getHeading()<<"\""<<endl;
360 cur=model->nextBranch(cur,prev);
366 ////////////////////////////////////////////////////////////////////////
367 void ExportKDE3Bookmarks::doExport()
370 dia.showCancelButton (true);
371 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
372 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE 3"));
373 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
374 if (dia.exec()==QDialog::Accepted)
376 model->exportXML(tmpDir.path(),false);
379 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
380 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
381 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
384 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
385 QProcess *proc= new QProcess ;
387 if (!proc->waitForStarted())
389 QMessageBox::warning(0,
390 QObject::tr("Warning"),
391 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
396 ////////////////////////////////////////////////////////////////////////
397 void ExportKDE4Bookmarks::doExport()
400 dia.showCancelButton (true);
401 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE 4"));
402 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
403 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
404 if (dia.exec()==QDialog::Accepted)
406 model->exportXML(tmpDir.path(),false);
409 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
410 p.setOutputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
411 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
414 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
415 QProcess *proc= new QProcess ;
417 if (!proc->waitForStarted())
419 QMessageBox::warning(0,
420 QObject::tr("Warning"),
421 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
426 ////////////////////////////////////////////////////////////////////////
427 void ExportFirefoxBookmarks::doExport()
430 dia.showCancelButton (true);
431 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
432 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
433 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
434 if (dia.exec()==QDialog::Accepted)
436 model->exportXML(tmpDir.path(),false);
440 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
441 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
442 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
445 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
446 QProcess *proc = new QProcess( );
447 proc->addArgument(ub);
449 if ( !proc->start() )
451 QMessageBox::warning(0,
452 QObject::tr("Warning"),
453 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
460 ////////////////////////////////////////////////////////////////////////
461 void ExportTaskjuggler::doExport()
463 model->exportXML(tmpDir.path(),false);
466 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
467 p.setOutputFile (outputFile);
468 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
472 ////////////////////////////////////////////////////////////////////////
473 void ExportLaTeX::doExport()
475 // Exports a map to a LaTex file.
476 // This file needs to be included
477 // or inported into a LaTex document
478 // it will not add a preamble, or anything
479 // that makes a full LaTex document.
480 QFile file (outputFile);
481 if ( !file.open( QIODevice::WriteOnly ) ) {
482 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
483 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
486 QTextStream ts( &file ); // use LANG decoding here...
487 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
489 // Main loop over all branches
491 // QString curIndent("");
494 BranchItem *cur=NULL;
495 BranchItem *prev=NULL;
496 model->nextBranch(cur,prev);
499 bo=(BranchObj*)(cur->getLMO());
501 if (!cur->hasHiddenExportParent() )
503 switch (cur->depth() )
507 ts << ("\\chapter{" + cur->getHeading()+ "}\n");
510 ts << ("\\section{" + cur->getHeading()+ "}\n");
513 ts << ("\\subsection{" + cur->getHeading()+ "}\n");
516 ts << ("\\subsubsection{" + cur->getHeading()+ "}\n");
519 ts << ("\\paragraph*{" + cur->getHeading()+ "}\n");
522 // If necessary, write note
523 if (!cur->getNoteObj().isEmpty()) {
524 ts << (cur->getNoteASCII());
528 cur=model->nextBranch(cur,prev);
533 ////////////////////////////////////////////////////////////////////////
539 ExportOO::~ExportOO()
543 QString ExportOO::buildList (TreeItem *current)
548 BranchItem *bi=current->getFirstBranch();
551 if (!bi->hasHiddenExportParent() ) // FIXME-3 use BranchItem...
554 r+="<text:list text:style-name=\"vym-list\">\n";
557 r+="<text:list-item><text:p >";
558 r+=quotemeta(bi->getHeading());
559 // If necessary, write note
560 if (!bi->getNoteObj().isEmpty())
561 r+=bi->getNoteOpenDoc();
563 r+=buildList (bi); // recursivly add deeper branches
564 r+="</text:list-item>\n";
566 bi=current->getBranchNum(i);
575 void ExportOO::exportPresentation()
579 BranchItem *firstMCO=(BranchItem*)(model->getRootItem()->getFirstBranch());
582 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("No objects in map!"));
586 // Insert new content
587 // FIXME add extra title in mapinfo for vym 1.13.x
588 content.replace ("<!-- INSERT TITLE -->",quotemeta(firstMCO->getHeading()));
589 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(model->getAuthor()));
594 BranchItem *sectionBI;
599 int mapcenters=model->getRootItem()->branchCount();
601 // useSections already has been set in setConfigFile
605 sectionBI=firstMCO->getFirstBranch();
608 while (sectionBI && !sectionBI->hasHiddenExportParent() )
612 // Add page with section title
613 onePage=sectionTemplate;
614 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBI->getHeading() ) );
616 pagesBI=sectionBI->getFirstBranch();
619 //i=-2; // only use inner loop to
620 // turn mainbranches into pages
621 //sectionBI=firstMCO;
626 while (pagesBI && !pagesBI->hasHiddenExportParent() )
628 // Add page with list of items
629 onePage=pageTemplate;
630 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBI->getHeading() ) );
631 list=buildList (pagesBI);
632 onePage.replace ("<!-- INSERT LIST -->", list);
634 if (pagesBI!=sectionBI)
637 pagesBI=((BranchItem*)pagesBI->parent())->getBranchNum(j);
639 pagesBI=NULL; // We are already iterating over the sectionBIs
643 sectionBI=model->getRootItem()->getBranchNum (i);
645 sectionBI=firstMCO->getBranchNum (i);
648 content.replace ("<!-- INSERT PAGES -->",allPages);
650 // Write modified content
651 QFile f (contentFile);
652 if ( !f.open( QIODevice::WriteOnly ) )
654 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
655 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
663 // zip tmpdir to destination
664 zipDir (tmpDir,outputFile);
667 bool ExportOO::setConfigFile (const QString &cf)
670 int i=cf.findRev ("/");
671 if (i>=0) configDir=cf.left(i);
673 set.readSettings(configFile);
676 templateDir=configDir+"/"+set.readEntry ("Template");
678 QDir d (templateDir);
681 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
686 contentTemplateFile=templateDir+"content-template.xml";
687 contentFile=tmpDir.path()+"/content.xml";
688 pageTemplateFile=templateDir+"page-template.xml";
689 sectionTemplateFile=templateDir+"section-template.xml";
691 if (set.readEntry("useSections").contains("yes"))
694 // Copy template to tmpdir
695 system ("cp -r "+templateDir+"* "+tmpDir.path());
697 // Read content-template
698 if (!loadStringFromDisk (contentTemplateFile,content))
700 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
704 // Read page-template
705 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
707 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
711 // Read section-template
712 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
714 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));