exportxhtmldialog.cpp
author insilmaril
Mon, 30 Oct 2006 12:39:37 +0000
changeset 396 445a5d5ee20b
parent 382 8b0ab4c0f767
child 408 c2a05fa925a1
permissions -rw-r--r--
Spanish doc is found, if LANG is set. Fixed wrong position of floatimages
insilmaril@382
     1
#include "exportxhtmldialog.h"
insilmaril@382
     2
insilmaril@382
     3
#include <QFileDialog>
insilmaril@382
     4
#include <QMessageBox>
insilmaril@382
     5
#include <QTextStream>
insilmaril@382
     6
insilmaril@382
     7
#include "options.h"
insilmaril@382
     8
#include "settings.h"
insilmaril@382
     9
insilmaril@382
    10
insilmaril@382
    11
extern Options options;
insilmaril@382
    12
extern QDir vymBaseDir;
insilmaril@382
    13
extern Settings settings;
insilmaril@382
    14
insilmaril@382
    15
ExportXHTMLDialog::ExportXHTMLDialog(QWidget* parent) : QDialog(parent)
insilmaril@382
    16
{
insilmaril@382
    17
    ui.setupUi(this);
insilmaril@382
    18
insilmaril@382
    19
	filepath="";
insilmaril@382
    20
	settingsChanged=false;
insilmaril@382
    21
	scriptProc=new Process;
insilmaril@382
    22
insilmaril@382
    23
    // signals and slots connections
insilmaril@382
    24
    connect(ui.browseExportDirButton, SIGNAL(pressed()), this, SLOT(browseDirectoryPressed()));
insilmaril@382
    25
    connect(ui.outputButton, SIGNAL(toggled(bool)), this, SLOT(outputButtonPressed(bool)));
insilmaril@382
    26
    connect(ui.browseXSLButton, SIGNAL(pressed()), this, SLOT(browseXSLPressed()));
insilmaril@382
    27
    connect(ui.browseCSSButton, SIGNAL(pressed()), this, SLOT(browseCSSPressed()));
insilmaril@382
    28
    connect(ui.imageButton, SIGNAL(toggled(bool)), this, SLOT(imageButtonPressed(bool)));
insilmaril@382
    29
    connect(ui.textColorButton, SIGNAL(toggled(bool)), this, SLOT(textcolorButtonPressed(bool)));
insilmaril@382
    30
    connect(ui.lineEditDir, SIGNAL(textChanged(const QString&)), this, SLOT(dirChanged()));
insilmaril@382
    31
    connect(ui.lineEditCSS, SIGNAL(textChanged(const QString&)), this, SLOT(cssChanged()));
insilmaril@382
    32
    connect(ui.lineEditXSL, SIGNAL(textChanged(const QString&)), this, SLOT(xslChanged()));
insilmaril@382
    33
    connect(ui.warningsButton, SIGNAL(toggled(bool)), this, SLOT(warningsButtonPressed(bool)));
insilmaril@382
    34
    connect(ui.saveSettingsInMapButton, SIGNAL(toggled(bool)), this, SLOT(saveSettingsInMapButtonPressed(bool)));
insilmaril@382
    35
    connect(ui.browsePreExportButton, SIGNAL(pressed()), this, SLOT(browsePreExportButtonPressed()));
insilmaril@382
    36
    connect(ui.lineEditPreScript, SIGNAL(textChanged(const QString&)), this, SLOT(prescriptChanged()));
insilmaril@382
    37
    connect(ui.lineEditPostScript, SIGNAL(textChanged(const QString&)), this, SLOT(postscriptChanged()));
insilmaril@382
    38
    connect(ui.browsePostExportButton, SIGNAL(pressed()), this, SLOT(browsePostExportButtonPressed()));
insilmaril@382
    39
}	
insilmaril@382
    40
insilmaril@382
    41
insilmaril@382
    42
