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_string_param {};
157 class param_not_float_param {};
158 class param_not_int_param {};
159 class param_not_bool_param {};
161 /** An error class for when a parameter is looked for that just
162 * simply doesn't exist */
163 class param_not_exist {};
165 /** An error class for when a filename already exists, but the user
166 * doesn't want to overwrite it */
167 class no_overwrite {};
169 private:
170 void make_param (Inkscape::XML::Node * paramrepr);
171 #if 0
172 inline param_t * param_shared (const gchar * name,
173 GSList * list);
174 #endif
175 public:
176 bool get_param_bool (const gchar * name,
177 const SPDocument * doc = NULL,
178 const Inkscape::XML::Node * node = NULL);
179 int get_param_int (const gchar * name,
180 const SPDocument * doc = NULL,
181 const Inkscape::XML::Node * node = NULL);
182 float get_param_float (const gchar * name,
183 const SPDocument * doc = NULL,
184 const Inkscape::XML::Node * node = NULL);
185 const gchar * get_param_string (const gchar * name,
186 const SPDocument * doc = NULL,
187 const Inkscape::XML::Node * node = NULL);
188 guint32 get_param_color (const gchar * name,
189 const SPDocument * doc = NULL,
190 const Inkscape::XML::Node * node = NULL);
191 const gchar * get_param_enum (const gchar * name,
192 const SPDocument * doc = NULL,
193 const Inkscape::XML::Node * node = NULL);
194 bool set_param_bool (const gchar * name,
195 bool value,
196 SPDocument * doc = NULL,
197 Inkscape::XML::Node * node = NULL);
198 int set_param_int (const gchar * name,
199 int value,
200 SPDocument * doc = NULL,
201 Inkscape::XML::Node * node = NULL);
202 float set_param_float (const gchar * name,
203 float value,
204 SPDocument * doc = NULL,
205 Inkscape::XML::Node * node = NULL);
206 const gchar * set_param_string (const gchar * name,
207 const gchar * value,
208 SPDocument * doc = NULL,
209 Inkscape::XML::Node * node = NULL);
210 guint32 set_param_color (const gchar * name,
211 guint32 color,
212 SPDocument * doc = NULL,
213 Inkscape::XML::Node * node = NULL);
215 /* Error file handling */
216 public:
217 static void error_file_open (void);
218 static void error_file_close (void);
220 public:
221 Gtk::Widget * autogui (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal = NULL);
222 void paramListString (std::list <std::string> & retlist);
223 void set_gui(bool s) { _gui = s; }
225 /* Extension editor dialog stuff */
226 public:
227 Gtk::VBox * get_info_widget(void);
228 Gtk::VBox * get_help_widget(void);
229 Gtk::VBox * get_params_widget(void);
230 protected:
231 inline static void add_val(Glib::ustring labelstr, Glib::ustring valuestr, Gtk::Table * table, int * row);
233 };
237 /*
239 This is a prototype for how collections should work. Whoever gets
240 around to implementing this gets to decide what a 'folder' and an
241 'item' really is. That is the joy of implementing it, eh?
243 class Collection : public Extension {
245 public:
246 folder get_root (void);
247 int get_count (folder);
248 thumbnail get_thumbnail(item);
249 item[] get_items(folder);
250 folder[] get_folders(folder);
251 metadata get_metadata(item);
252 image get_image(item);
254 };
255 */
257 } /* namespace Extension */
258 } /* namespace Inkscape */
260 #endif /* __INK_EXTENSION_H__ */
262 /*
263 Local Variables:
264 mode:c++
265 c-file-style:"stroustrup"
266 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
267 indent-tabs-mode:nil
268 fill-column:99
269 End:
270 */
271 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :