1 /*
2 * Authors:
3 * Ted Gould <ted@gould.cx>
4 *
5 * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
6 * Copyright (C) 2002-2004 Authors
7 *
8 * Released under GNU GPL, read the file 'COPYING' for more information
9 */
11 #include "document.h"
12 #include "implementation/implementation.h"
13 #include "output.h"
15 #include "prefdialog.h"
17 /* Inkscape::Extension::Output */
19 namespace Inkscape {
20 namespace Extension {
22 /**
23 \return None
24 \brief Builds a SPModuleOutput object from a XML description
25 \param module The module to be initialized
26 \param repr The XML description in a Inkscape::XML::Node tree
28 Okay, so you want to build a SPModuleOutput object.
30 This function first takes and does the build of the parent class,
31 which is SPModule. Then, it looks for the <output> section of the
32 XML description. Under there should be several fields which
33 describe the output module to excruciating detail. Those are parsed,
34 copied, and put into the structure that is passed in as module.
35 Overall, there are many levels of indentation, just to handle the
36 levels of indentation in the XML file.
37 */
38 Output::Output (Inkscape::XML::Node * in_repr, Implementation::Implementation * in_imp) : Extension(in_repr, in_imp)
39 {
40 mimetype = NULL;
41 extension = NULL;
42 filetypename = NULL;
43 filetypetooltip = NULL;
44 dataloss = TRUE;
46 if (repr != NULL) {
47 Inkscape::XML::Node * child_repr;
49 child_repr = sp_repr_children(repr);
51 while (child_repr != NULL) {
52 if (!strcmp(child_repr->name(), "output")) {
53 child_repr = sp_repr_children(child_repr);
54 while (child_repr != NULL) {
55 char const * chname = child_repr->name();
56 if (chname[0] == '_') /* Allow _ for translation of tags */
57 chname++;
58 if (!strcmp(chname, "extension")) {
59 g_free (extension);
60 extension = g_strdup(sp_repr_children(child_repr)->content());
61 }
62 if (!strcmp(chname, "mimetype")) {
63 g_free (mimetype);
64 mimetype = g_strdup(sp_repr_children(child_repr)->content());
65 }
66 if (!strcmp(chname, "filetypename")) {
67 g_free (filetypename);
68 filetypename = g_strdup(sp_repr_children(child_repr)->content());
69 }
70 if (!strcmp(chname, "filetypetooltip")) {
71 g_free (filetypetooltip);
72 filetypetooltip = g_strdup(sp_repr_children(child_repr)->content());
73 }
74 if (!strcmp(chname, "dataloss")) {
75 if (!strcmp(sp_repr_children(child_repr)->content(), "FALSE")) {
76 dataloss = FALSE;
77 }
78 }
80 child_repr = sp_repr_next(child_repr);
81 }
83 break;
84 }
86 child_repr = sp_repr_next(child_repr);
87 }
89 }
90 }
92 /**
93 \brief Destroy an output extension
94 */
95 Output::~Output (void)
96 {
97 g_free(mimetype);
98 g_free(extension);
99 g_free(filetypename);
100 g_free(filetypetooltip);
101 return;
102 }
104 /**
105 \return Whether this extension checks out
106 \brief Validate this extension
108 This function checks to make sure that the output extension has
109 a filename extension and a MIME type. Then it calls the parent
110 class' check function which also checks out the implmentation.
111 */
112 bool
113 Output::check (void)
114 {
115 if (extension == NULL)
116 return FALSE;
117 if (mimetype == NULL)
118 return FALSE;
120 return Extension::check();
121 }
123 /**
124 \return IETF mime-type for the extension
125 \brief Get the mime-type that describes this extension
126 */
127 gchar *
128 Output::get_mimetype(void)
129 {
130 return mimetype;
131 }
133 /**
134 \return Filename extension for the extension
135 \brief Get the filename extension for this extension
136 */
137 gchar *
138 Output::get_extension(void)
139 {
140 return extension;
141 }
143 /**
144 \return The name of the filetype supported
145 \brief Get the name of the filetype supported
146 */
147 gchar *
148 Output::get_filetypename(void)
149 {
150 if (filetypename != NULL)
151 return filetypename;
152 else
153 return get_name();
154 }
156 /**
157 \return Tooltip giving more information on the filetype
158 \brief Get the tooltip for more information on the filetype
159 */
160 gchar *
161 Output::get_filetypetooltip(void)
162 {
163 return filetypetooltip;
164 }
166 /**
167 \return A dialog to get settings for this extension
168 \brief Create a dialog for preference for this extension
170 Calls the implementation to get the preferences.
171 */
172 bool
173 Output::prefs (void)
174 {
175 if (!loaded())
176 set_state(Extension::STATE_LOADED);
177 if (!loaded()) return false;
179 Gtk::Widget * controls;
180 controls = imp->prefs_output(this);
181 if (controls == NULL) {
182 // std::cout << "No preferences for Output" << std::endl;
183 return true;
184 }
186 PrefDialog * dialog = new PrefDialog(this->get_name(), this->get_help(), controls);
187 int response = dialog->run();
188 dialog->hide();
190 delete dialog;
192 if (response == Gtk::RESPONSE_OK) return true;
193 return false;
194 }
196 /**
197 \return None
198 \brief Save a document as a file
199 \param doc Document to save
200 \param uri File to save the document as
202 This function does a little of the dirty work involved in saving
203 a document so that the implementation only has to worry about geting
204 bits on the disk.
206 The big thing that it does is remove and readd the fields that are
207 only used at runtime and shouldn't be saved. One that may surprise
208 people is the output extension. This is not saved so that the IDs
209 could be changed, and old files will still work properly.
210 */
211 void
212 Output::save (SPDocument * doc, const gchar * uri)
213 {
214 try {
215 imp->save(this, doc, uri);
216 }
217 catch (...) {
218 throw;
219 }
221 return;
222 }
224 } } /* namespace Inkscape, Extension */
226 /*
227 Local Variables:
228 mode:c++
229 c-file-style:"stroustrup"
230 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
231 indent-tabs-mode:nil
232 fill-column:99
233 End:
234 */
235 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :