exports.cpp
author insilmaril
Mon, 18 Jun 2007 15:10:18 +0000
changeset 505 244e309b4047
parent 497 ab118b86bc54
child 512 96680eb33a79
permissions -rw-r--r--
1.8.73 - beta testing
insilmaril@0
     1
#include "exports.h"
insilmaril@171
     2
#include "file.h"
insilmaril@171
     3
#include "linkablemapobj.h"
insilmaril@171
     4
#include "misc.h"
insilmaril@171
     5
#include "mainwindow.h"
insilmaril@311
     6
#include "warningdialog.h"
insilmaril@228
     7
#include "xsltproc.h"
insilmaril@0
     8
insilmaril@171
     9
extern Main *mainWindow;
insilmaril@228
    10
extern QDir vymBaseDir;
insilmaril@404
    11
extern QString vymName;
insilmaril@131
    12
insilmaril@171
    13
ExportBase::ExportBase()
insilmaril@0
    14
{
insilmaril@0
    15
	indentPerDepth="  ";
insilmaril@377
    16
	bool ok;
insilmaril@393
    17
    tmpDir.setPath (makeUniqueDir(ok,"/tmp/vym-export-XXXXXX"));
insilmaril@377
    18
	if (!tmpDir.exists() || !ok)
insilmaril@377
    19
		QMessageBox::critical( 0, QObject::tr( "Error" ),
insilmaril@377
    20
					   QObject::tr("Couldn't access temporary directory\n"));
insilmaril@228
    21
}
insilmaril@228
    22
insilmaril@228
    23
ExportBase::~ExportBase()
insilmaril@228
    24
{
insilmaril@377
    25
	// Cleanup tmpdir
insilmaril@228
    26
	removeDir (tmpDir);
insilmaril@0
    27
}
insilmaril@0
    28
insilmaril@424
    29
void ExportBase::setDir(const QDir &d)
insilmaril@0
    30
{
insilmaril@424
    31
	outDir=d;
insilmaril@199
    32
}
insilmaril@199
    33
insilmaril@199
    34
void ExportBase::setFile (const QString &p)
insilmaril@199
    35
{
insilmaril@199
    36
	outputFile=p;
insilmaril@0
    37
}
insilmaril@0
    38
insilmaril@171
    39
void ExportBase::setMapCenter(MapCenterObj *mc)
insilmaril@0
    40
{
insilmaril@0
    41
	mapCenter=mc;
insilmaril@0
    42
}
insilmaril@0
    43
insilmaril@228
    44
void ExportBase::setCaption (const QString &s)
insilmaril@228
    45
{
insilmaril@228
    46
	caption=s;
insilmaril@228
    47
}
insilmaril@228
    48
insilmaril@228
    49
void ExportBase::addFilter(const QString &s)
insilmaril@228
    50
{
insilmaril@228
    51
	filter=s;
insilmaril@228
    52
}
insilmaril@228
    53
insilmaril@228
    54
bool ExportBase::execDialog()
insilmaril@228
    55
{
insilmaril@228
    56
	if (mapCenter && mapCenter->getMapEditor())
insilmaril@228
    57
	{
insilmaril@228
    58
		QFileDialog *fd=new QFileDialog( mapCenter->getMapEditor(), caption);
insilmaril@366
    59
		fd->setFilter (filter);
insilmaril@228
    60
		fd->setCaption(caption);
insilmaril@228
    61
		fd->setMode( QFileDialog::AnyFile );
insilmaril@424
    62
		fd->setDir (outDir);
insilmaril@228
    63
		fd->show();
insilmaril@228
    64
insilmaril@228
    65
		if ( fd->exec() == QDialog::Accepted )
insilmaril@228
    66
		{
insilmaril@228
    67
			if (QFile (fd->selectedFile()).exists() )
insilmaril@228
    68
			{
insilmaril@404
    69
				QMessageBox mb( vymName,
insilmaril@228
    70
					QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()), 
insilmaril@228
    71
				QMessageBox::Warning,
insilmaril@228
    72
				QMessageBox::Yes | QMessageBox::Default,
insilmaril@228
    73
				QMessageBox::Cancel | QMessageBox::Escape,
insilmaril@366
    74
				Qt::NoButton );
insilmaril@228
    75
				mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
insilmaril@228
    76
				mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
insilmaril@228
    77
				ExportBase ex;
insilmaril@228
    78
				switch( mb.exec() ) 
insilmaril@228
    79
				{
insilmaril@228
    80
					case QMessageBox::Yes:
insilmaril@228
    81
						// save 
insilmaril@228
    82
						break;;
insilmaril@228
    83
					case QMessageBox::Cancel:
insilmaril@228
    84
						// return, do nothing
insilmaril@228
    85
						return false;
insilmaril@228
    86
						break;
insilmaril@228
    87
				}
insilmaril@228
    88
			}
insilmaril@228
    89
			outputFile=fd->selectedFile();
insilmaril@228
    90
			return true;
insilmaril@228
    91
		}
insilmaril@228
    92
	}
