insilmaril@0: /**************************************************************************** insilmaril@0: ** ui.h extension file, included from the uic-generated form implementation. insilmaril@0: ** insilmaril@0: ** If you wish to add, delete or rename functions or slots use insilmaril@0: ** Qt Designer which will update this file, preserving your code. Create an insilmaril@0: ** init() function in place of a constructor, and a destroy() function in insilmaril@0: ** place of a destructor. insilmaril@0: *****************************************************************************/ insilmaril@0: insilmaril@0: insilmaril@0: extern Settings settings; insilmaril@0: insilmaril@0: void ExportXHTMLDialog::init() insilmaril@0: { insilmaril@0: dia=new ShowTextDialog (); insilmaril@0: xsltprocessor="xsltproc"; insilmaril@0: filepath=""; insilmaril@0: settingsChanged=false; insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::readSettings() insilmaril@0: { insilmaril@0: insilmaril@0: dir=settings.readLocalEntry (filepath,"/vym/export/xhtml/exportDir","./" ); insilmaril@0: lineEditDir->setText(dir); insilmaril@0: insilmaril@0: insilmaril@0: if ( settings.readLocalEntry (filepath,"/vym/export/xhtml/useImage","yes")=="yes") insilmaril@0: useImage=true; insilmaril@0: else insilmaril@0: useImage=false; insilmaril@0: imageButton->setChecked(useImage); insilmaril@0: insilmaril@0: if ( settings.readLocalEntry (filepath,"/vym/export/xhtml/useTextColor","no")=="yes") insilmaril@0: useTextColor=true; insilmaril@0: else insilmaril@0: useTextColor=false; insilmaril@0: textColorButton->setChecked(useTextColor); insilmaril@0: insilmaril@0: /* FIXME this was used in old html export, is not yet in new stylesheet insilmaril@0: if ( settings.readEntry ("/vym/export/html/useHeading","no")=="yes") insilmaril@0: useHeading=true; insilmaril@0: else insilmaril@0: useHeading=false; insilmaril@0: checkBox4_2->setChecked(useHeading); insilmaril@0: */ insilmaril@0: insilmaril@0: if ( settings.readLocalEntry (filepath,"/vym/export/xhtml/saveSettingsInMap","no")=="yes") insilmaril@0: saveSettingsInMap=true; insilmaril@0: else insilmaril@0: saveSettingsInMap=false; insilmaril@0: saveSettingsInMapButton->setChecked(saveSettingsInMap); insilmaril@0: insilmaril@0: if ( settings.readEntry ("/vym/export/xhtml/showWarnings","yes")=="yes") insilmaril@0: showWarnings=true; insilmaril@0: else insilmaril@0: showWarnings=false; insilmaril@0: warningsButton->setChecked(showWarnings); insilmaril@0: insilmaril@0: if ( settings.readEntry ("/vym/export/xhtml/showOutput","no")=="yes") insilmaril@0: showOutput=true; insilmaril@0: else insilmaril@0: showOutput=false; insilmaril@0: outputButton->setChecked(showOutput); insilmaril@0: insilmaril@0: xsl=settings.readLocalEntry insilmaril@0: (filepath,"/vym/export/xhtml/xsl","/usr/share/vym/styles/vym2xhtml.xsl"); insilmaril@0: lineEditXSL->setText(xsl); insilmaril@0: insilmaril@0: css=settings.readLocalEntry insilmaril@0: (filepath,"/vym/export/xhtml/css","/usr/share/vym/styles/vym.css"); insilmaril@0: lineEditCSS->setText(css); insilmaril@0: insilmaril@0: prescript=settings.readLocalEntry insilmaril@0: (filepath,"/vym/export/xhtml/prescript",""); insilmaril@0: lineEditPreScript->setText (prescript); insilmaril@0: insilmaril@0: postscript=settings.readLocalEntry insilmaril@0: (filepath,"/vym/export/xhtml/postscript",""); insilmaril@0: lineEditPostScript->setText (postscript); insilmaril@0: insilmaril@0: if (!prescript.isEmpty() || !postscript.isEmpty()) insilmaril@0: { insilmaril@0: QMessageBox::warning( 0, tr( "Warning" ),tr( insilmaril@0: "The settings saved in the map " insilmaril@0: "would like to run scripts:\n\n") + insilmaril@0: prescript +" "+postscript +"\n\n"+ insilmaril@0: tr("Please check, if you really\n" insilmaril@0: "want to allow this in your system!")); insilmaril@0: insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::destroy() insilmaril@0: { insilmaril@0: delete (dia); insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::dirChanged() insilmaril@0: { insilmaril@0: dir=lineEditDir->text(); insilmaril@0: if (dir.right(1)!="/") insilmaril@0: dir+="/"; insilmaril@0: settingsChanged=true; insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::browseDirectoryPressed() insilmaril@0: { insilmaril@0: QFileDialog fd( this, tr("VYM - Export HTML to directory")); insilmaril@0: fd.setMode (QFileDialog::DirectoryOnly); insilmaril@0: fd.setCaption(tr("VYM - Export HTML to directory")); insilmaril@0: fd.setModal (true); insilmaril@0: fd.show(); insilmaril@0: insilmaril@0: if ( fd.exec() == QDialog::Accepted ) insilmaril@0: { insilmaril@0: dir=fd.selectedFile(); insilmaril@0: lineEditDir->setText (dir ); insilmaril@0: settingsChanged=true; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::imageButtonPressed(bool b) insilmaril@0: { insilmaril@0: useImage=b; insilmaril@0: settingsChanged=true; insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::textcolorButtonPressed(bool b) insilmaril@0: { insilmaril@0: useTextColor=b; insilmaril@0: settingsChanged=true; insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::saveSettingsInMapButtonPressed(bool b) insilmaril@0: { insilmaril@0: saveSettingsInMap=b; insilmaril@0: settingsChanged=true; insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::warningsButtonPressed(bool b) insilmaril@0: { insilmaril@0: showWarnings=b; insilmaril@0: settingsChanged=true; insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void ExportXHTMLDialog::outputButtonPressed(bool b) insilmaril@0: { insilmaril@0: showOutput=b; insilmaril@0: settingsChanged=true; insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::cssChanged() insilmaril@0: { insilmaril@0: css=lineEditCSS->text(); insilmaril@0: settingsChanged=true; insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::browseCSSPressed() insilmaril@0: { insilmaril@0: QFileDialog fd( this, tr("VYM - Path to CSS file")); insilmaril@0: fd.setModal (true); insilmaril@0: fd.addFilter ("Cascading Stylesheet (*.css)"); insilmaril@0: fd.show(); insilmaril@0: insilmaril@0: if ( fd.exec() == QDialog::Accepted ) insilmaril@0: { insilmaril@0: css=fd.selectedFile(); insilmaril@0: lineEditCSS->setText (css ); insilmaril@0: settingsChanged=true; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::xslChanged() insilmaril@0: { insilmaril@0: xsl=lineEditXSL->text(); insilmaril@0: settingsChanged=true; insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::prescriptChanged() insilmaril@0: { insilmaril@0: prescript=lineEditPreScript->text(); insilmaril@0: settingsChanged=true; insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::browseXSLPressed() insilmaril@0: { insilmaril@0: QFileDialog fd( this, tr("VYM - Path to XSL file")); insilmaril@0: fd.setModal (true); insilmaril@0: fd.addFilter ("Extensible Styleshee Language (*.xsl)"); insilmaril@0: fd.show(); insilmaril@0: insilmaril@0: if ( fd.exec() == QDialog::Accepted ) insilmaril@0: { insilmaril@0: xsl=fd.selectedFile(); insilmaril@0: lineEditXSL->setText (xsl ); insilmaril@0: settingsChanged=true; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::postscriptChanged() insilmaril@0: { insilmaril@0: postscript=lineEditPostScript->text(); insilmaril@0: settingsChanged=true; insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::browsePreExportButtonPressed() insilmaril@0: { insilmaril@0: QFileDialog fd( this, tr("VYM - Path to pre export script")); insilmaril@0: fd.setModal (true); insilmaril@0: fd.addFilter ("Scripts (*.sh *.pl *.py *.php)"); insilmaril@0: fd.show(); insilmaril@0: insilmaril@0: if ( fd.exec() == QDialog::Accepted ) insilmaril@0: { insilmaril@0: prescript=fd.selectedFile(); insilmaril@0: lineEditPreScript->setText (prescript ); insilmaril@0: settingsChanged=true; insilmaril@0: } insilmaril@0: insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::browsePostExportButtonPressed() insilmaril@0: { insilmaril@0: QFileDialog fd( this, tr("VYM - Path to post export script")); insilmaril@0: fd.setModal (true); insilmaril@0: fd.addFilter ("Scripts (*.sh *.pl *.py *.php)"); insilmaril@0: fd.show(); insilmaril@0: insilmaril@0: if ( fd.exec() == QDialog::Accepted ) insilmaril@0: { insilmaril@0: postscript=fd.selectedFile(); insilmaril@0: lineEditPostScript->setText (postscript ); insilmaril@0: settingsChanged=true; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void ExportXHTMLDialog::doExport (const QString &mapname) insilmaril@0: { insilmaril@0: // Save options to settings file insilmaril@0: // (but don't save at destructor, which insilmaril@0: // is called for "cancel", too) insilmaril@0: settings.setLocalEntry (filepath,"/vym/export/xhtml/exportDir",dir); insilmaril@0: insilmaril@0: settings.setLocalEntry (filepath,"/vym/export/xhtml/prescript",prescript); insilmaril@0: settings.setLocalEntry (filepath,"/vym/export/xhtml/postscript",postscript); insilmaril@0: insilmaril@0: if (useImage) insilmaril@0: settings.setLocalEntry (filepath,"/vym/export/xhtml/useImage","yes"); insilmaril@0: else insilmaril@0: settings.setLocalEntry (filepath,"/vym/export/xhtml/useImage","no"); insilmaril@0: insilmaril@0: if (useTextColor) insilmaril@0: settings.setLocalEntry (filepath,"/vym/export/xhtml/useTextColor","yes"); insilmaril@0: else insilmaril@0: settings.setLocalEntry (filepath,"/vym/export/xhtml/useTextColor","no"); insilmaril@0: insilmaril@0: if (showWarnings) insilmaril@0: settings.writeEntry ("/vym/export/xhtml/showWarnings","yes"); insilmaril@0: else insilmaril@0: settings.writeEntry ("/vym/export/xhtml/showWarnings","no"); insilmaril@0: insilmaril@0: if (showOutput) insilmaril@0: settings.writeEntry ("/vym/export/xhtml/showOutput","yes"); insilmaril@0: else insilmaril@0: settings.writeEntry ("/vym/export/xhtml/showOutput","no"); insilmaril@0: insilmaril@0: settings.setLocalEntry insilmaril@0: (filepath,"/vym/export/xhtml/xsl",xsl); insilmaril@0: settings.setLocalEntry insilmaril@0: (filepath,"/vym/export/xhtml/css",css); insilmaril@0: insilmaril@0: //FIXME add option for url image (globe flag) here insilmaril@0: if (true) insilmaril@0: { insilmaril@0: QPixmap pm (flag_url_xpm); insilmaril@0: pm.save (dir + "/flags/url.png","PNG"); insilmaril@0: } insilmaril@0: insilmaril@0: if (!saveSettingsInMap) insilmaril@0: settings.clearLocal("/vym/export/xhtml"); insilmaril@0: else insilmaril@0: settings.setLocalEntry insilmaril@0: (filepath,"/vym/export/xhtml/saveSettingsInMap","yes"); insilmaril@0: insilmaril@0: // Copy CSS file insilmaril@0: QFile css_src (css); insilmaril@0: QFile css_dst (dir+"vym.css"); insilmaril@0: if (!css_src.open ( IO_ReadOnly)) insilmaril@0: QMessageBox::warning( 0, tr( "Warning" ),css +tr(" could not be opened!")); insilmaril@0: else insilmaril@0: { insilmaril@0: if (!css_dst.open( IO_WriteOnly)) insilmaril@0: QMessageBox::warning( 0, tr( "Warning" ), dir+"vym.css" +tr(" could not be opened!")); insilmaril@0: else insilmaril@0: { insilmaril@0: insilmaril@0: QTextStream tsout( &css_dst); insilmaril@0: QTextStream tsin ( &css_src); insilmaril@0: QString s= tsin.read(); insilmaril@0: tsout << s; insilmaril@0: css_dst.close(); insilmaril@0: } insilmaril@0: css_src.close(); insilmaril@0: } insilmaril@0: insilmaril@0: if (!prescript.isEmpty()) runScript (prescript,dir+mapname+".xml"); insilmaril@0: insilmaril@0: Process *xsltProc=new Process (); insilmaril@0: xsltProc->clearArguments(); insilmaril@0: xsltProc->addArgument (xsltprocessor); insilmaril@0: if (useImage) insilmaril@0: { insilmaril@0: xsltProc->addArgument ("--stringparam"); insilmaril@0: xsltProc->addArgument ("imagemap"); insilmaril@0: xsltProc->addArgument ("images/"+mapname+".png"); insilmaril@0: } insilmaril@0: if (useTextColor) insilmaril@0: { insilmaril@0: xsltProc->addArgument ("--stringparam"); insilmaril@0: xsltProc->addArgument ("use.textcolor"); insilmaril@0: xsltProc->addArgument ("1"); insilmaril@0: } insilmaril@0: xsltProc->addArgument ("--stringparam"); insilmaril@0: xsltProc->addArgument ("mapname"); insilmaril@0: xsltProc->addArgument (mapname+".vym"); insilmaril@0: insilmaril@0: xsltProc->addArgument ("--output"); insilmaril@0: xsltProc->addArgument (dir+mapname+".html"); insilmaril@0: xsltProc->addArgument (xsl); insilmaril@0: xsltProc->addArgument (dir+mapname+".xml"); insilmaril@0: dia->append ("vym is executing: \n" + xsltProc->arguments().join(" ") ); insilmaril@0: if (!xsltProc->start() ) insilmaril@0: { insilmaril@0: QMessageBox::critical( 0, tr( "Critical Error" ), insilmaril@0: tr("Couldn't start ") + xsltprocessor ); insilmaril@0: } else insilmaril@0: { insilmaril@0: xsltProc->waitFinished(); insilmaril@0: if (!xsltProc->normalExit() ) insilmaril@0: QMessageBox::critical( 0, tr( "Critical Error" ), insilmaril@0: xsltprocessor +" " +tr("didn't exit normally") + insilmaril@0: xsltProc->getErrout() ); insilmaril@0: else insilmaril@0: if (xsltProc->exitStatus()>0) showOutput=true; insilmaril@0: insilmaril@0: } insilmaril@0: dia->append ("\n"); insilmaril@0: dia->append (xsltProc->getErrout()); insilmaril@0: dia->append (xsltProc->getStdout()); insilmaril@0: insilmaril@0: if (!postscript.isEmpty()) runScript (postscript,dir+mapname+".html"); insilmaril@0: insilmaril@0: if (showOutput) dia->exec(); insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::setFilePath(const QString &s) insilmaril@0: { insilmaril@0: filepath=s; insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::setMapName(const QString &s) insilmaril@0: { insilmaril@0: mapname=s; insilmaril@0: } insilmaril@0: insilmaril@0: QString ExportXHTMLDialog::getDir() insilmaril@0: { insilmaril@0: return dir; insilmaril@0: } insilmaril@0: insilmaril@0: bool ExportXHTMLDialog::warnings() insilmaril@0: { insilmaril@0: return showWarnings; insilmaril@0: } insilmaril@0: insilmaril@0: bool ExportXHTMLDialog::hasChanged() insilmaril@0: { insilmaril@0: return settingsChanged; insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void ExportXHTMLDialog::runScript(QString spath, QString fpath) insilmaril@0: { insilmaril@0: spath.replace ("%f",fpath); insilmaril@0: QStringList args=QStringList::split (' ',spath,false); insilmaril@0: insilmaril@0: Process *scriptProc=new Process (); insilmaril@0: scriptProc->clearArguments(); insilmaril@0: scriptProc->setArguments (args); insilmaril@0: dia->append ("vym is executing: \n" + scriptProc->arguments().join(" ") ); insilmaril@0: if (!scriptProc->start() ) insilmaril@0: { insilmaril@0: QMessageBox::critical( 0, tr( "Critical Error" ), insilmaril@0: tr("Couldn't start ") + spath ); insilmaril@0: } else insilmaril@0: { insilmaril@0: scriptProc->waitFinished(); insilmaril@0: if (!scriptProc->normalExit() ) insilmaril@0: QMessageBox::critical( 0, tr( "Critical Error" ), insilmaril@0: spath +" " +tr("didn't exit normally") + insilmaril@0: scriptProc->getErrout() ); insilmaril@0: else insilmaril@0: if (scriptProc->exitStatus()>0) showOutput=true; insilmaril@0: insilmaril@0: } insilmaril@0: dia->append ("\n"); insilmaril@0: dia->append (scriptProc->getErrout()); insilmaril@0: dia->append (scriptProc->getStdout()); insilmaril@0: }