Code

Add Miklos's new Cairo PDF rendering
[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 /** Defines the key for PDF printing */
47 #define SP_MODULE_KEY_PRINT_PDF    "org.inkscape.print.pdf"
48 #define SP_MODULE_KEY_PRINT_CAIRO_PDF   "org.inkscape.print.pdf.cairo"
49 /** Defines the key for LaTeX printing */
50 #define SP_MODULE_KEY_PRINT_LATEX    "org.inkscape.print.latex"
51 /** Defines the key for printing with GNOME Print */
52 #define SP_MODULE_KEY_PRINT_GNOME "org.inkscape.print.gnome"
53 /** Defines the key for printing under Win32 */
54 #define SP_MODULE_KEY_PRINT_WIN32 "org.inkscape.print.win32"
55 #ifdef WIN32
56 /** Defines the default printing to use */
57 #define SP_MODULE_KEY_PRINT_DEFAULT  SP_MODULE_KEY_PRINT_WIN32
58 #else
59 #ifdef WITH_GNOME_PRINT
60 /** Defines the default printing to use */
61 #define SP_MODULE_KEY_PRINT_DEFAULT  SP_MODULE_KEY_PRINT_GNOME
62 #else
63 /** Defines the default printing to use */
64 #define SP_MODULE_KEY_PRINT_DEFAULT  SP_MODULE_KEY_PRINT_PS
65 #endif
66 #endif
68 /** Mime type for SVG */
69 #define MIME_SVG "image/svg+xml"
71 /** Name of the extension error file */
72 #define EXTENSION_ERROR_LOG_FILENAME  "extension-errors.log"
74 namespace Inkscape {
75 namespace Extension {
77 /** The object that is the basis for the Extension system.  This object
78     contains all of the information that all Extension have.  The
79     individual items are detailed within. This is the interface that
80     those who want to _use_ the extensions system should use.  This
81     is most likely to be those who are inside the Inkscape program. */
82 class Extension {
83 public:
84     /** An enumeration to identify if the Extension has been loaded or not. */
85     typedef enum {
86         STATE_LOADED,      /**< The extension has been loaded successfully */
87         STATE_UNLOADED,    /**< The extension has not been loaded */
88         STATE_DEACTIVATED  /**< The extension is missing something which makes it unusable */
89     } state_t;
90     static std::vector<const gchar *> search_path; /**< A vector of paths to search for extensions */
92 private:
93     gchar     *id;                        /**< The unique identifier for the Extension */
94     gchar     *name;                      /**< A user friendly name for the Extension */
95     gchar     *_help;                     /**< A string that contains a help text for the user */
96     state_t    _state;                    /**< Which state the Extension is currently in */
97     std::vector<Dependency *>  _deps;     /**< Dependencies for this extension */
98     static std::ofstream error_file;      /**< This is the place where errors get reported */
100 protected:
101     Inkscape::XML::Node *repr;                         /**< The XML description of the Extension */
102     Implementation::Implementation * imp; /**< An object that holds all the functions for making this work */
103     ExpirationTimer * timer;              /**< Timeout to unload after a given time */
105 public:
106                   Extension    (Inkscape::XML::Node * in_repr,
107                                 Implementation::Implementation * in_imp);
108     virtual      ~Extension    (void);
110     void          set_state    (state_t in_state);
111     state_t       get_state    (void);
112     bool          loaded       (void);
113     virtual bool  check        (void);
114     Inkscape::XML::Node *      get_repr     (void);
115     gchar *       get_id       (void);
116     gchar *       get_name     (void);
117     /** \brief  Gets the help string for this extension */
118     gchar const * get_help     (void) { return _help; }
119     void          deactivate   (void);
120     bool          deactivated  (void);
121     void          printFailure (Glib::ustring reason);
124 /* Parameter Stuff */
125 private:
126     GSList * parameters; /**< A table to store the parameters for this extension.
127                               This only gets created if there are parameters in this
128                               extension */
130 public:
131     /** An error class for when a parameter is called on a type it is not */
132     class param_wrong_type {};
133     
134     /** An error class for when a parameter is looked for that just 
135      * simply doesn't exist */
136     class param_not_exist {};
137     
138     /** An error class for when a filename already exists, but the user 
139      * doesn't want to overwrite it */
140     class no_overwrite {};
142 private:
143     void             make_param       (Inkscape::XML::Node * paramrepr);
144 #if 0
145     inline param_t * param_shared     (const gchar * name,
146                                        GSList * list);
147 #endif
148 public:
149     bool             get_param_bool   (const gchar * name,
150                                        const SPDocument *   doc = NULL,
151                                        const Inkscape::XML::Node * node = NULL);
152     int              get_param_int    (const gchar * name,
153                                        const SPDocument *   doc = NULL,
154                                        const Inkscape::XML::Node * node = NULL);
155     float            get_param_float  (const gchar * name,
156                                        const SPDocument *   doc = NULL,
157                                        const Inkscape::XML::Node * node = NULL);
158     const gchar *    get_param_string (const gchar * name,
159                                        const SPDocument *   doc = NULL,
160                                        const Inkscape::XML::Node * node = NULL);
161     bool             set_param_bool   (const gchar * name,
162                                        bool          value,
163                                        SPDocument *   doc = NULL,
164                                        Inkscape::XML::Node *       node = NULL);
165     int              set_param_int    (const gchar * name,
166                                        int           value,
167                                        SPDocument *   doc = NULL,
168                                        Inkscape::XML::Node *       node = NULL);
169     float            set_param_float  (const gchar * name,
170                                        float         value,
171                                        SPDocument *   doc = NULL,
172                                        Inkscape::XML::Node *       node = NULL);
173     const gchar *    set_param_string (const gchar * name,
174                                        const gchar * value,
175                                        SPDocument *   doc = NULL,
176                                        Inkscape::XML::Node *       node = NULL);
178     /* Error file handling */
179 public:
180     static void      error_file_open  (void);
181     static void      error_file_close (void);
183 public:
184     Gtk::Widget *    autogui (SPDocument * doc, Inkscape::XML::Node * node);
185     Glib::ustring *  paramString (void);
187     /* Extension editor dialog stuff */
188 public:
189     Gtk::VBox *    get_info_widget(void);
190     Gtk::VBox *    get_help_widget(void);
191     Gtk::VBox *    get_params_widget(void);
192 protected:
193     inline static void add_val(Glib::ustring labelstr, Glib::ustring valuestr, Gtk::Table * table, int * row);
195 };
199 /*
201 This is a prototype for how collections should work.  Whoever gets
202 around to implementing this gets to decide what a 'folder' and an
203 'item' really is.  That is the joy of implementing it, eh?
205 class Collection : public Extension {
207 public:
208     folder  get_root (void);
209     int     get_count (folder);
210     thumbnail get_thumbnail(item);
211     item[]  get_items(folder);
212     folder[]  get_folders(folder);
213     metadata get_metadata(item);
214     image   get_image(item);
216 };
217 */
219 }  /* namespace Extension */
220 }  /* namespace Inkscape */
222 #endif /* __INK_EXTENSION_H__ */
224 /*
225   Local Variables:
226   mode:c++
227   c-file-style:"stroustrup"
228   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
229   indent-tabs-mode:nil
230   fill-column:99
231   End:
232 */
233 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :