Code

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