insilmaril@824
|
1 |
#include "exporthtmldialog.h"
|
insilmaril@824
|
2 |
|
insilmaril@824
|
3 |
#include <QFileDialog>
|
insilmaril@824
|
4 |
#include <QMessageBox>
|
insilmaril@824
|
5 |
#include <QTextStream>
|
insilmaril@824
|
6 |
|
insilmaril@824
|
7 |
#include "options.h"
|
insilmaril@824
|
8 |
#include "settings.h"
|
insilmaril@824
|
9 |
#include "warningdialog.h"
|
insilmaril@824
|
10 |
|
insilmaril@824
|
11 |
|
insilmaril@824
|
12 |
extern Options options;
|
insilmaril@824
|
13 |
extern QDir vymBaseDir;
|
insilmaril@824
|
14 |
extern Settings settings;
|
insilmaril@824
|
15 |
extern bool debug;
|
insilmaril@824
|
16 |
|
insilmaril@824
|
17 |
ExportHTMLDialog::ExportHTMLDialog(QWidget* parent) : QDialog(parent)
|
insilmaril@824
|
18 |
{
|
insilmaril@824
|
19 |
ui.setupUi(this);
|
insilmaril@824
|
20 |
|
insilmaril@824
|
21 |
filepath="";
|
insilmaril@824
|
22 |
settingsChanged=false;
|
insilmaril@824
|
23 |
scriptProc=new Process;
|
insilmaril@824
|
24 |
|
insilmaril@824
|
25 |
// signals and slots connections
|
insilmaril@824
|
26 |
connect(ui.browseExportDirButton, SIGNAL(pressed()), this, SLOT(browseDirectoryPressed()));
|
insilmaril@824
|
27 |
connect(ui.outputButton, SIGNAL(toggled(bool)), this, SLOT(outputButtonPressed(bool)));
|
insilmaril@824
|
28 |
connect(ui.browseCSSButton, SIGNAL(pressed()), this, SLOT(browseCSSPressed()));
|
insilmaril@824
|
29 |
connect(ui.imageButton, SIGNAL(toggled(bool)), this, SLOT(imageButtonPressed(bool)));
|
insilmaril@824
|
30 |
connect(ui.textColorButton, SIGNAL(toggled(bool)), this, SLOT(textcolorButtonPressed(bool)));
|
insilmaril@824
|
31 |
connect(ui.lineEditDir, SIGNAL(textChanged(const QString&)), this, SLOT(dirChanged()));
|
insilmaril@824
|
32 |
connect(ui.lineEditCSS, SIGNAL(textChanged(const QString&)), this, SLOT(cssChanged()));
|
insilmaril@824
|
33 |
connect(ui.saveSettingsInMapButton, SIGNAL(toggled(bool)), this, SLOT(saveSettingsInMapButtonPressed(bool)));
|
insilmaril@824
|
34 |
connect(ui.browsePreExportButton, SIGNAL(pressed()), this, SLOT(browsePreExportButtonPressed()));
|
insilmaril@824
|
35 |
connect(ui.lineEditPreScript, SIGNAL(textChanged(const QString&)), this, SLOT(prescriptChanged()));
|
insilmaril@824
|
36 |
connect(ui.lineEditPostScript, SIGNAL(textChanged(const QString&)), this, SLOT(postscriptChanged()));
|
insilmaril@824
|
37 |
connect(ui.browsePostExportButton, SIGNAL(pressed()), this, SLOT(browsePostExportButtonPressed()));
|
insilmaril@824
|
38 |
}
|
insilmaril@824
|
39 |
|
insilmaril@824
|
40 |
|
insilmaril@824
|
41 |
void ExportHTMLDialog::readSettings()
|
insilmaril@824
|
42 |
{
|
insilmaril@824
|
43 |
|
insilmaril@824
|
44 |
dir=settings.readLocalEntry (filepath,"/export/html/exportDir",vymBaseDir.currentDirPath() );
|
insilmaril@824
|
45 |
ui.lineEditDir->setText(dir);
|
insilmaril@824
|
46 |
|
insilmaril@824
|
47 |
if ( settings.readLocalEntry (filepath,"/export/html/useImage","yes")=="yes")
|
insilmaril@824
|
48 |
useImage=true;
|
insilmaril@824
|
49 |
else
|
insilmaril@824
|
50 |
useImage=false;
|
insilmaril@824
|
51 |
ui.imageButton->setChecked(useImage);
|
insilmaril@824
|
52 |
|
insilmaril@824
|
53 |
if ( settings.readLocalEntry (filepath,"/export/html/useTextColor","no")=="yes")
|
insilmaril@824
|
54 |
useTextColor=true;
|
insilmaril@824
|
55 |
else
|
insilmaril@824
|
56 |
useTextColor=false;
|
insilmaril@824
|
57 |
ui.textColorButton->setChecked(useTextColor);
|
insilmaril@824
|
58 |
|
insilmaril@824
|
59 |
/* TODO this was used in old html export, is not yet in new stylesheet
|
insilmaril@824
|
60 |
if ( settings.readEntry ("/export/html/useHeading","no")=="yes")
|
insilmaril@824
|
61 |
useHeading=true;
|
insilmaril@824
|
62 |
else
|
insilmaril@824
|
63 |
useHeading=false;
|
insilmaril@824
|
64 |
checkBox4_2->setChecked(useHeading);
|
insilmaril@824
|
65 |
*/
|
insilmaril@824
|
66 |
|
insilmaril@824
|
67 |
if ( settings.readLocalEntry (filepath,"/export/html/saveSettingsInMap","no")=="yes")
|
insilmaril@824
|
68 |
saveSettingsInMap=true;
|
insilmaril@824
|
69 |
else
|
insilmaril@824
|
70 |
saveSettingsInMap=false;
|
insilmaril@824
|
71 |
ui.saveSettingsInMapButton->setChecked(saveSettingsInMap);
|
insilmaril@824
|
72 |
|
insilmaril@824
|
73 |
if ( settings.readEntry ("/export/html/showOutput","no")=="yes")
|
insilmaril@824
|
74 |
showOutput=true;
|
insilmaril@824
|
75 |
else
|
insilmaril@824
|
76 |
showOutput=false;
|
insilmaril@824
|
77 |
ui.outputButton->setChecked(showOutput);
|
insilmaril@824
|
78 |
|
insilmaril@824
|
79 |
// For testing better use local styles
|
insilmaril@824
|
80 |
const QString defcss(vymBaseDir.path() + "/styles/vym.css");
|
insilmaril@824
|
81 |
if (options.isOn ("local"))
|
insilmaril@824
|
82 |
{
|
insilmaril@824
|
83 |
css=defcss;
|
insilmaril@824
|
84 |
} else
|
insilmaril@824
|
85 |
{
|
insilmaril@824
|
86 |
css=settings.readLocalEntry
|
insilmaril@824
|
87 |
(filepath,"/export/html/css",defcss);
|
insilmaril@824
|
88 |
}
|
insilmaril@824
|
89 |
ui.lineEditCSS->setText(css);
|
insilmaril@824
|
90 |
|
insilmaril@824
|
91 |
prescript=settings.readLocalEntry
|
insilmaril@824
|
92 |
(filepath,"/export/html/prescript","");
|
insilmaril@824
|
93 |
ui.lineEditPreScript->setText (prescript);
|
insilmaril@824
|
94 |
|
insilmaril@824
|
95 |
postscript=settings.readLocalEntry
|
insilmaril@824
|
96 |
(filepath,"/export/html/postscript","");
|
insilmaril@824
|
97 |
ui.lineEditPostScript->setText (postscript);
|
insilmaril@824
|
98 |
|
insilmaril@824
|
99 |
if (!prescript.isEmpty() || !postscript.isEmpty())
|
insilmaril@824
|
100 |
{
|
insilmaril@824
|
101 |
QMessageBox::warning( 0, tr( "Warning" ),tr(
|
insilmaril@824
|
102 |
"The settings saved in the map "
|
insilmaril@824
|
103 |
"would like to run scripts:\n\n"
|
insilmaril@824
|
104 |
"%1\n\n"
|
insilmaril@824
|
105 |
"Please check, if you really\n"
|
insilmaril@824
|
106 |
"want to allow this in your system!").arg(prescript+" "+postscript));
|
insilmaril@824
|
107 |
|
insilmaril@824
|
108 |
}
|
insilmaril@824
|
109 |
}
|
insilmaril@824
|
110 |
|
insilmaril@824
|
111 |
void ExportHTMLDialog::setDir(const QString &d)
|
insilmaril@824
|
112 |
{
|
insilmaril@824
|
113 |
dir=d;
|
insilmaril@824
|
114 |
if (dir.right(1)!="/") dir+="/";
|
insilmaril@824
|
115 |
}
|
insilmaril@824
|
116 |
|
insilmaril@824
|
117 |
void ExportHTMLDialog::dirChanged()
|
insilmaril@824
|
118 |
{
|
insilmaril@824
|
119 |
setDir (ui.lineEditDir->text());
|
insilmaril@824
|
120 |
settingsChanged=true;
|
insilmaril@824
|
121 |
}
|
insilmaril@824
|
122 |
|
insilmaril@824
|
123 |
void ExportHTMLDialog::browseDirectoryPressed()
|
insilmaril@824
|
124 |
{
|
insilmaril@824
|
125 |
QFileDialog fd( this);
|
insilmaril@824
|
126 |
fd.setMode (QFileDialog::DirectoryOnly);
|
insilmaril@824
|
127 |
fd.setCaption(tr("VYM - Export HTML to directory"));
|
insilmaril@824
|
128 |
fd.setModal (true);
|
insilmaril@824
|
129 |
fd.setDirectory (QDir::current());
|
insilmaril@824
|
130 |
fd.show();
|
insilmaril@824
|
131 |
|
insilmaril@824
|
132 |
if ( fd.exec() == QDialog::Accepted )
|
insilmaril@824
|
133 |
{
|
insilmaril@824
|
134 |
QDir dir=fd.selectedFile();
|
insilmaril@824
|
135 |
ui.lineEditDir->setText (dir.path() );
|
insilmaril@824
|
136 |
settingsChanged=true;
|
insilmaril@824
|
137 |
}
|
insilmaril@824
|
138 |
}
|
insilmaril@824
|
139 |
|
insilmaril@824
|
140 |
void ExportHTMLDialog::imageButtonPressed(bool b)
|
insilmaril@824
|
141 |
{
|
insilmaril@824
|
142 |
useImage=b;
|
insilmaril@824
|
143 |
settingsChanged=true;
|
insilmaril@824
|
144 |
}
|
insilmaril@824
|
145 |
|
insilmaril@824
|
146 |
void ExportHTMLDialog::textcolorButtonPressed(bool b)
|
insilmaril@824
|
147 |
{
|
insilmaril@824
|
148 |
useTextColor=b;
|
insilmaril@824
|
149 |
settingsChanged=true;
|
insilmaril@824
|
150 |
}
|
insilmaril@824
|
151 |
|
insilmaril@824
|
152 |
void ExportHTMLDialog::saveSettingsInMapButtonPressed(bool b)
|
insilmaril@824
|
153 |
{
|
insilmaril@824
|
154 |
saveSettingsInMap=b;
|
insilmaril@824
|
155 |
settingsChanged=true;
|
insilmaril@824
|
156 |
}
|
insilmaril@824
|
157 |
|
insilmaril@824
|
158 |
void ExportHTMLDialog::warningsButtonPressed(bool b)
|
insilmaril@824
|
159 |
{
|
insilmaril@824
|
160 |
showWarnings=b;
|
insilmaril@824
|
161 |
settingsChanged=true;
|
insilmaril@824
|
162 |
}
|
insilmaril@824
|
163 |
|
insilmaril@824
|
164 |
|
insilmaril@824
|
165 |
void ExportHTMLDialog::outputButtonPressed(bool b)
|
insilmaril@824
|
166 |
{
|
insilmaril@824
|
167 |
showOutput=b;
|
insilmaril@824
|
168 |
settingsChanged=true;
|
insilmaril@824
|
169 |
}
|
insilmaril@824
|
170 |
|
insilmaril@824
|
171 |
void ExportHTMLDialog::cssChanged()
|
insilmaril@824
|
172 |
{
|
insilmaril@824
|
173 |
css=ui.lineEditCSS->text();
|
insilmaril@824
|
174 |
settingsChanged=true;
|
insilmaril@824
|
175 |
}
|
insilmaril@824
|
176 |
|
insilmaril@824
|
177 |
QString ExportHTMLDialog::getCSSPath()
|
insilmaril@824
|
178 |
{
|
insilmaril@824
|
179 |
return css;
|
insilmaril@824
|
180 |
}
|
insilmaril@824
|
181 |
|
insilmaril@824
|
182 |
void ExportHTMLDialog::browseCSSPressed()
|
insilmaril@824
|
183 |
{
|
insilmaril@824
|
184 |
QFileDialog fd( this);
|
insilmaril@824
|
185 |
fd.setModal (true);
|
insilmaril@824
|
186 |
fd.setFilter ("Cascading Stylesheet (*.css)");
|
insilmaril@824
|
187 |
fd.setDirectory (QDir::current());
|
insilmaril@824
|
188 |
fd.show();
|
insilmaril@824
|
189 |
|
insilmaril@824
|
190 |
if ( fd.exec() == QDialog::Accepted )
|
insilmaril@824
|
191 |
{
|
insilmaril@824
|
192 |
css=fd.selectedFile();
|
insilmaril@824
|
193 |
ui.lineEditCSS->setText (css );
|
insilmaril@824
|
194 |
settingsChanged=true;
|
insilmaril@824
|
195 |
}
|
insilmaril@824
|
196 |
}
|
insilmaril@824
|
197 |
|
insilmaril@824
|
198 |
void ExportHTMLDialog::prescriptChanged()
|
insilmaril@824
|
199 |
{
|
insilmaril@824
|
200 |
prescript=ui.lineEditPreScript->text();
|
insilmaril@824
|
201 |
settingsChanged=true;
|
insilmaril@824
|
202 |
}
|
insilmaril@824
|
203 |
|
insilmaril@824
|
204 |
void ExportHTMLDialog::postscriptChanged()
|
insilmaril@824
|
205 |
{
|
insilmaril@824
|
206 |
postscript=ui.lineEditPostScript->text();
|
insilmaril@824
|
207 |
settingsChanged=true;
|
insilmaril@824
|
208 |
}
|
insilmaril@824
|
209 |
|
insilmaril@824
|
210 |
void ExportHTMLDialog::browsePreExportButtonPressed()
|
insilmaril@824
|
211 |
{
|
insilmaril@824
|
212 |
QFileDialog fd( this);
|
insilmaril@824
|
213 |
fd.setModal (true);
|
insilmaril@824
|
214 |
fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
|
insilmaril@824
|
215 |
fd.setDirectory (QDir::current());
|
insilmaril@824
|
216 |
fd.show();
|
insilmaril@824
|
217 |
|
insilmaril@824
|
218 |
if ( fd.exec() == QDialog::Accepted )
|
insilmaril@824
|
219 |
{
|
insilmaril@824
|
220 |
prescript=fd.selectedFile();
|
insilmaril@824
|
221 |
ui.lineEditPreScript->setText (prescript );
|
insilmaril@824
|
222 |
settingsChanged=true;
|
insilmaril@824
|
223 |
}
|
insilmaril@824
|
224 |
|
insilmaril@824
|
225 |
}
|
insilmaril@824
|
226 |
|
insilmaril@824
|
227 |
void ExportHTMLDialog::browsePostExportButtonPressed()
|
insilmaril@824
|
228 |
{
|
insilmaril@824
|
229 |
QFileDialog fd( this);
|
insilmaril@824
|
230 |
fd.setModal (true);
|
insilmaril@824
|
231 |
fd.setFilter ("Scripts (*.sh *.pl *.py *.php)");
|
insilmaril@824
|
232 |
fd.setDirectory (QDir::current());
|
insilmaril@824
|
233 |
fd.show();
|
insilmaril@824
|
234 |
|
insilmaril@824
|
235 |
if ( fd.exec() == QDialog::Accepted )
|
insilmaril@824
|
236 |
{
|
insilmaril@824
|
237 |
postscript=fd.selectedFile();
|
insilmaril@824
|
238 |
ui.lineEditPostScript->setText (postscript );
|
insilmaril@824
|
239 |
settingsChanged=true;
|
insilmaril@824
|
240 |
}
|
insilmaril@824
|
241 |
}
|
insilmaril@824
|
242 |
|
insilmaril@824
|
243 |
|
insilmaril@824
|
244 |
void ExportHTMLDialog::doExport (const QString &mapname)
|
insilmaril@824
|
245 |
{
|
insilmaril@824
|
246 |
|
insilmaril@824
|
247 |
// Save options to settings file
|
insilmaril@824
|
248 |
// (but don't save at destructor, which
|
insilmaril@824
|
249 |
// is called for "cancel", too)
|
insilmaril@824
|
250 |
settings.setLocalEntry (filepath,"/export/html/exportDir",dir);
|
insilmaril@824
|
251 |
settings.setLocalEntry (filepath,"/export/html/prescript",prescript);
|
insilmaril@824
|
252 |
settings.setLocalEntry (filepath,"/export/html/postscript",postscript);
|
insilmaril@824
|
253 |
|
insilmaril@824
|
254 |
if (useImage)
|
insilmaril@824
|
255 |
settings.setLocalEntry (filepath,"/export/html/useImage","yes");
|
insilmaril@824
|
256 |
else
|
insilmaril@824
|
257 |
settings.setLocalEntry (filepath,"/export/html/useImage","no");
|
insilmaril@824
|
258 |
|
insilmaril@824
|
259 |
if (useTextColor)
|
insilmaril@824
|
260 |
settings.setLocalEntry (filepath,"/export/html/useTextColor","yes");
|
insilmaril@824
|
261 |
else
|
insilmaril@824
|
262 |
settings.setLocalEntry (filepath,"/export/html/useTextColor","no");
|
insilmaril@824
|
263 |
|
insilmaril@824
|
264 |
if (showWarnings)
|
insilmaril@824
|
265 |
settings.writeEntry ("/export/html/showWarnings","yes");
|
insilmaril@824
|
266 |
else
|
insilmaril@824
|
267 |
settings.writeEntry ("/export/html/showWarnings","no");
|
insilmaril@824
|
268 |
|
insilmaril@824
|
269 |
if (showOutput)
|
insilmaril@824
|
270 |
settings.writeEntry ("/export/html/showOutput","yes");
|
insilmaril@824
|
271 |
else
|
insilmaril@824
|
272 |
settings.writeEntry ("/export/html/showOutput","no");
|
insilmaril@824
|
273 |
|
insilmaril@824
|
274 |
QString ipath;
|
insilmaril@824
|
275 |
ipath=vymBaseDir.path()+"/flags/flag-url-16x16.png";
|
insilmaril@824
|
276 |
if (!options.isOn ("local"))
|
insilmaril@824
|
277 |
{
|
insilmaril@824
|
278 |
settings.setLocalEntry
|
insilmaril@824
|
279 |
(filepath,"/export/html/css",css);
|
insilmaril@824
|
280 |
}
|
insilmaril@824
|
281 |
|
insilmaril@824
|
282 |
if (!saveSettingsInMap)
|
insilmaril@824
|
283 |
settings.clearLocal("/export/html");
|
insilmaril@824
|
284 |
else
|
insilmaril@824
|
285 |
settings.setLocalEntry
|
insilmaril@824
|
286 |
(filepath,"/export/html/saveSettingsInMap","yes");
|
insilmaril@824
|
287 |
|
insilmaril@824
|
288 |
// Provide a smaller URL-icon to improve Layout //FIXME-1
|
insilmaril@824
|
289 |
QPixmap pm;
|
insilmaril@824
|
290 |
if (!pm.load(ipath,"PNG") )
|
insilmaril@824
|
291 |
QMessageBox::warning( 0, tr( "Warning" ),tr("Could not open %1").arg(ipath));
|
insilmaril@824
|
292 |
|
insilmaril@824
|
293 |
|
insilmaril@824
|
294 |
if(!pm.save (dir + "flags/flag-url-16x16.png","PNG"))
|
insilmaril@824
|
295 |
QMessageBox::warning( 0, tr( "Warning" ),tr("Could not write %1").arg(ipath));
|
insilmaril@824
|
296 |
|
insilmaril@824
|
297 |
if (!prescript.isEmpty()) runScript (prescript,dir+mapname+".xml");
|
insilmaril@824
|
298 |
|
insilmaril@824
|
299 |
/* FIXME-1
|
insilmaril@824
|
300 |
if (useImage)
|
insilmaril@824
|
301 |
p.addStringParam ("imagemap","images/"+mapname+".png");
|
insilmaril@824
|
302 |
if (useTextColor)
|
insilmaril@824
|
303 |
p.addStringParam ("use.textcolor","1");
|
insilmaril@824
|
304 |
p.addStringParam ("mapname",mapname+".vym");
|
insilmaril@824
|
305 |
|
insilmaril@824
|
306 |
p.setOutputFile (dir+mapname+".html");
|
insilmaril@824
|
307 |
p.setInputFile (dir+mapname+".xml");
|
insilmaril@824
|
308 |
p.process();
|
insilmaril@824
|
309 |
*/
|
insilmaril@824
|
310 |
|
insilmaril@824
|
311 |
if (!postscript.isEmpty()) runScript (postscript,dir+mapname+".html");
|
insilmaril@824
|
312 |
|
insilmaril@824
|
313 |
}
|
insilmaril@824
|
314 |
|
insilmaril@824
|
315 |
void ExportHTMLDialog::setFilePath(const QString &s)
|
insilmaril@824
|
316 |
{
|
insilmaril@824
|
317 |
filepath=s;
|
insilmaril@824
|
318 |
}
|
insilmaril@824
|
319 |
|
insilmaril@824
|
320 |
void ExportHTMLDialog::setMapName(const QString &s)
|
insilmaril@824
|
321 |
{
|
insilmaril@824
|
322 |
mapname=s;
|
insilmaril@824
|
323 |
}
|
insilmaril@824
|
324 |
|
insilmaril@824
|
325 |
QString ExportHTMLDialog::getDir()
|
insilmaril@824
|
326 |
{
|
insilmaril@824
|
327 |
return dir;
|
insilmaril@824
|
328 |
}
|
insilmaril@824
|
329 |
|
insilmaril@824
|
330 |
bool ExportHTMLDialog::warnings()
|
insilmaril@824
|
331 |
{
|
insilmaril@824
|
332 |
return showWarnings;
|
insilmaril@824
|
333 |
}
|
insilmaril@824
|
334 |
|
insilmaril@824
|
335 |
bool ExportHTMLDialog::hasChanged()
|
insilmaril@824
|
336 |
{
|
insilmaril@824
|
337 |
return settingsChanged;
|
insilmaril@824
|
338 |
}
|
insilmaril@824
|
339 |
|
insilmaril@824
|
340 |
|
insilmaril@824
|
341 |
void ExportHTMLDialog::runScript(QString spath, QString fpath)
|
insilmaril@824
|
342 |
{
|
insilmaril@824
|
343 |
spath.replace ("%f",fpath);
|
insilmaril@824
|
344 |
QStringList args=QStringList::split (' ',spath,false);
|
insilmaril@824
|
345 |
|
insilmaril@824
|
346 |
//FIXME-1 p.addOutput ("vym is executing: \n" + spath+" "+args.join(" ") );
|
insilmaril@824
|
347 |
scriptProc->start (spath,args);
|
insilmaril@824
|
348 |
if (!scriptProc->waitForStarted() )
|
insilmaril@824
|
349 |
{
|
insilmaril@824
|
350 |
QMessageBox::critical( 0, tr( "Critical Error" ),
|
insilmaril@824
|
351 |
tr("Could not start %1").arg(spath) );
|
insilmaril@824
|
352 |
} else
|
insilmaril@824
|
353 |
{
|
insilmaril@824
|
354 |
if (!scriptProc->waitForFinished())
|
insilmaril@824
|
355 |
QMessageBox::critical( 0, tr( "Critical Error" ),
|
insilmaril@824
|
356 |
tr("%1 didn't exit normally").arg(spath) +
|
insilmaril@824
|
357 |
scriptProc->getErrout() );
|
insilmaril@824
|
358 |
else
|
insilmaril@824
|
359 |
if (scriptProc->exitStatus()>0) showOutput=true;
|
insilmaril@824
|
360 |
|
insilmaril@824
|
361 |
}
|
insilmaril@824
|
362 |
/* FIXME-1
|
insilmaril@824
|
363 |
p.addOutput ("\n");
|
insilmaril@824
|
364 |
p.addOutput (scriptProc->getErrout());
|
insilmaril@824
|
365 |
p.addOutput (scriptProc->getStdout());
|
insilmaril@824
|
366 |
*/
|
insilmaril@824
|
367 |
}
|
insilmaril@824
|
368 |
|