More undo/redo commands. 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 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
126 QTextStream ts( &file ); // use LANG decoding here...
128 // Main loop over all branches
130 QString actIndent("");
133 bo=mapCenter->first();
137 for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
139 if (bo->getDepth()==0)
141 ts << (bo->getHeading()+ "\n");
142 for (j=0;j<bo->getHeading().length();j++) ts<<"=";
144 } else if (bo->getDepth()==1)
145 ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
146 else if (bo->getDepth()==2)
147 ts << (actIndent + " o " + bo->getHeading()+ "\n");
149 ts << (actIndent + " - " + bo->getHeading()+ "\n");
151 // If necessary, write note
152 if (!bo->getNote().isEmpty())
154 s =bo->getNoteASCII();
155 s=s.replace ("\n","\n"+actIndent);
164 ////////////////////////////////////////////////////////////////////////
165 void ExportKDEBookmarks::doExport()
168 if (mapCenter) me=mapCenter->getMapEditor();
172 dia.setCancelButton (true);
173 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
174 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
175 dia.setShowAgainName("/vym/warnings/overwriteKDEBookmarks");
176 if (dia.exec()==QDialog::Accepted)
178 me->exportXML(tmpDir.path());
181 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
182 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
183 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
186 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
187 QProcess *proc= new QProcess ();
189 if (!proc->waitForStarted());
191 QMessageBox::warning(0,
192 QObject::tr("Warning"),
193 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
200 ////////////////////////////////////////////////////////////////////////
201 void ExportFirefoxBookmarks::doExport()
204 if (mapCenter) me=mapCenter->getMapEditor();
208 dia.setCancelButton (true);
209 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
210 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
211 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
212 if (dia.exec()==QDialog::Accepted)
214 me->exportXML(tmpDir.path());
218 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
219 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
220 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
223 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
224 QProcess *proc = new QProcess( );
225 proc->addArgument(ub);
227 if ( !proc->start() )
229 QMessageBox::warning(0,
230 QObject::tr("Warning"),
231 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
240 ////////////////////////////////////////////////////////////////////////
241 void ExportTaskjuggler::doExport()
244 if (mapCenter) me=mapCenter->getMapEditor();
247 me->exportXML(tmpDir.path());
250 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
251 p.setOutputFile (outputFile);
252 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
258 ////////////////////////////////////////////////////////////////////////
259 void ExportLaTeX::doExport()
261 // Exports a map to a LaTex file.
262 // This file needs to be included
263 // or inported into a LaTex document
264 // it will not add a preamble, or anything
265 // that makes a full LaTex document.
266 QFile file (outputFile);
267 if ( !file.open( QIODevice::WriteOnly ) ) {
268 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
269 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
272 QTextStream ts( &file ); // use LANG decoding here...
273 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
275 // Main loop over all branches
277 // QString actIndent("");
280 bo=mapCenter->first();
282 if (bo->getDepth()==0);
283 else if (bo->getDepth()==1) {
284 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
286 else if (bo->getDepth()==2) {
287 ts << ("\\section{" + bo->getHeading()+ "}\n");
289 else if (bo->getDepth()==3) {
290 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
292 else if (bo->getDepth()==4) {
293 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
296 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
299 // If necessary, write note
300 if (!bo->getNote().isEmpty()) {
301 ts << (bo->getNoteASCII());
309 ////////////////////////////////////////////////////////////////////////
315 ExportOO::~ExportOO()
319 QString ExportOO::buildList (BranchObj *current)
325 bo=current->getFirstBranch();
329 r+="<text:list text:style-name=\"vym-list\">\n";
332 r+="<text:list-item><text:p >";
333 r+=quotemeta(bo->getHeading());
334 // If necessary, write note
335 if (!bo->getNote().isEmpty())
336 r+=bo->getNoteOpenDoc();
338 r+=buildList (bo); // recursivly add deeper branches
339 r+="</text:list-item>\n";
341 bo=current->getBranchNum(i);
349 void ExportOO::exportPresentation()
353 // Insert new content
354 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
355 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
360 BranchObj *sectionBO=mapCenter->getFirstBranch();
370 // Add page with section title
371 onePage=sectionTemplate;
372 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
376 i=-2; // only use inner loop to
377 // turn mainbranches into pages
382 pagesBO=sectionBO->getFirstBranch();
386 // Add page with list of items
387 onePage=pageTemplate;
388 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
389 list=buildList (pagesBO);
390 onePage.replace ("<!-- INSERT LIST -->", list);
393 pagesBO=sectionBO->getBranchNum(j);
396 sectionBO=mapCenter->getBranchNum(i);
399 content.replace ("<!-- INSERT PAGES -->",allPages);
401 // Write modified content
402 QFile f (contentFile);
403 if ( !f.open( QIODevice::WriteOnly ) )
405 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
406 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
414 // zip tmpdir to destination
415 zipDir (tmpDir,outputFile);
418 bool ExportOO::setConfigFile (const QString &cf)
421 int i=cf.findRev ("/");
422 if (i>=0) configDir=cf.left(i);
424 set.readSettings(configFile);
427 templateDir=configDir+"/"+set.readEntry ("Template");
429 QDir d (templateDir);
432 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
437 contentTemplateFile=templateDir+"content-template.xml";
438 contentFile=tmpDir.path()+"/content.xml";
439 pageTemplateFile=templateDir+"page-template.xml";
440 sectionTemplateFile=templateDir+"section-template.xml";
442 if (set.readEntry("useSections").contains("yes"))
445 // Copy template to tmpdir
446 system ("cp -r "+templateDir+"* "+tmpDir.path());
448 // Read content-template
449 if (!loadStringFromDisk (contentTemplateFile,content))
451 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
455 // Read page-template
456 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
458 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
462 // Read section-template
463 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
465 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));