exportxhtmldialog.ui.h
author insilmaril
Wed, 14 Jun 2006 14:43:18 +0000
branchqt4-port
changeset 6 db50e4164311
parent 2 608f976aa7bb
child 16 41c3d7f9f532
permissions -rw-r--r--
Basic editing works again
insilmaril@2
     1
//Added by qt3to4:
insilmaril@2
     2
#include <QPixmap>
insilmaril@2
     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@2
    15
extern QDir vymBaseDir;
insilmaril@2
    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@2
    22
	scriptProc=new Process;
insilmaril@0
    23
}
insilmaril@0
    24
insilmaril@0
    25
void ExportXHTMLDialog::readSettings()
insilmaril@0
    26
{
insilmaril@0
    27
insilmaril@2
    28
	dir=settings.readLocalEntry (filepath,"/vym/export/xhtml/exportDir",vymBaseDir.currentDirPath() );
insilmaril@0
    29
	lineEditDir->setText(dir);
insilmaril@0
    30
	
insilmaril@0
    31
    if ( settings.readLocalEntry (filepath,"/vym/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@0
    37
	if ( settings.readLocalEntry (filepath,"/vym/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@0
    44
	if ( settings.readEntry ("/vym/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@0
    51
	if ( settings.readLocalEntry (filepath,"/vym/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@0
    57
	if ( settings.readEntry ("/vym/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@0
    63
	if ( settings.readEntry ("/vym/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@2
    69
	// For testing better use local styles
insilmaril@2
    70
	if (options.isOn ("local"))
insilmaril@2
    71
	{
insilmaril@2
    72
		xsl=vymBaseDir.path()+"/styles/vym2xhtml.xsl";
insilmaril@2
    73
		css=vymBaseDir.path()+"/styles/vym.css";
insilmaril@2
    74
	} else
insilmaril@2
    75
	{
insilmaril@2
    76
		xsl=settings.readLocalEntry 
insilmaril@2
    77
			(filepath,"/vym/export/xhtml/xsl","/usr/share/vym/styles/vym2xhtml.xsl");
insilmaril@2
    78
		css=settings.readLocalEntry 
insilmaril@2
    79
			(filepath,"/vym/export/xhtml/css","/usr/share/vym/styles/vym.css");	
insilmaril@2
    80
	}
insilmaril@0
    81
	lineEditXSL->setText(xsl);
insilmaril@0
    82
	lineEditCSS->setText(css);
insilmaril@0
    83
	
insilmaril@0
    84
	prescript=settings.readLocalEntry
insilmaril@0
    85
		(filepath,"/vym/export/xhtml/prescript","");
insilmaril@0
    86
	lineEditPreScript->setText (prescript);	
insilmaril@0
    87
	
insilmaril@0
    88
	postscript=settings.readLocalEntry
insilmaril@0
    89
		(filepath,"/vym/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@2
    96
		"would like to run scripts:\n\n"
insilmaril@2
    97
		"%1\n\n"
insilmaril@2
    98
		"Please check, if you really\n"
insilmaril@2
    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@2
   118
   	Q3FileDialog fd( this, tr("VYM - Export HTML to directory"));
insilmaril@2
   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@2
   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@2
   198
   	Q3FileDialog fd( this, tr("VYM - Path to XSL file"));
insilmaril@0
   199
	fd.setModal (true);
insilmaril@2
   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@2
   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@2
   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@0
   254
	settings.setLocalEntry (filepath,"/vym/export/xhtml/exportDir",dir);
insilmaril@0
   255
	settings.setLocalEntry (filepath,"/vym/export/xhtml/prescript",prescript);
insilmaril@0
   256
	settings.setLocalEntry (filepath,"/vym/export/xhtml/postscript",postscript);
insilmaril@0
   257
insilmaril@0
   258
    if (useImage)
insilmaril@0
   259
		settings.setLocalEntry (filepath,"/vym/export/xhtml/useImage","yes");
insilmaril@0
   260
    else
insilmaril@0
   261
		settings.setLocalEntry (filepath,"/vym/export/xhtml/useImage","no");	
insilmaril@0
   262
	
insilmaril@0
   263
  if (useTextColor)
insilmaril@0
   264
		settings.setLocalEntry (filepath,"/vym/export/xhtml/useTextColor","yes");
insilmaril@0
   265
    else
insilmaril@0
   266
		settings.setLocalEntry (filepath,"/vym/export/xhtml/useTextColor","no");	
insilmaril@0
   267
	
insilmaril@0
   268
   if (showWarnings)
insilmaril@0
   269
		settings.writeEntry ("/vym/export/xhtml/showWarnings","yes");
insilmaril@0
   270
    else
insilmaril@0
   271
		settings.writeEntry ("/vym/export/xhtml/showWarnings","no");	
insilmaril@0
   272
			
insilmaril@0
   273
	if (showOutput)
insilmaril@0
   274
		settings.writeEntry ("/vym/export/xhtml/showOutput","yes");
insilmaril@0
   275
	else
insilmaril@0
   276
		settings.writeEntry ("/vym/export/xhtml/showOutput","no");	
insilmaril@0
   277
insilmaril@2
   278
	QString ipath;	
insilmaril@2
   279
	ipath=vymBaseDir.path()+"/flags/flag-url-16x16.png";
insilmaril@2
   280
	if (!options.isOn ("local"))
insilmaril@2
   281
	{
insilmaril@2
   282
		settings.setLocalEntry 
insilmaril@2
   283
			(filepath,"/vym/export/xhtml/xsl",xsl);
insilmaril@2
   284
		settings.setLocalEntry 
insilmaril@2
   285
			(filepath,"/vym/export/xhtml/css",css);	
insilmaril@0
   286
	}
insilmaril@0
   287
insilmaril@2
   288
	// Provide a smaller URL-icon to improve Layout
insilmaril@2
   289
	QPixmap pm;
insilmaril@2
   290
	if (!pm.load(ipath,"PNG") )
insilmaril@2
   291
		QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(ipath));
insilmaril@2
   292
		
insilmaril@2
   293
		
insilmaril@2
   294
	if(!pm.save (dir + "flags/flag-url-16x16.png","PNG"))
insilmaril@2
   295
		QMessageBox::warning( 0, tr( "Warning" ),tr("Could not write %1").arg(ipath));
insilmaril@0
   296
	if (!saveSettingsInMap)
insilmaril@0
   297
		settings.clearLocal("/vym/export/xhtml");
insilmaril@0
   298
	else	
insilmaril@0
   299
		settings.setLocalEntry 
insilmaril@0
   300
			(filepath,"/vym/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@2
   305
	if (!css_src.open ( QIODevice::ReadOnly))
insilmaril@2
   306
		QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(css));
insilmaril@0
   307
	else
insilmaril@0
   308
	{
insilmaril@2
   309
		if (!css_dst.open( QIODevice::WriteOnly))
insilmaril@2
   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@2
   326
		p.addStringParam ("imagemap","images/"+mapname+".png");
insilmaril@0
   327
	if (useTextColor)
insilmaril@2
   328
		p.addStringParam ("use.textcolor","1");
insilmaril@2
   329
	p.addStringParam ("mapname",mapname+".vym");
insilmaril@0
   330
	
insilmaril@2
   331
	p.setOutputFile (dir+mapname+".html");
insilmaril@2
   332
	p.setInputFile (dir+mapname+".xml");
insilmaril@2
   333
	p.setXSLFile (xsl);
insilmaril@2
   334
	p.process();
insilmaril@2
   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@2
   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@2
   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@2
   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@2
   389
	p.addOutput ("\n");
insilmaril@2
   390
	p.addOutput (scriptProc->getErrout());
insilmaril@2
   391
	p.addOutput (scriptProc->getStdout());
insilmaril@0
   392
}