1 #ifndef __INK_EXTENSION_H__
2 #define __INK_EXTENSION_H__
4 /** \file
5 * Frontend to certain, possibly pluggable, actions.
6 */
8 /*
9 * Authors:
10 * Ted Gould <ted@gould.cx>
11 *
12 * Copyright (C) 2002-2005 Authors
13 *
14 * Released under GNU GPL, read the file 'COPYING' for more information
15 */
17 #include <ostream>
18 #include <fstream>
19 #include <vector>
20 #include <gtkmm/widget.h>
21 #include <gtkmm/box.h>
22 #include <gtkmm/table.h>
23 #include <glibmm/ustring.h>
24 #include "xml/repr.h"
25 #include "extension/extension-forward.h"
27 /** The key that is used to identify that the I/O should be autodetected */
28 #define SP_MODULE_KEY_AUTODETECT "autodetect"
29 /** This is the key for the SVG input module */
30 #define SP_MODULE_KEY_INPUT_SVG "org.inkscape.input.svg"
31 #define SP_MODULE_KEY_INPUT_SVGZ "org.inkscape.input.svgz"
32 /** Specifies the input module that should be used if none are selected */
33 #define SP_MODULE_KEY_INPUT_DEFAULT SP_MODULE_KEY_AUTODETECT
34 /** The key for outputing standard W3C SVG */
35 #define SP_MODULE_KEY_OUTPUT_SVG "org.inkscape.output.svg.plain"
36 #define SP_MODULE_KEY_OUTPUT_SVGZ "org.inkscape.output.svgz.plain"
37 /** This is an output file that has SVG data with the Sodipodi namespace extensions */
38 #define SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE "org.inkscape.output.svg.inkscape"
39 #define SP_MODULE_KEY_OUTPUT_SVGZ_INKSCAPE "org.inkscape.output.svgz.inkscape"
40 /** Which output module should be used? */
41 #define SP_MODULE_KEY_OUTPUT_DEFAULT SP_MODULE_KEY_AUTODETECT
43 /** Defines the key for Postscript printing */
44 #define SP_MODULE_KEY_PRINT_PS "org.inkscape.print.ps"
45 #define SP_MODULE_KEY_PRINT_CAIRO_PS "org.inkscape.print.ps.cairo"
46 #define SP_MODULE_KEY_PRINT_CAIRO_EPS "org.inkscape.print.eps.cairo"
47 /** Defines the key for PDF printing */
48 #define SP_MODULE_KEY_PRINT_PDF "org.inkscape.print.pdf"
49 #define SP_MODULE_KEY_PRINT_CAIRO_PDF "org.inkscape.print.pdf.cairo"
50 /** Defines the key for LaTeX printing */
51 #define SP_MODULE_KEY_PRINT_LATEX "org.inkscape.print.latex"
52 /** Defines the key for printing with GNOME Print */
53 #define SP_MODULE_KEY_PRINT_GNOME "org.inkscape.print.gnome"
54 /** Defines the key for printing under Win32 */
55 #define SP_MODULE_KEY_PRINT_WIN32 "org.inkscape.print.win32"
56 #ifdef WIN32
57 /** Defines the default printing to use */
58 #define SP_MODULE_KEY_PRINT_DEFAULT SP_MODULE_KEY_PRINT_WIN32
59 #else
60 /** Defines the default printing to use */
61 #define SP_MODULE_KEY_PRINT_DEFAULT SP_MODULE_KEY_PRINT_PS
62 #endif
64 /** Mime type for SVG */
65 #define MIME_SVG "image/svg+xml"
67 /** Name of the extension error file */
68 #define EXTENSION_ERROR_LOG_FILENAME "extension-errors.log"
71 #define INKSCAPE_EXTENSION_URI "http://www.inkscape.org/namespace/inkscape/extension"
72 #define INKSCAPE_EXTENSION_NS_NC "extension"
73 #define INKSCAPE_EXTENSION_NS "extension:"
75 struct SPDocument;
77 namespace Inkscape {
78 namespace Extension {
80 /** The object that is the basis for the Extension system. This object
81 contains all of the information that all Extension have. The
82 individual items are detailed within. This is the interface that
83 those who want to _use_ the extensions system should use. This
84 is most likely to be those who are inside the Inkscape program. */
85 class Extension {
86 public:
87 /** An enumeration to identify if the Extension has been loaded or not. */
88 typedef enum {
89 STATE_LOADED, /**< The extension has been loaded successfully */
90 STATE_UNLOADED, /**< The extension has not been loaded */
91 STATE_DEACTIVATED /**< The extension is missing something which makes it unusable */
92 } state_t;
93 static std::vector<const gchar *> search_path; /**< A vector of paths to search for extensions */
95 private:
96 gchar *id; /**< The unique identifier for the Extension */
97 gchar *name; /**< A user friendly name for the Extension */
98 gchar *_help; /**< A string that contains a help text for the user */
99 state_t _state; /**< Which state the Extension is currently in */
100 std::vector<Dependency *> _deps; /**< Dependencies for this extension */
101 static std::ofstream error_file; /**< This is the place where errors get reported */
103 protected:
104 Inkscape::XML::Node *repr; /**< The XML description of the Extension */
105 Implementation::Implementation * imp; /**< An object that holds all the functions for making this work */
106 ExpirationTimer * timer; /**< Timeout to unload after a given time */
108 public:
109 Extension (Inkscape::XML::Node * in_repr,
110 Implementation::Implementation * in_imp);
111 virtual ~Extension (void);
113 void set_state (state_t in_state);
114 state_t get_state (void);
115 bool loaded (void);
116 virtual bool check (void);
117 Inkscape::XML::Node * get_repr (void);
118 gchar * get_id (void);
119 gchar * get_name (void);
120 /** \brief Gets the help string for this extension */
121 gchar const * get_help (void) { return _help; }
122 void deactivate (void);
123 bool deactivated (void);
124 void printFailure (Glib::ustring reason);
125 Implementation::Implementation * get_imp (void) { return imp; };
127 /* Parameter Stuff */
128 private:
129 GSList * parameters; /**< A table to store the parameters for this extension.
130 This only gets created if there are parameters in this
131 extension */
133 public:
134 /** \brief A function to get the the number of parameters that
135 the extension has.
136 \return The number of parameters. */
137 unsigned int param_count ( ) { return parameters == NULL ? 0 :
138 g_slist_length(parameters); };
139 /** \brief A function to get the the number of parameters that
140 are visible to the user that the extension has.
141 \return The number of visible parameters.
143 \note Currently this just calls param_count as visible isn't implemented
144 but in the future it'll do something different. Please call
145 the appropriate function in code so that it'll work in the
146 future.
147 */
148 unsigned int param_visible_count ( );
150 public:
151 /** An error class for when a parameter is called on a type it is not */
152 class param_wrong_type {};
153 class param_not_color_param {};
154 class param_not_enum_param {};
155 class param_not_string_param {};
156 class param_not_float_param {};
157 class param_not_int_param {};
158 class param_not_bool_param {};
160 /** An error class for when a parameter is looked for that just
161 * simply doesn't exist */
162 class param_not_exist {};
164 /** An error class for when a filename already exists, but the user
165 * doesn't want to overwrite it */
166 class no_overwrite {};
168 private:
169 void make_param (Inkscape::XML::Node * paramrepr);
170 #if 0
171 inline param_t * param_shared (const gchar * name,
172 GSList * list);
173 #endif
174 public:
175 bool get_param_bool (const gchar * name,
176 const SPDocument * doc = NULL,
177 const Inkscape::XML::Node * node = NULL);
178 int get_param_int (const gchar * name,
179 const SPDocument * doc = NULL,
180 const Inkscape::XML::Node * node = NULL);
181 float get_param_float (const gchar * name,
182 const SPDocument * doc = NULL,
183 const Inkscape::XML::Node * node = NULL);
184 const gchar * get_param_string (const gchar * name,
185 const SPDocument * doc = NULL,
186 const Inkscape::XML::Node * node = NULL);
187 guint32 get_param_color (const gchar * name,
188 const SPDocument * doc = NULL,
189 const Inkscape::XML::Node * node = NULL);
190 const gchar * get_param_enum (const gchar * name,
191 const SPDocument * doc = NULL,
192 const Inkscape::XML::Node * node = NULL);
193 bool set_param_bool (const gchar * name,
194 bool value,
195 SPDocument * doc = NULL,
196 Inkscape::XML::Node * node = NULL);
197 int set_param_int (const gchar * name,
198 int value,
199 SPDocument * doc = NULL,
200 Inkscape::XML::Node * node = NULL);
201 float set_param_float (const gchar * name,
202 float value,
203 SPDocument * doc = NULL,
204 Inkscape::XML::Node * node = NULL);
205 const gchar * set_param_string (const gchar * name,
206 const gchar * value,
207 SPDocument * doc = NULL,
208 Inkscape::XML::Node * node = NULL);
209 guint32 set_param_color (const gchar * name,
210 guint32 color,
211 SPDocument * doc = NULL,
212 Inkscape::XML::Node * node = NULL);
214 /* Error file handling */
215 public:
216 static void error_file_open (void);
217 static void error_file_close (void);
219 public:
220 Gtk::Widget * autogui (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal = NULL);
221 void paramListString (std::list <std::string> & retlist);
223 /* Extension editor dialog stuff */
224 public:
225 Gtk::VBox * get_info_widget(void);
226 Gtk::VBox * get_help_widget(void);
227 Gtk::VBox * get_params_widget(void);
228 protected:
229 inline static void add_val(Glib::ustring labelstr, Glib::ustring valuestr, Gtk::Table * table, int * row);
231 };
235 /*
237 This is a prototype for how collections should work. Whoever gets
238 around to implementing this gets to decide what a 'folder' and an
239 'item' really is. That is the joy of implementing it, eh?
241 class Collection : public Extension {
243 public:
244 folder get_root (void);
245 int get_count (folder);
246 thumbnail get_thumbnail(item);
247 item[] get_items(folder);
248 folder[] get_folders(folder);
249 metadata get_metadata(item);
250 image get_image(item);
252 };
253 */
255 } /* namespace Extension */
256 } /* namespace Inkscape */
258 #endif /* __INK_EXTENSION_H__ */
260 /*
261 Local Variables:
262 mode:c++
263 c-file-style:"stroustrup"
264 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
265 indent-tabs-mode:nil
266 fill-column:99
267 End:
268 */
269 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :