Code

Node tool: special case node duplication for endnodes - select new endnode
[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 "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     
173     Parameter *      get_param        (const gchar * name);
175 public:
176     bool             get_param_bool   (const gchar * name,
177                                        const SPDocument *   doc = NULL,
178                                        const Inkscape::XML::Node * node = NULL);
180     int              get_param_int    (const gchar * name,
181                                        const SPDocument *   doc = NULL,
182                                        const Inkscape::XML::Node * node = NULL);
184     float            get_param_float  (const gchar * name,
185                                        const SPDocument *   doc = NULL,
186                                        const Inkscape::XML::Node * node = NULL);
188     const gchar *    get_param_string (const gchar * name,
189                                        const SPDocument *   doc = NULL,
190                                        const Inkscape::XML::Node * node = NULL);
192     guint32          get_param_color  (const gchar * name,
193                                        const SPDocument *   doc = NULL,
194                                        const Inkscape::XML::Node * node = NULL);
196     const gchar *    get_param_enum   (const gchar * name,
197                                        const SPDocument *   doc = NULL,
198                                        const Inkscape::XML::Node * node = NULL);
200     gchar const *get_param_optiongroup( gchar const * name,
201                                         SPDocument const *   doc = 0,
202                                         Inkscape::XML::Node const * node = 0);
204     bool             set_param_bool   (const gchar * name,
205                                        bool          value,
206                                        SPDocument *   doc = NULL,
207                                        Inkscape::XML::Node *       node = NULL);
209     int              set_param_int    (const gchar * name,
210                                        int           value,
211                                        SPDocument *   doc = NULL,
212                                        Inkscape::XML::Node *       node = NULL);
214     float            set_param_float  (const gchar * name,
215                                        float         value,
216                                        SPDocument *   doc = NULL,
217                                        Inkscape::XML::Node *       node = NULL);
219     const gchar *    set_param_string (const gchar * name,
220                                        const gchar * value,
221                                        SPDocument *   doc = NULL,
222                                        Inkscape::XML::Node *       node = NULL);
224     gchar const * set_param_optiongroup(gchar const * name,
225                                         gchar const * value,
226                                         SPDocument * doc = 0,
227                                         Inkscape::XML::Node * node = 0);
229     guint32          set_param_color  (const gchar * name,
230                                        guint32 color,
231                                        SPDocument *   doc = NULL,
232                                        Inkscape::XML::Node *       node = NULL);
234     /* Error file handling */
235 public:
236     static void      error_file_open  (void);
237     static void      error_file_close (void);
239 public:
240     Gtk::Widget *    autogui (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal = NULL);
241     void paramListString (std::list <std::string> & retlist);
242     void set_gui(bool s) { _gui = s; }
244     /* Extension editor dialog stuff */
245 public:
246     Gtk::VBox *    get_info_widget(void);
247     Gtk::VBox *    get_help_widget(void);
248     Gtk::VBox *    get_params_widget(void);
249 protected:
250     inline static void add_val(Glib::ustring labelstr, Glib::ustring valuestr, Gtk::Table * table, int * row);
252 };
256 /*
258 This is a prototype for how collections should work.  Whoever gets
259 around to implementing this gets to decide what a 'folder' and an
260 'item' really is.  That is the joy of implementing it, eh?
262 class Collection : public Extension {
264 public:
265     folder  get_root (void);
266     int     get_count (folder);
267     thumbnail get_thumbnail(item);
268     item[]  get_items(folder);
269     folder[]  get_folders(folder);
270     metadata get_metadata(item);
271     image   get_image(item);
273 };
274 */
276 }  /* namespace Extension */
277 }  /* namespace Inkscape */
279 #endif /* __INK_EXTENSION_H__ */
281 /*
282   Local Variables:
283   mode:c++
284   c-file-style:"stroustrup"
285   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
286   indent-tabs-mode:nil
287   fill-column:99
288   End:
289 */
290 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :