1.11.2 split up of xml helper functions. started to work on attributes
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::setMapCenter(MapCenterObj *mc)
50 void ExportBase::setCaption (const QString &s)
55 void ExportBase::addFilter(const QString &s)
60 bool ExportBase::execDialog()
62 if (mapCenter && mapCenter->getMapEditor())
64 QFileDialog *fd=new QFileDialog( mapCenter->getMapEditor(), caption);
65 fd->setFilter (filter);
66 fd->setCaption(caption);
67 fd->setMode( QFileDialog::AnyFile );
71 if ( fd->exec() == QDialog::Accepted )
73 if (QFile (fd->selectedFile()).exists() )
75 QMessageBox mb( vymName,
76 QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
78 QMessageBox::Yes | QMessageBox::Default,
79 QMessageBox::Cancel | QMessageBox::Escape,
81 mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
82 mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
86 case QMessageBox::Yes:
89 case QMessageBox::Cancel:
95 outputFile=fd->selectedFile();
103 bool ExportBase::canceled()
108 QString ExportBase::getSectionString(BranchObj *bostart)
110 // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
112 BranchObj *bo=bostart;
113 int depth=bo->getDepth();
116 r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
117 bo=(BranchObj*)(bo->getParObj());
118 depth=bo->getDepth();
126 ////////////////////////////////////////////////////////////////////////
127 ExportASCII::ExportASCII()
129 filter="TXT (*.txt)";
130 caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
133 void ExportASCII::doExport()
135 QFile file (outputFile);
136 if ( !file.open( QIODevice::WriteOnly ) )
138 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
141 QTextStream ts( &file ); // use LANG decoding here...
143 // Main loop over all branches
148 bo=mapCenter->first();
153 for (i=0;i<bo->getDepth()-1;i++) curIndent+= indentPerDepth;
155 if (!bo->hasHiddenExportParent() )
157 switch (bo->getDepth())
160 ts << underline (bo->getHeading(),QString("="));
165 ts << (underline (getSectionString(bo) + bo->getHeading(), QString("-") ) );
170 ts << (curIndent + "* " + bo->getHeading());
174 ts << (curIndent + "- " + bo->getHeading());
178 ts << (curIndent + "- " + bo->getHeading());
183 // If necessary, write note
184 if (!bo->getNote().isEmpty())
187 s =curIndent + bo->getNoteASCII( curIndent, 80);
188 s=s.replace ("\n","\n"+curIndent);
189 ts << QString (s+"\n");
197 QString ExportASCII::underline (const QString &text, const QString &line)
199 QString r=text + "\n";
200 for (int j=0;j<text.length();j++) r+=line;
205 ////////////////////////////////////////////////////////////////////////
206 void ExportCSV::doExport()
208 QFile file (outputFile);
209 if ( !file.open( QIODevice::WriteOnly ) )
211 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
214 QTextStream ts( &file ); // use LANG decoding here...
217 ts << "\"Note\"" <<endl;
219 // Main loop over all branches
221 QString curIndent("");
224 bo=mapCenter->first();
227 if (!bo->hasHiddenExportParent() )
229 // If necessary, write note
230 if (!bo->getNote().isEmpty())
232 s =bo->getNoteASCII();
233 s=s.replace ("\n","\n"+curIndent);
234 ts << ("\""+s+"\",");
239 for (i=0;i<bo->getDepth();i++) curIndent+= "\"\",";
242 ts << curIndent << "\"" << bo->getHeading()<<"\""<<endl;
251 ////////////////////////////////////////////////////////////////////////
252 void ExportKDEBookmarks::doExport()
255 if (mapCenter) me=mapCenter->getMapEditor();
259 dia.showCancelButton (true);
260 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
261 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
262 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
263 if (dia.exec()==QDialog::Accepted)
265 me->exportXML(tmpDir.path(),false);
268 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
269 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
270 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
273 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
274 QProcess *proc= new QProcess ;
276 if (!proc->waitForStarted())
278 QMessageBox::warning(0,
279 QObject::tr("Warning"),
280 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
287 ////////////////////////////////////////////////////////////////////////
288 void ExportFirefoxBookmarks::doExport()
291 if (mapCenter) me=mapCenter->getMapEditor();
295 dia.showCancelButton (true);
296 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
297 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
298 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
299 if (dia.exec()==QDialog::Accepted)
301 me->exportXML(tmpDir.path(),false);
305 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
306 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
307 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
310 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
311 QProcess *proc = new QProcess( );
312 proc->addArgument(ub);
314 if ( !proc->start() )
316 QMessageBox::warning(0,
317 QObject::tr("Warning"),
318 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
327 ////////////////////////////////////////////////////////////////////////
328 void ExportTaskjuggler::doExport()
331 if (mapCenter) me=mapCenter->getMapEditor();
334 me->exportXML(tmpDir.path(),false);
337 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
338 p.setOutputFile (outputFile);
339 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
345 ////////////////////////////////////////////////////////////////////////
346 void ExportLaTeX::doExport()
348 // Exports a map to a LaTex file.
349 // This file needs to be included
350 // or inported into a LaTex document
351 // it will not add a preamble, or anything
352 // that makes a full LaTex document.
353 QFile file (outputFile);
354 if ( !file.open( QIODevice::WriteOnly ) ) {
355 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
356 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
359 QTextStream ts( &file ); // use LANG decoding here...
360 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
362 // Main loop over all branches
364 // QString curIndent("");
367 bo=mapCenter->first();
369 if (!bo->hasHiddenExportParent() )
371 if (bo->getDepth()==0);
372 else if (bo->getDepth()==1) {
373 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
375 else if (bo->getDepth()==2) {
376 ts << ("\\section{" + bo->getHeading()+ "}\n");
378 else if (bo->getDepth()==3) {
379 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
381 else if (bo->getDepth()==4) {
382 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
385 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
388 // If necessary, write note
389 if (!bo->getNote().isEmpty()) {
390 ts << (bo->getNoteASCII());
399 ////////////////////////////////////////////////////////////////////////
405 ExportOO::~ExportOO()
409 QString ExportOO::buildList (BranchObj *current)
415 bo=current->getFirstBranch();
418 if (!bo->hasHiddenExportParent() )
421 r+="<text:list text:style-name=\"vym-list\">\n";
424 r+="<text:list-item><text:p >";
425 r+=quotemeta(bo->getHeading());
426 // If necessary, write note
427 if (!bo->getNote().isEmpty())
428 r+=bo->getNoteOpenDoc();
430 r+=buildList (bo); // recursivly add deeper branches
431 r+="</text:list-item>\n";
433 bo=current->getBranchNum(i);
442 void ExportOO::exportPresentation()
446 // Insert new content
447 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
448 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
453 BranchObj *sectionBO=mapCenter->getFirstBranch();
459 while (sectionBO && !sectionBO->hasHiddenExportParent() )
463 // Add page with section title
464 onePage=sectionTemplate;
465 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
469 i=-2; // only use inner loop to
470 // turn mainbranches into pages
475 pagesBO=sectionBO->getFirstBranch();
477 while (pagesBO && !pagesBO->hasHiddenExportParent() )
479 // Add page with list of items
480 onePage=pageTemplate;
481 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
482 list=buildList (pagesBO);
483 onePage.replace ("<!-- INSERT LIST -->", list);
486 pagesBO=sectionBO->getBranchNum(j);
489 sectionBO=mapCenter->getBranchNum(i);
492 content.replace ("<!-- INSERT PAGES -->",allPages);
494 // Write modified content
495 QFile f (contentFile);
496 if ( !f.open( QIODevice::WriteOnly ) )
498 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
499 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
507 // zip tmpdir to destination
508 zipDir (tmpDir,outputFile);
511 bool ExportOO::setConfigFile (const QString &cf)
514 int i=cf.findRev ("/");
515 if (i>=0) configDir=cf.left(i);
517 set.readSettings(configFile);
520 templateDir=configDir+"/"+set.readEntry ("Template");
522 QDir d (templateDir);
525 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
530 contentTemplateFile=templateDir+"content-template.xml";
531 contentFile=tmpDir.path()+"/content.xml";
532 pageTemplateFile=templateDir+"page-template.xml";
533 sectionTemplateFile=templateDir+"section-template.xml";
535 if (set.readEntry("useSections").contains("yes"))
538 // Copy template to tmpdir
539 system ("cp -r "+templateDir+"* "+tmpDir.path());
541 // Read content-template
542 if (!loadStringFromDisk (contentTemplateFile,content))
544 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
548 // Read page-template
549 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
551 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
555 // Read section-template
556 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
558 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));