Removed some FIXMEs. Added translations
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 QString &p)
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 );
64 if ( fd->exec() == QDialog::Accepted )
66 if (QFile (fd->selectedFile()).exists() )
68 QMessageBox mb( vymName,
69 QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
71 QMessageBox::Yes | QMessageBox::Default,
72 QMessageBox::Cancel | QMessageBox::Escape,
74 mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
75 mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
79 case QMessageBox::Yes:
82 case QMessageBox::Cancel:
88 outputFile=fd->selectedFile();
95 QString ExportBase::getSectionString(BranchObj *bostart)
97 // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
99 BranchObj *bo=bostart;
100 int depth=bo->getDepth();
103 r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
104 bo=(BranchObj*)(bo->getParObj());
105 depth=bo->getDepth();
114 ////////////////////////////////////////////////////////////////////////
115 void ExportASCII::doExport()
117 QFile file (outputFile);
118 if ( !file.open( QIODevice::WriteOnly ) )
120 qWarning ("ExportBase::exportXML couldn't open "+outputFile);
123 QTextStream ts( &file ); // use LANG decoding here...
125 // Main loop over all branches
127 QString actIndent("");
130 bo=mapCenter->first();
134 for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
136 if (bo->getDepth()==0)
138 ts << (bo->getHeading()+ "\n");
139 for (j=0;j<bo->getHeading().length();j++) ts<<"=";
141 } else if (bo->getDepth()==1)
142 ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
143 else if (bo->getDepth()==2)
144 ts << (actIndent + " o " + bo->getHeading()+ "\n");
146 ts << (actIndent + " - " + bo->getHeading()+ "\n");
148 // If necessary, write note
149 if (!bo->getNote().isEmpty())
151 s =bo->getNoteASCII();
152 s=s.replace ("\n","\n"+actIndent);
161 ////////////////////////////////////////////////////////////////////////
162 void ExportKDEBookmarks::doExport()
165 if (mapCenter) me=mapCenter->getMapEditor();
169 dia.showCancelButton (true);
170 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
171 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
172 dia.setShowAgainName("/vym/warnings/overwriteKDEBookmarks");
173 if (dia.exec()==QDialog::Accepted)
175 me->exportXML(tmpDir.path());
178 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
179 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
180 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
183 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
184 QProcess *proc= new QProcess ;
186 if (!proc->waitForStarted())
188 QMessageBox::warning(0,
189 QObject::tr("Warning"),
190 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
197 ////////////////////////////////////////////////////////////////////////
198 void ExportFirefoxBookmarks::doExport()
201 if (mapCenter) me=mapCenter->getMapEditor();
205 dia.showCancelButton (true);
206 dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
207 dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
208 dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
209 if (dia.exec()==QDialog::Accepted)
211 me->exportXML(tmpDir.path());
215 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
216 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
217 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
220 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
221 QProcess *proc = new QProcess( );
222 proc->addArgument(ub);
224 if ( !proc->start() )
226 QMessageBox::warning(0,
227 QObject::tr("Warning"),
228 QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
237 ////////////////////////////////////////////////////////////////////////
238 void ExportTaskjuggler::doExport()
241 if (mapCenter) me=mapCenter->getMapEditor();
244 me->exportXML(tmpDir.path());
247 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
248 p.setOutputFile (outputFile);
249 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
255 ////////////////////////////////////////////////////////////////////////
256 void ExportLaTeX::doExport()
258 // Exports a map to a LaTex file.
259 // This file needs to be included
260 // or inported into a LaTex document
261 // it will not add a preamble, or anything
262 // that makes a full LaTex document.
263 QFile file (outputFile);
264 if ( !file.open( QIODevice::WriteOnly ) ) {
265 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
266 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
269 QTextStream ts( &file ); // use LANG decoding here...
270 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
272 // Main loop over all branches
274 // QString actIndent("");
277 bo=mapCenter->first();
279 if (bo->getDepth()==0);
280 else if (bo->getDepth()==1) {
281 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
283 else if (bo->getDepth()==2) {
284 ts << ("\\section{" + bo->getHeading()+ "}\n");
286 else if (bo->getDepth()==3) {
287 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
289 else if (bo->getDepth()==4) {
290 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
293 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
296 // If necessary, write note
297 if (!bo->getNote().isEmpty()) {
298 ts << (bo->getNoteASCII());
306 ////////////////////////////////////////////////////////////////////////
312 ExportOO::~ExportOO()
316 QString ExportOO::buildList (BranchObj *current)
322 bo=current->getFirstBranch();
326 r+="<text:list text:style-name=\"vym-list\">\n";
329 r+="<text:list-item><text:p >";
330 r+=quotemeta(bo->getHeading());
331 // If necessary, write note
332 if (!bo->getNote().isEmpty())
333 r+=bo->getNoteOpenDoc();
335 r+=buildList (bo); // recursivly add deeper branches
336 r+="</text:list-item>\n";
338 bo=current->getBranchNum(i);
346 void ExportOO::exportPresentation()
350 // Insert new content
351 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
352 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
357 BranchObj *sectionBO=mapCenter->getFirstBranch();
367 // Add page with section title
368 onePage=sectionTemplate;
369 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
373 i=-2; // only use inner loop to
374 // turn mainbranches into pages
379 pagesBO=sectionBO->getFirstBranch();
383 // Add page with list of items
384 onePage=pageTemplate;
385 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
386 list=buildList (pagesBO);
387 onePage.replace ("<!-- INSERT LIST -->", list);
390 pagesBO=sectionBO->getBranchNum(j);
393 sectionBO=mapCenter->getBranchNum(i);
396 content.replace ("<!-- INSERT PAGES -->",allPages);
398 // Write modified content
399 QFile f (contentFile);
400 if ( !f.open( QIODevice::WriteOnly ) )
402 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
403 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
411 // zip tmpdir to destination
412 zipDir (tmpDir,outputFile);
415 bool ExportOO::setConfigFile (const QString &cf)
418 int i=cf.findRev ("/");
419 if (i>=0) configDir=cf.left(i);
421 set.readSettings(configFile);
424 templateDir=configDir+"/"+set.readEntry ("Template");
426 QDir d (templateDir);
429 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
434 contentTemplateFile=templateDir+"content-template.xml";
435 contentFile=tmpDir.path()+"/content.xml";
436 pageTemplateFile=templateDir+"page-template.xml";
437 sectionTemplateFile=templateDir+"section-template.xml";
439 if (set.readEntry("useSections").contains("yes"))
442 // Copy template to tmpdir
443 system ("cp -r "+templateDir+"* "+tmpDir.path());
445 // Read content-template
446 if (!loadStringFromDisk (contentTemplateFile,content))
448 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
452 // Read page-template
453 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
455 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
459 // Read section-template
460 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
462 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));