insilmaril@228
    93
	return false;
insilmaril@228
    94
}
insilmaril@228
    95
insilmaril@171
    96
QString ExportBase::getSectionString(BranchObj *bostart)
insilmaril@163
    97
{
insilmaril@205
    98
	// Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
insilmaril@163
    99
	QString r;
insilmaril@163
   100
	BranchObj *bo=bostart;
insilmaril@163
   101
	int depth=bo->getDepth();
insilmaril@163
   102
	while (depth>0)
insilmaril@163
   103
	{
insilmaril@163
   104
		r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
insilmaril@163
   105
		bo=(BranchObj*)(bo->getParObj());
insilmaril@163
   106
		depth=bo->getDepth();
insilmaril@163
   107
	}	
insilmaril@163
   108
	if (r.isEmpty())
insilmaril@163
   109
		return r;
insilmaril@163
   110
	else	
insilmaril@163
   111
		return r + " ";
insilmaril@163
   112
}
insilmaril@163
   113
insilmaril@239
   114
////////////////////////////////////////////////////////////////////////
insilmaril@228
   115
void ExportASCII::doExport()
insilmaril@0
   116
{
insilmaril@199
   117
	QFile file (outputFile);
insilmaril@366
   118
	if ( !file.open( QIODevice::WriteOnly ) )
insilmaril@0
   119
	{
insilmaril@228
   120
		qWarning ("ExportBase::exportXML  couldn't open "+outputFile);
insilmaril@0
   121
		return;
insilmaril@0
   122
	}
insilmaril@0
   123
	QTextStream ts( &file );	// use LANG decoding here...
insilmaril@0
   124
insilmaril@0
   125
	// Main loop over all branches
insilmaril@0
   126
	QString s;
insilmaril@0
   127
	QString actIndent("");
insilmaril@366
   128
	int i,j;
insilmaril@0
   129
	BranchObj *bo;
insilmaril@0
   130
	bo=mapCenter->first();
insilmaril@0
   131
	while (bo) 
insilmaril@0
   132
	{
insilmaril@254
   133
		// Make indentstring
insilmaril@254
   134
		for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
insilmaril@254
   135
insilmaril@254
   136
		if (bo->getDepth()==0)
insilmaril@239
   137
		{
insilmaril@254
   138
			ts << (bo->getHeading()+ "\n");
insilmaril@254
   139
			for (j=0;j<bo->getHeading().length();j++) ts<<"=";
insilmaril@254
   140
			ts << "\n";
insilmaril@254
   141
		} else 	if (bo->getDepth()==1)
insilmaril@254
   142
			ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
insilmaril@254
   143
		else	if (bo->getDepth()==2)
insilmaril@440
   144
			ts << (actIndent + " * " + bo->getHeading()+ "\n");
insilmaril@440
   145
		else	if (bo->getDepth()==3)
insilmaril@254
   146
			ts << (actIndent + " o " + bo->getHeading()+ "\n");
insilmaril@254
   147
		else	
insilmaril@254
   148
			ts << (actIndent + " - " + bo->getHeading()+ "\n");
insilmaril@254
   149
		
insilmaril@254
   150
		// If necessary, write note
insilmaril@254
   151
		if (!bo->getNote().isEmpty())
insilmaril@254
   152
		{
insilmaril@254
   153
			s =bo->getNoteASCII();
insilmaril@254
   154
			s=s.replace ("\n","\n"+actIndent);
insilmaril@254
   155
			ts << (s+"\n\n");
insilmaril@0
   156
		}
insilmaril@0
   157
		bo=bo->next();
insilmaril@0
   158
		actIndent="";
insilmaril@0
   159
	}
insilmaril@0
   160
	file.close();
insilmaril@0
   161
}
insilmaril@0
   162
