exports.cpp
author insilmaril
Mon, 14 Jan 2008 16:26:59 +0000
changeset 646 371945eb6d31
parent 643 7eb4e5529c82
child 688 d0086df58648
permissions -rw-r--r--
Added french manual by Claude
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@613
   188
				s =curIndent + bo->getNoteASCII( curIndent, 80);
insilmaril@613
   189
				s=s.replace ("\n","\n"+curIndent);
insilmaril@613
   190
				ts << QString (s+"\n");
insilmaril@600
   191
			}
insilmaril@0
   192
		}
insilmaril@643
   193
		bo=model->next(bo);
insilmaril@0
   194
	}
insilmaril@0
   195
	file.close();
insilmaril@0
   196
}
insilmaril@0
   197
insilmaril@613
   198
QString ExportASCII::underline (const QString &text, const QString &line)
insilmaril@613
   199
{
insilmaril@613
   200
	QString r=text + "\n";
insilmaril@613
   201
	for (int j=0;j<text.length();j++) r+=line;
insilmaril@613
   202
	return r;
insilmaril@613
   203
}
insilmaril@613
   204
insilmaril@497
   205
insilmaril@497
   206
////////////////////////////////////////////////////////////////////////
insilmaril@497
   207
void ExportCSV::doExport()
insilmaril@497
   208
{
insilmaril@497
   209
	QFile file (outputFile);
insilmaril@497
   210
	if ( !file.open( QIODevice::WriteOnly ) )
insilmaril@497
   211
	{
insilmaril@497
   212
		qWarning ("ExportBase::exportXML  couldn't open "+outputFile);
insilmaril@497
   213
		return;
insilmaril@497
   214
	}
insilmaril@497
   215
	QTextStream ts( &file );	// use LANG decoding here...
insilmaril@497
   216
insilmaril@497
   217
	// Write header
insilmaril@497
   218
	ts << "\"Note\""  <<endl;
insilmaril@497
   219
insilmaril@497
   220
	// Main loop over all branches
insilmaril@497
   221
	QString s;
insilmaril@613
   222
	QString curIndent("");
insilmaril@512
   223
	int i;
insilmaril@497
   224
	BranchObj *bo;
insilmaril@643
   225
	bo=model->first();
insilmaril@497
   226
	while (bo) 
insilmaril@497
   227
	{
insilmaril@600
   228
		if (!bo->hasHiddenExportParent() )
insilmaril@497
   229
		{
insilmaril@600
   230
			// If necessary, write note
insilmaril@600
   231
			if (!bo->getNote().isEmpty())
insilmaril@600
   232
			{
insilmaril@600
   233
				s =bo->getNoteASCII();
insilmaril@613
   234
				s=s.replace ("\n","\n"+curIndent);
insilmaril@600
   235
				ts << ("\""+s+"\",");
insilmaril@600
   236
			} else
insilmaril@600
   237
				ts <<"\"\",";
insilmaril@497
   238
insilmaril@600
   239
			// Make indentstring
insilmaril@613
   240
			for (i=0;i<bo->getDepth();i++) curIndent+= "\"\",";
insilmaril@497
   241
insilmaril@600
   242
			// Write heading
insilmaril@613
   243
			ts << curIndent << "\"" << bo->getHeading()<<"\""<<endl;
insilmaril@600
   244
		}
insilmaril@497
   245
		
insilmaril@643
   246
		bo=model->next(bo);
insilmaril@613
   247
		curIndent="";
insilmaril@497
   248
	}
insilmaril@497
   249
	file.close();
insilmaril@497
   250
}
insilmaril@497
   251
insilmaril@239
   252
////////////////////////////////////////////////////////////////////////
insilmaril@239
   253
