exports.cpp
author insilmaril
Thu, 18 Mar 2010 11:46:52 +0000
changeset 839 fbb927bbdda3
parent 825 1ad892c1a709
child 843 2d36a7bb0867
permissions -rw-r--r--
Version bump to 1.13.1 due to first release of 1.13.0 to openSUSE buildservice
insilmaril@0
     1
#include "exports.h"
insilmaril@750
     2
insilmaril@750
     3
#include "branchitem.h"
insilmaril@171
     4
#include "file.h"
insilmaril@171
     5
#include "linkablemapobj.h"
insilmaril@171
     6
#include "misc.h"
insilmaril@171
     7
#include "mainwindow.h"
insilmaril@311
     8
#include "warningdialog.h"
insilmaril@228
     9
#include "xsltproc.h"
insilmaril@0
    10
insilmaril@824
    11
insilmaril@171
    12
extern Main *mainWindow;
insilmaril@228
    13
extern QDir vymBaseDir;
insilmaril@404
    14
extern QString vymName;
insilmaril@131
    15
insilmaril@171
    16
ExportBase::ExportBase()
insilmaril@0
    17
{
insilmaril@819
    18
	init();
insilmaril@819
    19
}
insilmaril@819
    20
insilmaril@819
    21
ExportBase::ExportBase(VymModel *m)
insilmaril@819
    22
{
insilmaril@819
    23
	init();
insilmaril@819
    24
	model=m;
insilmaril@819
    25
}
insilmaril@819
    26
insilmaril@819
    27
ExportBase::~ExportBase()
insilmaril@819
    28
{
insilmaril@819
    29
	// Cleanup tmpdir
insilmaril@819
    30
	removeDir (tmpDir);
insilmaril@819
    31
}
insilmaril@819
    32
insilmaril@819
    33
void ExportBase::init()
insilmaril@819
    34
{
insilmaril@0
    35
	indentPerDepth="  ";
insilmaril@377
    36
	bool ok;
insilmaril@606
    37
    tmpDir.setPath (makeTmpDir(ok,"vym-export"));
insilmaril@377
    38
	if (!tmpDir.exists() || !ok)
insilmaril@377
    39
		QMessageBox::critical( 0, QObject::tr( "Error" ),
insilmaril@377
    40
					   QObject::tr("Couldn't access temporary directory\n"));
insilmaril@512
    41
	cancelFlag=false;				   
insilmaril@228
    42
}
insilmaril@228
    43
insilmaril@424
    44
void ExportBase::setDir(const QDir &d)
insilmaril@0
    45
{
insilmaril@424
    46
	outDir=d;
insilmaril@199
    47
}
insilmaril@199
    48
insilmaril@199
    49
void ExportBase::setFile (const QString &p)
insilmaril@199
    50
{
insilmaril@199
    51
	outputFile=p;
insilmaril@0
    52
}
insilmaril@0
    53
insilmaril@512
    54
QString ExportBase::getFile ()
insilmaril@512
    55
{
insilmaril@512
    56
	return outputFile;
insilmaril@512
    57
}
insilmaril@512
    58
insilmaril@643
    59
void ExportBase::setModel(VymModel *m)
insilmaril@0
    60
{
insilmaril@643
    61
	model=m;
insilmaril@0
    62
}
insilmaril@0
    63
insilmaril@228
    64
void ExportBase::setCaption (const QString &s)
insilmaril@228
    65
{
insilmaril@228
    66
	caption=s;
insilmaril@228
    67
}
insilmaril@228
    68
insilmaril@228
    69
void ExportBase::addFilter(const QString &s)
insilmaril@228
    70
{
insilmaril@228
    71
	filter=s;
insilmaril@228
    72
}
insilmaril@228
    73
insilmaril@228
    74
bool ExportBase::execDialog()
insilmaril@228
    75
{
insilmaril@228
    76
	{
insilmaril@643
    77
		QFileDialog *fd=new QFileDialog( 0, caption);
insilmaril@366
    78
		fd->setFilter (filter);
insilmaril@228
    79
		fd->setCaption(caption);
insilmaril@228
    80
		fd->setMode( QFileDialog::AnyFile );
insilmaril@424
    81
		fd->setDir (outDir);
insilmaril@228
    82
		fd->show();
insilmaril@228
    83
insilmaril@228
    84
		if ( fd->exec() == QDialog::Accepted )
insilmaril@228
    85
		{
insilmaril@228
    86
			if (QFile (fd->selectedFile()).exists() )
insilmaril@228
    87
			{
insilmaril@404
    88
				QMessageBox mb( vymName,
insilmaril@228
    89
					QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()), 
insilmaril@228
    90
				QMessageBox::Warning,
insilmaril@228
    91
				QMessageBox::Yes | QMessageBox::Default,
insilmaril@228
    92
				QMessageBox::Cancel | QMessageBox::Escape,
insilmaril@366
    93
				Qt::NoButton );
insilmaril@228
    94
				mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
insilmaril@228
    95
				mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
insilmaril@228
    96
				ExportBase ex;
insilmaril@228
    97
				switch( mb.exec() ) 
insilmaril@228
    98
				{
insilmaril@228
    99
					case QMessageBox::Yes:
insilmaril@228
   100
						// save 
insilmaril@228
   101
						break;;
insilmaril@228
   102
					case QMessageBox::Cancel:
insilmaril@512
   103
						cancelFlag=true;
insilmaril@228
   104
						return false;
insilmaril@228
   105
						break;
insilmaril@228
   106
				}
insilmaril@228
   107
			}
insilmaril@228
   108
			outputFile=fd->selectedFile();
insilmaril@512
   109
			cancelFlag=false;
insilmaril@228
   110
			return true;
insilmaril@228
   111
		}
insilmaril@228
   112
	}
insilmaril@228
   113
	return false;
insilmaril@228
   114
}
insilmaril@228
   115
insilmaril@512
   116
bool ExportBase::canceled()
insilmaril@512
   117
{
insilmaril@512
   118
	return cancelFlag;
insilmaril@512
   119
}
insilmaril@512
   120
insilmaril@791
   121
