Debian Codegraph @

src/af/xap/xp/xap_Dlg_HTMLOptions.cpp

raw
1 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
2
3 /* AbiSource Application Framework
4 * Copyright (C) 2002 AbiSource, Inc.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301 USA.
20 */
21
22 #include <string.h>
23
24 #include "ut_assert.h"
25 #include "ut_string_class.h"
26
27 #include "xap_App.h"
28 #include "xap_Prefs.h"
29 #include "xap_Dlg_HTMLOptions.h"
30
31 /*****************************************************************/
32
33 XAP_Dialog_HTMLOptions::XAP_Dialog_HTMLOptions (XAP_DialogFactory * pDlgFactory,
34 XAP_Dialog_Id id)
35 : XAP_Dialog_NonPersistent(pDlgFactory,id),
36 m_bShouldSave(true),
37 m_exp_opt(NULL),
38 m_app(NULL),
39 m_pLinkCSS(NULL)
40 {
41 //
42 m_pLinkCSS = new UT_UTF8String;
43 }
44
45 XAP_Dialog_HTMLOptions::~XAP_Dialog_HTMLOptions(void)
46 {
47 DELETEP(m_pLinkCSS);
48 }
49
50 void XAP_Dialog_HTMLOptions::setHTMLOptions (XAP_Exp_HTMLOptions * exp_opt, XAP_App * app)
51 {
52 UT_ASSERT (exp_opt);
53
54 m_exp_opt = exp_opt;
55 m_app = app;
56 }
57
58 void XAP_Dialog_HTMLOptions::set_HTML4 (bool enable)
59 {
60 m_exp_opt->bIs4 = enable;
61 m_exp_opt->bIsAbiWebDoc = enable ? false : m_exp_opt->bIsAbiWebDoc;
62 }
63
64 void XAP_Dialog_HTMLOptions::set_PHTML (bool enable)
65 {
66 m_exp_opt->bIs4 = enable ? false : m_exp_opt->bIs4;
67 m_exp_opt->bIsAbiWebDoc = enable;
68 }
69
70 void XAP_Dialog_HTMLOptions::set_Declare_XML (bool enable)
71 {
72 if (can_set_Declare_XML ()) m_exp_opt->bDeclareXML = enable;
73 }
74
75 void XAP_Dialog_HTMLOptions::set_Allow_AWML (bool enable)
76 {
77 if (can_set_Allow_AWML ()) m_exp_opt->bAllowAWML = enable;
78 }
79
80 void XAP_Dialog_HTMLOptions::set_Embed_CSS (bool enable)
81 {
82 if (can_set_Embed_CSS ()) m_exp_opt->bEmbedCSS = enable;
83 }
84
85 void XAP_Dialog_HTMLOptions::set_Link_CSS (bool enable)
86 {
87 if (can_set_Link_CSS ())
88 {
89 m_exp_opt->bLinkCSS = enable;
90
91 if(enable)
92 m_exp_opt->bEmbedCSS = false;
93 }
94 }
95
96 void XAP_Dialog_HTMLOptions::set_Class_Only (bool enable)
97 {
98 if (can_set_Class_Only())
99 m_exp_opt->bClassOnly = enable;
100 }
101
102 void XAP_Dialog_HTMLOptions::set_Abs_Units (bool enable)
103 {
104 if (can_set_Abs_Units())
105 m_exp_opt->bAbsUnits = enable;
106 }
107
108 void XAP_Dialog_HTMLOptions::set_Scale_Units (bool enable)
109 {
110 if (can_set_Scale_Units())
111 m_exp_opt->bScaleUnits = enable;
112 }
113
114 void XAP_Dialog_HTMLOptions::set_Link_CSS_File (const char * file)
115 {
116 if(!m_pLinkCSS || !file || !can_set_Link_CSS ())
117 return;
118
119 *m_pLinkCSS = file;
120 }
121
122 void XAP_Dialog_HTMLOptions::set_Embed_Images (bool enable)
123 {
124 m_exp_opt->bEmbedImages = enable;
125 }
126
127
128 void XAP_Dialog_HTMLOptions::set_MathML_Render_PNG(bool enable)
129 {
130 if (can_set_MathML_Render_PNG())
131 {
132 m_exp_opt->bMathMLRenderPNG = enable;
133 }
134 }
135
136 void XAP_Dialog_HTMLOptions::set_Split_Document(bool enable)
137 {
138 if (can_set_Split_Document())
139 {
140 m_exp_opt->bSplitDocument = enable;
141 }
142 }
143
144
145
146
147
148 void XAP_Dialog_HTMLOptions::saveDefaults ()
149 {
150 UT_ASSERT(m_app);
151 if (m_app == NULL) return;
152
153 XAP_Prefs * pPrefs = m_app->getPrefs ();
154 if (pPrefs == NULL) return;
155
156 XAP_PrefsScheme * pPScheme = pPrefs->getCurrentScheme ();
157 if (pPScheme == NULL) return;
158
159 UT_UTF8String pref;
160
161 if (m_exp_opt->bIs4)
162 {
163 if (pref.byteLength ()) pref += ",";
164 pref += "HTML4";
165 }
166 if (m_exp_opt->bIsAbiWebDoc)
167 {
168 if (pref.byteLength ()) pref += ",";
169 pref += "PHTML";
170 }
171 if (m_exp_opt->bDeclareXML)
172 {
173 if (pref.byteLength ()) pref += ",";
174 pref += "?xml";
175 }
176 if (m_exp_opt->bAllowAWML)
177 {
178 if (pref.byteLength ()) pref += ",";
179 pref += "xmlns:awml";
180 }
181 if (m_exp_opt->bEmbedCSS)
182 {
183 if (pref.byteLength ()) pref += ",";
184 pref += "+CSS";
185 }
186 if (m_exp_opt->bAbsUnits)
187 {
188 if (pref.byteLength ()) pref += ",";
189 pref += "+AbsUnits";
190 }
191 if (m_exp_opt->bScaleUnits)
192 {
193 if (pref.byteLength ()) pref += ",";
194 pref += "+ScaleUnits";
195 }
196 if (m_exp_opt->bMathMLRenderPNG)
197 {
198 if (pref.byteLength ()) pref += ",";
199 pref += "+MathMLPNG";
200 }
201 if (m_exp_opt->bSplitDocument)
202 {
203 if (pref.byteLength ()) pref += ",";
204 pref += "+SplitDoc";
205 }
206 if (m_exp_opt->iCompact)
207 {
208 if (pref.byteLength ()) pref += ",";
209 pref += "Compact:";
210 pref += UT_UTF8String_sprintf("%d", m_exp_opt->iCompact);
211 }
212 if (m_exp_opt->bLinkCSS)
213 {
214 if (pref.byteLength ()) pref += ",";
215 pref += "LinkCSS";
216 }
217 if (m_exp_opt->bClassOnly)
218 {
219 if (pref.byteLength ()) pref += ",";
220 pref += "ClassOnly";
221 }
222 if (m_exp_opt->bEmbedImages)
223 {
224 if (pref.byteLength ()) pref += ",";
225 pref += "data:base64";
226 }
227 if (m_exp_opt->bEmbedImages)
228 {
229 if (pref.byteLength ()) pref += ",";
230 pref += "data:base64";
231 }
232 const gchar * szValue = (const gchar *) pref.utf8_str ();
233
234 pPScheme->setValue (XAP_PREF_KEY_HTMLExportOptions, szValue);
235 }
236
237 void XAP_Dialog_HTMLOptions::restoreDefaults ()
238 {
239 if (m_exp_opt == NULL) return;
240 XAP_Dialog_HTMLOptions::getHTMLDefaults (m_exp_opt, m_app);
241 }
242
243 void XAP_Dialog_HTMLOptions::getHTMLDefaults (XAP_Exp_HTMLOptions * exp_opt, XAP_App * app)
244 {
245 UT_ASSERT(exp_opt);
246
247 if (exp_opt == NULL) return;
248
249 exp_opt->bIs4 = false;
250 exp_opt->bIsAbiWebDoc = false;
251 exp_opt->bDeclareXML = true;
252 exp_opt->bAllowAWML = true;
253 exp_opt->bEmbedCSS = true;
254 exp_opt->bAbsUnits = false;
255 exp_opt->bScaleUnits = false;
256 exp_opt->iCompact = 0;
257 exp_opt->bEmbedImages = false;
258 exp_opt->bMathMLRenderPNG = false;
259 exp_opt->bSplitDocument = false;
260 if (app == NULL) return;
261
262 const XAP_Prefs * pPrefs = app->getPrefs ();
263
264 if (pPrefs == NULL) return;
265
266 const gchar * szValue = NULL;
267 bool haveValue = pPrefs->getPrefsValue (XAP_PREF_KEY_HTMLExportOptions, &szValue);
268
269 if (haveValue && szValue)
270 {
271 const char * pref = (const char *) szValue;
272
273 exp_opt->bIs4 = (strstr (pref, "HTML4") == NULL) ? false : true;
274 exp_opt->bIsAbiWebDoc = (strstr (pref, "PHTML") == NULL) ? false : true;
275 exp_opt->bDeclareXML = (strstr (pref, "?xml") == NULL) ? false : true;
276 exp_opt->bAllowAWML = (strstr (pref, "xmlns:awml") == NULL) ? false : true;
277 exp_opt->bEmbedCSS = (strstr (pref, "+CSS") == NULL) ? false : true;
278 exp_opt->bAbsUnits = (strstr (pref, "+AbsUnits") == NULL) ? false : true;
279 exp_opt->bScaleUnits = (strstr (pref, "+ScaleUnits") == NULL) ? false : true;
280
281 const char * p = strstr (pref, "Compact:");
282 if(p)
283 {
284 p += 8;
285 exp_opt->iCompact = atoi(p);
286 }
287
288 exp_opt->bLinkCSS = (strstr (pref, "LinkCSS") == NULL) ? false : true;
289 exp_opt->bClassOnly = (strstr (pref, "ClassOnly") == NULL) ? false : true;
290 exp_opt->bEmbedImages = (strstr (pref, "data:base64") == NULL) ? false : true;
291 exp_opt->bMathMLRenderPNG = (strstr (pref, "+MathMLPNG") == NULL) ? false : true;
292 exp_opt->bSplitDocument = (strstr (pref, "+SplitDoc") == NULL) ? false : true;
293
294
295 if (exp_opt->bIs4) exp_opt->bIsAbiWebDoc = false;
296 }
297 }