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