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