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