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