exports.cpp
author insilmaril
Thu May 07 08:48:53 2009 +0000 (2009-05-07)
changeset 766 7a71a914afdb
parent 750 ff3b01ce0960
child 773 340bc29da9a0
permissions -rw-r--r--
Started to reanimate flags
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@171
   109
QString ExportBase::getSectionString(BranchObj *bostart)
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@749
   113
	TreeItem *ti=bostart->getTreeItem();
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@746
   134
void ExportASCII::doExport()	//FIXME-1 segfaults...
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
	int d;
insilmaril@741
   151
insilmaril@753
   152
	BranchObj *bo;	//FIXME-3 still needed?
insilmaril@741
   153
	cur=model->next (cur,prev,d);
insilmaril@741
   154
	while (cur) 
insilmaril@0
   155
	{
insilmaril@741
   156
		if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
insilmaril@740
   157
		{
insilmaril@741
   158
			bo=(BranchObj*)(cur->getLMO());
insilmaril@741
   159
			std::cout << "ExportASCII::  "<<cur->getHeading().toStdString()<<std::endl;
insilmaril@254
   160
insilmaril@740
   161
			// Make indentstring
insilmaril@740
   162
			curIndent="";
insilmaril@741
   163
			for (i=0;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
insilmaril@740
   164
insilmaril@753
   165
			if (!cur->hasHiddenExportParent() )
insilmaril@600
   166
			{
insilmaril@741
   167
				switch (cur->depth())
insilmaril@740
   168
				{
insilmaril@740
   169
					case 0:
insilmaril@741
   170
						ts << underline (cur->getHeading(),QString("="));
insilmaril@740
   171
						ts << "\n";
insilmaril@740
   172
						break;
insilmaril@740
   173
					case 1:
insilmaril@740
   174
						ts << "\n";
insilmaril@741
   175
						ts << (underline (getSectionString(bo) + cur->getHeading(), QString("-") ) );
insilmaril@740
   176
						ts << "\n";
insilmaril@740
   177
						break;
insilmaril@740
   178
					case 2:
insilmaril@740
   179
						ts << "\n";
insilmaril@741
   180
						ts << (curIndent + "* " + cur->getHeading());
insilmaril@740
   181
						ts << "\n";
insilmaril@740
   182
						break;
insilmaril@740
   183
					case 3:
insilmaril@741
   184
						ts << (curIndent + "- " + cur->getHeading());
insilmaril@740
   185
						ts << "\n";
insilmaril@740
   186
						break;
insilmaril@740
   187
					default:
insilmaril@741
   188
						ts << (curIndent + "- " + cur->getHeading());
insilmaril@740
   189
						ts << "\n";
insilmaril@740
   190
						break;
insilmaril@740
   191
				}
insilmaril@613
   192
insilmaril@740
   193
				// If necessary, write note
insilmaril@746
   194
				if (!cur->getNoteObj().isEmpty())
insilmaril@740
   195
				{
insilmaril@740
   196
					curIndent +="  | ";
insilmaril@746
   197
					s=cur->getNoteASCII( curIndent, 80);
insilmaril@740
   198
					ts << s;
insilmaril@740
   199
				}
insilmaril@600
   200
			}
insilmaril@0
   201
		}
insilmaril@741
   202
		cur=model->next(cur,prev,d);
insilmaril@0
   203
	}
insilmaril@0
   204
	file.close();
insilmaril@0
   205
}
insilmaril@0
   206
insilmaril@613
   207
QString ExportASCII::underline (const QString &text, const QString &line)
insilmaril@613
   208
{
insilmaril@613
   209
	QString r=text + "\n";
insilmaril@613
   210
	for (int j=0;j<text.length();j++) r+=line;
insilmaril@613
   211
	return r;
insilmaril@613
   212
}
insilmaril@613
   213
insilmaril@497
   214
insilmaril@497
   215
////////////////////////////////////////////////////////////////////////
insilmaril@497
   216
void ExportCSV::doExport()
insilmaril@497
   217
{
insilmaril@497
   218
	QFile file (outputFile);
insilmaril@497
   219
	if ( !file.open( QIODevice::WriteOnly ) )
insilmaril@497
   220
	{
insilmaril@497
   221
		qWarning ("ExportBase::exportXML  couldn't open "+outputFile);
insilmaril@497
   222
		return;
insilmaril@497
   223
	}
insilmaril@497
   224
	QTextStream ts( &file );	// use LANG decoding here...
insilmaril@497
   225
insilmaril@497
   226
	// Write header
insilmaril@497
   227
	ts << "\"Note\""  <<endl;
insilmaril@497
   228
insilmaril@497
   229
	// Main loop over all branches
insilmaril@497
   230
	QString s;
insilmaril@613
   231
	QString curIndent("");
insilmaril@512
   232
	int i;
insilmaril@753
   233
	BranchObj *bo;  //FIXME-3 still needed?
insilmaril@750
   234
	BranchItem *cur=NULL;
insilmaril@750
   235
	BranchItem *prev=NULL;
insilmaril@741
   236
	int d;
insilmaril@741
   237
	cur=model->next (cur,prev,d);
insilmaril@741
   238
	while (cur) 
insilmaril@497
   239
	{
insilmaril@741
   240
		bo=(BranchObj*)(cur->getLMO());
insilmaril@740
   241
insilmaril@753
   242
		if (!cur->hasHiddenExportParent() )
insilmaril@497
   243
		{
insilmaril@600
   244
			// If necessary, write note
insilmaril@746
   245
			if (!cur->getNoteObj().isEmpty())
insilmaril@600
   246
			{
insilmaril@746
   247
				s =cur->getNoteASCII();
insilmaril@613
   248
				s=s.replace ("\n","\n"+curIndent);
insilmaril@600
   249
				ts << ("\""+s+"\",");
insilmaril@600
   250
			} else
insilmaril@600
   251
				ts <<"\"\",";
insilmaril@497
   252
insilmaril@600
   253
			// Make indentstring
insilmaril@741
   254
			for (i=0;i<cur->depth();i++) curIndent+= "\"\",";
insilmaril@497
   255
insilmaril@600
   256
			// Write heading
insilmaril@741
   257
			ts << curIndent << "\"" << cur->getHeading()<<"\""<<endl;
insilmaril@600
   258
		}
insilmaril@497
   259
		
insilmaril@741
   260
		cur=model->next(cur,prev,d);
insilmaril@613
   261
		curIndent="";
insilmaril@497
   262
	}
insilmaril@497
   263
	file.close();
insilmaril@497
   264
}
insilmaril@497
   265
insilmaril@239
   266
////////////////////////////////////////////////////////////////////////
insilmaril@742
   267
