exports.cpp
author insilmaril
Tue, 15 Dec 2009 09:14:59 +0000
changeset 818 25ee6b988b73
parent 815 2881c4424190
child 819 8f987e376035
permissions -rw-r--r--
Fixed A&O report to show subitems
     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 extern Main *mainWindow;
    12 extern QDir vymBaseDir;
    13 extern QString vymName;
    14 
    15 ExportBase::ExportBase()
    16 {
    17 	indentPerDepth="  ";
    18 	bool ok;
    19     tmpDir.setPath (makeTmpDir(ok,"vym-export"));
    20 	if (!tmpDir.exists() || !ok)
    21 		QMessageBox::critical( 0, QObject::tr( "Error" ),
    22 					   QObject::tr("Couldn't access temporary directory\n"));
    23 	cancelFlag=false;				   
    24 }
    25 
    26 ExportBase::~ExportBase()
    27 {
    28 	// Cleanup tmpdir
    29 	removeDir (tmpDir);
    30 }
    31 
    32 void ExportBase::setDir(const QDir &d)
    33 {
    34 	outDir=d;
    35 }
    36 
    37 void ExportBase::setFile (const QString &p)
    38 {
    39 	outputFile=p;
    40 }
    41 
    42 QString ExportBase::getFile ()
    43 {
    44 	return outputFile;
    45 }
    46 
    47 void ExportBase::setModel(VymModel *m)
    48 {
    49 	model=m;
    50 }
    51 
    52 void ExportBase::setCaption (const QString &s)
    53 {
    54 	caption=s;
    55 }
    56 
    57 void ExportBase::addFilter(const QString &s)
    58 {
    59 	filter=s;
    60 }
    61 
    62 bool ExportBase::execDialog()
    63 {
    64 	{
    65 		QFileDialog *fd=new QFileDialog( 0, caption);
    66 		fd->setFilter (filter);
    67 		fd->setCaption(caption);
    68 		fd->setMode( QFileDialog::AnyFile );
    69 		fd->setDir (outDir);
    70 		fd->show();
    71 
    72 		if ( fd->exec() == QDialog::Accepted )
    73 		{
    74 			if (QFile (fd->selectedFile()).exists() )
    75 			{
    76 				QMessageBox mb( vymName,
    77 					QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()), 
    78 				QMessageBox::Warning,
    79 				QMessageBox::Yes | QMessageBox::Default,
    80 				QMessageBox::Cancel | QMessageBox::Escape,
    81 				Qt::NoButton );
    82 				mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
    83 				mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
    84 				ExportBase ex;
    85 				switch( mb.exec() ) 
    86 				{
    87 					case QMessageBox::Yes:
    88 						// save 
    89 						break;;
    90 					case QMessageBox::Cancel:
    91 						cancelFlag=true;
    92 						return false;
    93 						break;
    94 				}
    95 			}
    96 			outputFile=fd->selectedFile();
    97 			cancelFlag=false;
    98 			return true;
    99 		}
   100 	}
   101 	return false;
   102 }
   103 
   104 bool ExportBase::canceled()
   105 {
   106 	return cancelFlag;
   107 }
   108 
   109 QString ExportBase::getSectionString(TreeItem *start)
   110 {
   111 	// Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
   112 	QString r;
   113 	TreeItem *ti=start;
   114 	int depth=ti->depth();
   115 	while (depth>0)
   116 	{
   117 		r=QString("%1").arg(1+ti->num(),0,10)+"." + r;
   118 		ti=ti->parent(); 
   119 		depth=ti->depth();
   120 	}	
   121 	if (r.isEmpty())
   122 		return r;
   123 	else	
   124 		return r + " ";
   125 }
   126 
   127 ////////////////////////////////////////////////////////////////////////
   128 ExportAO::ExportAO()
   129 {
   130 	filter="TXT (*.txt)";
   131 	caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
   132 }
   133 
   134 void ExportAO::doExport()	
   135 {
   136 	QFile file (outputFile);
   137 	if ( !file.open( QIODevice::WriteOnly ) )
   138 	{
   139 		qWarning ("ExportAO::doExport couldn't open "+outputFile);
   140 		return;
   141 	}
   142 	QTextStream ts( &file );	// use LANG decoding here...
   143 
   144 	// Main loop over all branches
   145 	QString s;
   146 	QString curIndent;
   147 	int i;
   148 	BranchItem *cur=NULL;
   149 	BranchItem *prev=NULL;
   150 
   151 	QString colString;
   152 	QColor col;
   153 
   154 	cur=model->nextBranch (cur,prev);
   155 	while (cur) 
   156 	{
   157 		if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
   158 		{
   159 			// Make indentstring
   160 			curIndent="";
   161 			for (i=0;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
   162 
   163 			if (!cur->hasHiddenExportParent() )
   164 			{
   165 				col=cur->getHeadingColor();
   166 				if (col==QColor (255,0,0))
   167 					colString="[R]";
   168 				else if (col==QColor (217,81,0))
   169 					colString="[O]";
   170 				else if (col==QColor (0,85,0))
   171 					colString="[G]";
   172 				else  	
   173 					colString="[?]";
   174 				switch (cur->depth())
   175 				{
   176 					case 0:
   177 						//ts << underline (cur->getHeading(),QString("="));
   178 						//ts << "\n";
   179 						break;
   180 					case 1:
   181 						//ts << "\n";
   182 						//ts << (underline ( cur->getHeading(), QString("-") ) );
   183 						//ts << "\n";
   184 						break;
   185 					case 2: // Main heading
   186 						ts << "\n";
   187 						ts << underline ( cur->getHeading(), QString("=") );
   188 						ts << "\n";
   189 						break;
   190 					case 3: // Achievement, Bonus, Objective ...
   191 						ts << "\n\n";
   192 						ts << underline ( cur->getHeading(), "-");
   193 						ts << "\n\n";
   194 						break;
   195 					case 4:	// That's the item we need to know
   196 						//ts << (curIndent + "* " + colString+" "+ cur->getHeading());
   197 						ts << colString+" "+ cur->getHeading();
   198 						if (cur->isActiveStandardFlag ("hook-green"))
   199 							ts << " [DONE] ";
   200 						else	if (cur->isActiveStandardFlag ("wip"))
   201 							ts << " [WIP] ";
   202 						else	if (cur->isActiveStandardFlag ("cross-red"))
   203 							ts << " [NOT STARTED] ";
   204 						ts << "\n";
   205 						break;
   206 					default:
   207 						ts << (curIndent + "- " + cur->getHeading());
   208 						ts << "\n";
   209 						break;
   210 				}
   211 
   212 				// If necessary, write note
   213 				if (!cur->getNoteObj().isEmpty())
   214 				{
   215 					curIndent +="  | ";
   216 					s=cur->getNoteASCII( curIndent, 80);
   217 					ts << s;
   218 				}
   219 			}
   220 		}
   221 		cur=model->nextBranch(cur,prev);
   222 	}
   223 	file.close();
   224 }
   225 
   226 QString ExportAO::underline (const QString &text, const QString &line)
   227 {
   228 	QString r=text + "\n";
   229 	for (int j=0;j<text.length();j++) r+=line;
   230 	return r;
   231 }
   232 
   233 
   234 ////////////////////////////////////////////////////////////////////////
   235 ExportASCII::ExportASCII()
   236 {
   237 	filter="TXT (*.txt)";
   238 	caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
   239 }
   240 
   241 void ExportASCII::doExport()	
   242 {
   243 	QFile file (outputFile);
   244 	if ( !file.open( QIODevice::WriteOnly ) )
   245 	{
   246 		qWarning ("ExportASCII::doExport couldn't open "+outputFile);
   247 		return;
   248 	}
   249 	QTextStream ts( &file );	// use LANG decoding here...
   250 
   251 	// Main loop over all branches
   252 	QString s;
   253 	QString curIndent;
   254 	int i;
   255 	BranchItem *cur=NULL;
   256 	BranchItem *prev=NULL;
   257 
   258 	cur=model->nextBranch (cur,prev);
   259 	while (cur) 
   260 	{
   261 		if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
   262 		{
   263 			// Make indentstring
   264 			curIndent="";
   265 			for (i=0;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
   266 
   267 			if (!cur->hasHiddenExportParent() )
   268 			{
   269 				//std::cout << "ExportASCII::  "<<curIndent.toStdString()<<cur->getHeading().toStdString()<<std::endl;
   270 				switch (cur->depth())
   271 				{
   272 					case 0:
   273 						ts << underline (cur->getHeading(),QString("="));
   274 						ts << "\n";
   275 						break;
   276 					case 1:
   277 						ts << "\n";
   278 						ts << (underline (getSectionString(cur) + cur->getHeading(), QString("-") ) );
   279 						ts << "\n";
   280 						break;
   281 					case 2:
   282 						ts << "\n";
   283 						ts << (curIndent + "* " + cur->getHeading());
   284 						ts << "\n";
   285 						break;
   286 					case 3:
   287 						ts << (curIndent + "- " + cur->getHeading());
   288 						ts << "\n";
   289 						break;
   290 					default:
   291 						ts << (curIndent + "- " + cur->getHeading());
   292 						ts << "\n";
   293 						break;
   294 				}
   295 
   296 				// If necessary, write note
   297 				if (!cur->getNoteObj().isEmpty())
   298 				{
   299 					curIndent +="  | ";
   300 					s=cur->getNoteASCII( curIndent, 80);
   301 					ts << s;
   302 				}
   303 			}
   304 		}
   305 		cur=model->nextBranch(cur,prev);
   306 	}
   307 	file.close();
   308 }
   309 
   310 QString ExportASCII::underline (const QString &text, const QString &line)
   311 {
   312 	QString r=text + "\n";
   313 	for (int j=0;j<text.length();j++) r+=line;
   314 	return r;
   315 }
   316 
   317 
   318 ////////////////////////////////////////////////////////////////////////
   319 void ExportCSV::doExport()
   320 {
   321 	QFile file (outputFile);
   322 	if ( !file.open( QIODevice::WriteOnly ) )
   323 	{
   324 		qWarning ("ExportBase::exportXML  couldn't open "+outputFile);
   325 		return;
   326 	}
   327 	QTextStream ts( &file );	// use LANG decoding here...
   328 
   329 	// Write header
   330 	ts << "\"Note\""  <<endl;
   331 
   332 	// Main loop over all branches
   333 	QString s;
   334 	QString curIndent("");
   335 	int i;
   336 	BranchObj *bo;  //FIXME-3 still needed?
   337 	BranchItem *cur=NULL;
   338 	BranchItem *prev=NULL;
   339 	cur=model->nextBranch (cur,prev);
   340 	while (cur) 
   341 	{
   342 		bo=(BranchObj*)(cur->getLMO());
   343 
   344 		if (!cur->hasHiddenExportParent() )
   345 		{
   346 			// If necessary, write note
   347 			if (!cur->getNoteObj().isEmpty())
   348 			{
   349 				s =cur->getNoteASCII();
   350 				s=s.replace ("\n","\n"+curIndent);
   351 				ts << ("\""+s+"\",");
   352 			} else
   353 				ts <<"\"\",";
   354 
   355 			// Make indentstring
   356 			for (i=0;i<cur->depth();i++) curIndent+= "\"\",";
   357 
   358 			// Write heading
   359 			ts << curIndent << "\"" << cur->getHeading()<<"\""<<endl;
   360 		}
   361 		
   362 		cur=model->nextBranch(cur,prev);
   363 		curIndent="";
   364 	}
   365 	file.close();
   366 }
   367 
   368 ////////////////////////////////////////////////////////////////////////
   369 void ExportKDE3Bookmarks::doExport() 
   370 {
   371 	WarningDialog dia;
   372 	dia.showCancelButton (true);
   373 	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
   374 	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE 3"));
   375 	dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
   376 	if (dia.exec()==QDialog::Accepted)
   377 	{
   378 		model->exportXML(tmpDir.path(),false);
   379 
   380 		XSLTProc p;
   381 		p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
   382 		p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
   383 		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
   384 		p.process();
   385 
   386 		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
   387 		QProcess *proc= new QProcess ;
   388 		proc->start( ub);
   389 		if (!proc->waitForStarted())
   390 		{
   391 			QMessageBox::warning(0, 
   392 				QObject::tr("Warning"),
   393 				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
   394 		}	
   395 	}
   396 }
   397 
   398 ////////////////////////////////////////////////////////////////////////
   399 void ExportKDE4Bookmarks::doExport() 
   400 {
   401 	WarningDialog dia;
   402 	dia.showCancelButton (true);
   403 	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE 4"));
   404 	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
   405 	dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
   406 	if (dia.exec()==QDialog::Accepted)
   407 	{
   408 		model->exportXML(tmpDir.path(),false);
   409 
   410 		XSLTProc p;
   411 		p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
   412 		p.setOutputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
   413 		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
   414 		p.process();
   415 
   416 		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
   417 		QProcess *proc= new QProcess ;
   418 		proc->start( ub);
   419 		if (!proc->waitForStarted())
   420 		{
   421 			QMessageBox::warning(0, 
   422 				QObject::tr("Warning"),
   423 				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
   424 		}	
   425 	}
   426 }
   427 
   428 ////////////////////////////////////////////////////////////////////////
   429 void ExportFirefoxBookmarks::doExport() 
   430 {
   431 	WarningDialog dia;
   432 	dia.showCancelButton (true);
   433 	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
   434 	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
   435 	dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
   436 	if (dia.exec()==QDialog::Accepted)
   437 	{
   438 		model->exportXML(tmpDir.path(),false);
   439 
   440 /*
   441 		XSLTProc p;
   442 		p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
   443 		p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
   444 		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
   445 		p.process();
   446 
   447 		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
   448 		QProcess *proc = new QProcess( );
   449 		proc->addArgument(ub);
   450 
   451 		if ( !proc->start() ) 
   452 		{
   453 			QMessageBox::warning(0, 
   454 				QObject::tr("Warning"),
   455 				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
   456 		}	
   457 
   458 */
   459 	}
   460 }
   461 
   462 ////////////////////////////////////////////////////////////////////////
   463 void ExportTaskjuggler::doExport() 
   464 {
   465 	model->exportXML(tmpDir.path(),false);
   466 
   467 	XSLTProc p;
   468 	p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
   469 	p.setOutputFile (outputFile);
   470 	p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
   471 	p.process();
   472 }
   473 
   474 ////////////////////////////////////////////////////////////////////////
   475 void ExportLaTeX::doExport() 
   476 {
   477 	// Exports a map to a LaTex file.  
   478 	// This file needs to be included 
   479 	// or inported into a LaTex document
   480 	// it will not add a preamble, or anything 
   481 	// that makes a full LaTex document.
   482   QFile file (outputFile);
   483   if ( !file.open( QIODevice::WriteOnly ) ) {
   484 	QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
   485 	mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
   486     return;
   487   }
   488   QTextStream ts( &file );	// use LANG decoding here...
   489   ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
   490   
   491   // Main loop over all branches
   492   QString s;
   493   // QString curIndent("");
   494   // int i;
   495   BranchObj *bo;
   496   BranchItem *cur=NULL;
   497   BranchItem *prev=NULL;
   498   model->nextBranch(cur,prev);
   499   while (cur) 
   500   {
   501 	bo=(BranchObj*)(cur->getLMO());
   502 
   503 	if (!cur->hasHiddenExportParent() )
   504 	{
   505 		switch (cur->depth() ) 
   506 		{
   507 			case 0: break;
   508 			case 1: 
   509 			  ts << ("\\chapter{" + cur->getHeading()+ "}\n");
   510 			  break;
   511 			case 2: 
   512 			  ts << ("\\section{" + cur->getHeading()+ "}\n");
   513 			  break;
   514 			case 3: 
   515 			  ts << ("\\subsection{" + cur->getHeading()+ "}\n");
   516 			  break;
   517 			case 4: 
   518 			  ts << ("\\subsubsection{" + cur->getHeading()+ "}\n");
   519 			  break;
   520 			default:
   521 			  ts << ("\\paragraph*{" + cur->getHeading()+ "}\n");
   522 			
   523 		}
   524 		// If necessary, write note
   525 		if (!cur->getNoteObj().isEmpty()) {
   526 		  ts << (cur->getNoteASCII());
   527 		  ts << ("\n");
   528 		}
   529 	}
   530     cur=model->nextBranch(cur,prev);
   531    }
   532   file.close();
   533 }
   534 
   535 ////////////////////////////////////////////////////////////////////////
   536 ExportOO::ExportOO()
   537 {
   538 	useSections=false;
   539 }
   540 
   541 ExportOO::~ExportOO()
   542 {
   543 }	
   544 
   545 QString ExportOO::buildList (TreeItem *current)
   546 {
   547     QString r;
   548 
   549     uint i=0;
   550 	BranchItem *bi=current->getFirstBranch();
   551 	if (bi)
   552     {
   553 		if (!bi->hasHiddenExportParent() )	// FIXME-3 use BranchItem...
   554 		{
   555 			// Start list
   556 			r+="<text:list text:style-name=\"vym-list\">\n";
   557 			while (bi)
   558 			{
   559 				r+="<text:list-item><text:p >";
   560 				r+=quotemeta(bi->getHeading());
   561 				// If necessary, write note
   562 				if (!bi->getNoteObj().isEmpty())
   563 					r+=bi->getNoteOpenDoc();
   564 				r+="</text:p>";
   565 				r+=buildList (bi);	// recursivly add deeper branches
   566 				r+="</text:list-item>\n";
   567 				i++;
   568 				bi=current->getBranchNum(i);
   569 			}
   570 			r+="</text:list>\n";
   571 		}
   572     }
   573     return r;
   574 }
   575 
   576 
   577 void ExportOO::exportPresentation()
   578 {
   579 	QString allPages;
   580 
   581 	BranchItem *firstMCO=(BranchItem*)(model->getRootItem()->getFirstBranch());
   582 	if (!firstMCO) 
   583 	{
   584 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("No objects in map!"));
   585 		return;
   586 	}
   587 
   588 	// Insert new content
   589 	// FIXME add extra title in mapinfo for vym 1.13.x
   590 	content.replace ("<!-- INSERT TITLE -->",quotemeta(firstMCO->getHeading()));
   591 	content.replace ("<!-- INSERT AUTHOR -->",quotemeta(model->getAuthor()));
   592 
   593 	QString	onePage;
   594 	QString list;
   595 	
   596 	BranchItem *sectionBI;	
   597     int i=0;
   598 	BranchItem *pagesBI;
   599     int j=0;
   600 
   601 	int mapcenters=model->getRootItem()->branchCount();
   602 
   603 	// useSections already has been set in setConfigFile 
   604 	if (mapcenters>1)	
   605 		sectionBI=firstMCO;
   606 	else
   607 		sectionBI=firstMCO->getFirstBranch();
   608 
   609 	// Walk sections
   610 	while (sectionBI && !sectionBI->hasHiddenExportParent() )
   611 	{
   612 		if (useSections)
   613 		{
   614 			// Add page with section title
   615 			onePage=sectionTemplate;
   616 			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBI->getHeading() ) );
   617 			allPages+=onePage;
   618 			pagesBI=sectionBI->getFirstBranch();
   619 		} else
   620 		{
   621 			//i=-2;	// only use inner loop to 
   622 			        // turn mainbranches into pages
   623 			//sectionBI=firstMCO;
   624 			pagesBI=sectionBI;
   625 		}
   626 
   627 		j=0;
   628 		while (pagesBI && !pagesBI->hasHiddenExportParent() )
   629 		{
   630 			// Add page with list of items
   631 			onePage=pageTemplate;
   632 			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBI->getHeading() ) );
   633 			list=buildList (pagesBI);
   634 			onePage.replace ("<!-- INSERT LIST -->", list);
   635 			allPages+=onePage;
   636 			if (pagesBI!=sectionBI)
   637 			{
   638 				j++;
   639 				pagesBI=((BranchItem*)pagesBI->parent())->getBranchNum(j);
   640 			} else
   641 				pagesBI=NULL;	// We are already iterating over the sectionBIs
   642 		}
   643 		i++;
   644 		if (mapcenters>1 )
   645 			sectionBI=model->getRootItem()->getBranchNum (i);
   646 		else
   647 			sectionBI=firstMCO->getBranchNum (i);
   648 	}
   649 	
   650 	content.replace ("<!-- INSERT PAGES -->",allPages);
   651 
   652 	// Write modified content
   653 	QFile f (contentFile);
   654     if ( !f.open( QIODevice::WriteOnly ) ) 
   655 	{
   656 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
   657 		mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
   658 		return;
   659     }
   660 
   661     QTextStream t( &f );
   662     t << content;
   663     f.close();
   664 
   665 	// zip tmpdir to destination
   666 	zipDir (tmpDir,outputFile);	
   667 }
   668 
   669 bool ExportOO::setConfigFile (const QString &cf)
   670 {
   671 	configFile=cf;
   672 	int i=cf.findRev ("/");
   673 	if (i>=0) configDir=cf.left(i);
   674 	SimpleSettings set;
   675 	set.readSettings(configFile);
   676 
   677 	// set paths
   678 	templateDir=configDir+"/"+set.readEntry ("Template");
   679 
   680 	QDir d (templateDir);
   681 	if (!d.exists())
   682 	{
   683 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
   684 		return false;
   685 
   686 	}
   687 
   688 	contentTemplateFile=templateDir+"content-template.xml";
   689 	contentFile=tmpDir.path()+"/content.xml";
   690 	pageTemplateFile=templateDir+"page-template.xml";
   691 	sectionTemplateFile=templateDir+"section-template.xml";
   692 
   693 	if (set.readEntry("useSections").contains("yes"))
   694 		useSections=true;
   695 
   696 	// Copy template to tmpdir
   697 	system ("cp -r "+templateDir+"* "+tmpDir.path());
   698 
   699 	// Read content-template
   700 	if (!loadStringFromDisk (contentTemplateFile,content))
   701 	{
   702 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
   703 		return false;
   704 	}
   705 
   706 	// Read page-template
   707 	if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
   708 	{
   709 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
   710 		return false;
   711 	}
   712 	
   713 	// Read section-template
   714 	if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
   715 	{
   716 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));
   717 		return false;
   718 	}
   719 	return true;
   720 }
   721