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