Code

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