exports.cpp
author insilmaril
Mon, 14 Dec 2009 10:17:55 +0000
changeset 817 b486ffd0fa11
parent 815 2881c4424190
child 818 25ee6b988b73
permissions -rw-r--r--
Bugfix for relinking mainbranches
     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\n";
   189 						break;
   190 					case 3: // Achievement, Bonus, Objective ...
   191 						ts << underline ( cur->getHeading(), "-");
   192 						ts << "\n\n";
   193 						break;
   194 					case 4:	// That's the item we need to know
   195 						//ts << (curIndent + "* " + colString+" "+ cur->getHeading());
   196 						ts << colString+" "+ cur->getHeading();
   197 						if (cur->isActiveStandardFlag ("hook-green"))
   198 							ts << " [DONE] ";
   199 						else	if (cur->isActiveStandardFlag ("wip"))
   200 							ts << " [WIP] ";
   201 						else	if (cur->isActiveStandardFlag ("cross-red"))
   202 							ts << " [NOT STARTED] ";
   203 						ts << "\n";
   204 					default:
   205 						break;
   206 						ts << (curIndent + "- " + cur->getHeading());
   207 						ts << "\n";
   208 						break;
   209 				}
   210 
   211 				// If necessary, write note
   212 				if (!cur->getNoteObj().isEmpty())
   213 				{
   214 					curIndent +="  | ";
   215 					s=cur->getNoteASCII( curIndent, 80);
   216 					ts << s;
   217 				}
   218 			}
   219 		}
   220 		cur=model->nextBranch(cur,prev);
   221 	}
   222 	file.close();
   223 }
   224 
   225 QString ExportAO::underline (const QString &text, const QString &line)
   226 {
   227 	QString r=text + "\n";
   228 	for (int j=0;j<text.length();j++) r+=line;
   229 	return r;
   230 }
   231 
   232 
   233 ////////////////////////////////////////////////////////////////////////
   234 ExportASCII::ExportASCII()
   235 {
   236 	filter="TXT (*.txt)";
   237 	caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
   238 }
   239 
   240 void ExportASCII::doExport()	
   241 {
   242 	QFile file (outputFile);
   243 	if ( !file.open( QIODevice::WriteOnly ) )
   244 	{
   245 		qWarning ("ExportASCII::doExport couldn't open "+outputFile);
   246 		return;
   247 	}
   248 	QTextStream ts( &file );	// use LANG decoding here...
   249 
   250 	// Main loop over all branches
   251 	QString s;
   252 	QString curIndent;
   253 	int i;
   254 	BranchItem *cur=NULL;
   255 	BranchItem *prev=NULL;
   256 
   257 	cur=model->nextBranch (cur,prev);
   258 	while (cur) 
   259 	{
   260 		if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
   261 		{
   262 			// Make indentstring
   263 			curIndent="";
   264 			for (i=0;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
   265 
   266 			if (!cur->hasHiddenExportParent() )
   267 			{
   268 				//std::cout << "ExportASCII::  "<<curIndent.toStdString()<<cur->getHeading().toStdString()<<std::endl;
   269 				switch (cur->depth())
   270 				{
   271 					case 0:
   272 						ts << underline (cur->getHeading(),QString("="));
   273 						ts << "\n";
   274 						break;
   275 					case 1:
   276 						ts << "\n";
   277 						ts << (underline (getSectionString(cur) + cur->getHeading(), QString("-") ) );
   278 						ts << "\n";
   279 						break;
   280 					case 2:
   281 						ts << "\n";
   282 						ts << (curIndent + "* " + cur->getHeading());
   283 						ts << "\n";
   284 						break;
   285 					case 3:
   286 						ts << (curIndent + "- " + cur->getHeading());
   287 						ts << "\n";
   288 						break;
   289 					default:
   290 						ts << (curIndent + "- " + cur->getHeading());
   291 						ts << "\n";
   292 						break;
   293 				}
   294 
   295 				// If necessary, write note
   296 				if (!cur->getNoteObj().isEmpty())
   297 				{
   298 					curIndent +="  | ";
   299 					s=cur->getNoteASCII( curIndent, 80);
   300 					ts << s;
   301 				}
   302 			}
   303 		}
   304 		cur=model->nextBranch(cur,prev);
   305 	}
   306 	file.close();
   307 }
   308 
   309 QString ExportASCII::underline (const QString &text, const QString &line)
   310 {
   311 	QString r=text + "\n";
   312 	for (int j=0;j<text.length();j++) r+=line;
   313 	return r;
   314 }
   315 
   316 
   317 ////////////////////////////////////////////////////////////////////////
   318 void ExportCSV::doExport()
   319 {
   320 	QFile file (outputFile);
   321 	if ( !file.open( QIODevice::WriteOnly ) )
   322 	{
   323 		qWarning ("ExportBase::exportXML  couldn't open "+outputFile);
   324 		return;
   325 	}
   326 	QTextStream ts( &file );	// use LANG decoding here...
   327 
   328 	// Write header
   329 	ts << "\"Note\""  <<endl;
   330 
   331 	// Main loop over all branches
   332 	QString s;
   333 	QString curIndent("");
   334 	int i;
   335 	BranchObj *bo;  //FIXME-3 still needed?
   336 	BranchItem *cur=NULL;
   337 	BranchItem *prev=NULL;
   338 	cur=model->nextBranch (cur,prev);
   339 	while (cur) 
   340 	{
   341 		bo=(BranchObj*)(cur->getLMO());
   342 
   343 		if (!cur->hasHiddenExportParent() )
   344 		{
   345 			// If necessary, write note
   346 			if (!cur->getNoteObj().isEmpty())
   347 			{
   348 				s =cur->getNoteASCII();
   349 				s=s.replace ("\n","\n"+curIndent);
   350 				ts << ("\""+s+"\",");
   351 			} else
   352 				ts <<"\"\",";
   353 
   354 			// Make indentstring
   355 			for (i=0;i<cur->depth();i++) curIndent+= "\"\",";
   356 
   357 			// Write heading
   358 			ts << curIndent << "\"" << cur->getHeading()<<"\""<<endl;
   359 		}
   360 		
   361 		cur=model->nextBranch(cur,prev);
   362 		curIndent="";
   363 	}
   364 	file.close();
   365 }
   366 
   367 ////////////////////////////////////////////////////////////////////////
   368 void ExportKDE3Bookmarks::doExport() 
   369 {
   370 	WarningDialog dia;
   371 	dia.showCancelButton (true);
   372 	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
   373 	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE 3"));
   374 	dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
   375 	if (dia.exec()==QDialog::Accepted)
   376 	{
   377 		model->exportXML(tmpDir.path(),false);
   378 
   379 		XSLTProc p;
   380 		p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
   381 		p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
   382 		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
   383 		p.process();
   384 
   385 		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
   386 		QProcess *proc= new QProcess ;
   387 		proc->start( ub);
   388 		if (!proc->waitForStarted())
   389 		{
   390 			QMessageBox::warning(0, 
   391 				QObject::tr("Warning"),
   392 				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
   393 		}	
   394 	}
   395 }
   396 
   397 ////////////////////////////////////////////////////////////////////////
   398 void ExportKDE4Bookmarks::doExport() 
   399 {
   400 	WarningDialog dia;
   401 	dia.showCancelButton (true);
   402 	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE 4"));
   403 	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
   404 	dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
   405 	if (dia.exec()==QDialog::Accepted)
   406 	{
   407 		model->exportXML(tmpDir.path(),false);
   408 
   409 		XSLTProc p;
   410 		p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
   411 		p.setOutputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
   412 		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
   413 		p.process();
   414 
   415 		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
   416 		QProcess *proc= new QProcess ;
   417 		proc->start( ub);
   418 		if (!proc->waitForStarted())
   419 		{
   420 			QMessageBox::warning(0, 
   421 				QObject::tr("Warning"),
   422 				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
   423 		}	
   424 	}
   425 }
   426 
   427 ////////////////////////////////////////////////////////////////////////
   428 void ExportFirefoxBookmarks::doExport() 
   429 {
   430 	WarningDialog dia;
   431 	dia.showCancelButton (true);
   432 	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
   433 	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
   434 	dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
   435 	if (dia.exec()==QDialog::Accepted)
   436 	{
   437 		model->exportXML(tmpDir.path(),false);
   438 
   439 /*
   440 		XSLTProc p;
   441 		p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
   442 		p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
   443 		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
   444 		p.process();
   445 
   446 		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
   447 		QProcess *proc = new QProcess( );
   448 		proc->addArgument(ub);
   449 
   450 		if ( !proc->start() ) 
   451 		{
   452 			QMessageBox::warning(0, 
   453 				QObject::tr("Warning"),
   454 				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
   455 		}	
   456 
   457 */
   458 	}
   459 }
   460 
   461 ////////////////////////////////////////////////////////////////////////
   462 void ExportTaskjuggler::doExport() 
   463 {
   464 	model->exportXML(tmpDir.path(),false);
   465 
   466 	XSLTProc p;
   467 	p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
   468 	p.setOutputFile (outputFile);
   469 	p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
   470 	p.process();
   471 }
   472 
   473 ////////////////////////////////////////////////////////////////////////
   474 void ExportLaTeX::doExport() 
   475 {
   476 	// Exports a map to a LaTex file.  
   477 	// This file needs to be included 
   478 	// or inported into a LaTex document
   479 	// it will not add a preamble, or anything 
   480 	// that makes a full LaTex document.
   481   QFile file (outputFile);
   482   if ( !file.open( QIODevice::WriteOnly ) ) {
   483 	QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
   484 	mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
   485     return;
   486   }
   487   QTextStream ts( &file );	// use LANG decoding here...
   488   ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
   489   
   490   // Main loop over all branches
   491   QString s;
   492   // QString curIndent("");
   493   // int i;
   494   BranchObj *bo;
   495   BranchItem *cur=NULL;
   496   BranchItem *prev=NULL;
   497   model->nextBranch(cur,prev);
   498   while (cur) 
   499   {
   500 	bo=(BranchObj*)(cur->getLMO());
   501 
   502 	if (!cur->hasHiddenExportParent() )
   503 	{
   504 		switch (cur->depth() ) 
   505 		{
   506 			case 0: break;
   507 			case 1: 
   508 			  ts << ("\\chapter{" + cur->getHeading()+ "}\n");
   509 			  break;
   510 			case 2: 
   511 			  ts << ("\\section{" + cur->getHeading()+ "}\n");
   512 			  break;
   513 			case 3: 
   514 			  ts << ("\\subsection{" + cur->getHeading()+ "}\n");
   515 			  break;
   516 			case 4: 
   517 			  ts << ("\\subsubsection{" + cur->getHeading()+ "}\n");
   518 			  break;
   519 			default:
   520 			  ts << ("\\paragraph*{" + cur->getHeading()+ "}\n");
   521 			
   522 		}
   523 		// If necessary, write note
   524 		if (!cur->getNoteObj().isEmpty()) {
   525 		  ts << (cur->getNoteASCII());
   526 		  ts << ("\n");
   527 		}
   528 	}
   529     cur=model->nextBranch(cur,prev);
   530    }
   531   file.close();
   532 }
   533 
   534 ////////////////////////////////////////////////////////////////////////
   535 ExportOO::ExportOO()
   536 {
   537 	useSections=false;
   538 }
   539 
   540 ExportOO::~ExportOO()
   541 {
   542 }	
   543 
   544 QString ExportOO::buildList (TreeItem *current)
   545 {
   546     QString r;
   547 
   548     uint i=0;
   549 	BranchItem *bi=current->getFirstBranch();
   550 	if (bi)
   551     {
   552 		if (!bi->hasHiddenExportParent() )	// FIXME-3 use BranchItem...
   553 		{
   554 			// Start list
   555 			r+="<text:list text:style-name=\"vym-list\">\n";
   556 			while (bi)
   557 			{
   558 				r+="<text:list-item><text:p >";
   559 				r+=quotemeta(bi->getHeading());
   560 				// If necessary, write note
   561 				if (!bi->getNoteObj().isEmpty())
   562 					r+=bi->getNoteOpenDoc();
   563 				r+="</text:p>";
   564 				r+=buildList (bi);	// recursivly add deeper branches
   565 				r+="</text:list-item>\n";
   566 				i++;
   567 				bi=current->getBranchNum(i);
   568 			}
   569 			r+="</text:list>\n";
   570 		}
   571     }
   572     return r;
   573 }
   574 
   575 
   576 void ExportOO::exportPresentation()
   577 {
   578 	QString allPages;
   579 
   580 	BranchItem *firstMCO=(BranchItem*)(model->getRootItem()->getFirstBranch());
   581 	if (!firstMCO) 
   582 	{
   583 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("No objects in map!"));
   584 		return;
   585 	}
   586 
   587 	// Insert new content
   588 	// FIXME add extra title in mapinfo for vym 1.13.x
   589 	content.replace ("<!-- INSERT TITLE -->",quotemeta(firstMCO->getHeading()));
   590 	content.replace ("<!-- INSERT AUTHOR -->",quotemeta(model->getAuthor()));
   591 
   592 	QString	onePage;
   593 	QString list;
   594 	
   595 	BranchItem *sectionBI;	
   596     int i=0;
   597 	BranchItem *pagesBI;
   598     int j=0;
   599 
   600 	int mapcenters=model->getRootItem()->branchCount();
   601 
   602 	// useSections already has been set in setConfigFile 
   603 	if (mapcenters>1)	
   604 		sectionBI=firstMCO;
   605 	else
   606 		sectionBI=firstMCO->getFirstBranch();
   607 
   608 	// Walk sections
   609 	while (sectionBI && !sectionBI->hasHiddenExportParent() )
   610 	{
   611 		if (useSections)
   612 		{
   613 			// Add page with section title
   614 			onePage=sectionTemplate;
   615 			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBI->getHeading() ) );
   616 			allPages+=onePage;
   617 			pagesBI=sectionBI->getFirstBranch();
   618 		} else
   619 		{
   620 			//i=-2;	// only use inner loop to 
   621 			        // turn mainbranches into pages
   622 			//sectionBI=firstMCO;
   623 			pagesBI=sectionBI;
   624 		}
   625 
   626 		j=0;
   627 		while (pagesBI && !pagesBI->hasHiddenExportParent() )
   628 		{
   629 			// Add page with list of items
   630 			onePage=pageTemplate;
   631 			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBI->getHeading() ) );
   632 			list=buildList (pagesBI);
   633 			onePage.replace ("<!-- INSERT LIST -->", list);
   634 			allPages+=onePage;
   635 			if (pagesBI!=sectionBI)
   636 			{
   637 				j++;
   638 				pagesBI=((BranchItem*)pagesBI->parent())->getBranchNum(j);
   639 			} else
   640 				pagesBI=NULL;	// We are already iterating over the sectionBIs
   641 		}
   642 		i++;
   643 		if (mapcenters>1 )
   644 			sectionBI=model->getRootItem()->getBranchNum (i);
   645 		else
   646 			sectionBI=firstMCO->getBranchNum (i);
   647 	}
   648 	
   649 	content.replace ("<!-- INSERT PAGES -->",allPages);
   650 
   651 	// Write modified content
   652 	QFile f (contentFile);
   653     if ( !f.open( QIODevice::WriteOnly ) ) 
   654 	{
   655 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
   656 		mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
   657 		return;
   658     }
   659 
   660     QTextStream t( &f );
   661     t << content;
   662     f.close();
   663 
   664 	// zip tmpdir to destination
   665 	zipDir (tmpDir,outputFile);	
   666 }
   667 
   668 bool ExportOO::setConfigFile (const QString &cf)
   669 {
   670 	configFile=cf;
   671 	int i=cf.findRev ("/");
   672 	if (i>=0) configDir=cf.left(i);
   673 	SimpleSettings set;
   674 	set.readSettings(configFile);
   675 
   676 	// set paths
   677 	templateDir=configDir+"/"+set.readEntry ("Template");
   678 
   679 	QDir d (templateDir);
   680 	if (!d.exists())
   681 	{
   682 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
   683 		return false;
   684 
   685 	}
   686 
   687 	contentTemplateFile=templateDir+"content-template.xml";
   688 	contentFile=tmpDir.path()+"/content.xml";
   689 	pageTemplateFile=templateDir+"page-template.xml";
   690 	sectionTemplateFile=templateDir+"section-template.xml";
   691 
   692 	if (set.readEntry("useSections").contains("yes"))
   693 		useSections=true;
   694 
   695 	// Copy template to tmpdir
   696 	system ("cp -r "+templateDir+"* "+tmpDir.path());
   697 
   698 	// Read content-template
   699 	if (!loadStringFromDisk (contentTemplateFile,content))
   700 	{
   701 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
   702 		return false;
   703 	}
   704 
   705 	// Read page-template
   706 	if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
   707 	{
   708 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
   709 		return false;
   710 	}
   711 	
   712 	// Read section-template
   713 	if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
   714 	{
   715 		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));
   716 		return false;
   717 	}
   718 	return true;
   719 }
   720