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)
277 // Save options to settings file
278 // (but don't save at destructor, which
279 // is called for "cancel", too)
280 settings.setLocalEntry (filepath,"/export/xhtml/exportDir",dir);
281 settings.setLocalEntry (filepath,"/export/xhtml/prescript",prescript);
282 settings.setLocalEntry (filepath,"/export/xhtml/postscript",postscript);
285 settings.setLocalEntry (filepath,"/export/xhtml/useImage","yes");
287 settings.setLocalEntry (filepath,"/export/xhtml/useImage","no");
290 settings.setLocalEntry (filepath,"/export/xhtml/useTextColor","yes");
292 settings.setLocalEntry (filepath,"/export/xhtml/useTextColor","no");
295 settings.writeEntry ("/export/xhtml/showWarnings","yes");
297 settings.writeEntry ("/export/xhtml/showWarnings","no");
300 settings.writeEntry ("/export/xhtml/showOutput","yes");
302 settings.writeEntry ("/export/xhtml/showOutput","no");
305 ipath=vymBaseDir.path()+"/flags/flag-url-16x16.png";
306 if (!options.isOn ("local"))
308 settings.setLocalEntry
309 (filepath,"/export/xhtml/xsl",xsl);
310 settings.setLocalEntry
311 (filepath,"/export/xhtml/css",css);
314 if (!saveSettingsInMap)
315 settings.clearLocal("/export/xhtml");
317 settings.setLocalEntry
318 (filepath,"/export/xhtml/saveSettingsInMap","yes");
320 // Provide a smaller URL-icon to improve Layout
322 if (!pm.load(ipath,"PNG") )
323 QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(ipath));
326 if(!pm.save (dir + "flags/flag-url-16x16.png","PNG"))
327 QMessageBox::warning( 0, tr( "Warning" ),tr("Could not write %1").arg(ipath));
331 QFile css_dst (dir+"vym.css");
332 if (!css_src.open ( QIODevice::ReadOnly))
333 QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(css));
336 if (!css_dst.open( QIODevice::WriteOnly))
337 QMessageBox::warning( 0, tr( "Warning" ), tr("Could not open %1").arg(dir+"vym.css"));
341 QTextStream tsout( &css_dst);
342 QTextStream tsin ( &css_src);
343 QString s= tsin.read();
350 if (!prescript.isEmpty()) runScript (prescript,dir+mapname+".xml");
353 p.addStringParam ("imagemap","images/"+mapname+".png");
355 p.addStringParam ("use.textcolor","1");
356 p.addStringParam ("mapname",mapname+".vym");
358 p.setOutputFile (dir+mapname+".html");
359 p.setInputFile (dir+mapname+".xml");
363 if (!postscript.isEmpty()) runScript (postscript,dir+mapname+".html");
367 void ExportXHTMLDialog::setFilePath(const QString &s)
372 void ExportXHTMLDialog::setMapName(const QString &s)
377 QString ExportXHTMLDialog::getDir()
382 bool ExportXHTMLDialog::warnings()
387 bool ExportXHTMLDialog::hasChanged()
389 return settingsChanged;
393 void ExportXHTMLDialog::runScript(QString spath, QString fpath)
395 spath.replace ("%f",fpath);
396 QStringList args=QStringList::split (' ',spath,false);
398 p.addOutput ("vym is executing: \n" + spath+" "+args.join(" ") );
399 scriptProc->start (spath,args);
400 if (!scriptProc->waitForStarted() )
402 QMessageBox::critical( 0, tr( "Critical Error" ),
403 tr("Could not start %1").arg(spath) );
406 if (!scriptProc->waitForFinished())
407 QMessageBox::critical( 0, tr( "Critical Error" ),
408 tr("%1 didn't exit normally").arg(spath) +
409 scriptProc->getErrout() );
411 if (scriptProc->exitStatus()>0) showOutput=true;
415 p.addOutput (scriptProc->getErrout());
416 p.addOutput (scriptProc->getStdout());