exports.cpp
author insilmaril
Tue Oct 16 09:53:22 2007 +0000 (2007-10-16)
changeset 601 54475d6f006a
parent 548 37fd6e3a38f1
child 606 84c73902f727
permissions -rw-r--r--
included <typeinfo>
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@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@0
   145
	QString actIndent("");
insilmaril@366
   146
	int i,j;
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@254
   152
		for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
insilmaril@254
   153
insilmaril@600
   154
		if (!bo->hasHiddenExportParent() )
insilmaril@239
   155
		{
insilmaril@600
   156
			if (bo->getDepth()==0)
insilmaril@600
   157
			{
insilmaril@600
   158
				ts << (bo->getHeading()+ "\n");
insilmaril@600
   159
				for (j=0;j<bo->getHeading().length();j++) ts<<"=";
insilmaril@600
   160
				ts << "\n";
insilmaril@600
   161
			} else 	if (bo->getDepth()==1)
insilmaril@600
   162
				ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
insilmaril@600
   163
			else	if (bo->getDepth()==2)
insilmaril@600
   164
				ts << (actIndent + " * " + bo->getHeading()+ "\n");
insilmaril@600
   165
			else	if (bo->getDepth()==3)
insilmaril@600
   166
				ts << (actIndent + " o " + bo->getHeading()+ "\n");
insilmaril@600
   167
			else	
insilmaril@600
   168
				ts << (actIndent + " - " + bo->getHeading()+ "\n");
insilmaril@600
   169
			
insilmaril@600
   170
			// If necessary, write note
insilmaril@600
   171
			if (!bo->getNote().isEmpty())
insilmaril@600
   172
			{
insilmaril@600
   173
				s =bo->getNoteASCII();
insilmaril@600
   174
				s=s.replace ("\n","\n"+actIndent);
insilmaril@600
   175
				ts << (s+"\n\n");
insilmaril@600
   176
			}
insilmaril@0
   177
		}
insilmaril@0
   178
		bo=bo->next();
insilmaril@0
   179
		actIndent="";
insilmaril@0
   180
	}
insilmaril@0
   181
	file.close();
insilmaril@0
   182
}
insilmaril@0
   183
insilmaril@497
   184
insilmaril@497
   185
////////////////////////////////////////////////////////////////////////
insilmaril@497
   186
void ExportCSV::doExport()
insilmaril@497
   187
{
insilmaril@497
   188
	QFile file (outputFile);
insilmaril@497
   189
	if ( !file.open( QIODevice::WriteOnly ) )
insilmaril@497
   190
	{
insilmaril@497
   191
		qWarning ("ExportBase::exportXML  couldn't open "+outputFile);
insilmaril@497
   192
		return;
insilmaril@497
   193
	}
insilmaril@497
   194
	QTextStream ts( &file );	// use LANG decoding here...
insilmaril@497
   195
insilmaril@497
   196
	// Write header
insilmaril@497
   197
	ts << "\"Note\""  <<endl;
insilmaril@497
   198
insilmaril@497
   199
	// Main loop over all branches
insilmaril@497
   200
	QString s;
insilmaril@497
   201
	QString actIndent("");
insilmaril@512
   202
	int i;
insilmaril@497
   203
	BranchObj *bo;
insilmaril@497
   204
	bo=mapCenter->first();
insilmaril@497
   205
	while (bo) 
insilmaril@497
   206
	{
insilmaril@600
   207
		if (!bo->hasHiddenExportParent() )
insilmaril@497
   208
		{
insilmaril@600
   209
			// If necessary, write note
insilmaril@600
   210
			if (!bo->getNote().isEmpty())
insilmaril@600
   211
			{
insilmaril@600
   212
				s =bo->getNoteASCII();
insilmaril@600
   213
				s=s.replace ("\n","\n"+actIndent);
insilmaril@600
   214
				ts << ("\""+s+"\",");
insilmaril@600
   215
			} else
insilmaril@600
   216
				ts <<"\"\",";
insilmaril@497
   217
insilmaril@600
   218
			// Make indentstring
insilmaril@600
   219
			for (i=0;i<bo->getDepth();i++) actIndent+= "\"\",";
insilmaril@497
   220
insilmaril@600
   221
			// Write heading
insilmaril@600
   222
			ts << actIndent << "\"" << bo->getHeading()<<"\""<<endl;
insilmaril@600
   223
		}
insilmaril@497
   224
		
insilmaril@497
   225
		bo=bo->next();
insilmaril@497
   226
		actIndent="";
insilmaril@497
   227
	}
insilmaril@497
   228
	file.close();
insilmaril@497
   229
}
insilmaril@497
   230
