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