exportxhtmldialog.ui.h
author insilmaril
Wed Jan 25 12:34:55 2006 +0000 (2006-01-25)
changeset 197 d529766ed9db
parent 0 7a96bd401351
child 203 1ced9d88d82d
permissions -rw-r--r--
Fixed outputFile in OO export
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@194
    86
		"would like to run scripts:\n\n"
insilmaril@194
    87
		"%1\n\n"
insilmaril@194
    88
		"Please check, if you really\n"
insilmaril@194
    89
		"want to allow this in your system!").arg(prescript+"  "+postscript));
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@194
   275
	// Provide a smaller URL-icon to improve Layout
insilmaril@194
   276
	QPixmap pm;
insilmaril@194
   277
	QString ipath="/usr/share/vym/images/flag-url-16x16.png";
insilmaril@194
   278
	if (!pm.load(ipath,"PNG") )
insilmaril@194
   279
		QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(ipath));
insilmaril@194
   280
		
insilmaril@194
   281
		
insilmaril@194
   282
	if(!pm.save (dir + "flags/url-16x16.png","PNG"))
insilmaril@194
   283
		QMessageBox::warning( 0, tr( "Warning" ),tr("Could not write %1").arg(ipath));
insilmaril@0
   284
insilmaril@0
   285
	if (!saveSettingsInMap)
insilmaril@0
   286
		settings.clearLocal("/vym/export/xhtml");
insilmaril@0
   287
	else	
insilmaril@0
   288
		settings.setLocalEntry 
insilmaril@0
   289
			(filepath,"/vym/export/xhtml/saveSettingsInMap","yes");
insilmaril@0
   290
insilmaril@0
   291
	// Copy CSS file
insilmaril@0
   292
	QFile css_src (css);
insilmaril@0
   293
	QFile css_dst (dir+"vym.css");
insilmaril@0
   294
	if (!css_src.open ( IO_ReadOnly))
insilmaril@194
   295
		QMessageBox::warning( 0, tr( "Warning" ),+tr("Could not open %1").arg(css));
insilmaril@0
   296
	else
insilmaril@0
   297
	{
insilmaril@0
   298
		if (!css_dst.open( IO_WriteOnly))
insilmaril@194
   299
			QMessageBox::warning( 0, tr( "Warning" ), tr("Could not open!").arg(dir+"vym.css"));
insilmaril@0
   300
		else
insilmaril@0
   301
		{	
insilmaril@0
   302
		
insilmaril@0
   303
			QTextStream tsout( &css_dst);
insilmaril@0
   304
			QTextStream tsin ( &css_src);
insilmaril@0
   305
			QString s= tsin.read();
insilmaril@0
   306
			tsout << s;
insilmaril@0
   307
			css_dst.close();
insilmaril@0
   308
		}	
insilmaril@0
   309
		css_src.close();
insilmaril@0
   310
	}
insilmaril@0
   311
insilmaril@0
   312
	if (!prescript.isEmpty()) runScript (prescript,dir+mapname+".xml");
insilmaril@0
   313
	
insilmaril@0
   314
	Process *xsltProc=new Process ();
insilmaril@0
   315
	xsltProc->clearArguments();
insilmaril@0
   316
	xsltProc->addArgument (xsltprocessor);	
insilmaril@0
   317
	if (useImage)
insilmaril@0
   318
	{
insilmaril@0
   319
		xsltProc->addArgument ("--stringparam");
insilmaril@0
   320
		xsltProc->addArgument ("imagemap");
insilmaril@0
   321
		xsltProc->addArgument ("images/"+mapname+".png");
insilmaril@0
   322
	}	
insilmaril@0
   323
	if (useTextColor)
insilmaril@0
   324
	{
insilmaril@0
   325
		xsltProc->addArgument ("--stringparam");
insilmaril@0
   326
		xsltProc->addArgument ("use.textcolor");
insilmaril@0
   327
		xsltProc->addArgument ("1");
insilmaril@0
   328
	}	
insilmaril@0
   329
	xsltProc->addArgument ("--stringparam");
insilmaril@0
   330
	xsltProc->addArgument ("mapname");
insilmaril@0
   331
	xsltProc->addArgument (mapname+".vym");
insilmaril@0
   332
	
insilmaril@0
   333
	xsltProc->addArgument ("--output");
insilmaril@0
   334
	xsltProc->addArgument (dir+mapname+".html");
insilmaril@0
   335
	xsltProc->addArgument (xsl);
insilmaril@0
   336
	xsltProc->addArgument (dir+mapname+".xml");
