More documentation, fixed small bug where links of unselected objects where visible again
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();
135 for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
137 if (bo->getDepth()==0)
139 ts << (bo->getHeading()+ "\n");
140 for (j=0;j<bo->getHeading().length();j++) ts<<"=";
142 } else if (bo->getDepth()==1)
143 ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
144 else if (bo->getDepth()==2)
145 ts << (actIndent + " o " + bo->getHeading()+ "\n");
147 ts << (actIndent + " - " + bo->getHeading()+ "\n");
149 // If necessary, write note
150 if (!bo->getNote().isEmpty())
152 s =bo->getNoteASCII();
153 s=s.replace ("\n","\n"+actIndent);
162 ////////////////////////////////////////////////////////////////////////
163 void ExportKDEBookmarks::doExport()
166 if (mapCenter) me=mapCenter->getMapEditor();
169 me->exportXML(tmpDir.path());
171 cout << "tmpDir="<<tmpDir.path()<<endl;
174 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
175 p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
176 p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
182 ////////////////////////////////////////////////////////////////////////
183 void ExportTaskjuggler::doExport()
186 if (mapCenter) me=mapCenter->getMapEditor();
189 me->exportXML(tmpDir.path());
191 cout << "tmpDir="<<tmpDir.path()<<endl;
194 p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
195 p.setOutputFile (outputFile);
196 p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
202 ////////////////////////////////////////////////////////////////////////
203 void ExportLaTeX::doExport()
205 // Exports a map to a LaTex file.
206 // This file needs to be included
207 // or inported into a LaTex document
208 // it will not add a preamble, or anything
209 // that makes a full LaTex document.
210 QFile file (outputFile);
211 if ( !file.open( IO_WriteOnly ) ) {
212 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
213 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
216 QTextStream ts( &file ); // use LANG decoding here...
217 ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
219 // Main loop over all branches
221 // QString actIndent("");
224 bo=mapCenter->first();
226 if (bo->getDepth()==0);
227 else if (bo->getDepth()==1) {
228 ts << ("\\chapter{" + bo->getHeading()+ "}\n");
230 else if (bo->getDepth()==2) {
231 ts << ("\\section{" + bo->getHeading()+ "}\n");
233 else if (bo->getDepth()==3) {
234 ts << ("\\subsection{" + bo->getHeading()+ "}\n");
236 else if (bo->getDepth()==4) {
237 ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
240 ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
243 // If necessary, write note
244 if (!bo->getNote().isEmpty()) {
245 ts << (bo->getNoteASCII());
253 ////////////////////////////////////////////////////////////////////////
259 ExportOO::~ExportOO()
263 QString ExportOO::buildList (BranchObj *current)
269 bo=current->getFirstBranch();
273 r+="<text:list text:style-name=\"vym-list\">\n";
276 r+="<text:list-item><text:p >";
277 r+=quotemeta(bo->getHeading());
278 // If necessary, write note
279 if (!bo->getNote().isEmpty())
280 r+=bo->getNoteOpenDoc();
282 r+=buildList (bo); // recursivly add deeper branches
283 r+="</text:list-item>\n";
285 bo=current->getBranchNum(i);
293 void ExportOO::exportPresentation()
297 // Insert new content
298 content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
299 content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
304 BranchObj *sectionBO=mapCenter->getFirstBranch();
314 // Add page with section title
315 onePage=sectionTemplate;
316 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
320 i=-2; // only use inner loop to
321 // turn mainbranches into pages
326 pagesBO=sectionBO->getFirstBranch();
330 // Add page with list of items
331 onePage=pageTemplate;
332 onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
333 list=buildList (pagesBO);
334 onePage.replace ("<!-- INSERT LIST -->", list);
337 pagesBO=sectionBO->getBranchNum(j);
340 sectionBO=mapCenter->getBranchNum(i);
343 content.replace ("<!-- INSERT PAGES -->",allPages);
345 // Write modified content
346 QFile f (contentFile);
347 if ( !f.open( IO_WriteOnly ) )
349 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
350 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
358 // zip tmpdir to destination
359 zipDir (tmpDir,outputFile);
362 bool ExportOO::setConfigFile (const QString &cf)
365 int i=cf.findRev ("/");
366 if (i>=0) configDir=cf.left(i);
368 set.readSettings(configFile);
371 templateDir=configDir+"/"+set.readEntry ("Template");
373 QDir d (templateDir);
376 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
381 contentTemplateFile=templateDir+"content-template.xml";
382 contentFile=tmpDir.path()+"/content.xml";
383 pageTemplateFile=templateDir+"page-template.xml";
384 sectionTemplateFile=templateDir+"section-template.xml";
386 if (set.readEntry("useSections").contains("yes"))
389 // Copy template to tmpdir
390 system ("cp -r "+templateDir+"* "+tmpDir.path());
392 // Read content-template
393 if (!loadStringFromDisk (contentTemplateFile,content))
395 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
399 // Read page-template
400 if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
402 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
406 // Read section-template
407 if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
409 QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));