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 (makeUniqueDir(ok,"/tmp/vym-export-XXXXXX"));
18 if (!tmpDir.exists() || !ok)
19 QMessageBox::critical( 0, QObject::tr( "Error" ),
20 QObject::tr("Couldn't access temporary directory\n"));
23 ExportBase::~ExportBase()
29 void ExportBase::setDir(const QDir &d)
34 void ExportBase::setFile (const QString &p)
39 void ExportBase::setMapCenter(MapCenterObj *mc)
44 void ExportBase::setCaption (const QString &s)
49 void ExportBase::addFilter(const QString &s)
54 bool ExportBase::execDialog()
56 if (mapCenter && mapCenter->getMapEditor())
58 QFileDialog *fd=new QFileDialog( mapCenter->getMapEditor(), caption);
59 fd->setFilter (filter);
60 fd->setCaption(caption);
61 fd->setMode( QFileDialog::AnyFile );
65 if ( fd->exec() == QDialog::Accepted )
67 if (QFile (fd->selectedFile()).exists() )
69 QMessageBox mb( vymName,
70 QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
72 QMessageBox::Yes | QMessageBox::Default,
73 QMessageBox::Cancel | QMessageBox::Escape,
75 mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
76 mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
80 case QMessageBox::Yes:
83 case QMessageBox::Cancel:
89 outputFile=fd->selectedFile();
96 QString ExportBase::getSectionString(BranchObj *bostart)
98 // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
100 BranchObj *bo=bostart;
101 int depth=bo->getDepth();
104 r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
105 bo=(BranchObj*)(bo->getParObj());
106 depth=bo->getDepth();
114 ////////////////////////////////////////////////////////////////////////
115 void ExportASCII::doExport()
117 QFile file (outputFile);
118 if ( !file.open( QIODevice::WriteOnly ) )
120 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
123 QTextStream ts( &file ); // use LANG decoding here...
125 // Main loop over all branches
127 QString actIndent("");
130 bo=mapCenter->first();
134 for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
136 if (bo->getDepth()==0)
138 ts << (bo->getHeading()+ "\n");
139 for (j=0;j<bo->getHeading().length();j++) ts<<"=";
141 } else if (bo->getDepth()==1)
142 ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
143 else if (bo->getDepth()==2)
144 ts << (actIndent + " * " + bo->getHeading()+ "\n");
145 else if (bo->getDepth()==3)
146 ts << (actIndent + " o " + bo->getHeading()+ "\n");
148 ts << (actIndent + " - " + bo->getHeading()+ "\n");
150 // If necessary, write note
151 if (!bo->getNote().isEmpty())
153 s =bo->getNoteASCII();
154 s=s.replace ("\n","\n"+actIndent);
164 ////////////////////////////////////////////////////////////////////////
165 void ExportCSV::doExport()
167 QFile file (outputFile);
168 if ( !file.open( QIODevice::WriteOnly ) )
170 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
173 QTextStream ts( &file ); // use LANG decoding here...
176 ts << "\"Note\"" <<endl;
178 // Main loop over all branches
180 QString actIndent("");
183 bo=mapCenter->first();
186 // If necessary, write note
187 if (!bo->getNote().isEmpty())
189 s =bo->getNoteASCII();
190 s=s.replace ("\n","\n"+actIndent);
191 ts << ("\""+s+"\",");
196 for (i=0;i<bo->getDepth();i++) actIndent+= "\"\",";
199 ts << actIndent << "\"" << bo->getHeading()<<"\""<<endl;
207 ////////////////////////////////////////////////////////////////////////
208 void ExportKDEBookmarks::doExport()
211 if (mapCenter) me=mapCenter->getMapEditor();
215 dia.showCancelButton (true);
216 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
217 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
218 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
219 if (dia.exec()==QDialog::Accepted)
221 me->exportXML(tmpDir.path());
224 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
225 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
226 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
229 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
230 QProcess *proc= new QProcess ;
232 if (!proc->waitForStarted())
234 QMessageBox::warning(0,
235 QObject::tr("Warning"),
236 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
243 ////////////////////////////////////////////////////////////////////////
244 void ExportFirefoxBookmarks::doExport()
247 if (mapCenter) me=mapCenter->getMapEditor();
251 dia.showCancelButton (true);
252 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
253 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
254 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
255 if (dia.exec()==QDialog::Accepted)
257 me->exportXML(tmpDir.path());
261 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
262 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
263 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
266 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
267 QProcess *proc = new QProcess( );
268 proc->addArgument(ub);
270 if ( !proc->start() )
272 QMessageBox::warning(0,
273 QObject::tr("Warning"),
274 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
283 ////////////////////////////////////////////////////////////////////////
284 void ExportTaskjuggler::doExport()
287 if (mapCenter) me=mapCenter->getMapEditor();
290 me->exportXML(tmpDir.path());
293 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
294 p.setOutputFile (outputFile);
295 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
301 ////////////////////////////////////////////////////////////////////////
302 void ExportLaTeX::doExport()
304 // Exports a map to a LaTex file.
305 // This file needs to be included
306 // or inported into a LaTex document
307 // it will not add a preamble, or anything
308 // that makes a full LaTex document.
309 QFile file (outputFile);
310 if ( !file.open( QIODevice::WriteOnly ) ) {
311 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
312 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
315 QTextStream ts( &file ); // use LANG decoding here...
316 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
318 // Main loop over all branches
320 // QString actIndent("");
323 bo=mapCenter->first();
325 if (bo->getDepth()==0);
326 else if (bo->getDepth()==1) {
327 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
329 else if (bo->getDepth()==2) {
330 ts << ("\\section{" + bo->getHeading()+ "}\n");
332 else if (bo->getDepth()==3) {
333 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
335 else if (bo->getDepth()==4) {
336 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
339 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
342 // If necessary, write note
343 if (!bo->getNote().isEmpty()) {
344 ts << (bo->getNoteASCII());
352 ////////////////////////////////////////////////////////////////////////
358 ExportOO::~ExportOO()
362 QString ExportOO::buildList (BranchObj *current)
368 bo=current->getFirstBranch();
372 r+="<text:list text:style-name=\"vym-list\">\n";
375 r+="<text:list-item><text:p >";
376 r+=quotemeta(bo->getHeading());
377 // If necessary, write note
378 if (!bo->getNote().isEmpty())
379 r+=bo->getNoteOpenDoc();
381 r+=buildList (bo); // recursivly add deeper branches
382 r+="</text:list-item>\n";
384 bo=current->getBranchNum(i);
392 void ExportOO::exportPresentation()
396 // Insert new content
397 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
398 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
403 BranchObj *sectionBO=mapCenter->getFirstBranch();
413 // Add page with section title
414 onePage=sectionTemplate;
415 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
419 i=-2; // only use inner loop to
420 // turn mainbranches into pages
425 pagesBO=sectionBO->getFirstBranch();
429 // Add page with list of items
430 onePage=pageTemplate;
431 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
432 list=buildList (pagesBO);
433 onePage.replace ("<!-- INSERT LIST -->", list);
436 pagesBO=sectionBO->getBranchNum(j);
439 sectionBO=mapCenter->getBranchNum(i);
442 content.replace ("<!-- INSERT PAGES -->",allPages);
444 // Write modified content
445 QFile f (contentFile);
446 if ( !f.open( QIODevice::WriteOnly ) )
448 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
449 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
457 // zip tmpdir to destination
458 zipDir (tmpDir,outputFile);
461 bool ExportOO::setConfigFile (const QString &cf)
464 int i=cf.findRev ("/");
465 if (i>=0) configDir=cf.left(i);
467 set.readSettings(configFile);
470 templateDir=configDir+"/"+set.readEntry ("Template");
472 QDir d (templateDir);
475 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
480 contentTemplateFile=templateDir+"content-template.xml";
481 contentFile=tmpDir.path()+"/content.xml";
482 pageTemplateFile=templateDir+"page-template.xml";
483 sectionTemplateFile=templateDir+"section-template.xml";
485 if (set.readEntry("useSections").contains("yes"))
488 // Copy template to tmpdir
489 system ("cp -r "+templateDir+"* "+tmpDir.path());
491 // Read content-template
492 if (!loadStringFromDisk (contentTemplateFile,content))
494 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
498 // Read page-template
499 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
501 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
505 // Read section-template
506 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
508 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));