hide export for floatimages.
1 #include <qfiledialog.h>
2 #include <qmessagebox.h>
6 #include "linkablemapobj.h"
8 #include "mainwindow.h"
11 extern Main *mainWindow;
12 extern QDir vymBaseDir;
15 ExportBase::ExportBase()
19 tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
22 ExportBase::~ExportBase()
28 void ExportBase::setDir(const QString &p)
33 void ExportBase::setFile (const QString &p)
38 void ExportBase::setMapCenter(MapCenterObj *mc)
43 void ExportBase::setCaption (const QString &s)
48 void ExportBase::addFilter(const QString &s)
53 bool ExportBase::execDialog()
55 if (mapCenter && mapCenter->getMapEditor())
57 QFileDialog *fd=new QFileDialog( mapCenter->getMapEditor(), caption);
58 fd->addFilter (filter);
59 fd->setCaption(caption);
60 fd->setMode( QFileDialog::AnyFile );
63 if ( fd->exec() == QDialog::Accepted )
65 if (QFile (fd->selectedFile()).exists() )
67 QMessageBox mb( __VYM,
68 QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
70 QMessageBox::Yes | QMessageBox::Default,
71 QMessageBox::Cancel | QMessageBox::Escape,
72 QMessageBox::NoButton );
73 mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
74 mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
78 case QMessageBox::Yes:
81 case QMessageBox::Cancel:
87 outputFile=fd->selectedFile();
94 QString ExportBase::getSectionString(BranchObj *bostart)
96 // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
98 BranchObj *bo=bostart;
99 int depth=bo->getDepth();
102 r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
103 bo=(BranchObj*)(bo->getParObj());
104 depth=bo->getDepth();
113 ////////////////////////////////////////////////////////////////////////
114 void ExportASCII::doExport()
116 QFile file (outputFile);
117 if ( !file.open( IO_WriteOnly ) )
119 // FIXME experimental, testing
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("");
131 bo=mapCenter->first();
134 if (!bo->hideInExport())
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);
165 ////////////////////////////////////////////////////////////////////////
166 void ExportKDEBookmarks::doExport()
169 if (mapCenter) me=mapCenter->getMapEditor();
172 me->exportXML(tmpDir.path());
174 cout << "tmpDir="<<tmpDir.path()<<endl;
177 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
178 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
179 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
185 ////////////////////////////////////////////////////////////////////////
186 void ExportTaskjuggler::doExport()
189 if (mapCenter) me=mapCenter->getMapEditor();
192 me->exportXML(tmpDir.path());
194 cout << "tmpDir="<<tmpDir.path()<<endl;
197 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
198 p.setOutputFile (outputFile);
199 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
205 ////////////////////////////////////////////////////////////////////////
206 void ExportLaTeX::doExport()
208 // Exports a map to a LaTex file.
209 // This file needs to be included
210 // or inported into a LaTex document
211 // it will not add a preamble, or anything
212 // that makes a full LaTex document.
213 QFile file (outputFile);
214 if ( !file.open( IO_WriteOnly ) ) {
215 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
216 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
219 QTextStream ts( &file ); // use LANG decoding here...
220 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
222 // Main loop over all branches
224 // QString actIndent("");
227 bo=mapCenter->first();
229 if (!bo->hideInExport())
231 if (bo->getDepth()==0);
232 else if (bo->getDepth()==1) {
233 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
235 else if (bo->getDepth()==2) {
236 ts << ("\\section{" + bo->getHeading()+ "}\n");
238 else if (bo->getDepth()==3) {
239 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
241 else if (bo->getDepth()==4) {
242 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
245 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
248 // If necessary, write note
249 if (!bo->getNote().isEmpty()) {
250 ts << (bo->getNoteASCII());
259 ////////////////////////////////////////////////////////////////////////
265 ExportOO::~ExportOO()
269 QString ExportOO::buildList (BranchObj *current)
275 bo=current->getFirstBranch();
279 r+="<text:list text:style-name=\"vym-list\">\n";
282 if (!bo->hideInExport())
284 r+="<text:list-item><text:p >";
285 r+=quotemeta(bo->getHeading());
286 // If necessary, write note
287 if (!bo->getNote().isEmpty())
288 r+=bo->getNoteOpenDoc();
290 r+=buildList (bo); // recursivly add deeper branches
291 r+="</text:list-item>\n";
294 bo=current->getBranchNum(i);
302 void ExportOO::exportPresentation()
306 // Insert new content
307 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
308 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
313 BranchObj *sectionBO=mapCenter->getFirstBranch();
323 // Add page with section title
324 onePage=sectionTemplate;
325 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
329 i=-2; // only use inner loop to
330 // turn mainbranches into pages
335 pagesBO=sectionBO->getFirstBranch();
339 // Add page with list of items
340 if (!pagesBO->hideInExport())
342 onePage=pageTemplate;
343 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
344 list=buildList (pagesBO);
345 onePage.replace ("<!-- INSERT LIST -->", list);
349 pagesBO=sectionBO->getBranchNum(j);
352 sectionBO=mapCenter->getBranchNum(i);
355 content.replace ("<!-- INSERT PAGES -->",allPages);
357 // Write modified content
358 QFile f (contentFile);
359 if ( !f.open( IO_WriteOnly ) )
361 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
362 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
370 // zip tmpdir to destination
371 zipDir (tmpDir,outputFile);
374 bool ExportOO::setConfigFile (const QString &cf)
377 int i=cf.findRev ("/");
378 if (i>=0) configDir=cf.left(i);
380 set.readSettings(configFile);
383 templateDir=configDir+"/"+set.readEntry ("Template");
385 QDir d (templateDir);
388 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
393 contentTemplateFile=templateDir+"content-template.xml";
394 contentFile=tmpDir.path()+"/content.xml";
395 pageTemplateFile=templateDir+"page-template.xml";
396 sectionTemplateFile=templateDir+"section-template.xml";
398 if (set.readEntry("useSections").contains("yes"))
401 // Copy template to tmpdir
402 system ("cp -r "+templateDir+"* "+tmpDir.path());
404 // Read content-template
405 if (!loadStringFromDisk (contentTemplateFile,content))
407 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
411 // Read page-template
412 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
414 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
418 // Read section-template
419 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
421 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));