exports.cpp
author convert-repo
Fri, 23 Jul 2010 16:43:49 +0000
changeset 849 988f1908a7c4
parent 847 43268373032d
permissions -rw-r--r--
update tags
     1 #include "exports.h"
     2 
     3 #include "branchitem.h"
     4 #include "file.h"
     5 #include "linkablemapobj.h"
     6 #include "misc.h"
     7 #include "mainwindow.h"
     8 #include "warningdialog.h"
     9 #include "xsltproc.h"
    10 
    11 
    12 extern Main *mainWindow;
    13 extern QDir vymBaseDir;
    14 extern QString vymName;
    15 
    16 ExportBase::ExportBase()
    17 {
    18 	init();
    19 }
    20 
    21 ExportBase::ExportBase(VymModel *m)
    22 {
    23 	init();
    24 	model=m;
    25 }
    26 
    27 ExportBase::~ExportBase()
    28 {
    29 	// Cleanup tmpdir
    30 	removeDir (tmpDir);
    31 }
    32 
    33 void ExportBase::init()
    34 {
    35 	indentPerDepth="  ";
    36 	bool ok;
    37     tmpDir.setPath (makeTmpDir(ok,"vym-export"));
    38 	if (!tmpDir.exists() || !ok)
    39 		QMessageBox::critical( 0, QObject::tr( "Error" ),
    40 					   QObject::tr("Couldn't access temporary directory\n"));
    41 	cancelFlag=false;				   
    42 }
    43 
    44 void ExportBase::setDir(const QDir &d)
    45 {
    46 	outDir=d;
    47 }
    48 
    49 void ExportBase::setFile (const QString &p)
    50 {
    51 	outputFile=p;
    52 }
    53 
    54 QString ExportBase::getFile ()
    55 {
    56 	return outputFile;
    57 }
    58 
    59 void ExportBase::setModel(VymModel *m)
    60 {
    61 	model=m;
    62 }
    63 
    64 void ExportBase::setCaption (const QString &s)
    65 {
    66 	caption=s;
    67 }
    68 
    69 void ExportBase::addFilter(const QString &s)
    70 {
    71 	filter=s;
    72 }
    73 
    74 bool ExportBase::execDialog()
    75 {
    76 	{
    77 		QFileDialog *fd=new QFileDialog( 0, caption);
    78 		fd->setFilter (filter);
    79 		fd->setCaption(caption);
    80 		fd->setMode( QFileDialog::AnyFile );
    81 		fd->setDir (outDir);
    82 		fd->show();
    83 
    84 		if ( fd->exec() == QDialog::Accepted )
    85 		{
    86 			if (QFile (fd->selectedFile()).exists() )
    87 			{
    88 				QMessageBox mb( vymName,
    89 					QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()), 
    90 				QMessageBox::Warning,
    91 				QMessageBox::Yes | QMessageBox::Default,
    92 				QMessageBox::Cancel | QMessageBox::Escape,
    93 				Qt::NoButton );
    94 				mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
    95 				mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
    96 				ExportBase ex;
    97 				switch( mb.exec() ) 
    98 				{
    99 					case QMessageBox::Yes:
   100 						// save 
   101 						break;;
   102 					case QMessageBox::Cancel:
   103 						cancelFlag=true;
   104 						return false;
   105 						break;
   106 				}
   107 			}
   108 			outputFile=fd->selectedFile();
   109 			cancelFlag=false;
   110 			return true;
   111 		}
   112 	}
   113 	return false;
   114 }
   115 
   116 bool ExportBase::canceled()
   117 {
   118 	return cancelFlag;
   119 }
   120 
   121 QString ExportBase::getSectionString(TreeItem *start)
   122 {
   123 	// Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
   124 	QString r;
   125 	TreeItem *ti=start;
   126 	int depth=ti->depth();
   127 	while (depth>0)
   128 	{
   129 		r=QString("%1").arg(1+ti->num(),0,10)+"." + r;
   130 		ti=ti->parent(); 
   131 		depth=ti->depth();
   132 	}	
   133 	if (r.isEmpty())
   134 		return r;
   135 	else	
   136 		return r + " ";
   137 }
   138 
   139 ////////////////////////////////////////////////////////////////////////
   140 ExportAO::ExportAO()
   141 {
   142 	filter="TXT (*.txt)";
   143 	caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
   144 }
   145 
   146 void ExportAO::doExport()	
   147 {
   148 	QFile file (outputFile);
   149 	if ( !file.open( QIODevice::WriteOnly ) )
   150 	{
   151 		qWarning ("ExportAO::doExport couldn't open "+outputFile);
   152 		return;
   153 	}
   154 	QTextStream ts( &file );	// use LANG decoding here...
   155 
   156 	// Main loop over all branches
   157 	QString s;
   158 	QString curIndent;
   159 	QString dashIndent;
   160 
   161 	int i;
   162 	BranchItem *cur=NULL;
   163 	BranchItem *prev=NULL;
   164 
   165 	QString colString;
   166 	QColor col;
   167 
   168 	cur=model->nextBranch (cur,prev);
   169 	while (cur) 
   170 	{
   171 		if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
   172 		{
   173 			// Make indentstring
   174 			curIndent="";
   175 			for (i=0;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
   176 
   177 			if (!cur->hasHiddenExportParent() )
   178 			{
   179 				col=cur->getHeadingColor();
   180 				if (col==QColor (255,0,0))
   181 					colString="[R]";
   182 				else if (col==QColor (217,81,0))
   183 					colString="[O]";
   184 				else if (col==QColor (0,85,0))
   185 					colString="[G]";
   186 				else  	
   187 					colString="[?]";
   188 
   189 				dashIndent="";	
   190 				switch (cur->depth())
   191 				{
   192 					case 0:
   193 						//ts << underline (cur->getHeading(),QString("="));
   194 						//ts << "\n";
   195 						break;
   196 					case 1:
   197 						//ts << "\n";
   198 						//ts << (underline ( cur->getHeading(), QString("-") ) );
   199 						//ts << "\n";
   200 						break;
   201 					case 2: // Main heading
   202 						ts << "\n";
   203 						ts << underline ( cur->getHeading(), QString("=") );
   204 						ts << "\n";
   205 						break;
   206 					case 3: // Achievement, Bonus, Objective ...
   207 						ts << "\n\n";
   208 						ts << underline ( cur->getHeading(), "-");
   209 						ts << "\n\n";
   210 						break;
   211 					case 4:	// That's the item we need to know
   212 						//ts << (curIndent + "* " + colString+" "+ cur->getHeading());
   213 						ts << colString+" "+ cur->getHeading();
   214 						if (cur->isActiveStandardFlag ("hook-green"))
   215 							ts << " [DONE] ";
   216 						else	if (cur->isActiveStandardFlag ("wip"))
   217 							ts << " [WIP] ";
   218 						else	if (cur->isActiveStandardFlag ("cross-red"))
   219 							ts << " [NOT STARTED] ";
   220 						ts << "\n";
   221 						break;
   222 					default:
   223 						ts << (curIndent + "- " + cur->getHeading());
   224 						ts << "\n";
   225 						dashIndent="  ";
   226 						break;
   227 				}
   228 
   229 				// If necessary, write URL
   230 				if (!cur->getURL().isEmpty())
   231 					ts << (curIndent + dashIndent + cur->getURL()) +"\n";
   232 
   233 				// If necessary, write note
   234 				if (!cur->getNoteObj().isEmpty())
   235 				{
   236 					curIndent +="  | ";
   237 					s=cur->getNoteASCII( curIndent, 80);
   238 					ts << s;
   239 				}
   240 			}
   241 		}
   242 		cur=model->nextBranch(cur,prev);
   243 	}
   244 	file.close();
   245 }
   246 
   247 QString ExportAO::underline (const QString &text, const QString &line)
   248 {
   249 	QString r=text + "\n";
   250 	for (int j=0;j<text.length();j++) r+=line;
   251 	return r;
   252 }
   253 
   254 
   255 ////////////////////////////////////////////////////////////////////////
   256 ExportASCII::ExportASCII()
   257 {
   258 	filter="TXT (*.txt)";
   259 	caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
   260 }
   261 
   262 void ExportASCII::doExport()	
   263 {
   264 	QFile file (outputFile);
   265 	if ( !file.open( QIODevice::WriteOnly ) )
   266 	{
   267 		qWarning ("ExportASCII::doExport couldn't open "+outputFile);
   268 		return;
   269 	}
   270 	QTextStream ts( &file );	// use LANG decoding here...
   271 
   272 	// Main loop over all branches
   273 	QString s;
   274 	QString curIndent;
   275 	QString dashIndent;
   276 	int i;
   277 	BranchItem *cur=NULL;
   278 	BranchItem *prev=NULL;
   279 
   280 	cur=model->nextBranch (cur,prev);
   281 	while (cur) 
   282 	{
   283 		if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
   284 		{
   285 			// Make indentstring
   286 			curIndent="";
   287 			for (i=1;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
   288 
   289 			if (!cur->hasHiddenExportParent() )
   290 			{
   291 				//std::cout << "ExportASCII::  "<<curIndent.toStdString()<<cur->getHeading().toStdString()<<std::endl;
   292 
   293 				dashIndent="";
   294 				switch (cur->depth())
   295 				{
   296 					case 0:
   297 						ts << underline (cur->getHeading(),QString("="));
   298 						ts << "\n";
   299 						break;
   300 					case 1:
   301 						ts << "\n";
   302 						ts << (underline (getSectionString(cur) + cur->getHeading(), QString("-") ) );
   303 						ts << "\n";
   304 						break;
   305 					case 2:
   306 						ts << "\n";
   307 						ts << (curIndent + "* " + cur->getHeading());
   308 						ts << "\n";
   309 						dashIndent="  ";
   310 						break;
   311 					case 3:
   312 						ts << (curIndent + "- " + cur->getHeading());
   313 						ts << "\n";
   314 						dashIndent="  ";
   315 						break;
   316 					default:
   317 						ts << (curIndent + "- " + cur->getHeading());
   318 						ts << "\n";
   319 						dashIndent="  ";
   320 						break;
   321 				}
   322 
   323 				// If necessary, write URL
   324 				if (!cur->getURL().isEmpty())
   325 					ts << (curIndent + dashIndent + cur->getURL()) +"\n";
   326 
   327 				// If necessary, write note
   328 				if (!cur->getNoteObj().isEmpty())
   329 				{
   330 					curIndent +="  | ";
   331 					s=cur->getNoteASCII( curIndent, 80);
   332 					ts << s;
   333 				}
   334 			}
   335 		}
   336 		cur=model->nextBranch(cur,prev);
   337 	}
   338 	file.close();
   339 }
   340 
   341 QString ExportASCII::underline (const QString &text, const QString &line)
   342 {
   343 	QString r=text + "\n";
   344 	for (int j=0;j<text.length();j++) r+=line;
   345 	return r;
   346 }
   347 
   348 
   349 ////////////////////////////////////////////////////////////////////////
   350 void ExportCSV::doExport()
   351 {
   352 	QFile file (outputFile);
   353 	if ( !file.open( QIODevice::WriteOnly ) )
   354 	{
   355 		qWarning ("ExportBase::exportXML  couldn't open "+outputFile);
   356 		return;
   357 	}
   358 	QTextStream ts( &file );	// use LANG decoding here...
   359 
   360 	// Write header
   361 	ts << "\"Note\""  <<endl;
   362 
   363 	// Main loop over all branches
   364 	QString s;
   365 	QString curIndent("");
   366 	int i;
   367 	BranchItem *cur=NULL;
   368 	BranchItem *prev=NULL;
   369 	cur=model->nextBranch (cur,prev);
   370 	while (cur) 
   371 	{
   372 		if (!cur->hasHiddenExportParent() )
   373 		{
   374 			// If necessary, write note
   375 			if (!cur->getNoteObj().isEmpty())
   376 			{
   377 				s =cur->getNoteASCII();
   378 				s=s.replace ("\n","\n"+curIndent);
   379 				ts << ("\""+s+"\",");
   380 			} else
   381 				ts <<"\"\",";
   382 
   383 			// Make indentstring
   384 			for (i=0;i<cur->depth();i++) curIndent+= "\"\",";
   385 
   386 			// Write heading
   387 			ts << curIndent << "\"" << cur->getHeading()<<"\""<<endl;
   388 		}
   389 		
   390 		cur=model->nextBranch(cur,prev);
   391 		curIndent="";
   392 	}
   393 	file.close();
   394 }
   395 
   396 ////////////////////////////////////////////////////////////////////////
   397 void ExportKDE3Bookmarks::doExport() 
   398 {
   399 	WarningDialog dia;
   400 	dia.showCancelButton (true);
   401 	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
   402 	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE 3"));
   403 	dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
   404 	if (dia.exec()==QDialog::Accepted)
   405 	{
   406 		model->exportXML(tmpDir.path(),false);
   407 
   408 		XSLTProc p;
   409 		p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
   410 		p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
   411 		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
   412 		p.process();
   413 
   414 		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
   415 		QProcess *proc= new QProcess ;
   416 		proc->start( ub);
   417 		if (!proc->waitForStarted())
   418 		{
   419 			QMessageBox::warning(0, 
   420 				QObject::tr("Warning"),
   421 				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
   422 		}	
   423 	}
   424 }
   425 
   426 ////////////////////////////////////////////////////////////////////////
   427 void ExportKDE4Bookmarks::doExport() 
   428 {
   429 	WarningDialog dia;
   430 	dia.showCancelButton (true);
   431 	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE 4"));
   432 	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
   433 	dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
   434 	if (dia.exec()==QDialog::Accepted)
   435 	{
   436 		model->exportXML(tmpDir.path(),false);
   437 
   438 		XSLTProc p;
   439 		p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
   440 		p.setOutputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
   441 		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
   442 		p.process();
   443 
   444 		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
   445 		QProcess *proc= new QProcess ;
   446 		proc->start( ub);
   447 		if (!proc->waitForStarted())
   448 		{
   449 			QMessageBox::warning(0, 
   450 				QObject::tr("Warning"),
   451 				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
   452 		}	
   453 	}
   454 }
   455 
   456 ////////////////////////////////////////////////////////////////////////
   457 void ExportFirefoxBookmarks::doExport() 
   458 {
   459 	WarningDialog dia;
   460 	dia.showCancelButton (true);
   461 	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
   462 	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
   463 	dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
   464 	if (dia.exec()==QDialog::Accepted)
   465 	{
   466 		model->exportXML(tmpDir.path(),false);
   467 
   468 /*
   469 		XSLTProc p;
   470 		p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
   471 		p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
   472 		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
   473 		p.process();
   474 
   475 		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
   476 		QProcess *proc = new QProcess( );
   477 		proc->addArgument(ub);
   478 
   479 		if ( !proc->start() ) 
   480 		{
   481 			QMessageBox::warning(0, 
   482 				QObject::tr("Warning"),
   483 				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
   484 		}	
   485 
   486 */
   487 	}
   488 }
   489 
   490 ////////////////////////////////////////////////////////////////////////
   491 ExportHTML::ExportHTML():ExportBase()
   492 {
   493 	init();
   494 }
   495 
   496 ExportHTML::ExportHTML(VymModel *m):ExportBase(m)
   497 {
   498 	init();
   499 }
   500 
   501 void ExportHTML::init()
   502 {
   503 	singularDelimiter=": ";
   504 	noSingulars=true;	
   505 	frameURLs=true;
   506 	cssFileName="vym.css";
   507 	cssOriginalPath="";	// Is set in VymModel, based on default setting in ExportHTMLDialog
   508 
   509 	if (model &&model->getMapEditor()) 
   510 		offset=model->getMapEditor()->getTotalBBox().topLeft();
   511 }
   512 
   513 QString ExportHTML::getBranchText(BranchItem *current)
   514 {
   515 	if (current)
   516 	{
   517 		bool vis=false;
   518 		QRectF hr;
   519 		LinkableMapObj *lmo=current->getLMO();
   520 		if (lmo)
   521 		{
   522 			hr=((BranchObj*)lmo)->getBBoxHeading();
   523 			if (lmo->isVisibleObj()) vis=true;
   524 		}
   525 		QString col;
   526 		QString id=model->getSelectString(current);
   527 		if (dia.useTextColor)
   528 			col=QString("style='color:%1'").arg(current->getHeadingColor().name());
   529 		QString s=QString("<span class='vym-branch%1' %2 id='%3'>")
   530 			.arg(current->depth())
   531 			.arg(col)
   532 			.arg(id);
   533 		QString url=current->getURL();	
   534 		QString heading=quotemeta(current->getHeading());
   535 		if (!url.isEmpty())
   536 		{
   537 			s+=QString ("<a href=\"%1\">").arg(url);
   538 			s+=QString ("<img src=\"flags/flag-url-16x16.png\">%1</a>").arg(heading);
   539 			s+="</a>";
   540 			
   541 			QRectF fbox=current->getBBoxURLFlag ();
   542 			if (vis)
   543 				imageMap+=QString("  <area shape='rect' coords='%1,%2,%3,%4' href='%5'>\n")
   544 					.arg(fbox.left()-offset.x())
   545 					.arg(fbox.top()-offset.y())
   546 					.arg(fbox.right()-offset.x())
   547 					.arg(fbox.bottom()-offset.y())
   548 					.arg(url);
   549 		} else	
   550 			s+=quotemeta(current->getHeading());
   551 		s+="</span>";
   552 
   553 		if (vis && dia.useImage)
   554 			imageMap+=QString("  <area shape='rect' coords='%1,%2,%3,%4' href='#%5'>\n")
   555 				.arg(hr.left()-offset.x())
   556 				.arg(hr.top()-offset.y())
   557 				.arg(hr.right()-offset.x())
   558 				.arg(hr.bottom()-offset.y())
   559 				.arg(id);
   560 
   561 		// Include note
   562 		if (!current->getNoteObj().isEmpty())
   563 			s+="<table border=1><tr><td>"+current->getNote()+"</td></tr></table>";
   564 
   565 		return s;
   566 	} 
   567 	return QString();
   568 }
   569 
   570 QString ExportHTML::buildList (BranchItem *current)
   571 {
   572     QString r;
   573 
   574     uint i=0;
   575 	BranchItem *bi=current->getFirstBranch();
   576 
   577 	// Only add itemized list, if we have more than one subitem.
   578 	// For only one subitem, just add a separator to keep page more compact
   579 	bool noSingularsHere=false;
   580 	if (current->branchCount()<2 && noSingulars) noSingularsHere=true;
   581 
   582 	if (bi)
   583     {
   584 		if (!noSingularsHere)
   585 			r+="<ul>\n";
   586 		else
   587 			r+=singularDelimiter;
   588 
   589 		while (bi)
   590 		{
   591 			if (!bi->hasHiddenExportParent() )	
   592 			{
   593 				if (!noSingularsHere) r+="<li>";
   594 				r+=getBranchText (bi);
   595 				if (!bi->getURL().isEmpty() && frameURLs && noSingularsHere)
   596 					// Add frame, if we have subitems to an URL
   597 					r+="<table border=1><tr><td>"+buildList (bi)+"</td></tr></table>";	// recursivly add deeper branches
   598 				else
   599 					r+=buildList (bi);	// recursivly add deeper branches
   600 				if (!noSingularsHere) r+="</li>";
   601 				r+="\n";
   602 			}
   603 			i++;
   604 			bi=current->getBranchNum(i);
   605 		}
   606 
   607 		if (!noSingularsHere) r+="</ul>\n";
   608 	}
   609     return r;
   610 }
   611 
   612 void ExportHTML::setCSSPath(const QString &p)
   613 {
   614 	cssOriginalPath=p;
   615 }
   616 
   617 void ExportHTML::doExport(bool useDialog) 
   618 {
   619 	// Execute dialog
   620 	dia.setFilePath (model->getFilePath());
   621 	dia.setMapName (model->getMapName());
   622 	dia.readSettings();
   623 	if (useDialog && dia.exec()!=QDialog::Accepted) return;
   624 
   625 	// Check if destination is not empty
   626 	QDir d=dia.getDir();
   627 	// Check, if warnings should be used before overwriting
   628 	// the output directory
   629 	if (d.exists() && d.count()>0)
   630 	{
   631 		WarningDialog warn;
   632 		warn.showCancelButton (true);
   633 		warn.setText(QString(
   634 			"The directory %1 is not empty.\n"
   635 			"Do you risk to overwrite some of its contents?").arg(d.path() ));
   636 		warn.setCaption("Warning: Directory not empty");
   637 		warn.setShowAgainName("mainwindow/export-XML-overwrite-dir");
   638 
   639 		if (warn.exec()!=QDialog::Accepted) 
   640 		{
   641 			mainWindow->statusMessage(QString(QObject::tr("Export aborted.")));
   642 			return;
   643 		}
   644 	}
   645 
   646 	setFile (d.path()+"/"+model->getMapName()+".html");
   647 	setCSSPath( dia.getCSSPath() );	// FIXME-2 css not copied?
   648 
   649 	// Copy CSS file
   650 	QFile css_src (cssOriginalPath);
   651 	QFile css_dst (outDir.path()+"/"+cssFileName);
   652 	if (!css_src.open ( QIODevice::ReadOnly))
   653 		QMessageBox::warning( 0, QObject::tr( "Warning","ExportHTML" ),QObject::tr("Could not open %1","ExportHTML").arg(cssOriginalPath));
   654 	else
   655 	{
   656 		if (!css_dst.open( QIODevice::WriteOnly))
   657 			QMessageBox::warning( 0, QObject::tr( "Warning" ), QObject::tr("Could not open %1").arg(css_dst.fileName()));
   658 		else
   659 		{	
   660 		
   661 			QTextStream tsout( &css_dst);
   662 			QTextStream tsin ( &css_src);
   663 			QString s= tsin.read();
   664 			tsout << s;
   665 			css_dst.close();
   666 		}	
   667 		css_src.close();
   668 	}
   669 
   670 
   671 
   672 	// Open file for writing
   673 	QFile file (outputFile);
   674 	if ( !file.open( QIODevice::WriteOnly ) ) 
   675 	{
   676 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
   677 		mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
   678 		return;
   679 	}
   680 	QTextStream ts( &file );	// use LANG decoding here...
   681 	ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
   682 
   683 	// Hide stuff during export
   684 	model->setExportMode (true);
   685 
   686 	// Write header
   687 	ts<<"<html>";
   688 	ts<<"<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"> ";
   689 	ts<<"<title>"+model->getMapName()<<"</title><body>";
   690 	ts<<" <link rel='stylesheet' id='css.stylesheet' href='"<<cssFileName<<"' />\n";
   691 
   692 	// Include image
   693 	if (dia.useImage)
   694 	{
   695 		ts<<"<center><img src=\""<<model->getMapName()<<".png\" usemap='#imagemap'></center>\n";
   696 		model->exportImage (d.path()+"/"+model->getMapName()+".png",false,"PNG");
   697 	}
   698 
   699 	// Main loop over all mapcenters
   700 	QString s;
   701 	TreeItem *rootItem=model->getRootItem();
   702 	BranchItem *bi;
   703 	for (int i=0; i<rootItem->branchCount(); i++)
   704 	{
   705 		bi=rootItem->getBranchNum(i);
   706 		if (!bi->hasHiddenExportParent())
   707 		{
   708 			ts<<getBranchText (bi);
   709 			ts<<buildList (bi);
   710 		}
   711 	}	
   712 
   713 	// Imagemap
   714 	ts<<"<map name='imagemap'>\n"+imageMap+"</map>\n";
   715 
   716 	// Write footer 
   717 	ts<<"<hr/>\n";
   718 	ts<<"<table class=\"vym-footer\">   \n\
   719       <tr> \n\
   720         <td class=\"vym-footerL\">"+model->getFileName()+"</td> \n\
   721         <td class=\"vym-footerC\">"+model->getDate()+"</td> \n\
   722         <td class=\"vym-footerR\"> vym "+model->getVersion()+"</td> \n\
   723       </tr> \n \
   724     </table>\n";
   725 	ts<<"</body></html>";
   726 	file.close();
   727 
   728 	if (!dia.postscript.isEmpty()) 
   729 	{
   730 		Process p;
   731 		p.runScript (dia.postscript,d.path()+"/"+model->getMapName()+".html");
   732 	}
   733 
   734 
   735 	dia.saveSettings();
   736 	model->setExportMode (false);
   737 }
   738 
   739 ////////////////////////////////////////////////////////////////////////
   740 void ExportTaskjuggler::doExport() 
   741 {
   742 	model->exportXML(tmpDir.path(),false);
   743 
   744 	XSLTProc p;
   745 	p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
   746 	p.setOutputFile (outputFile);
   747 	p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
   748 	p.process();
   749 }
   750 
   751 ////////////////////////////////////////////////////////////////////////
   752 void ExportLaTeX::doExport() 
   753 {
   754 	// Exports a map to a LaTex file.  
   755 	// This file needs to be included 
   756 	// or inported into a LaTex document
   757 	// it will not add a preamble, or anything 
   758 	// that makes a full LaTex document.
   759   QFile file (outputFile);
   760   if ( !file.open( QIODevice::WriteOnly ) ) {
   761 	QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
   762 	mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
   763     return;
   764   }
   765   QTextStream ts( &file );	// use LANG decoding here...
   766   ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
   767   
   768   // Main loop over all branches
   769   QString s;
   770   // QString curIndent("");
   771   // int i;
   772   BranchObj *bo;
   773   BranchItem *cur=NULL;
   774   BranchItem *prev=NULL;
   775   model->nextBranch(cur,prev);
   776   while (cur) 
   777   {
   778 	bo=(BranchObj*)(cur->getLMO());
   779 
   780 	if (!cur->hasHiddenExportParent() )
   781 	{
   782 		switch (cur->depth() ) 
   783 		{
   784 			case 0: break;
   785 			case 1: 
   786 			  ts << ("\\chapter{" + cur->getHeading()+ "}\n");
   787 			  break;
   788 			case 2: 
   789 			  ts << ("\\section{" + cur->getHeading()+ "}\n");
   790 			  break;
   791 			case 3: 
   792 			  ts << ("\\subsection{" + cur->getHeading()+ "}\n");
   793 			  break;
   794 			case 4: 
   795 			  ts << ("\\subsubsection{" + cur->getHeading()+ "}\n");
   796 			  break;
   797 			default:
   798 			  ts << ("\\paragraph*{" + cur->getHeading()+ "}\n");
   799 			
   800 		}
   801 		// If necessary, write note
   802 		if (!cur->getNoteObj().isEmpty()) {
   803 		  ts << (cur->getNoteASCII());
   804 		  ts << ("\n");
   805 		}
   806 	}
   807     cur=model->nextBranch(cur,prev);
   808    }
   809   file.close();
   810 }
   811 
   812 ////////////////////////////////////////////////////////////////////////
   813 ExportOO::ExportOO()
   814 {
   815 	useSections=false;
   816 }
   817 
   818 ExportOO::~ExportOO()
   819 {
   820 }	
   821 
   822 QString ExportOO::buildList (TreeItem *current)
   823 {
   824     QString r;
   825 
   826     uint i=0;
   827 	BranchItem *bi=current->getFirstBranch();
   828 	if (bi)
   829     {
   830 		// Start list
   831 		r+="<text:list text:style-name=\"vym-list\">\n";
   832 		while (bi)
   833 		{
   834 			if (!bi->hasHiddenExportParent() )	
   835 			{
   836 				r+="<text:list-item><text:p >";
   837 				r+=quotemeta(bi->getHeading());
   838 				// If necessary, write note
   839 				if (!bi->getNoteObj().isEmpty())
   840 					r+=bi->getNoteOpenDoc();
   841 				r+="</text:p>";
   842 				r+=buildList (bi);	// recursivly add deeper branches
   843 				r+="</text:list-item>\n";
   844 			}
   845 			i++;
   846 			bi=current->getBranchNum(i);
   847 		}
   848 		r+="</text:list>\n";
   849     }
   850     return r;
   851 }
   852 
   853 
   854 void ExportOO::exportPresentation()
   855 {
   856 	QString allPages;
   857 
   858 	BranchItem *firstMCO=(BranchItem*)(model->getRootItem()->getFirstBranch());
   859 	if (!firstMCO) 
   860 	{
   861 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("No objects in map!"));
   862 		return;
   863 	}
   864 
   865 	// Insert new content
   866 	// FIXME add extra title in mapinfo for vym 1.13.x
   867 	content.replace ("<!-- INSERT TITLE -->",quotemeta(firstMCO->getHeading()));
   868 	content.replace ("<!-- INSERT AUTHOR -->",quotemeta(model->getAuthor()));
   869 
   870 	QString	onePage;
   871 	QString list;
   872 	
   873 	BranchItem *sectionBI;	
   874     int i=0;
   875 	BranchItem *pagesBI;
   876     int j=0;
   877 
   878 	int mapcenters=model->getRootItem()->branchCount();
   879 
   880 	// useSections already has been set in setConfigFile 
   881 	if (mapcenters>1)	
   882 		sectionBI=firstMCO;
   883 	else
   884 		sectionBI=firstMCO->getFirstBranch();
   885 
   886 	// Walk sections
   887 	while (sectionBI && !sectionBI->hasHiddenExportParent() )
   888 	{
   889 		if (useSections)
   890 		{
   891 			// Add page with section title
   892 			onePage=sectionTemplate;
   893 			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBI->getHeading() ) );
   894 			allPages+=onePage;
   895 			pagesBI=sectionBI->getFirstBranch();
   896 		} else
   897 		{
   898 			//i=-2;	// only use inner loop to 
   899 			        // turn mainbranches into pages
   900 			//sectionBI=firstMCO;
   901 			pagesBI=sectionBI;
   902 		}
   903 
   904 		j=0;
   905 		while (pagesBI && !pagesBI->hasHiddenExportParent() )
   906 		{
   907 			// Add page with list of items
   908 			onePage=pageTemplate;
   909 			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBI->getHeading() ) );
   910 			list=buildList (pagesBI);
   911 			onePage.replace ("<!-- INSERT LIST -->", list);
   912 			allPages+=onePage;
   913 			if (pagesBI!=sectionBI)
   914 			{
   915 				j++;
   916 				pagesBI=((BranchItem*)pagesBI->parent())->getBranchNum(j);
   917 			} else
   918 				pagesBI=NULL;	// We are already iterating over the sectionBIs
   919 		}
   920 		i++;
   921 		if (mapcenters>1 )
   922 			sectionBI=model->getRootItem()->getBranchNum (i);
   923 		else
   924 			sectionBI=firstMCO->getBranchNum (i);
   925 	}
   926 	
   927 	content.replace ("<!-- INSERT PAGES -->",allPages);
   928 
   929 	// Write modified content
   930 	QFile f (contentFile);
   931     if ( !f.open( QIODevice::WriteOnly ) ) 
   932 	{
   933 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
   934 		mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
   935 		return;
   936     }
   937 
   938     QTextStream t( &f );
   939     t << content;
   940     f.close();
   941 
   942 	// zip tmpdir to destination
   943 	zipDir (tmpDir,outputFile);	
   944 }
   945 
   946 bool ExportOO::setConfigFile (const QString &cf)
   947 {
   948 	configFile=cf;
   949 	int i=cf.findRev ("/");
   950 	if (i>=0) configDir=cf.left(i);
   951 	SimpleSettings set;
   952 	set.readSettings(configFile);
   953 
   954 	// set paths
   955 	templateDir=configDir+"/"+set.readEntry ("Template");
   956 
   957 	QDir d (templateDir);
   958 	if (!d.exists())
   959 	{
   960 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
   961 		return false;
   962 
   963 	}
   964 
   965 	contentTemplateFile=templateDir+"content-template.xml";
   966 	contentFile=tmpDir.path()+"/content.xml";
   967 	pageTemplateFile=templateDir+"page-template.xml";
   968 	sectionTemplateFile=templateDir+"section-template.xml";
   969 
   970 	if (set.readEntry("useSections").contains("yes"))
   971 		useSections=true;
   972 
   973 	// Copy template to tmpdir
   974 	system ("cp -r "+templateDir+"* "+tmpDir.path());
   975 
   976 	// Read content-template
   977 	if (!loadStringFromDisk (contentTemplateFile,content))
   978 	{
   979 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
   980 		return false;
   981 	}
   982 
   983 	// Read page-template
   984 	if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
   985 	{
   986 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
   987 		return false;
   988 	}
   989 	
   990 	// Read section-template
   991 	if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
   992 	{
   993 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));
   994 		return false;
   995 	}
   996 	return true;
   997 }
   998