exports.cpp
author insilmaril
Tue, 01 Dec 2009 11:06:15 +0000
changeset 813 82ebfc46233b
parent 807 f9f7922989d8
child 815 2881c4424190
permissions -rw-r--r--
Fixed undo of detach()
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@807
   128
ExportAO::ExportAO()
insilmaril@807
   129
{
insilmaril@807
   130
	filter="TXT (*.txt)";
insilmaril@807
   131
	caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
insilmaril@807
   132
}
insilmaril@807
   133
insilmaril@807
   134
void ExportAO::doExport()	
insilmaril@807
   135
{
insilmaril@807
   136
	QFile file (outputFile);
insilmaril@807
   137
	if ( !file.open( QIODevice::WriteOnly ) )
insilmaril@807
   138
	{
insilmaril@807
   139
		qWarning ("ExportAO::doExport couldn't open "+outputFile);
insilmaril@807
   140
		return;
insilmaril@807
   141
	}
insilmaril@807
   142
	QTextStream ts( &file );	// use LANG decoding here...
insilmaril@807
   143
insilmaril@807
   144
	// Main loop over all branches
insilmaril@807
   145
	QString s;
insilmaril@807
   146
	QString curIndent;
insilmaril@807
   147
	int i;
insilmaril@807
   148
	BranchItem *cur=NULL;
insilmaril@807
   149
	BranchItem *prev=NULL;
insilmaril@807
   150
insilmaril@807
   151
	QString colString;
insilmaril@807
   152
	QColor col;
insilmaril@807
   153
insilmaril@807
   154
	cur=model->nextBranch (cur,prev);
insilmaril@807
   155
	while (cur) 
insilmaril@807
   156
	{
insilmaril@807
   157
		if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
insilmaril@807
   158
		{
insilmaril@807
   159
			// Make indentstring
insilmaril@807
   160
			curIndent="";
insilmaril@807
   161
			for (i=0;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
insilmaril@807
   162
insilmaril@807
   163
			if (!cur->hasHiddenExportParent() )
insilmaril@807
   164
			{
insilmaril@807
   165
				col=cur->getHeadingColor();
insilmaril@807
   166
				if (col==QColor (255,0,0))
insilmaril@807
   167
					colString="[R]";
insilmaril@807
   168
				else if (col==QColor (217,81,0))
insilmaril@807
   169
					colString="[O]";
insilmaril@807
   170
				else if (col==QColor (0,85,0))
insilmaril@807
   171
					colString="[G]";
insilmaril@807
   172
				else  	
insilmaril@807
   173
					colString="[?]";
insilmaril@807
   174
				switch (cur->depth())
insilmaril@807
   175
				{
insilmaril@807
   176
					case 0:
insilmaril@807
   177
						//ts << underline (cur->getHeading(),QString("="));
insilmaril@807
   178
						//ts << "\n";
insilmaril@807
   179
						break;
insilmaril@807
   180
					case 1:
insilmaril@807
   181
						//ts << "\n";
insilmaril@807
   182
						//ts << (underline ( cur->getHeading(), QString("-") ) );
insilmaril@807
   183
						//ts << "\n";
insilmaril@807
   184
						break;
insilmaril@807
   185
					case 2: // Main heading
insilmaril@807
   186
						ts << "\n";
insilmaril@807
   187
						ts << underline ( cur->getHeading(), QString("=") );
insilmaril@807
   188
						ts << "\n\n";
insilmaril@807
   189
						break;
insilmaril@807
   190
					case 3: // Achievement, Bonus, Objective ...
insilmaril@807
   191
						ts << underline ( cur->getHeading(), "-");
insilmaril@807
   192
						ts << "\n\n";
insilmaril@807
   193
						break;
insilmaril@807
   194
					case 4:	// That's the item we need to know
insilmaril@807
   195
						ts << (curIndent + "* " + colString+" "+ cur->getHeading());
insilmaril@807
   196
						if (cur->isActiveStandardFlag ("hook-green"))
insilmaril@807
   197
							ts << " [DONE] ";
insilmaril@807
   198
						else	if (cur->isActiveStandardFlag ("clock"))
insilmaril@807
   199
							ts << " [WIP] ";
insilmaril@807
   200
						else	if (cur->isActiveStandardFlag ("cross-red"))
insilmaril@807
   201
							ts << " [NOT STARTED] ";
insilmaril@807
   202
						ts << "\n";
insilmaril@807
   203
					default:
insilmaril@807
   204
						break;
insilmaril@807
   205
						ts << (curIndent + "- " + cur->getHeading());
insilmaril@807
   206
						ts << "\n";
insilmaril@807
   207
						break;
insilmaril@807
   208
				}
insilmaril@807
   209
insilmaril@807
   210
				// If necessary, write note
insilmaril@807
   211
				if (!cur->getNoteObj().isEmpty())
insilmaril@807
   212
				{
insilmaril@807
   213
					curIndent +="  | ";
insilmaril@807
   214
					s=cur->getNoteASCII( curIndent, 80);
insilmaril@807
   215
					ts << s;
insilmaril@807
   216
				}
insilmaril@807
   217
			}
insilmaril@807
   218
		}
insilmaril@807
   219
		cur=model->nextBranch(cur,prev);
insilmaril@807
   220
	}
insilmaril@807
   221
	file.close();
insilmaril@807
   222
}
insilmaril@807
   223
insilmaril@807
   224
QString ExportAO::underline (const QString &text, const QString &line)
insilmaril@807
   225
{
insilmaril@807
   226
	QString r=text + "\n";
insilmaril@807
   227
	for (int j=0;j<text.length();j++) r+=line;
insilmaril@807
   228
	return r;
insilmaril@807
   229
}
insilmaril@807
   230
insilmaril@807
   231
insilmaril@807
   232
////////////////////////////////////////////////////////////////////////
insilmaril@512
   233
ExportASCII::ExportASCII()
insilmaril@512
   234
{
insilmaril@512
   235
	filter="TXT (*.txt)";
insilmaril@512
   236
	caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
insilmaril@512
   237
}
insilmaril@512
   238
insilmaril@777
   239
void ExportASCII::doExport()	
insilmaril@0
   240
{
insilmaril@199
   241
	QFile file (outputFile);
insilmaril@366
   242
	if ( !file.open( QIODevice::WriteOnly ) )
insilmaril@0
   243
	{
insilmaril@807
   244
		qWarning ("ExportASCII::doExport couldn't open "+outputFile);
insilmaril@0
   245
		return;
insilmaril@0
   246
	}
insilmaril@0
   247
	QTextStream ts( &file );	// use LANG decoding here...
insilmaril@0
   248
insilmaril@0
   249
	// Main loop over all branches
insilmaril@0
   250
	QString s;
insilmaril@613
   251
	QString curIndent;
insilmaril@613
   252
	int i;
insilmaril@750
   253
	BranchItem *cur=NULL;
insilmaril@750
   254
	BranchItem *prev=NULL;
insilmaril@741
   255
insilmaril@804
   256
	cur=model->nextBranch (cur,prev);
insilmaril@741
   257
	while (cur) 
insilmaril@0
   258
	{
insilmaril@741
   259
		if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
insilmaril@740
   260
		{
insilmaril@740
   261
			// Make indentstring
insilmaril@740
   262
			curIndent="";
insilmaril@741
   263
			for (i=0;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
insilmaril@740
   264
insilmaril@753
   265
			if (!cur->hasHiddenExportParent() )
insilmaril@600
   266
			{
insilmaril@791
   267
				//std::cout << "ExportASCII::  "<<curIndent.toStdString()<<cur->getHeading().toStdString()<<std::endl;
insilmaril@741
   268
				switch (cur->depth())
insilmaril@740
   269
				{
insilmaril@740
   270
					case 0:
insilmaril@741
   271
						ts << underline (cur->getHeading(),QString("="));
insilmaril@740
   272
						ts << "\n";
insilmaril@740
   273
						break;
insilmaril@740
   274
					case 1:
insilmaril@740
   275
						ts << "\n";
insilmaril@791
   276
						ts << (underline (getSectionString(cur) + cur->getHeading(), QString("-") ) );
insilmaril@740
   277
						ts << "\n";
insilmaril@740
   278
						break;
insilmaril@740
   279
					case 2:
insilmaril@740
   280
						ts << "\n";
insilmaril@741
   281
						ts << (curIndent + "* " + cur->getHeading());
insilmaril@740
   282
						ts << "\n";
insilmaril@740
   283
						break;
insilmaril@740
   284
					case 3:
insilmaril@741
   285
						ts << (curIndent + "- " + cur->getHeading());
insilmaril@740
   286
						ts << "\n";
insilmaril@740
   287
						break;
insilmaril@740
   288
					default:
insilmaril@741
   289
						ts << (curIndent + "- " + cur->getHeading());
insilmaril@740
   290
						ts << "\n";
insilmaril@740
   291
						break;
insilmaril@740
   292
				}
insilmaril@613
   293
insilmaril@740
   294
				// If necessary, write note
insilmaril@746
   295
				if (!cur->getNoteObj().isEmpty())
insilmaril@740
   296
				{
insilmaril@740
   297
					curIndent +="  | ";
insilmaril@746
   298
					s=cur->getNoteASCII( curIndent, 80);
insilmaril@740
   299
					ts << s;
insilmaril@740
   300
				}
insilmaril@600
   301
			}
insilmaril@0
   302
		}
insilmaril@804
   303
		cur=model->nextBranch(cur,prev);
insilmaril@0
   304
	}
insilmaril@0
   305
	file.close();
insilmaril@0
   306
}
insilmaril@0
   307
insilmaril@613
   308
QString ExportASCII::underline (const QString &text, const QString &line)
insilmaril@613
   309
{
insilmaril@613
   310
	QString r=text + "\n";
insilmaril@613
   311
	for (int j=0;j<text.length();j++) r+=line;
insilmaril@613
   312
	return r;
insilmaril@613
   313
}
insilmaril@613
   314
insilmaril@497
   315
insilmaril@497
   316
////////////////////////////////////////////////////////////////////////
insilmaril@497
   317
void ExportCSV::doExport()
insilmaril@497
   318
{
insilmaril@497
   319
	QFile file (outputFile);
insilmaril@497
   320
	if ( !file.open( QIODevice::WriteOnly ) )
insilmaril@497
   321
	{
insilmaril@497
   322
		qWarning ("ExportBase::exportXML  couldn't open "+outputFile);
insilmaril@497
   323
		return;
insilmaril@497
   324
	}
insilmaril@497
   325
	QTextStream ts( &file );	// use LANG decoding here...
insilmaril@497
   326
insilmaril@497
   327
	// Write header
insilmaril@497
   328
	ts << "\"Note\""  <<endl;
insilmaril@497
   329
insilmaril@497
   330
	// Main loop over all branches
insilmaril@497
   331
	QString s;
insilmaril@613
   332
	QString curIndent("");
insilmaril@512
   333
	int i;
insilmaril@753
   334
	BranchObj *bo;  //FIXME-3 still needed?
insilmaril@750
   335
	BranchItem *cur=NULL;
insilmaril@750
   336
	BranchItem *prev=NULL;
insilmaril@804
   337
	cur=model->nextBranch (cur,prev);
insilmaril@741
   338
	while (cur) 
insilmaril@497
   339
	{
insilmaril@741
   340
		bo=(BranchObj*)(cur->getLMO());
insilmaril@740
   341
insilmaril@753
   342
		if (!cur->hasHiddenExportParent() )
insilmaril@497
   343
		{
insilmaril@600
   344
			// If necessary, write note
insilmaril@746
   345
			if (!cur->getNoteObj().isEmpty())
insilmaril@600
   346
			{
insilmaril@746
   347
				s =cur->getNoteASCII();
insilmaril@613
   348
				s=s.replace ("\n","\n"+curIndent);
insilmaril@600
   349
				ts << ("\""+s+"\",");
insilmaril@600
   350
			} else
insilmaril@600
   351
				ts <<"\"\",";
insilmaril@497
   352
insilmaril@600
   353
			// Make indentstring
insilmaril@741
   354
			for (i=0;i<cur->depth();i++) curIndent+= "\"\",";
insilmaril@497
   355
insilmaril@600
   356
			// Write heading
insilmaril@741
   357
			ts << curIndent << "\"" << cur->getHeading()<<"\""<<endl;
insilmaril@600
   358
		}
insilmaril@497
   359
		
insilmaril@804
   360
		cur=model->nextBranch(cur,prev);
insilmaril@613
   361
		curIndent="";
insilmaril@497
   362
	}
insilmaril@497
   363
	file.close();
insilmaril@497
   364
}
insilmaril@497
   365
insilmaril@239
   366
////////////////////////////////////////////////////////////////////////
insilmaril@742
   367
void ExportKDE3Bookmarks::doExport() 
insilmaril@239
   368
{
insilmaril@721
   369
	WarningDialog dia;
insilmaril@721
   370
	dia.showCancelButton (true);
insilmaril@721
   371
	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
insilmaril@742
   372
	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE 3"));
insilmaril@742
   373
	dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
insilmaril@742
   374
	if (dia.exec()==QDialog::Accepted)
insilmaril@742
   375
	{
insilmaril@742
   376
		model->exportXML(tmpDir.path(),false);
insilmaril@742
   377
insilmaril@742
   378
		XSLTProc p;
insilmaril@742
   379
		p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
insilmaril@742
   380
		p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
insilmaril@742
   381
		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
insilmaril@742
   382
		p.process();
insilmaril@742
   383
insilmaril@742
   384
		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
insilmaril@742
   385
		QProcess *proc= new QProcess ;
insilmaril@742
   386
		proc->start( ub);
insilmaril@742
   387
		if (!proc->waitForStarted())
insilmaril@742
   388
		{
insilmaril@742
   389
			QMessageBox::warning(0, 
insilmaril@742
   390
				QObject::tr("Warning"),
insilmaril@742
   391
				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
insilmaril@742
   392
		}	
insilmaril@742
   393
	}
insilmaril@742
   394
}
insilmaril@742
   395
insilmaril@742
   396
////////////////////////////////////////////////////////////////////////
insilmaril@742
   397
void ExportKDE4Bookmarks::doExport() 
insilmaril@742
   398
{
insilmaril@742
   399
	WarningDialog dia;
insilmaril@742
   400
	dia.showCancelButton (true);
insilmaril@742
   401
	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE 4"));
insilmaril@721
   402
	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE"));
insilmaril@721
   403
	dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
insilmaril@721
   404
	if (dia.exec()==QDialog::Accepted)
insilmaril@239
   405
	{
insilmaril@721
   406
		model->exportXML(tmpDir.path(),false);
insilmaril@721
   407
insilmaril@721
   408
		XSLTProc p;
insilmaril@721
   409
		p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
insilmaril@742
   410
		p.setOutputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
insilmaril@721
   411
		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
insilmaril@721
   412
		p.process();
insilmaril@721
   413
insilmaril@721
   414
		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
insilmaril@721
   415
		QProcess *proc= new QProcess ;
insilmaril@721
   416
		proc->start( ub);
insilmaril@721
   417
		if (!proc->waitForStarted())
insilmaril@311
   418
		{
insilmaril@721
   419
			QMessageBox::warning(0, 
insilmaril@721
   420
				QObject::tr("Warning"),
insilmaril@721
   421
				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
insilmaril@721
   422
		}	
insilmaril@239
   423
	}
insilmaril@239
   424
}
insilmaril@239
   425
insilmaril@239
   426
////////////////////////////////////////////////////////////////////////
insilmaril@311
   427
void ExportFirefoxBookmarks::doExport() 
insilmaril@311
   428
{
insilmaril@721
   429
	WarningDialog dia;
insilmaril@721
   430
	dia.showCancelButton (true);
insilmaril@721
   431
	dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
insilmaril@721
   432
	dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
insilmaril@721
   433
	dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
insilmaril@721
   434
	if (dia.exec()==QDialog::Accepted)
insilmaril@311
   435
	{
insilmaril@721
   436
		model->exportXML(tmpDir.path(),false);
insilmaril@311
   437
insilmaril@311
   438
/*
insilmaril@721
   439
		XSLTProc p;
insilmaril@721
   440
		p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
insilmaril@721
   441
		p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
insilmaril@721
   442
		p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
insilmaril@721
   443
		p.process();
insilmaril@311
   444
insilmaril@721
   445
		QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
insilmaril@721
   446
		QProcess *proc = new QProcess( );
insilmaril@721
   447
		proc->addArgument(ub);
insilmaril@311
   448
insilmaril@721
   449
		if ( !proc->start() ) 
insilmaril@721
   450
		{
insilmaril@721
   451
			QMessageBox::warning(0, 
insilmaril@721
   452
				QObject::tr("Warning"),
insilmaril@721
   453
				QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
insilmaril@721
   454
		}	
insilmaril@311
   455
insilmaril@311
   456
*/
insilmaril@311
   457
	}
insilmaril@311
   458
}
insilmaril@311
   459
insilmaril@311
   460
////////////////////////////////////////////////////////////////////////
insilmaril@228
   461
void ExportTaskjuggler::doExport() 
insilmaril@228
   462
{
insilmaril@721
   463
	model->exportXML(tmpDir.path(),false);
insilmaril@228
   464
insilmaril@721
   465
	XSLTProc p;
insilmaril@721
   466
	p.setInputFile (tmpDir.path()+"/"+model->getMapName()+".xml");
insilmaril@721
   467
	p.setOutputFile (outputFile);
insilmaril@721
   468
	p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
insilmaril@721
   469
	p.process();
insilmaril@228
   470
}
insilmaril@228
   471
insilmaril@239
   472
////////////////////////////////////////////////////////////////////////
insilmaril@228
   473
void ExportLaTeX::doExport() 
insilmaril@0
   474
{
insilmaril@183
   475
	// Exports a map to a LaTex file.  
insilmaril@183
   476
	// This file needs to be included 
insilmaril@183
   477
	// or inported into a LaTex document
insilmaril@183
   478
	// it will not add a preamble, or anything 
insilmaril@183
   479
	// that makes a full LaTex document.
insilmaril@199
   480
  QFile file (outputFile);
insilmaril@366
   481
  if ( !file.open( QIODevice::WriteOnly ) ) {
insilmaril@205
   482
	QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
insilmaril@205
   483
	mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
insilmaril@163
   484
    return;
insilmaril@163
   485
  }
insilmaril@163
   486
  QTextStream ts( &file );	// use LANG decoding here...
insilmaril@163
   487
  ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
insilmaril@163
   488
  
insilmaril@163
   489
  // Main loop over all branches
insilmaril@163
   490
  QString s;
insilmaril@613
   491
  // QString curIndent("");
insilmaril@163
   492
  // int i;
insilmaril@163
   493
  BranchObj *bo;
insilmaril@750
   494
  BranchItem *cur=NULL;
insilmaril@750
   495
  BranchItem *prev=NULL;
insilmaril@804
   496
  model->nextBranch(cur,prev);
insilmaril@741
   497
  while (cur) 
insilmaril@740
   498
  {
insilmaril@741
   499
	bo=(BranchObj*)(cur->getLMO());
insilmaril@740
   500
insilmaril@753
   501
	if (!cur->hasHiddenExportParent() )
insilmaril@600
   502
	{
insilmaril@741
   503
		switch (cur->depth() ) 
insilmaril@740
   504
		{
insilmaril@740
   505
			case 0: break;
insilmaril@740
   506
			case 1: 
insilmaril@753
   507
			  ts << ("\\chapter{" + cur->getHeading()+ "}\n");
insilmaril@740
   508
			  break;
insilmaril@740
   509
			case 2: 
insilmaril@753
   510
			  ts << ("\\section{" + cur->getHeading()+ "}\n");
insilmaril@740
   511
			  break;
insilmaril@740
   512
			case 3: 
insilmaril@753
   513
			  ts << ("\\subsection{" + cur->getHeading()+ "}\n");
insilmaril@740
   514
			  break;
insilmaril@740
   515
			case 4: 
insilmaril@753
   516
			  ts << ("\\subsubsection{" + cur->getHeading()+ "}\n");
insilmaril@740
   517
			  break;
insilmaril@740
   518
			default:
insilmaril@753
   519
			  ts << ("\\paragraph*{" + cur->getHeading()+ "}\n");
insilmaril@740
   520
			
insilmaril@600
   521
		}
insilmaril@600
   522
		// If necessary, write note
insilmaril@746
   523
		if (!cur->getNoteObj().isEmpty()) {
insilmaril@746
   524
		  ts << (cur->getNoteASCII());
insilmaril@600
   525
		  ts << ("\n");
insilmaril@600
   526
		}
insilmaril@254
   527
	}
insilmaril@804
   528
    cur=model->nextBranch(cur,prev);
insilmaril@163
   529
   }
insilmaril@163
   530
  file.close();
insilmaril@0
   531
}
insilmaril@0
   532
insilmaril@239
   533
////////////////////////////////////////////////////////////////////////
insilmaril@171
   534
ExportOO::ExportOO()
insilmaril@171
   535
{
insilmaril@199
   536
	useSections=false;
insilmaril@171
   537
}
insilmaril@163
   538
insilmaril@171
   539
ExportOO::~ExportOO()
insilmaril@171
   540
{
insilmaril@171
   541
}	
insilmaril@163
   542
insilmaril@750
   543
QString ExportOO::buildList (TreeItem *current)
insilmaril@171
   544
{
insilmaril@171
   545
    QString r;
insilmaril@183
   546
insilmaril@183
   547
    uint i=0;
insilmaril@750
   548
	BranchItem *bi=current->getFirstBranch();
insilmaril@750
   549
	if (bi)
insilmaril@171
   550
    {
insilmaril@804
   551
		if (!bi->hasHiddenExportParent() )	// FIXME-3 use BranchItem...
insilmaril@600
   552
		{
insilmaril@600
   553
			// Start list
insilmaril@600
   554
			r+="<text:list text:style-name=\"vym-list\">\n";
insilmaril@750
   555
			while (bi)
insilmaril@600
   556
			{
insilmaril@600
   557
				r+="<text:list-item><text:p >";
insilmaril@750
   558
				r+=quotemeta(bi->getHeading());
insilmaril@600
   559
				// If necessary, write note
insilmaril@750
   560
				if (!bi->getNoteObj().isEmpty())
insilmaril@750
   561
					r+=bi->getNoteOpenDoc();
insilmaril@600
   562
				r+="</text:p>";
insilmaril@750
   563
				r+=buildList (bi);	// recursivly add deeper branches
insilmaril@600
   564
				r+="</text:list-item>\n";
insilmaril@600
   565
				i++;
insilmaril@750
   566
				bi=current->getBranchNum(i);
insilmaril@600
   567
			}
insilmaril@600
   568
			r+="</text:list>\n";
insilmaril@600
   569
		}
insilmaril@171
   570
    }
insilmaril@171
   571
    return r;
insilmaril@171
   572
}
insilmaril@163
   573
insilmaril@171
   574
insilmaril@171
   575
void ExportOO::exportPresentation()
insilmaril@171
   576
{
insilmaril@183
   577
	QString allPages;
insilmaril@171
   578
insilmaril@804
   579
	BranchItem *firstMCO=(BranchItem*)(model->getRootItem()->getFirstBranch());
insilmaril@804
   580
	if (!firstMCO) 
insilmaril@804
   581
	{
insilmaril@804
   582
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("No objects in map!"));
insilmaril@804
   583
		return;
insilmaril@804
   584
	}
insilmaril@804
   585
insilmaril@163
   586
	// Insert new content
insilmaril@804
   587
	// FIXME add extra title in mapinfo for vym 1.13.x
insilmaril@804
   588
	content.replace ("<!-- INSERT TITLE -->",quotemeta(firstMCO->getHeading()));
insilmaril@804
   589
	content.replace ("<!-- INSERT AUTHOR -->",quotemeta(model->getAuthor()));
insilmaril@183
   590
insilmaril@183
   591
	QString	onePage;
insilmaril@183
   592
	QString list;
insilmaril@183
   593
	
insilmaril@804
   594
	BranchItem *sectionBI;	
insilmaril@183
   595
    int i=0;
insilmaril@804
   596
	BranchItem *pagesBI;
insilmaril@183
   597
    int j=0;
insilmaril@183
   598
insilmaril@804
   599
	int mapcenters=model->getRootItem()->branchCount();
insilmaril@804
   600
insilmaril@804
   601
	// useSections already has been set in setConfigFile 
insilmaril@804
   602
	if (mapcenters>1)	
insilmaril@804
   603
		sectionBI=firstMCO;
insilmaril@804
   604
	else
insilmaril@804
   605
		sectionBI=firstMCO->getFirstBranch();
insilmaril@804
   606
insilmaril@194
   607
	// Walk sections
insilmaril@804
   608
	while (sectionBI && !sectionBI->hasHiddenExportParent() )
insilmaril@183
   609
	{
insilmaril@194
   610
		if (useSections)
insilmaril@183
   611
		{
insilmaril@194
   612
			// Add page with section title
insilmaril@194
   613
			onePage=sectionTemplate;
insilmaril@804
   614
			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBI->getHeading() ) );
insilmaril@183
   615
			allPages+=onePage;
insilmaril@804
   616
			pagesBI=sectionBI->getFirstBranch();
insilmaril@183
   617
		} else
insilmaril@183
   618
		{
insilmaril@804
   619
			//i=-2;	// only use inner loop to 
insilmaril@183
   620
			        // turn mainbranches into pages
insilmaril@804
   621
			//sectionBI=firstMCO;
insilmaril@804
   622
			pagesBI=sectionBI;
insilmaril@183
   623
		}
insilmaril@183
   624
insilmaril@183
   625
		j=0;
insilmaril@804
   626
		while (pagesBI && !pagesBI->hasHiddenExportParent() )
insilmaril@183
   627
		{
insilmaril@183
   628
			// Add page with list of items
insilmaril@254
   629
			onePage=pageTemplate;
insilmaril@804
   630
			onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBI->getHeading() ) );
insilmaril@804
   631
			list=buildList (pagesBI);
insilmaril@254
   632
			onePage.replace ("<!-- INSERT LIST -->", list);
insilmaril@254
   633
			allPages+=onePage;
insilmaril@804
   634
			if (pagesBI!=sectionBI)
insilmaril@804
   635
			{
insilmaril@804
   636
				j++;
insilmaril@804
   637
				pagesBI=((BranchItem*)pagesBI->parent())->getBranchNum(j);
insilmaril@804
   638
			} else
insilmaril@804
   639
				pagesBI=NULL;	// We are already iterating over the sectionBIs
insilmaril@183
   640
		}
insilmaril@183
   641
		i++;
insilmaril@804
   642
		if (mapcenters>1 )
insilmaril@804
   643
			sectionBI=model->getRootItem()->getBranchNum (i);
insilmaril@804
   644
		else
insilmaril@804
   645
			sectionBI=firstMCO->getBranchNum (i);
insilmaril@183
   646
	}
