Code

62d455fcf9968fd94ad0b6ab76a387ddb87256b5
[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 <glibmm/ustring.h>
22 #include "xml/repr.h"
23 #include "extension/extension-forward.h"
25 /** The key that is used to identify that the I/O should be autodetected */
26 #define SP_MODULE_KEY_AUTODETECT "autodetect"
27 /** This is the key for the SVG input module */
28 #define SP_MODULE_KEY_INPUT_SVG "org.inkscape.input.svg"
29 #define SP_MODULE_KEY_INPUT_SVGZ "org.inkscape.input.svgz"
30 /** Specifies the input module that should be used if none are selected */
31 #define SP_MODULE_KEY_INPUT_DEFAULT SP_MODULE_KEY_AUTODETECT
32 /** The key for outputing standard W3C SVG */
33 #define SP_MODULE_KEY_OUTPUT_SVG "org.inkscape.output.svg.plain"
34 #define SP_MODULE_KEY_OUTPUT_SVGZ "org.inkscape.output.svgz.plain"
35 /** This is an output file that has SVG data with the Sodipodi namespace extensions */
36 #define SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE "org.inkscape.output.svg.inkscape"
37 #define SP_MODULE_KEY_OUTPUT_SVGZ_INKSCAPE "org.inkscape.output.svgz.inkscape"
38 /** Which output module should be used? */
39 #define SP_MODULE_KEY_OUTPUT_DEFAULT SP_MODULE_KEY_AUTODETECT
41 /** Defines the key for Postscript printing */
42 #define SP_MODULE_KEY_PRINT_PS    "org.inkscape.print.ps"
43 /** Defines the key for LaTeX printing */
44 #define SP_MODULE_KEY_PRINT_LATEX    "org.inkscape.print.latex"
45 /** Defines the key for printing with GNOME Print */
46 #define SP_MODULE_KEY_PRINT_GNOME "org.inkscape.print.gnome"
47 /** Defines the key for printing under Win32 */
48 #define SP_MODULE_KEY_PRINT_WIN32 "org.inkscape.print.win32"
49 #ifdef WIN32
50 /** Defines the default printing to use */
51 #define SP_MODULE_KEY_PRINT_DEFAULT  SP_MODULE_KEY_PRINT_WIN32
52 #else
53 #ifdef WITH_GNOME_PRINT
54 /** Defines the default printing to use */
55 #define SP_MODULE_KEY_PRINT_DEFAULT  SP_MODULE_KEY_PRINT_GNOME
56 #else
57 /** Defines the default printing to use */
58 #define SP_MODULE_KEY_PRINT_DEFAULT  SP_MODULE_KEY_PRINT_PS
59 #endif
60 #endif
62 /** Mime type for SVG */
63 #define MIME_SVG "image/svg+xml"
65 /** Name of the extension error file */
66 #define EXTENSION_ERROR_LOG_FILENAME  "extension-errors.log"
68 namespace Inkscape {
69 namespace Extension {
71 /** The object that is the basis for the Extension system.  This object
72     contains all of the information that all Extension have.  The
73     individual items are detailed within. This is the interface that
74     those who want to _use_ the extensions system should use.  This
75     is most likely to be those who are inside the Inkscape program. */
76 class Extension {
77 public:
78     /** An enumeration to identify if the Extension has been loaded or not. */
79     typedef enum {
80         STATE_LOADED,      /**< The extension has been loaded successfully */
81         STATE_UNLOADED,    /**< The extension has not been loaded */
82         STATE_DEACTIVATED  /**< The extension is missing something which makes it unusable */
83     } state_t;
84     static std::vector<const gchar *> search_path; /**< A vector of paths to search for extensions */
86 private:
87     gchar     *id;                        /**< The unique identifier for the Extension */
88     gchar     *name;                      /**< A user friendly name for the Extension */
89     gchar     *_help;                     /**< A string that contains a help text for the user */
90     state_t    _state;                    /**< Which state the Extension is currently in */
91     std::vector<Dependency *>  _deps;     /**< Dependencies for this extension */
92     static std::ofstream error_file;      /**< This is the place where errors get reported */
94 protected:
95     Inkscape::XML::Node *repr;                         /**< The XML description of the Extension */
96     Implementation::Implementation * imp; /**< An object that holds all the functions for making this work */
97     ExpirationTimer * timer;              /**< Timeout to unload after a given time */
99 public:
100                   Extension    (Inkscape::XML::Node * in_repr,
101                                 Implementation::Implementation * in_imp);
102     virtual      ~Extension    (void);
104     void          set_state    (state_t in_state);
105     state_t       get_state    (void);
106     bool          loaded       (void);
107     virtual bool  check        (void);
108     Inkscape::XML::Node *      get_repr     (void);
109     gchar *       get_id       (void);
110     gchar *       get_name     (void);
111     /** \brief  Gets the help string for this extension */
112     gchar const * get_help     (void) { return _help; }
113     void          deactivate   (void);
114     bool          deactivated  (void);
115     void          printFailure (Glib::ustring reason);
118 /* Parameter Stuff */
119 private:
120     GSList * parameters; /**< A table to store the parameters for this extension.
121                               This only gets created if there are parameters in this
122                               extension */
124 public:
125     /** An error class for when a parameter is called on a type it is not */
126     class param_wrong_type {};
127     
128     /** An error class for when a parameter is looked for that just 
129      * simply doesn't exist */
130     class param_not_exist {};
131     
132     /** An error class for when a filename already exists, but the user 
133      * doesn't want to overwrite it */
134     class no_overwrite {};
136 private:
137     void             make_param       (Inkscape::XML::Node * paramrepr);
138 #if 0
139     inline param_t * param_shared     (const gchar * name,
140                                        GSList * list);
141 #endif
142 public:
143     bool             get_param_bool   (const gchar * name,
144                                        const Inkscape::XML::Document *   doc = NULL);
145     int              get_param_int    (const gchar * name,
146                                        const Inkscape::XML::Document *   doc = NULL);
147     float            get_param_float  (const gchar * name,
148                                        const Inkscape::XML::Document *   doc = NULL);
149     const gchar *    get_param_string (const gchar * name,
150                                        const Inkscape::XML::Document *   doc = NULL);
151     bool             set_param_bool   (const gchar * name,
152                                        bool          value,
153                                        Inkscape::XML::Document *   doc = NULL);
154     int              set_param_int    (const gchar * name,
155                                        int           value,
156                                        Inkscape::XML::Document *   doc = NULL);
157     float            set_param_float  (const gchar * name,
158                                        float         value,
159                                        Inkscape::XML::Document *   doc = NULL);
160     const gchar *    set_param_string (const gchar * name,
161                                        const gchar * value,
162                                        Inkscape::XML::Document *   doc = NULL);
164     /* Error file handling */
165 public:
166     static void      error_file_open  (void);
167     static void      error_file_close (void);
169 public:
170     Gtk::Widget *    autogui (void);
171     Glib::ustring *  paramString (void);
173     /* Extension editor dialog stuff */
174 public:
175     Gtk::Widget *    get_info_widget(void);
176     Gtk::Widget *    get_help_widget(void);
177     Gtk::Widget *    get_params_widget(void);
179 };
183 /*
185 This is a prototype for how collections should work.  Whoever gets
186 around to implementing this gets to decide what a 'folder' and an
187 'item' really is.  That is the joy of implementing it, eh?
189 class Collection : public Extension {
191 public:
192     folder  get_root (void);
193     int     get_count (folder);
194     thumbnail get_thumbnail(item);
195     item[]  get_items(folder);
196     folder[]  get_folders(folder);
197     metadata get_metadata(item);
198     image   get_image(item);
200 };
201 */
203 }  /* namespace Extension */
204 }  /* namespace Inkscape */
206 #endif /* __INK_EXTENSION_H__ */
208 /*
209   Local Variables:
210   mode:c++
211   c-file-style:"stroustrup"
212   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
213   indent-tabs-mode:nil
214   fill-column:99
215   End:
216 */
217 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :