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
145 QString actIndent("");
148 bo=mapCenter->first();
152 for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
154 if (!bo->hasHiddenExportParent() )
156 if (bo->getDepth()==0)
158 ts << (bo->getHeading()+ "\n");
159 for (j=0;j<bo->getHeading().length();j++) ts<<"=";
161 } else if (bo->getDepth()==1)
162 ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
163 else if (bo->getDepth()==2)
164 ts << (actIndent + " * " + bo->getHeading()+ "\n");
165 else if (bo->getDepth()==3)
166 ts << (actIndent + " o " + bo->getHeading()+ "\n");
168 ts << (actIndent + " - " + bo->getHeading()+ "\n");
170 // If necessary, write note
171 if (!bo->getNote().isEmpty())
173 s =bo->getNoteASCII();
174 s=s.replace ("\n","\n"+actIndent);
185 ////////////////////////////////////////////////////////////////////////
186 void ExportCSV::doExport()
188 QFile file (outputFile);
189 if ( !file.open( QIODevice::WriteOnly ) )
191 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
194 QTextStream ts( &file ); // use LANG decoding here...
197 ts << "\"Note\"" <<endl;
199 // Main loop over all branches
201 QString actIndent("");
204 bo=mapCenter->first();
207 if (!bo->hasHiddenExportParent() )
209 // If necessary, write note
210 if (!bo->getNote().isEmpty())
212 s =bo->getNoteASCII();
213 s=s.replace ("\n","\n"+actIndent);
214 ts << ("\""+s+"\",");
219 for (i=0;i<bo->getDepth();i++) actIndent+= "\"\",";
222 ts << actIndent << "\"" << bo->getHeading()<<"\""<<endl;
231 ////////////////////////////////////////////////////////////////////////
232 void ExportKDEBookmarks::doExport()
235 if (mapCenter) me=mapCenter->getMapEditor();
239 dia.showCancelButton (true);
240 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
241 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
242 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
243 if (dia.exec()==QDialog::Accepted)
245 me->exportXML(tmpDir.path(),false);
248 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
249 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
250 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
253 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
254 QProcess *proc= new QProcess ;
256 if (!proc->waitForStarted())
258 QMessageBox::warning(0,
259 QObject::tr("Warning"),
260 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
267 ////////////////////////////////////////////////////////////////////////
268 void ExportFirefoxBookmarks::doExport()
271 if (mapCenter) me=mapCenter->getMapEditor();
275 dia.showCancelButton (true);
276 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
277 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
278 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
279 if (dia.exec()==QDialog::Accepted)
281 me->exportXML(tmpDir.path(),false);
285 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
286 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
287 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
290 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
291 QProcess *proc = new QProcess( );
292 proc->addArgument(ub);
294 if ( !proc->start() )
296 QMessageBox::warning(0,
297 QObject::tr("Warning"),
298 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
307 ////////////////////////////////////////////////////////////////////////
308 void ExportTaskjuggler::doExport()
311 if (mapCenter) me=mapCenter->getMapEditor();
314 me->exportXML(tmpDir.path(),false);
317 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
318 p.setOutputFile (outputFile);
319 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 actIndent("");
347 bo=mapCenter->first();
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 // Insert new content
427 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
428 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
433 BranchObj *sectionBO=mapCenter->getFirstBranch();
439 while (sectionBO && !sectionBO->hasHiddenExportParent() )
443 // Add page with section title
444 onePage=sectionTemplate;
445 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
449 i=-2; // only use inner loop to
450 // turn mainbranches into pages
455 pagesBO=sectionBO->getFirstBranch();
457 while (pagesBO && !pagesBO->hasHiddenExportParent() )
459 // Add page with list of items
460 onePage=pageTemplate;
461 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
462 list=buildList (pagesBO);
463 onePage.replace ("<!-- INSERT LIST -->", list);
466 pagesBO=sectionBO->getBranchNum(j);
469 sectionBO=mapCenter->getBranchNum(i);
472 content.replace ("<!-- INSERT PAGES -->",allPages);
474 // Write modified content
475 QFile f (contentFile);
476 if ( !f.open( QIODevice::WriteOnly ) )
478 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
479 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
487 // zip tmpdir to destination
488 zipDir (tmpDir,outputFile);
491 bool ExportOO::setConfigFile (const QString &cf)
494 int i=cf.findRev ("/");
495 if (i>=0) configDir=cf.left(i);
497 set.readSettings(configFile);
500 templateDir=configDir+"/"+set.readEntry ("Template");
502 QDir d (templateDir);
505 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
510 contentTemplateFile=templateDir+"content-template.xml";
511 contentFile=tmpDir.path()+"/content.xml";
512 pageTemplateFile=templateDir+"page-template.xml";
513 sectionTemplateFile=templateDir+"section-template.xml";
515 if (set.readEntry("useSections").contains("yes"))
518 // Copy template to tmpdir
519 system ("cp -r "+templateDir+"* "+tmpDir.path());
521 // Read content-template
522 if (!loadStringFromDisk (contentTemplateFile,content))
524 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
528 // Read page-template
529 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
531 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
535 // Read section-template
536 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
538 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));