insilmaril@239
   231
////////////////////////////////////////////////////////////////////////
insilmaril@239
   232
void ExportKDEBookmarks::doExport() 
insilmaril@239
   233
{
insilmaril@239
   234
	MapEditor *me=NULL;
insilmaril@239
   235
	if (mapCenter) me=mapCenter->getMapEditor();
insilmaril@239
   236
	if (me)
insilmaril@239
   237
	{
insilmaril@311
   238
		WarningDialog dia;
insilmaril@384
   239
		dia.showCancelButton (true);
insilmaril@311
   240
		dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
insilmaril@311
   241
		dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
insilmaril@432
   242
		dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
insilmaril@311
   243
		if (dia.exec()==QDialog::Accepted)
insilmaril@311
   244
		{
insilmaril@548
   245
			me->exportXML(tmpDir.path(),false);
insilmaril@239
   246
insilmaril@311
   247
			XSLTProc p;
insilmaril@311
   248
			p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
insilmaril@311
   249
			p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
insilmaril@311
   250
			p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
insilmaril@311
   251
			p.process();
insilmaril@311
   252
insilmaril@311
   253
			QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
insilmaril@377
   254
			QProcess *proc= new QProcess ;
insilmaril@366
   255
			proc->start( ub);
insilmaril@377
   256
			if (!proc->waitForStarted())
insilmaril@311
   257
			{
insilmaril@311
   258
				QMessageBox::warning(0, 
insilmaril@311
   259
					QObject::tr("Warning"),
insilmaril@311
   260
					QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
insilmaril@311
   261
			}	
insilmaril@311
   262
		}
insilmaril@239
   263
	}
insilmaril@239
   264
insilmaril@239
   265
}
insilmaril@239
   266
insilmaril@239
   267
////////////////////////////////////////////////////////////////////////
insilmaril@311
   268
void ExportFirefoxBookmarks::doExport() 
insilmaril@311
   269
{
insilmaril@311
   270
	MapEditor *me=NULL;
insilmaril@311
   271
	if (mapCenter) me=mapCenter->getMapEditor();
insilmaril@311
   272
	if (me)
insilmaril@311
   273
	{
insilmaril@311
   274
		WarningDialog dia;
insilmaril@384
   275
		dia.showCancelButton (true);
insilmaril@311
   276
		dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
insilmaril@311
   277
		dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
insilmaril@311
   278
		dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
insilmaril@311
   279
		if (dia.exec()==QDialog::Accepted)
insilmaril@311
   280
		{
insilmaril@548
   281
			me->exportXML(tmpDir.path(),false);
insilmaril@311
   282
insilmaril@311
   283
/*
insilmaril@311
   284
			XSLTProc p;
insilmaril@311
   285
			p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
insilmaril@311
   286
			p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
insilmaril@311
   287
			p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
insilmaril@311
   288
			p.process();
insilmaril@311
   289
insilmaril@311
   290
			QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
insilmaril@311
   291
			QProcess *proc = new QProcess( );
insilmaril@311
   292
			proc->addArgument(ub);
insilmaril@311
   293
insilmaril@311
   294
			if ( !proc->start() ) 
insilmaril@311
   295
			{
insilmaril@311
   296
				QMessageBox::warning(0, 
insilmaril@311
   297
					QObject::tr("Warning"),
insilmaril@311
   298
					QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
insilmaril@311
   299
			}	
insilmaril@311
   300
insilmaril@311
   301
*/
insilmaril@311
   302
insilmaril@311
   303
		}
insilmaril@311
   304
	}
insilmaril@311
   305
}
insilmaril@311
   306
insilmaril@311
   307
////////////////////////////////////////////////////////////////////////
insilmaril@228
   308
void ExportTaskjuggler::doExport() 
insilmaril@228
   309
{
insilmaril@228
   310
	MapEditor *me=NULL;
insilmaril@228
   311
	if (mapCenter) me=mapCenter->getMapEditor();
insilmaril@228
   312
	if (me)
insilmaril@228
   313
	{
insilmaril@548
   314
		me->exportXML(tmpDir.path(),false);
insilmaril@228
   315
insilmaril@228
   316
		XSLTProc p;
insilmaril@228
   317
		p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
insilmaril@228
   318
		p.setOutputFile (outputFile);
insilmaril@228
   319
		p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
insilmaril@228
   320
		p.process();
insilmaril@228
   321
	}
insilmaril@228
   322
insilmaril@228
   323
}
insilmaril@228
   324
insilmaril@239
   325
////////////////////////////////////////////////////////////////////////
insilmaril@228
   326
void ExportLaTeX::doExport() 
insilmaril@0
   327
{
insilmaril@183
   328
	// Exports a map to a LaTex file.  
insilmaril@183
   329
	// This file needs to be included 
insilmaril@183
   330
	// or inported into a LaTex document
insilmaril@183
   331
	// it will not add a preamble, or anything 
insilmaril@183
   332
	// that makes a full LaTex document.
insilmaril@199
   333
  QFile file (outputFile);
insilmaril@366
   334
  if ( !file.open( QIODevice::WriteOnly ) ) {
insilmaril@205
   335
	QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
insilmaril@205
   336
	mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
insilmaril@163
   337
    return;
insilmaril@163
   338
  }
insilmaril@163
   339
  QTextStream ts( &file );	// use LANG decoding here...
insilmaril@163
   340
  ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
insilmaril@163
   341
  
insilmaril@163
   342
  // Main loop over all branches
insilmaril@163
   343
  QString s;
insilmaril@163
   344
  // QString actIndent("");
insilmaril@163
   345
  // int i;
insilmaril@163
   346
  BranchObj *bo;
insilmaril@163
   347
  bo=mapCenter->first();
insilmaril@163
   348
  while (bo) {
insilmaril@600
   349
	if (!bo->hasHiddenExportParent() )
insilmaril@600
   350
	{
insilmaril@600
   351
		if (bo->getDepth()==0);
insilmaril@600
   352
		else if (bo->getDepth()==1) {
insilmaril@600
   353
		  ts << ("\\chapter{" + bo->getHeading()+ "}\n");
insilmaril@600
   354
		}
insilmaril@600
   355
		else if (bo->getDepth()==2) {
insilmaril@600
   356
		  ts << ("\\section{" + bo->getHeading()+ "}\n");
insilmaril@600
   357
		}
insilmaril@600
   358
		else if (bo->getDepth()==3) {
insilmaril@600
   359
		  ts << ("\\subsection{" + bo->getHeading()+ "}\n");
insilmaril@600
   360
		}
insilmaril@600
   361
		else if (bo->getDepth()==4) {
insilmaril@600
   362
		  ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
insilmaril@600
   363
		}
insilmaril@600
   364
		else {
insilmaril@600
   365
		  ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
insilmaril@600
   366
		}
insilmaril@600
   367
		
insilmaril@600
   368
		// If necessary, write note
insilmaril@600
   369
		if (!bo->getNote().isEmpty()) {
insilmaril@600
   370
		  ts << (bo->getNoteASCII());
insilmaril@600
   371
		  ts << ("\n");
insilmaril@600
   372
		}
insilmaril@254
   373
	}
insilmaril@163
   374
    bo=bo->next();
insilmaril@163
   375
   }
insilmaril@163
   376
  file.close();
insilmaril@0
   377
}
insilmaril@0
   378
insilmaril@239
   379
////////////////////////////////////////////////////////////////////////
insilmaril@171
   380
ExportOO::ExportOO()
insilmaril@171
   381
{
insilmaril@199
   382
	useSections=false;
insilmaril@171
   383
}
insilmaril@163
   384
insilmaril@171
   385
ExportOO::~ExportOO()
insilmaril@171
   386
{
insilmaril@171
   387
}	
insilmaril@163
   388
insilmaril@171
   389
QString ExportOO::buildList (BranchObj *current)
insilmaril@171
   390
{
insilmaril@171
   391
    QString r;
insilmaril@171
   392
    BranchObj *bo;
insilmaril@183
   393
insilmaril@183
   394
    uint i=0;
insilmaril@171
   395
    bo=current->getFirstBranch();
insilmaril@171
   396
    if (bo)
insilmaril@171
   397
    {
insilmaril@600
   398
		if (!bo->hasHiddenExportParent() )
insilmaril@600
   399
		{
insilmaril@600
   400
			// Start list
insilmaril@600
   401
			r+="<text:list text:style-name=\"vym-list\">\n";
insilmaril@600
   402
			while (bo)
insilmaril@600
   403
			{
insilmaril@600
   404
				r+="<text:list-item><text:p >";
insilmaril@600
   405
				r+=quotemeta(bo->getHeading());
insilmaril@600
   406
				// If necessary, write note
insilmaril@600
   407
				if (!bo->getNote().isEmpty())
insilmaril@600
   408
					r+=bo->getNoteOpenDoc();
insilmaril@600
   409
				r+="</text:p>";
insilmaril@600
   410
				r+=buildList (bo);	// recursivly add deeper branches
insilmaril@600
   411
				r+="</text:list-item>\n";
insilmaril@600
   412
				i++;
insilmaril@600
   413
				bo=current->getBranchNum(i);
insilmaril@600
   414
			}
insilmaril@600
   415
			r+="</text:list>\n";
insilmaril@600
   416
		}
insilmaril@171
   417
    }
insilmaril@171
   418
    return r;
insilmaril@171
   419
}
insilmaril@163
   420
insilmaril@171
   421
insilmaril@171
   422
void ExportOO::exportPresentation()
insilmaril@171
   423
{
insilmaril@183
   424
	QString allPages;
insilmaril@171
   425
insilmaril@163
   426
	// Insert new content
insilmaril@171
   427
	content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
insilmaril@171
   428
	content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
insilmaril@183
   429
insilmaril@183
   430
	QString	onePage;
insilmaril@183
   431
	QString list;
insilmaril@183
   432
	
insilmaril@194
   433
	BranchObj *sectionBO=mapCenter->getFirstBranch();
insilmaril@183
   434
    int i=0;
insilmaril@183
   435
	BranchObj *pagesBO;
insilmaril@183
   436
    int j=0;
insilmaril@183
   437
insilmaril@194
   438
	// Walk sections
insilmaril@600
   439
	while (sectionBO && !sectionBO->hasHiddenExportParent() )
insilmaril@183
   440
	{
insilmaril@194
   441
		if (useSections)
insilmaril@183
   442
		{
insilmaril@194
   443
			// Add page with section title
insilmaril@194
   444
			onePage=sectionTemplate;
insilmaril@194
   445
			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
insilmaril@183
   446
			allPages+=onePage;
insilmaril@183
   447
		} else
insilmaril@183
   448
		{
insilmaril@183
   449
			i=-2;	// only use inner loop to 
insilmaril@183
   450
			        // turn mainbranches into pages
insilmaril@194
   451
			sectionBO=mapCenter;
insilmaril@183
   452
		}
insilmaril@183
   453
insilmaril@183
   454
		// Walk mainpages
insilmaril@194
   455
		pagesBO=sectionBO->getFirstBranch();
insilmaril@183
   456
		j=0;
insilmaril@600
   457
		while (pagesBO && !pagesBO->hasHiddenExportParent() )
insilmaril@183
   458
		{
insilmaril@183
   459
			// Add page with list of items
insilmaril@254
   460
			onePage=pageTemplate;
insilmaril@254
   461
			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
insilmaril@254
   462
			list=buildList (pagesBO);
insilmaril@254
   463
			onePage.replace ("<!-- INSERT LIST -->", list);
insilmaril@254
   464
			allPages+=onePage;
insilmaril@183
   465
			j++;
insilmaril@194
   466
			pagesBO=sectionBO->getBranchNum(j);
insilmaril@183
   467
		}
insilmaril@183
   468
		i++;
insilmaril@194
   469
		sectionBO=mapCenter->getBranchNum(i);
insilmaril@183
   470
	}
insilmaril@183
   471
	
insilmaril@171
   472
	content.replace ("<!-- INSERT PAGES -->",allPages);
insilmaril@171
   473
insilmaril@171
   474
	// Write modified content
insilmaril@171
   475
	QFile f (contentFile);
insilmaril@366
   476
    if ( !f.open( QIODevice::WriteOnly ) ) 
insilmaril@171
   477
	{
insilmaril@205
   478
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
insilmaril@205
   479
		mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
insilmaril@171
   480
		return;
insilmaril@171
   481
    }
insilmaril@171
   482
insilmaril@171
   483
    QTextStream t( &f );
insilmaril@171
   484
    t << content;
insilmaril@171
   485
    f.close();
insilmaril@171
   486
insilmaril@163
   487
	// zip tmpdir to destination
insilmaril@171
   488
	zipDir (tmpDir,outputFile);	
insilmaril@163
   489
}
insilmaril@163
   490
insilmaril@194
   491
bool ExportOO::setConfigFile (const QString &cf)
insilmaril@183
   492
{
insilmaril@183
   493
	configFile=cf;
insilmaril@183
   494
	int i=cf.findRev ("/");
insilmaril@183
   495
	if (i>=0) configDir=cf.left(i);
insilmaril@183
   496
	SimpleSettings set;
insilmaril@183
   497
	set.readSettings(configFile);
insilmaril@183
   498
insilmaril@183
   499
	// set paths
insilmaril@183
   500
	templateDir=configDir+"/"+set.readEntry ("Template");
insilmaril@183
   501
insilmaril@194
   502
	QDir d (templateDir);
insilmaril@194
   503
	if (!d.exists())
insilmaril@194
   504
	{
insilmaril@194
   505
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
insilmaril@194
   506
		return false;
insilmaril@194
   507
insilmaril@194
   508
	}
insilmaril@183
   509
insilmaril@183
   510
	contentTemplateFile=templateDir+"content-template.xml";
insilmaril@183
   511
	contentFile=tmpDir.path()+"/content.xml";
insilmaril@183
   512
	pageTemplateFile=templateDir+"page-template.xml";
insilmaril@194
   513
	sectionTemplateFile=templateDir+"section-template.xml";
insilmaril@183
   514
insilmaril@199
   515
	if (set.readEntry("useSections").contains("yes"))
insilmaril@199
   516
		useSections=true;
insilmaril@199
   517
insilmaril@183
   518
	// Copy template to tmpdir
insilmaril@183
   519
	system ("cp -r "+templateDir+"* "+tmpDir.path());
insilmaril@183
   520
insilmaril@183
   521
	// Read content-template
insilmaril@183
   522
	if (!loadStringFromDisk (contentTemplateFile,content))
insilmaril@183
   523
	{
insilmaril@194
   524
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
insilmaril@194
   525
		return false;
insilmaril@183
   526
	}
insilmaril@183
   527
insilmaril@183
   528
	// Read page-template
insilmaril@183
   529
	if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
insilmaril@183
   530
	{
insilmaril@194
   531
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
insilmaril@194
   532
		return false;
insilmaril@183
   533
	}
insilmaril@183
   534
	
insilmaril@194
   535
	// Read section-template
insilmaril@201
   536
	if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
insilmaril@183
   537
	{
insilmaril@194
   538
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));
insilmaril@194
   539
		return false;
insilmaril@183
   540
	}
insilmaril@194
   541
	return true;
insilmaril@183
   542
}
insilmaril@183
   543