Code

Following this thread: http://www.nabble.com/Extension-parameters-td9064285.html...
[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 /** 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"
70 namespace Inkscape {
71 namespace Extension {
73 /** The object that is the basis for the Extension system.  This object
74     contains all of the information that all Extension have.  The
75     individual items are detailed within. This is the interface that
76     those who want to _use_ the extensions system should use.  This
77     is most likely to be those who are inside the Inkscape program. */
78 class Extension {
79 public:
80     /** An enumeration to identify if the Extension has been loaded or not. */
81     typedef enum {
82         STATE_LOADED,      /**< The extension has been loaded successfully */
83         STATE_UNLOADED,    /**< The extension has not been loaded */
84         STATE_DEACTIVATED  /**< The extension is missing something which makes it unusable */
85     } state_t;
86     static std::vector<const gchar *> search_path; /**< A vector of paths to search for extensions */
88 private:
89     gchar     *id;                        /**< The unique identifier for the Extension */
90     gchar     *name;                      /**< A user friendly name for the Extension */
91     gchar     *_help;                     /**< A string that contains a help text for the user */
92     state_t    _state;                    /**< Which state the Extension is currently in */
93     std::vector<Dependency *>  _deps;     /**< Dependencies for this extension */
94     static std::ofstream error_file;      /**< This is the place where errors get reported */
96 protected:
97     Inkscape::XML::Node *repr;            /**< The XML description of the Extension */
98     Implementation::Implementation * imp; /**< An object that holds all the functions for making this work */
99     ExpirationTimer * timer;              /**< Timeout to unload after a given time */
101 public:
102                   Extension    (Inkscape::XML::Node * in_repr,
103                                 Implementation::Implementation * in_imp);
104     virtual      ~Extension    (void);
106     void          set_state    (state_t in_state);
107     state_t       get_state    (void);
108     bool          loaded       (void);
109     virtual bool  check        (void);
110     Inkscape::XML::Node *      get_repr     (void);
111     gchar *       get_id       (void);
112     gchar *       get_name     (void);
113     /** \brief  Gets the help string for this extension */
114     gchar const * get_help     (void) { return _help; }
115     void          deactivate   (void);
116     bool          deactivated  (void);
117     void          printFailure (Glib::ustring reason);
118     Implementation::Implementation * get_imp (void) { return imp; };
120 /* Parameter Stuff */
121 private:
122     GSList * parameters; /**< A table to store the parameters for this extension.
123                               This only gets created if there are parameters in this
124                               extension */
126 public:
127     /** \brief  A function to get the the number of parameters that
128                 the extension has.
129         \return The number of parameters. */
130     unsigned int param_count ( ) { return parameters == NULL ? 0 :
131                                               g_slist_length(parameters); };
132     /** \brief  A function to get the the number of parameters that
133                 are visible to the user that the extension has.
134         \return The number of visible parameters. 
135         
136         \note Currently this just calls param_count as visible isn't implemented
137               but in the future it'll do something different.  Please call
138               the appropriate function in code so that it'll work in the
139               future.
140     */
141     unsigned int param_visible_count ( );
143 public:
144     /** An error class for when a parameter is called on a type it is not */
145     class param_wrong_type {};
146     class param_not_color_param {};
147     class param_not_enum_param {};
148     class param_not_string_param {};
149     class param_not_float_param {};
150     class param_not_int_param {};
151     class param_not_bool_param {};
152     
153     /** An error class for when a parameter is looked for that just 
154      * simply doesn't exist */
155     class param_not_exist {};
156     
157     /** An error class for when a filename already exists, but the user 
158      * doesn't want to overwrite it */
159     class no_overwrite {};
161 private:
162     void             make_param       (Inkscape::XML::Node * paramrepr);
163 #if 0
164     inline param_t * param_shared     (const gchar * name,
165                                        GSList * list);
166 #endif
167 public:
168     bool             get_param_bool   (const gchar * name,
169                                        const SPDocument *   doc = NULL,
170                                        const Inkscape::XML::Node * node = NULL);
171     int              get_param_int    (const gchar * name,
172                                        const SPDocument *   doc = NULL,
173                                        const Inkscape::XML::Node * node = NULL);
174     float            get_param_float  (const gchar * name,
175                                        const SPDocument *   doc = NULL,
176                                        const Inkscape::XML::Node * node = NULL);
177     const gchar *    get_param_string (const gchar * name,
178                                        const SPDocument *   doc = NULL,
179                                        const Inkscape::XML::Node * node = NULL);
180     guint32          get_param_color  (const gchar * name,
181                                        const SPDocument *   doc = NULL,
182                                        const Inkscape::XML::Node * node = NULL);
183     const gchar *    get_param_enum   (const gchar * name,
184                                        const SPDocument *   doc = NULL,
185                                        const Inkscape::XML::Node * node = NULL);
186     bool             set_param_bool   (const gchar * name,
187                                        bool          value,
188                                        SPDocument *   doc = NULL,
189                                        Inkscape::XML::Node *       node = NULL);
190     int              set_param_int    (const gchar * name,
191                                        int           value,
192                                        SPDocument *   doc = NULL,
193                                        Inkscape::XML::Node *       node = NULL);
194     float            set_param_float  (const gchar * name,
195                                        float         value,
196                                        SPDocument *   doc = NULL,
197                                        Inkscape::XML::Node *       node = NULL);
198     const gchar *    set_param_string (const gchar * name,
199                                        const gchar * value,
200                                        SPDocument *   doc = NULL,
201                                        Inkscape::XML::Node *       node = NULL);
202     guint32          set_param_color  (const gchar * name,
203                                        guint32 color,
204                                        SPDocument *   doc = NULL,
205                                        Inkscape::XML::Node *       node = NULL);
207     /* Error file handling */
208 public:
209     static void      error_file_open  (void);
210     static void      error_file_close (void);
212 public:
213     Gtk::Widget *    autogui (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal = NULL);
214     void paramListString (std::list <std::string> & retlist);
216     /* Extension editor dialog stuff */
217 public:
218     Gtk::VBox *    get_info_widget(void);
219     Gtk::VBox *    get_help_widget(void);
220     Gtk::VBox *    get_params_widget(void);
221 protected:
222     inline static void add_val(Glib::ustring labelstr, Glib::ustring valuestr, Gtk::Table * table, int * row);
224 };
228 /*
230 This is a prototype for how collections should work.  Whoever gets
231 around to implementing this gets to decide what a 'folder' and an
232 'item' really is.  That is the joy of implementing it, eh?
234 class Collection : public Extension {
236 public:
237     folder  get_root (void);
238     int     get_count (folder);
239     thumbnail get_thumbnail(item);
240     item[]  get_items(folder);
241     folder[]  get_folders(folder);
242     metadata get_metadata(item);
243     image   get_image(item);
245 };
246 */
248 }  /* namespace Extension */
249 }  /* namespace Inkscape */
251 #endif /* __INK_EXTENSION_H__ */
253 /*
254   Local Variables:
255   mode:c++
256   c-file-style:"stroustrup"
257   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
258   indent-tabs-mode:nil
259   fill-column:99
260   End:
261 */
262 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :