Code

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