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()
62 //MapEditor *me=model.getMapEditor(); FIXME needed?
63 // if (model->mapCenters.count() && me)
65 QFileDialog *fd=new QFileDialog( 0, caption);
66 fd->setFilter (filter);
67 fd->setCaption(caption);
68 fd->setMode( QFileDialog::AnyFile );
72 if ( fd->exec() == QDialog::Accepted )
74 if (QFile (fd->selectedFile()).exists() )
76 QMessageBox mb( vymName,
77 QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
79 QMessageBox::Yes | QMessageBox::Default,
80 QMessageBox::Cancel | QMessageBox::Escape,
82 mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
83 mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
87 case QMessageBox::Yes:
90 case QMessageBox::Cancel:
96 outputFile=fd->selectedFile();
104 bool ExportBase::canceled()
109 QString ExportBase::getSectionString(BranchObj *bostart)
111 // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
113 BranchObj *bo=bostart;
114 int depth=bo->getDepth();
117 r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
118 bo=(BranchObj*)(bo->getParObj());
119 depth=bo->getDepth();
127 ////////////////////////////////////////////////////////////////////////
128 ExportASCII::ExportASCII()
130 filter="TXT (*.txt)";
131 caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
134 void ExportASCII::doExport()
136 QFile file (outputFile);
137 if ( !file.open( QIODevice::WriteOnly ) )
139 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
142 QTextStream ts( &file ); // use LANG decoding here...
144 // Main loop over all branches
154 for (i=0;i<bo->getDepth()-1;i++) curIndent+= indentPerDepth;
156 if (!bo->hasHiddenExportParent() )
158 switch (bo->getDepth())
161 ts << underline (bo->getHeading(),QString("="));
166 ts << (underline (getSectionString(bo) + bo->getHeading(), QString("-") ) );
171 ts << (curIndent + "* " + bo->getHeading());
175 ts << (curIndent + "- " + bo->getHeading());
179 ts << (curIndent + "- " + bo->getHeading());
184 // If necessary, write note
185 if (!bo->getNote().isEmpty())
188 s=bo->getNoteASCII( curIndent, 80);
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("");
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 dia.showCancelButton (true);
256 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
257 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
258 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
259 if (dia.exec()==QDialog::Accepted)
261 model->exportXML(tmpDir.path(),false);
264 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
265 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
266 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
269 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
270 QProcess *proc= new QProcess ;
272 if (!proc->waitForStarted())
274 QMessageBox::warning(0,
275 QObject::tr("Warning"),
276 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
281 ////////////////////////////////////////////////////////////////////////
282 void ExportFirefoxBookmarks::doExport()
285 dia.showCancelButton (true);
286 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
287 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
288 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
289 if (dia.exec()==QDialog::Accepted)
291 model->exportXML(tmpDir.path(),false);
295 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
296 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
297 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
300 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
301 QProcess *proc = new QProcess( );
302 proc->addArgument(ub);
304 if ( !proc->start() )
306 QMessageBox::warning(0,
307 QObject::tr("Warning"),
308 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
315 ////////////////////////////////////////////////////////////////////////
316 void ExportTaskjuggler::doExport()
318 model->exportXML(tmpDir.path(),false);
321 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
322 p.setOutputFile (outputFile);
323 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
327 ////////////////////////////////////////////////////////////////////////
328 void ExportLaTeX::doExport()
330 // Exports a map to a LaTex file.
331 // This file needs to be included
332 // or inported into a LaTex document
333 // it will not add a preamble, or anything
334 // that makes a full LaTex document.
335 QFile file (outputFile);
336 if ( !file.open( QIODevice::WriteOnly ) ) {
337 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
338 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
341 QTextStream ts( &file ); // use LANG decoding here...
342 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
344 // Main loop over all branches
346 // QString curIndent("");
351 if (!bo->hasHiddenExportParent() )
353 if (bo->getDepth()==0);
354 else if (bo->getDepth()==1) {
355 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
357 else if (bo->getDepth()==2) {
358 ts << ("\\section{" + bo->getHeading()+ "}\n");
360 else if (bo->getDepth()==3) {
361 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
363 else if (bo->getDepth()==4) {
364 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
367 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
370 // If necessary, write note
371 if (!bo->getNote().isEmpty()) {
372 ts << (bo->getNoteASCII());
381 ////////////////////////////////////////////////////////////////////////
387 ExportOO::~ExportOO()
391 QString ExportOO::buildList (BranchObj *current)
397 bo=current->getFirstBranch();
400 if (!bo->hasHiddenExportParent() )
403 r+="<text:list text:style-name=\"vym-list\">\n";
406 r+="<text:list-item><text:p >";
407 r+=quotemeta(bo->getHeading());
408 // If necessary, write note
409 if (!bo->getNote().isEmpty())
410 r+=bo->getNoteOpenDoc();
412 r+=buildList (bo); // recursivly add deeper branches
413 r+="</text:list-item>\n";
415 bo=current->getBranchNum(i);
424 void ExportOO::exportPresentation()
428 /* FIXME not adapted to multiple mapCenters yet
429 // Insert new content
430 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
431 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
436 BranchObj *sectionBO=mapCenter->getFirstBranch();
442 while (sectionBO && !sectionBO->hasHiddenExportParent() )
446 // Add page with section title
447 onePage=sectionTemplate;
448 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
452 i=-2; // only use inner loop to
453 // turn mainbranches into pages
458 pagesBO=sectionBO->getFirstBranch();
460 while (pagesBO && !pagesBO->hasHiddenExportParent() )
462 // Add page with list of items
463 onePage=pageTemplate;
464 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
465 list=buildList (pagesBO);
466 onePage.replace ("<!-- INSERT LIST -->", list);
469 pagesBO=sectionBO->getBranchNum(j);
472 sectionBO=mapCenter->getBranchNum(i);
475 content.replace ("<!-- INSERT PAGES -->",allPages);
477 // Write modified content
478 QFile f (contentFile);
479 if ( !f.open( QIODevice::WriteOnly ) )
481 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
482 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
490 // zip tmpdir to destination
491 zipDir (tmpDir,outputFile);
495 bool ExportOO::setConfigFile (const QString &cf)
498 int i=cf.findRev ("/");
499 if (i>=0) configDir=cf.left(i);
501 set.readSettings(configFile);
504 templateDir=configDir+"/"+set.readEntry ("Template");
506 QDir d (templateDir);
509 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
514 contentTemplateFile=templateDir+"content-template.xml";
515 contentFile=tmpDir.path()+"/content.xml";
516 pageTemplateFile=templateDir+"page-template.xml";
517 sectionTemplateFile=templateDir+"section-template.xml";
519 if (set.readEntry("useSections").contains("yes"))
522 // Copy template to tmpdir
523 system ("cp -r "+templateDir+"* "+tmpDir.path());
525 // Read content-template
526 if (!loadStringFromDisk (contentTemplateFile,content))
528 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
532 // Read page-template
533 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
535 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
539 // Read section-template
540 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
542 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));