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