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