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();
134 cout << "export bo="<<bo->getHeading().ascii()<<endl;
136 for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
138 if (bo->getDepth()==0)
140 ts << (bo->getHeading()+ "\n");
141 for (j=0;j<bo->getHeading().length();j++) ts<<"=";
143 } else if (bo->getDepth()==1)
144 ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
145 else if (bo->getDepth()==2)
146 ts << (actIndent + " * " + bo->getHeading()+ "\n");
147 else if (bo->getDepth()==3)
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.showCancelButton (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("/exports/KDE/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.showCancelButton (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));