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()
63 QFileDialog *fd=new QFileDialog( 0, caption);
64 fd->setFilter (filter);
65 fd->setCaption(caption);
66 fd->setMode( QFileDialog::AnyFile );
70 if ( fd->exec() == QDialog::Accepted )
72 if (QFile (fd->selectedFile()).exists() )
74 QMessageBox mb( vymName,
75 QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
77 QMessageBox::Yes | QMessageBox::Default,
78 QMessageBox::Cancel | QMessageBox::Escape,
80 mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
81 mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
85 case QMessageBox::Yes:
88 case QMessageBox::Cancel:
94 outputFile=fd->selectedFile();
102 bool ExportBase::canceled()
107 QString ExportBase::getSectionString(BranchObj *bostart)
109 // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
111 BranchObj *bo=bostart;
112 int depth=bo->getDepth();
115 r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
116 bo=(BranchObj*)(bo->getParObj());
117 depth=bo->getDepth();
125 ////////////////////////////////////////////////////////////////////////
126 ExportASCII::ExportASCII()
128 filter="TXT (*.txt)";
129 caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
132 void ExportASCII::doExport()
134 QFile file (outputFile);
135 if ( !file.open( QIODevice::WriteOnly ) )
137 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
140 QTextStream ts( &file ); // use LANG decoding here...
142 // Main loop over all branches
151 if (ti->getType()==TreeItem::Branch || ti->getType()==TreeItem::MapCenter)
153 bo=(BranchObj*)(ti->getLMO());
157 for (i=0;i<ti->depth()-1;i++) curIndent+= indentPerDepth;
159 if (!bo->hasHiddenExportParent() )
164 ts << underline (ti->getHeading(),QString("="));
169 ts << (underline (getSectionString(bo) + ti->getHeading(), QString("-") ) );
174 ts << (curIndent + "* " + ti->getHeading());
178 ts << (curIndent + "- " + ti->getHeading());
182 ts << (curIndent + "- " + ti->getHeading());
187 // If necessary, write note
188 if (!bo->getNote().isEmpty())
191 s=bo->getNoteASCII( curIndent, 80);
201 QString ExportASCII::underline (const QString &text, const QString &line)
203 QString r=text + "\n";
204 for (int j=0;j<text.length();j++) r+=line;
209 ////////////////////////////////////////////////////////////////////////
210 void ExportCSV::doExport()
212 QFile file (outputFile);
213 if ( !file.open( QIODevice::WriteOnly ) )
215 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
218 QTextStream ts( &file ); // use LANG decoding here...
221 ts << "\"Note\"" <<endl;
223 // Main loop over all branches
225 QString curIndent("");
228 TreeItem *ti=model->first();
231 bo=(BranchObj*)(ti->getLMO());
233 if (!bo->hasHiddenExportParent() )
235 // If necessary, write note
236 if (!bo->getNote().isEmpty())
238 s =bo->getNoteASCII();
239 s=s.replace ("\n","\n"+curIndent);
240 ts << ("\""+s+"\",");
245 for (i=0;i<ti->depth();i++) curIndent+= "\"\",";
248 ts << curIndent << "\"" << ti->getHeading()<<"\""<<endl;
257 ////////////////////////////////////////////////////////////////////////
258 void ExportKDEBookmarks::doExport()
261 dia.showCancelButton (true);
262 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
263 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
264 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
265 if (dia.exec()==QDialog::Accepted)
267 model->exportXML(tmpDir.path(),false);
270 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
271 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
272 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
275 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
276 QProcess *proc= new QProcess ;
278 if (!proc->waitForStarted())
280 QMessageBox::warning(0,
281 QObject::tr("Warning"),
282 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
287 ////////////////////////////////////////////////////////////////////////
288 void ExportFirefoxBookmarks::doExport()
291 dia.showCancelButton (true);
292 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
293 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
294 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
295 if (dia.exec()==QDialog::Accepted)
297 model->exportXML(tmpDir.path(),false);
301 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
302 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
303 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
306 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
307 QProcess *proc = new QProcess( );
308 proc->addArgument(ub);
310 if ( !proc->start() )
312 QMessageBox::warning(0,
313 QObject::tr("Warning"),
314 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
321 ////////////////////////////////////////////////////////////////////////
322 void ExportTaskjuggler::doExport()
324 model->exportXML(tmpDir.path(),false);
327 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
328 p.setOutputFile (outputFile);
329 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
333 ////////////////////////////////////////////////////////////////////////
334 void ExportLaTeX::doExport()
336 // Exports a map to a LaTex file.
337 // This file needs to be included
338 // or inported into a LaTex document
339 // it will not add a preamble, or anything
340 // that makes a full LaTex document.
341 QFile file (outputFile);
342 if ( !file.open( QIODevice::WriteOnly ) ) {
343 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
344 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
347 QTextStream ts( &file ); // use LANG decoding here...
348 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
350 // Main loop over all branches
352 // QString curIndent("");
355 TreeItem *ti=model->first();
358 bo=(BranchObj*)(ti->getLMO());
360 if (!bo->hasHiddenExportParent() )
362 switch (ti->depth() )
366 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
369 ts << ("\\section{" + bo->getHeading()+ "}\n");
372 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
375 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
378 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
381 // If necessary, write note
382 if (!bo->getNote().isEmpty()) {
383 ts << (bo->getNoteASCII());
392 ////////////////////////////////////////////////////////////////////////
398 ExportOO::~ExportOO()
402 QString ExportOO::buildList (BranchObj *current)
408 bo=current->getFirstBranch();
411 if (!bo->hasHiddenExportParent() )
414 r+="<text:list text:style-name=\"vym-list\">\n";
417 r+="<text:list-item><text:p >";
418 r+=quotemeta(bo->getHeading());
419 // If necessary, write note
420 if (!bo->getNote().isEmpty())
421 r+=bo->getNoteOpenDoc();
423 r+=buildList (bo); // recursivly add deeper branches
424 r+="</text:list-item>\n";
426 bo=current->getBranchNum(i);
435 void ExportOO::exportPresentation()
439 /* FIXME not adapted to multiple mapCenters yet
440 // Insert new content
441 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
442 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
447 BranchObj *sectionBO=mapCenter->getFirstBranch();
453 while (sectionBO && !sectionBO->hasHiddenExportParent() )
457 // Add page with section title
458 onePage=sectionTemplate;
459 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
463 i=-2; // only use inner loop to
464 // turn mainbranches into pages
469 pagesBO=sectionBO->getFirstBranch();
471 while (pagesBO && !pagesBO->hasHiddenExportParent() )
473 // Add page with list of items
474 onePage=pageTemplate;
475 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
476 list=buildList (pagesBO);
477 onePage.replace ("<!-- INSERT LIST -->", list);
480 pagesBO=sectionBO->getBranchNum(j);
483 sectionBO=mapCenter->getBranchNum(i);
486 content.replace ("<!-- INSERT PAGES -->",allPages);
488 // Write modified content
489 QFile f (contentFile);
490 if ( !f.open( QIODevice::WriteOnly ) )
492 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
493 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
501 // zip tmpdir to destination
502 zipDir (tmpDir,outputFile);
506 bool ExportOO::setConfigFile (const QString &cf)
509 int i=cf.findRev ("/");
510 if (i>=0) configDir=cf.left(i);
512 set.readSettings(configFile);
515 templateDir=configDir+"/"+set.readEntry ("Template");
517 QDir d (templateDir);
520 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
525 contentTemplateFile=templateDir+"content-template.xml";
526 contentFile=tmpDir.path()+"/content.xml";
527 pageTemplateFile=templateDir+"page-template.xml";
528 sectionTemplateFile=templateDir+"section-template.xml";
530 if (set.readEntry("useSections").contains("yes"))
533 // Copy template to tmpdir
534 system ("cp -r "+templateDir+"* "+tmpDir.path());
536 // Read content-template
537 if (!loadStringFromDisk (contentTemplateFile,content))
539 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
543 // Read page-template
544 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
546 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
550 // Read section-template
551 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
553 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));