insilmaril@382: #include "exportxhtmldialog.h"
insilmaril@382:
insilmaril@382: #include
insilmaril@382: #include
insilmaril@382: #include
insilmaril@382:
insilmaril@382: #include "options.h"
insilmaril@382: #include "settings.h"
insilmaril@382:
insilmaril@382:
insilmaril@382: extern Options options;
insilmaril@382: extern QDir vymBaseDir;
insilmaril@382: extern Settings settings;
insilmaril@515: extern bool debug;
insilmaril@382:
insilmaril@382: ExportXHTMLDialog::ExportXHTMLDialog(QWidget* parent) : QDialog(parent)
insilmaril@382: {
insilmaril@382: ui.setupUi(this);
insilmaril@382:
insilmaril@382: filepath="";
insilmaril@382: settingsChanged=false;
insilmaril@382: scriptProc=new Process;
insilmaril@382:
insilmaril@382: // signals and slots connections
insilmaril@382: connect(ui.browseExportDirButton, SIGNAL(pressed()), this, SLOT(browseDirectoryPressed()));
insilmaril@382: connect(ui.outputButton, SIGNAL(toggled(bool)), this, SLOT(outputButtonPressed(bool)));
insilmaril@382: connect(ui.browseXSLButton, SIGNAL(pressed()), this, SLOT(browseXSLPressed()));
insilmaril@382: connect(ui.browseCSSButton, SIGNAL(pressed()), this, SLOT(browseCSSPressed()));
insilmaril@382: connect(ui.imageButton, SIGNAL(toggled(bool)), this, SLOT(imageButtonPressed(bool)));
insilmaril@382: connect(ui.textColorButton, SIGNAL(toggled(bool)), this, SLOT(textcolorButtonPressed(bool)));
insilmaril@382: connect(ui.lineEditDir, SIGNAL(textChanged(const QString&)), this, SLOT(dirChanged()));
insilmaril@382: connect(ui.lineEditCSS, SIGNAL(textChanged(const QString&)), this, SLOT(cssChanged()));
insilmaril@382: connect(ui.lineEditXSL, SIGNAL(textChanged(const QString&)), this, SLOT(xslChanged()));
insilmaril@382: connect(ui.warningsButton, SIGNAL(toggled(bool)), this, SLOT(warningsButtonPressed(bool)));
insilmaril@382: connect(ui.saveSettingsInMapButton, SIGNAL(toggled(bool)), this, SLOT(saveSettingsInMapButtonPressed(bool)));
insilmaril@382: connect(ui.browsePreExportButton, SIGNAL(pressed()), this, SLOT(browsePreExportButtonPressed()));
insilmaril@382: connect(ui.lineEditPreScript, SIGNAL(textChanged(const QString&)), this, SLOT(prescriptChanged()));
insilmaril@382: connect(ui.lineEditPostScript, SIGNAL(textChanged(const QString&)), this, SLOT(postscriptChanged()));
insilmaril@382: connect(ui.browsePostExportButton, SIGNAL(pressed()), this, SLOT(browsePostExportButtonPressed()));
insilmaril@382: }
insilmaril@382:
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::readSettings()
insilmaril@382: {
insilmaril@382:
insilmaril@382: dir=settings.readLocalEntry (filepath,"/export/xhtml/exportDir",vymBaseDir.currentDirPath() );
insilmaril@382: ui.lineEditDir->setText(dir);
insilmaril@382:
insilmaril@382: if ( settings.readLocalEntry (filepath,"/export/xhtml/useImage","yes")=="yes")
insilmaril@382: useImage=true;
insilmaril@382: else
insilmaril@382: useImage=false;
insilmaril@382: ui.imageButton->setChecked(useImage);
insilmaril@382:
insilmaril@382: if ( settings.readLocalEntry (filepath,"/export/xhtml/useTextColor","no")=="yes")
insilmaril@382: useTextColor=true;
insilmaril@382: else
insilmaril@382: useTextColor=false;
insilmaril@382: ui.textColorButton->setChecked(useTextColor);
insilmaril@382:
insilmaril@412: /* TODO this was used in old html export, is not yet in new stylesheet
insilmaril@382: if ( settings.readEntry ("/export/html/useHeading","no")=="yes")
insilmaril@382: useHeading=true;
insilmaril@382: else
insilmaril@382: useHeading=false;
insilmaril@382: checkBox4_2->setChecked(useHeading);
insilmaril@382: */
insilmaril@382:
insilmaril@382: if ( settings.readLocalEntry (filepath,"/export/xhtml/saveSettingsInMap","no")=="yes")
insilmaril@382: saveSettingsInMap=true;
insilmaril@382: else
insilmaril@382: saveSettingsInMap=false;
insilmaril@382: ui.saveSettingsInMapButton->setChecked(saveSettingsInMap);
insilmaril@382:
insilmaril@382: if ( settings.readEntry ("/export/xhtml/showWarnings","yes")=="yes")
insilmaril@382: showWarnings=true;
insilmaril@382: else
insilmaril@382: showWarnings=false;
insilmaril@382: ui.warningsButton->setChecked(showWarnings);
insilmaril@382:
insilmaril@382: if ( settings.readEntry ("/export/xhtml/showOutput","no")=="yes")
insilmaril@382: showOutput=true;
insilmaril@382: else
insilmaril@382: showOutput=false;
insilmaril@382: ui.outputButton->setChecked(showOutput);
insilmaril@382:
insilmaril@382: // For testing better use local styles
insilmaril@624: const QString defxsl(vymBaseDir.path() + "/styles/vym2xhtml.xsl");
insilmaril@624: const QString defcss(vymBaseDir.path() + "/styles/vym.css");
insilmaril@382: if (options.isOn ("local"))
insilmaril@382: {
insilmaril@624: xsl=defxsl;
insilmaril@624: css=defcss;
insilmaril@382: } else
insilmaril@382: {
insilmaril@382: xsl=settings.readLocalEntry
insilmaril@624: (filepath,"/export/xhtml/xsl",defxsl);
insilmaril@382: css=settings.readLocalEntry
insilmaril@624: (filepath,"/export/xhtml/css",defcss);
insilmaril@382: }
insilmaril@382: ui.lineEditXSL->setText(xsl);
insilmaril@382: ui.lineEditCSS->setText(css);
insilmaril@382:
insilmaril@382: prescript=settings.readLocalEntry
insilmaril@382: (filepath,"/export/xhtml/prescript","");
insilmaril@382: ui.lineEditPreScript->setText (prescript);
insilmaril@382:
insilmaril@382: postscript=settings.readLocalEntry
insilmaril@382: (filepath,"/export/xhtml/postscript","");
insilmaril@382: ui.lineEditPostScript->setText (postscript);
insilmaril@382:
insilmaril@382: if (!prescript.isEmpty() || !postscript.isEmpty())
insilmaril@382: {
insilmaril@382: QMessageBox::warning( 0, tr( "Warning" ),tr(
insilmaril@382: "The settings saved in the map "
insilmaril@382: "would like to run scripts:\n\n"
insilmaril@382: "%1\n\n"
insilmaril@382: "Please check, if you really\n"
insilmaril@382: "want to allow this in your system!").arg(prescript+" "+postscript));
insilmaril@382:
insilmaril@382: }
insilmaril@382: }
insilmaril@382:
insilmaril@515: void ExportXHTMLDialog::setDir(const QString &d)
insilmaril@515: {
insilmaril@515: dir=d;
insilmaril@515: if (dir.right(1)!="/") dir+="/";
insilmaril@515: }
insilmaril@515:
insilmaril@382: void ExportXHTMLDialog::dirChanged()
insilmaril@382: {
insilmaril@515: setDir (ui.lineEditDir->text());
insilmaril@382: settingsChanged=true;
insilmaril@382: }
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::browseDirectoryPressed()
insilmaril@382: {
insilmaril@382: QFileDialog fd( this);
insilmaril@382: fd.setMode (QFileDialog::DirectoryOnly);
insilmaril@382: fd.setCaption(tr("VYM - Export HTML to directory"));
insilmaril@382: fd.setModal (true);
insilmaril@382: fd.setDirectory (QDir::current());
insilmaril@382: fd.show();
insilmaril@382:
insilmaril@382: if ( fd.exec() == QDialog::Accepted )
insilmaril@382: {
insilmaril@382: dir=fd.selectedFile();
insilmaril@382: ui.lineEditDir->setText (dir );
insilmaril@382: settingsChanged=true;
insilmaril@382: }
insilmaril@382: }
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::imageButtonPressed(bool b)
insilmaril@382: {
insilmaril@382: useImage=b;
insilmaril@382: settingsChanged=true;
insilmaril@382: }
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::textcolorButtonPressed(bool b)
insilmaril@382: {
insilmaril@382: useTextColor=b;
insilmaril@382: settingsChanged=true;
insilmaril@382: }
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::saveSettingsInMapButtonPressed(bool b)
insilmaril@382: {
insilmaril@382: saveSettingsInMap=b;
insilmaril@382: settingsChanged=true;
insilmaril@382: }
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::warningsButtonPressed(bool b)
insilmaril@382: {
insilmaril@382: showWarnings=b;
insilmaril@382: settingsChanged=true;
insilmaril@382: }
insilmaril@382:
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::outputButtonPressed(bool b)
insilmaril@382: {
insilmaril@382: showOutput=b;
insilmaril@382: settingsChanged=true;
insilmaril@382: }
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::cssChanged()
insilmaril@382: {
insilmaril@382: css=ui.lineEditCSS->text();
insilmaril@382: settingsChanged=true;
insilmaril@382: }
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::browseCSSPressed()
insilmaril@382: {
insilmaril@382: QFileDialog fd( this);
insilmaril@382: fd.setModal (true);
insilmaril@382: fd.setFilter ("Cascading Stylesheet (*.css)");
insilmaril@382: fd.setDirectory (QDir::current());
insilmaril@382: fd.show();
insilmaril@382:
insilmaril@382: if ( fd.exec() == QDialog::Accepted )
insilmaril@382: {
insilmaril@382: css=fd.selectedFile();
insilmaril@382: ui.lineEditCSS->setText (css );
insilmaril@382: settingsChanged=true;
insilmaril@382: }
insilmaril@382: }
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::xslChanged()
insilmaril@382: {
insilmaril@382: xsl=ui.lineEditXSL->text();
insilmaril@382: settingsChanged=true;
insilmaril@382: }
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::prescriptChanged()
insilmaril@382: {
insilmaril@382: prescript=ui.lineEditPreScript->text();
insilmaril@382: settingsChanged=true;
insilmaril@382: }
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::browseXSLPressed()
insilmaril@382: {
insilmaril@382: QFileDialog fd( this);
insilmaril@382: fd.setModal (true);
insilmaril@382: fd.setFilter ("Extensible Stylesheet Language (*.xsl)");
insilmaril@382: fd.setDirectory (QDir::current());
insilmaril@382: fd.show();
insilmaril@382:
insilmaril@382: if ( fd.exec() == QDialog::Accepted )
insilmaril@382: {
insilmaril@382: xsl=fd.selectedFile();
insilmaril@382: ui.lineEditXSL->setText (xsl );
insilmaril@382: settingsChanged=true;
insilmaril@382: }
insilmaril@382: }
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::postscriptChanged()
insilmaril@382: {
insilmaril@382: postscript=ui.lineEditPostScript->text();
insilmaril@382: settingsChanged=true;
insilmaril@382: }
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::browsePreExportButtonPressed()
insilmaril@382: {
insilmaril@382: QFileDialog fd( this);
insilmaril@382: fd.setModal (true);
insilmaril@382: fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
insilmaril@382: fd.setDirectory (QDir::current());
insilmaril@382: fd.show();
insilmaril@382:
insilmaril@382: if ( fd.exec() == QDialog::Accepted )
insilmaril@382: {
insilmaril@382: prescript=fd.selectedFile();
insilmaril@382: ui.lineEditPreScript->setText (prescript );
insilmaril@382: settingsChanged=true;
insilmaril@382: }
insilmaril@382:
insilmaril@382: }
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::browsePostExportButtonPressed()
insilmaril@382: {
insilmaril@382: QFileDialog fd( this);
insilmaril@382: fd.setModal (true);
insilmaril@382: fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
insilmaril@382: fd.setDirectory (QDir::current());
insilmaril@382: fd.show();
insilmaril@382:
insilmaril@382: if ( fd.exec() == QDialog::Accepted )
insilmaril@382: {
insilmaril@382: postscript=fd.selectedFile();
insilmaril@382: ui.lineEditPostScript->setText (postscript );
insilmaril@382: settingsChanged=true;
insilmaril@382: }
insilmaril@382: }
insilmaril@382:
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::doExport (const QString &mapname)
insilmaril@382: {
insilmaril@822:
insilmaril@382: // Save options to settings file
insilmaril@382: // (but don't save at destructor, which
insilmaril@382: // is called for "cancel", too)
insilmaril@382: settings.setLocalEntry (filepath,"/export/xhtml/exportDir",dir);
insilmaril@382: settings.setLocalEntry (filepath,"/export/xhtml/prescript",prescript);
insilmaril@382: settings.setLocalEntry (filepath,"/export/xhtml/postscript",postscript);
insilmaril@382:
insilmaril@382: if (useImage)
insilmaril@382: settings.setLocalEntry (filepath,"/export/xhtml/useImage","yes");
insilmaril@382: else
insilmaril@382: settings.setLocalEntry (filepath,"/export/xhtml/useImage","no");
insilmaril@382:
insilmaril@382: if (useTextColor)
insilmaril@382: settings.setLocalEntry (filepath,"/export/xhtml/useTextColor","yes");
insilmaril@382: else
insilmaril@382: settings.setLocalEntry (filepath,"/export/xhtml/useTextColor","no");
insilmaril@382:
insilmaril@382: if (showWarnings)
insilmaril@382: settings.writeEntry ("/export/xhtml/showWarnings","yes");
insilmaril@382: else
insilmaril@382: settings.writeEntry ("/export/xhtml/showWarnings","no");
insilmaril@382:
insilmaril@382: if (showOutput)
insilmaril@382: settings.writeEntry ("/export/xhtml/showOutput","yes");
insilmaril@382: else
insilmaril@382: settings.writeEntry ("/export/xhtml/showOutput","no");
insilmaril@382:
insilmaril@382: QString ipath;
insilmaril@382: ipath=vymBaseDir.path()+"/flags/flag-url-16x16.png";
insilmaril@382: if (!options.isOn ("local"))
insilmaril@382: {
insilmaril@382: settings.setLocalEntry
insilmaril@382: (filepath,"/export/xhtml/xsl",xsl);
insilmaril@382: settings.setLocalEntry
insilmaril@382: (filepath,"/export/xhtml/css",css);
insilmaril@382: }
insilmaril@382:
insilmaril@822: if (!saveSettingsInMap)
insilmaril@822: settings.clearLocal("/export/xhtml");
insilmaril@822: else
insilmaril@822: settings.setLocalEntry
insilmaril@822: (filepath,"/export/xhtml/saveSettingsInMap","yes");
insilmaril@822:
insilmaril@382: // Provide a smaller URL-icon to improve Layout
insilmaril@382: QPixmap pm;
insilmaril@382: if (!pm.load(ipath,"PNG") )
insilmaril@382: QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(ipath));
insilmaril@382:
insilmaril@382:
insilmaril@382: if(!pm.save (dir + "flags/flag-url-16x16.png","PNG"))
insilmaril@382: QMessageBox::warning( 0, tr( "Warning" ),tr("Could not write %1").arg(ipath));
insilmaril@382:
insilmaril@382: // Copy CSS file
insilmaril@382: QFile css_src (css);
insilmaril@382: QFile css_dst (dir+"vym.css");
insilmaril@382: if (!css_src.open ( QIODevice::ReadOnly))
insilmaril@382: QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(css));
insilmaril@382: else
insilmaril@382: {
insilmaril@382: if (!css_dst.open( QIODevice::WriteOnly))
insilmaril@382: QMessageBox::warning( 0, tr( "Warning" ), tr("Could not open %1").arg(dir+"vym.css"));
insilmaril@382: else
insilmaril@382: {
insilmaril@382:
insilmaril@382: QTextStream tsout( &css_dst);
insilmaril@382: QTextStream tsin ( &css_src);
insilmaril@382: QString s= tsin.read();
insilmaril@382: tsout << s;
insilmaril@382: css_dst.close();
insilmaril@382: }
insilmaril@382: css_src.close();
insilmaril@382: }
insilmaril@382:
insilmaril@382: if (!prescript.isEmpty()) runScript (prescript,dir+mapname+".xml");
insilmaril@382:
insilmaril@382: if (useImage)
insilmaril@382: p.addStringParam ("imagemap","images/"+mapname+".png");
insilmaril@382: if (useTextColor)
insilmaril@382: p.addStringParam ("use.textcolor","1");
insilmaril@382: p.addStringParam ("mapname",mapname+".vym");
insilmaril@382:
insilmaril@382: p.setOutputFile (dir+mapname+".html");
insilmaril@382: p.setInputFile (dir+mapname+".xml");
insilmaril@382: p.setXSLFile (xsl);
insilmaril@382: p.process();
insilmaril@382:
insilmaril@382: if (!postscript.isEmpty()) runScript (postscript,dir+mapname+".html");
insilmaril@382:
insilmaril@382: }
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::setFilePath(const QString &s)
insilmaril@382: {
insilmaril@382: filepath=s;
insilmaril@382: }
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::setMapName(const QString &s)
insilmaril@382: {
insilmaril@382: mapname=s;
insilmaril@382: }
insilmaril@382:
insilmaril@382: QString ExportXHTMLDialog::getDir()
insilmaril@382: {
insilmaril@382: return dir;
insilmaril@382: }
insilmaril@382:
insilmaril@382: bool ExportXHTMLDialog::warnings()
insilmaril@382: {
insilmaril@382: return showWarnings;
insilmaril@382: }
insilmaril@382:
insilmaril@382: bool ExportXHTMLDialog::hasChanged()
insilmaril@382: {
insilmaril@382: return settingsChanged;
insilmaril@382: }
insilmaril@382:
insilmaril@382:
insilmaril@382: void ExportXHTMLDialog::runScript(QString spath, QString fpath)
insilmaril@382: {
insilmaril@382: spath.replace ("%f",fpath);
insilmaril@382: QStringList args=QStringList::split (' ',spath,false);
insilmaril@382:
insilmaril@408: p.addOutput ("vym is executing: \n" + spath+" "+args.join(" ") );
insilmaril@408: scriptProc->start (spath,args);
insilmaril@408: if (!scriptProc->waitForStarted() )
insilmaril@382: {
insilmaril@382: QMessageBox::critical( 0, tr( "Critical Error" ),
insilmaril@382: tr("Could not start %1").arg(spath) );
insilmaril@382: } else
insilmaril@382: {
insilmaril@428: if (!scriptProc->waitForFinished())
insilmaril@382: QMessageBox::critical( 0, tr( "Critical Error" ),
insilmaril@382: tr("%1 didn't exit normally").arg(spath) +
insilmaril@382: scriptProc->getErrout() );
insilmaril@382: else
insilmaril@382: if (scriptProc->exitStatus()>0) showOutput=true;
insilmaril@382:
insilmaril@382: }
insilmaril@382: p.addOutput ("\n");
insilmaril@382: p.addOutput (scriptProc->getErrout());
insilmaril@382: p.addOutput (scriptProc->getStdout());
insilmaril@382: }
insilmaril@382: