Code

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