insilmaril@183
   647
	
insilmaril@171
   648
	content.replace ("<!-- INSERT PAGES -->",allPages);
insilmaril@171
   649
insilmaril@171
   650
	// Write modified content
insilmaril@171
   651
	QFile f (contentFile);
insilmaril@366
   652
    if ( !f.open( QIODevice::WriteOnly ) ) 
insilmaril@171
   653
	{
insilmaril@205
   654
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
insilmaril@205
   655
		mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
insilmaril@171
   656
		return;
insilmaril@171
   657
    }
insilmaril@171
   658
insilmaril@171
   659
    QTextStream t( &f );
insilmaril@171
   660
    t << content;
insilmaril@171
   661
    f.close();
insilmaril@171
   662
insilmaril@163
   663
	// zip tmpdir to destination
insilmaril@171
   664
	zipDir (tmpDir,outputFile);	
insilmaril@163
   665
}
insilmaril@163
   666
insilmaril@194
   667
bool ExportOO::setConfigFile (const QString &cf)
insilmaril@183
   668
{
insilmaril@183
   669
	configFile=cf;
insilmaril@183
   670
	int i=cf.findRev ("/");
insilmaril@183
   671
	if (i>=0) configDir=cf.left(i);
insilmaril@183
   672
	SimpleSettings set;
insilmaril@183
   673
	set.readSettings(configFile);
insilmaril@183
   674
insilmaril@183
   675
	// set paths
insilmaril@183
   676
	templateDir=configDir+"/"+set.readEntry ("Template");
insilmaril@183
   677
insilmaril@194
   678
	QDir d (templateDir);
insilmaril@194
   679
	if (!d.exists())
insilmaril@194
   680
	{
insilmaril@194
   681
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
insilmaril@194
   682
		return false;
insilmaril@194
   683
insilmaril@194
   684
	}
insilmaril@183
   685
insilmaril@183
   686
	contentTemplateFile=templateDir+"content-template.xml";
insilmaril@183
   687
	contentFile=tmpDir.path()+"/content.xml";
insilmaril@183
   688
	pageTemplateFile=templateDir+"page-template.xml";
insilmaril@194
   689
	sectionTemplateFile=templateDir+"section-template.xml";
insilmaril@183
   690
insilmaril@199
   691
	if (set.readEntry("useSections").contains("yes"))
insilmaril@199
   692
		useSections=true;
insilmaril@199
   693
insilmaril@183
   694
	// Copy template to tmpdir
insilmaril@183
   695
	system ("cp -r "+templateDir+"* "+tmpDir.path());
insilmaril@183
   696
insilmaril@183
   697
	// Read content-template
insilmaril@183
   698
	if (!loadStringFromDisk (contentTemplateFile,content))
insilmaril@183
   699
	{
insilmaril@194
   700
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
insilmaril@194
   701
		return false;
insilmaril@183
   702
	}
insilmaril@183
   703
insilmaril@183
   704
	// Read page-template
insilmaril@183
   705
	if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
insilmaril@183
   706
	{
insilmaril@194
   707
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
insilmaril@194
   708
		return false;
insilmaril@183
   709
	}
insilmaril@183
   710
	
insilmaril@194
   711
	// Read section-template
insilmaril@201
   712
	if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
insilmaril@183
   713
	{
insilmaril@194
   714
		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));
insilmaril@194
   715
		return false;
insilmaril@183
   716
	}
insilmaril@194
   717
	return true;
insilmaril@183
   718
}
insilmaril@183
   719