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 ...
192 ts << underline ( cur->getHeading(), "-");
195 case 4: // That's the item we need to know
196 //ts << (curIndent + "* " + colString+" "+ cur->getHeading());
197 ts << colString+" "+ cur->getHeading();
198 if (cur->isActiveStandardFlag ("hook-green"))
200 else if (cur->isActiveStandardFlag ("wip"))
202 else if (cur->isActiveStandardFlag ("cross-red"))
203 ts << " [NOT STARTED] ";
207 ts << (curIndent + "- " + cur->getHeading());
212 // If necessary, write note
213 if (!cur->getNoteObj().isEmpty())
216 s=cur->getNoteASCII( curIndent, 80);
221 cur=model->nextBranch(cur,prev);
226 QString ExportAO::underline (const QString &text, const QString &line)
228 QString r=text + "\n";
229 for (int j=0;j<text.length();j++) r+=line;
234 ////////////////////////////////////////////////////////////////////////
235 ExportASCII::ExportASCII()
237 filter="TXT (*.txt)";
238 caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
241 void ExportASCII::doExport()
243 QFile file (outputFile);
244 if ( !file.open( QIODevice::WriteOnly ) )
246 qWarning ("ExportASCII::doExport couldn't open "+outputFile);
249 QTextStream ts( &file ); // use LANG decoding here...
251 // Main loop over all branches
255 BranchItem *cur=NULL;
256 BranchItem *prev=NULL;
258 cur=model->nextBranch (cur,prev);
261 if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
265 for (i=0;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
267 if (!cur->hasHiddenExportParent() )
269 //std::cout << "ExportASCII:: "<<curIndent.toStdString()<<cur->getHeading().toStdString()<<std::endl;
270 switch (cur->depth())
273 ts << underline (cur->getHeading(),QString("="));
278 ts << (underline (getSectionString(cur) + cur->getHeading(), QString("-") ) );
283 ts << (curIndent + "* " + cur->getHeading());
287 ts << (curIndent + "- " + cur->getHeading());
291 ts << (curIndent + "- " + cur->getHeading());
296 // If necessary, write note
297 if (!cur->getNoteObj().isEmpty())
300 s=cur->getNoteASCII( curIndent, 80);
305 cur=model->nextBranch(cur,prev);
310 QString ExportASCII::underline (const QString &text, const QString &line)
312 QString r=text + "\n";
313 for (int j=0;j<text.length();j++) r+=line;
318 ////////////////////////////////////////////////////////////////////////
319 void ExportCSV::doExport()
321 QFile file (outputFile);
322 if ( !file.open( QIODevice::WriteOnly ) )
324 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
327 QTextStream ts( &file ); // use LANG decoding here...
330 ts << "\"Note\"" <<endl;
332 // Main loop over all branches
334 QString curIndent("");
336 BranchObj *bo; //FIXME-3 still needed?
337 BranchItem *cur=NULL;
338 BranchItem *prev=NULL;
339 cur=model->nextBranch (cur,prev);
342 bo=(BranchObj*)(cur->getLMO());
344 if (!cur->hasHiddenExportParent() )
346 // If necessary, write note
347 if (!cur->getNoteObj().isEmpty())
349 s =cur->getNoteASCII();
350 s=s.replace ("\n","\n"+curIndent);
351 ts << ("\""+s+"\",");
356 for (i=0;i<cur->depth();i++) curIndent+= "\"\",";
359 ts << curIndent << "\"" << cur->getHeading()<<"\""<<endl;
362 cur=model->nextBranch(cur,prev);
368 ////////////////////////////////////////////////////////////////////////
369 void ExportKDE3Bookmarks::doExport()
372 dia.showCancelButton (true);
373 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
374 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE 3"));
375 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
376 if (dia.exec()==QDialog::Accepted)
378 model->exportXML(tmpDir.path(),false);
381 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
382 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
383 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
386 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
387 QProcess *proc= new QProcess ;
389 if (!proc->waitForStarted())
391 QMessageBox::warning(0,
392 QObject::tr("Warning"),
393 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
398 ////////////////////////////////////////////////////////////////////////
399 void ExportKDE4Bookmarks::doExport()
402 dia.showCancelButton (true);
403 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE 4"));
404 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
405 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
406 if (dia.exec()==QDialog::Accepted)
408 model->exportXML(tmpDir.path(),false);
411 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
412 p.setOutputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
413 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
416 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
417 QProcess *proc= new QProcess ;
419 if (!proc->waitForStarted())
421 QMessageBox::warning(0,
422 QObject::tr("Warning"),
423 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
428 ////////////////////////////////////////////////////////////////////////
429 void ExportFirefoxBookmarks::doExport()
432 dia.showCancelButton (true);
433 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
434 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
435 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
436 if (dia.exec()==QDialog::Accepted)
438 model->exportXML(tmpDir.path(),false);
442 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
443 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
444 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
447 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
448 QProcess *proc = new QProcess( );
449 proc->addArgument(ub);
451 if ( !proc->start() )
453 QMessageBox::warning(0,
454 QObject::tr("Warning"),
455 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
462 ////////////////////////////////////////////////////////////////////////
463 void ExportTaskjuggler::doExport()
465 model->exportXML(tmpDir.path(),false);
468 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
469 p.setOutputFile (outputFile);
470 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
474 ////////////////////////////////////////////////////////////////////////
475 void ExportLaTeX::doExport()
477 // Exports a map to a LaTex file.
478 // This file needs to be included
479 // or inported into a LaTex document
480 // it will not add a preamble, or anything
481 // that makes a full LaTex document.
482 QFile file (outputFile);
483 if ( !file.open( QIODevice::WriteOnly ) ) {
484 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
485 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
488 QTextStream ts( &file ); // use LANG decoding here...
489 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
491 // Main loop over all branches
493 // QString curIndent("");
496 BranchItem *cur=NULL;
497 BranchItem *prev=NULL;
498 model->nextBranch(cur,prev);
501 bo=(BranchObj*)(cur->getLMO());
503 if (!cur->hasHiddenExportParent() )
505 switch (cur->depth() )
509 ts << ("\\chapter{" + cur->getHeading()+ "}\n");
512 ts << ("\\section{" + cur->getHeading()+ "}\n");
515 ts << ("\\subsection{" + cur->getHeading()+ "}\n");
518 ts << ("\\subsubsection{" + cur->getHeading()+ "}\n");
521 ts << ("\\paragraph*{" + cur->getHeading()+ "}\n");
524 // If necessary, write note
525 if (!cur->getNoteObj().isEmpty()) {
526 ts << (cur->getNoteASCII());
530 cur=model->nextBranch(cur,prev);
535 ////////////////////////////////////////////////////////////////////////
541 ExportOO::~ExportOO()
545 QString ExportOO::buildList (TreeItem *current)
550 BranchItem *bi=current->getFirstBranch();
553 if (!bi->hasHiddenExportParent() ) // FIXME-3 use BranchItem...
556 r+="<text:list text:style-name=\"vym-list\">\n";
559 r+="<text:list-item><text:p >";
560 r+=quotemeta(bi->getHeading());
561 // If necessary, write note
562 if (!bi->getNoteObj().isEmpty())
563 r+=bi->getNoteOpenDoc();
565 r+=buildList (bi); // recursivly add deeper branches
566 r+="</text:list-item>\n";
568 bi=current->getBranchNum(i);
577 void ExportOO::exportPresentation()
581 BranchItem *firstMCO=(BranchItem*)(model->getRootItem()->getFirstBranch());
584 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("No objects in map!"));
588 // Insert new content
589 // FIXME add extra title in mapinfo for vym 1.13.x
590 content.replace ("<!-- INSERT TITLE -->",quotemeta(firstMCO->getHeading()));
591 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(model->getAuthor()));
596 BranchItem *sectionBI;
601 int mapcenters=model->getRootItem()->branchCount();
603 // useSections already has been set in setConfigFile
607 sectionBI=firstMCO->getFirstBranch();
610 while (sectionBI && !sectionBI->hasHiddenExportParent() )
614 // Add page with section title
615 onePage=sectionTemplate;
616 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBI->getHeading() ) );
618 pagesBI=sectionBI->getFirstBranch();
621 //i=-2; // only use inner loop to
622 // turn mainbranches into pages
623 //sectionBI=firstMCO;
628 while (pagesBI && !pagesBI->hasHiddenExportParent() )
630 // Add page with list of items
631 onePage=pageTemplate;
632 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBI->getHeading() ) );
633 list=buildList (pagesBI);
634 onePage.replace ("<!-- INSERT LIST -->", list);
636 if (pagesBI!=sectionBI)
639 pagesBI=((BranchItem*)pagesBI->parent())->getBranchNum(j);
641 pagesBI=NULL; // We are already iterating over the sectionBIs
645 sectionBI=model->getRootItem()->getBranchNum (i);
647 sectionBI=firstMCO->getBranchNum (i);
650 content.replace ("<!-- INSERT PAGES -->",allPages);
652 // Write modified content
653 QFile f (contentFile);
654 if ( !f.open( QIODevice::WriteOnly ) )
656 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
657 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
665 // zip tmpdir to destination
666 zipDir (tmpDir,outputFile);
669 bool ExportOO::setConfigFile (const QString &cf)
672 int i=cf.findRev ("/");
673 if (i>=0) configDir=cf.left(i);
675 set.readSettings(configFile);
678 templateDir=configDir+"/"+set.readEntry ("Template");
680 QDir d (templateDir);
683 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
688 contentTemplateFile=templateDir+"content-template.xml";
689 contentFile=tmpDir.path()+"/content.xml";
690 pageTemplateFile=templateDir+"page-template.xml";
691 sectionTemplateFile=templateDir+"section-template.xml";
693 if (set.readEntry("useSections").contains("yes"))
696 // Copy template to tmpdir
697 system ("cp -r "+templateDir+"* "+tmpDir.path());
699 // Read content-template
700 if (!loadStringFromDisk (contentTemplateFile,content))
702 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
706 // Read page-template
707 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
709 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
713 // Read section-template
714 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
716 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));