1 /****************************************************************************
2 ** ui.h extension file, included from the uic-generated form implementation.
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 *****************************************************************************/
11 extern Settings settings;
13 void ExportXHTMLDialog::init()
15 dia=new ShowTextDialog ();
16 xsltprocessor="xsltproc";
18 settingsChanged=false;
21 void ExportXHTMLDialog::readSettings()
24 dir=settings.readLocalEntry (filepath,"/vym/export/xhtml/exportDir","./" );
25 lineEditDir->setText(dir);
28 if ( settings.readLocalEntry (filepath,"/vym/export/xhtml/useImage","yes")=="yes")
32 imageButton->setChecked(useImage);
34 if ( settings.readLocalEntry (filepath,"/vym/export/xhtml/useTextColor","no")=="yes")
38 textColorButton->setChecked(useTextColor);
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")
45 checkBox4_2->setChecked(useHeading);
48 if ( settings.readLocalEntry (filepath,"/vym/export/xhtml/saveSettingsInMap","no")=="yes")
49 saveSettingsInMap=true;
51 saveSettingsInMap=false;
52 saveSettingsInMapButton->setChecked(saveSettingsInMap);
54 if ( settings.readEntry ("/vym/export/xhtml/showWarnings","yes")=="yes")
58 warningsButton->setChecked(showWarnings);
60 if ( settings.readEntry ("/vym/export/xhtml/showOutput","no")=="yes")
64 outputButton->setChecked(showOutput);
66 xsl=settings.readLocalEntry
67 (filepath,"/vym/export/xhtml/xsl","/usr/share/vym/styles/vym2xhtml.xsl");
68 lineEditXSL->setText(xsl);
70 css=settings.readLocalEntry
71 (filepath,"/vym/export/xhtml/css","/usr/share/vym/styles/vym.css");
72 lineEditCSS->setText(css);
74 prescript=settings.readLocalEntry
75 (filepath,"/vym/export/xhtml/prescript","");
76 lineEditPreScript->setText (prescript);
78 postscript=settings.readLocalEntry
79 (filepath,"/vym/export/xhtml/postscript","");
80 lineEditPostScript->setText (postscript);
82 if (!prescript.isEmpty() || !postscript.isEmpty())
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!"));
94 void ExportXHTMLDialog::destroy()
99 void ExportXHTMLDialog::dirChanged()
101 dir=lineEditDir->text();
102 if (dir.right(1)!="/")
104 settingsChanged=true;
107 void ExportXHTMLDialog::browseDirectoryPressed()
109 QFileDialog fd( this, tr("VYM - Export HTML to directory"));
110 fd.setMode (QFileDialog::DirectoryOnly);
111 fd.setCaption(tr("VYM - Export HTML to directory"));
115 if ( fd.exec() == QDialog::Accepted )
117 dir=fd.selectedFile();
118 lineEditDir->setText (dir );
119 settingsChanged=true;
123 void ExportXHTMLDialog::imageButtonPressed(bool b)
126 settingsChanged=true;
129 void ExportXHTMLDialog::textcolorButtonPressed(bool b)
132 settingsChanged=true;
135 void ExportXHTMLDialog::saveSettingsInMapButtonPressed(bool b)
138 settingsChanged=true;
141 void ExportXHTMLDialog::warningsButtonPressed(bool b)
144 settingsChanged=true;
148 void ExportXHTMLDialog::outputButtonPressed(bool b)
151 settingsChanged=true;
154 void ExportXHTMLDialog::cssChanged()
156 css=lineEditCSS->text();
157 settingsChanged=true;
160 void ExportXHTMLDialog::browseCSSPressed()
162 QFileDialog fd( this, tr("VYM - Path to CSS file"));
164 fd.addFilter ("Cascading Stylesheet (*.css)");
167 if ( fd.exec() == QDialog::Accepted )
169 css=fd.selectedFile();
170 lineEditCSS->setText (css );
171 settingsChanged=true;
175 void ExportXHTMLDialog::xslChanged()
177 xsl=lineEditXSL->text();
178 settingsChanged=true;
181 void ExportXHTMLDialog::prescriptChanged()
183 prescript=lineEditPreScript->text();
184 settingsChanged=true;
187 void ExportXHTMLDialog::browseXSLPressed()
189 QFileDialog fd( this, tr("VYM - Path to XSL file"));
191 fd.addFilter ("Extensible Styleshee Language (*.xsl)");
194 if ( fd.exec() == QDialog::Accepted )
196 xsl=fd.selectedFile();
197 lineEditXSL->setText (xsl );
198 settingsChanged=true;
202 void ExportXHTMLDialog::postscriptChanged()
204 postscript=lineEditPostScript->text();
205 settingsChanged=true;
208 void ExportXHTMLDialog::browsePreExportButtonPressed()
210 QFileDialog fd( this, tr("VYM - Path to pre export script"));
212 fd.addFilter ("Scripts (*.sh *.pl *.py *.php)");
215 if ( fd.exec() == QDialog::Accepted )
217 prescript=fd.selectedFile();
218 lineEditPreScript->setText (prescript );
219 settingsChanged=true;
224 void ExportXHTMLDialog::browsePostExportButtonPressed()
226 QFileDialog fd( this, tr("VYM - Path to post export script"));
228 fd.addFilter ("Scripts (*.sh *.pl *.py *.php)");
231 if ( fd.exec() == QDialog::Accepted )
233 postscript=fd.selectedFile();
234 lineEditPostScript->setText (postscript );
235 settingsChanged=true;
240 void ExportXHTMLDialog::doExport (const QString &mapname)
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);
247 settings.setLocalEntry (filepath,"/vym/export/xhtml/prescript",prescript);
248 settings.setLocalEntry (filepath,"/vym/export/xhtml/postscript",postscript);
251 settings.setLocalEntry (filepath,"/vym/export/xhtml/useImage","yes");
253 settings.setLocalEntry (filepath,"/vym/export/xhtml/useImage","no");
256 settings.setLocalEntry (filepath,"/vym/export/xhtml/useTextColor","yes");
258 settings.setLocalEntry (filepath,"/vym/export/xhtml/useTextColor","no");
261 settings.writeEntry ("/vym/export/xhtml/showWarnings","yes");
263 settings.writeEntry ("/vym/export/xhtml/showWarnings","no");
266 settings.writeEntry ("/vym/export/xhtml/showOutput","yes");
268 settings.writeEntry ("/vym/export/xhtml/showOutput","no");
270 settings.setLocalEntry
271 (filepath,"/vym/export/xhtml/xsl",xsl);
272 settings.setLocalEntry
273 (filepath,"/vym/export/xhtml/css",css);
275 //FIXME add option for url image (globe flag) here
278 QPixmap pm (flag_url_xpm);
279 pm.save (dir + "/flags/url.png","PNG");
282 if (!saveSettingsInMap)
283 settings.clearLocal("/vym/export/xhtml");
285 settings.setLocalEntry
286 (filepath,"/vym/export/xhtml/saveSettingsInMap","yes");
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!"));
295 if (!css_dst.open( IO_WriteOnly))
296 QMessageBox::warning( 0, tr( "Warning" ), dir+"vym.css" +tr(" could not be opened!"));
300 QTextStream tsout( &css_dst);
301 QTextStream tsin ( &css_src);
302 QString s= tsin.read();
309 if (!prescript.isEmpty()) runScript (prescript,dir+mapname+".xml");
311 Process *xsltProc=new Process ();
312 xsltProc->clearArguments();
313 xsltProc->addArgument (xsltprocessor);
316 xsltProc->addArgument ("--stringparam");
317 xsltProc->addArgument ("imagemap");
318 xsltProc->addArgument ("images/"+mapname+".png");
322 xsltProc->addArgument ("--stringparam");
323 xsltProc->addArgument ("use.textcolor");
324 xsltProc->addArgument ("1");
326 xsltProc->addArgument ("--stringparam");
327 xsltProc->addArgument ("mapname");
328 xsltProc->addArgument (mapname+".vym");
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() )
337 QMessageBox::critical( 0, tr( "Critical Error" ),
338 tr("Couldn't start ") + xsltprocessor );
341 xsltProc->waitFinished();
342 if (!xsltProc->normalExit() )
343 QMessageBox::critical( 0, tr( "Critical Error" ),
344 xsltprocessor +" " +tr("didn't exit normally") +
345 xsltProc->getErrout() );
347 if (xsltProc->exitStatus()>0) showOutput=true;
351 dia->append (xsltProc->getErrout());
352 dia->append (xsltProc->getStdout());
354 if (!postscript.isEmpty()) runScript (postscript,dir+mapname+".html");
356 if (showOutput) dia->exec();
359 void ExportXHTMLDialog::setFilePath(const QString &s)
364 void ExportXHTMLDialog::setMapName(const QString &s)
369 QString ExportXHTMLDialog::getDir()
374 bool ExportXHTMLDialog::warnings()
379 bool ExportXHTMLDialog::hasChanged()
381 return settingsChanged;
385 void ExportXHTMLDialog::runScript(QString spath, QString fpath)
387 spath.replace ("%f",fpath);
388 QStringList args=QStringList::split (' ',spath,false);
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() )
396 QMessageBox::critical( 0, tr( "Critical Error" ),
397 tr("Couldn't start ") + spath );
400 scriptProc->waitFinished();
401 if (!scriptProc->normalExit() )
402 QMessageBox::critical( 0, tr( "Critical Error" ),
403 spath +" " +tr("didn't exit normally") +
404 scriptProc->getErrout() );
406 if (scriptProc->exitStatus()>0) showOutput=true;
410 dia->append (scriptProc->getErrout());
411 dia->append (scriptProc->getStdout());