1 #include "exportxhtmldialog.h"
11 extern Options options;
12 extern QDir vymBaseDir;
13 extern Settings settings;
15 ExportXHTMLDialog::ExportXHTMLDialog(QWidget* parent) : QDialog(parent)
20 settingsChanged=false;
21 scriptProc=new Process;
23 // signals and slots connections
24 connect(ui.browseExportDirButton, SIGNAL(pressed()), this, SLOT(browseDirectoryPressed()));
25 connect(ui.outputButton, SIGNAL(toggled(bool)), this, SLOT(outputButtonPressed(bool)));
26 connect(ui.browseXSLButton, SIGNAL(pressed()), this, SLOT(browseXSLPressed()));
27 connect(ui.browseCSSButton, SIGNAL(pressed()), this, SLOT(browseCSSPressed()));
28 connect(ui.imageButton, SIGNAL(toggled(bool)), this, SLOT(imageButtonPressed(bool)));
29 connect(ui.textColorButton, SIGNAL(toggled(bool)), this, SLOT(textcolorButtonPressed(bool)));
30 connect(ui.lineEditDir, SIGNAL(textChanged(const QString&)), this, SLOT(dirChanged()));
31 connect(ui.lineEditCSS, SIGNAL(textChanged(const QString&)), this, SLOT(cssChanged()));
32 connect(ui.lineEditXSL, SIGNAL(textChanged(const QString&)), this, SLOT(xslChanged()));
33 connect(ui.warningsButton, SIGNAL(toggled(bool)), this, SLOT(warningsButtonPressed(bool)));
34 connect(ui.saveSettingsInMapButton, SIGNAL(toggled(bool)), this, SLOT(saveSettingsInMapButtonPressed(bool)));
35 connect(ui.browsePreExportButton, SIGNAL(pressed()), this, SLOT(browsePreExportButtonPressed()));
36 connect(ui.lineEditPreScript, SIGNAL(textChanged(const QString&)), this, SLOT(prescriptChanged()));
37 connect(ui.lineEditPostScript, SIGNAL(textChanged(const QString&)), this, SLOT(postscriptChanged()));
38 connect(ui.browsePostExportButton, SIGNAL(pressed()), this, SLOT(browsePostExportButtonPressed()));
42 void ExportXHTMLDialog::readSettings()
45 dir=settings.readLocalEntry (filepath,"/export/xhtml/exportDir",vymBaseDir.currentDirPath() );
46 ui.lineEditDir->setText(dir);
48 if ( settings.readLocalEntry (filepath,"/export/xhtml/useImage","yes")=="yes")
52 ui.imageButton->setChecked(useImage);
54 if ( settings.readLocalEntry (filepath,"/export/xhtml/useTextColor","no")=="yes")
58 ui.textColorButton->setChecked(useTextColor);
60 /* TODO this was used in old html export, is not yet in new stylesheet
61 if ( settings.readEntry ("/export/html/useHeading","no")=="yes")
65 checkBox4_2->setChecked(useHeading);
68 if ( settings.readLocalEntry (filepath,"/export/xhtml/saveSettingsInMap","no")=="yes")
69 saveSettingsInMap=true;
71 saveSettingsInMap=false;
72 ui.saveSettingsInMapButton->setChecked(saveSettingsInMap);
74 if ( settings.readEntry ("/export/xhtml/showWarnings","yes")=="yes")
78 ui.warningsButton->setChecked(showWarnings);
80 if ( settings.readEntry ("/export/xhtml/showOutput","no")=="yes")
84 ui.outputButton->setChecked(showOutput);
86 // For testing better use local styles
87 if (options.isOn ("local"))
89 xsl=vymBaseDir.path()+"/styles/vym2xhtml.xsl";
90 css=vymBaseDir.path()+"/styles/vym.css";
93 xsl=settings.readLocalEntry
94 (filepath,"/export/xhtml/xsl","/usr/share/vym/styles/vym2xhtml.xsl");
95 css=settings.readLocalEntry
96 (filepath,"/export/xhtml/css","/usr/share/vym/styles/vym.css");
98 ui.lineEditXSL->setText(xsl);
99 ui.lineEditCSS->setText(css);
101 prescript=settings.readLocalEntry
102 (filepath,"/export/xhtml/prescript","");
103 ui.lineEditPreScript->setText (prescript);
105 postscript=settings.readLocalEntry
106 (filepath,"/export/xhtml/postscript","");
107 ui.lineEditPostScript->setText (postscript);
109 if (!prescript.isEmpty() || !postscript.isEmpty())
111 QMessageBox::warning( 0, tr( "Warning" ),tr(
112 "The settings saved in the map "
113 "would like to run scripts:\n\n"
115 "Please check, if you really\n"
116 "want to allow this in your system!").arg(prescript+" "+postscript));
121 void ExportXHTMLDialog::dirChanged()
123 dir=ui.lineEditDir->text();
124 if (dir.right(1)!="/")
126 settingsChanged=true;
129 void ExportXHTMLDialog::browseDirectoryPressed()
131 QFileDialog fd( this);
132 fd.setMode (QFileDialog::DirectoryOnly);
133 fd.setCaption(tr("VYM - Export HTML to directory"));
135 fd.setDirectory (QDir::current());
138 if ( fd.exec() == QDialog::Accepted )
140 dir=fd.selectedFile();
141 ui.lineEditDir->setText (dir );
142 settingsChanged=true;
146 void ExportXHTMLDialog::imageButtonPressed(bool b)
149 settingsChanged=true;
152 void ExportXHTMLDialog::textcolorButtonPressed(bool b)
155 settingsChanged=true;
158 void ExportXHTMLDialog::saveSettingsInMapButtonPressed(bool b)
161 settingsChanged=true;
164 void ExportXHTMLDialog::warningsButtonPressed(bool b)
167 settingsChanged=true;
171 void ExportXHTMLDialog::outputButtonPressed(bool b)
174 settingsChanged=true;
177 void ExportXHTMLDialog::cssChanged()
179 css=ui.lineEditCSS->text();
180 settingsChanged=true;
183 void ExportXHTMLDialog::browseCSSPressed()
185 QFileDialog fd( this);
187 fd.setFilter ("Cascading Stylesheet (*.css)");
188 fd.setDirectory (QDir::current());
191 if ( fd.exec() == QDialog::Accepted )
193 css=fd.selectedFile();
194 ui.lineEditCSS->setText (css );
195 settingsChanged=true;
199 void ExportXHTMLDialog::xslChanged()
201 xsl=ui.lineEditXSL->text();
202 settingsChanged=true;
205 void ExportXHTMLDialog::prescriptChanged()
207 prescript=ui.lineEditPreScript->text();
208 settingsChanged=true;
211 void ExportXHTMLDialog::browseXSLPressed()
213 QFileDialog fd( this);
215 fd.setFilter ("Extensible Stylesheet Language (*.xsl)");
216 fd.setDirectory (QDir::current());
219 if ( fd.exec() == QDialog::Accepted )
221 xsl=fd.selectedFile();
222 ui.lineEditXSL->setText (xsl );
223 settingsChanged=true;
227 void ExportXHTMLDialog::postscriptChanged()
229 postscript=ui.lineEditPostScript->text();
230 settingsChanged=true;
233 void ExportXHTMLDialog::browsePreExportButtonPressed()
235 QFileDialog fd( this);
237 fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
238 fd.setDirectory (QDir::current());
241 if ( fd.exec() == QDialog::Accepted )
243 prescript=fd.selectedFile();
244 ui.lineEditPreScript->setText (prescript );
245 settingsChanged=true;
250 void ExportXHTMLDialog::browsePostExportButtonPressed()
252 QFileDialog fd( this);
254 fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
255 fd.setDirectory (QDir::current());
258 if ( fd.exec() == QDialog::Accepted )
260 postscript=fd.selectedFile();
261 ui.lineEditPostScript->setText (postscript );
262 settingsChanged=true;
267 void ExportXHTMLDialog::doExport (const QString &mapname)
269 // Save options to settings file
270 // (but don't save at destructor, which
271 // is called for "cancel", too)
272 settings.setLocalEntry (filepath,"/export/xhtml/exportDir",dir);
273 settings.setLocalEntry (filepath,"/export/xhtml/prescript",prescript);
274 settings.setLocalEntry (filepath,"/export/xhtml/postscript",postscript);
277 settings.setLocalEntry (filepath,"/export/xhtml/useImage","yes");
279 settings.setLocalEntry (filepath,"/export/xhtml/useImage","no");
282 settings.setLocalEntry (filepath,"/export/xhtml/useTextColor","yes");
284 settings.setLocalEntry (filepath,"/export/xhtml/useTextColor","no");
287 settings.writeEntry ("/export/xhtml/showWarnings","yes");
289 settings.writeEntry ("/export/xhtml/showWarnings","no");
292 settings.writeEntry ("/export/xhtml/showOutput","yes");
294 settings.writeEntry ("/export/xhtml/showOutput","no");
297 ipath=vymBaseDir.path()+"/flags/flag-url-16x16.png";
298 if (!options.isOn ("local"))
300 settings.setLocalEntry
301 (filepath,"/export/xhtml/xsl",xsl);
302 settings.setLocalEntry
303 (filepath,"/export/xhtml/css",css);
306 // Provide a smaller URL-icon to improve Layout
308 if (!pm.load(ipath,"PNG") )
309 QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(ipath));
312 if(!pm.save (dir + "flags/flag-url-16x16.png","PNG"))
313 QMessageBox::warning( 0, tr( "Warning" ),tr("Could not write %1").arg(ipath));
314 if (!saveSettingsInMap)
315 settings.clearLocal("/export/xhtml");
317 settings.setLocalEntry
318 (filepath,"/export/xhtml/saveSettingsInMap","yes");
322 QFile css_dst (dir+"vym.css");
323 if (!css_src.open ( QIODevice::ReadOnly))
324 QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(css));
327 if (!css_dst.open( QIODevice::WriteOnly))
328 QMessageBox::warning( 0, tr( "Warning" ), tr("Could not open %1").arg(dir+"vym.css"));
332 QTextStream tsout( &css_dst);
333 QTextStream tsin ( &css_src);
334 QString s= tsin.read();
341 if (!prescript.isEmpty()) runScript (prescript,dir+mapname+".xml");
344 p.addStringParam ("imagemap","images/"+mapname+".png");
346 p.addStringParam ("use.textcolor","1");
347 p.addStringParam ("mapname",mapname+".vym");
349 p.setOutputFile (dir+mapname+".html");
350 p.setInputFile (dir+mapname+".xml");
354 if (!postscript.isEmpty()) runScript (postscript,dir+mapname+".html");
358 void ExportXHTMLDialog::setFilePath(const QString &s)
363 void ExportXHTMLDialog::setMapName(const QString &s)
368 QString ExportXHTMLDialog::getDir()
373 bool ExportXHTMLDialog::warnings()
378 bool ExportXHTMLDialog::hasChanged()
380 return settingsChanged;
384 void ExportXHTMLDialog::runScript(QString spath, QString fpath)
386 spath.replace ("%f",fpath);
387 QStringList args=QStringList::split (' ',spath,false);
389 p.addOutput ("vym is executing: \n" + spath+" "+args.join(" ") );
390 scriptProc->start (spath,args);
391 if (!scriptProc->waitForStarted() )
393 QMessageBox::critical( 0, tr( "Critical Error" ),
394 tr("Could not start %1").arg(spath) );
397 scriptProc->waitFinished();
398 if (scriptProc->exitStatus()!=QProcess::NormalExit )
399 QMessageBox::critical( 0, tr( "Critical Error" ),
400 tr("%1 didn't exit normally").arg(spath) +
401 scriptProc->getErrout() );
403 if (scriptProc->exitStatus()>0) showOutput=true;
407 p.addOutput (scriptProc->getErrout());
408 p.addOutput (scriptProc->getStdout());