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 */
102 bool _gui;
104 protected:
105 Inkscape::XML::Node *repr; /**< The XML description of the Extension */
106 Implementation::Implementation * imp; /**< An object that holds all the functions for making this work */
107 ExpirationTimer * timer; /**< Timeout to unload after a given time */
109 public:
110 Extension (Inkscape::XML::Node * in_repr,
111 Implementation::Implementation * in_imp);
112 virtual ~Extension (void);
114 void set_state (state_t in_state);
115 state_t get_state (void);
116 bool loaded (void);
117 virtual bool check (void);
118 Inkscape::XML::Node * get_repr (void);
119 gchar * get_id (void);
120 gchar * get_name (void);
121 /** \brief Gets the help string for this extension */
122 gchar const * get_help (void) { return _help; }
123 void deactivate (void);
124 bool deactivated (void);
125 void printFailure (Glib::ustring reason);
126 Implementation::Implementation * get_imp (void) { return imp; };
128 /* Parameter Stuff */
129 private:
130 GSList * parameters; /**< A table to store the parameters for this extension.
131 This only gets created if there are parameters in this
132 extension */
134 public:
135 /** \brief A function to get the the number of parameters that
136 the extension has.
137 \return The number of parameters. */
138 unsigned int param_count ( ) { return parameters == NULL ? 0 :
139 g_slist_length(parameters); };
140 /** \brief A function to get the the number of parameters that
141 are visible to the user that the extension has.
142 \return The number of visible parameters.
144 \note Currently this just calls param_count as visible isn't implemented
145 but in the future it'll do something different. Please call
146 the appropriate function in code so that it'll work in the
147 future.
148 */
149 unsigned int param_visible_count ( );
151 public:
152 /** An error class for when a parameter is called on a type it is not */
153 class param_wrong_type {};
154 class param_not_color_param {};
155 class param_not_enum_param {};
156 class param_not_optiongroup_param {};
157 class param_not_string_param {};
158 class param_not_float_param {};
159 class param_not_int_param {};
160 class param_not_bool_param {};
162 /** An error class for when a parameter is looked for that just
163 * simply doesn't exist */
164 class param_not_exist {};
166 /** An error class for when a filename already exists, but the user
167 * doesn't want to overwrite it */
168 class no_overwrite {};
170 private:
171 void make_param (Inkscape::XML::Node * paramrepr);
172 #if 0
173 inline param_t * param_shared (const gchar * name,
174 GSList * list);
175 #endif
176 public:
177 bool get_param_bool (const gchar * name,
178 const SPDocument * doc = NULL,
179 const Inkscape::XML::Node * node = NULL);
181 int get_param_int (const gchar * name,
182 const SPDocument * doc = NULL,
183 const Inkscape::XML::Node * node = NULL);
185 float get_param_float (const gchar * name,
186 const SPDocument * doc = NULL,
187 const Inkscape::XML::Node * node = NULL);
189 const gchar * get_param_string (const gchar * name,
190 const SPDocument * doc = NULL,
191 const Inkscape::XML::Node * node = NULL);
193 guint32 get_param_color (const gchar * name,
194 const SPDocument * doc = NULL,
195 const Inkscape::XML::Node * node = NULL);
197 const gchar * get_param_enum (const gchar * name,
198 const SPDocument * doc = NULL,
199 const Inkscape::XML::Node * node = NULL);
201 gchar const *get_param_optiongroup( gchar const * name,
202 SPDocument const * doc = 0,
203 Inkscape::XML::Node const * node = 0);
205 bool set_param_bool (const gchar * name,
206 bool value,
207 SPDocument * doc = NULL,
208 Inkscape::XML::Node * node = NULL);
210 int set_param_int (const gchar * name,
211 int value,
212 SPDocument * doc = NULL,
213 Inkscape::XML::Node * node = NULL);
215 float set_param_float (const gchar * name,
216 float value,
217 SPDocument * doc = NULL,
218 Inkscape::XML::Node * node = NULL);
220 const gchar * set_param_string (const gchar * name,
221 const gchar * value,
222 SPDocument * doc = NULL,
223 Inkscape::XML::Node * node = NULL);
225 gchar const * set_param_optiongroup(gchar const * name,
226 gchar const * value,
227 SPDocument * doc = 0,
228 Inkscape::XML::Node * node = 0);
230 guint32 set_param_color (const gchar * name,
231 guint32 color,
232 SPDocument * doc = NULL,
233 Inkscape::XML::Node * node = NULL);
235 /* Error file handling */
236 public:
237 static void error_file_open (void);
238 static void error_file_close (void);
240 public:
241 Gtk::Widget * autogui (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal = NULL);
242 void paramListString (std::list <std::string> & retlist);
243 void set_gui(bool s) { _gui = s; }
245 /* Extension editor dialog stuff */
246 public:
247 Gtk::VBox * get_info_widget(void);
248 Gtk::VBox * get_help_widget(void);
249 Gtk::VBox * get_params_widget(void);
250 protected:
251 inline static void add_val(Glib::ustring labelstr, Glib::ustring valuestr, Gtk::Table * table, int * row);
253 };
257 /*
259 This is a prototype for how collections should work. Whoever gets
260 around to implementing this gets to decide what a 'folder' and an
261 'item' really is. That is the joy of implementing it, eh?
263 class Collection : public Extension {
265 public:
266 folder get_root (void);
267 int get_count (folder);
268 thumbnail get_thumbnail(item);
269 item[] get_items(folder);
270 folder[] get_folders(folder);
271 metadata get_metadata(item);
272 image get_image(item);
274 };
275 */
277 } /* namespace Extension */
278 } /* namespace Inkscape */
280 #endif /* __INK_EXTENSION_H__ */
282 /*
283 Local Variables:
284 mode:c++
285 c-file-style:"stroustrup"
286 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
287 indent-tabs-mode:nil
288 fill-column:99
289 End:
290 */
291 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :