3 #include "branchitem.h"
5 #include "linkablemapobj.h"
7 #include "mainwindow.h"
8 #include "warningdialog.h"
11 extern Main *mainWindow;
12 extern QDir vymBaseDir;
13 extern QString vymName;
15 ExportBase::ExportBase()
19 tmpDir.setPath (makeTmpDir(ok,"vym-export"));
20 if (!tmpDir.exists() || !ok)
21 QMessageBox::critical( 0, QObject::tr( "Error" ),
22 QObject::tr("Couldn't access temporary directory\n"));
26 ExportBase::~ExportBase()
32 void ExportBase::setDir(const QDir &d)
37 void ExportBase::setFile (const QString &p)
42 QString ExportBase::getFile ()
47 void ExportBase::setModel(VymModel *m)
52 void ExportBase::setCaption (const QString &s)
57 void ExportBase::addFilter(const QString &s)
62 bool ExportBase::execDialog()
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(TreeItem *start)
111 // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
114 int depth=ti->depth();
117 r=QString("%1").arg(1+ti->num(),0,10)+"." + r;
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
148 BranchItem *cur=NULL;
149 BranchItem *prev=NULL;
151 cur=model->next (cur,prev);
154 if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
158 for (i=0;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
160 if (!cur->hasHiddenExportParent() )
162 //std::cout << "ExportASCII:: "<<curIndent.toStdString()<<cur->getHeading().toStdString()<<std::endl;
163 switch (cur->depth())
166 ts << underline (cur->getHeading(),QString("="));
171 ts << (underline (getSectionString(cur) + cur->getHeading(), QString("-") ) );
176 ts << (curIndent + "* " + cur->getHeading());
180 ts << (curIndent + "- " + cur->getHeading());
184 ts << (curIndent + "- " + cur->getHeading());
189 // If necessary, write note
190 if (!cur->getNoteObj().isEmpty())
193 s=cur->getNoteASCII( curIndent, 80);
198 cur=model->next(cur,prev);
203 QString ExportASCII::underline (const QString &text, const QString &line)
205 QString r=text + "\n";
206 for (int j=0;j<text.length();j++) r+=line;
211 ////////////////////////////////////////////////////////////////////////
212 void ExportCSV::doExport()
214 QFile file (outputFile);
215 if ( !file.open( QIODevice::WriteOnly ) )
217 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
220 QTextStream ts( &file ); // use LANG decoding here...
223 ts << "\"Note\"" <<endl;
225 // Main loop over all branches
227 QString curIndent("");
229 BranchObj *bo; //FIXME-3 still needed?
230 BranchItem *cur=NULL;
231 BranchItem *prev=NULL;
232 cur=model->next (cur,prev);
235 bo=(BranchObj*)(cur->getLMO());
237 if (!cur->hasHiddenExportParent() )
239 // If necessary, write note
240 if (!cur->getNoteObj().isEmpty())
242 s =cur->getNoteASCII();
243 s=s.replace ("\n","\n"+curIndent);
244 ts << ("\""+s+"\",");
249 for (i=0;i<cur->depth();i++) curIndent+= "\"\",";
252 ts << curIndent << "\"" << cur->getHeading()<<"\""<<endl;
255 cur=model->next(cur,prev);
261 ////////////////////////////////////////////////////////////////////////
262 void ExportKDE3Bookmarks::doExport()
265 dia.showCancelButton (true);
266 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
267 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE 3"));
268 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
269 if (dia.exec()==QDialog::Accepted)
271 model->exportXML(tmpDir.path(),false);
274 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
275 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
276 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
279 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
280 QProcess *proc= new QProcess ;
282 if (!proc->waitForStarted())
284 QMessageBox::warning(0,
285 QObject::tr("Warning"),
286 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
291 ////////////////////////////////////////////////////////////////////////
292 void ExportKDE4Bookmarks::doExport()
295 dia.showCancelButton (true);
296 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE 4"));
297 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
298 dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
299 if (dia.exec()==QDialog::Accepted)
301 model->exportXML(tmpDir.path(),false);
304 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
305 p.setOutputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
306 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
309 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
310 QProcess *proc= new QProcess ;
312 if (!proc->waitForStarted())
314 QMessageBox::warning(0,
315 QObject::tr("Warning"),
316 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
321 ////////////////////////////////////////////////////////////////////////
322 void ExportFirefoxBookmarks::doExport()
325 dia.showCancelButton (true);
326 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
327 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
328 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
329 if (dia.exec()==QDialog::Accepted)
331 model->exportXML(tmpDir.path(),false);
335 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
336 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
337 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
340 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
341 QProcess *proc = new QProcess( );
342 proc->addArgument(ub);
344 if ( !proc->start() )
346 QMessageBox::warning(0,
347 QObject::tr("Warning"),
348 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
355 ////////////////////////////////////////////////////////////////////////
356 void ExportTaskjuggler::doExport()
358 model->exportXML(tmpDir.path(),false);
361 p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
362 p.setOutputFile (outputFile);
363 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
367 ////////////////////////////////////////////////////////////////////////
368 void ExportLaTeX::doExport()
370 // Exports a map to a LaTex file.
371 // This file needs to be included
372 // or inported into a LaTex document
373 // it will not add a preamble, or anything
374 // that makes a full LaTex document.
375 QFile file (outputFile);
376 if ( !file.open( QIODevice::WriteOnly ) ) {
377 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
378 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
381 QTextStream ts( &file ); // use LANG decoding here...
382 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
384 // Main loop over all branches
386 // QString curIndent("");
389 BranchItem *cur=NULL;
390 BranchItem *prev=NULL;
391 model->next(cur,prev);
394 bo=(BranchObj*)(cur->getLMO());
396 if (!cur->hasHiddenExportParent() )
398 switch (cur->depth() )
402 ts << ("\\chapter{" + cur->getHeading()+ "}\n");
405 ts << ("\\section{" + cur->getHeading()+ "}\n");
408 ts << ("\\subsection{" + cur->getHeading()+ "}\n");
411 ts << ("\\subsubsection{" + cur->getHeading()+ "}\n");
414 ts << ("\\paragraph*{" + cur->getHeading()+ "}\n");
417 // If necessary, write note
418 if (!cur->getNoteObj().isEmpty()) {
419 ts << (cur->getNoteASCII());
423 cur=model->next(cur,prev);
428 ////////////////////////////////////////////////////////////////////////
434 ExportOO::~ExportOO()
438 QString ExportOO::buildList (TreeItem *current)
443 BranchItem *bi=current->getFirstBranch();
446 if (true) //if (!bo->hasHiddenExportParent() ) // FIXME-2 use BranchItem...
449 r+="<text:list text:style-name=\"vym-list\">\n";
452 r+="<text:list-item><text:p >";
453 r+=quotemeta(bi->getHeading());
454 // If necessary, write note
455 if (!bi->getNoteObj().isEmpty())
456 r+=bi->getNoteOpenDoc();
458 r+=buildList (bi); // recursivly add deeper branches
459 r+="</text:list-item>\n";
461 bi=current->getBranchNum(i);
470 void ExportOO::exportPresentation()
474 /* FIXME-2 not adapted to multiple mapCenters yet, see patch already done in 1.12.2...
475 // Insert new content
476 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
477 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
482 BranchObj *sectionBO=mapCenter->getFirstBranch();
488 while (sectionBO && !sectionBO->hasHiddenExportParent() )
492 // Add page with section title
493 onePage=sectionTemplate;
494 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
498 i=-2; // only use inner loop to
499 // turn mainbranches into pages
504 pagesBO=sectionBO->getFirstBranch();
506 while (pagesBO && !pagesBO->hasHiddenExportParent() )
508 // Add page with list of items
509 onePage=pageTemplate;
510 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
511 list=buildList (pagesBO->getTreeItem() );
512 onePage.replace ("<!-- INSERT LIST -->", list);
515 pagesBO=sectionBO->getBranchNum(j);
518 sectionBO=mapCenter->getBranchNum(i);
521 content.replace ("<!-- INSERT PAGES -->",allPages);
523 // Write modified content
524 QFile f (contentFile);
525 if ( !f.open( QIODevice::WriteOnly ) )
527 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
528 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
536 // zip tmpdir to destination
537 zipDir (tmpDir,outputFile);
541 bool ExportOO::setConfigFile (const QString &cf)
544 int i=cf.findRev ("/");
545 if (i>=0) configDir=cf.left(i);
547 set.readSettings(configFile);
550 templateDir=configDir+"/"+set.readEntry ("Template");
552 QDir d (templateDir);
555 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
560 contentTemplateFile=templateDir+"content-template.xml";
561 contentFile=tmpDir.path()+"/content.xml";
562 pageTemplateFile=templateDir+"page-template.xml";
563 sectionTemplateFile=templateDir+"section-template.xml";
565 if (set.readEntry("useSections").contains("yes"))
568 // Copy template to tmpdir
569 system ("cp -r "+templateDir+"* "+tmpDir.path());
571 // Read content-template
572 if (!loadStringFromDisk (contentTemplateFile,content))
574 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
578 // Read page-template
579 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
581 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
585 // Read section-template
586 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
588 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));