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