1 #include <q3filedialog.h>
2 #include <qmessagebox.h>
9 #include "linkablemapobj.h"
11 #include "mainwindow.h"
12 #include "warningdialog.h"
15 extern Main *mainWindow;
16 extern QDir vymBaseDir;
19 ExportBase::ExportBase()
23 // FIXME not neededtmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
24 if (!tmpDir.cd ("tmp"))
25 qWarning ("Could not access temporary directory for export");
26 // FIXME there's more needed here...
29 ExportBase::~ExportBase()
35 void ExportBase::setDir(const QString &p)
40 void ExportBase::setFile (const QString &p)
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 );
70 if ( fd->exec() == QDialog::Accepted )
72 if (QFile (fd->selectedFile()).exists() )
74 QMessageBox mb( __VYM,
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();
101 QString ExportBase::getSectionString(BranchObj *bostart)
103 // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
105 BranchObj *bo=bostart;
106 int depth=bo->getDepth();
109 r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
110 bo=(BranchObj*)(bo->getParObj());
111 depth=bo->getDepth();
120 ////////////////////////////////////////////////////////////////////////
121 void ExportASCII::doExport()
123 QFile file (outputFile);
124 if ( !file.open( QIODevice::WriteOnly ) )
126 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
129 QTextStream ts( &file ); // use LANG decoding here...
131 // Main loop over all branches
133 QString actIndent("");
136 bo=mapCenter->first();
140 for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
142 if (bo->getDepth()==0)
144 ts << (bo->getHeading()+ "\n");
145 for (j=0;j<bo->getHeading().length();j++) ts<<"=";
147 } else if (bo->getDepth()==1)
148 ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
149 else if (bo->getDepth()==2)
150 ts << (actIndent + " o " + bo->getHeading()+ "\n");
152 ts << (actIndent + " - " + bo->getHeading()+ "\n");
154 // If necessary, write note
155 if (!bo->getNote().isEmpty())
157 s =bo->getNoteASCII();
158 s=s.replace ("\n","\n"+actIndent);
167 ////////////////////////////////////////////////////////////////////////
168 void ExportKDEBookmarks::doExport()
171 if (mapCenter) me=mapCenter->getMapEditor();
175 dia.setCancelButton (true);
176 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
177 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
178 dia.setShowAgainName("/vym/warnings/overwriteKDEBookmarks");
179 if (dia.exec()==QDialog::Accepted)
181 me->exportXML(tmpDir.path());
184 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
185 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
186 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
189 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
190 QProcess *proc= new QProcess ();
192 if (!proc->waitForStarted());
194 QMessageBox::warning(0,
195 QObject::tr("Warning"),
196 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
203 ////////////////////////////////////////////////////////////////////////
204 void ExportFirefoxBookmarks::doExport()
207 if (mapCenter) me=mapCenter->getMapEditor();
211 dia.setCancelButton (true);
212 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
213 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
214 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
215 if (dia.exec()==QDialog::Accepted)
217 me->exportXML(tmpDir.path());
221 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
222 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
223 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
226 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
227 QProcess *proc = new QProcess( );
228 proc->addArgument(ub);
230 if ( !proc->start() )
232 QMessageBox::warning(0,
233 QObject::tr("Warning"),
234 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
243 ////////////////////////////////////////////////////////////////////////
244 void ExportTaskjuggler::doExport()
247 if (mapCenter) me=mapCenter->getMapEditor();
250 me->exportXML(tmpDir.path());
253 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
254 p.setOutputFile (outputFile);
255 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
261 ////////////////////////////////////////////////////////////////////////
262 void ExportLaTeX::doExport()
264 // Exports a map to a LaTex file.
265 // This file needs to be included
266 // or inported into a LaTex document
267 // it will not add a preamble, or anything
268 // that makes a full LaTex document.
269 QFile file (outputFile);
270 if ( !file.open( QIODevice::WriteOnly ) ) {
271 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
272 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
275 QTextStream ts( &file ); // use LANG decoding here...
276 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
278 // Main loop over all branches
280 // QString actIndent("");
283 bo=mapCenter->first();
285 if (bo->getDepth()==0);
286 else if (bo->getDepth()==1) {
287 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
289 else if (bo->getDepth()==2) {
290 ts << ("\\section{" + bo->getHeading()+ "}\n");
292 else if (bo->getDepth()==3) {
293 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
295 else if (bo->getDepth()==4) {
296 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
299 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
302 // If necessary, write note
303 if (!bo->getNote().isEmpty()) {
304 ts << (bo->getNoteASCII());
312 ////////////////////////////////////////////////////////////////////////
318 ExportOO::~ExportOO()
322 QString ExportOO::buildList (BranchObj *current)
328 bo=current->getFirstBranch();
332 r+="<text:list text:style-name=\"vym-list\">\n";
335 r+="<text:list-item><text:p >";
336 r+=quotemeta(bo->getHeading());
337 // If necessary, write note
338 if (!bo->getNote().isEmpty())
339 r+=bo->getNoteOpenDoc();
341 r+=buildList (bo); // recursivly add deeper branches
342 r+="</text:list-item>\n";
344 bo=current->getBranchNum(i);
352 void ExportOO::exportPresentation()
356 // Insert new content
357 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
358 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
363 BranchObj *sectionBO=mapCenter->getFirstBranch();
373 // Add page with section title
374 onePage=sectionTemplate;
375 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
379 i=-2; // only use inner loop to
380 // turn mainbranches into pages
385 pagesBO=sectionBO->getFirstBranch();
389 // Add page with list of items
390 onePage=pageTemplate;
391 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
392 list=buildList (pagesBO);
393 onePage.replace ("<!-- INSERT LIST -->", list);
396 pagesBO=sectionBO->getBranchNum(j);
399 sectionBO=mapCenter->getBranchNum(i);
402 content.replace ("<!-- INSERT PAGES -->",allPages);
404 // Write modified content
405 QFile f (contentFile);
406 if ( !f.open( QIODevice::WriteOnly ) )
408 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
409 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
417 // zip tmpdir to destination
418 zipDir (tmpDir,outputFile);
421 bool ExportOO::setConfigFile (const QString &cf)
424 int i=cf.findRev ("/");
425 if (i>=0) configDir=cf.left(i);
427 set.readSettings(configFile);
430 templateDir=configDir+"/"+set.readEntry ("Template");
432 QDir d (templateDir);
435 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
440 contentTemplateFile=templateDir+"content-template.xml";
441 contentFile=tmpDir.path()+"/content.xml";
442 pageTemplateFile=templateDir+"page-template.xml";
443 sectionTemplateFile=templateDir+"section-template.xml";
445 if (set.readEntry("useSections").contains("yes"))
448 // Copy template to tmpdir
449 system ("cp -r "+templateDir+"* "+tmpDir.path());
451 // Read content-template
452 if (!loadStringFromDisk (contentTemplateFile,content))
454 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
458 // Read page-template
459 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
461 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
465 // Read section-template
466 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
468 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));