]> git.sven.stormbind.net Git - sven/vym.git/blob - src/export-html-dialog.cpp
New upstream version 2.9.22
[sven/vym.git] / src / export-html-dialog.cpp
1 #include "export-html-dialog.h"
2
3 #include <QFileDialog>
4 #include <QMessageBox>
5
6 #include "file.h"
7 #include "settings.h"
8
9 extern QDir vymBaseDir;
10 extern Settings settings;
11 extern bool debug;
12
13 ExportHTMLDialog::ExportHTMLDialog(QWidget *parent) : QDialog(parent)
14 {
15     ui.setupUi(this);
16
17     filepath = "";
18     settingsChanged = false;
19
20     // signals and slots connections
21     connect(ui.browseExportDirButton, SIGNAL(pressed()), this,
22             SLOT(browseDirectoryPressed()));
23     connect(ui.browseCssSrcButton, SIGNAL(pressed()), this,
24             SLOT(browseCssSrcPressed()));
25     connect(ui.browseCssDstButton, SIGNAL(pressed()), this,
26             SLOT(browseCssDstPressed()));
27     connect(ui.imageCheckBox, SIGNAL(toggled(bool)), this,
28             SLOT(imageCheckBoxPressed(bool)));
29     connect(ui.includeImagesCheckBox, SIGNAL(toggled(bool)), this,
30             SLOT(includeImagesCheckBoxPressed(bool)));
31     connect(ui.TOCCheckBox, SIGNAL(toggled(bool)), this,
32             SLOT(TOCCheckBoxPressed(bool)));
33     connect(ui.numberingCheckBox, SIGNAL(toggled(bool)), this,
34             SLOT(numberingCheckBoxPressed(bool)));
35     connect(ui.taskFlagsCheckBox, SIGNAL(toggled(bool)), this,
36             SLOT(taskFlagsCheckBoxPressed(bool)));
37     connect(ui.userFlagsCheckBox, SIGNAL(toggled(bool)), this,
38             SLOT(userFlagsCheckBoxPressed(bool)));
39     connect(ui.textColorCheckBox, SIGNAL(toggled(bool)), this,
40             SLOT(textcolorCheckBoxPressed(bool)));
41     connect(ui.lineEditDir, SIGNAL(textChanged(const QString &)), this,
42             SLOT(dirChanged()));
43     connect(ui.copyCssCheckBox, SIGNAL(pressed()), this,
44             SLOT(copyCssPressed()));
45     connect(ui.lineEditCssSrc, SIGNAL(textChanged(const QString &)), this,
46             SLOT(cssSrcChanged()));
47     connect(ui.lineEditCssDst, SIGNAL(textChanged(const QString &)), this,
48             SLOT(cssDstChanged()));
49     connect(ui.saveSettingsInMapCheckBox, SIGNAL(toggled(bool)), this,
50             SLOT(saveSettingsInMapCheckBoxPressed(bool)));
51     connect(ui.lineEditPostScript, SIGNAL(textChanged(const QString &)), this,
52             SLOT(postscriptChanged()));
53     connect(ui.browsePostExportButton, SIGNAL(pressed()), this,
54             SLOT(browsePostExportButtonPressed()));
55 }
56
57 void ExportHTMLDialog::readSettings()
58 {
59     dir.setPath(settings
60               .localValue(filepath, "/export/html/exportDir",
61                           vymBaseDir.currentPath())
62               .toString()); // FIXME-3 exportDir only needed for dialog
63     ui.lineEditDir->setText(dir.absolutePath());
64
65     includeMapImage =
66         settings.localValue(filepath, "/export/html/includeMapImage", "true")
67             .toBool();
68     ui.imageCheckBox->setChecked(includeMapImage);
69
70     includeImages =
71         settings.localValue(filepath, "/export/html/includeImages", "true")
72             .toBool();
73     ui.includeImagesCheckBox->setChecked(includeImages);
74
75     useTOC =
76         settings.localValue(filepath, "/export/html/useTOC", "true").toBool();
77     ui.TOCCheckBox->setChecked(useTOC);
78
79     useNumbering =
80         settings.localValue(filepath, "/export/html/useNumbering", "true")
81             .toBool();
82     ui.numberingCheckBox->setChecked(useNumbering);
83
84     useTaskFlags =
85         settings.localValue(filepath, "/export/html/useTaskFlags", "true")
86             .toBool();
87     ui.taskFlagsCheckBox->setChecked(useTaskFlags);
88
89     useUserFlags =
90         settings.localValue(filepath, "/export/html/useUserFlags", "true")
91             .toBool();
92     ui.userFlagsCheckBox->setChecked(useUserFlags);
93
94     useTextColor =
95         settings.localValue(filepath, "/export/html/useTextColor", "no")
96             .toBool();
97     ui.textColorCheckBox->setChecked(useTextColor);
98
99     /* FIXME-3 this was used in old html export, is not yet in new stylesheet
100         useHeading=settings.readValue
101        ("/export/html/useHeading","false").toBool();
102         checkBox4_2->setChecked(useHeading);
103     */
104
105     saveSettingsInMap =
106         settings.localValue(filepath, "/export/html/saveSettingsInMap", "no")
107             .toBool();
108     ui.saveSettingsInMapCheckBox->setChecked(saveSettingsInMap);
109
110     // CSS settings
111     css_copy =
112         settings.localValue(filepath, "/export/html/copy_css", true).toBool();
113     ui.copyCssCheckBox->setChecked(css_copy);
114
115     QString css_org = vymBaseDir.path() + "/styles/vym.css";
116     css_src = settings.localValue(filepath, "/export/html/css_src", css_org)
117                   .toString();
118     css_dst =
119         settings.localValue(filepath, "/export/html/css_dst", basename(css_org))
120             .toString();
121
122     ui.lineEditCssSrc->setText(css_src);
123     ui.lineEditCssDst->setText(css_dst);
124
125     postscript =
126         settings.localValue(filepath, "/export/html/postscript", "").toString();
127     ui.lineEditPostScript->setText(postscript);
128
129     if (!postscript.isEmpty()) {
130         QMessageBox::warning(0, tr("Warning"),
131                              tr("The settings saved in the map "
132                                 "would like to run script:\n\n"
133                                 "%1\n\n"
134                                 "Please check, if you really\n"
135                                 "want to allow this in your system!")
136                                  .arg(postscript));
137     }
138 }
139
140 void ExportHTMLDialog::setDirectory(const QString &d) { dir.setPath(d); }
141
142 void ExportHTMLDialog::dirChanged()
143 {
144     setDirectory(ui.lineEditDir->text());
145     settingsChanged = true;
146 }
147
148 void ExportHTMLDialog::browseDirectoryPressed()
149 {
150     QFileDialog fd(this);
151     fd.setFileMode(QFileDialog::DirectoryOnly);
152     fd.setWindowTitle(tr("VYM - Export HTML to directory"));
153     fd.setModal(true);
154     fd.setDirectory(QDir::current());
155     fd.show();
156
157     if (fd.exec() == QDialog::Accepted) {
158         QDir dir = fd.directory();
159         ui.lineEditDir->setText(dir.path());
160         settingsChanged = true;
161     }
162 }
163
164 void ExportHTMLDialog::imageCheckBoxPressed(bool b)
165 {
166     includeMapImage = b;
167     settingsChanged = true;
168 }
169
170 void ExportHTMLDialog::includeImagesCheckBoxPressed(bool b)
171 {
172     includeImages = b;
173     settingsChanged = true;
174 }
175
176 void ExportHTMLDialog::TOCCheckBoxPressed(bool b)
177 {
178     useTOC = b;
179     settingsChanged = true;
180 }
181
182 void ExportHTMLDialog::numberingCheckBoxPressed(bool b)
183 {
184     useNumbering = b;
185     settingsChanged = true;
186 }
187
188 void ExportHTMLDialog::taskFlagsCheckBoxPressed(bool b)
189 {
190     useTaskFlags = b;
191     settingsChanged = true;
192 }
193
194 void ExportHTMLDialog::userFlagsCheckBoxPressed(bool b)
195 {
196     useUserFlags = b;
197     settingsChanged = true;
198 }
199
200 void ExportHTMLDialog::textcolorCheckBoxPressed(bool b)
201 {
202     useTextColor = b;
203     settingsChanged = true;
204 }
205
206 void ExportHTMLDialog::saveSettingsInMapCheckBoxPressed(bool b)
207 {
208     saveSettingsInMap = b;
209     settingsChanged = true;
210 }
211
212 void ExportHTMLDialog::warningsCheckBoxPressed(bool b)
213 {
214     showWarnings = b;
215     settingsChanged = true;
216 }
217
218 void ExportHTMLDialog::outputCheckBoxPressed(bool b)
219 {
220     showOutput = b;
221     settingsChanged = true;
222 }
223
224 void ExportHTMLDialog::cssSrcChanged()
225 {
226     css_src = ui.lineEditCssSrc->text();
227     settingsChanged = true;
228 }
229
230 void ExportHTMLDialog::cssDstChanged()
231 {
232     css_dst = ui.lineEditCssDst->text();
233     settingsChanged = true;
234 }
235
236 QString ExportHTMLDialog::getCssSrc()
237 {
238     if (css_copy)
239         return css_src;
240     else
241         return QString();
242 }
243
244 QString ExportHTMLDialog::getCssDst() { return css_dst; }
245
246 void ExportHTMLDialog::copyCssPressed()
247 {
248     css_copy = ui.imageCheckBox->isChecked();
249     settingsChanged = true;
250 }
251
252 void ExportHTMLDialog::browseCssSrcPressed()
253 {
254     QFileDialog fd(this);
255     fd.setModal(true);
256     fd.setNameFilter("Cascading Stylesheet (*.css)");
257     fd.setDirectory(QDir::current());
258     fd.show();
259
260     if (fd.exec() == QDialog::Accepted) {
261         if (!fd.selectedFiles().isEmpty()) {
262             css_src = fd.selectedFiles().first();
263             ui.lineEditCssSrc->setText(css_src);
264             settingsChanged = true;
265         }
266     }
267 }
268
269 void ExportHTMLDialog::browseCssDstPressed()
270 {
271     QFileDialog fd(this);
272     fd.setModal(true);
273     fd.setNameFilter("Cascading Stylesheet (*.css)");
274     fd.setDirectory(QDir::current());
275     fd.show();
276
277     if (fd.exec() == QDialog::Accepted) {
278         if (!fd.selectedFiles().isEmpty()) {
279             css_dst = fd.selectedFiles().first();
280             ui.lineEditCssDst->setText(css_dst);
281             settingsChanged = true;
282         }
283     }
284 }
285
286 void ExportHTMLDialog::postscriptChanged()
287 {
288     postscript = ui.lineEditPostScript->text();
289     settingsChanged = true;
290 }
291
292 void ExportHTMLDialog::browsePostExportButtonPressed()
293 {
294     QFileDialog fd(this);
295     fd.setModal(true);
296     fd.setNameFilter("Scripts (*.sh *.pl *.py *.php)");
297     fd.setDirectory(QDir::current());
298     fd.show();
299
300     if (fd.exec() == QDialog::Accepted) {
301         if (!fd.selectedFiles().isEmpty()) {
302             postscript = fd.selectedFiles().first();
303             ui.lineEditPostScript->setText(postscript);
304             settingsChanged = true;
305         }
306     }
307 }
308
309 void ExportHTMLDialog::saveSettings()
310 {
311     // Save options to settings file
312     // (but don't save at destructor, which
313     // is called for "cancel", too)
314     if (!saveSettingsInMap)
315         settings.clearLocal(filepath, "/export/html");
316     else {
317         settings.setLocalValue(
318             filepath, "/export/html/exportDir",
319             dir.absolutePath()); // FIXME-3 exportDir only needed for dialog
320         settings.setLocalValue(filepath, "/export/html/saveSettingsInMap",
321                                "yes");
322         settings.setLocalValue(filepath, "/export/html/postscript", postscript);
323         settings.setLocalValue(filepath, "/export/html/includeMapImage",
324                                includeMapImage);
325         settings.setLocalValue(filepath, "/export/html/includeImages",
326                                includeImages);
327         settings.setLocalValue(filepath, "/export/html/useTOC", useTOC);
328         settings.setLocalValue(filepath, "/export/html/useNumbering",
329                                useNumbering);
330         settings.setLocalValue(filepath, "/export/html/useTaskFlags",
331                                useTaskFlags);
332         settings.setLocalValue(filepath, "/export/html/useUserFlags",
333                                useUserFlags);
334         settings.setLocalValue(filepath, "/export/html/useTextColor",
335                                useTextColor);
336         settings.setLocalValue(filepath, "/export/html/css_copy", css_copy);
337         settings.setLocalValue(filepath, "/export/html/css_src", css_src);
338         settings.setLocalValue(filepath, "/export/html/css_dst", css_dst);
339         settings.setValue("/export/html/showWarnings", showWarnings);
340         settings.setValue("/export/html/showOutput", showOutput);
341     }
342 }
343
344 void ExportHTMLDialog::setFilePath(const QString &s) { filepath = s; }
345
346 void ExportHTMLDialog::setMapName(const QString &s) { mapname = s; }
347
348 QDir ExportHTMLDialog::getDir() { return dir; }
349
350 bool ExportHTMLDialog::warnings() { return showWarnings; }
351
352 bool ExportHTMLDialog::hasChanged() { return settingsChanged; } // FIXME-2 never used