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();
115 ////////////////////////////////////////////////////////////////////////
116 void ExportASCII::doExport()
118 QFile file (outputFile);
119 if ( !file.open( QIODevice::WriteOnly ) )
121 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
124 QTextStream ts( &file ); // use LANG decoding here...
126 // Main loop over all branches
128 QString actIndent("");
131 bo=mapCenter->first();
135 for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
137 if (bo->getDepth()==0)
139 ts << (bo->getHeading()+ "\n");
140 for (j=0;j<bo->getHeading().length();j++) ts<<"=";
142 } else if (bo->getDepth()==1)
143 ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
144 else if (bo->getDepth()==2)
145 ts << (actIndent + " o " + bo->getHeading()+ "\n");
147 ts << (actIndent + " - " + bo->getHeading()+ "\n");
149 // If necessary, write note
150 if (!bo->getNote().isEmpty())
152 s =bo->getNoteASCII();
153 s=s.replace ("\n","\n"+actIndent);
162 ////////////////////////////////////////////////////////////////////////
163 void ExportKDEBookmarks::doExport()
166 if (mapCenter) me=mapCenter->getMapEditor();
170 dia.showCancelButton (true);
171 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
172 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
173 dia.setShowAgainName("/vym/warnings/overwriteKDEBookmarks");
174 if (dia.exec()==QDialog::Accepted)
176 me->exportXML(tmpDir.path());
179 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
180 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
181 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
184 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
185 QProcess *proc= new QProcess ;
187 if (!proc->waitForStarted())
189 QMessageBox::warning(0,
190 QObject::tr("Warning"),
191 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
198 ////////////////////////////////////////////////////////////////////////
199 void ExportFirefoxBookmarks::doExport()
202 if (mapCenter) me=mapCenter->getMapEditor();
206 dia.showCancelButton (true);
207 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
208 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
209 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
210 if (dia.exec()==QDialog::Accepted)
212 me->exportXML(tmpDir.path());
216 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
217 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
218 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
221 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
222 QProcess *proc = new QProcess( );
223 proc->addArgument(ub);
225 if ( !proc->start() )
227 QMessageBox::warning(0,
228 QObject::tr("Warning"),
229 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
238 ////////////////////////////////////////////////////////////////////////
239 void ExportTaskjuggler::doExport()
242 if (mapCenter) me=mapCenter->getMapEditor();
245 me->exportXML(tmpDir.path());
248 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
249 p.setOutputFile (outputFile);
250 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
256 ////////////////////////////////////////////////////////////////////////
257 void ExportLaTeX::doExport()
259 // Exports a map to a LaTex file.
260 // This file needs to be included
261 // or inported into a LaTex document
262 // it will not add a preamble, or anything
263 // that makes a full LaTex document.
264 QFile file (outputFile);
265 if ( !file.open( QIODevice::WriteOnly ) ) {
266 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
267 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
270 QTextStream ts( &file ); // use LANG decoding here...
271 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
273 // Main loop over all branches
275 // QString actIndent("");
278 bo=mapCenter->first();
280 if (bo->getDepth()==0);
281 else if (bo->getDepth()==1) {
282 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
284 else if (bo->getDepth()==2) {
285 ts << ("\\section{" + bo->getHeading()+ "}\n");
287 else if (bo->getDepth()==3) {
288 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
290 else if (bo->getDepth()==4) {
291 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
294 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
297 // If necessary, write note
298 if (!bo->getNote().isEmpty()) {
299 ts << (bo->getNoteASCII());
307 ////////////////////////////////////////////////////////////////////////
313 ExportOO::~ExportOO()
317 QString ExportOO::buildList (BranchObj *current)
323 bo=current->getFirstBranch();
327 r+="<text:list text:style-name=\"vym-list\">\n";
330 r+="<text:list-item><text:p >";
331 r+=quotemeta(bo->getHeading());
332 // If necessary, write note
333 if (!bo->getNote().isEmpty())
334 r+=bo->getNoteOpenDoc();
336 r+=buildList (bo); // recursivly add deeper branches
337 r+="</text:list-item>\n";
339 bo=current->getBranchNum(i);
347 void ExportOO::exportPresentation()
351 // Insert new content
352 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
353 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
358 BranchObj *sectionBO=mapCenter->getFirstBranch();
368 // Add page with section title
369 onePage=sectionTemplate;
370 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
374 i=-2; // only use inner loop to
375 // turn mainbranches into pages
380 pagesBO=sectionBO->getFirstBranch();
384 // Add page with list of items
385 onePage=pageTemplate;
386 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
387 list=buildList (pagesBO);
388 onePage.replace ("<!-- INSERT LIST -->", list);
391 pagesBO=sectionBO->getBranchNum(j);
394 sectionBO=mapCenter->getBranchNum(i);
397 content.replace ("<!-- INSERT PAGES -->",allPages);
399 // Write modified content
400 QFile f (contentFile);
401 if ( !f.open( QIODevice::WriteOnly ) )
403 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
404 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
412 // zip tmpdir to destination
413 zipDir (tmpDir,outputFile);
416 bool ExportOO::setConfigFile (const QString &cf)
419 int i=cf.findRev ("/");
420 if (i>=0) configDir=cf.left(i);
422 set.readSettings(configFile);
425 templateDir=configDir+"/"+set.readEntry ("Template");
427 QDir d (templateDir);
430 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
435 contentTemplateFile=templateDir+"content-template.xml";
436 contentFile=tmpDir.path()+"/content.xml";
437 pageTemplateFile=templateDir+"page-template.xml";
438 sectionTemplateFile=templateDir+"section-template.xml";
440 if (set.readEntry("useSections").contains("yes"))
443 // Copy template to tmpdir
444 system ("cp -r "+templateDir+"* "+tmpDir.path());
446 // Read content-template
447 if (!loadStringFromDisk (contentTemplateFile,content))
449 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
453 // Read page-template
454 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
456 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
460 // Read section-template
461 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
463 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));