exports.cpp
author insilmaril
Mon Jul 27 12:53:17 2009 +0000 (2009-07-27)
changeset 783 85dec6a8c12c
parent 773 340bc29da9a0
child 791 f1006de05c54
permissions -rw-r--r--
Playing with dbus, fixed name of TW translation file
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@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@753
   151
	BranchObj *bo;	//FIXME-3 still needed?
insilmaril@773
   152
	cur=model->next (cur,prev);
insilmaril@741
   153
	while (cur) 
insilmaril@0
   154
	{
insilmaril@741
   155
		if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
insilmaril@740
   156
		{
insilmaril@741
   157
			bo=(BranchObj*)(cur->getLMO());
insilmaril@741
   158
			std::cout << "ExportASCII::  "<<cur->getHeading().toStdString()<<std::endl;
insilmaril@254
   159
insilmaril@740
   160
			// Make indentstring
insilmaril@740
   161
			curIndent="";
insilmaril@741
   162
			for (i=0;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
insilmaril@740
   163
insilmaril@753
   164
			if (!cur->hasHiddenExportParent() )
insilmaril@600
   165
			{
insilmaril@741
   166
				switch (cur->depth())
insilmaril@740
   167
				{
insilmaril@740
   168
					case 0:
insilmaril@741
   169
						ts << underline (cur->getHeading(),QString("="));
insilmaril@740
   170
						ts << "\n";
insilmaril@740
   171
						break;
insilmaril@740
   172
					case 1:
insilmaril@740
   173
						ts << "\n";
insilmaril@741
   174
						ts << (underline (getSectionString(bo) + cur->getHeading(), QString("-") ) );
insilmaril@740
   175
						ts << "\n";
insilmaril@740
   176
						break;
insilmaril@740
   177
					case 2:
insilmaril@740
   178
						ts << "\n";
insilmaril@741
   179
						ts << (curIndent + "* " + cur->getHeading());
insilmaril@740
   180
						ts << "\n";
insilmaril@740
   181
						break;
insilmaril@740
   182
					case 3:
insilmaril@741
   183
						ts << (curIndent + "- " + cur->getHeading());
insilmaril@740
   184
						ts << "\n";
insilmaril@740
   185
						break;
insilmaril@740
   186
					default:
insilmaril@741
   187
						ts << (curIndent + "- " + cur->getHeading());
insilmaril@740
   188
						ts << "\n";
insilmaril@740
   189
						break;
insilmaril@740
   190
				}
insilmaril@613
   191
insilmaril@740
   192
				// If necessary, write note
insilmaril@746
   193
				if (!cur->getNoteObj().isEmpty())
insilmaril@740
   194
				{
insilmaril@740
   195
					curIndent +="  | ";
insilmaril@746
   196
					s=cur->getNoteASCII( curIndent, 80);
insilmaril@740
   197
					ts << s;
insilmaril@740
   198
				}
insilmaril@600
   199
			}
insilmaril@0
   200
		}
insilmaril@773
   201
		cur=model->next(cur,prev);
insilmaril@0
   202
	}
insilmaril@0
   203
	file.close();
insilmaril@0
   204
}
insilmaril@0
   205
insilmaril@613
   206
QString ExportASCII::underline (const QString &text, const QString &line)
insilmaril@613
   207
{
insilmaril@613
   208
	QString r=text + "\n";
insilmaril@613
   209
	for (int j=0;j<text.length();j++) r+=line;
insilmaril@613
   210
	return r;
insilmaril@613
   211
}
insilmaril@613
   212
insilmaril@497
   213
insilmaril@497
   214
////////////////////////////////////////////////////////////////////////
insilmaril@497
   215
void ExportCSV::doExport()
insilmaril@497
   216
{
insilmaril@497
   217
	QFile file (outputFile);
insilmaril@497
   218
	if ( !file.open( QIODevice::WriteOnly ) )
insilmaril@497
   219
	{
insilmaril@497
   220
		qWarning ("ExportBase::exportXML  couldn't open "+outputFile);
insilmaril@497
   221
		return;
insilmaril@497
   222
	}
insilmaril@497
   223
	QTextStream ts( &file );	// use LANG decoding here...
insilmaril@497
   224
insilmaril@497
   225
	// Write header
insilmaril@497
   226
	ts << "\"Note\""  <<endl;
insilmaril@497
   227
insilmaril@497
   228
	// Main loop over all branches
insilmaril@497
   229
	QString s;
insilmaril@613
   230
	QString curIndent("");
insilmaril@512
   231
	int i;
insilmaril@753
   232
	BranchObj *bo;  //FIXME-3 still needed?
insilmaril@750
   233
	BranchItem *cur=NULL;
insilmaril@750
   234
	BranchItem *prev=NULL;
insilmaril@773
   235
	cur=model->next (cur,prev);
insilmaril@741
   236
	while (cur) 
insilmaril@497
   237
	{
insilmaril@741
   238
		bo=(BranchObj*)(cur->getLMO());
insilmaril@740
   239
insilmaril@753
   240
		if (!cur->hasHiddenExportParent() )
insilmaril@497
   241
		{
insilmaril@600
   242
			// If necessary, write note
insilmaril@746
   243
			if (!cur->getNoteObj().isEmpty())
insilmaril@600
   244
			{
insilmaril@746
   245
				s =cur->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@773
   258
		cur=model->next(cur,prev);
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@750
   392
  BranchItem *cur=NULL;
insilmaril@750
   393
  BranchItem *prev=NULL;
insilmaril@773
   394
  model->next(cur,prev);
insilmaril@741
   395
  while (cur) 
insilmaril@740
   396
  {
insilmaril@741
   397
	bo=(BranchObj*)(cur->getLMO());
insilmaril@740
   398
insilmaril@753
   399
	if (!cur->hasHiddenExportParent() )
insilmaril@600
   400
	{
insilmaril@741
   401
		switch (cur->depth() ) 
insilmaril@740
   402
		{
insilmaril@740
   403
			case 0: break;
insilmaril@740
   404
			case 1: 
insilmaril@753
   405
			  ts << ("\\chapter{" + cur->getHeading()+ "}\n");
insilmaril@740
   406
			  break;
insilmaril@740
   407
			case 2: 
insilmaril@753
   408
			  ts << ("\\section{" + cur->getHeading()+ "}\n");
insilmaril@740
   409
			  break;
insilmaril@740
   410
			case 3: 
insilmaril@753
   411
			  ts << ("\\subsection{" + cur->getHeading()+ "}\n");
insilmaril@740
   412
			  break;
insilmaril@740
   413
			case 4: 
insilmaril@753
   414
			  ts << ("\\subsubsection{" + cur->getHeading()+ "}\n");
insilmaril@740
   415
			  break;
insilmaril@740
   416
			default:
insilmaril@753
   417
			  ts << ("\\paragraph*{" + cur->getHeading()+ "}\n");
insilmaril@740
   418
			
insilmaril@600
   419
		}
insilmaril@600
   420
		// If necessary, write note
insilmaril@746
   421
		if (!cur->getNoteObj().isEmpty()) {
insilmaril@746
   422
		  ts << (cur->getNoteASCII());
insilmaril@600
   423
		  ts << ("\n");
insilmaril@600
   424
		}
insilmaril@254
   425
	}
insilmaril@773
   426
    cur=model->next(cur,prev);
insilmaril@163
   427
   }
insilmaril@163
   428
  file.close();
insilmaril@0
   429
}
insilmaril@0
   430
insilmaril@239
   431
////////////////////////////////////////////////////////////////////////
insilmaril@171
   432
ExportOO::ExportOO()
insilmaril@171
   433
{
insilmaril@199
   434
	useSections=false;
insilmaril@171
   435
}
insilmaril@163
   436
insilmaril@171
   437
ExportOO::~ExportOO()
insilmaril@171
   438
{
insilmaril@171
   439
}	
insilmaril@163
   440
insilmaril@750
   441
QString ExportOO::buildList (TreeItem *current)
insilmaril@171
   442
{
insilmaril@171
   443
    QString r;
insilmaril@183
   444
insilmaril@183
   445
    uint i=0;
insilmaril@750
   446
	BranchItem *bi=current->getFirstBranch();
insilmaril@750
   447
	if (bi)
insilmaril@171
   448
    {
insilmaril@750
   449
		if (true) //if (!bo->hasHiddenExportParent() )	// FIXME-2 use BranchItem...
insilmaril@600
   450
		{
insilmaril@600
   451
			// Start list
insilmaril@600
   452
			r+="<text:list text:style-name=\"vym-list\">\n";
insilmaril@750
   453
			while (bi)
insilmaril@600
   454
			{
insilmaril@600
   455
				r+="<text:list-item><text:p >";
insilmaril@750
   456
				r+=quotemeta(bi->getHeading());
insilmaril@600
   457
				// If necessary, write note
insilmaril@750
   458
				if (!bi->getNoteObj().isEmpty())
insilmaril@750
   459
					r+=bi->getNoteOpenDoc();
insilmaril@600
   460
				r+="</text:p>";
insilmaril@750
   461
				r+=buildList (bi);	// recursivly add deeper branches
insilmaril@600
   462
				r+="</text:list-item>\n";
insilmaril@600
   463
				i++;
insilmaril@750
   464
				bi=current->getBranchNum(i);
insilmaril@600
   465
			}
insilmaril@600
   466
			r+="</text:list>\n";
insilmaril@600
   467
		}
insilmaril@171
   468
    }
insilmaril@171
   469
    return r;
insilmaril@171
   470
}
insilmaril@163
   471
insilmaril@171
   472
insilmaril@171
   473
void ExportOO::exportPresentation()
insilmaril@171
   474
{
insilmaril@183
   475
	QString allPages;
insilmaril@171
   476
insilmaril@746
   477
/* FIXME-2 not adapted to multiple mapCenters yet, see patch already done in 1.12.2...
insilmaril@163
   478
	// Insert new content
insilmaril@171
   479
	content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
insilmaril@171
   480
	content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
insilmaril@183
   481
insilmaril@183
   482
	QString	onePage;
insilmaril@183
   483
	QString list;
insilmaril@183
   484
	
insilmaril@194
   485
	BranchObj *sectionBO=mapCenter->getFirstBranch();
insilmaril@183
   486
    int i=0;
insilmaril@183
   487
	BranchObj *pagesBO;
insilmaril@183
   488
    int j=0;
insilmaril@183
   489
insilmaril@194
   490
	// Walk sections
insilmaril@600
   491
	while (sectionBO && !sectionBO->hasHiddenExportParent() )
insilmaril@183
   492
	{
insilmaril@194
   493
		if (useSections)
insilmaril@183
   494
		{
insilmaril@194
   495
			// Add page with section title
insilmaril@194
   496
			onePage=sectionTemplate;
insilmaril@194
   497
			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
insilmaril@183
   498
			allPages+=onePage;
insilmaril@183
   499
		} else
insilmaril@183
   500
		{
insilmaril@183
   501
			i=-2;	// only use inner loop to 
insilmaril@183
   502
			        // turn mainbranches into pages
insilmaril@194
   503
			sectionBO=mapCenter;
insilmaril@183
   504
		}
insilmaril@183
   505
insilmaril@183
   506
		// Walk mainpages
insilmaril@194
   507
		pagesBO=sectionBO->getFirstBranch();
insilmaril@183
   508
		j=0;
insilmaril@600
   509
		while (pagesBO && !pagesBO->hasHiddenExportParent() )
insilmaril@183
   510
		{
insilmaril@183
   511
			// Add page with list of items
insilmaril@254
   512
			onePage=pageTemplate;
insilmaril@254
   513
			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
insilmaril@750
   514
			list=buildList (pagesBO->getTreeItem() );  
insilmaril@254
   515
			onePage.replace ("<!-- INSERT LIST -->", list);
insilmaril@254
   516
			allPages+=onePage;
insilmaril@183
   517
			j++;
insilmaril@194
   518
			pagesBO=sectionBO->getBranchNum(j);
insilmaril@183
   519
		}
insilmaril@183
   520
		i++;
insilmaril@194
   521
		sectionBO=mapCenter->getBranchNum(i);
insilmaril@183
   522
	}
insilmaril@183
   523
	
insilmaril@171
   524
	content.replace ("<!-- INSERT PAGES -->",allPages);
insilmaril@171
   525
insilmaril@171
   526
	// Write modified content
insilmaril@171
   527
	QFile f (contentFile);
insilmaril@366
   528
    if ( !f.open( QIODevice::WriteOnly ) ) 
insilmaril@171
   529
	{
insilmaril@205
   530
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
insilmaril@205
   531
		mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
insilmaril@171
   532
		return;
insilmaril@171
   533
    }
insilmaril@171
   534
insilmaril@171
   535
    QTextStream t( &f );
insilmaril@171
   536
    t << content;
insilmaril@171
   537
    f.close();
insilmaril@171
   538
insilmaril@163
   539
	// zip tmpdir to destination
insilmaril@171
   540
	zipDir (tmpDir,outputFile);	
insilmaril@643
   541
*/
insilmaril@163
   542
}
insilmaril@163
   543
insilmaril@194
   544
bool ExportOO::setConfigFile (const QString &cf)
insilmaril@183
   545
{
insilmaril@183
   546
	configFile=cf;
insilmaril@183
   547
	int i=cf.findRev ("/");
insilmaril@183
   548
	if (i>=0) configDir=cf.left(i);
insilmaril@183
   549
	SimpleSettings set;
insilmaril@183
   550
	set.readSettings(configFile);
insilmaril@183
   551
insilmaril@183
   552
	// set paths
insilmaril@183
   553
	templateDir=configDir+"/"+set.readEntry ("Template");
insilmaril@183
   554
insilmaril@194
   555
	QDir d (templateDir);
insilmaril@194
   556
	if (!d.exists())
insilmaril@194
   557
	{
insilmaril@194
   558
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
insilmaril@194
   559
		return false;
insilmaril@194
   560
insilmaril@194
   561
	}
insilmaril@183
   562
insilmaril@183
   563
	contentTemplateFile=templateDir+"content-template.xml";
insilmaril@183
   564
	contentFile=tmpDir.path()+"/content.xml";
insilmaril@183
   565
	pageTemplateFile=templateDir+"page-template.xml";
insilmaril@194
   566
	sectionTemplateFile=templateDir+"section-template.xml";
insilmaril@183
   567
insilmaril@199
   568
	if (set.readEntry("useSections").contains("yes"))
insilmaril@199
   569
		useSections=true;
insilmaril@199
   570
insilmaril@183
   571
	// Copy template to tmpdir
insilmaril@183
   572
	system ("cp -r "+templateDir+"* "+tmpDir.path());
insilmaril@183
   573
insilmaril@183
   574
	// Read content-template
insilmaril@183
   575
	if (!loadStringFromDisk (contentTemplateFile,content))
insilmaril@183
   576
	{
insilmaril@194
   577
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
insilmaril@194
   578
		return false;
insilmaril@183
   579
	}
insilmaril@183
   580
insilmaril@183
   581
	// Read page-template
insilmaril@183
   582
	if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
insilmaril@183
   583
	{
insilmaril@194
   584
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
insilmaril@194
   585
		return false;
insilmaril@183
   586
	}
insilmaril@183
   587
	
insilmaril@194
   588
	// Read section-template
insilmaril@201
   589
	if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
insilmaril@183
   590
	{
insilmaril@194
   591
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));
insilmaril@194
   592
		return false;
insilmaril@183
   593
	}
insilmaril@194
   594
	return true;
insilmaril@183
   595
}
insilmaril@183
   596