Runs basically on Mac now. Undo debug output still enabled
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 tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
26 ExportBase::~ExportBase()
32 void ExportBase::setDir(const QString &p)
37 void ExportBase::setFile (const QString &p)
42 void ExportBase::setMapCenter(MapCenterObj *mc)
47 void ExportBase::setCaption (const QString &s)
52 void ExportBase::addFilter(const QString &s)
57 bool ExportBase::execDialog()
59 if (mapCenter && mapCenter->getMapEditor())
61 QFileDialog *fd=new QFileDialog( mapCenter->getMapEditor(), caption);
62 fd->setFilter (filter);
63 fd->setCaption(caption);
64 fd->setMode( QFileDialog::AnyFile );
67 if ( fd->exec() == QDialog::Accepted )
69 if (QFile (fd->selectedFile()).exists() )
71 QMessageBox mb( __VYM,
72 QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
74 QMessageBox::Yes | QMessageBox::Default,
75 QMessageBox::Cancel | QMessageBox::Escape,
77 mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
78 mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
82 case QMessageBox::Yes:
85 case QMessageBox::Cancel:
91 outputFile=fd->selectedFile();
98 QString ExportBase::getSectionString(BranchObj *bostart)
100 // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
102 BranchObj *bo=bostart;
103 int depth=bo->getDepth();
106 r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
107 bo=(BranchObj*)(bo->getParObj());
108 depth=bo->getDepth();
117 ////////////////////////////////////////////////////////////////////////
118 void ExportASCII::doExport()
120 QFile file (outputFile);
121 if ( !file.open( QIODevice::WriteOnly ) )
123 // FIXME experimental, testing
124 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
127 QTextStream ts( &file ); // use LANG decoding here...
129 // Main loop over all branches
131 QString actIndent("");
134 bo=mapCenter->first();
138 for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
140 if (bo->getDepth()==0)
142 ts << (bo->getHeading()+ "\n");
143 for (j=0;j<bo->getHeading().length();j++) ts<<"=";
145 } else if (bo->getDepth()==1)
146 ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
147 else if (bo->getDepth()==2)
148 ts << (actIndent + " o " + bo->getHeading()+ "\n");
150 ts << (actIndent + " - " + bo->getHeading()+ "\n");
152 // If necessary, write note
153 if (!bo->getNote().isEmpty())
155 s =bo->getNoteASCII();
156 s=s.replace ("\n","\n"+actIndent);
165 ////////////////////////////////////////////////////////////////////////
166 void ExportKDEBookmarks::doExport()
169 if (mapCenter) me=mapCenter->getMapEditor();
173 dia.setCancelButton (true);
174 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
175 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
176 dia.setShowAgainName("/vym/warnings/overwriteKDEBookmarks");
177 if (dia.exec()==QDialog::Accepted)
179 me->exportXML(tmpDir.path());
182 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
183 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
184 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
187 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
188 QProcess *proc= new QProcess ();
190 if (!proc->waitForStarted());
192 QMessageBox::warning(0,
193 QObject::tr("Warning"),
194 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
201 ////////////////////////////////////////////////////////////////////////
202 void ExportFirefoxBookmarks::doExport()
205 if (mapCenter) me=mapCenter->getMapEditor();
209 dia.setCancelButton (true);
210 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
211 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
212 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
213 if (dia.exec()==QDialog::Accepted)
215 me->exportXML(tmpDir.path());
219 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
220 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
221 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
224 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
225 QProcess *proc = new QProcess( );
226 proc->addArgument(ub);
228 if ( !proc->start() )
230 QMessageBox::warning(0,
231 QObject::tr("Warning"),
232 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
241 ////////////////////////////////////////////////////////////////////////
242 void ExportTaskjuggler::doExport()
245 if (mapCenter) me=mapCenter->getMapEditor();
248 me->exportXML(tmpDir.path());
251 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
252 p.setOutputFile (outputFile);
253 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
259 ////////////////////////////////////////////////////////////////////////
260 void ExportLaTeX::doExport()
262 // Exports a map to a LaTex file.
263 // This file needs to be included
264 // or inported into a LaTex document
265 // it will not add a preamble, or anything
266 // that makes a full LaTex document.
267 QFile file (outputFile);
268 if ( !file.open( QIODevice::WriteOnly ) ) {
269 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
270 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
273 QTextStream ts( &file ); // use LANG decoding here...
274 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
276 // Main loop over all branches
278 // QString actIndent("");
281 bo=mapCenter->first();
283 if (bo->getDepth()==0);
284 else if (bo->getDepth()==1) {
285 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
287 else if (bo->getDepth()==2) {
288 ts << ("\\section{" + bo->getHeading()+ "}\n");
290 else if (bo->getDepth()==3) {
291 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
293 else if (bo->getDepth()==4) {
294 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
297 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
300 // If necessary, write note
301 if (!bo->getNote().isEmpty()) {
302 ts << (bo->getNoteASCII());
310 ////////////////////////////////////////////////////////////////////////
316 ExportOO::~ExportOO()
320 QString ExportOO::buildList (BranchObj *current)
326 bo=current->getFirstBranch();
330 r+="<text:list text:style-name=\"vym-list\">\n";
333 r+="<text:list-item><text:p >";
334 r+=quotemeta(bo->getHeading());
335 // If necessary, write note
336 if (!bo->getNote().isEmpty())
337 r+=bo->getNoteOpenDoc();
339 r+=buildList (bo); // recursivly add deeper branches
340 r+="</text:list-item>\n";
342 bo=current->getBranchNum(i);
350 void ExportOO::exportPresentation()
354 // Insert new content
355 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
356 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
361 BranchObj *sectionBO=mapCenter->getFirstBranch();
371 // Add page with section title
372 onePage=sectionTemplate;
373 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
377 i=-2; // only use inner loop to
378 // turn mainbranches into pages
383 pagesBO=sectionBO->getFirstBranch();
387 // Add page with list of items
388 onePage=pageTemplate;
389 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
390 list=buildList (pagesBO);
391 onePage.replace ("<!-- INSERT LIST -->", list);
394 pagesBO=sectionBO->getBranchNum(j);
397 sectionBO=mapCenter->getBranchNum(i);
400 content.replace ("<!-- INSERT PAGES -->",allPages);
402 // Write modified content
403 QFile f (contentFile);
404 if ( !f.open( QIODevice::WriteOnly ) )
406 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
407 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
415 // zip tmpdir to destination
416 zipDir (tmpDir,outputFile);
419 bool ExportOO::setConfigFile (const QString &cf)
422 int i=cf.findRev ("/");
423 if (i>=0) configDir=cf.left(i);
425 set.readSettings(configFile);
428 templateDir=configDir+"/"+set.readEntry ("Template");
430 QDir d (templateDir);
433 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
438 contentTemplateFile=templateDir+"content-template.xml";
439 contentFile=tmpDir.path()+"/content.xml";
440 pageTemplateFile=templateDir+"page-template.xml";
441 sectionTemplateFile=templateDir+"section-template.xml";
443 if (set.readEntry("useSections").contains("yes"))
446 // Copy template to tmpdir
447 system ("cp -r "+templateDir+"* "+tmpDir.path());
449 // Read content-template
450 if (!loadStringFromDisk (contentTemplateFile,content))
452 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
456 // Read page-template
457 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
459 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
463 // Read section-template
464 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
466 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));