void ExportKDEBookmarks::doExport() 
insilmaril@239
   254
{
insilmaril@643
   255
	MapEditor *me=model->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@643
   290
	MapEditor *me=model->getMapEditor();
insilmaril@311
   291
	if (me)
insilmaril@311
   292
	{
insilmaril@311
   293
		WarningDialog dia;
insilmaril@384
   294
		dia.showCancelButton (true);
insilmaril@311
   295
		dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
insilmaril@311
   296
		dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
insilmaril@311
   297
		dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
insilmaril@311
   298
		if (dia.exec()==QDialog::Accepted)
insilmaril@311
   299
		{
insilmaril@548
   300
			me->exportXML(tmpDir.path(),false);
insilmaril@311
   301
insilmaril@311
   302
/*
insilmaril@311
   303
			XSLTProc p;
insilmaril@311
   304
			p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
insilmaril@311
   305
			p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
insilmaril@311
   306
			p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
insilmaril@311
   307
			p.process();
insilmaril@311
   308
insilmaril@311
   309
			QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
insilmaril@311
   310
			QProcess *proc = new QProcess( );
insilmaril@311
   311
			proc->addArgument(ub);
insilmaril@311
   312
insilmaril@311
   313
			if ( !proc->start() ) 
insilmaril@311
   314
			{
insilmaril@311
   315
				QMessageBox::warning(0, 
insilmaril@311
   316
					QObject::tr("Warning"),
insilmaril@311
   317
					QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
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@311
   326
////////////////////////////////////////////////////////////////////////
insilmaril@228
   327
void ExportTaskjuggler::doExport() 
insilmaril@228
   328
{
insilmaril@643
   329
	MapEditor *me=model->getMapEditor();
insilmaril@228
   330
	if (me)
insilmaril@228
   331
	{
insilmaril@548
   332
		me->exportXML(tmpDir.path(),false);
insilmaril@228
   333
insilmaril@228
   334
		XSLTProc p;
insilmaril@228
   335
		p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
insilmaril@228
   336
		p.setOutputFile (outputFile);
insilmaril@228
   337
		p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
insilmaril@228
   338
		p.process();
insilmaril@228
   339
	}
insilmaril@228
   340
insilmaril@228
   341
}
insilmaril@228
   342
insilmaril@239
   343
////////////////////////////////////////////////////////////////////////
insilmaril@228
   344
void ExportLaTeX::doExport() 
insilmaril@0
   345
{
insilmaril@183
   346
	// Exports a map to a LaTex file.  
insilmaril@183
   347
	// This file needs to be included 
insilmaril@183
   348
	// or inported into a LaTex document
insilmaril@183
   349
	// it will not add a preamble, or anything 
insilmaril@183
   350
	// that makes a full LaTex document.
insilmaril@199
   351
  QFile file (outputFile);
insilmaril@366
   352
  if ( !file.open( QIODevice::WriteOnly ) ) {
insilmaril@205
   353
	QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
insilmaril@205
   354
	mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
insilmaril@163
   355
    return;
insilmaril@163
   356
  }
insilmaril@163
   357
  QTextStream ts( &file );	// use LANG decoding here...
insilmaril@163
   358
  ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
insilmaril@163
   359
  
insilmaril@163
   360
  // Main loop over all branches
insilmaril@163
   361
  QString s;
insilmaril@613
   362
  // QString curIndent("");
insilmaril@163
   363
  // int i;
insilmaril@163
   364
  BranchObj *bo;
insilmaril@643
   365
  bo=model->first();
insilmaril@163
   366
  while (bo) {
insilmaril@600
   367
	if (!bo->hasHiddenExportParent() )
insilmaril@600
   368
	{
insilmaril@600
   369
		if (bo->getDepth()==0);
insilmaril@600
   370
		else if (bo->getDepth()==1) {
insilmaril@600
   371
		  ts << ("\\chapter{" + bo->getHeading()+ "}\n");
insilmaril@600
   372
		}
insilmaril@600
   373
		else if (bo->getDepth()==2) {
insilmaril@600
   374
		  ts << ("\\section{" + bo->getHeading()+ "}\n");
insilmaril@600
   375
		}
insilmaril@600
   376
		else if (bo->getDepth()==3) {
insilmaril@600
   377
		  ts << ("\\subsection{" + bo->getHeading()+ "}\n");
insilmaril@600
   378
		}
insilmaril@600
   379
		else if (bo->getDepth()==4) {
insilmaril@600
   380
		  ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
insilmaril@600
   381
		}
insilmaril@600
   382
		else {
insilmaril@600
   383
		  ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
insilmaril@600
   384
		}
insilmaril@600
   385
		
insilmaril@600
   386
		// If necessary, write note
insilmaril@600
   387
		if (!bo->getNote().isEmpty()) {
insilmaril@600
   388
		  ts << (bo->getNoteASCII());
insilmaril@600
   389
		  ts << ("\n");
insilmaril@600
   390
		}
insilmaril@254
   391
	}
insilmaril@643
   392
    bo=model->next(bo);
insilmaril@163
   393
   }
insilmaril@163
   394
  file.close();
insilmaril@0
   395
}
insilmaril@0
   396
insilmaril@239
   397
////////////////////////////////////////////////////////////////////////
insilmaril@171
   398
ExportOO::ExportOO()
insilmaril@171
   399
{
insilmaril@199
   400
	useSections=false;
insilmaril@171
   401
}
insilmaril@163
   402
insilmaril@171
   403
ExportOO::~ExportOO()
insilmaril@171
   404
{
insilmaril@171
   405
}	
insilmaril@163
   406
insilmaril@171
   407
QString ExportOO::buildList (BranchObj *current)
insilmaril@171
   408
{
insilmaril@171
   409
    QString r;
insilmaril@171
   410
    BranchObj *bo;
insilmaril@183
   411
insilmaril@183
   412
    uint i=0;
insilmaril@171
   413
    bo=current->getFirstBranch();
insilmaril@171
   414
    if (bo)
insilmaril@171
   415
    {
insilmaril@600
   416
		if (!bo->hasHiddenExportParent() )
insilmaril@600
   417
		{
insilmaril@600
   418
			// Start list
insilmaril@600
   419
			r+="<text:list text:style-name=\"vym-list\">\n";
insilmaril@600
   420
			while (bo)
insilmaril@600
   421
			{
insilmaril@600
   422
				r+="<text:list-item><text:p >";
insilmaril@600
   423
				r+=quotemeta(bo->getHeading());
insilmaril@600
   424
				// If necessary, write note
insilmaril@600
   425
				if (!bo->getNote().isEmpty())
insilmaril@600
   426
					r+=bo->getNoteOpenDoc();
insilmaril@600
   427
				r+="</text:p>";
insilmaril@600
   428
				r+=buildList (bo);	// recursivly add deeper branches
insilmaril@600
   429
				r+="</text:list-item>\n";
insilmaril@600
   430
				i++;
insilmaril@600
   431
				bo=current->getBranchNum(i);
insilmaril@600
   432
			}
insilmaril@600
   433
			r+="</text:list>\n";
insilmaril@600
   434
		}
insilmaril@171
   435
    }
insilmaril@171
   436
    return r;
insilmaril@171
   437
}
insilmaril@163
   438
insilmaril@171
   439
insilmaril@171
   440
void ExportOO::exportPresentation()
insilmaril@171
   441
{
insilmaril@183
   442
	QString allPages;
insilmaril@171
   443
insilmaril@643
   444
/* FIXME not adapted to multiple mapCenters yet
insilmaril@163
   445
	// Insert new content
insilmaril@171
   446
	content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
insilmaril@171
   447
	content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
insilmaril@183
   448
insilmaril@183
   449
	QString	onePage;
insilmaril@183
   450
	QString list;
insilmaril@183
   451
	
insilmaril@194
   452
	BranchObj *sectionBO=mapCenter->getFirstBranch();
insilmaril@183
   453
    int i=0;
insilmaril@183
   454
	BranchObj *pagesBO;
insilmaril@183
   455
    int j=0;
insilmaril@183
   456
insilmaril@194
   457
	// Walk sections
insilmaril@600
   458
	while (sectionBO && !sectionBO->hasHiddenExportParent() )
insilmaril@183
   459
	{
insilmaril@194
   460
		if (useSections)
insilmaril@183
   461
		{
insilmaril@194
   462
			// Add page with section title
insilmaril@194
   463
			onePage=sectionTemplate;
insilmaril@194
   464
			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
insilmaril@183
   465
			allPages+=onePage;
insilmaril@183
   466
		} else
insilmaril@183
   467
		{
insilmaril@183
   468
			i=-2;	// only use inner loop to 
insilmaril@183
   469
			        // turn mainbranches into pages
insilmaril@194
   470
			sectionBO=mapCenter;
insilmaril@183
   471
		}
insilmaril@183
   472
insilmaril@183
   473
		// Walk mainpages
insilmaril@194
   474
		pagesBO=sectionBO->getFirstBranch();
insilmaril@183
   475
		j=0;
insilmaril@600
   476
		while (pagesBO && !pagesBO->hasHiddenExportParent() )
insilmaril@183
   477
		{
insilmaril@183
   478
			// Add page with list of items
insilmaril@254
   479
			onePage=pageTemplate;
insilmaril@254
   480
			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
insilmaril@254
   481
			list=buildList (pagesBO);
insilmaril@254
   482
			onePage.replace ("<!-- INSERT LIST -->", list);
insilmaril@254
   483
			allPages+=onePage;
insilmaril@183
   484
			j++;
insilmaril@194
   485
			pagesBO=sectionBO->getBranchNum(j);
insilmaril@183
   486
		}
insilmaril@183
   487
		i++;
insilmaril@194
   488
		sectionBO=mapCenter->getBranchNum(i);
insilmaril@183
   489
	}
insilmaril@183
   490
	
insilmaril@171
   491
	content.replace ("<!-- INSERT PAGES -->",allPages);
insilmaril@171
   492
insilmaril@171
   493
	// Write modified content
insilmaril@171
   494
	QFile f (contentFile);
insilmaril@366
   495
    if ( !f.open( QIODevice::WriteOnly ) ) 
insilmaril@171
   496
	{
insilmaril@205
   497
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
insilmaril@205
   498
		mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
insilmaril@171
   499
		return;
insilmaril@171
   500
    }
insilmaril@171
   501
insilmaril@171
   502
    QTextStream t( &f );
insilmaril@171
   503
    t << content;
insilmaril@171
   504
    f.close();
insilmaril@171
   505
insilmaril@163
   506
	// zip tmpdir to destination
insilmaril@171
   507
	zipDir (tmpDir,outputFile);	
insilmaril@643
   508
*/
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