Various fixes, also from 1.12. branch
1 #include "exportxhtmldialog.h"
11 extern Options options;
12 extern QDir vymBaseDir;
13 extern Settings settings;
16 ExportXHTMLDialog::ExportXHTMLDialog(QWidget* parent) : QDialog(parent)
21 settingsChanged=false;
22 scriptProc=new Process;
24 // signals and slots connections
25 connect(ui.browseExportDirButton, SIGNAL(pressed()), this, SLOT(browseDirectoryPressed()));
26 connect(ui.outputButton, SIGNAL(toggled(bool)), this, SLOT(outputButtonPressed(bool)));
27 connect(ui.browseXSLButton, SIGNAL(pressed()), this, SLOT(browseXSLPressed()));
28 connect(ui.browseCSSButton, SIGNAL(pressed()), this, SLOT(browseCSSPressed()));
29 connect(ui.imageButton, SIGNAL(toggled(bool)), this, SLOT(imageButtonPressed(bool)));
30 connect(ui.textColorButton, SIGNAL(toggled(bool)), this, SLOT(textcolorButtonPressed(bool)));
31 connect(ui.lineEditDir, SIGNAL(textChanged(const QString&)), this, SLOT(dirChanged()));
32 connect(ui.lineEditCSS, SIGNAL(textChanged(const QString&)), this, SLOT(cssChanged()));
33 connect(ui.lineEditXSL, SIGNAL(textChanged(const QString&)), this, SLOT(xslChanged()));
34 connect(ui.warningsButton, SIGNAL(toggled(bool)), this, SLOT(warningsButtonPressed(bool)));
35 connect(ui.saveSettingsInMapButton, SIGNAL(toggled(bool)), this, SLOT(saveSettingsInMapButtonPressed(bool)));
36 connect(ui.browsePreExportButton, SIGNAL(pressed()), this, SLOT(browsePreExportButtonPressed()));
37 connect(ui.lineEditPreScript, SIGNAL(textChanged(const QString&)), this, SLOT(prescriptChanged()));
38 connect(ui.lineEditPostScript, SIGNAL(textChanged(const QString&)), this, SLOT(postscriptChanged()));
39 connect(ui.browsePostExportButton, SIGNAL(pressed()), this, SLOT(browsePostExportButtonPressed()));
43 void ExportXHTMLDialog::readSettings()
46 dir=settings.readLocalEntry (filepath,"/export/xhtml/exportDir",vymBaseDir.currentDirPath() );
47 ui.lineEditDir->setText(dir);
49 if ( settings.readLocalEntry (filepath,"/export/xhtml/useImage","yes")=="yes")
53 ui.imageButton->setChecked(useImage);
55 if ( settings.readLocalEntry (filepath,"/export/xhtml/useTextColor","no")=="yes")
59 ui.textColorButton->setChecked(useTextColor);
61 /* TODO this was used in old html export, is not yet in new stylesheet
62 if ( settings.readEntry ("/export/html/useHeading","no")=="yes")
66 checkBox4_2->setChecked(useHeading);
69 if ( settings.readLocalEntry (filepath,"/export/xhtml/saveSettingsInMap","no")=="yes")
70 saveSettingsInMap=true;
72 saveSettingsInMap=false;
73 ui.saveSettingsInMapButton->setChecked(saveSettingsInMap);
75 if ( settings.readEntry ("/export/xhtml/showWarnings","yes")=="yes")
79 ui.warningsButton->setChecked(showWarnings);
81 if ( settings.readEntry ("/export/xhtml/showOutput","no")=="yes")
85 ui.outputButton->setChecked(showOutput);
87 // For testing better use local styles
88 const QString defxsl(vymBaseDir.path() + "/styles/vym2xhtml.xsl");
89 const QString defcss(vymBaseDir.path() + "/styles/vym.css");
90 if (options.isOn ("local"))
96 xsl=settings.readLocalEntry
97 (filepath,"/export/xhtml/xsl",defxsl);
98 css=settings.readLocalEntry
99 (filepath,"/export/xhtml/css",defcss);
101 ui.lineEditXSL->setText(xsl);
102 ui.lineEditCSS->setText(css);
104 prescript=settings.readLocalEntry
105 (filepath,"/export/xhtml/prescript","");
106 ui.lineEditPreScript->setText (prescript);
108 postscript=settings.readLocalEntry
109 (filepath,"/export/xhtml/postscript","");
110 ui.lineEditPostScript->setText (postscript);
112 if (!prescript.isEmpty() || !postscript.isEmpty())
114 QMessageBox::warning( 0, tr( "Warning" ),tr(
115 "The settings saved in the map "
116 "would like to run scripts:\n\n"
118 "Please check, if you really\n"
119 "want to allow this in your system!").arg(prescript+" "+postscript));
124 void ExportXHTMLDialog::setDir(const QString &d)
127 if (dir.right(1)!="/") dir+="/";
130 void ExportXHTMLDialog::dirChanged()
132 setDir (ui.lineEditDir->text());
133 settingsChanged=true;
136 void ExportXHTMLDialog::browseDirectoryPressed()
138 QFileDialog fd( this);
139 fd.setMode (QFileDialog::DirectoryOnly);
140 fd.setCaption(tr("VYM - Export HTML to directory"));
142 fd.setDirectory (QDir::current());
145 if ( fd.exec() == QDialog::Accepted )
147 dir=fd.selectedFile();
148 ui.lineEditDir->setText (dir );
149 settingsChanged=true;
153 void ExportXHTMLDialog::imageButtonPressed(bool b)
156 settingsChanged=true;
159 void ExportXHTMLDialog::textcolorButtonPressed(bool b)
162 settingsChanged=true;
165 void ExportXHTMLDialog::saveSettingsInMapButtonPressed(bool b)
168 settingsChanged=true;
171 void ExportXHTMLDialog::warningsButtonPressed(bool b)
174 settingsChanged=true;
178 void ExportXHTMLDialog::outputButtonPressed(bool b)
181 settingsChanged=true;
184 void ExportXHTMLDialog::cssChanged()
186 css=ui.lineEditCSS->text();
187 settingsChanged=true;
190 void ExportXHTMLDialog::browseCSSPressed()
192 QFileDialog fd( this);
194 fd.setFilter ("Cascading Stylesheet (*.css)");
195 fd.setDirectory (QDir::current());
198 if ( fd.exec() == QDialog::Accepted )
200 css=fd.selectedFile();
201 ui.lineEditCSS->setText (css );
202 settingsChanged=true;
206 void ExportXHTMLDialog::xslChanged()
208 xsl=ui.lineEditXSL->text();
209 settingsChanged=true;
212 void ExportXHTMLDialog::prescriptChanged()
214 prescript=ui.lineEditPreScript->text();
215 settingsChanged=true;
218 void ExportXHTMLDialog::browseXSLPressed()
220 QFileDialog fd( this);
222 fd.setFilter ("Extensible Stylesheet Language (*.xsl)");
223 fd.setDirectory (QDir::current());
226 if ( fd.exec() == QDialog::Accepted )
228 xsl=fd.selectedFile();
229 ui.lineEditXSL->setText (xsl );
230 settingsChanged=true;
234 void ExportXHTMLDialog::postscriptChanged()
236 postscript=ui.lineEditPostScript->text();
237 settingsChanged=true;
240 void ExportXHTMLDialog::browsePreExportButtonPressed()
242 QFileDialog fd( this);
244 fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
245 fd.setDirectory (QDir::current());
248 if ( fd.exec() == QDialog::Accepted )
250 prescript=fd.selectedFile();
251 ui.lineEditPreScript->setText (prescript );
252 settingsChanged=true;
257 void ExportXHTMLDialog::browsePostExportButtonPressed()
259 QFileDialog fd( this);
261 fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
262 fd.setDirectory (QDir::current());
265 if ( fd.exec() == QDialog::Accepted )
267 postscript=fd.selectedFile();
268 ui.lineEditPostScript->setText (postscript );
269 settingsChanged=true;
274 void ExportXHTMLDialog::doExport (const QString &mapname)
276 // Save options to settings file
277 // (but don't save at destructor, which
278 // is called for "cancel", too)
279 settings.setLocalEntry (filepath,"/export/xhtml/exportDir",dir);
280 settings.setLocalEntry (filepath,"/export/xhtml/prescript",prescript);
281 settings.setLocalEntry (filepath,"/export/xhtml/postscript",postscript);
284 settings.setLocalEntry (filepath,"/export/xhtml/useImage","yes");
286 settings.setLocalEntry (filepath,"/export/xhtml/useImage","no");
289 settings.setLocalEntry (filepath,"/export/xhtml/useTextColor","yes");
291 settings.setLocalEntry (filepath,"/export/xhtml/useTextColor","no");
294 settings.writeEntry ("/export/xhtml/showWarnings","yes");
296 settings.writeEntry ("/export/xhtml/showWarnings","no");
299 settings.writeEntry ("/export/xhtml/showOutput","yes");
301 settings.writeEntry ("/export/xhtml/showOutput","no");
304 ipath=vymBaseDir.path()+"/flags/flag-url-16x16.png";
305 if (!options.isOn ("local"))
307 settings.setLocalEntry
308 (filepath,"/export/xhtml/xsl",xsl);
309 settings.setLocalEntry
310 (filepath,"/export/xhtml/css",css);
313 // Provide a smaller URL-icon to improve Layout
315 if (!pm.load(ipath,"PNG") )
316 QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(ipath));
319 if(!pm.save (dir + "flags/flag-url-16x16.png","PNG"))
320 QMessageBox::warning( 0, tr( "Warning" ),tr("Could not write %1").arg(ipath));
321 if (!saveSettingsInMap)
322 settings.clearLocal("/export/xhtml");
324 settings.setLocalEntry
325 (filepath,"/export/xhtml/saveSettingsInMap","yes");
329 QFile css_dst (dir+"vym.css");
330 if (!css_src.open ( QIODevice::ReadOnly))
331 QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(css));
334 if (!css_dst.open( QIODevice::WriteOnly))
335 QMessageBox::warning( 0, tr( "Warning" ), tr("Could not open %1").arg(dir+"vym.css"));
339 QTextStream tsout( &css_dst);
340 QTextStream tsin ( &css_src);
341 QString s= tsin.read();
348 if (!prescript.isEmpty()) runScript (prescript,dir+mapname+".xml");
351 p.addStringParam ("imagemap","images/"+mapname+".png");
353 p.addStringParam ("use.textcolor","1");
354 p.addStringParam ("mapname",mapname+".vym");
356 p.setOutputFile (dir+mapname+".html");
357 p.setInputFile (dir+mapname+".xml");
361 if (!postscript.isEmpty()) runScript (postscript,dir+mapname+".html");
365 void ExportXHTMLDialog::setFilePath(const QString &s)
370 void ExportXHTMLDialog::setMapName(const QString &s)
375 QString ExportXHTMLDialog::getDir()
380 bool ExportXHTMLDialog::warnings()
385 bool ExportXHTMLDialog::hasChanged()
387 return settingsChanged;
391 void ExportXHTMLDialog::runScript(QString spath, QString fpath)
393 spath.replace ("%f",fpath);
394 QStringList args=QStringList::split (' ',spath,false);
396 p.addOutput ("vym is executing: \n" + spath+" "+args.join(" ") );
397 scriptProc->start (spath,args);
398 if (!scriptProc->waitForStarted() )
400 QMessageBox::critical( 0, tr( "Critical Error" ),
401 tr("Could not start %1").arg(spath) );
404 if (!scriptProc->waitForFinished())
405 QMessageBox::critical( 0, tr( "Critical Error" ),
406 tr("%1 didn't exit normally").arg(spath) +
407 scriptProc->getErrout() );
409 if (scriptProc->exitStatus()>0) showOutput=true;
413 p.addOutput (scriptProc->getErrout());
414 p.addOutput (scriptProc->getStdout());