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