void ExportXHTMLDialog::readSettings()
insilmaril@382
    43
{
insilmaril@382
    44
insilmaril@382
    45
	dir=settings.readLocalEntry (filepath,"/export/xhtml/exportDir",vymBaseDir.currentDirPath() );
insilmaril@382
    46
	ui.lineEditDir->setText(dir);
insilmaril@382
    47
	
insilmaril@382
    48
    if ( settings.readLocalEntry (filepath,"/export/xhtml/useImage","yes")=="yes")
insilmaril@382
    49
		useImage=true;
insilmaril@382
    50
	else	
insilmaril@382
    51
		useImage=false;
insilmaril@382
    52
	ui.imageButton->setChecked(useImage);
insilmaril@382
    53
		
insilmaril@382
    54
	if ( settings.readLocalEntry (filepath,"/export/xhtml/useTextColor","no")=="yes")
insilmaril@382
    55
		useTextColor=true;
insilmaril@382
    56
	else	
insilmaril@382
    57
		useTextColor=false;
insilmaril@382
    58
	ui.textColorButton->setChecked(useTextColor);
insilmaril@382
    59
	
insilmaril@382
    60
/* FIXME this was used in old html export, is not yet in new stylesheet
insilmaril@382
    61
	if ( settings.readEntry ("/export/html/useHeading","no")=="yes")
insilmaril@382
    62
		useHeading=true;
insilmaril@382
    63
	else	
insilmaril@382
    64
		useHeading=false;
insilmaril@382
    65
	checkBox4_2->setChecked(useHeading);
insilmaril@382
    66
*/		
insilmaril@382
    67
insilmaril@382
    68
	if ( settings.readLocalEntry (filepath,"/export/xhtml/saveSettingsInMap","no")=="yes")
insilmaril@382
    69
		saveSettingsInMap=true;
insilmaril@382
    70
	else	
insilmaril@382
    71
		saveSettingsInMap=false;
insilmaril@382
    72
	ui.saveSettingsInMapButton->setChecked(saveSettingsInMap);
insilmaril@382
    73
insilmaril@382
    74
	if ( settings.readEntry ("/export/xhtml/showWarnings","yes")=="yes")
insilmaril@382
    75
		showWarnings=true;
insilmaril@382
    76
	else	
insilmaril@382
    77
		showWarnings=false;
insilmaril@382
    78
	ui.warningsButton->setChecked(showWarnings);
insilmaril@382
    79
	
insilmaril@382
    80
	if ( settings.readEntry ("/export/xhtml/showOutput","no")=="yes")
insilmaril@382
    81
		showOutput=true;
insilmaril@382
    82
	else	
insilmaril@382
    83
		showOutput=false;
insilmaril@382
    84
	ui.outputButton->setChecked(showOutput);
insilmaril@382
    85
insilmaril@382
    86
	// For testing better use local styles
insilmaril@382
    87
	if (options.isOn ("local"))
insilmaril@382
    88
	{
insilmaril@382
    89
		xsl=vymBaseDir.path()+"/styles/vym2xhtml.xsl";
insilmaril@382
    90
		css=vymBaseDir.path()+"/styles/vym.css";
insilmaril@382
    91
	} else
insilmaril@382
    92
	{
insilmaril@382
    93
		xsl=settings.readLocalEntry 
insilmaril@382
    94
			(filepath,"/export/xhtml/xsl","/usr/share/vym/styles/vym2xhtml.xsl");
insilmaril@382
    95
		css=settings.readLocalEntry 
insilmaril@382
    96
			(filepath,"/export/xhtml/css","/usr/share/vym/styles/vym.css");	
insilmaril@382
    97
	}
insilmaril@382
    98
	ui.lineEditXSL->setText(xsl);
insilmaril@382
    99
	ui.lineEditCSS->setText(css);
insilmaril@382
   100
	
insilmaril@382
   101
	prescript=settings.readLocalEntry
insilmaril@382
   102
		(filepath,"/export/xhtml/prescript","");
insilmaril@382
   103
	ui.lineEditPreScript->setText (prescript);	
insilmaril@382
   104
	
insilmaril@382
   105
	postscript=settings.readLocalEntry
insilmaril@382
   106
		(filepath,"/export/xhtml/postscript","");
insilmaril@382
   107
	ui.lineEditPostScript->setText (postscript);	
insilmaril@382
   108
insilmaril@382
   109
	if (!prescript.isEmpty() || !postscript.isEmpty())
insilmaril@382
   110
	{
insilmaril@382
   111
		QMessageBox::warning( 0, tr( "Warning" ),tr(
insilmaril@382
   112
		"The settings saved in the map "
insilmaril@382
   113
		"would like to run scripts:\n\n"
insilmaril@382
   114
		"%1\n\n"
insilmaril@382
   115
		"Please check, if you really\n"
insilmaril@382
   116
		"want to allow this in your system!").arg(prescript+"  "+postscript));
insilmaril@382
   117
		
insilmaril@382
   118
	}
insilmaril@382
   119
}
insilmaril@382
   120
insilmaril@382
   121
void ExportXHTMLDialog::dirChanged()
insilmaril@382
   122
{
insilmaril@382
   123
	dir=ui.lineEditDir->text();
insilmaril@382
   124
	if (dir.right(1)!="/")
insilmaril@382
   125
		dir+="/";
insilmaril@382
   126
	settingsChanged=true;
insilmaril@382
   127
}
insilmaril@382
   128
insilmaril@382
   129
void ExportXHTMLDialog::browseDirectoryPressed()
insilmaril@382
   130
{
insilmaril@382
   131
   	QFileDialog fd( this);
insilmaril@382
   132
	fd.setMode (QFileDialog::DirectoryOnly);
insilmaril@382
   133
	fd.setCaption(tr("VYM - Export HTML to directory"));
insilmaril@382
   134
	fd.setModal (true);
insilmaril@382
   135
	fd.setDirectory (QDir::current());
insilmaril@382
   136
	fd.show();
insilmaril@382
   137
insilmaril@382
   138
	if ( fd.exec() == QDialog::Accepted )
insilmaril@382
   139
	{
insilmaril@382
   140
		dir=fd.selectedFile();
insilmaril@382
   141
		ui.lineEditDir->setText (dir );
insilmaril@382
   142
		settingsChanged=true;
insilmaril@382
   143
	}
insilmaril@382
   144
}
insilmaril@382
   145
insilmaril@382
   146
void ExportXHTMLDialog::imageButtonPressed(bool b)
insilmaril@382
   147
{
insilmaril@382
   148
	useImage=b;
insilmaril@382
   149
	settingsChanged=true;
insilmaril@382
   150
}
insilmaril@382
   151
insilmaril@382
   152
void ExportXHTMLDialog::textcolorButtonPressed(bool b)
insilmaril@382
   153
{
insilmaril@382
   154
	useTextColor=b;	
insilmaril@382
   155
	settingsChanged=true;
insilmaril@382
   156
}
insilmaril@382
   157
insilmaril@382
   158
void ExportXHTMLDialog::saveSettingsInMapButtonPressed(bool b)
insilmaril@382
   159
{
insilmaril@382
   160
	saveSettingsInMap=b;	
insilmaril@382
   161
	settingsChanged=true;
insilmaril@382
   162
}
insilmaril@382
   163
insilmaril@382
   164
void ExportXHTMLDialog::warningsButtonPressed(bool b)
insilmaril@382
   165
{
insilmaril@382
   166
	showWarnings=b;
insilmaril@382
   167
	settingsChanged=true;
insilmaril@382
   168
}
insilmaril@382
   169
insilmaril@382
   170
insilmaril@382
   171
void ExportXHTMLDialog::outputButtonPressed(bool b)
insilmaril@382
   172
{
insilmaril@382
   173
	showOutput=b;
insilmaril@382
   174
	settingsChanged=true;
insilmaril@382
   175
}
insilmaril@382
   176
insilmaril@382
   177
void ExportXHTMLDialog::cssChanged()
insilmaril@382
   178
{
insilmaril@382
   179
	css=ui.lineEditCSS->text();
insilmaril@382
   180
	settingsChanged=true;
insilmaril@382
   181
}
insilmaril@382
   182
insilmaril@382
   183
void ExportXHTMLDialog::browseCSSPressed()
insilmaril@382
   184
{
insilmaril@382
   185
   	QFileDialog fd( this);
insilmaril@382
   186
	fd.setModal (true);
insilmaril@382
   187
	fd.setFilter ("Cascading Stylesheet (*.css)");
insilmaril@382
   188
	fd.setDirectory (QDir::current());
insilmaril@382
   189
	fd.show();
insilmaril@382
   190
insilmaril@382
   191
	if ( fd.exec() == QDialog::Accepted )
insilmaril@382
   192
	{
insilmaril@382
   193
		css=fd.selectedFile();
insilmaril@382
   194
		ui.lineEditCSS->setText (css );
insilmaril@382
   195
		settingsChanged=true;
insilmaril@382
   196
	}
insilmaril@382
   197
}
insilmaril@382
   198
