exportxhtmldialog.cpp
changeset 845 b98c1793bb8b
parent 844 c48bb42fb977
child 846 f0fe7c36ec5c
     1.1 --- a/exportxhtmldialog.cpp	Wed Apr 07 10:45:24 2010 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,418 +0,0 @@
     1.4 -#include "exportxhtmldialog.h"
     1.5 -
     1.6 -#include <QFileDialog>
     1.7 -#include <QMessageBox>
     1.8 -#include <QTextStream>
     1.9 -
    1.10 -#include "options.h"
    1.11 -#include "settings.h"
    1.12 -
    1.13 -
    1.14 -extern Options options;
    1.15 -extern QDir vymBaseDir;
    1.16 -extern Settings settings;
    1.17 -extern bool debug;
    1.18 -
    1.19 -ExportXHTMLDialog::ExportXHTMLDialog(QWidget* parent) : QDialog(parent)
    1.20 -{
    1.21 -    ui.setupUi(this);
    1.22 -
    1.23 -	filepath="";
    1.24 -	settingsChanged=false;
    1.25 -	scriptProc=new Process;
    1.26 -
    1.27 -    // signals and slots connections
    1.28 -    connect(ui.browseExportDirButton, SIGNAL(pressed()), this, SLOT(browseDirectoryPressed()));
    1.29 -    connect(ui.outputButton, SIGNAL(toggled(bool)), this, SLOT(outputButtonPressed(bool)));
    1.30 -    connect(ui.browseXSLButton, SIGNAL(pressed()), this, SLOT(browseXSLPressed()));
    1.31 -    connect(ui.browseCSSButton, SIGNAL(pressed()), this, SLOT(browseCSSPressed()));
    1.32 -    connect(ui.imageButton, SIGNAL(toggled(bool)), this, SLOT(imageButtonPressed(bool)));
    1.33 -    connect(ui.textColorButton, SIGNAL(toggled(bool)), this, SLOT(textcolorButtonPressed(bool)));
    1.34 -    connect(ui.lineEditDir, SIGNAL(textChanged(const QString&)), this, SLOT(dirChanged()));
    1.35 -    connect(ui.lineEditCSS, SIGNAL(textChanged(const QString&)), this, SLOT(cssChanged()));
    1.36 -    connect(ui.lineEditXSL, SIGNAL(textChanged(const QString&)), this, SLOT(xslChanged()));
    1.37 -    connect(ui.warningsButton, SIGNAL(toggled(bool)), this, SLOT(warningsButtonPressed(bool)));
    1.38 -    connect(ui.saveSettingsInMapButton, SIGNAL(toggled(bool)), this, SLOT(saveSettingsInMapButtonPressed(bool)));
    1.39 -    connect(ui.browsePreExportButton, SIGNAL(pressed()), this, SLOT(browsePreExportButtonPressed()));
    1.40 -    connect(ui.lineEditPreScript, SIGNAL(textChanged(const QString&)), this, SLOT(prescriptChanged()));
    1.41 -    connect(ui.lineEditPostScript, SIGNAL(textChanged(const QString&)), this, SLOT(postscriptChanged()));
    1.42 -    connect(ui.browsePostExportButton, SIGNAL(pressed()), this, SLOT(browsePostExportButtonPressed()));
    1.43 -}	
    1.44 -
    1.45 -
    1.46 -void ExportXHTMLDialog::readSettings()
    1.47 -{
    1.48 -
    1.49 -	dir=settings.readLocalEntry (filepath,"/export/xhtml/exportDir",vymBaseDir.currentDirPath() );
    1.50 -	ui.lineEditDir->setText(dir);
    1.51 -	
    1.52 -    if ( settings.readLocalEntry (filepath,"/export/xhtml/useImage","yes")=="yes")
    1.53 -		useImage=true;
    1.54 -	else	
    1.55 -		useImage=false;
    1.56 -	ui.imageButton->setChecked(useImage);
    1.57 -		
    1.58 -	if ( settings.readLocalEntry (filepath,"/export/xhtml/useTextColor","no")=="yes")
    1.59 -		useTextColor=true;
    1.60 -	else	
    1.61 -		useTextColor=false;
    1.62 -	ui.textColorButton->setChecked(useTextColor);
    1.63 -	
    1.64 -/* TODO this was used in old html export, is not yet in new stylesheet
    1.65 -	if ( settings.readEntry ("/export/html/useHeading","no")=="yes")
    1.66 -		useHeading=true;
    1.67 -	else	
    1.68 -		useHeading=false;
    1.69 -	checkBox4_2->setChecked(useHeading);
    1.70 -*/		
    1.71 -
    1.72 -	if ( settings.readLocalEntry (filepath,"/export/xhtml/saveSettingsInMap","no")=="yes")
    1.73 -		saveSettingsInMap=true;
    1.74 -	else	
    1.75 -		saveSettingsInMap=false;
    1.76 -	ui.saveSettingsInMapButton->setChecked(saveSettingsInMap);
    1.77 -
    1.78 -	if ( settings.readEntry ("/export/xhtml/showWarnings","yes")=="yes")
    1.79 -		showWarnings=true;
    1.80 -	else	
    1.81 -		showWarnings=false;
    1.82 -	ui.warningsButton->setChecked(showWarnings);
    1.83 -	
    1.84 -	if ( settings.readEntry ("/export/xhtml/showOutput","no")=="yes")
    1.85 -		showOutput=true;
    1.86 -	else	
    1.87 -		showOutput=false;
    1.88 -	ui.outputButton->setChecked(showOutput);
    1.89 -
    1.90 -	// For testing better use local styles
    1.91 -    const QString defxsl(vymBaseDir.path() + "/styles/vym2xhtml.xsl");
    1.92 -    const QString defcss(vymBaseDir.path() + "/styles/vym.css");
    1.93 -	if (options.isOn ("local"))
    1.94 -	{
    1.95 -		xsl=defxsl;
    1.96 -		css=defcss;
    1.97 -	} else
    1.98 -	{
    1.99 -		xsl=settings.readLocalEntry 
   1.100 -			(filepath,"/export/xhtml/xsl",defxsl);
   1.101 -		css=settings.readLocalEntry 
   1.102 -			(filepath,"/export/xhtml/css",defcss);	
   1.103 -	}
   1.104 -	ui.lineEditXSL->setText(xsl);
   1.105 -	ui.lineEditCSS->setText(css);
   1.106 -	
   1.107 -	prescript=settings.readLocalEntry
   1.108 -		(filepath,"/export/xhtml/prescript","");
   1.109 -	ui.lineEditPreScript->setText (prescript);	
   1.110 -	
   1.111 -	postscript=settings.readLocalEntry
   1.112 -		(filepath,"/export/xhtml/postscript","");
   1.113 -	ui.lineEditPostScript->setText (postscript);	
   1.114 -
   1.115 -	if (!prescript.isEmpty() || !postscript.isEmpty())
   1.116 -	{
   1.117 -		QMessageBox::warning( 0, tr( "Warning" ),tr(
   1.118 -		"The settings saved in the map "
   1.119 -		"would like to run scripts:\n\n"
   1.120 -		"%1\n\n"
   1.121 -		"Please check, if you really\n"
   1.122 -		"want to allow this in your system!").arg(prescript+"  "+postscript));
   1.123 -		
   1.124 -	}
   1.125 -}
   1.126 -
   1.127 -void ExportXHTMLDialog::setDir(const QString &d)
   1.128 -{
   1.129 -	dir=d;
   1.130 -	if (dir.right(1)!="/") dir+="/";
   1.131 -}
   1.132 -
   1.133 -void ExportXHTMLDialog::dirChanged()
   1.134 -{
   1.135 -	setDir (ui.lineEditDir->text());
   1.136 -	settingsChanged=true;
   1.137 -}
   1.138 -
   1.139 -void ExportXHTMLDialog::browseDirectoryPressed()
   1.140 -{
   1.141 -   	QFileDialog fd( this);
   1.142 -	fd.setMode (QFileDialog::DirectoryOnly);
   1.143 -	fd.setCaption(tr("VYM - Export HTML to directory"));
   1.144 -	fd.setModal (true);
   1.145 -	fd.setDirectory (QDir::current());
   1.146 -	fd.show();
   1.147 -
   1.148 -	if ( fd.exec() == QDialog::Accepted )
   1.149 -	{
   1.150 -		dir=fd.selectedFile();
   1.151 -		ui.lineEditDir->setText (dir );
   1.152 -		settingsChanged=true;
   1.153 -	}
   1.154 -}
   1.155 -
   1.156 -void ExportXHTMLDialog::imageButtonPressed(bool b)
   1.157 -{
   1.158 -	useImage=b;
   1.159 -	settingsChanged=true;
   1.160 -}
   1.161 -
   1.162 -void ExportXHTMLDialog::textcolorButtonPressed(bool b)
   1.163 -{
   1.164 -	useTextColor=b;	
   1.165 -	settingsChanged=true;
   1.166 -}
   1.167 -
   1.168 -void ExportXHTMLDialog::saveSettingsInMapButtonPressed(bool b)
   1.169 -{
   1.170 -	saveSettingsInMap=b;	
   1.171 -	settingsChanged=true;
   1.172 -}
   1.173 -
   1.174 -void ExportXHTMLDialog::warningsButtonPressed(bool b)
   1.175 -{
   1.176 -	showWarnings=b;
   1.177 -	settingsChanged=true;
   1.178 -}
   1.179 -
   1.180 -
   1.181 -void ExportXHTMLDialog::outputButtonPressed(bool b)
   1.182 -{
   1.183 -	showOutput=b;
   1.184 -	settingsChanged=true;
   1.185 -}
   1.186 -
   1.187 -void ExportXHTMLDialog::cssChanged()
   1.188 -{
   1.189 -	css=ui.lineEditCSS->text();
   1.190 -	settingsChanged=true;
   1.191 -}
   1.192 -
   1.193 -void ExportXHTMLDialog::browseCSSPressed()
   1.194 -{
   1.195 -   	QFileDialog fd( this);
   1.196 -	fd.setModal (true);
   1.197 -	fd.setFilter ("Cascading Stylesheet (*.css)");
   1.198 -	fd.setDirectory (QDir::current());
   1.199 -	fd.show();
   1.200 -
   1.201 -	if ( fd.exec() == QDialog::Accepted )
   1.202 -	{
   1.203 -		css=fd.selectedFile();
   1.204 -		ui.lineEditCSS->setText (css );
   1.205 -		settingsChanged=true;
   1.206 -	}
   1.207 -}
   1.208 -
   1.209 -void ExportXHTMLDialog::xslChanged()
   1.210 -{
   1.211 -	xsl=ui.lineEditXSL->text();
   1.212 -	settingsChanged=true;
   1.213 -}
   1.214 -
   1.215 -void ExportXHTMLDialog::prescriptChanged()
   1.216 -{
   1.217 -	prescript=ui.lineEditPreScript->text();
   1.218 -	settingsChanged=true;
   1.219 -}
   1.220 -
   1.221 -void ExportXHTMLDialog::browseXSLPressed()
   1.222 -{
   1.223 -   	QFileDialog fd( this);
   1.224 -	fd.setModal (true);
   1.225 -	fd.setFilter ("Extensible Stylesheet Language (*.xsl)");
   1.226 -	fd.setDirectory (QDir::current());
   1.227 -	fd.show();
   1.228 -
   1.229 -	if ( fd.exec() == QDialog::Accepted )
   1.230 -	{
   1.231 -		xsl=fd.selectedFile();
   1.232 -		ui.lineEditXSL->setText (xsl );
   1.233 -		settingsChanged=true;
   1.234 -	}
   1.235 -}
   1.236 -
   1.237 -void ExportXHTMLDialog::postscriptChanged()
   1.238 -{
   1.239 -	postscript=ui.lineEditPostScript->text();
   1.240 -	settingsChanged=true;
   1.241 -}
   1.242 -
   1.243 -void ExportXHTMLDialog::browsePreExportButtonPressed()
   1.244 -{
   1.245 -	QFileDialog fd( this);
   1.246 -	fd.setModal (true);
   1.247 -	fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
   1.248 -	fd.setDirectory (QDir::current());
   1.249 -	fd.show();
   1.250 -
   1.251 -	if ( fd.exec() == QDialog::Accepted )
   1.252 -	{
   1.253 -		prescript=fd.selectedFile();
   1.254 -		ui.lineEditPreScript->setText (prescript );
   1.255 -		settingsChanged=true;
   1.256 -	}
   1.257 -
   1.258 -}
   1.259 -
   1.260 -void ExportXHTMLDialog::browsePostExportButtonPressed()
   1.261 -{
   1.262 -	QFileDialog fd( this);
   1.263 -	fd.setModal (true);
   1.264 -	fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
   1.265 -	fd.setDirectory (QDir::current());
   1.266 -	fd.show();
   1.267 -
   1.268 -	if ( fd.exec() == QDialog::Accepted )
   1.269 -	{
   1.270 -		postscript=fd.selectedFile();
   1.271 -		ui.lineEditPostScript->setText (postscript );
   1.272 -		settingsChanged=true;
   1.273 -	}
   1.274 -}
   1.275 -
   1.276 -
   1.277 -void ExportXHTMLDialog::doExport (const QString &mapname)
   1.278 -{
   1.279 -
   1.280 -	// Save options to settings file 
   1.281 -	// (but don't save at destructor, which
   1.282 -	// is called for "cancel", too)
   1.283 -	settings.setLocalEntry (filepath,"/export/xhtml/exportDir",dir);
   1.284 -	settings.setLocalEntry (filepath,"/export/xhtml/prescript",prescript);
   1.285 -	settings.setLocalEntry (filepath,"/export/xhtml/postscript",postscript);
   1.286 -
   1.287 -    if (useImage)
   1.288 -		settings.setLocalEntry (filepath,"/export/xhtml/useImage","yes");
   1.289 -    else
   1.290 -		settings.setLocalEntry (filepath,"/export/xhtml/useImage","no");	
   1.291 -	
   1.292 -  if (useTextColor)
   1.293 -		settings.setLocalEntry (filepath,"/export/xhtml/useTextColor","yes");
   1.294 -    else
   1.295 -		settings.setLocalEntry (filepath,"/export/xhtml/useTextColor","no");	
   1.296 -	
   1.297 -   if (showWarnings)
   1.298 -		settings.writeEntry ("/export/xhtml/showWarnings","yes");
   1.299 -    else
   1.300 -		settings.writeEntry ("/export/xhtml/showWarnings","no");	
   1.301 -			
   1.302 -	if (showOutput)
   1.303 -		settings.writeEntry ("/export/xhtml/showOutput","yes");
   1.304 -	else
   1.305 -		settings.writeEntry ("/export/xhtml/showOutput","no");	
   1.306 -
   1.307 -	QString ipath;	
   1.308 -	ipath=vymBaseDir.path()+"/flags/flag-url-16x16.png";
   1.309 -	if (!options.isOn ("local"))
   1.310 -	{
   1.311 -		settings.setLocalEntry 
   1.312 -			(filepath,"/export/xhtml/xsl",xsl);
   1.313 -		settings.setLocalEntry 
   1.314 -			(filepath,"/export/xhtml/css",css);	
   1.315 -	}
   1.316 -
   1.317 -	if (!saveSettingsInMap)
   1.318 -		settings.clearLocal("/export/xhtml");
   1.319 -	else	
   1.320 -		settings.setLocalEntry 
   1.321 -			(filepath,"/export/xhtml/saveSettingsInMap","yes");
   1.322 -
   1.323 -	// Provide a smaller URL-icon to improve Layout
   1.324 -	QPixmap pm;
   1.325 -	if (!pm.load(ipath,"PNG") )
   1.326 -		QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(ipath));
   1.327 -		
   1.328 -		
   1.329 -	if(!pm.save (dir + "flags/flag-url-16x16.png","PNG"))
   1.330 -		QMessageBox::warning( 0, tr( "Warning" ),tr("Could not write %1").arg(ipath));
   1.331 -
   1.332 -	// Copy CSS file
   1.333 -	QFile css_src (css);
   1.334 -	QFile css_dst (dir+"vym.css");
   1.335 -	if (!css_src.open ( QIODevice::ReadOnly))
   1.336 -		QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(css));
   1.337 -	else
   1.338 -	{
   1.339 -		if (!css_dst.open( QIODevice::WriteOnly))
   1.340 -			QMessageBox::warning( 0, tr( "Warning" ), tr("Could not open %1").arg(dir+"vym.css"));
   1.341 -		else
   1.342 -		{	
   1.343 -		
   1.344 -			QTextStream tsout( &css_dst);
   1.345 -			QTextStream tsin ( &css_src);
   1.346 -			QString s= tsin.read();
   1.347 -			tsout << s;
   1.348 -			css_dst.close();
   1.349 -		}	
   1.350 -		css_src.close();
   1.351 -	}
   1.352 -
   1.353 -	if (!prescript.isEmpty()) runScript (prescript,dir+mapname+".xml");
   1.354 -	
   1.355 -	if (useImage)
   1.356 -		p.addStringParam ("imagemap","images/"+mapname+".png");
   1.357 -	if (useTextColor)
   1.358 -		p.addStringParam ("use.textcolor","1");
   1.359 -	p.addStringParam ("mapname",mapname+".vym");
   1.360 -	
   1.361 -	p.setOutputFile (dir+mapname+".html");
   1.362 -	p.setInputFile (dir+mapname+".xml");
   1.363 -	p.setXSLFile (xsl);
   1.364 -	p.process();
   1.365 -
   1.366 -	if (!postscript.isEmpty()) runScript (postscript,dir+mapname+".html");
   1.367 -
   1.368 -}
   1.369 -
   1.370 -void ExportXHTMLDialog::setFilePath(const QString &s)
   1.371 -{
   1.372 -	filepath=s;
   1.373 -}
   1.374 -
   1.375 -void ExportXHTMLDialog::setMapName(const QString &s)
   1.376 -{
   1.377 -	mapname=s;
   1.378 -}
   1.379 -
   1.380 -QString ExportXHTMLDialog::getDir()
   1.381 -{
   1.382 -	return dir;
   1.383 -}
   1.384 -
   1.385 -bool ExportXHTMLDialog::warnings()
   1.386 -{
   1.387 -	return showWarnings;
   1.388 -}
   1.389 -
   1.390 -bool ExportXHTMLDialog::hasChanged()
   1.391 -{
   1.392 -	return settingsChanged;
   1.393 -}
   1.394 -
   1.395 -
   1.396 -void ExportXHTMLDialog::runScript(QString spath, QString fpath)
   1.397 -{
   1.398 -	spath.replace ("%f",fpath);
   1.399 -	QStringList args=QStringList::split (' ',spath,false);
   1.400 -		
   1.401 -	p.addOutput ("vym is executing: \n" + spath+" "+args.join(" ") );	
   1.402 -	scriptProc->start (spath,args);
   1.403 -	if (!scriptProc->waitForStarted() )
   1.404 -	{
   1.405 -		QMessageBox::critical( 0, tr( "Critical Error" ),
   1.406 -					   tr("Could not start %1").arg(spath) );
   1.407 -	} else
   1.408 -	{
   1.409 -		if (!scriptProc->waitForFinished())
   1.410 -			QMessageBox::critical( 0, tr( "Critical Error" ),
   1.411 -			   tr("%1 didn't exit normally").arg(spath) +
   1.412 -			   scriptProc->getErrout() );
   1.413 -		else
   1.414 -			if (scriptProc->exitStatus()>0) showOutput=true;
   1.415 -			
   1.416 -	}	
   1.417 -	p.addOutput ("\n");
   1.418 -	p.addOutput (scriptProc->getErrout());
   1.419 -	p.addOutput (scriptProc->getStdout());
   1.420 -}
   1.421 -