exports.cpp
branchrelease-1-12-maintained
changeset 59 1c550f80c43b
parent 0 7a96bd401351
child 62 85683324f94a
     1.1 --- a/exports.cpp	Sun Jan 30 12:58:47 2005 +0000
     1.2 +++ b/exports.cpp	Tue Mar 10 11:27:17 2009 +0000
     1.3 @@ -1,87 +1,114 @@
     1.4  #include "exports.h"
     1.5 +#include "file.h"
     1.6 +#include "linkablemapobj.h"
     1.7 +#include "misc.h"
     1.8 +#include "mainwindow.h"
     1.9 +#include "warningdialog.h"
    1.10 +#include "xsltproc.h"
    1.11  
    1.12 -#include "linkablemapobj.h"
    1.13 +extern Main *mainWindow;
    1.14 +extern QDir vymBaseDir;
    1.15 +extern QString vymName;
    1.16  
    1.17 -
    1.18 -Export::Export()
    1.19 +ExportBase::ExportBase()
    1.20  {
    1.21  	indentPerDepth="  ";
    1.22 +	bool ok;
    1.23 +    tmpDir.setPath (makeTmpDir(ok,"vym-export"));
    1.24 +	if (!tmpDir.exists() || !ok)
    1.25 +		QMessageBox::critical( 0, QObject::tr( "Error" ),
    1.26 +					   QObject::tr("Couldn't access temporary directory\n"));
    1.27 +	cancelFlag=false;				   
    1.28  }
    1.29  
    1.30 -bool Export::setOutputDir(QString dirname)
    1.31 +ExportBase::~ExportBase()
    1.32  {
    1.33 -	outdir.setPath (dirname);
    1.34 -	if ( outdir.exists() )
    1.35 -	{
    1.36 -		// FIXME
    1.37 -		// ask for confirmation
    1.38 -		// then delete outdir
    1.39 -		return true;
    1.40 -	} else
    1.41 -	{
    1.42 -		// try to create directory
    1.43 -		//return outdir.mkdir (outdir.absPath());
    1.44 -		// FIXME
    1.45 -		return true;
    1.46 -	}
    1.47 +	// Cleanup tmpdir
    1.48 +	removeDir (tmpDir);
    1.49  }
    1.50  
    1.51 -void Export::setPath (const QString &p)
    1.52 +void ExportBase::setDir(const QDir &d)
    1.53  {
    1.54 -	filepath=p;
    1.55 +	outDir=d;
    1.56  }
    1.57  
    1.58 -void Export::setMapCenter(MapCenterObj *mc)
    1.59 +void ExportBase::setFile (const QString &p)
    1.60  {
    1.61 -	mapCenter=mc;
    1.62 +	outputFile=p;
    1.63  }
    1.64  
    1.65 -void Export::exportMap()
    1.66 +QString ExportBase::getFile ()
    1.67  {
    1.68 -	QFile file (filepath);
    1.69 -	if ( !file.open( IO_WriteOnly ) )
    1.70 -	{
    1.71 -		// FIXME
    1.72 -		cout << "Export::exportMap  couldn't open "<<filepath<<endl;
    1.73 -		return;
    1.74 -	}
    1.75 -	QTextStream ts( &file );	// use LANG decoding here...
    1.76 -
    1.77 -	// Main loop over all branches
    1.78 -	QString s;
    1.79 -	QString actIndent("");
    1.80 -	int i;
    1.81 -	BranchObj *bo;
    1.82 -	bo=mapCenter->first();
    1.83 -	while (bo) 
    1.84 -	{
    1.85 -		// Make indentstring
    1.86 -		for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
    1.87 -
    1.88 -		// Write heading
    1.89 -		//	write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n");
    1.90 -		if (bo->getDepth()==1)
    1.91 -			ts << (getSectionString(bo) + bo->getHeading()+ "\n");
    1.92 -		else	
    1.93 -			ts << (actIndent + " - " + bo->getHeading()+ "\n");
    1.94 -		
    1.95 -		// If necessary, write note
    1.96 -		if (!bo->getNote().isEmpty())
    1.97 -		{
    1.98 -			ts << ("-------------------Begin of Note-----------------\n");
    1.99 -			ts << (bo->getNote());
   1.100 -			ts << ("\n");
   1.101 -			ts << ("-------------------End of Note-------------------\n");
   1.102 -		}
   1.103 -		
   1.104 -		bo=bo->next();
   1.105 -		actIndent="";
   1.106 -	}
   1.107 -	file.close();
   1.108 +	return outputFile;
   1.109  }
   1.110  
   1.111 -QString Export::getSectionString(BranchObj *bostart)
   1.112 +void ExportBase::setModel(VymModel *m)
   1.113  {
   1.114 +	model=m;
   1.115 +}
   1.116 +
   1.117 +void ExportBase::setCaption (const QString &s)
   1.118 +{
   1.119 +	caption=s;
   1.120 +}
   1.121 +
   1.122 +void ExportBase::addFilter(const QString &s)
   1.123 +{
   1.124 +	filter=s;
   1.125 +}
   1.126 +
   1.127 +bool ExportBase::execDialog()
   1.128 +{
   1.129 +	//MapEditor *me=model.getMapEditor(); FIXME needed?
   1.130 +	// if (model->mapCenters.count() && me)
   1.131 +	{
   1.132 +		QFileDialog *fd=new QFileDialog( 0, caption);
   1.133 +		fd->setFilter (filter);
   1.134 +		fd->setCaption(caption);
   1.135 +		fd->setMode( QFileDialog::AnyFile );
   1.136 +		fd->setDir (outDir);
   1.137 +		fd->show();
   1.138 +
   1.139 +		if ( fd->exec() == QDialog::Accepted )
   1.140 +		{
   1.141 +			if (QFile (fd->selectedFile()).exists() )
   1.142 +			{
   1.143 +				QMessageBox mb( vymName,
   1.144 +					QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()), 
   1.145 +				QMessageBox::Warning,
   1.146 +				QMessageBox::Yes | QMessageBox::Default,
   1.147 +				QMessageBox::Cancel | QMessageBox::Escape,
   1.148 +				Qt::NoButton );
   1.149 +				mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
   1.150 +				mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
   1.151 +				ExportBase ex;
   1.152 +				switch( mb.exec() ) 
   1.153 +				{
   1.154 +					case QMessageBox::Yes:
   1.155 +						// save 
   1.156 +						break;;
   1.157 +					case QMessageBox::Cancel:
   1.158 +						cancelFlag=true;
   1.159 +						return false;
   1.160 +						break;
   1.161 +				}
   1.162 +			}
   1.163 +			outputFile=fd->selectedFile();
   1.164 +			cancelFlag=false;
   1.165 +			return true;
   1.166 +		}
   1.167 +	}
   1.168 +	return false;
   1.169 +}
   1.170 +
   1.171 +bool ExportBase::canceled()
   1.172 +{
   1.173 +	return cancelFlag;
   1.174 +}
   1.175 +
   1.176 +QString ExportBase::getSectionString(BranchObj *bostart)
   1.177 +{
   1.178 +	// Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
   1.179  	QString r;
   1.180  	BranchObj *bo=bostart;
   1.181  	int depth=bo->getDepth();
   1.182 @@ -97,36 +124,460 @@
   1.183  		return r + " ";
   1.184  }
   1.185  
   1.186 -void Export::exportAsHTML()
   1.187 +////////////////////////////////////////////////////////////////////////
   1.188 +ExportASCII::ExportASCII()
   1.189  {
   1.190 -	// FIXME  just testing...
   1.191 +	filter="TXT (*.txt)";
   1.192 +	caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
   1.193 +}
   1.194 +
   1.195 +void ExportASCII::doExport()
   1.196 +{
   1.197 +	QFile file (outputFile);
   1.198 +	if ( !file.open( QIODevice::WriteOnly ) )
   1.199 +	{
   1.200 +		qWarning ("ExportBase::exportXML  couldn't open "+outputFile);
   1.201 +		return;
   1.202 +	}
   1.203 +	QTextStream ts( &file );	// use LANG decoding here...
   1.204 +
   1.205  	// Main loop over all branches
   1.206  	QString s;
   1.207 -	QString actIndent("");
   1.208 +	QString curIndent;
   1.209  	int i;
   1.210  	BranchObj *bo;
   1.211 -	bo=mapCenter->first();
   1.212 +	bo=model->first();
   1.213  	while (bo) 
   1.214  	{
   1.215  		// Make indentstring
   1.216 -		for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
   1.217 +		curIndent="";
   1.218 +		for (i=0;i<bo->getDepth()-1;i++) curIndent+= indentPerDepth;
   1.219  
   1.220 -		// Write heading
   1.221 -		write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n");
   1.222 -		
   1.223 -		// If necessary, write note
   1.224 -		if (!bo->getNote().isEmpty())
   1.225 +		if (!bo->hasHiddenExportParent() )
   1.226  		{
   1.227 -			write (bo->getNote());
   1.228 +			switch (bo->getDepth())
   1.229 +			{
   1.230 +				case 0:
   1.231 +					ts << underline (bo->getHeading(),QString("="));
   1.232 +					ts << "\n";
   1.233 +					break;
   1.234 +				case 1:
   1.235 +					ts << "\n";
   1.236 +					ts << (underline (getSectionString(bo) + bo->getHeading(), QString("-") ) );
   1.237 +					ts << "\n";
   1.238 +					break;
   1.239 +				case 2:
   1.240 +					ts << "\n";
   1.241 +					ts << (curIndent + "* " + bo->getHeading());
   1.242 +					ts << "\n";
   1.243 +					break;
   1.244 +				case 3:
   1.245 +					ts << (curIndent + "- " + bo->getHeading());
   1.246 +					ts << "\n";
   1.247 +					break;
   1.248 +				default:
   1.249 +					ts << (curIndent + "- " + bo->getHeading());
   1.250 +					ts << "\n";
   1.251 +					break;
   1.252 +			}
   1.253 +
   1.254 +			// If necessary, write note
   1.255 +			if (!bo->getNote().isEmpty())
   1.256 +			{
   1.257 +				curIndent +="  | ";
   1.258 +				s=bo->getNoteASCII( curIndent, 80);
   1.259 +				ts << s;
   1.260 +			}
   1.261 +		}
   1.262 +		bo=model->next(bo);
   1.263 +	}
   1.264 +	file.close();
   1.265 +}
   1.266 +
   1.267 +QString ExportASCII::underline (const QString &text, const QString &line)
   1.268 +{
   1.269 +	QString r=text + "\n";
   1.270 +	for (int j=0;j<text.length();j++) r+=line;
   1.271 +	return r;
   1.272 +}
   1.273 +
   1.274 +
   1.275 +////////////////////////////////////////////////////////////////////////
   1.276 +void ExportCSV::doExport()
   1.277 +{
   1.278 +	QFile file (outputFile);
   1.279 +	if ( !file.open( QIODevice::WriteOnly ) )
   1.280 +	{
   1.281 +		qWarning ("ExportBase::exportXML  couldn't open "+outputFile);
   1.282 +		return;
   1.283 +	}
   1.284 +	QTextStream ts( &file );	// use LANG decoding here...
   1.285 +
   1.286 +	// Write header
   1.287 +	ts << "\"Note\""  <<endl;
   1.288 +
   1.289 +	// Main loop over all branches
   1.290 +	QString s;
   1.291 +	QString curIndent("");
   1.292 +	int i;
   1.293 +	BranchObj *bo;
   1.294 +	bo=model->first();
   1.295 +	while (bo) 
   1.296 +	{
   1.297 +		if (!bo->hasHiddenExportParent() )
   1.298 +		{
   1.299 +			// If necessary, write note
   1.300 +			if (!bo->getNote().isEmpty())
   1.301 +			{
   1.302 +				s =bo->getNoteASCII();
   1.303 +				s=s.replace ("\n","\n"+curIndent);
   1.304 +				ts << ("\""+s+"\",");
   1.305 +			} else
   1.306 +				ts <<"\"\",";
   1.307 +
   1.308 +			// Make indentstring
   1.309 +			for (i=0;i<bo->getDepth();i++) curIndent+= "\"\",";
   1.310 +
   1.311 +			// Write heading
   1.312 +			ts << curIndent << "\"" << bo->getHeading()<<"\""<<endl;
   1.313  		}
   1.314  		
   1.315 -		bo=bo->next();
   1.316 -		actIndent="";
   1.317 +		bo=model->next(bo);
   1.318 +		curIndent="";
   1.319 +	}
   1.320 +	file.close();
   1.321 +}
   1.322 +
   1.323 +////////////////////////////////////////////////////////////////////////
   1.324 +void ExportKDEBookmarks::doExport() 
   1.325 +{
   1.326 +	MapEditor *me=model->getMapEditor();
   1.327 +	if (me)
   1.328 +	{
   1.329 +		WarningDialog dia;
   1.330 +		dia.showCancelButton (true);
   1.331 +		dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
   1.332 +		dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
   1.333 +		dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
   1.334 +		if (dia.exec()==QDialog::Accepted)
   1.335 +		{
   1.336 +			me->exportXML(tmpDir.path(),false);
   1.337 +
   1.338 +			XSLTProc p;
   1.339 +			p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
   1.340 +			p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
   1.341 +			p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
   1.342 +			p.process();
   1.343 +
   1.344 +			QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
   1.345 +			QProcess *proc= new QProcess ;
   1.346 +			proc->start( ub);
   1.347 +			if (!proc->waitForStarted())
   1.348 +			{
   1.349 +				QMessageBox::warning(0, 
   1.350 +					QObject::tr("Warning"),
   1.351 +					QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
   1.352 +			}	
   1.353 +		}
   1.354 +	}
   1.355 +
   1.356 +}
   1.357 +
   1.358 +////////////////////////////////////////////////////////////////////////
   1.359 +void ExportFirefoxBookmarks::doExport() 
   1.360 +{
   1.361 +	MapEditor *me=model->getMapEditor();
   1.362 +	if (me)
   1.363 +	{
   1.364 +		WarningDialog dia;
   1.365 +		dia.showCancelButton (true);
   1.366 +		dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
   1.367 +		dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
   1.368 +		dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
   1.369 +		if (dia.exec()==QDialog::Accepted)
   1.370 +		{
   1.371 +			me->exportXML(tmpDir.path(),false);
   1.372 +
   1.373 +/*
   1.374 +			XSLTProc p;
   1.375 +			p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
   1.376 +			p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
   1.377 +			p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
   1.378 +			p.process();
   1.379 +
   1.380 +			QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
   1.381 +			QProcess *proc = new QProcess( );
   1.382 +			proc->addArgument(ub);
   1.383 +
   1.384 +			if ( !proc->start() ) 
   1.385 +			{
   1.386 +				QMessageBox::warning(0, 
   1.387 +					QObject::tr("Warning"),
   1.388 +					QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
   1.389 +			}	
   1.390 +
   1.391 +*/
   1.392 +
   1.393 +		}
   1.394  	}
   1.395  }
   1.396  
   1.397 -void Export::write(QString s)
   1.398 +////////////////////////////////////////////////////////////////////////
   1.399 +void ExportTaskjuggler::doExport() 
   1.400  {
   1.401 -	cout << s;
   1.402 +	MapEditor *me=model->getMapEditor();
   1.403 +	if (me)
   1.404 +	{
   1.405 +		me->exportXML(tmpDir.path(),false);
   1.406 +
   1.407 +		XSLTProc p;
   1.408 +		p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
   1.409 +		p.setOutputFile (outputFile);
   1.410 +		p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
   1.411 +		p.process();
   1.412 +	}
   1.413 +
   1.414  }
   1.415  
   1.416 +////////////////////////////////////////////////////////////////////////
   1.417 +void ExportLaTeX::doExport() 
   1.418 +{
   1.419 +	// Exports a map to a LaTex file.  
   1.420 +	// This file needs to be included 
   1.421 +	// or inported into a LaTex document
   1.422 +	// it will not add a preamble, or anything 
   1.423 +	// that makes a full LaTex document.
   1.424 +  QFile file (outputFile);
   1.425 +  if ( !file.open( QIODevice::WriteOnly ) ) {
   1.426 +	QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
   1.427 +	mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
   1.428 +    return;
   1.429 +  }
   1.430 +  QTextStream ts( &file );	// use LANG decoding here...
   1.431 +  ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
   1.432 +  
   1.433 +  // Main loop over all branches
   1.434 +  QString s;
   1.435 +  // QString curIndent("");
   1.436 +  // int i;
   1.437 +  BranchObj *bo;
   1.438 +  bo=model->first();
   1.439 +  while (bo) {
   1.440 +	if (!bo->hasHiddenExportParent() )
   1.441 +	{
   1.442 +		if (bo->getDepth()==0);
   1.443 +		else if (bo->getDepth()==1) {
   1.444 +		  ts << ("\\chapter{" + bo->getHeading()+ "}\n");
   1.445 +		}
   1.446 +		else if (bo->getDepth()==2) {
   1.447 +		  ts << ("\\section{" + bo->getHeading()+ "}\n");
   1.448 +		}
   1.449 +		else if (bo->getDepth()==3) {
   1.450 +		  ts << ("\\subsection{" + bo->getHeading()+ "}\n");
   1.451 +		}
   1.452 +		else if (bo->getDepth()==4) {
   1.453 +		  ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
   1.454 +		}
   1.455 +		else {
   1.456 +		  ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
   1.457 +		}
   1.458 +		
   1.459 +		// If necessary, write note
   1.460 +		if (!bo->getNote().isEmpty()) {
   1.461 +		  ts << (bo->getNoteASCII());
   1.462 +		  ts << ("\n");
   1.463 +		}
   1.464 +	}
   1.465 +    bo=model->next(bo);
   1.466 +   }
   1.467 +  file.close();
   1.468 +}
   1.469 +
   1.470 +////////////////////////////////////////////////////////////////////////
   1.471 +ExportOO::ExportOO()
   1.472 +{
   1.473 +	useSections=false;
   1.474 +}
   1.475 +
   1.476 +ExportOO::~ExportOO()
   1.477 +{
   1.478 +}	
   1.479 +
   1.480 +QString ExportOO::buildList (BranchObj *current)
   1.481 +{
   1.482 +    QString r;
   1.483 +    BranchObj *bo;
   1.484 +
   1.485 +    uint i=0;
   1.486 +    bo=current->getFirstBranch();
   1.487 +    if (bo)
   1.488 +    {
   1.489 +		if (!bo->hasHiddenExportParent() )
   1.490 +		{
   1.491 +			// Start list
   1.492 +			r+="<text:list text:style-name=\"vym-list\">\n";
   1.493 +			while (bo)
   1.494 +			{
   1.495 +				r+="<text:list-item><text:p >";
   1.496 +				r+=quotemeta(bo->getHeading());
   1.497 +				// If necessary, write note
   1.498 +				if (!bo->getNote().isEmpty())
   1.499 +					r+=bo->getNoteOpenDoc();
   1.500 +				r+="</text:p>";
   1.501 +				r+=buildList (bo);	// recursivly add deeper branches
   1.502 +				r+="</text:list-item>\n";
   1.503 +				i++;
   1.504 +				bo=current->getBranchNum(i);
   1.505 +			}
   1.506 +			r+="</text:list>\n";
   1.507 +		}
   1.508 +    }
   1.509 +    return r;
   1.510 +}
   1.511 +
   1.512 +
   1.513 +void ExportOO::exportPresentation()
   1.514 +{
   1.515 +	QString allPages;
   1.516 +
   1.517 +	MapCenterObj *firstMCO=(MapCenterObj*)model->first();
   1.518 +	if (!firstMCO) 
   1.519 +	{
   1.520 +		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("No objects in map!"));
   1.521 +		return;
   1.522 +	}
   1.523 +
   1.524 +	// Insert new content
   1.525 +	// FIXME add extra title in mapinfo for vym 1.13.x
   1.526 +	content.replace ("<!-- INSERT TITLE -->",quotemeta(firstMCO->getHeading()));
   1.527 +	content.replace ("<!-- INSERT AUTHOR -->",quotemeta(model->getAuthor()));
   1.528 +
   1.529 +	QString	onePage;
   1.530 +	QString list;
   1.531 +	
   1.532 +	BranchObj *sectionBO;	
   1.533 +    int i=0;
   1.534 +	BranchObj *pagesBO;
   1.535 +    int j=0;
   1.536 +
   1.537 +	int mapcenters=model->countMapCenters();
   1.538 +
   1.539 +	// useSections already has been set in setConfigFile 
   1.540 +	if (mapcenters>1)	
   1.541 +		sectionBO=firstMCO;
   1.542 +	else
   1.543 +		sectionBO=firstMCO->getFirstBranch();
   1.544 +
   1.545 +	// Walk sections
   1.546 +	while (sectionBO && !sectionBO->hasHiddenExportParent() )
   1.547 +	{
   1.548 +		if (useSections)
   1.549 +		{
   1.550 +			// Add page with section title
   1.551 +			onePage=sectionTemplate;
   1.552 +			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
   1.553 +			allPages+=onePage;
   1.554 +			pagesBO=sectionBO->getFirstBranch();
   1.555 +		} else
   1.556 +		{
   1.557 +			//i=-2;	// only use inner loop to 
   1.558 +			        // turn mainbranches into pages
   1.559 +			//sectionBO=firstMCO;
   1.560 +			pagesBO=sectionBO;
   1.561 +		}
   1.562 +
   1.563 +		j=0;
   1.564 +		while (pagesBO && !pagesBO->hasHiddenExportParent() )
   1.565 +		{
   1.566 +			// Add page with list of items
   1.567 +			onePage=pageTemplate;
   1.568 +			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
   1.569 +			list=buildList (pagesBO);
   1.570 +			onePage.replace ("<!-- INSERT LIST -->", list);
   1.571 +			allPages+=onePage;
   1.572 +			if (pagesBO!=sectionBO)
   1.573 +			{
   1.574 +				j++;
   1.575 +				pagesBO=((BranchObj*)pagesBO->getParObj())->getBranchNum(j);
   1.576 +			} else
   1.577 +				pagesBO=NULL;	// We are already iterating over the sectionBOs
   1.578 +		}
   1.579 +		i++;
   1.580 +		if (mapcenters>1 )
   1.581 +			sectionBO=model->getMapCenterNum (i);
   1.582 +		else
   1.583 +			sectionBO=firstMCO->getBranchNum (i);
   1.584 +	}
   1.585 +	
   1.586 +	content.replace ("<!-- INSERT PAGES -->",allPages);
   1.587 +
   1.588 +	// Write modified content
   1.589 +	QFile f (contentFile);
   1.590 +    if ( !f.open( QIODevice::WriteOnly ) ) 
   1.591 +	{
   1.592 +		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
   1.593 +		mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
   1.594 +		return;
   1.595 +    }
   1.596 +
   1.597 +    QTextStream t( &f );
   1.598 +    t << content;
   1.599 +    f.close();
   1.600 +
   1.601 +	// zip tmpdir to destination
   1.602 +	zipDir (tmpDir,outputFile);	
   1.603 +}
   1.604 +
   1.605 +bool ExportOO::setConfigFile (const QString &cf)
   1.606 +{
   1.607 +	configFile=cf;
   1.608 +	int i=cf.findRev ("/");
   1.609 +	if (i>=0) configDir=cf.left(i);
   1.610 +	SimpleSettings set;
   1.611 +	set.readSettings(configFile);
   1.612 +
   1.613 +	// set paths
   1.614 +	templateDir=configDir+"/"+set.readEntry ("Template");
   1.615 +
   1.616 +	QDir d (templateDir);
   1.617 +	if (!d.exists())
   1.618 +	{
   1.619 +		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
   1.620 +		return false;
   1.621 +
   1.622 +	}
   1.623 +
   1.624 +	contentTemplateFile=templateDir+"content-template.xml";
   1.625 +	contentFile=tmpDir.path()+"/content.xml";
   1.626 +	pageTemplateFile=templateDir+"page-template.xml";
   1.627 +	sectionTemplateFile=templateDir+"section-template.xml";
   1.628 +
   1.629 +	if (model->countMapCenters()>1 ||set.readEntry("useSections").contains("yes"))
   1.630 +		useSections=true;
   1.631 +
   1.632 +	// Copy template to tmpdir
   1.633 +	system ("cp -r "+templateDir+"* "+tmpDir.path());
   1.634 +
   1.635 +	// Read content-template
   1.636 +	if (!loadStringFromDisk (contentTemplateFile,content))
   1.637 +	{
   1.638 +		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
   1.639 +		return false;
   1.640 +	}
   1.641 +
   1.642 +	// Read page-template
   1.643 +	if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
   1.644 +	{
   1.645 +		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
   1.646 +		return false;
   1.647 +	}
   1.648 +	
   1.649 +	// Read section-template
   1.650 +	if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
   1.651 +	{
   1.652 +		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));
   1.653 +		return false;
   1.654 +	}
   1.655 +	return true;
   1.656 +}
   1.657 +