insilmaril@2: //Added by qt3to4: insilmaril@2: #include insilmaril@2: #include 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@2: extern QDir vymBaseDir; insilmaril@2: extern Options options; insilmaril@0: insilmaril@0: void ExportXHTMLDialog::init() insilmaril@0: { insilmaril@0: filepath=""; insilmaril@0: settingsChanged=false; insilmaril@2: scriptProc=new Process; insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::readSettings() insilmaril@0: { insilmaril@0: insilmaril@2: dir=settings.readLocalEntry (filepath,"/vym/export/xhtml/exportDir",vymBaseDir.currentDirPath() ); insilmaril@0: lineEditDir->setText(dir); 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@2: // For testing better use local styles insilmaril@2: if (options.isOn ("local")) insilmaril@2: { insilmaril@2: xsl=vymBaseDir.path()+"/styles/vym2xhtml.xsl"; insilmaril@2: css=vymBaseDir.path()+"/styles/vym.css"; insilmaril@2: } else insilmaril@2: { insilmaril@2: xsl=settings.readLocalEntry insilmaril@2: (filepath,"/vym/export/xhtml/xsl","/usr/share/vym/styles/vym2xhtml.xsl"); insilmaril@2: css=settings.readLocalEntry insilmaril@2: (filepath,"/vym/export/xhtml/css","/usr/share/vym/styles/vym.css"); insilmaril@2: } insilmaril@0: lineEditXSL->setText(xsl); 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@2: "would like to run scripts:\n\n" insilmaril@2: "%1\n\n" insilmaril@2: "Please check, if you really\n" insilmaril@2: "want to allow this in your system!").arg(prescript+" "+postscript)); insilmaril@0: insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void ExportXHTMLDialog::destroy() insilmaril@0: { 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@2: Q3FileDialog fd( this, tr("VYM - Export HTML to directory")); insilmaril@2: fd.setMode (Q3FileDialog::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@2: Q3FileDialog 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@2: Q3FileDialog fd( this, tr("VYM - Path to XSL file")); insilmaril@0: fd.setModal (true); insilmaril@2: fd.addFilter ("Extensible Stylesheet 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@2: Q3FileDialog 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@2: Q3FileDialog 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: 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@2: QString ipath; insilmaril@2: ipath=vymBaseDir.path()+"/flags/flag-url-16x16.png"; insilmaril@2: if (!options.isOn ("local")) insilmaril@2: { insilmaril@2: settings.setLocalEntry insilmaril@2: (filepath,"/vym/export/xhtml/xsl",xsl); insilmaril@2: settings.setLocalEntry insilmaril@2: (filepath,"/vym/export/xhtml/css",css); insilmaril@0: } insilmaril@0: insilmaril@2: // Provide a smaller URL-icon to improve Layout insilmaril@2: QPixmap pm; insilmaril@2: if (!pm.load(ipath,"PNG") ) insilmaril@2: QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(ipath)); insilmaril@2: insilmaril@2: insilmaril@2: if(!pm.save (dir + "flags/flag-url-16x16.png","PNG")) insilmaril@2: QMessageBox::warning( 0, tr( "Warning" ),tr("Could not write %1").arg(ipath)); 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@2: if (!css_src.open ( QIODevice::ReadOnly)) insilmaril@2: QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(css)); insilmaril@0: else insilmaril@0: { insilmaril@2: if (!css_dst.open( QIODevice::WriteOnly)) insilmaril@2: QMessageBox::warning( 0, tr( "Warning" ), tr("Could not open %1").arg(dir+"vym.css")); 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: if (useImage) insilmaril@2: p.addStringParam ("imagemap","images/"+mapname+".png"); insilmaril@0: if (useTextColor) insilmaril@2: p.addStringParam ("use.textcolor","1"); insilmaril@2: p.addStringParam ("mapname",mapname+".vym"); insilmaril@0: insilmaril@2: p.setOutputFile (dir+mapname+".html"); insilmaril@2: p.setInputFile (dir+mapname+".xml"); insilmaril@2: p.setXSLFile (xsl); insilmaril@2: p.process(); insilmaril@2: insilmaril@0: if (!postscript.isEmpty()) runScript (postscript,dir+mapname+".html"); insilmaril@0: 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: scriptProc->clearArguments(); insilmaril@0: scriptProc->setArguments (args); insilmaril@2: p.addOutput ("vym is executing: \n" + scriptProc->arguments().join(" ") ); insilmaril@0: if (!scriptProc->start() ) insilmaril@0: { insilmaril@0: QMessageBox::critical( 0, tr( "Critical Error" ), insilmaril@2: tr("Could not start %1").arg(spath) ); insilmaril@0: } else insilmaril@0: { insilmaril@0: scriptProc->waitFinished(); insilmaril@0: if (!scriptProc->normalExit() ) insilmaril@0: QMessageBox::critical( 0, tr( "Critical Error" ), insilmaril@2: tr("%1 didn't exit normally").arg(spath) + insilmaril@0: scriptProc->getErrout() ); insilmaril@0: else insilmaril@0: if (scriptProc->exitStatus()>0) showOutput=true; insilmaril@0: insilmaril@0: } insilmaril@2: p.addOutput ("\n"); insilmaril@2: p.addOutput (scriptProc->getErrout()); insilmaril@2: p.addOutput (scriptProc->getStdout()); insilmaril@0: }