insilmaril@382
   199
void ExportXHTMLDialog::xslChanged()
insilmaril@382
   200
{
insilmaril@382
   201
	xsl=ui.lineEditXSL->text();
insilmaril@382
   202
	settingsChanged=true;
insilmaril@382
   203
}
insilmaril@382
   204
insilmaril@382
   205
void ExportXHTMLDialog::prescriptChanged()
insilmaril@382
   206
{
insilmaril@382
   207
	prescript=ui.lineEditPreScript->text();
insilmaril@382
   208
	settingsChanged=true;
insilmaril@382
   209
}
insilmaril@382
   210
insilmaril@382
   211
void ExportXHTMLDialog::browseXSLPressed()
insilmaril@382
   212
{
insilmaril@382
   213
   	QFileDialog fd( this);
insilmaril@382
   214
	fd.setModal (true);
insilmaril@382
   215
	fd.setFilter ("Extensible Stylesheet Language (*.xsl)");
insilmaril@382
   216
	fd.setDirectory (QDir::current());
insilmaril@382
   217
	fd.show();
insilmaril@382
   218
insilmaril@382
   219
	if ( fd.exec() == QDialog::Accepted )
insilmaril@382
   220
	{
insilmaril@382
   221
		xsl=fd.selectedFile();
insilmaril@382
   222
		ui.lineEditXSL->setText (xsl );
insilmaril@382
   223
		settingsChanged=true;
insilmaril@382
   224
	}
insilmaril@382
   225
}
insilmaril@382
   226
insilmaril@382
   227
void ExportXHTMLDialog::postscriptChanged()
insilmaril@382
   228
{
insilmaril@382
   229
	postscript=ui.lineEditPostScript->text();
insilmaril@382
   230
	settingsChanged=true;
insilmaril@382
   231
}
insilmaril@382
   232
insilmaril@382
   233
void ExportXHTMLDialog::browsePreExportButtonPressed()
insilmaril@382
   234
{
insilmaril@382
   235
	QFileDialog fd( this);
insilmaril@382
   236
	fd.setModal (true);
insilmaril@382
   237
	fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
insilmaril@382
   238
	fd.setDirectory (QDir::current());
insilmaril@382
   239
	fd.show();
insilmaril@382
   240
insilmaril@382
   241
	if ( fd.exec() == QDialog::Accepted )
insilmaril@382
   242
	{
insilmaril@382
   243
		prescript=fd.selectedFile();
insilmaril@382
   244
		ui.lineEditPreScript->setText (prescript );
insilmaril@382
   245
		settingsChanged=true;
insilmaril@382
   246
	}
insilmaril@382
   247
insilmaril@382
   248
}
insilmaril@382
   249
insilmaril@382
   250
void ExportXHTMLDialog::browsePostExportButtonPressed()
insilmaril@382
   251
{
insilmaril@382
   252
	QFileDialog fd( this);
insilmaril@382
   253
	fd.setModal (true);
insilmaril@382
   254
	fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
insilmaril@382
   255
	fd.setDirectory (QDir::current());
insilmaril@382
   256
	fd.show();
insilmaril@382
   257
insilmaril@382
   258
	if ( fd.exec() == QDialog::Accepted )
insilmaril@382
   259
	{
insilmaril@382
   260
		postscript=fd.selectedFile();
insilmaril@382
   261
		ui.lineEditPostScript->setText (postscript );
insilmaril@382
   262
		settingsChanged=true;
insilmaril@382
   263
	}
insilmaril@382
   264
}
insilmaril@382
   265
insilmaril@382
   266
insilmaril@382
   267
void ExportXHTMLDialog::doExport (const QString &mapname)
insilmaril@382
   268
{
insilmaril@382
   269
	// Save options to settings file 
insilmaril@382
   270
	// (but don't save at destructor, which
insilmaril@382
   271
	// is called for "cancel", too)
insilmaril@382
   272
	settings.setLocalEntry (filepath,"/export/xhtml/exportDir",dir);
insilmaril@382
   273
	settings.setLocalEntry (filepath,"/export/xhtml/prescript",prescript);
insilmaril@382
   274
	settings.setLocalEntry (filepath,"/export/xhtml/postscript",postscript);
insilmaril@382
   275
insilmaril@382
   276
    if (useImage)
insilmaril@382
   277
		settings.setLocalEntry (filepath,"/export/xhtml/useImage","yes");
insilmaril@382
   278
    else
insilmaril@382
   279
		settings.setLocalEntry (filepath,"/export/xhtml/useImage","no");	
insilmaril@382
   280
	
insilmaril@382
   281
  if (useTextColor)
insilmaril@382
   282
		settings.setLocalEntry (filepath,"/export/xhtml/useTextColor","yes");
insilmaril@382
   283
    else
insilmaril@382
   284
		settings.setLocalEntry (filepath,"/export/xhtml/useTextColor","no");	
insilmaril@382
   285
	
insilmaril@382
   286
   if (showWarnings)
insilmaril@382
   287
		settings.writeEntry ("/export/xhtml/showWarnings","yes");
insilmaril@382
   288
    else
insilmaril@382
   289
		settings.writeEntry ("/export/xhtml/showWarnings","no");	
insilmaril@382
   290
			
insilmaril@382
   291
	if (showOutput)
insilmaril@382
   292
		settings.writeEntry ("/export/xhtml/showOutput","yes");
insilmaril@382
   293
	else
insilmaril@382
   294
		settings.writeEntry ("/export/xhtml/showOutput","no");	
insilmaril@382
   295
insilmaril@382
   296
	QString ipath;	
insilmaril@382
   297
	ipath=vymBaseDir.path()+"/flags/flag-url-16x16.png";
insilmaril@382
   298
	if (!options.isOn ("local"))
insilmaril@382
   299
	{
insilmaril@382
   300
		settings.setLocalEntry 
insilmaril@382
   301
			(filepath,"/export/xhtml/xsl",xsl);
insilmaril@382
   302
		settings.setLocalEntry 
insilmaril@382
   303
			(filepath,"/export/xhtml/css",css);	
insilmaril@382
   304
	}
insilmaril@382
   305
insilmaril@382
   306
	// Provide a smaller URL-icon to improve Layout
insilmaril@382
   307
	QPixmap pm;
insilmaril@382
   308
	if (!pm.load(ipath,"PNG") )
insilmaril@382
   309
		QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(ipath));
insilmaril@382
   310
		
insilmaril@382
   311
		
insilmaril@382
   312
	if(!pm.save (dir + "flags/flag-url-16x16.png","PNG"))
insilmaril@382
   313
		QMessageBox::warning( 0, tr( "Warning" ),tr("Could not write %1").arg(ipath));
insilmaril@382
   314
	if (!saveSettingsInMap)
insilmaril@382
   315
		settings.clearLocal("/export/xhtml");
insilmaril@382
   316
	else	
insilmaril@382
   317
		settings.setLocalEntry 
insilmaril@382
   318
			(filepath,"/export/xhtml/saveSettingsInMap","yes");
insilmaril@382
   319
insilmaril@382
   320
	// Copy CSS file
insilmaril@382
   321
	QFile css_src (css);
insilmaril@382
   322
	QFile css_dst (dir+"vym.css");
insilmaril@382
   323
	if (!css_src.open ( QIODevice::ReadOnly))
insilmaril@382
   324
		QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(css));
insilmaril@382
   325
	else
insilmaril@382
   326
	{
insilmaril@382
   327
		if (!css_dst.open( QIODevice::WriteOnly))
insilmaril@382
   328
			QMessageBox::warning( 0, tr( "Warning" ), tr("Could not open %1").arg(dir+"vym.css"));
insilmaril@382
   329
		else
insilmaril@382
   330
		{	
insilmaril@382
   331
		
insilmaril@382
   332
			QTextStream tsout( &css_dst);
insilmaril@382
   333
			QTextStream tsin ( &css_src);
insilmaril@382
   334
			QString s= tsin.read();
insilmaril@382
   335
			tsout << s;
insilmaril@382
   336
			css_dst.close();
insilmaril@382
   337
		}	
insilmaril@382
   338
		css_src.close();
insilmaril@382
   339
	}
insilmaril@382
   340
insilmaril@382
   341
	if (!prescript.isEmpty()) runScript (prescript,dir+mapname+".xml");
insilmaril@382
   342
	
insilmaril@382
   343
	if (useImage)
insilmaril@382
   344
		p.addStringParam ("imagemap","images/"+mapname+".png");
insilmaril@382
   345
	if (useTextColor)
insilmaril@382
   346
		p.addStringParam ("use.textcolor","1");
insilmaril@382
   347
	p.addStringParam ("mapname",mapname+".vym");
insilmaril@382
   348
	
insilmaril@382
   349
	p.setOutputFile (dir+mapname+".html");
insilmaril@382
   350
	p.setInputFile (dir+mapname+".xml");
insilmaril@382
   351
	p.setXSLFile (xsl);
insilmaril@382
   352
	p.process();
insilmaril@382
   353
insilmaril@382
   354
	if (!postscript.isEmpty()) runScript (postscript,dir+mapname+".html");
insilmaril@382
   355
insilmaril@382
   356
}
insilmaril@382
   357
insilmaril@382
   358
void ExportXHTMLDialog::setFilePath(const QString &s)
insilmaril@382
   359
{
insilmaril@382
   360
	filepath=s;
insilmaril@382
   361
}
insilmaril@382
   362
insilmaril@382
   363
void ExportXHTMLDialog::setMapName(const QString &s)
insilmaril@382
   364
{
insilmaril@382
   365
	mapname=s;
insilmaril@382
   366
}
insilmaril@382
   367
insilmaril@382
   368
QString ExportXHTMLDialog::getDir()
insilmaril@382
   369
{
insilmaril@382
   370
	return dir;
insilmaril@382
   371
}
insilmaril@382
   372
insilmaril@382
   373
bool ExportXHTMLDialog::warnings()
insilmaril@382
   374
{
insilmaril@382
   375
	return showWarnings;
insilmaril@382
   376
}
insilmaril@382
   377
insilmaril@382
   378
bool ExportXHTMLDialog::hasChanged()
insilmaril@382
   379
{
insilmaril@382
   380
	return settingsChanged;
insilmaril@382
   381
}
insilmaril@382
   382
insilmaril@382
   383
insilmaril@382
   384
void ExportXHTMLDialog::runScript(QString spath, QString fpath)
insilmaril@382
   385
{
insilmaril@382
   386
	spath.replace ("%f",fpath);
insilmaril@382
   387
	QStringList args=QStringList::split (' ',spath,false);
insilmaril@382
   388
		
insilmaril@382
   389
	scriptProc->clearArguments();
insilmaril@382
   390
	scriptProc->setArguments (args);	
insilmaril@382
   391
	p.addOutput ("vym is executing: \n" + scriptProc->arguments().join(" ") );	
insilmaril@382
   392
	if (!scriptProc->start() )
insilmaril@382
   393
	{
insilmaril@382
   394
		QMessageBox::critical( 0, tr( "Critical Error" ),
insilmaril@382
   395
					   tr("Could not start %1").arg(spath) );
insilmaril@382
   396
	} else
insilmaril@382
   397
	{
insilmaril@382
   398
		scriptProc->waitFinished();
insilmaril@382
   399
		if (!scriptProc->normalExit() )
insilmaril@382
   400
			QMessageBox::critical( 0, tr( "Critical Error" ),
insilmaril@382
   401
			   tr("%1 didn't exit normally").arg(spath) +
insilmaril@382
   402
			   scriptProc->getErrout() );
insilmaril@382
   403
		else
insilmaril@382
   404
			if (scriptProc->exitStatus()>0) showOutput=true;
insilmaril@382
   405
			
insilmaril@382
   406
	}	
insilmaril@382
   407
	p.addOutput ("\n");
insilmaril@382
   408
	p.addOutput (scriptProc->getErrout());
insilmaril@382
   409
	p.addOutput (scriptProc->getStdout());
insilmaril@382
   410
}
insilmaril@382
   411