1 /*
2 * Authors:
3 * Ted Gould <ted@gould.cx>
4 *
5 * Copyright (C) 2002-2005 Authors
6 *
7 * Released under GNU GPL, read the file 'COPYING' for more information
8 */
10 #ifdef HAVE_CONFIG_H
11 # include "config.h"
12 #endif
14 #include "implementation/implementation.h"
15 #include "timer.h"
16 #include "input.h"
17 #include "io/sys.h"
18 #include "prefdialog.h"
20 /* Inkscape::Extension::Input */
22 namespace Inkscape {
23 namespace Extension {
25 /**
26 \return None
27 \brief Builds a SPModuleInput object from a XML description
28 \param module The module to be initialized
29 \param repr The XML description in a Inkscape::XML::Node tree
31 Okay, so you want to build a SPModuleInput object.
33 This function first takes and does the build of the parent class,
34 which is SPModule. Then, it looks for the <input> section of the
35 XML description. Under there should be several fields which
36 describe the input module to excruciating detail. Those are parsed,
37 copied, and put into the structure that is passed in as module.
38 Overall, there are many levels of indentation, just to handle the
39 levels of indentation in the XML file.
40 */
41 Input::Input (Inkscape::XML::Node * in_repr, Implementation::Implementation * in_imp) : Extension(in_repr, in_imp)
42 {
43 mimetype = NULL;
44 extension = NULL;
45 filetypename = NULL;
46 filetypetooltip = NULL;
47 output_extension = NULL;
49 printf("Input::Input\n");
51 if (repr != NULL) {
52 Inkscape::XML::Node * child_repr;
54 child_repr = sp_repr_children(repr);
56 while (child_repr != NULL) {
57 if (!strcmp(child_repr->name(), "input")) {
58 child_repr = sp_repr_children(child_repr);
59 while (child_repr != NULL) {
60 char const * chname = child_repr->name();
61 if (chname[0] == '_') /* Allow _ for translation of tags */
62 chname++;
63 if (!strcmp(chname, "extension")) {
64 g_free (extension);
65 extension = g_strdup(sp_repr_children(child_repr)->content());
66 }
67 if (!strcmp(chname, "mimetype")) {
68 g_free (mimetype);
69 mimetype = g_strdup(sp_repr_children(child_repr)->content());
70 }
71 if (!strcmp(chname, "filetypename")) {
72 g_free (filetypename);
73 filetypename = g_strdup(sp_repr_children(child_repr)->content());
74 }
75 if (!strcmp(chname, "filetypetooltip")) {
76 g_free (filetypetooltip);
77 filetypetooltip = g_strdup(sp_repr_children(child_repr)->content());
78 }
79 if (!strcmp(chname, "output_extension")) {
80 g_free (output_extension);
81 output_extension = g_strdup(sp_repr_children(child_repr)->content());
82 }
84 child_repr = sp_repr_next(child_repr);
85 }
87 break;
88 }
90 child_repr = sp_repr_next(child_repr);
91 }
93 }
95 return;
96 }
98 /**
99 \return None
100 \brief Destroys an Input extension
101 */
102 Input::~Input (void)
103 {
104 g_free(mimetype);
105 g_free(extension);
106 g_free(filetypename);
107 g_free(filetypetooltip);
108 g_free(output_extension);
109 return;
110 }
112 /**
113 \return Whether this extension checks out
114 \brief Validate this extension
116 This function checks to make sure that the input extension has
117 a filename extension and a MIME type. Then it calls the parent
118 class' check function which also checks out the implmentation.
119 */
120 bool
121 Input::check (void)
122 {
123 if (extension == NULL)
124 return FALSE;
125 if (mimetype == NULL)
126 return FALSE;
128 return Extension::check();
129 }
131 /**
132 \return A new document
133 \brief This function creates a document from a file
134 \param uri The filename to create the document from
136 This function acts as the first step in creating a new document
137 from a file. The first thing that this does is make sure that the
138 file actually exists. If it doesn't, a NULL is returned. If the
139 file exits, then it is opened using the implmentation of this extension.
141 After opening the document the output_extension is set. What this
142 accomplishes is that save can try to use an extension that supports
143 the same fileformat. So something like opening and saveing an
144 Adobe Illustrator file can be transparent (not recommended, but
145 transparent). This is all done with undo being turned off.
146 */
147 SPDocument *
148 Input::open (const gchar *uri)
149 {
150 printf("Input::open\n");
152 if (!loaded()) {
153 set_state(Extension::STATE_LOADED);
154 }
155 if (!loaded()) {
156 return NULL;
157 }
158 timer->touch();
160 SPDocument *const doc = imp->open(this, uri);
161 if (doc != NULL) {
162 Inkscape::XML::Node * repr = sp_document_repr_root(doc);
163 bool saved = sp_document_get_undo_sensitive(doc);
164 sp_document_set_undo_sensitive (doc, false);
165 repr->setAttribute("inkscape:output_extension", output_extension);
166 sp_document_set_undo_sensitive (doc, saved);
167 }
169 return doc;
170 }
172 /**
173 \return IETF mime-type for the extension
174 \brief Get the mime-type that describes this extension
175 */
176 gchar *
177 Input::get_mimetype(void)
178 {
179 return mimetype;
180 }
182 /**
183 \return Filename extension for the extension
184 \brief Get the filename extension for this extension
185 */
186 gchar *
187 Input::get_extension(void)
188 {
189 return extension;
190 }
192 /**
193 \return The name of the filetype supported
194 \brief Get the name of the filetype supported
195 */
196 gchar *
197 Input::get_filetypename(void)
198 {
199 if (filetypename != NULL)
200 return filetypename;
201 else
202 return get_name();
203 }
205 /**
206 \return Tooltip giving more information on the filetype
207 \brief Get the tooltip for more information on the filetype
208 */
209 gchar *
210 Input::get_filetypetooltip(void)
211 {
212 return filetypetooltip;
213 }
215 /**
216 \return A dialog to get settings for this extension
217 \brief Create a dialog for preference for this extension
219 Calls the implementation to get the preferences.
220 */
221 bool
222 Input::prefs (const gchar *uri)
223 {
224 if (!loaded())
225 set_state(Extension::STATE_LOADED);
226 if (!loaded()) return false;
228 Gtk::Widget * controls;
229 controls = imp->prefs_input(this, uri);
230 if (controls == NULL) {
231 // std::cout << "No preferences for Input" << std::endl;
232 return true;
233 }
235 PrefDialog * dialog = new PrefDialog(this->get_name(), this->get_help(), controls);
236 int response = dialog->run();
237 dialog->hide();
239 delete dialog;
241 if (response == Gtk::RESPONSE_OK) return true;
242 return false;
243 }
245 } } /* namespace Inkscape, Extension */
247 /*
248 Local Variables:
249 mode:c++
250 c-file-style:"stroustrup"
251 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
252 indent-tabs-mode:nil
253 fill-column:99
254 End:
255 */
256 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :