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"));
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->getDepth()==0)
156 ts << (bo->getHeading()+ "\n");
157 for (j=0;j<bo->getHeading().length();j++) ts<<"=";
159 } else if (bo->getDepth()==1)
160 ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
161 else if (bo->getDepth()==2)
162 ts << (actIndent + " * " + bo->getHeading()+ "\n");
163 else if (bo->getDepth()==3)
164 ts << (actIndent + " o " + bo->getHeading()+ "\n");
166 ts << (actIndent + " - " + bo->getHeading()+ "\n");
168 // If necessary, write note
169 if (!bo->getNote().isEmpty())
171 s =bo->getNoteASCII();
172 s=s.replace ("\n","\n"+actIndent);
182 ////////////////////////////////////////////////////////////////////////
183 void ExportCSV::doExport()
185 QFile file (outputFile);
186 if ( !file.open( QIODevice::WriteOnly ) )
188 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
191 QTextStream ts( &file ); // use LANG decoding here...
194 ts << "\"Note\"" <<endl;
196 // Main loop over all branches
198 QString actIndent("");
201 bo=mapCenter->first();
204 // If necessary, write note
205 if (!bo->getNote().isEmpty())
207 s =bo->getNoteASCII();
208 s=s.replace ("\n","\n"+actIndent);
209 ts << ("\""+s+"\",");
214 for (i=0;i<bo->getDepth();i++) actIndent+= "\"\",";
217 ts << actIndent << "\"" << bo->getHeading()<<"\""<<endl;
225 ////////////////////////////////////////////////////////////////////////
226 void ExportKDEBookmarks::doExport()
229 if (mapCenter) me=mapCenter->getMapEditor();
233 dia.showCancelButton (true);
234 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
235 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
236 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
237 if (dia.exec()==QDialog::Accepted)
239 me->exportXML(tmpDir.path());
242 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
243 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
244 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
247 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
248 QProcess *proc= new QProcess ;
250 if (!proc->waitForStarted())
252 QMessageBox::warning(0,
253 QObject::tr("Warning"),
254 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
261 ////////////////////////////////////////////////////////////////////////
262 void ExportFirefoxBookmarks::doExport()
265 if (mapCenter) me=mapCenter->getMapEditor();
269 dia.showCancelButton (true);
270 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
271 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
272 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
273 if (dia.exec()==QDialog::Accepted)
275 me->exportXML(tmpDir.path());
279 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
280 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
281 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
284 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
285 QProcess *proc = new QProcess( );
286 proc->addArgument(ub);
288 if ( !proc->start() )
290 QMessageBox::warning(0,
291 QObject::tr("Warning"),
292 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
301 ////////////////////////////////////////////////////////////////////////
302 void ExportTaskjuggler::doExport()
305 if (mapCenter) me=mapCenter->getMapEditor();
308 me->exportXML(tmpDir.path());
311 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
312 p.setOutputFile (outputFile);
313 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
319 ////////////////////////////////////////////////////////////////////////
320 void ExportLaTeX::doExport()
322 // Exports a map to a LaTex file.
323 // This file needs to be included
324 // or inported into a LaTex document
325 // it will not add a preamble, or anything
326 // that makes a full LaTex document.
327 QFile file (outputFile);
328 if ( !file.open( QIODevice::WriteOnly ) ) {
329 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
330 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
333 QTextStream ts( &file ); // use LANG decoding here...
334 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
336 // Main loop over all branches
338 // QString actIndent("");
341 bo=mapCenter->first();
343 if (bo->getDepth()==0);
344 else if (bo->getDepth()==1) {
345 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
347 else if (bo->getDepth()==2) {
348 ts << ("\\section{" + bo->getHeading()+ "}\n");
350 else if (bo->getDepth()==3) {
351 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
353 else if (bo->getDepth()==4) {
354 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
357 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
360 // If necessary, write note
361 if (!bo->getNote().isEmpty()) {
362 ts << (bo->getNoteASCII());
370 ////////////////////////////////////////////////////////////////////////
376 ExportOO::~ExportOO()
380 QString ExportOO::buildList (BranchObj *current)
386 bo=current->getFirstBranch();
390 r+="<text:list text:style-name=\"vym-list\">\n";
393 r+="<text:list-item><text:p >";
394 r+=quotemeta(bo->getHeading());
395 // If necessary, write note
396 if (!bo->getNote().isEmpty())
397 r+=bo->getNoteOpenDoc();
399 r+=buildList (bo); // recursivly add deeper branches
400 r+="</text:list-item>\n";
402 bo=current->getBranchNum(i);
410 void ExportOO::exportPresentation()
414 // Insert new content
415 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
416 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
421 BranchObj *sectionBO=mapCenter->getFirstBranch();
431 // Add page with section title
432 onePage=sectionTemplate;
433 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
437 i=-2; // only use inner loop to
438 // turn mainbranches into pages
443 pagesBO=sectionBO->getFirstBranch();
447 // Add page with list of items
448 onePage=pageTemplate;
449 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
450 list=buildList (pagesBO);
451 onePage.replace ("<!-- INSERT LIST -->", list);
454 pagesBO=sectionBO->getBranchNum(j);
457 sectionBO=mapCenter->getBranchNum(i);
460 content.replace ("<!-- INSERT PAGES -->",allPages);
462 // Write modified content
463 QFile f (contentFile);
464 if ( !f.open( QIODevice::WriteOnly ) )
466 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
467 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
475 // zip tmpdir to destination
476 zipDir (tmpDir,outputFile);
479 bool ExportOO::setConfigFile (const QString &cf)
482 int i=cf.findRev ("/");
483 if (i>=0) configDir=cf.left(i);
485 set.readSettings(configFile);
488 templateDir=configDir+"/"+set.readEntry ("Template");
490 QDir d (templateDir);
493 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
498 contentTemplateFile=templateDir+"content-template.xml";
499 contentFile=tmpDir.path()+"/content.xml";
500 pageTemplateFile=templateDir+"page-template.xml";
501 sectionTemplateFile=templateDir+"section-template.xml";
503 if (set.readEntry("useSections").contains("yes"))
506 // Copy template to tmpdir
507 system ("cp -r "+templateDir+"* "+tmpDir.path());
509 // Read content-template
510 if (!loadStringFromDisk (contentTemplateFile,content))
512 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
516 // Read page-template
517 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
519 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
523 // Read section-template
524 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
526 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));