insilmaril@497
   163
insilmaril@497
   164
////////////////////////////////////////////////////////////////////////
insilmaril@497
   165
void ExportCSV::doExport()
insilmaril@497
   166
{
insilmaril@497
   167
	QFile file (outputFile);
insilmaril@497
   168
	if ( !file.open( QIODevice::WriteOnly ) )
insilmaril@497
   169
	{
insilmaril@497
   170
		qWarning ("ExportBase::exportXML  couldn't open "+outputFile);
insilmaril@497
   171
		return;
insilmaril@497
   172
	}
insilmaril@497
   173
	QTextStream ts( &file );	// use LANG decoding here...
insilmaril@497
   174
insilmaril@497
   175
	// Write header
insilmaril@497
   176
	ts << "\"Note\""  <<endl;
insilmaril@497
   177
insilmaril@497
   178
	// Main loop over all branches
insilmaril@497
   179
	QString s;
insilmaril@497
   180
	QString actIndent("");
insilmaril@497
   181
	int i,j;
insilmaril@497
   182
	BranchObj *bo;
insilmaril@497
   183
	bo=mapCenter->first();
insilmaril@497
   184
	while (bo) 
insilmaril@497
   185
	{
insilmaril@497
   186
		// If necessary, write note
insilmaril@497
   187
		if (!bo->getNote().isEmpty())
insilmaril@497
   188
		{
insilmaril@497
   189
			s =bo->getNoteASCII();
insilmaril@497
   190
			s=s.replace ("\n","\n"+actIndent);
insilmaril@497
   191
			ts << ("\""+s+"\",");
insilmaril@497
   192
		} else
insilmaril@497
   193
			ts <<"\"\",";
insilmaril@497
   194
insilmaril@497
   195
		// Make indentstring
insilmaril@497
   196
		for (i=0;i<bo->getDepth();i++) actIndent+= "\"\",";
insilmaril@497
   197
insilmaril@497
   198
		// Write heading
insilmaril@497
   199
		ts << actIndent << "\"" << bo->getHeading()<<"\""<<endl;
insilmaril@497
   200
		
insilmaril@497
   201
		bo=bo->next();
insilmaril@497
   202
		actIndent="";
insilmaril@497
   203
	}
insilmaril@497
   204
	file.close();
insilmaril@497
   205
}
insilmaril@497
   206
insilmaril@239
   207
////////////////////////////////////////////////////////////////////////
insilmaril@239
   208
