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 if (options.isOn ("local"))
90 xsl=vymBaseDir.path()+"/styles/vym2xhtml.xsl";
91 css=vymBaseDir.path()+"/styles/vym.css";
94 xsl=settings.readLocalEntry
95 (filepath,"/export/xhtml/xsl","/usr/share/vym/styles/vym2xhtml.xsl");
96 css=settings.readLocalEntry
97 (filepath,"/export/xhtml/css","/usr/share/vym/styles/vym.css");
99 ui.lineEditXSL->setText(xsl);
100 ui.lineEditCSS->setText(css);
102 prescript=settings.readLocalEntry
103 (filepath,"/export/xhtml/prescript","");
104 ui.lineEditPreScript->setText (prescript);
106 postscript=settings.readLocalEntry
107 (filepath,"/export/xhtml/postscript","");
108 ui.lineEditPostScript->setText (postscript);
110 if (!prescript.isEmpty() || !postscript.isEmpty())
112 QMessageBox::warning( 0, tr( "Warning" ),tr(
113 "The settings saved in the map "
114 "would like to run scripts:\n\n"
116 "Please check, if you really\n"
117 "want to allow this in your system!").arg(prescript+" "+postscript));
122 void ExportXHTMLDialog::setDir(const QString &d)
125 if (dir.right(1)!="/") dir+="/";
128 void ExportXHTMLDialog::dirChanged()
130 setDir (ui.lineEditDir->text());
131 settingsChanged=true;
134 void ExportXHTMLDialog::browseDirectoryPressed()
136 QFileDialog fd( this);
137 fd.setMode (QFileDialog::DirectoryOnly);
138 fd.setCaption(tr("VYM - Export HTML to directory"));
140 fd.setDirectory (QDir::current());
143 if ( fd.exec() == QDialog::Accepted )
145 dir=fd.selectedFile();
146 ui.lineEditDir->setText (dir );
147 settingsChanged=true;
151 void ExportXHTMLDialog::imageButtonPressed(bool b)
154 settingsChanged=true;
157 void ExportXHTMLDialog::textcolorButtonPressed(bool b)
160 settingsChanged=true;
163 void ExportXHTMLDialog::saveSettingsInMapButtonPressed(bool b)
166 settingsChanged=true;
169 void ExportXHTMLDialog::warningsButtonPressed(bool b)
172 settingsChanged=true;
176 void ExportXHTMLDialog::outputButtonPressed(bool b)
179 settingsChanged=true;
182 void ExportXHTMLDialog::cssChanged()
184 css=ui.lineEditCSS->text();
185 settingsChanged=true;
188 void ExportXHTMLDialog::browseCSSPressed()
190 QFileDialog fd( this);
192 fd.setFilter ("Cascading Stylesheet (*.css)");
193 fd.setDirectory (QDir::current());
196 if ( fd.exec() == QDialog::Accepted )
198 css=fd.selectedFile();
199 ui.lineEditCSS->setText (css );
200 settingsChanged=true;
204 void ExportXHTMLDialog::xslChanged()
206 xsl=ui.lineEditXSL->text();
207 settingsChanged=true;
210 void ExportXHTMLDialog::prescriptChanged()
212 prescript=ui.lineEditPreScript->text();
213 settingsChanged=true;
216 void ExportXHTMLDialog::browseXSLPressed()
218 QFileDialog fd( this);
220 fd.setFilter ("Extensible Stylesheet Language (*.xsl)");
221 fd.setDirectory (QDir::current());
224 if ( fd.exec() == QDialog::Accepted )
226 xsl=fd.selectedFile();
227 ui.lineEditXSL->setText (xsl );
228 settingsChanged=true;
232 void ExportXHTMLDialog::postscriptChanged()
234 postscript=ui.lineEditPostScript->text();
235 settingsChanged=true;
238 void ExportXHTMLDialog::browsePreExportButtonPressed()
240 QFileDialog fd( this);
242 fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
243 fd.setDirectory (QDir::current());
246 if ( fd.exec() == QDialog::Accepted )
248 prescript=fd.selectedFile();
249 ui.lineEditPreScript->setText (prescript );
250 settingsChanged=true;
255 void ExportXHTMLDialog::browsePostExportButtonPressed()
257 QFileDialog fd( this);
259 fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
260 fd.setDirectory (QDir::current());
263 if ( fd.exec() == QDialog::Accepted )
265 postscript=fd.selectedFile();
266 ui.lineEditPostScript->setText (postscript );
267 settingsChanged=true;
272 void ExportXHTMLDialog::doExport (const QString &mapname)
274 // Save options to settings file
275 // (but don't save at destructor, which
276 // is called for "cancel", too)
277 settings.setLocalEntry (filepath,"/export/xhtml/exportDir",dir);
278 settings.setLocalEntry (filepath,"/export/xhtml/prescript",prescript);
279 settings.setLocalEntry (filepath,"/export/xhtml/postscript",postscript);
282 settings.setLocalEntry (filepath,"/export/xhtml/useImage","yes");
284 settings.setLocalEntry (filepath,"/export/xhtml/useImage","no");
287 settings.setLocalEntry (filepath,"/export/xhtml/useTextColor","yes");
289 settings.setLocalEntry (filepath,"/export/xhtml/useTextColor","no");
292 settings.writeEntry ("/export/xhtml/showWarnings","yes");
294 settings.writeEntry ("/export/xhtml/showWarnings","no");
297 settings.writeEntry ("/export/xhtml/showOutput","yes");
299 settings.writeEntry ("/export/xhtml/showOutput","no");
302 ipath=vymBaseDir.path()+"/flags/flag-url-16x16.png";
303 if (!options.isOn ("local"))
305 settings.setLocalEntry
306 (filepath,"/export/xhtml/xsl",xsl);
307 settings.setLocalEntry
308 (filepath,"/export/xhtml/css",css);
311 // Provide a smaller URL-icon to improve Layout
313 if (!pm.load(ipath,"PNG") )
314 QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(ipath));
317 if(!pm.save (dir + "flags/flag-url-16x16.png","PNG"))
318 QMessageBox::warning( 0, tr( "Warning" ),tr("Could not write %1").arg(ipath));
319 if (!saveSettingsInMap)
320 settings.clearLocal("/export/xhtml");
322 settings.setLocalEntry
323 (filepath,"/export/xhtml/saveSettingsInMap","yes");
327 QFile css_dst (dir+"vym.css");
328 if (!css_src.open ( QIODevice::ReadOnly))
329 QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(css));
332 if (!css_dst.open( QIODevice::WriteOnly))
333 QMessageBox::warning( 0, tr( "Warning" ), tr("Could not open %1").arg(dir+"vym.css"));
337 QTextStream tsout( &css_dst);
338 QTextStream tsin ( &css_src);
339 QString s= tsin.read();
346 if (!prescript.isEmpty()) runScript (prescript,dir+mapname+".xml");
349 p.addStringParam ("imagemap","images/"+mapname+".png");
351 p.addStringParam ("use.textcolor","1");
352 p.addStringParam ("mapname",mapname+".vym");
354 p.setOutputFile (dir+mapname+".html");
355 p.setInputFile (dir+mapname+".xml");
359 if (!postscript.isEmpty()) runScript (postscript,dir+mapname+".html");
363 void ExportXHTMLDialog::setFilePath(const QString &s)
368 void ExportXHTMLDialog::setMapName(const QString &s)
373 QString ExportXHTMLDialog::getDir()
378 bool ExportXHTMLDialog::warnings()
383 bool ExportXHTMLDialog::hasChanged()
385 return settingsChanged;
389 void ExportXHTMLDialog::runScript(QString spath, QString fpath)
391 spath.replace ("%f",fpath);
392 QStringList args=QStringList::split (' ',spath,false);
394 p.addOutput ("vym is executing: \n" + spath+" "+args.join(" ") );
395 scriptProc->start (spath,args);
396 if (!scriptProc->waitForStarted() )
398 QMessageBox::critical( 0, tr( "Critical Error" ),
399 tr("Could not start %1").arg(spath) );
402 if (!scriptProc->waitForFinished())
403 QMessageBox::critical( 0, tr( "Critical Error" ),
404 tr("%1 didn't exit normally").arg(spath) +
405 scriptProc->getErrout() );
407 if (scriptProc->exitStatus()>0) showOutput=true;
411 p.addOutput (scriptProc->getErrout());
412 p.addOutput (scriptProc->getStdout());