void ExportKDE3Bookmarks::doExport() 
insilmaril@239
   268
{
insilmaril@721
   269
	WarningDialog dia;
insilmaril@721
   270
	dia.showCancelButton (true);
insilmaril@721
   271
	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
insilmaril@742
   272
	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE 3"));
insilmaril@742
   273
	dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
insilmaril@742
   274
	if (dia.exec()==QDialog::Accepted)
insilmaril@742
   275
	{
insilmaril@742
   276
		model->exportXML(tmpDir.path(),false);
insilmaril@742
   277
insilmaril@742
   278
		XSLTProc p;
insilmaril@742
   279
		p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
insilmaril@742
   280
		p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
insilmaril@742
   281
		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
insilmaril@742
   282
		p.process();
insilmaril@742
   283
insilmaril@742
   284
		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
insilmaril@742
   285
		QProcess *proc= new QProcess ;
insilmaril@742
   286
		proc->start( ub);
insilmaril@742
   287
		if (!proc->waitForStarted())
insilmaril@742
   288
		{
insilmaril@742
   289
			QMessageBox::warning(0, 
insilmaril@742
   290
				QObject::tr("Warning"),
insilmaril@742
   291
				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
insilmaril@742
   292
		}	
insilmaril@742
   293
	}
insilmaril@742
   294
}
insilmaril@742
   295
insilmaril@742
   296
////////////////////////////////////////////////////////////////////////
insilmaril@742
   297
void ExportKDE4Bookmarks::doExport() 
insilmaril@742
   298
{
insilmaril@742
   299
	WarningDialog dia;
insilmaril@742
   300
	dia.showCancelButton (true);
insilmaril@742
   301
	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE 4"));
insilmaril@721
   302
	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
insilmaril@721
   303
	dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
insilmaril@721
   304
	if (dia.exec()==QDialog::Accepted)
insilmaril@239
   305
	{
insilmaril@721
   306
		model->exportXML(tmpDir.path(),false);
insilmaril@721
   307
insilmaril@721
   308
		XSLTProc p;
insilmaril@721
   309
		p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
insilmaril@742
   310
		p.setOutputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
insilmaril@721
   311
		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
insilmaril@721
   312
		p.process();
insilmaril@721
   313
insilmaril@721
   314
		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
insilmaril@721
   315
		QProcess *proc= new QProcess ;
insilmaril@721
   316
		proc->start( ub);
insilmaril@721
   317
		if (!proc->waitForStarted())
insilmaril@311
   318
		{
insilmaril@721
   319
			QMessageBox::warning(0, 
insilmaril@721
   320
				QObject::tr("Warning"),
insilmaril@721
   321
				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
insilmaril@721
   322
		}	
insilmaril@239
   323
	}
insilmaril@239
   324
}
insilmaril@239
   325
insilmaril@239
   326
////////////////////////////////////////////////////////////////////////
insilmaril@311
   327
void ExportFirefoxBookmarks::doExport() 
insilmaril@311
   328
{
insilmaril@721
   329
	WarningDialog dia;
insilmaril@721
   330
	dia.showCancelButton (true);
insilmaril@721
   331
	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
insilmaril@721
   332
	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
insilmaril@721
   333
	dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
insilmaril@721
   334
	if (dia.exec()==QDialog::Accepted)
insilmaril@311
   335
	{
insilmaril@721
   336
		model->exportXML(tmpDir.path(),false);
insilmaril@311
   337
insilmaril@311
   338
/*
insilmaril@721
   339
		XSLTProc p;
insilmaril@721
   340
		p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
insilmaril@721
   341
		p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
insilmaril@721
   342
		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
insilmaril@721
   343
		p.process();
insilmaril@311
   344
insilmaril@721
   345
		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
insilmaril@721
   346
		QProcess *proc = new QProcess( );
insilmaril@721
   347
		proc->addArgument(ub);
insilmaril@311
   348
insilmaril@721
   349
		if ( !proc->start() ) 
insilmaril@721
   350
		{
insilmaril@721
   351
			QMessageBox::warning(0, 
insilmaril@721
   352
				QObject::tr("Warning"),
insilmaril@721
   353
				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
insilmaril@721
   354
		}	
insilmaril@311
   355
insilmaril@311
   356
*/
insilmaril@311
   357
	}
insilmaril@311
   358
}
insilmaril@311
   359
insilmaril@311
   360
////////////////////////////////////////////////////////////////////////
insilmaril@228
   361
void ExportTaskjuggler::doExport() 
insilmaril@228
   362
{
insilmaril@721
   363
	model->exportXML(tmpDir.path(),false);
insilmaril@228
   364
insilmaril@721
   365
	XSLTProc p;
insilmaril@721
   366
	p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
insilmaril@721
   367
	p.setOutputFile (outputFile);
insilmaril@721
   368
	p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
insilmaril@721
   369
	p.process();
insilmaril@228
   370
}
insilmaril@228
   371
insilmaril@239
   372
////////////////////////////////////////////////////////////////////////
insilmaril@228
   373
void ExportLaTeX::doExport() 
insilmaril@0
   374
{
insilmaril@183
   375
	// Exports a map to a LaTex file.  
insilmaril@183
   376
	// This file needs to be included 
insilmaril@183
   377
	// or inported into a LaTex document
insilmaril@183
   378
	// it will not add a preamble, or anything 
insilmaril@183
   379
	// that makes a full LaTex document.
insilmaril@199
   380
  QFile file (outputFile);
insilmaril@366
   381
  if ( !file.open( QIODevice::WriteOnly ) ) {
insilmaril@205
   382
	QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
insilmaril@205
   383
	mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
insilmaril@163
   384
    return;
insilmaril@163
   385
  }
insilmaril@163
   386
  QTextStream ts( &file );	// use LANG decoding here...
insilmaril@163
   387
  ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
insilmaril@163
   388
  
insilmaril@163
   389
  // Main loop over all branches
insilmaril@163
   390
  QString s;
insilmaril@613
   391
  // QString curIndent("");
insilmaril@163
   392
  // int i;
insilmaril@163
   393
  BranchObj *bo;
insilmaril@750
   394
  BranchItem *cur=NULL;
insilmaril@750
   395
  BranchItem *prev=NULL;
insilmaril@753
   396
  int d;  //FIXME-3 still needed?
insilmaril@741
   397
  model->next(cur,prev,d);
insilmaril@741
   398
  while (cur) 
insilmaril@740
   399
  {
insilmaril@741
   400
	bo=(BranchObj*)(cur->getLMO());
insilmaril@740
   401
insilmaril@753
   402
	if (!cur->hasHiddenExportParent() )
insilmaril@600
   403
	{
insilmaril@741
   404
		switch (cur->depth() ) 
insilmaril@740
   405
		{
insilmaril@740
   406
			case 0: break;
insilmaril@740
   407
			case 1: 
insilmaril@753
   408
			  ts << ("\\chapter{" + cur->getHeading()+ "}\n");
insilmaril@740
   409
			  break;
insilmaril@740
   410
			case 2: 
insilmaril@753
   411
			  ts << ("\\section{" + cur->getHeading()+ "}\n");
insilmaril@740
   412
			  break;
insilmaril@740
   413
			case 3: 
insilmaril@753
   414
			  ts << ("\\subsection{" + cur->getHeading()+ "}\n");
insilmaril@740
   415
			  break;
insilmaril@740
   416
			case 4: 
insilmaril@753
   417
			  ts << ("\\subsubsection{" + cur->getHeading()+ "}\n");
insilmaril@740
   418
			  break;
insilmaril@740
   419
			default:
insilmaril@753
   420
			  ts << ("\\paragraph*{" + cur->getHeading()+ "}\n");
insilmaril@740
   421
			
insilmaril@600
   422
		}
insilmaril@600
   423
		// If necessary, write note
insilmaril@746
   424
		if (!cur->getNoteObj().isEmpty()) {
insilmaril@746
   425
		  ts << (cur->getNoteASCII());
insilmaril@600
   426
		  ts << ("\n");
insilmaril@600
   427
		}
insilmaril@254
   428
	}
insilmaril@741
   429
    cur=model->next(cur,prev,d);
insilmaril@163
   430
   }
insilmaril@163
   431
  file.close();
insilmaril@0
   432
}
insilmaril@0
   433
insilmaril@239
   434
////////////////////////////////////////////////////////////////////////
insilmaril@171
   435
ExportOO::ExportOO()
insilmaril@171
   436
{
insilmaril@199
   437
	useSections=false;
insilmaril@171
   438
}
insilmaril@163
   439
insilmaril@171
   440
ExportOO::~ExportOO()
insilmaril@171
   441
{
insilmaril@171
   442
}	
insilmaril@163
   443
insilmaril@750
   444
QString ExportOO::buildList (TreeItem *current)
insilmaril@171
   445
{
insilmaril@171
   446
    QString r;
insilmaril@183
   447
insilmaril@183
   448
    uint i=0;
insilmaril@750
   449
	BranchItem *bi=current->getFirstBranch();
insilmaril@750
   450
	if (bi)
insilmaril@171
   451
    {
insilmaril@750
   452
		if (true) //if (!bo->hasHiddenExportParent() )	// FIXME-2 use BranchItem...
insilmaril@600
   453
		{
insilmaril@600
   454
			// Start list
insilmaril@600
   455
			r+="<text:list text:style-name=\"vym-list\">\n";
insilmaril@750
   456
			while (bi)
insilmaril@600
   457
			{
insilmaril@600
   458
				r+="<text:list-item><text:p >";
insilmaril@750
   459
				r+=quotemeta(bi->getHeading());
insilmaril@600
   460
				// If necessary, write note
insilmaril@750
   461
				if (!bi->getNoteObj().isEmpty())
insilmaril@750
   462
					r+=bi->getNoteOpenDoc();
insilmaril@600
   463
				r+="</text:p>";
insilmaril@750
   464
				r+=buildList (bi);	// recursivly add deeper branches
insilmaril@600
   465
				r+="</text:list-item>\n";
insilmaril@600
   466
				i++;
insilmaril@750
   467
				bi=current->getBranchNum(i);
insilmaril@600
   468
			}
insilmaril@600
   469
			r+="</text:list>\n";
insilmaril@600
   470
		}
insilmaril@171
   471
    }
insilmaril@171
   472
    return r;
insilmaril@171
   473
}
insilmaril@163
   474
insilmaril@171
   475
insilmaril@171
   476
void ExportOO::exportPresentation()
insilmaril@171
   477
{
insilmaril@183
   478
	QString allPages;
insilmaril@171
   479
insilmaril@746
   480
/* FIXME-2 not adapted to multiple mapCenters yet, see patch already done in 1.12.2...
insilmaril@163
   481
	// Insert new content
insilmaril@171
   482
	content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
insilmaril@171
   483
	content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
insilmaril@183
   484
insilmaril@183
   485
	QString	onePage;
insilmaril@183
   486
	QString list;
insilmaril@183
   487
	
insilmaril@194
   488
	BranchObj *sectionBO=mapCenter->getFirstBranch();
insilmaril@183
   489
    int i=0;
insilmaril@183
   490
	BranchObj *pagesBO;
insilmaril@183
   491
    int j=0;
insilmaril@183
   492
insilmaril@194
   493
	// Walk sections
insilmaril@600
   494
	while (sectionBO && !sectionBO->hasHiddenExportParent() )
insilmaril@183
   495
	{
insilmaril@194
   496
		if (useSections)
insilmaril@183
   497
		{
insilmaril@194
   498
			// Add page with section title
insilmaril@194
   499
			onePage=sectionTemplate;
insilmaril@194
   500
			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
insilmaril@183
   501
			allPages+=onePage;
insilmaril@183
   502
		} else
insilmaril@183
   503
		{
insilmaril@183
   504
			i=-2;	// only use inner loop to 
insilmaril@183
   505
			        // turn mainbranches into pages
insilmaril@194
   506
			sectionBO=mapCenter;
insilmaril@183
   507
		}
insilmaril@183
   508
insilmaril@183
   509
		// Walk mainpages
insilmaril@194
   510
		pagesBO=sectionBO->getFirstBranch();
insilmaril@183
   511
		j=0;
insilmaril@600
   512
		while (pagesBO && !pagesBO->hasHiddenExportParent() )
insilmaril@183
   513
		{
insilmaril@183
   514
			// Add page with list of items
insilmaril@254
   515
			onePage=pageTemplate;
insilmaril@254
   516
			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
insilmaril@750
   517
			list=buildList (pagesBO->getTreeItem() );  
insilmaril@254
   518
			onePage.replace ("<!-- INSERT LIST -->", list);
insilmaril@254
   519
			allPages+=onePage;
insilmaril@183
   520
			j++;
insilmaril@194
   521
			pagesBO=sectionBO->getBranchNum(j);
insilmaril@183
   522
		}
insilmaril@183
   523
		i++;
insilmaril@194
   524
		sectionBO=mapCenter->getBranchNum(i);
insilmaril@183
   525
	}
insilmaril@183
   526
	
insilmaril@171
   527
	content.replace ("<!-- INSERT PAGES -->",allPages);
insilmaril@171
   528
insilmaril@171
   529
	// Write modified content
insilmaril@171
   530
	QFile f (contentFile);
insilmaril@366
   531
    if ( !f.open( QIODevice::WriteOnly ) ) 
insilmaril@171
   532
	{
insilmaril@205
   533
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
insilmaril@205
   534
		mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
insilmaril@171
   535
		return;
insilmaril@171
   536
    }
insilmaril@171
   537
insilmaril@171
   538
    QTextStream t( &f );
insilmaril@171
   539
    t << content;
insilmaril@171
   540
    f.close();
insilmaril@171
   541
insilmaril@163
   542
	// zip tmpdir to destination
insilmaril@171
   543
	zipDir (tmpDir,outputFile);	
insilmaril@643
   544
*/
insilmaril@163
   545
}
insilmaril@163
   546
insilmaril@194
   547
bool ExportOO::setConfigFile (const QString &cf)
insilmaril@183
   548
{
insilmaril@183
   549
	configFile=cf;
insilmaril@183
   550
	int i=cf.findRev ("/");
insilmaril@183
   551
	if (i>=0) configDir=cf.left(i);
insilmaril@183
   552
	SimpleSettings set;
insilmaril@183
   553
	set.readSettings(configFile);
insilmaril@183
   554
insilmaril@183
   555
	// set paths
insilmaril@183
   556
	templateDir=configDir+"/"+set.readEntry ("Template");
insilmaril@183
   557
insilmaril@194
   558
	QDir d (templateDir);
insilmaril@194
   559
	if (!d.exists())
insilmaril@194
   560
	{
insilmaril@194
   561
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
insilmaril@194
   562
		return false;
insilmaril@194
   563
insilmaril@194
   564
	}
insilmaril@183
   565
insilmaril@183
   566
	contentTemplateFile=templateDir+"content-template.xml";
insilmaril@183
   567
	contentFile=tmpDir.path()+"/content.xml";
insilmaril@183
   568
	pageTemplateFile=templateDir+"page-template.xml";
insilmaril@194
   569
	sectionTemplateFile=templateDir+"section-template.xml";
insilmaril@183
   570
insilmaril@199
   571
	if (set.readEntry("useSections").contains("yes"))
insilmaril@199
   572
		useSections=true;
insilmaril@199
   573
insilmaril@183
   574
	// Copy template to tmpdir
insilmaril@183
   575
	system ("cp -r "+templateDir+"* "+tmpDir.path());
insilmaril@183
   576
insilmaril@183
   577
	// Read content-template
insilmaril@183
   578
	if (!loadStringFromDisk (contentTemplateFile,content))
insilmaril@183
   579
	{
insilmaril@194
   580
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
insilmaril@194
   581
		return false;
insilmaril@183
   582
	}
insilmaril@183
   583
insilmaril@183
   584
	// Read page-template
insilmaril@183
   585
	if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
insilmaril@183
   586
	{
insilmaril@194
   587
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
insilmaril@194
   588
		return false;
insilmaril@183
   589
	}
insilmaril@183
   590
	
insilmaril@194
   591
	// Read section-template
insilmaril@201
   592
	if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
insilmaril@183
   593
	{
insilmaril@194
   594
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));
insilmaril@194
   595
		return false;
insilmaril@183
   596
	}
insilmaril@194
   597
	return true;
insilmaril@183
   598
}
insilmaril@183
   599