Added dialog for HTML export. Grouping in Switchboard shortcuts
1 #include "exporthtmldialog.h"
9 #include "warningdialog.h"
12 extern Options options;
13 extern QDir vymBaseDir;
14 extern Settings settings;
17 ExportHTMLDialog::ExportHTMLDialog(QWidget* parent) : QDialog(parent)
22 settingsChanged=false;
23 scriptProc=new Process;
25 // signals and slots connections
26 connect(ui.browseExportDirButton, SIGNAL(pressed()), this, SLOT(browseDirectoryPressed()));
27 connect(ui.outputButton, SIGNAL(toggled(bool)), this, SLOT(outputButtonPressed(bool)));
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.saveSettingsInMapButton, SIGNAL(toggled(bool)), this, SLOT(saveSettingsInMapButtonPressed(bool)));
34 connect(ui.browsePreExportButton, SIGNAL(pressed()), this, SLOT(browsePreExportButtonPressed()));
35 connect(ui.lineEditPreScript, SIGNAL(textChanged(const QString&)), this, SLOT(prescriptChanged()));
36 connect(ui.lineEditPostScript, SIGNAL(textChanged(const QString&)), this, SLOT(postscriptChanged()));
37 connect(ui.browsePostExportButton, SIGNAL(pressed()), this, SLOT(browsePostExportButtonPressed()));
41 void ExportHTMLDialog::readSettings()
44 dir=settings.readLocalEntry (filepath,"/export/html/exportDir",vymBaseDir.currentDirPath() );
45 ui.lineEditDir->setText(dir);
47 if ( settings.readLocalEntry (filepath,"/export/html/useImage","yes")=="yes")
51 ui.imageButton->setChecked(useImage);
53 if ( settings.readLocalEntry (filepath,"/export/html/useTextColor","no")=="yes")
57 ui.textColorButton->setChecked(useTextColor);
59 /* TODO this was used in old html export, is not yet in new stylesheet
60 if ( settings.readEntry ("/export/html/useHeading","no")=="yes")
64 checkBox4_2->setChecked(useHeading);
67 if ( settings.readLocalEntry (filepath,"/export/html/saveSettingsInMap","no")=="yes")
68 saveSettingsInMap=true;
70 saveSettingsInMap=false;
71 ui.saveSettingsInMapButton->setChecked(saveSettingsInMap);
73 if ( settings.readEntry ("/export/html/showOutput","no")=="yes")
77 ui.outputButton->setChecked(showOutput);
79 // For testing better use local styles
80 const QString defcss(vymBaseDir.path() + "/styles/vym.css");
81 if (options.isOn ("local"))
86 css=settings.readLocalEntry
87 (filepath,"/export/html/css",defcss);
89 ui.lineEditCSS->setText(css);
91 prescript=settings.readLocalEntry
92 (filepath,"/export/html/prescript","");
93 ui.lineEditPreScript->setText (prescript);
95 postscript=settings.readLocalEntry
96 (filepath,"/export/html/postscript","");
97 ui.lineEditPostScript->setText (postscript);
99 if (!prescript.isEmpty() || !postscript.isEmpty())
101 QMessageBox::warning( 0, tr( "Warning" ),tr(
102 "The settings saved in the map "
103 "would like to run scripts:\n\n"
105 "Please check, if you really\n"
106 "want to allow this in your system!").arg(prescript+" "+postscript));
111 void ExportHTMLDialog::setDir(const QString &d)
114 if (dir.right(1)!="/") dir+="/";
117 void ExportHTMLDialog::dirChanged()
119 setDir (ui.lineEditDir->text());
120 settingsChanged=true;
123 void ExportHTMLDialog::browseDirectoryPressed()
125 QFileDialog fd( this);
126 fd.setMode (QFileDialog::DirectoryOnly);
127 fd.setCaption(tr("VYM - Export HTML to directory"));
129 fd.setDirectory (QDir::current());
132 if ( fd.exec() == QDialog::Accepted )
134 QDir dir=fd.selectedFile();
135 ui.lineEditDir->setText (dir.path() );
136 settingsChanged=true;
140 void ExportHTMLDialog::imageButtonPressed(bool b)
143 settingsChanged=true;
146 void ExportHTMLDialog::textcolorButtonPressed(bool b)
149 settingsChanged=true;
152 void ExportHTMLDialog::saveSettingsInMapButtonPressed(bool b)
155 settingsChanged=true;
158 void ExportHTMLDialog::warningsButtonPressed(bool b)
161 settingsChanged=true;
165 void ExportHTMLDialog::outputButtonPressed(bool b)
168 settingsChanged=true;
171 void ExportHTMLDialog::cssChanged()
173 css=ui.lineEditCSS->text();
174 settingsChanged=true;
177 QString ExportHTMLDialog::getCSSPath()
182 void ExportHTMLDialog::browseCSSPressed()
184 QFileDialog fd( this);
186 fd.setFilter ("Cascading Stylesheet (*.css)");
187 fd.setDirectory (QDir::current());
190 if ( fd.exec() == QDialog::Accepted )
192 css=fd.selectedFile();
193 ui.lineEditCSS->setText (css );
194 settingsChanged=true;
198 void ExportHTMLDialog::prescriptChanged()
200 prescript=ui.lineEditPreScript->text();
201 settingsChanged=true;
204 void ExportHTMLDialog::postscriptChanged()
206 postscript=ui.lineEditPostScript->text();
207 settingsChanged=true;
210 void ExportHTMLDialog::browsePreExportButtonPressed()
212 QFileDialog fd( this);
214 fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
215 fd.setDirectory (QDir::current());
218 if ( fd.exec() == QDialog::Accepted )
220 prescript=fd.selectedFile();
221 ui.lineEditPreScript->setText (prescript );
222 settingsChanged=true;
227 void ExportHTMLDialog::browsePostExportButtonPressed()
229 QFileDialog fd( this);
231 fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
232 fd.setDirectory (QDir::current());
235 if ( fd.exec() == QDialog::Accepted )
237 postscript=fd.selectedFile();
238 ui.lineEditPostScript->setText (postscript );
239 settingsChanged=true;
244 void ExportHTMLDialog::doExport (const QString &mapname)
247 // Save options to settings file
248 // (but don't save at destructor, which
249 // is called for "cancel", too)
250 settings.setLocalEntry (filepath,"/export/html/exportDir",dir);
251 settings.setLocalEntry (filepath,"/export/html/prescript",prescript);
252 settings.setLocalEntry (filepath,"/export/html/postscript",postscript);
255 settings.setLocalEntry (filepath,"/export/html/useImage","yes");
257 settings.setLocalEntry (filepath,"/export/html/useImage","no");
260 settings.setLocalEntry (filepath,"/export/html/useTextColor","yes");
262 settings.setLocalEntry (filepath,"/export/html/useTextColor","no");
265 settings.writeEntry ("/export/html/showWarnings","yes");
267 settings.writeEntry ("/export/html/showWarnings","no");
270 settings.writeEntry ("/export/html/showOutput","yes");
272 settings.writeEntry ("/export/html/showOutput","no");
275 ipath=vymBaseDir.path()+"/flags/flag-url-16x16.png";
276 if (!options.isOn ("local"))
278 settings.setLocalEntry
279 (filepath,"/export/html/css",css);
282 if (!saveSettingsInMap)
283 settings.clearLocal("/export/html");
285 settings.setLocalEntry
286 (filepath,"/export/html/saveSettingsInMap","yes");
288 // Provide a smaller URL-icon to improve Layout //FIXME-1
290 if (!pm.load(ipath,"PNG") )
291 QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(ipath));
294 if(!pm.save (dir + "flags/flag-url-16x16.png","PNG"))
295 QMessageBox::warning( 0, tr( "Warning" ),tr("Could not write %1").arg(ipath));
297 if (!prescript.isEmpty()) runScript (prescript,dir+mapname+".xml");
301 p.addStringParam ("imagemap","images/"+mapname+".png");
303 p.addStringParam ("use.textcolor","1");
304 p.addStringParam ("mapname",mapname+".vym");
306 p.setOutputFile (dir+mapname+".html");
307 p.setInputFile (dir+mapname+".xml");
311 if (!postscript.isEmpty()) runScript (postscript,dir+mapname+".html");
315 void ExportHTMLDialog::setFilePath(const QString &s)
320 void ExportHTMLDialog::setMapName(const QString &s)
325 QString ExportHTMLDialog::getDir()
330 bool ExportHTMLDialog::warnings()
335 bool ExportHTMLDialog::hasChanged()
337 return settingsChanged;
341 void ExportHTMLDialog::runScript(QString spath, QString fpath)
343 spath.replace ("%f",fpath);
344 QStringList args=QStringList::split (' ',spath,false);
346 //FIXME-1 p.addOutput ("vym is executing: \n" + spath+" "+args.join(" ") );
347 scriptProc->start (spath,args);
348 if (!scriptProc->waitForStarted() )
350 QMessageBox::critical( 0, tr( "Critical Error" ),
351 tr("Could not start %1").arg(spath) );
354 if (!scriptProc->waitForFinished())
355 QMessageBox::critical( 0, tr( "Critical Error" ),
356 tr("%1 didn't exit normally").arg(spath) +
357 scriptProc->getErrout() );
359 if (scriptProc->exitStatus()>0) showOutput=true;
364 p.addOutput (scriptProc->getErrout());
365 p.addOutput (scriptProc->getStdout());