1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/exportxhtmldialog.cpp Mon Nov 20 12:12:02 2006 +0000
1.3 @@ -0,0 +1,411 @@
1.4 +#include "exportxhtmldialog.h"
1.5 +
1.6 +#include <QFileDialog>
1.7 +#include <QMessageBox>
1.8 +#include <QTextStream>
1.9 +
1.10 +#include "options.h"
1.11 +#include "settings.h"
1.12 +
1.13 +
1.14 +extern Options options;
1.15 +extern QDir vymBaseDir;
1.16 +extern Settings settings;
1.17 +
1.18 +ExportXHTMLDialog::ExportXHTMLDialog(QWidget* parent) : QDialog(parent)
1.19 +{
1.20 + ui.setupUi(this);
1.21 +
1.22 + filepath="";
1.23 + settingsChanged=false;
1.24 + scriptProc=new Process;
1.25 +
1.26 + // signals and slots connections
1.27 + connect(ui.browseExportDirButton, SIGNAL(pressed()), this, SLOT(browseDirectoryPressed()));
1.28 + connect(ui.outputButton, SIGNAL(toggled(bool)), this, SLOT(outputButtonPressed(bool)));
1.29 + connect(ui.browseXSLButton, SIGNAL(pressed()), this, SLOT(browseXSLPressed()));
1.30 + connect(ui.browseCSSButton, SIGNAL(pressed()), this, SLOT(browseCSSPressed()));
1.31 + connect(ui.imageButton, SIGNAL(toggled(bool)), this, SLOT(imageButtonPressed(bool)));
1.32 + connect(ui.textColorButton, SIGNAL(toggled(bool)), this, SLOT(textcolorButtonPressed(bool)));
1.33 + connect(ui.lineEditDir, SIGNAL(textChanged(const QString&)), this, SLOT(dirChanged()));
1.34 + connect(ui.lineEditCSS, SIGNAL(textChanged(const QString&)), this, SLOT(cssChanged()));
1.35 + connect(ui.lineEditXSL, SIGNAL(textChanged(const QString&)), this, SLOT(xslChanged()));
1.36 + connect(ui.warningsButton, SIGNAL(toggled(bool)), this, SLOT(warningsButtonPressed(bool)));
1.37 + connect(ui.saveSettingsInMapButton, SIGNAL(toggled(bool)), this, SLOT(saveSettingsInMapButtonPressed(bool)));
1.38 + connect(ui.browsePreExportButton, SIGNAL(pressed()), this, SLOT(browsePreExportButtonPressed()));
1.39 + connect(ui.lineEditPreScript, SIGNAL(textChanged(const QString&)), this, SLOT(prescriptChanged()));
1.40 + connect(ui.lineEditPostScript, SIGNAL(textChanged(const QString&)), this, SLOT(postscriptChanged()));
1.41 + connect(ui.browsePostExportButton, SIGNAL(pressed()), this, SLOT(browsePostExportButtonPressed()));
1.42 +}
1.43 +
1.44 +
1.45 +void ExportXHTMLDialog::readSettings()
1.46 +{
1.47 +
1.48 + dir=settings.readLocalEntry (filepath,"/export/xhtml/exportDir",vymBaseDir.currentDirPath() );
1.49 + ui.lineEditDir->setText(dir);
1.50 +
1.51 + if ( settings.readLocalEntry (filepath,"/export/xhtml/useImage","yes")=="yes")
1.52 + useImage=true;
1.53 + else
1.54 + useImage=false;
1.55 + ui.imageButton->setChecked(useImage);
1.56 +
1.57 + if ( settings.readLocalEntry (filepath,"/export/xhtml/useTextColor","no")=="yes")
1.58 + useTextColor=true;
1.59 + else
1.60 + useTextColor=false;
1.61 + ui.textColorButton->setChecked(useTextColor);
1.62 +
1.63 +/* FIXME this was used in old html export, is not yet in new stylesheet
1.64 + if ( settings.readEntry ("/export/html/useHeading","no")=="yes")
1.65 + useHeading=true;
1.66 + else
1.67 + useHeading=false;
1.68 + checkBox4_2->setChecked(useHeading);
1.69 +*/
1.70 +
1.71 + if ( settings.readLocalEntry (filepath,"/export/xhtml/saveSettingsInMap","no")=="yes")
1.72 + saveSettingsInMap=true;
1.73 + else
1.74 + saveSettingsInMap=false;
1.75 + ui.saveSettingsInMapButton->setChecked(saveSettingsInMap);
1.76 +
1.77 + if ( settings.readEntry ("/export/xhtml/showWarnings","yes")=="yes")
1.78 + showWarnings=true;
1.79 + else
1.80 + showWarnings=false;
1.81 + ui.warningsButton->setChecked(showWarnings);
1.82 +
1.83 + if ( settings.readEntry ("/export/xhtml/showOutput","no")=="yes")
1.84 + showOutput=true;
1.85 + else
1.86 + showOutput=false;
1.87 + ui.outputButton->setChecked(showOutput);
1.88 +
1.89 + // For testing better use local styles
1.90 + if (options.isOn ("local"))
1.91 + {
1.92 + xsl=vymBaseDir.path()+"/styles/vym2xhtml.xsl";
1.93 + css=vymBaseDir.path()+"/styles/vym.css";
1.94 + } else
1.95 + {
1.96 + xsl=settings.readLocalEntry
1.97 + (filepath,"/export/xhtml/xsl","/usr/share/vym/styles/vym2xhtml.xsl");
1.98 + css=settings.readLocalEntry
1.99 + (filepath,"/export/xhtml/css","/usr/share/vym/styles/vym.css");
1.100 + }
1.101 + ui.lineEditXSL->setText(xsl);
1.102 + ui.lineEditCSS->setText(css);
1.103 +
1.104 + prescript=settings.readLocalEntry
1.105 + (filepath,"/export/xhtml/prescript","");
1.106 + ui.lineEditPreScript->setText (prescript);
1.107 +
1.108 + postscript=settings.readLocalEntry
1.109 + (filepath,"/export/xhtml/postscript","");
1.110 + ui.lineEditPostScript->setText (postscript);
1.111 +
1.112 + if (!prescript.isEmpty() || !postscript.isEmpty())
1.113 + {
1.114 + QMessageBox::warning( 0, tr( "Warning" ),tr(
1.115 + "The settings saved in the map "
1.116 + "would like to run scripts:\n\n"
1.117 + "%1\n\n"
1.118 + "Please check, if you really\n"
1.119 + "want to allow this in your system!").arg(prescript+" "+postscript));
1.120 +
1.121 + }
1.122 +}
1.123 +
1.124 +void ExportXHTMLDialog::dirChanged()
1.125 +{
1.126 + dir=ui.lineEditDir->text();
1.127 + if (dir.right(1)!="/")
1.128 + dir+="/";
1.129 + settingsChanged=true;
1.130 +}
1.131 +
1.132 +void ExportXHTMLDialog::browseDirectoryPressed()
1.133 +{
1.134 + QFileDialog fd( this);
1.135 + fd.setMode (QFileDialog::DirectoryOnly);
1.136 + fd.setCaption(tr("VYM - Export HTML to directory"));
1.137 + fd.setModal (true);
1.138 + fd.setDirectory (QDir::current());
1.139 + fd.show();
1.140 +
1.141 + if ( fd.exec() == QDialog::Accepted )
1.142 + {
1.143 + dir=fd.selectedFile();
1.144 + ui.lineEditDir->setText (dir );
1.145 + settingsChanged=true;
1.146 + }
1.147 +}
1.148 +
1.149 +void ExportXHTMLDialog::imageButtonPressed(bool b)
1.150 +{
1.151 + useImage=b;
1.152 + settingsChanged=true;
1.153 +}
1.154 +
1.155 +void ExportXHTMLDialog::textcolorButtonPressed(bool b)
1.156 +{
1.157 + useTextColor=b;
1.158 + settingsChanged=true;
1.159 +}
1.160 +
1.161 +void ExportXHTMLDialog::saveSettingsInMapButtonPressed(bool b)
1.162 +{
1.163 + saveSettingsInMap=b;
1.164 + settingsChanged=true;
1.165 +}
1.166 +
1.167 +void ExportXHTMLDialog::warningsButtonPressed(bool b)
1.168 +{
1.169 + showWarnings=b;
1.170 + settingsChanged=true;
1.171 +}
1.172 +
1.173 +
1.174 +void ExportXHTMLDialog::outputButtonPressed(bool b)
1.175 +{
1.176 + showOutput=b;
1.177 + settingsChanged=true;
1.178 +}
1.179 +
1.180 +void ExportXHTMLDialog::cssChanged()
1.181 +{
1.182 + css=ui.lineEditCSS->text();
1.183 + settingsChanged=true;
1.184 +}
1.185 +
1.186 +void ExportXHTMLDialog::browseCSSPressed()
1.187 +{
1.188 + QFileDialog fd( this);
1.189 + fd.setModal (true);
1.190 + fd.setFilter ("Cascading Stylesheet (*.css)");
1.191 + fd.setDirectory (QDir::current());
1.192 + fd.show();
1.193 +
1.194 + if ( fd.exec() == QDialog::Accepted )
1.195 + {
1.196 + css=fd.selectedFile();
1.197 + ui.lineEditCSS->setText (css );
1.198 + settingsChanged=true;
1.199 + }
1.200 +}
1.201 +
1.202 +void ExportXHTMLDialog::xslChanged()
1.203 +{
1.204 + xsl=ui.lineEditXSL->text();
1.205 + settingsChanged=true;
1.206 +}
1.207 +
1.208 +void ExportXHTMLDialog::prescriptChanged()
1.209 +{
1.210 + prescript=ui.lineEditPreScript->text();
1.211 + settingsChanged=true;
1.212 +}
1.213 +
1.214 +void ExportXHTMLDialog::browseXSLPressed()
1.215 +{
1.216 + QFileDialog fd( this);
1.217 + fd.setModal (true);
1.218 + fd.setFilter ("Extensible Stylesheet Language (*.xsl)");
1.219 + fd.setDirectory (QDir::current());
1.220 + fd.show();
1.221 +
1.222 + if ( fd.exec() == QDialog::Accepted )
1.223 + {
1.224 + xsl=fd.selectedFile();
1.225 + ui.lineEditXSL->setText (xsl );
1.226 + settingsChanged=true;
1.227 + }
1.228 +}
1.229 +
1.230 +void ExportXHTMLDialog::postscriptChanged()
1.231 +{
1.232 + postscript=ui.lineEditPostScript->text();
1.233 + settingsChanged=true;
1.234 +}
1.235 +
1.236 +void ExportXHTMLDialog::browsePreExportButtonPressed()
1.237 +{
1.238 + QFileDialog fd( this);
1.239 + fd.setModal (true);
1.240 + fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
1.241 + fd.setDirectory (QDir::current());
1.242 + fd.show();
1.243 +
1.244 + if ( fd.exec() == QDialog::Accepted )
1.245 + {
1.246 + prescript=fd.selectedFile();
1.247 + ui.lineEditPreScript->setText (prescript );
1.248 + settingsChanged=true;
1.249 + }
1.250 +
1.251 +}
1.252 +
1.253 +void ExportXHTMLDialog::browsePostExportButtonPressed()
1.254 +{
1.255 + QFileDialog fd( this);
1.256 + fd.setModal (true);
1.257 + fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
1.258 + fd.setDirectory (QDir::current());
1.259 + fd.show();
1.260 +
1.261 + if ( fd.exec() == QDialog::Accepted )
1.262 + {
1.263 + postscript=fd.selectedFile();
1.264 + ui.lineEditPostScript->setText (postscript );
1.265 + settingsChanged=true;
1.266 + }
1.267 +}
1.268 +
1.269 +
1.270 +void ExportXHTMLDialog::doExport (const QString &mapname)
1.271 +{
1.272 + // Save options to settings file
1.273 + // (but don't save at destructor, which
1.274 + // is called for "cancel", too)
1.275 + settings.setLocalEntry (filepath,"/export/xhtml/exportDir",dir);
1.276 + settings.setLocalEntry (filepath,"/export/xhtml/prescript",prescript);
1.277 + settings.setLocalEntry (filepath,"/export/xhtml/postscript",postscript);
1.278 +
1.279 + if (useImage)
1.280 + settings.setLocalEntry (filepath,"/export/xhtml/useImage","yes");
1.281 + else
1.282 + settings.setLocalEntry (filepath,"/export/xhtml/useImage","no");
1.283 +
1.284 + if (useTextColor)
1.285 + settings.setLocalEntry (filepath,"/export/xhtml/useTextColor","yes");
1.286 + else
1.287 + settings.setLocalEntry (filepath,"/export/xhtml/useTextColor","no");
1.288 +
1.289 + if (showWarnings)
1.290 + settings.writeEntry ("/export/xhtml/showWarnings","yes");
1.291 + else
1.292 + settings.writeEntry ("/export/xhtml/showWarnings","no");
1.293 +
1.294 + if (showOutput)
1.295 + settings.writeEntry ("/export/xhtml/showOutput","yes");
1.296 + else
1.297 + settings.writeEntry ("/export/xhtml/showOutput","no");
1.298 +
1.299 + QString ipath;
1.300 + ipath=vymBaseDir.path()+"/flags/flag-url-16x16.png";
1.301 + if (!options.isOn ("local"))
1.302 + {
1.303 + settings.setLocalEntry
1.304 + (filepath,"/export/xhtml/xsl",xsl);
1.305 + settings.setLocalEntry
1.306 + (filepath,"/export/xhtml/css",css);
1.307 + }
1.308 +
1.309 + // Provide a smaller URL-icon to improve Layout
1.310 + QPixmap pm;
1.311 + if (!pm.load(ipath,"PNG") )
1.312 + QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(ipath));
1.313 +
1.314 +
1.315 + if(!pm.save (dir + "flags/flag-url-16x16.png","PNG"))
1.316 + QMessageBox::warning( 0, tr( "Warning" ),tr("Could not write %1").arg(ipath));
1.317 + if (!saveSettingsInMap)
1.318 + settings.clearLocal("/export/xhtml");
1.319 + else
1.320 + settings.setLocalEntry
1.321 + (filepath,"/export/xhtml/saveSettingsInMap","yes");
1.322 +
1.323 + // Copy CSS file
1.324 + QFile css_src (css);
1.325 + QFile css_dst (dir+"vym.css");
1.326 + if (!css_src.open ( QIODevice::ReadOnly))
1.327 + QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(css));
1.328 + else
1.329 + {
1.330 + if (!css_dst.open( QIODevice::WriteOnly))
1.331 + QMessageBox::warning( 0, tr( "Warning" ), tr("Could not open %1").arg(dir+"vym.css"));
1.332 + else
1.333 + {
1.334 +
1.335 + QTextStream tsout( &css_dst);
1.336 + QTextStream tsin ( &css_src);
1.337 + QString s= tsin.read();
1.338 + tsout << s;
1.339 + css_dst.close();
1.340 + }
1.341 + css_src.close();
1.342 + }
1.343 +
1.344 + if (!prescript.isEmpty()) runScript (prescript,dir+mapname+".xml");
1.345 +
1.346 + if (useImage)
1.347 + p.addStringParam ("imagemap","images/"+mapname+".png");
1.348 + if (useTextColor)
1.349 + p.addStringParam ("use.textcolor","1");
1.350 + p.addStringParam ("mapname",mapname+".vym");
1.351 +
1.352 + p.setOutputFile (dir+mapname+".html");
1.353 + p.setInputFile (dir+mapname+".xml");
1.354 + p.setXSLFile (xsl);
1.355 + p.process();
1.356 +
1.357 + if (!postscript.isEmpty()) runScript (postscript,dir+mapname+".html");
1.358 +
1.359 +}
1.360 +
1.361 +void ExportXHTMLDialog::setFilePath(const QString &s)
1.362 +{
1.363 + filepath=s;
1.364 +}
1.365 +
1.366 +void ExportXHTMLDialog::setMapName(const QString &s)
1.367 +{
1.368 + mapname=s;
1.369 +}
1.370 +
1.371 +QString ExportXHTMLDialog::getDir()
1.372 +{
1.373 + return dir;
1.374 +}
1.375 +
1.376 +bool ExportXHTMLDialog::warnings()
1.377 +{
1.378 + return showWarnings;
1.379 +}
1.380 +
1.381 +bool ExportXHTMLDialog::hasChanged()
1.382 +{
1.383 + return settingsChanged;
1.384 +}
1.385 +
1.386 +
1.387 +void ExportXHTMLDialog::runScript(QString spath, QString fpath)
1.388 +{
1.389 + spath.replace ("%f",fpath);
1.390 + QStringList args=QStringList::split (' ',spath,false);
1.391 +
1.392 + scriptProc->clearArguments();
1.393 + scriptProc->setArguments (args);
1.394 + p.addOutput ("vym is executing: \n" + scriptProc->arguments().join(" ") );
1.395 + if (!scriptProc->start() )
1.396 + {
1.397 + QMessageBox::critical( 0, tr( "Critical Error" ),
1.398 + tr("Could not start %1").arg(spath) );
1.399 + } else
1.400 + {
1.401 + scriptProc->waitFinished();
1.402 + if (!scriptProc->normalExit() )
1.403 + QMessageBox::critical( 0, tr( "Critical Error" ),
1.404 + tr("%1 didn't exit normally").arg(spath) +
1.405 + scriptProc->getErrout() );
1.406 + else
1.407 + if (scriptProc->exitStatus()>0) showOutput=true;
1.408 +
1.409 + }
1.410 + p.addOutput ("\n");
1.411 + p.addOutput (scriptProc->getErrout());
1.412 + p.addOutput (scriptProc->getStdout());
1.413 +}
1.414 +