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