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