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