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