QString ExportBase::getSectionString(TreeItem *start)
insilmaril@163
   122
{
insilmaril@205
   123
	// Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
insilmaril@163
   124
	QString r;
insilmaril@791
   125
	TreeItem *ti=start;
insilmaril@749
   126
	int depth=ti->depth();
insilmaril@163
   127
	while (depth>0)
insilmaril@163
   128
	{
insilmaril@749
   129
		r=QString("%1").arg(1+ti->num(),0,10)+"." + r;
insilmaril@749
   130
		ti=ti->parent(); 
insilmaril@749
   131
		depth=ti->depth();
insilmaril@163
   132
	}	
insilmaril@163
   133
	if (r.isEmpty())
insilmaril@163
   134
		return r;
insilmaril@163
   135
	else	
insilmaril@163
   136
		return r + " ";
insilmaril@163
   137
}
insilmaril@163
   138
insilmaril@239
   139
////////////////////////////////////////////////////////////////////////
insilmaril@807
   140
ExportAO::ExportAO()
insilmaril@807
   141
{
insilmaril@807
   142
	filter="TXT (*.txt)";
insilmaril@807
   143
	caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
insilmaril@807
   144
}
insilmaril@807
   145
insilmaril@807
   146
void ExportAO::doExport()	
insilmaril@807
   147
{
insilmaril@807
   148
	QFile file (outputFile);
insilmaril@807
   149
	if ( !file.open( QIODevice::WriteOnly ) )
insilmaril@807
   150
	{
insilmaril@807
   151
		qWarning ("ExportAO::doExport couldn't open "+outputFile);
insilmaril@807
   152
		return;
insilmaril@807
   153
	}
insilmaril@807
   154
	QTextStream ts( &file );	// use LANG decoding here...
insilmaril@807
   155
insilmaril@807
   156
	// Main loop over all branches
insilmaril@807
   157
	QString s;
insilmaril@807
   158
	QString curIndent;
insilmaril@807
   159
	int i;
insilmaril@807
   160
	BranchItem *cur=NULL;
insilmaril@807
   161
	BranchItem *prev=NULL;
insilmaril@807
   162
insilmaril@807
   163
	QString colString;
insilmaril@807
   164
	QColor col;
insilmaril@807
   165
insilmaril@807
   166
	cur=model->nextBranch (cur,prev);
insilmaril@807
   167
	while (cur) 
insilmaril@807
   168
	{
insilmaril@807
   169
		if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
insilmaril@807
   170
		{
insilmaril@807
   171
			// Make indentstring
insilmaril@807
   172
			curIndent="";
insilmaril@807
   173
			for (i=0;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
insilmaril@807
   174
insilmaril@807
   175
			if (!cur->hasHiddenExportParent() )
insilmaril@807
   176
			{
insilmaril@807
   177
				col=cur->getHeadingColor();
insilmaril@807
   178
				if (col==QColor (255,0,0))
insilmaril@807
   179
					colString="[R]";
insilmaril@807
   180
				else if (col==QColor (217,81,0))
insilmaril@807
   181
					colString="[O]";
insilmaril@807
   182
				else if (col==QColor (0,85,0))
insilmaril@807
   183
					colString="[G]";
insilmaril@807
   184
				else  	
insilmaril@807
   185
					colString="[?]";
insilmaril@807
   186
				switch (cur->depth())
insilmaril@807
   187
				{
insilmaril@807
   188
					case 0:
insilmaril@807
   189
						//ts << underline (cur->getHeading(),QString("="));
insilmaril@807
   190
						//ts << "\n";
insilmaril@807
   191
						break;
insilmaril@807
   192
					case 1:
insilmaril@807
   193
						//ts << "\n";
insilmaril@807
   194
						//ts << (underline ( cur->getHeading(), QString("-") ) );
insilmaril@807
   195
						//ts << "\n";
insilmaril@807
   196
						break;
insilmaril@807
   197
					case 2: // Main heading
insilmaril@807
   198
						ts << "\n";
insilmaril@807
   199
						ts << underline ( cur->getHeading(), QString("=") );
insilmaril@818
   200
						ts << "\n";
insilmaril@807
   201
						break;
insilmaril@807
   202
					case 3: // Achievement, Bonus, Objective ...
insilmaril@818
   203
						ts << "\n\n";
insilmaril@807
   204
						ts << underline ( cur->getHeading(), "-");
insilmaril@807
   205
						ts << "\n\n";
insilmaril@807
   206
						break;
insilmaril@807
   207
					case 4:	// That's the item we need to know
insilmaril@815
   208
						//ts << (curIndent + "* " + colString+" "+ cur->getHeading());
insilmaril@815
   209
						ts << colString+" "+ cur->getHeading();
insilmaril@807
   210
						if (cur->isActiveStandardFlag ("hook-green"))
insilmaril@807
   211
							ts << " [DONE] ";
insilmaril@815
   212
						else	if (cur->isActiveStandardFlag ("wip"))
insilmaril@807
   213
							ts << " [WIP] ";
insilmaril@807
   214
						else	if (cur->isActiveStandardFlag ("cross-red"))
insilmaril@807
   215
							ts << " [NOT STARTED] ";
insilmaril@807
   216
						ts << "\n";
insilmaril@818
   217
						break;
insilmaril@807
   218
					default:
insilmaril@807
   219
						ts << (curIndent + "- " + cur->getHeading());
insilmaril@807
   220
						ts << "\n";
insilmaril@807
   221
						break;
insilmaril@807
   222
				}
insilmaril@807
   223
insilmaril@807
   224
				// If necessary, write note
insilmaril@807
   225
				if (!cur->getNoteObj().isEmpty())
insilmaril@807
   226
				{
insilmaril@807
   227
					curIndent +="  | ";
insilmaril@807
   228
					s=cur->getNoteASCII( curIndent, 80);
insilmaril@807
   229
					ts << s;
insilmaril@807
   230
				}
insilmaril@807
   231
			}
insilmaril@807
   232
		}
insilmaril@807
   233
		cur=model->nextBranch(cur,prev);
insilmaril@807
   234
	}
insilmaril@807
   235
	file.close();
insilmaril@807
   236
}
insilmaril@807
   237
insilmaril@807
   238
QString ExportAO::underline (const QString &text, const QString &line)
insilmaril@807
   239
{
insilmaril@807
   240
	QString r=text + "\n";
insilmaril@807
   241
	for (int j=0;j<text.length();j++) r+=line;
insilmaril@807
   242
	return r;
insilmaril@807
   243
}
insilmaril@807
   244
insilmaril@807
   245
insilmaril@807
   246
////////////////////////////////////////////////////////////////////////
insilmaril@512
   247
ExportASCII::ExportASCII()
insilmaril@512
   248
{
insilmaril@512
   249
	filter="TXT (*.txt)";
insilmaril@512
   250
	caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
insilmaril@512
   251
}
insilmaril@512
   252
insilmaril@777
   253
void ExportASCII::doExport()	
insilmaril@0
   254
{
insilmaril@199
   255
	QFile file (outputFile);
insilmaril@366
   256
	if ( !file.open( QIODevice::WriteOnly ) )
insilmaril@0
   257
	{
insilmaril@807
   258
		qWarning ("ExportASCII::doExport couldn't open "+outputFile);
insilmaril@0
   259
		return;
insilmaril@0
   260
	}
insilmaril@0
   261
	QTextStream ts( &file );	// use LANG decoding here...
insilmaril@0
   262
insilmaril@0
   263
	// Main loop over all branches
insilmaril@0
   264
	QString s;
insilmaril@613
   265
	QString curIndent;
insilmaril@613
   266
	int i;
insilmaril@750
   267
	BranchItem *cur=NULL;
insilmaril@750
   268
	BranchItem *prev=NULL;
insilmaril@741
   269
insilmaril@804
   270
	cur=model->nextBranch (cur,prev);
insilmaril@741
   271
	while (cur) 
insilmaril@0
   272
	{
insilmaril@741
   273
		if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
insilmaril@740
   274
		{
insilmaril@740
   275
			// Make indentstring
insilmaril@740
   276
			curIndent="";
insilmaril@819
   277
			for (i=1;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
insilmaril@740
   278
insilmaril@753
   279
			if (!cur->hasHiddenExportParent() )
insilmaril@600
   280
			{
insilmaril@791
   281
				//std::cout << "ExportASCII::  "<<curIndent.toStdString()<<cur->getHeading().toStdString()<<std::endl;
insilmaril@741
   282
				switch (cur->depth())
insilmaril@740
   283
				{
insilmaril@740
   284
					case 0:
insilmaril@741
   285
						ts << underline (cur->getHeading(),QString("="));
insilmaril@740
   286
						ts << "\n";
insilmaril@740
   287
						break;
insilmaril@740
   288
					case 1:
insilmaril@740
   289
						ts << "\n";
insilmaril@791
   290
						ts << (underline (getSectionString(cur) + cur->getHeading(), QString("-") ) );
insilmaril@740
   291
						ts << "\n";
insilmaril@740
   292
						break;
insilmaril@740
   293
					case 2:
insilmaril@740
   294
						ts << "\n";
insilmaril@741
   295
						ts << (curIndent + "* " + cur->getHeading());
insilmaril@740
   296
						ts << "\n";
insilmaril@740
   297
						break;
insilmaril@740
   298
					case 3:
insilmaril@741
   299
						ts << (curIndent + "- " + cur->getHeading());
insilmaril@740
   300
						ts << "\n";
insilmaril@740
   301
						break;
insilmaril@740
   302
					default:
insilmaril@741
   303
						ts << (curIndent + "- " + cur->getHeading());
insilmaril@740
   304
						ts << "\n";
insilmaril@740
   305
						break;
insilmaril@740
   306
				}
insilmaril@613
   307
insilmaril@740
   308
				// If necessary, write note
insilmaril@746
   309
				if (!cur->getNoteObj().isEmpty())
insilmaril@740
   310
				{
insilmaril@740
   311
					curIndent +="  | ";
insilmaril@746
   312
					s=cur->getNoteASCII( curIndent, 80);
insilmaril@740
   313
					ts << s;
insilmaril@740
   314
				}
insilmaril@600
   315
			}
insilmaril@0
   316
		}
insilmaril@804
   317
		cur=model->nextBranch(cur,prev);
insilmaril@0
   318
	}
insilmaril@0
   319
	file.close();
insilmaril@0
   320
}
insilmaril@0
   321
insilmaril@613
   322
QString ExportASCII::underline (const QString &text, const QString &line)
insilmaril@613
   323
{
insilmaril@613
   324
	QString r=text + "\n";
insilmaril@613
   325
	for (int j=0;j<text.length();j++) r+=line;
insilmaril@613
   326
	return r;
insilmaril@613
   327
}
insilmaril@613
   328
insilmaril@497
   329
insilmaril@497
   330
////////////////////////////////////////////////////////////////////////
insilmaril@497
   331
void ExportCSV::doExport()
insilmaril@497
   332
{
insilmaril@497
   333
	QFile file (outputFile);
insilmaril@497
   334
	if ( !file.open( QIODevice::WriteOnly ) )
insilmaril@497
   335
	{
insilmaril@497
   336
		qWarning ("ExportBase::exportXML  couldn't open "+outputFile);
insilmaril@497
   337
		return;
insilmaril@497
   338
	}
insilmaril@497
   339
	QTextStream ts( &file );	// use LANG decoding here...
insilmaril@497
   340
insilmaril@497
   341
	// Write header
insilmaril@497
   342
	ts << "\"Note\""  <<endl;
insilmaril@497
   343
insilmaril@497
   344
	// Main loop over all branches
insilmaril@497
   345
	QString s;
insilmaril@613
   346
	QString curIndent("");
insilmaril@512
   347
	int i;
insilmaril@750
   348
	BranchItem *cur=NULL;
insilmaril@750
   349
	BranchItem *prev=NULL;
insilmaril@804
   350
	cur=model->nextBranch (cur,prev);
insilmaril@741
   351
	while (cur) 
insilmaril@497
   352
	{
insilmaril@753
   353
		if (!cur->hasHiddenExportParent() )
insilmaril@497
   354
		{
insilmaril@600
   355
			// If necessary, write note
insilmaril@746
   356
			if (!cur->getNoteObj().isEmpty())
insilmaril@600
   357
			{
insilmaril@746
   358
				s =cur->getNoteASCII();
insilmaril@613
   359
				s=s.replace ("\n","\n"+curIndent);
insilmaril@600
   360
				ts << ("\""+s+"\",");
insilmaril@600
   361
			} else
insilmaril@600
   362
				ts <<"\"\",";
insilmaril@497
   363
insilmaril@600
   364
			// Make indentstring
insilmaril@741
   365
			for (i=0;i<cur->depth();i++) curIndent+= "\"\",";
insilmaril@497
   366
insilmaril@600
   367
			// Write heading
insilmaril@741
   368
			ts << curIndent << "\"" << cur->getHeading()<<"\""<<endl;
insilmaril@600
   369
		}
insilmaril@497
   370
		
insilmaril@804
   371
		cur=model->nextBranch(cur,prev);
insilmaril@613
   372
		curIndent="";
insilmaril@497
   373
	}
insilmaril@497
   374
	file.close();
insilmaril@497
   375
}
insilmaril@497
   376
insilmaril@239
   377
////////////////////////////////////////////////////////////////////////
insilmaril@742
   378
void ExportKDE3Bookmarks::doExport() 
insilmaril@239
   379
{
insilmaril@721
   380
	WarningDialog dia;
insilmaril@721
   381
	dia.showCancelButton (true);
insilmaril@721
   382
	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
insilmaril@742
   383
	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE 3"));
insilmaril@742
   384
	dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
insilmaril@742
   385
	if (dia.exec()==QDialog::Accepted)
insilmaril@742
   386
	{
insilmaril@742
   387
		model->exportXML(tmpDir.path(),false);
insilmaril@742
   388
insilmaril@742
   389
		XSLTProc p;
insilmaril@742
   390
		p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
insilmaril@742
   391
		p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
insilmaril@742
   392
		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
insilmaril@742
   393
		p.process();
insilmaril@742
   394
insilmaril@742
   395
		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
insilmaril@742
   396
		QProcess *proc= new QProcess ;
insilmaril@742
   397
		proc->start( ub);
insilmaril@742
   398
		if (!proc->waitForStarted())
insilmaril@742
   399
		{
insilmaril@742
   400
			QMessageBox::warning(0, 
insilmaril@742
   401
				QObject::tr("Warning"),
insilmaril@742
   402
				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
insilmaril@742
   403
		}	
insilmaril@742
   404
	}
insilmaril@742
   405
}
insilmaril@742
   406
insilmaril@742
   407
////////////////////////////////////////////////////////////////////////
insilmaril@742
   408
void ExportKDE4Bookmarks::doExport() 
insilmaril@742
   409
{
insilmaril@742
   410
	WarningDialog dia;
insilmaril@742
   411
	dia.showCancelButton (true);
insilmaril@742
   412
	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE 4"));
insilmaril@721
   413
	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
insilmaril@721
   414
	dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
insilmaril@721
   415
	if (dia.exec()==QDialog::Accepted)
insilmaril@239
   416
	{
insilmaril@721
   417
		model->exportXML(tmpDir.path(),false);
insilmaril@721
   418
insilmaril@721
   419
		XSLTProc p;
insilmaril@721
   420
		p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
insilmaril@742
   421
		p.setOutputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
insilmaril@721
   422
		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
insilmaril@721
   423
		p.process();
insilmaril@721
   424
insilmaril@721
   425
		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
insilmaril@721
   426
		QProcess *proc= new QProcess ;
insilmaril@721
   427
		proc->start( ub);
insilmaril@721
   428
		if (!proc->waitForStarted())
insilmaril@311
   429
		{
insilmaril@721
   430
			QMessageBox::warning(0, 
insilmaril@721
   431
				QObject::tr("Warning"),
insilmaril@721
   432
				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
insilmaril@721
   433
		}	
insilmaril@239
   434
	}
insilmaril@239
   435
}
insilmaril@239
   436
insilmaril@239
   437
////////////////////////////////////////////////////////////////////////
insilmaril@311
   438
void ExportFirefoxBookmarks::doExport() 
insilmaril@311
   439
{
insilmaril@721
   440
	WarningDialog dia;
insilmaril@721
   441
	dia.showCancelButton (true);
insilmaril@721
   442
	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
insilmaril@721
   443
	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
insilmaril@721
   444
	dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
insilmaril@721
   445
	if (dia.exec()==QDialog::Accepted)
insilmaril@311
   446
	{
insilmaril@721
   447
		model->exportXML(tmpDir.path(),false);
insilmaril@311
   448
insilmaril@311
   449
/*
insilmaril@721
   450
		XSLTProc p;
insilmaril@721
   451
		p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
insilmaril@721
   452
		p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
insilmaril@721
   453
		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
insilmaril@721
   454
		p.process();
insilmaril@311
   455
insilmaril@721
   456
		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
insilmaril@721
   457
		QProcess *proc = new QProcess( );
insilmaril@721
   458
		proc->addArgument(ub);
insilmaril@311
   459
insilmaril@721
   460
		if ( !proc->start() ) 
insilmaril@721
   461
		{
insilmaril@721
   462
			QMessageBox::warning(0, 
insilmaril@721
   463
				QObject::tr("Warning"),
insilmaril@721
   464
				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
insilmaril@721
   465
		}	
insilmaril@311
   466
insilmaril@311
   467
*/
insilmaril@311
   468
	}
insilmaril@311
   469
}
insilmaril@311
   470
insilmaril@311
   471
////////////////////////////////////////////////////////////////////////
insilmaril@819
   472
ExportHTML::ExportHTML():ExportBase()
insilmaril@819
   473
{
insilmaril@819
   474
	init();
insilmaril@819
   475
}
insilmaril@819
   476
insilmaril@819
   477
ExportHTML::ExportHTML(VymModel *m):ExportBase(m)
insilmaril@819
   478
{
insilmaril@819
   479
	init();
insilmaril@819
   480
}
insilmaril@819
   481
insilmaril@819
   482
void ExportHTML::init()
insilmaril@819
   483
{
insilmaril@819
   484
	singularDelimiter=": ";
insilmaril@819
   485
	noSingulars=true;	
insilmaril@819
   486
	frameURLs=true;
insilmaril@824
   487
	cssFileName="vym.css";
insilmaril@824
   488
	cssOriginalPath="";	// Is set in VymModel, based on default setting in ExportHTMLDialog
insilmaril@819
   489
insilmaril@819
   490
	if (model &&model->getMapEditor()) 
insilmaril@819
   491
		offset=model->getMapEditor()->getTotalBBox().topLeft();
insilmaril@819
   492
}
insilmaril@819
   493
insilmaril@819
   494
QString ExportHTML::getBranchText(BranchItem *current)
insilmaril@819
   495
{
insilmaril@819
   496
	if (current)
insilmaril@819
   497
	{
insilmaril@819
   498
		bool vis=false;
insilmaril@819
   499
		QRectF hr;
insilmaril@819
   500
		LinkableMapObj *lmo=current->getLMO();
insilmaril@819
   501
		if (lmo)
insilmaril@819
   502
		{
insilmaril@819
   503
			hr=((BranchObj*)lmo)->getBBoxHeading();
insilmaril@819
   504
			if (lmo->isVisibleObj()) vis=true;
insilmaril@819
   505
		}
insilmaril@819
   506
		QString col;
insilmaril@819
   507
		QString id=model->getSelectString(current);
insilmaril@825
   508
		if (dia.useTextColor)
insilmaril@819
   509
			col=QString("style='color:%1'").arg(current->getHeadingColor().name());
insilmaril@819
   510
		QString s=QString("<span class='vym-branch%1' %2 id='%3'>")
insilmaril@819
   511
			.arg(current->depth())
insilmaril@819
   512
			.arg(col)
insilmaril@819
   513
			.arg(id);
insilmaril@819
   514
		QString url=current->getURL();	
insilmaril@819
   515
		if (!url.isEmpty())
insilmaril@819
   516
		{
insilmaril@819
   517
			s+=QString ("<a href=\"%1\">").arg(url);
insilmaril@819
   518
			s+=QString ("<img src=\"flags/flag-url-16x16.png\">%1</a>").arg(quotemeta(current->getHeading()));
insilmaril@819
   519
			s+="</a>";
insilmaril@819
   520
			
insilmaril@823
   521
			QRectF fbox=current->getBBoxURLFlag ();
insilmaril@819
   522
			if (vis)
insilmaril@819
   523
				imageMap+=QString("  <area shape='rect' coords='%1,%2,%3,%4' href='%5'>\n")
insilmaril@819
   524
					.arg(fbox.left()-offset.x())
insilmaril@819
   525
					.arg(fbox.top()-offset.y())
insilmaril@819
   526
					.arg(fbox.right()-offset.x())
insilmaril@819
   527
					.arg(fbox.bottom()-offset.y())
insilmaril@819
   528
					.arg(url);
insilmaril@819
   529
		} else	
insilmaril@819
   530
			s+=quotemeta(current->getHeading());
insilmaril@819
   531
		s+="</span>";
insilmaril@819
   532
insilmaril@825
   533
		if (vis && dia.useImage)
insilmaril@819
   534
			imageMap+=QString("  <area shape='rect' coords='%1,%2,%3,%4' href='#%5'>\n")
insilmaril@819
   535
				.arg(hr.left()-offset.x())
insilmaril@819
   536
				.arg(hr.top()-offset.y())
insilmaril@819
   537
				.arg(hr.right()-offset.x())
insilmaril@819
   538
				.arg(hr.bottom()-offset.y())
insilmaril@819
   539
				.arg(id);
insilmaril@819
   540
insilmaril@819
   541
		// Include note
insilmaril@819
   542
		if (!current->getNoteObj().isEmpty())
insilmaril@819
   543
			s+="<table border=1><tr><td>"+current->getNote()+"</td></tr></table>";
insilmaril@819
   544
insilmaril@819
   545
		return s;
insilmaril@819
   546
	} 
insilmaril@819
   547
	return QString();
insilmaril@819
   548
}
insilmaril@819
   549
insilmaril@819
   550
QString ExportHTML::buildList (BranchItem *current)
insilmaril@819
   551
{
insilmaril@819
   552
    QString r;
insilmaril@819
   553
insilmaril@819
   554
    uint i=0;
insilmaril@819
   555
	BranchItem *bi=current->getFirstBranch();
insilmaril@819
   556
insilmaril@819
   557
	// Only add itemized list, if we have more than one subitem.
insilmaril@819
   558
	// For only one subitem, just add a separator to keep page more compact
insilmaril@819
   559
	bool noSingularsHere=false;
insilmaril@819
   560
	if (current->branchCount()<2 && noSingulars) noSingularsHere=true;
insilmaril@819
   561
insilmaril@819
   562
	if (bi)
insilmaril@819
   563
    {
insilmaril@819
   564
		if (!noSingularsHere)
insilmaril@819
   565
			r+="<ul>\n";
insilmaril@819
   566
		else
insilmaril@819
   567
			r+=singularDelimiter;
insilmaril@819
   568
insilmaril@819
   569
		while (bi)
insilmaril@819
   570
		{
insilmaril@819
   571
			if (!bi->hasHiddenExportParent() )	
insilmaril@819
   572
			{
insilmaril@819
   573
				if (!noSingularsHere) r+="<li>";
insilmaril@819
   574
				r+=getBranchText (bi);
insilmaril@819
   575
				if (!bi->getURL().isEmpty() && frameURLs && noSingularsHere)
insilmaril@819
   576
					// Add frame, if we have subitems to an URL
insilmaril@819
   577
					r+="<table border=1><tr><td>"+buildList (bi)+"</td></tr></table>";	// recursivly add deeper branches
insilmaril@819
   578
				else
insilmaril@819
   579
					r+=buildList (bi);	// recursivly add deeper branches
insilmaril@819
   580
				if (!noSingularsHere) r+="</li>";
insilmaril@819
   581
				r+="\n";
insilmaril@819
   582
			}
insilmaril@819
   583
			i++;
insilmaril@819
   584
			bi=current->getBranchNum(i);
insilmaril@819
   585
		}
insilmaril@819
   586
insilmaril@819
   587
		if (!noSingularsHere) r+="</ul>\n";
insilmaril@819
   588
	}
insilmaril@819
   589
    return r;
insilmaril@819
   590
}
insilmaril@819
   591
insilmaril@824
   592
void ExportHTML::setCSSPath(const QString &p)
insilmaril@824
   593
{
insilmaril@824
   594
	cssOriginalPath=p;
insilmaril@824
   595
}
insilmaril@824
   596
insilmaril@825
   597
void ExportHTML::doExport(bool useDialog) 
insilmaril@819
   598
{
insilmaril@825
   599
	// Execute dialog
insilmaril@825
   600
	dia.setFilePath (model->getFilePath());
insilmaril@825
   601
	dia.setMapName (model->getMapName());
insilmaril@825
   602
	dia.readSettings();
insilmaril@825
   603
	if (useDialog && dia.exec()!=QDialog::Accepted) return;
insilmaril@825
   604
insilmaril@825
   605
	// Check if destination is not empty
insilmaril@825
   606
	QDir d=dia.getDir();
insilmaril@825
   607
	// Check, if warnings should be used before overwriting
insilmaril@825
   608
	// the output directory
insilmaril@825
   609
	if (d.exists() && d.count()>0)
insilmaril@825
   610
	{
insilmaril@825
   611
		WarningDialog warn;
insilmaril@825
   612
		warn.showCancelButton (true);
insilmaril@825
   613
		warn.setText(QString(
insilmaril@825
   614
			"The directory %1 is not empty.\n"
insilmaril@825
   615
			"Do you risk to overwrite some of its contents?").arg(d.path() ));
insilmaril@825
   616
		warn.setCaption("Warning: Directory not empty");
insilmaril@825
   617
		warn.setShowAgainName("mainwindow/export-XML-overwrite-dir");
insilmaril@825
   618
insilmaril@825
   619
		if (warn.exec()!=QDialog::Accepted) 
insilmaril@825
   620
		{
insilmaril@825
   621
			mainWindow->statusMessage(QString(QObject::tr("Export aborted.")));
insilmaril@825
   622
			return;
insilmaril@825
   623
		}
insilmaril@825
   624
	}
insilmaril@825
   625
insilmaril@825
   626
	setFile (d.path()+"/"+model->getMapName()+".html");
insilmaril@825
   627
	setCSSPath( dia.getCSSPath() );
insilmaril@825
   628
insilmaril@825
   629
	// Copy CSS file
insilmaril@824
   630
	QFile css_src (cssOriginalPath);
insilmaril@824
   631
	QFile css_dst (outDir.path()+"/"+cssFileName);
insilmaril@824
   632
	if (!css_src.open ( QIODevice::ReadOnly))
insilmaril@824
   633
		QMessageBox::warning( 0, QObject::tr( "Warning","ExportHTML" ),QObject::tr("Could not open %1","ExportHTML").arg(cssOriginalPath));
insilmaril@824
   634
	else
insilmaril@824
   635
	{
insilmaril@824
   636
		if (!css_dst.open( QIODevice::WriteOnly))
insilmaril@824
   637
			QMessageBox::warning( 0, QObject::tr( "Warning" ), QObject::tr("Could not open %1").arg(css_dst.fileName()));
insilmaril@824
   638
		else
insilmaril@824
   639
		{	
insilmaril@824
   640
		
insilmaril@824
   641
			QTextStream tsout( &css_dst);
insilmaril@824
   642
			QTextStream tsin ( &css_src);
insilmaril@824
   643
			QString s= tsin.read();
insilmaril@824
   644
			tsout << s;
insilmaril@824
   645
			css_dst.close();
insilmaril@824
   646
		}	
insilmaril@824
   647
		css_src.close();
insilmaril@824
   648
	}
insilmaril@824
   649
insilmaril@824
   650
insilmaril@824
   651
insilmaril@824
   652
	// Open file for writing
insilmaril@819
   653
	QFile file (outputFile);
insilmaril@819
   654
	if ( !file.open( QIODevice::WriteOnly ) ) 
insilmaril@819
   655
	{
insilmaril@819
   656
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
insilmaril@819
   657
		mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
insilmaril@819
   658
		return;
insilmaril@819
   659
	}
insilmaril@819
   660
	QTextStream ts( &file );	// use LANG decoding here...
insilmaril@819
   661
	ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
insilmaril@819
   662
insilmaril@825
   663
	// Hide stuff during export
insilmaril@825
   664
	model->setExportMode (true);
insilmaril@825
   665
insilmaril@819
   666
	// Write header
insilmaril@819
   667
	ts<<"<html><title>"+model->getMapName()<<"</title><body>";
insilmaril@824
   668
	ts<<" <link rel='stylesheet' id='css.stylesheet' href='"<<cssFileName<<"' />\n";
insilmaril@819
   669
insilmaril@819
   670
	// Include image
insilmaril@825
   671
	if (dia.useImage)
insilmaril@825
   672
	{
insilmaril@825
   673
		ts<<"<center><img src=\""<<model->getMapName()<<".png\" usemap='#imagemap'></center>\n";
insilmaril@825
   674
		model->exportImage (d.path()+"/"+model->getMapName()+".png",false,"PNG");
insilmaril@825
   675
	}
insilmaril@819
   676
insilmaril@819
   677
	// Main loop over all mapcenters
insilmaril@819
   678
	QString s;
insilmaril@819
   679
	TreeItem *rootItem=model->getRootItem();
insilmaril@819
   680
	BranchItem *bi;
insilmaril@819
   681
	for (int i=0; i<rootItem->branchCount(); i++)
insilmaril@819
   682
	{
insilmaril@819
   683
		bi=rootItem->getBranchNum(i);
insilmaril@819
   684
		if (!bi->hasHiddenExportParent())
insilmaril@819
   685
		{
insilmaril@819
   686
			ts<<getBranchText (bi);
insilmaril@819
   687
			ts<<buildList (bi);
insilmaril@819
   688
		}
insilmaril@819
   689
	}	
insilmaril@819
   690
insilmaril@819
   691
	// Imagemap
insilmaril@819
   692
	ts<<"<map name='imagemap'>\n"+imageMap+"</map>\n";
insilmaril@819
   693
insilmaril@819
   694
	// Write footer 
insilmaril@819
   695
	ts<<"<hr/>\n";
insilmaril@819
   696
	ts<<"<table class=\"vym-footer\">   \n\
insilmaril@819
   697
      <tr> \n\
insilmaril@819
   698
        <td class=\"vym-footerL\">"+model->getFileName()+"</td> \n\
insilmaril@819
   699
        <td class=\"vym-footerC\">"+model->getDate()+"</td> \n\
insilmaril@819
   700
        <td class=\"vym-footerR\"> vym "+model->getVersion()+"</td> \n\
insilmaril@819
   701
      </tr> \n \
insilmaril@819
   702
    </table>\n";
insilmaril@819
   703
	ts<<"</body></html>";
insilmaril@819
   704
	file.close();
insilmaril@825
   705
insilmaril@825
   706
	if (!dia.postscript.isEmpty()) 
insilmaril@825
   707
	{
insilmaril@825
   708
		Process p;
insilmaril@825
   709
		p.runScript (dia.postscript,d.path()+"/"+model->getMapName()+".html");
insilmaril@825
   710
	}
insilmaril@825
   711
insilmaril@825
   712
insilmaril@825
   713
	dia.saveSettings();
insilmaril@825
   714
	model->setExportMode (true);
insilmaril@819
   715
}
insilmaril@819
   716
insilmaril@819
   717
////////////////////////////////////////////////////////////////////////
insilmaril@228
   718
void ExportTaskjuggler::doExport() 
insilmaril@228
   719
{
insilmaril@721
   720
	model->exportXML(tmpDir.path(),false);
insilmaril@228
   721
insilmaril@721
   722
	XSLTProc p;
insilmaril@721
   723
	p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
insilmaril@721
   724
	p.setOutputFile (outputFile);
insilmaril@721
   725
	p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
insilmaril@721
   726
	p.process();
insilmaril@228
   727
}
insilmaril@228
   728
insilmaril@239
   729
////////////////////////////////////////////////////////////////////////
insilmaril@228
   730
void ExportLaTeX::doExport() 
insilmaril@0
   731
{
insilmaril@183
   732
	// Exports a map to a LaTex file.  
insilmaril@183
   733
	// This file needs to be included 
insilmaril@183
   734
	// or inported into a LaTex document
insilmaril@183
   735
	// it will not add a preamble, or anything 
insilmaril@183
   736
	// that makes a full LaTex document.
insilmaril@199
   737
  QFile file (outputFile);
insilmaril@366
   738
  if ( !file.open( QIODevice::WriteOnly ) ) {
insilmaril@205
   739
	QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
insilmaril@205
   740
	mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
insilmaril@163
   741
    return;
insilmaril@163
   742
  }
insilmaril@163
   743
  QTextStream ts( &file );	// use LANG decoding here...
insilmaril@163
   744
  ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
insilmaril@163
   745
  
insilmaril@163
   746
  // Main loop over all branches
insilmaril@163
   747
  QString s;
insilmaril@613
   748
  // QString curIndent("");
insilmaril@163
   749
  // int i;
insilmaril@163
   750
  BranchObj *bo;
insilmaril@750
   751
  BranchItem *cur=NULL;
insilmaril@750
   752
  BranchItem *prev=NULL;
insilmaril@804
   753
  model->nextBranch(cur,prev);
insilmaril@741
   754
  while (cur) 
insilmaril@740
   755
  {
insilmaril@741
   756
	bo=(BranchObj*)(cur->getLMO());
insilmaril@740
   757
insilmaril@753
   758
	if (!cur->hasHiddenExportParent() )
insilmaril@600
   759
	{
insilmaril@741
   760
		switch (cur->depth() ) 
insilmaril@740
   761
		{
insilmaril@740
   762
			case 0: break;
insilmaril@740
   763
			case 1: 
insilmaril@753
   764
			  ts << ("\\chapter{" + cur->getHeading()+ "}\n");
insilmaril@740
   765
			  break;
insilmaril@740
   766
			case 2: 
insilmaril@753
   767
			  ts << ("\\section{" + cur->getHeading()+ "}\n");
insilmaril@740
   768
			  break;
insilmaril@740
   769
			case 3: 
insilmaril@753
   770
			  ts << ("\\subsection{" + cur->getHeading()+ "}\n");
insilmaril@740
   771
			  break;
insilmaril@740
   772
			case 4: 
insilmaril@753
   773
			  ts << ("\\subsubsection{" + cur->getHeading()+ "}\n");
insilmaril@740
   774
			  break;
insilmaril@740
   775
			default:
insilmaril@753
   776
			  ts << ("\\paragraph*{" + cur->getHeading()+ "}\n");
insilmaril@740
   777
			
insilmaril@600
   778
		}
insilmaril@600
   779
		// If necessary, write note
insilmaril@746
   780
		if (!cur->getNoteObj().isEmpty()) {
insilmaril@746
   781
		  ts << (cur->getNoteASCII());
insilmaril@600
   782
		  ts << ("\n");
insilmaril@600
   783
		}
insilmaril@254
   784
	}
insilmaril@804
   785
    cur=model->nextBranch(cur,prev);
insilmaril@163
   786
   }
insilmaril@163
   787
  file.close();
insilmaril@0
   788
}
insilmaril@0
   789
insilmaril@239
   790
////////////////////////////////////////////////////////////////////////
insilmaril@171
   791
ExportOO::ExportOO()
insilmaril@171
   792
{
insilmaril@199
   793
	useSections=false;
insilmaril@171
   794
}
insilmaril@163
   795
insilmaril@171
   796
ExportOO::~ExportOO()
insilmaril@171
   797
{
insilmaril@171
   798
}	
insilmaril@163
   799
insilmaril@750
   800
QString ExportOO::buildList (TreeItem *current)
insilmaril@171
   801
{
insilmaril@171
   802
    QString r;
insilmaril@183
   803
insilmaril@183
   804
    uint i=0;
insilmaril@750
   805
	BranchItem *bi=current->getFirstBranch();
insilmaril@750
   806
	if (bi)
insilmaril@171
   807
    {
insilmaril@819
   808
		// Start list
insilmaril@819
   809
		r+="<text:list text:style-name=\"vym-list\">\n";
insilmaril@819
   810
		while (bi)
insilmaril@600
   811
		{
insilmaril@819
   812
			if (!bi->hasHiddenExportParent() )	
insilmaril@600
   813
			{
insilmaril@600
   814
				r+="<text:list-item><text:p >";
insilmaril@750
   815
				r+=quotemeta(bi->getHeading());
insilmaril@600
   816
				// If necessary, write note
insilmaril@750
   817
				if (!bi->getNoteObj().isEmpty())
insilmaril@750
   818
					r+=bi->getNoteOpenDoc();
insilmaril@600
   819
				r+="</text:p>";
insilmaril@750
   820
				r+=buildList (bi);	// recursivly add deeper branches
insilmaril@600
   821
				r+="</text:list-item>\n";
insilmaril@600
   822
			}
insilmaril@819
   823
			i++;
insilmaril@819
   824
			bi=current->getBranchNum(i);
insilmaril@600
   825
		}
insilmaril@819
   826
		r+="</text:list>\n";
insilmaril@171
   827
    }
insilmaril@171
   828
    return r;
insilmaril@171
   829
}
insilmaril@163
   830
insilmaril@171
   831
insilmaril@171
   832
void ExportOO::exportPresentation()
insilmaril@171
   833
{
insilmaril@183
   834
	QString allPages;
insilmaril@171
   835
insilmaril@804
   836
	BranchItem *firstMCO=(BranchItem*)(model->getRootItem()->getFirstBranch());
insilmaril@804
   837
	if (!firstMCO) 
insilmaril@804
   838
	{
insilmaril@804
   839
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("No objects in map!"));
insilmaril@804
   840
		return;
insilmaril@804
   841
	}
insilmaril@804
   842
insilmaril@163
   843
	// Insert new content
insilmaril@804
   844
	// FIXME add extra title in mapinfo for vym 1.13.x
insilmaril@804
   845
	content.replace ("<!-- INSERT TITLE -->",quotemeta(firstMCO->getHeading()));
insilmaril@804
   846
	content.replace ("<!-- INSERT AUTHOR -->",quotemeta(model->getAuthor()));
insilmaril@183
   847
insilmaril@183
   848
	QString	onePage;
insilmaril@183
   849
	QString list;
insilmaril@183
   850
	
insilmaril@804
   851
	BranchItem *sectionBI;	
insilmaril@183
   852
    int i=0;
insilmaril@804
   853
	BranchItem *pagesBI;
insilmaril@183
   854
    int j=0;
insilmaril@183
   855
insilmaril@804
   856
	int mapcenters=model->getRootItem()->branchCount();
insilmaril@804
   857
insilmaril@804
   858
	// useSections already has been set in setConfigFile 
insilmaril@804
   859
	if (mapcenters>1)	
insilmaril@804
   860
		sectionBI=firstMCO;
insilmaril@804
   861
	else
insilmaril@804
   862
		sectionBI=firstMCO->getFirstBranch();
insilmaril@804
   863
insilmaril@194
   864
	// Walk sections
insilmaril@804
   865
	while (sectionBI && !sectionBI->hasHiddenExportParent() )
insilmaril@183
   866
	{
insilmaril@194
   867
		if (useSections)
insilmaril@183
   868
		{
insilmaril@194
   869
			// Add page with section title
insilmaril@194
   870
			onePage=sectionTemplate;
insilmaril@804
   871
			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBI->getHeading() ) );
insilmaril@183
   872
			allPages+=onePage;
insilmaril@804
   873
			pagesBI=sectionBI->getFirstBranch();
insilmaril@183
   874
		} else
insilmaril@183
   875
		{
insilmaril@804
   876
			//i=-2;	// only use inner loop to 
insilmaril@183
   877
			        // turn mainbranches into pages
insilmaril@804
   878
			//sectionBI=firstMCO;
insilmaril@804
   879
			pagesBI=sectionBI;
insilmaril@183
   880
		}
insilmaril@183
   881
insilmaril@183
   882
		j=0;
insilmaril@804
   883
		while (pagesBI && !pagesBI->hasHiddenExportParent() )
insilmaril@183
   884
		{
insilmaril@183
   885
			// Add page with list of items
insilmaril@254
   886
			onePage=pageTemplate;
insilmaril@804
   887
			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBI->getHeading() ) );
insilmaril@804
   888
			list=buildList (pagesBI);
insilmaril@254
   889
			onePage.replace ("<!-- INSERT LIST -->", list);
insilmaril@254
   890
			allPages+=onePage;
insilmaril@804
   891
			if (pagesBI!=sectionBI)
insilmaril@804
   892
			{
insilmaril@804
   893
				j++;
insilmaril@804
   894
				pagesBI=((BranchItem*)pagesBI->parent())->getBranchNum(j);
insilmaril@804
   895
			} else
insilmaril@804
   896
				pagesBI=NULL;	// We are already iterating over the sectionBIs
insilmaril@183
   897
		}
insilmaril@183
   898
		i++;
insilmaril@804
   899
		if (mapcenters>1 )
insilmaril@804
   900
			sectionBI=model->getRootItem()->getBranchNum (i);
insilmaril@804
   901
		else
insilmaril@804
   902
			sectionBI=firstMCO->getBranchNum (i);
insilmaril@183
   903
	}
