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