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
152 for (i=0;i<bo->getDepth()-1;i++) curIndent+= indentPerDepth;
154 if (!bo->hasHiddenExportParent() )
156 switch (bo->getDepth())
159 ts << underline (bo->getHeading(),QString("="));
164 ts << (underline (getSectionString(bo) + bo->getHeading(), QString("-") ) );
169 ts << (curIndent + "* " + bo->getHeading());
173 ts << (curIndent + "- " + bo->getHeading());
177 ts << (curIndent + "- " + bo->getHeading());
182 // If necessary, write note
183 if (!bo->getNote().isEmpty())
186 s=bo->getNoteASCII( curIndent, 80);
195 QString ExportASCII::underline (const QString &text, const QString &line)
197 QString r=text + "\n";
198 for (int j=0;j<text.length();j++) r+=line;
203 ////////////////////////////////////////////////////////////////////////
204 void ExportCSV::doExport()
206 QFile file (outputFile);
207 if ( !file.open( QIODevice::WriteOnly ) )
209 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
212 QTextStream ts( &file ); // use LANG decoding here...
215 ts << "\"Note\"" <<endl;
217 // Main loop over all branches
219 QString curIndent("");
225 if (!bo->hasHiddenExportParent() )
227 // If necessary, write note
228 if (!bo->getNote().isEmpty())
230 s =bo->getNoteASCII();
231 s=s.replace ("\n","\n"+curIndent);
232 ts << ("\""+s+"\",");
237 for (i=0;i<bo->getDepth();i++) curIndent+= "\"\",";
240 ts << curIndent << "\"" << bo->getHeading()<<"\""<<endl;
249 ////////////////////////////////////////////////////////////////////////
250 void ExportKDEBookmarks::doExport()
253 dia.showCancelButton (true);
254 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
255 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
256 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
257 if (dia.exec()==QDialog::Accepted)
259 model->exportXML(tmpDir.path(),false);
262 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
263 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
264 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
267 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
268 QProcess *proc= new QProcess ;
270 if (!proc->waitForStarted())
272 QMessageBox::warning(0,
273 QObject::tr("Warning"),
274 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
279 ////////////////////////////////////////////////////////////////////////
280 void ExportFirefoxBookmarks::doExport()
283 dia.showCancelButton (true);
284 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
285 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
286 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
287 if (dia.exec()==QDialog::Accepted)
289 model->exportXML(tmpDir.path(),false);
293 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
294 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
295 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
298 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
299 QProcess *proc = new QProcess( );
300 proc->addArgument(ub);
302 if ( !proc->start() )
304 QMessageBox::warning(0,
305 QObject::tr("Warning"),
306 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
313 ////////////////////////////////////////////////////////////////////////
314 void ExportTaskjuggler::doExport()
316 model->exportXML(tmpDir.path(),false);
319 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
320 p.setOutputFile (outputFile);
321 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
325 ////////////////////////////////////////////////////////////////////////
326 void ExportLaTeX::doExport()
328 // Exports a map to a LaTex file.
329 // This file needs to be included
330 // or inported into a LaTex document
331 // it will not add a preamble, or anything
332 // that makes a full LaTex document.
333 QFile file (outputFile);
334 if ( !file.open( QIODevice::WriteOnly ) ) {
335 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
336 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
339 QTextStream ts( &file ); // use LANG decoding here...
340 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
342 // Main loop over all branches
344 // QString curIndent("");
349 if (!bo->hasHiddenExportParent() )
351 if (bo->getDepth()==0);
352 else if (bo->getDepth()==1) {
353 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
355 else if (bo->getDepth()==2) {
356 ts << ("\\section{" + bo->getHeading()+ "}\n");
358 else if (bo->getDepth()==3) {
359 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
361 else if (bo->getDepth()==4) {
362 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
365 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
368 // If necessary, write note
369 if (!bo->getNote().isEmpty()) {
370 ts << (bo->getNoteASCII());
379 ////////////////////////////////////////////////////////////////////////
385 ExportOO::~ExportOO()
389 QString ExportOO::buildList (BranchObj *current)
395 bo=current->getFirstBranch();
398 if (!bo->hasHiddenExportParent() )
401 r+="<text:list text:style-name=\"vym-list\">\n";
404 r+="<text:list-item><text:p >";
405 r+=quotemeta(bo->getHeading());
406 // If necessary, write note
407 if (!bo->getNote().isEmpty())
408 r+=bo->getNoteOpenDoc();
410 r+=buildList (bo); // recursivly add deeper branches
411 r+="</text:list-item>\n";
413 bo=current->getBranchNum(i);
422 void ExportOO::exportPresentation()
426 /* FIXME not adapted to multiple mapCenters yet
427 // Insert new content
428 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
429 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
434 BranchObj *sectionBO=mapCenter->getFirstBranch();
440 while (sectionBO && !sectionBO->hasHiddenExportParent() )
444 // Add page with section title
445 onePage=sectionTemplate;
446 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
450 i=-2; // only use inner loop to
451 // turn mainbranches into pages
456 pagesBO=sectionBO->getFirstBranch();
458 while (pagesBO && !pagesBO->hasHiddenExportParent() )
460 // Add page with list of items
461 onePage=pageTemplate;
462 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
463 list=buildList (pagesBO);
464 onePage.replace ("<!-- INSERT LIST -->", list);
467 pagesBO=sectionBO->getBranchNum(j);
470 sectionBO=mapCenter->getBranchNum(i);
473 content.replace ("<!-- INSERT PAGES -->",allPages);
475 // Write modified content
476 QFile f (contentFile);
477 if ( !f.open( QIODevice::WriteOnly ) )
479 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
480 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
488 // zip tmpdir to destination
489 zipDir (tmpDir,outputFile);
493 bool ExportOO::setConfigFile (const QString &cf)
496 int i=cf.findRev ("/");
497 if (i>=0) configDir=cf.left(i);
499 set.readSettings(configFile);
502 templateDir=configDir+"/"+set.readEntry ("Template");
504 QDir d (templateDir);
507 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
512 contentTemplateFile=templateDir+"content-template.xml";
513 contentFile=tmpDir.path()+"/content.xml";
514 pageTemplateFile=templateDir+"page-template.xml";
515 sectionTemplateFile=templateDir+"section-template.xml";
517 if (set.readEntry("useSections").contains("yes"))
520 // Copy template to tmpdir
521 system ("cp -r "+templateDir+"* "+tmpDir.path());
523 // Read content-template
524 if (!loadStringFromDisk (contentTemplateFile,content))
526 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
530 // Read page-template
531 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
533 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
537 // Read section-template
538 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
540 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));