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