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