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()
63 QFileDialog *fd=new QFileDialog( 0, caption);
64 fd->setFilter (filter);
65 fd->setCaption(caption);
66 fd->setMode( QFileDialog::AnyFile );
70 if ( fd->exec() == QDialog::Accepted )
72 if (QFile (fd->selectedFile()).exists() )
74 QMessageBox mb( vymName,
75 QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
77 QMessageBox::Yes | QMessageBox::Default,
78 QMessageBox::Cancel | QMessageBox::Escape,
80 mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
81 mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
85 case QMessageBox::Yes:
88 case QMessageBox::Cancel:
94 outputFile=fd->selectedFile();
102 bool ExportBase::canceled()
107 QString ExportBase::getSectionString(BranchObj *bostart)
109 // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
111 BranchObj *bo=bostart;
112 int depth=bo->getDepth();
115 r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
116 bo=(BranchObj*)(bo->getParObj());
117 depth=bo->getDepth();
125 ////////////////////////////////////////////////////////////////////////
126 ExportASCII::ExportASCII()
128 filter="TXT (*.txt)";
129 caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
132 void ExportASCII::doExport()
134 QFile file (outputFile);
135 if ( !file.open( QIODevice::WriteOnly ) )
137 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
140 QTextStream ts( &file ); // use LANG decoding here...
142 // Main loop over all branches
151 cur=model->next (cur,prev,d);
154 if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
156 bo=(BranchObj*)(cur->getLMO());
157 std::cout << "ExportASCII:: "<<cur->getHeading().toStdString()<<std::endl;
161 for (i=0;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
163 if (!bo->hasHiddenExportParent() )
165 switch (cur->depth())
168 ts << underline (cur->getHeading(),QString("="));
173 ts << (underline (getSectionString(bo) + cur->getHeading(), QString("-") ) );
178 ts << (curIndent + "* " + cur->getHeading());
182 ts << (curIndent + "- " + cur->getHeading());
186 ts << (curIndent + "- " + cur->getHeading());
191 // If necessary, write note
192 if (!bo->getNote().isEmpty())
195 s=bo->getNoteASCII( curIndent, 80);
200 cur=model->next(cur,prev,d);
205 QString ExportASCII::underline (const QString &text, const QString &line)
207 QString r=text + "\n";
208 for (int j=0;j<text.length();j++) r+=line;
213 ////////////////////////////////////////////////////////////////////////
214 void ExportCSV::doExport()
216 QFile file (outputFile);
217 if ( !file.open( QIODevice::WriteOnly ) )
219 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
222 QTextStream ts( &file ); // use LANG decoding here...
225 ts << "\"Note\"" <<endl;
227 // Main loop over all branches
229 QString curIndent("");
235 cur=model->next (cur,prev,d);
238 bo=(BranchObj*)(cur->getLMO());
240 if (!bo->hasHiddenExportParent() )
242 // If necessary, write note
243 if (!bo->getNote().isEmpty())
245 s =bo->getNoteASCII();
246 s=s.replace ("\n","\n"+curIndent);
247 ts << ("\""+s+"\",");
252 for (i=0;i<cur->depth();i++) curIndent+= "\"\",";
255 ts << curIndent << "\"" << cur->getHeading()<<"\""<<endl;
258 cur=model->next(cur,prev,d);
264 ////////////////////////////////////////////////////////////////////////
265 void ExportKDE3Bookmarks::doExport()
268 dia.showCancelButton (true);
269 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
270 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE 3"));
271 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
272 if (dia.exec()==QDialog::Accepted)
274 model->exportXML(tmpDir.path(),false);
277 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
278 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
279 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
282 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
283 QProcess *proc= new QProcess ;
285 if (!proc->waitForStarted())
287 QMessageBox::warning(0,
288 QObject::tr("Warning"),
289 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
294 ////////////////////////////////////////////////////////////////////////
295 void ExportKDE4Bookmarks::doExport()
298 dia.showCancelButton (true);
299 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE 4"));
300 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
301 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
302 if (dia.exec()==QDialog::Accepted)
304 model->exportXML(tmpDir.path(),false);
307 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
308 p.setOutputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
309 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
312 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
313 QProcess *proc= new QProcess ;
315 if (!proc->waitForStarted())
317 QMessageBox::warning(0,
318 QObject::tr("Warning"),
319 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
324 ////////////////////////////////////////////////////////////////////////
325 void ExportFirefoxBookmarks::doExport()
328 dia.showCancelButton (true);
329 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
330 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
331 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
332 if (dia.exec()==QDialog::Accepted)
334 model->exportXML(tmpDir.path(),false);
338 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
339 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
340 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
343 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
344 QProcess *proc = new QProcess( );
345 proc->addArgument(ub);
347 if ( !proc->start() )
349 QMessageBox::warning(0,
350 QObject::tr("Warning"),
351 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
358 ////////////////////////////////////////////////////////////////////////
359 void ExportTaskjuggler::doExport()
361 model->exportXML(tmpDir.path(),false);
364 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
365 p.setOutputFile (outputFile);
366 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
370 ////////////////////////////////////////////////////////////////////////
371 void ExportLaTeX::doExport()
373 // Exports a map to a LaTex file.
374 // This file needs to be included
375 // or inported into a LaTex document
376 // it will not add a preamble, or anything
377 // that makes a full LaTex document.
378 QFile file (outputFile);
379 if ( !file.open( QIODevice::WriteOnly ) ) {
380 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
381 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
384 QTextStream ts( &file ); // use LANG decoding here...
385 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
387 // Main loop over all branches
389 // QString curIndent("");
395 model->next(cur,prev,d);
398 bo=(BranchObj*)(cur->getLMO());
400 if (!bo->hasHiddenExportParent() )
402 switch (cur->depth() )
406 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
409 ts << ("\\section{" + bo->getHeading()+ "}\n");
412 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
415 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
418 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
421 // If necessary, write note
422 if (!bo->getNote().isEmpty()) {
423 ts << (bo->getNoteASCII());
427 cur=model->next(cur,prev,d);
432 ////////////////////////////////////////////////////////////////////////
438 ExportOO::~ExportOO()
442 QString ExportOO::buildList (BranchObj *current)
448 bo=current->getFirstBranch();
451 if (!bo->hasHiddenExportParent() )
454 r+="<text:list text:style-name=\"vym-list\">\n";
457 r+="<text:list-item><text:p >";
458 r+=quotemeta(bo->getHeading());
459 // If necessary, write note
460 if (!bo->getNote().isEmpty())
461 r+=bo->getNoteOpenDoc();
463 r+=buildList (bo); // recursivly add deeper branches
464 r+="</text:list-item>\n";
466 bo=current->getBranchNum(i);
475 void ExportOO::exportPresentation()
479 /* FIXME not adapted to multiple mapCenters yet
480 // Insert new content
481 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
482 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
487 BranchObj *sectionBO=mapCenter->getFirstBranch();
493 while (sectionBO && !sectionBO->hasHiddenExportParent() )
497 // Add page with section title
498 onePage=sectionTemplate;
499 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
503 i=-2; // only use inner loop to
504 // turn mainbranches into pages
509 pagesBO=sectionBO->getFirstBranch();
511 while (pagesBO && !pagesBO->hasHiddenExportParent() )
513 // Add page with list of items
514 onePage=pageTemplate;
515 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
516 list=buildList (pagesBO);
517 onePage.replace ("<!-- INSERT LIST -->", list);
520 pagesBO=sectionBO->getBranchNum(j);
523 sectionBO=mapCenter->getBranchNum(i);
526 content.replace ("<!-- INSERT PAGES -->",allPages);
528 // Write modified content
529 QFile f (contentFile);
530 if ( !f.open( QIODevice::WriteOnly ) )
532 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
533 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
541 // zip tmpdir to destination
542 zipDir (tmpDir,outputFile);
546 bool ExportOO::setConfigFile (const QString &cf)
549 int i=cf.findRev ("/");
550 if (i>=0) configDir=cf.left(i);
552 set.readSettings(configFile);
555 templateDir=configDir+"/"+set.readEntry ("Template");
557 QDir d (templateDir);
560 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
565 contentTemplateFile=templateDir+"content-template.xml";
566 contentFile=tmpDir.path()+"/content.xml";
567 pageTemplateFile=templateDir+"page-template.xml";
568 sectionTemplateFile=templateDir+"section-template.xml";
570 if (set.readEntry("useSections").contains("yes"))
573 // Copy template to tmpdir
574 system ("cp -r "+templateDir+"* "+tmpDir.path());
576 // Read content-template
577 if (!loadStringFromDisk (contentTemplateFile,content))
579 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
583 // Read page-template
584 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
586 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
590 // Read section-template
591 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
593 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));