insilmaril@183
   904
	
insilmaril@171
   905
	content.replace ("<!-- INSERT PAGES -->",allPages);
insilmaril@171
   906
insilmaril@171
   907
	// Write modified content
insilmaril@171
   908
	QFile f (contentFile);
insilmaril@366
   909
    if ( !f.open( QIODevice::WriteOnly ) ) 
insilmaril@171
   910
	{
insilmaril@205
   911
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
insilmaril@205
   912
		mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
insilmaril@171
   913
		return;
insilmaril@171
   914
    }
insilmaril@171
   915
insilmaril@171
   916
    QTextStream t( &f );
insilmaril@171
   917
    t << content;
insilmaril@171
   918
    f.close();
insilmaril@171
   919
insilmaril@163
   920
	// zip tmpdir to destination
insilmaril@171
   921
	zipDir (tmpDir,outputFile);	
insilmaril@163
   922
}
insilmaril@163
   923
insilmaril@194
   924
bool ExportOO::setConfigFile (const QString &cf)
insilmaril@183
   925
{
insilmaril@183
   926
	configFile=cf;
insilmaril@183
   927
	int i=cf.findRev ("/");
insilmaril@183
   928
	if (i>=0) configDir=cf.left(i);
insilmaril@183
   929
	SimpleSettings set;
insilmaril@183
   930
	set.readSettings(configFile);
insilmaril@183
   931
insilmaril@183
   932
	// set paths
insilmaril@183
   933
	templateDir=configDir+"/"+set.readEntry ("Template");
insilmaril@183
   934
insilmaril@194
   935
	QDir d (templateDir);
insilmaril@194
   936
	if (!d.exists())
insilmaril@194
   937
	{
insilmaril@194
   938
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
insilmaril@194
   939
		return false;
insilmaril@194
   940
insilmaril@194
   941
	}
insilmaril@183
   942
insilmaril@183
   943
	contentTemplateFile=templateDir+"content-template.xml";
insilmaril@183
   944
	contentFile=tmpDir.path()+"/content.xml";
insilmaril@183
   945
	pageTemplateFile=templateDir+"page-template.xml";
insilmaril@194
   946
	sectionTemplateFile=templateDir+"section-template.xml";
insilmaril@183
   947
insilmaril@199
   948
	if (set.readEntry("useSections").contains("yes"))
insilmaril@199
   949
		useSections=true;
insilmaril@199
   950
insilmaril@183
   951
	// Copy template to tmpdir
insilmaril@183
   952
	system ("cp -r "+templateDir+"* "+tmpDir.path());
insilmaril@183
   953
insilmaril@183
   954
	// Read content-template
insilmaril@183
   955
	if (!loadStringFromDisk (contentTemplateFile,content))
insilmaril@183
   956
	{
insilmaril@194
   957
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
insilmaril@194
   958
		return false;
insilmaril@183
   959
	}
insilmaril@183
   960
insilmaril@183
   961
	// Read page-template
insilmaril@183
   962
	if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
insilmaril@183
   963
	{
insilmaril@194
   964
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
insilmaril@194
   965
		return false;
insilmaril@183
   966
	}
insilmaril@183
   967
	
insilmaril@194
   968
	// Read section-template
insilmaril@201
   969
	if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
insilmaril@183
   970
	{
insilmaril@194
   971
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));
insilmaril@194
   972
		return false;
insilmaril@183
   973
	}
insilmaril@194
   974
	return true;
insilmaril@183
   975
}
insilmaril@183
   976