void ExportKDEBookmarks::doExport() 
insilmaril@239
   209
{
insilmaril@239
   210
	MapEditor *me=NULL;
insilmaril@239
   211
	if (mapCenter) me=mapCenter->getMapEditor();
insilmaril@239
   212
	if (me)
insilmaril@239
   213
	{
insilmaril@311
   214
		WarningDialog dia;
insilmaril@384
   215
		dia.showCancelButton (true);
insilmaril@311
   216
		dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
insilmaril@311
   217
		dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
insilmaril@432
   218
		dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
insilmaril@311
   219
		if (dia.exec()==QDialog::Accepted)
insilmaril@311
   220
		{
insilmaril@311
   221
			me->exportXML(tmpDir.path());
insilmaril@239
   222
insilmaril@311
   223
			XSLTProc p;
insilmaril@311
   224
			p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
insilmaril@311
   225
			p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
insilmaril@311
   226
			p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
insilmaril@311
   227
			p.process();
insilmaril@311
   228
insilmaril@311
   229
			QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
insilmaril@377
   230
			QProcess *proc= new QProcess ;
insilmaril@366
   231
			proc->start( ub);
insilmaril@377
   232
			if (!proc->waitForStarted())
insilmaril@311
   233
			{
insilmaril@311
   234
				QMessageBox::warning(0, 
insilmaril@311
   235
					QObject::tr("Warning"),
insilmaril@311
   236
					QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
insilmaril@311
   237
			}	
insilmaril@311
   238
		}
insilmaril@239
   239
	}
insilmaril@239
   240
insilmaril@239
   241
}
insilmaril@239
   242
insilmaril@239
   243
////////////////////////////////////////////////////////////////////////
insilmaril@311
   244
void ExportFirefoxBookmarks::doExport() 
insilmaril@311
   245
{
insilmaril@311
   246
	MapEditor *me=NULL;
insilmaril@311
   247
	if (mapCenter) me=mapCenter->getMapEditor();
insilmaril@311
   248
	if (me)
insilmaril@311
   249
	{
insilmaril@311
   250
		WarningDialog dia;
insilmaril@384
   251
		dia.showCancelButton (true);
insilmaril@311
   252
		dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
insilmaril@311
   253
		dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
insilmaril@311
   254
		dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
insilmaril@311
   255
		if (dia.exec()==QDialog::Accepted)
insilmaril@311
   256
		{
insilmaril@311
   257
			me->exportXML(tmpDir.path());
insilmaril@311
   258
insilmaril@311
   259
/*
insilmaril@311
   260
			XSLTProc p;
insilmaril@311
   261
			p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
insilmaril@311
   262
			p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
insilmaril@311
   263
			p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
insilmaril@311
   264
			p.process();
insilmaril@311
   265
insilmaril@311
   266
			QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
insilmaril@311
   267
			QProcess *proc = new QProcess( );
insilmaril@311
   268
			proc->addArgument(ub);
insilmaril@311
   269
insilmaril@311
   270
			if ( !proc->start() ) 
insilmaril@311
   271
			{
insilmaril@311
   272
				QMessageBox::warning(0, 
insilmaril@311
   273
					QObject::tr("Warning"),
insilmaril@311
   274
					QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
insilmaril@311
   275
			}	
insilmaril@311
   276
insilmaril@311
   277
*/
insilmaril@311
   278
insilmaril@311
   279
		}
insilmaril@311
   280
	}
insilmaril@311
   281
}
insilmaril@311
   282
insilmaril@311
   283
////////////////////////////////////////////////////////////////////////
insilmaril@228
   284
void ExportTaskjuggler::doExport() 
insilmaril@228
   285
{
insilmaril@228
   286
	MapEditor *me=NULL;
insilmaril@228
   287
	if (mapCenter) me=mapCenter->getMapEditor();
insilmaril@228
   288
	if (me)
insilmaril@228
   289
	{
insilmaril@228
   290
		me->exportXML(tmpDir.path());
insilmaril@228
   291
insilmaril@228
   292
		XSLTProc p;
insilmaril@228
   293
		p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
insilmaril@228
   294
		p.setOutputFile (outputFile);
insilmaril@228
   295
		p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
insilmaril@228
   296
		p.process();
insilmaril@228
   297
	}
insilmaril@228
   298
insilmaril@228
   299
}
insilmaril@228
   300
insilmaril@239
   301
////////////////////////////////////////////////////////////////////////
insilmaril@228
   302
void ExportLaTeX::doExport() 
insilmaril@0
   303
{
insilmaril@183
   304
	// Exports a map to a LaTex file.  
insilmaril@183
   305
	// This file needs to be included 
insilmaril@183
   306
	// or inported into a LaTex document
insilmaril@183
   307
	// it will not add a preamble, or anything 
insilmaril@183
   308
	// that makes a full LaTex document.
insilmaril@199
   309
  QFile file (outputFile);
insilmaril@366
   310
  if ( !file.open( QIODevice::WriteOnly ) ) {
insilmaril@205
   311
	QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
insilmaril@205
   312
	mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
insilmaril@163
   313
    return;
insilmaril@163
   314
  }
insilmaril@163
   315
  QTextStream ts( &file );	// use LANG decoding here...
insilmaril@163
   316
  ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
insilmaril@163
   317
  
insilmaril@163
   318
  // Main loop over all branches
insilmaril@163
   319
  QString s;
insilmaril@163
   320
  // QString actIndent("");
insilmaril@163
   321
  // int i;
insilmaril@163
   322
  BranchObj *bo;
insilmaril@163
   323
  bo=mapCenter->first();
insilmaril@163
   324
  while (bo) {
insilmaril@254
   325
	if (bo->getDepth()==0);
insilmaril@254
   326
	else if (bo->getDepth()==1) {
insilmaril@254
   327
	  ts << ("\\chapter{" + bo->getHeading()+ "}\n");
insilmaril@254
   328
	}
insilmaril@254
   329
	else if (bo->getDepth()==2) {
insilmaril@254
   330
	  ts << ("\\section{" + bo->getHeading()+ "}\n");
insilmaril@254
   331
	}
insilmaril@254
   332
	else if (bo->getDepth()==3) {
insilmaril@254
   333
	  ts << ("\\subsection{" + bo->getHeading()+ "}\n");
insilmaril@254
   334
	}
insilmaril@254
   335
	else if (bo->getDepth()==4) {
insilmaril@254
   336
	  ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
insilmaril@254
   337
	}
insilmaril@254
   338
	else {
insilmaril@254
   339
	  ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
insilmaril@254
   340
	}
insilmaril@254
   341
	
insilmaril@254
   342
	// If necessary, write note
insilmaril@254
   343
	if (!bo->getNote().isEmpty()) {
insilmaril@254
   344
	  ts << (bo->getNoteASCII());
insilmaril@254
   345
	  ts << ("\n");
insilmaril@254
   346
	}
insilmaril@163
   347
    bo=bo->next();
insilmaril@163
   348
   }
insilmaril@163
   349
  file.close();
insilmaril@0
   350
}
insilmaril@0
   351
insilmaril@239
   352
////////////////////////////////////////////////////////////////////////
insilmaril@171
   353
ExportOO::ExportOO()
insilmaril@171
   354
{
insilmaril@199
   355
	useSections=false;
insilmaril@171
   356
}
insilmaril@163
   357
insilmaril@171
   358
ExportOO::~ExportOO()
insilmaril@171
   359
{
insilmaril@171
   360
}	
insilmaril@163
   361
insilmaril@171
   362
QString ExportOO::buildList (BranchObj *current)
insilmaril@171
   363
{
insilmaril@171
   364
    QString r;
insilmaril@171
   365
    BranchObj *bo;
insilmaril@183
   366
insilmaril@183
   367
    uint i=0;
insilmaril@171
   368
    bo=current->getFirstBranch();
insilmaril@171
   369
    if (bo)
insilmaril@171
   370
    {
insilmaril@171
   371
        // Start list
insilmaril@234
   372
        r+="<text:list text:style-name=\"vym-list\">\n";
insilmaril@171
   373
        while (bo)
insilmaril@171
   374
        {
insilmaril@254
   375
			r+="<text:list-item><text:p >";
insilmaril@254
   376
			r+=quotemeta(bo->getHeading());
insilmaril@254
   377
			// If necessary, write note
insilmaril@254
   378
			if (!bo->getNote().isEmpty())
insilmaril@254
   379
				r+=bo->getNoteOpenDoc();
insilmaril@254
   380
			r+="</text:p>";
insilmaril@254
   381
			r+=buildList (bo);	// recursivly add deeper branches
insilmaril@254
   382
			r+="</text:list-item>\n";
insilmaril@183
   383
			i++;
insilmaril@183
   384
			bo=current->getBranchNum(i);
insilmaril@171
   385
        }
insilmaril@171
   386
        r+="</text:list>\n";
insilmaril@171
   387
    }
insilmaril@171
   388
    return r;
insilmaril@171
   389
}
insilmaril@163
   390
insilmaril@171
   391
insilmaril@171
   392
void ExportOO::exportPresentation()
insilmaril@171
   393
{
insilmaril@183
   394
	QString allPages;
insilmaril@171
   395
insilmaril@163
   396
	// Insert new content
insilmaril@171
   397
	content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
insilmaril@171
   398
	content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
insilmaril@183
   399
insilmaril@183
   400
	QString	onePage;
insilmaril@183
   401
	QString list;
insilmaril@183
   402
	
insilmaril@194
   403
	BranchObj *sectionBO=mapCenter->getFirstBranch();
insilmaril@183
   404
    int i=0;
insilmaril@183
   405
	BranchObj *pagesBO;
insilmaril@183
   406
    int j=0;
insilmaril@183
   407
insilmaril@194
   408
	// Walk sections
insilmaril@194
   409
	while (sectionBO)
insilmaril@183
   410
	{
insilmaril@194
   411
		if (useSections)
insilmaril@183
   412
		{
insilmaril@194
   413
			// Add page with section title
insilmaril@194
   414
			onePage=sectionTemplate;
insilmaril@194
   415
			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
insilmaril@183
   416
			allPages+=onePage;
insilmaril@183
   417
		} else
insilmaril@183
   418
		{
insilmaril@183
   419
			i=-2;	// only use inner loop to 
insilmaril@183
   420
			        // turn mainbranches into pages
insilmaril@194
   421
			sectionBO=mapCenter;
insilmaril@183
   422
		}
insilmaril@183
   423
insilmaril@183
   424
		// Walk mainpages
insilmaril@194
   425
		pagesBO=sectionBO->getFirstBranch();
insilmaril@183
   426
		j=0;
insilmaril@183
   427
		while (pagesBO)
insilmaril@183
   428
		{
insilmaril@183
   429
			// Add page with list of items
insilmaril@254
   430
			onePage=pageTemplate;
insilmaril@254
   431
			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
insilmaril@254
   432
			list=buildList (pagesBO);
insilmaril@254
   433
			onePage.replace ("<!-- INSERT LIST -->", list);
insilmaril@254
   434
			allPages+=onePage;
insilmaril@183
   435
			j++;
insilmaril@194
   436
			pagesBO=sectionBO->getBranchNum(j);
insilmaril@183
   437
		}
insilmaril@183
   438
		i++;
insilmaril@194
   439
		sectionBO=mapCenter->getBranchNum(i);
insilmaril@183
   440
	}
insilmaril@183
   441
	
insilmaril@171
   442
	content.replace ("<!-- INSERT PAGES -->",allPages);
insilmaril@171
   443
insilmaril@171
   444
	// Write modified content
insilmaril@171
   445
	QFile f (contentFile);
insilmaril@366
   446
    if ( !f.open( QIODevice::WriteOnly ) ) 
insilmaril@171
   447
	{
insilmaril@205
   448
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
insilmaril@205
   449
		mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
insilmaril@171
   450
		return;
insilmaril@171
   451
    }
insilmaril@171
   452
insilmaril@171
   453
    QTextStream t( &f );
insilmaril@171
   454
    t << content;
insilmaril@171
   455
    f.close();
insilmaril@171
   456
insilmaril@163
   457
	// zip tmpdir to destination
insilmaril@171
   458
	zipDir (tmpDir,outputFile);	
insilmaril@163
   459
}
insilmaril@163
   460
insilmaril@194
   461
bool ExportOO::setConfigFile (const QString &cf)
insilmaril@183
   462
{
insilmaril@183
   463
	configFile=cf;
insilmaril@183
   464
	int i=cf.findRev ("/");
insilmaril@183
   465
	if (i>=0) configDir=cf.left(i);
insilmaril@183
   466
	SimpleSettings set;
insilmaril@183
   467
	set.readSettings(configFile);
insilmaril@183
   468
insilmaril@183
   469
	// set paths
insilmaril@183
   470
	templateDir=configDir+"/"+set.readEntry ("Template");
insilmaril@183
   471
insilmaril@194
   472
	QDir d (templateDir);
insilmaril@194
   473
	if (!d.exists())
insilmaril@194
   474
	{
insilmaril@194
   475
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
insilmaril@194
   476
		return false;
insilmaril@194
   477
insilmaril@194
   478
	}
insilmaril@183
   479
insilmaril@183
   480
	contentTemplateFile=templateDir+"content-template.xml";
insilmaril@183
   481
	contentFile=tmpDir.path()+"/content.xml";
insilmaril@183
   482
	pageTemplateFile=templateDir+"page-template.xml";
insilmaril@194
   483
	sectionTemplateFile=templateDir+"section-template.xml";
insilmaril@183
   484
insilmaril@199
   485
	if (set.readEntry("useSections").contains("yes"))
insilmaril@199
   486
		useSections=true;
insilmaril@199
   487
insilmaril@183
   488
	// Copy template to tmpdir
insilmaril@183
   489
	system ("cp -r "+templateDir+"* "+tmpDir.path());
insilmaril@183
   490
insilmaril@183
   491
	// Read content-template
insilmaril@183
   492
	if (!loadStringFromDisk (contentTemplateFile,content))
insilmaril@183
   493
	{
insilmaril@194
   494
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
insilmaril@194
   495
		return false;
insilmaril@183
   496
	}
insilmaril@183
   497
insilmaril@183
   498
	// Read page-template
insilmaril@183
   499
	if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
insilmaril@183
   500
	{
insilmaril@194
   501
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
insilmaril@194
   502
		return false;
insilmaril@183
   503
	}
insilmaril@183
   504
	
insilmaril@194
   505
	// Read section-template
insilmaril@201
   506
	if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
insilmaril@183
   507
	{
insilmaril@194
   508
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));
insilmaril@194
   509
		return false;
insilmaril@183
   510
	}
insilmaril@194
   511
	return true;
insilmaril@183
   512
}
insilmaril@183
   513