insilmaril@0
   337
	dia->append ("vym is executing: \n" + xsltProc->arguments().join(" ") );	
insilmaril@0
   338
	if (!xsltProc->start() )
insilmaril@0
   339
	{
insilmaril@0
   340
		QMessageBox::critical( 0, tr( "Critical Error" ),
insilmaril@194
   341
					   tr("Could not start %1").arg(xsltprocessor) );
insilmaril@0
   342
	} else
insilmaril@0
   343
	{
insilmaril@0
   344
		xsltProc->waitFinished();
insilmaril@0
   345
		if (!xsltProc->normalExit() )
insilmaril@0
   346
			QMessageBox::critical( 0, tr( "Critical Error" ),
insilmaril@194
   347
			   tr("%1 didn't exit normally").arg(xsltprocessor) +
insilmaril@0
   348
			   xsltProc->getErrout() );
insilmaril@0
   349
		else
insilmaril@0
   350
			if (xsltProc->exitStatus()>0) showOutput=true;
insilmaril@0
   351
			
insilmaril@0
   352
	}	
insilmaril@0
   353
	dia->append ("\n");
insilmaril@0
   354
	dia->append (xsltProc->getErrout());
insilmaril@0
   355
	dia->append (xsltProc->getStdout());
insilmaril@0
   356
	
insilmaril@0
   357
	if (!postscript.isEmpty()) runScript (postscript,dir+mapname+".html");
insilmaril@0
   358
insilmaril@0
   359
	if (showOutput) dia->exec();
insilmaril@0
   360
}
insilmaril@0
   361
insilmaril@0
   362
void ExportXHTMLDialog::setFilePath(const QString &s)
insilmaril@0
   363
{
insilmaril@0
   364
	filepath=s;
insilmaril@0
   365
}
insilmaril@0
   366
insilmaril@0
   367
void ExportXHTMLDialog::setMapName(const QString &s)
insilmaril@0
   368
{
insilmaril@0
   369
	mapname=s;
insilmaril@0
   370
}
insilmaril@0
   371
insilmaril@0
   372
QString ExportXHTMLDialog::getDir()
insilmaril@0
   373
{
insilmaril@0
   374
	return dir;
insilmaril@0
   375
}
insilmaril@0
   376
insilmaril@0
   377
bool ExportXHTMLDialog::warnings()
insilmaril@0
   378
{
insilmaril@0
   379
	return showWarnings;
insilmaril@0
   380
}
insilmaril@0
   381
insilmaril@0
   382
bool ExportXHTMLDialog::hasChanged()
insilmaril@0
   383
{
insilmaril@0
   384
	return settingsChanged;
insilmaril@0
   385
}
insilmaril@0
   386
insilmaril@0
   387
insilmaril@0
   388
void ExportXHTMLDialog::runScript(QString spath, QString fpath)
insilmaril@0
   389
{
insilmaril@0
   390
	spath.replace ("%f",fpath);
insilmaril@0
   391
	QStringList args=QStringList::split (' ',spath,false);
insilmaril@0
   392
		
insilmaril@0
   393
	Process *scriptProc=new Process ();
insilmaril@0
   394
	scriptProc->clearArguments();
insilmaril@0
   395
	scriptProc->setArguments (args);	
insilmaril@0
   396
	dia->append ("vym is executing: \n" + scriptProc->arguments().join(" ") );	
insilmaril@0
   397
	if (!scriptProc->start() )
insilmaril@0
   398
	{
insilmaril@0
   399
		QMessageBox::critical( 0, tr( "Critical Error" ),
insilmaril@194
   400
					   tr("Couldn't start %1").arg(spath) );
insilmaril@0
   401
	} else
insilmaril@0
   402
	{
insilmaril@0
   403
		scriptProc->waitFinished();
insilmaril@0
   404
		if (!scriptProc->normalExit() )
insilmaril@0
   405
			QMessageBox::critical( 0, tr( "Critical Error" ),
insilmaril@194
   406
			   tr("%1 didn't exit normally").arg(spath) +
insilmaril@0
   407
			   scriptProc->getErrout() );
insilmaril@0
   408
		else
insilmaril@0
   409
			if (scriptProc->exitStatus()>0) showOutput=true;
insilmaril@0
   410
			
insilmaril@0
   411
	}	
insilmaril@0
   412
	dia->append ("\n");
insilmaril@0
   413
	dia->append (scriptProc->getErrout());
insilmaril@0
   414
	dia->append (scriptProc->getStdout());
insilmaril@0
   415
}