Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
extension.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
9/*
10 * Authors:
11 * Ted Gould <ted@gould.cx>
12 *
13 * Copyright (C) 2002-2005 Authors
14 *
15 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
16 */
17
18#ifndef INK_EXTENSION_H
19#define INK_EXTENSION_H
20
21#include <cstdint>
22#include <list>
23#include <memory>
24#include <string>
25#include <vector>
26
27#include <glibmm/ustring.h>
28#include <sigc++/signal.h>
29
30#include "util/hybrid-pointer.h"
31
32// Push color headers to all extensions
33#include "colors/color.h"
34
35namespace Glib {
36class ustring;
37} // namespace Glib
38
39namespace Gtk {
40class Grid;
41class Box;
42class Widget;
43} // namespace Gtk
44
46#define SP_MODULE_KEY_AUTODETECT "autodetect"
48#define SP_MODULE_KEY_INPUT_SVG "org.inkscape.input.svg"
49#define SP_MODULE_KEY_INPUT_SVGZ "org.inkscape.input.svgz"
51#define SP_MODULE_KEY_INPUT_DEFAULT SP_MODULE_KEY_AUTODETECT
53#define SP_MODULE_KEY_OUTPUT_SVG "org.inkscape.output.svg.plain"
54#define SP_MODULE_KEY_OUTPUT_SVGZ "org.inkscape.output.svgz.plain"
56#define SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE "org.inkscape.output.svg.inkscape"
57#define SP_MODULE_KEY_OUTPUT_SVGZ_INKSCAPE "org.inkscape.output.svgz.inkscape"
59#define SP_MODULE_KEY_OUTPUT_DEFAULT SP_MODULE_KEY_AUTODETECT
60
62#define SP_MODULE_KEY_RASTER_PNG "org.inkscape.output.png.inkscape"
63
65#define SP_MODULE_KEY_PRINT_PS "org.inkscape.print.ps"
66#define SP_MODULE_KEY_PRINT_CAIRO_PS "org.inkscape.print.ps.cairo"
67#define SP_MODULE_KEY_PRINT_CAIRO_EPS "org.inkscape.print.eps.cairo"
69#define SP_MODULE_KEY_PRINT_PDF "org.inkscape.print.pdf"
70#define SP_MODULE_KEY_PRINT_CAIRO_PDF "org.inkscape.print.pdf.cairo"
72#define SP_MODULE_KEY_PRINT_LATEX "org.inkscape.print.latex"
74#define SP_MODULE_KEY_PRINT_GNOME "org.inkscape.print.gnome"
75
77#define MIME_SVG "image/svg+xml"
78
80#define EXTENSION_ERROR_LOG_FILENAME "extension-errors.log"
81
82
83#define INKSCAPE_EXTENSION_URI "http://www.inkscape.org/namespace/inkscape/extension"
84#define INKSCAPE_EXTENSION_NS_NC "extension"
85#define INKSCAPE_EXTENSION_NS "extension:"
86
88{
89 MODULE_EXTENSION, // implementation/script.h python extensions
90 MODULE_XSLT, // implementation/xslt.h xml transform extensions
91 MODULE_PLUGIN, // plugins/*/*.h C++ extensions
92 MODULE_UNKNOWN_IMP // No implementation, so nothing created.
93};
94
105
106class SPDocument;
107
108namespace Inkscape {
109
110namespace XML {
111class Node;
112} // namespace XML
113
114namespace Extension {
115
116class ExecutionEnv;
117class Dependency;
118class ProcessingAction;
119class ExpirationTimer;
120class ExpirationTimer;
121class InxParameter;
122class InxWidget;
123
124namespace Implementation {
125class Implementation;
126} // namespace Implementation
127
134public:
142
143private:
144 std::string _id ;
145 std::string _name;
147 int _priority = 0;
148 std::vector<std::unique_ptr<Dependency>> _deps;
149 static FILE *error_file;
150 std::string _error_reason;
151 bool _gui = true;
152
153 std::vector<ProcessingAction> _actions;
155protected:
163 std::string _base_directory;
165 std::unique_ptr<ExpirationTimer> timer;
168private:
169 char const *_translationdomain = nullptr;
174
175public:
176 Extension(Inkscape::XML::Node *in_repr, ImplementationHolder implementation, std::string *base_directory);
177 virtual ~Extension();
178
179 void set_state (state_t in_state);
181 bool loaded ();
182 virtual bool check ();
183 virtual bool prefs();
185 char const *get_id () const;
186 char const *get_name () const;
187 virtual void deactivate ();
188 bool deactivated ();
189 void printFailure (Glib::ustring const &reason);
190 std::string const &getErrorReason() { return _error_reason; };
192 auto const &get_base_directory() const { return _base_directory; };
193 void set_base_directory(std::string const &base_directory) { _base_directory = base_directory; };
194 std::string get_dependency_location(char const *name);
195 char const *get_translation(char const *msgid, char const *msgctxt = nullptr) const;
196 void set_environment(SPDocument const *doc = nullptr);
198
199 int get_sort_priority() const { return _priority; }
200 void set_sort_priority(int priority) { _priority = priority; }
201
203
204 /* Parameter Stuff */
205private:
206 std::vector<std::unique_ptr<InxWidget>> _widgets;
208public:
211 unsigned int widget_visible_count() const;
212
216
219
222
225
227 class no_implementation_for_extension : public std::exception {};
228
231 class no_overwrite {};
232
233private:
234 void make_param (Inkscape::XML::Node * paramrepr);
235
248 InxParameter *get_param(char const *name);
249
251 InxParameter const *get_param(char const *name) const;
252
253public:
254 bool get_param_bool (char const *name) const;
255 bool get_param_bool (char const *name, bool alt) const;
256 int get_param_int (char const *name) const;
257 int get_param_int (char const *name, int alt) const;
258 double get_param_float (char const *name) const;
259 double get_param_float (char const *name, double alt) const;
260 char const *get_param_string (char const *name, char const *alt) const;
261 char const *get_param_string (char const *name) const;
262 char const *get_param_optiongroup (char const *name, char const *alt) const;
263 char const *get_param_optiongroup (char const *name) const;
264
265 Colors::Color get_param_color(char const *name) const;
266
267 bool get_param_optiongroup_contains (char const *name, char const *value) const;
268 bool get_param_optiongroup_is(char const *name, std::string_view value, bool alt = false) const;
269
270 bool set_param_bool (char const *name, bool value);
271 int set_param_int (char const *name, int value);
272 double set_param_float (char const *name, double value);
273 char const *set_param_string (char const *name, char const *value);
274 char const *set_param_optiongroup (char const *name, char const *value);
275 void set_param_color (char const *name, Colors::Color const &color);
276 void set_param_any(char const *name, std::string const &value);
277 void set_param_hidden(char const *name, bool hidden);
278
279 /* Error file handling */
280 static void error_file_open ();
281 static void error_file_close();
282 static void error_file_write(Glib::ustring const &text);
283
284 Gtk::Widget *autogui (SPDocument *doc, Inkscape::XML::Node *node, sigc::signal<void ()> *changeSignal = nullptr);
285 void paramListString(std::list<std::string> &retlist) const;
286 void set_gui(bool s) { _gui = s; }
287 bool get_gui() const { return _gui; }
288
289 /* Extension editor dialog stuff */
290 Gtk::Box *get_info_widget();
291 Gtk::Box *get_params_widget();
292
293protected:
294 inline static void add_val(Glib::ustring const &labelstr, Glib::ustring const &valuestr,
295 Gtk::Grid * table, int * row);
296};
297
298/*
299This is a prototype for how collections should work. Whoever gets
300around to implementing this gets to decide what a 'folder' and an
301'item' really is. That is the joy of implementing it, eh?
302
303class Collection : public Extension {
304
305public:
306 folder get_root (void);
307 int get_count (folder);
308 thumbnail get_thumbnail(item);
309 item[] get_items(folder);
310 folder[] get_folders(folder);
311 metadata get_metadata(item);
312 image get_image(item);
313
314};
315*/
316
317} // namespace Extension
318} // namespace Inkscape
319
320#endif // INK_EXTENSION_H
321
322/*
323 Local Variables:
324 mode:c++
325 c-file-style:"stroustrup"
326 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
327 indent-tabs-mode:nil
328 fill-column:99
329 End:
330*/
331// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
no valid ID found while parsing XML representation
Definition extension.h:218
no valid name found while parsing XML representation
Definition extension.h:221
extension is not compatible with the current system and should not be loaded
Definition extension.h:224
No implementation could be loaded for the extension.
Definition extension.h:227
An error class for when a filename already exists, but the user doesn't want to overwrite it.
Definition extension.h:231
An error class for when a parameter is looked for that just simply doesn't exist.
Definition extension.h:215
The object that is the basis for the Extension system.
Definition extension.h:133
double set_param_float(char const *name, double value)
Sets a parameter identified by name with the double in the parameter value.
state_t get_state()
A getter for the state variable.
int _priority
when sorted, should this come before any others
Definition extension.h:147
char const * get_param_optiongroup(char const *name, char const *alt) const
Like get_param_optiongroup but with a default on param_not_exist error.
virtual void deactivate()
This function diactivates the extension (which makes it unusable, but not deleted)
std::string _name
A user friendly name for the Extension.
Definition extension.h:145
int get_param_int(char const *name) const
Gets a parameter identified by name with the integer placed in value.
char const * get_translation(char const *msgid, char const *msgctxt=nullptr) const
Gets a translation within the context of the current extension.
static void error_file_write(Glib::ustring const &text)
A function to write to the error log file.
std::unique_ptr< ExpirationTimer > timer
Timeout to unload after a given time.
Definition extension.h:165
std::string _error_reason
Short, textual explanation for the latest error.
Definition extension.h:150
state_t
An enumeration to identify if the Extension has been loaded or not.
Definition extension.h:136
@ STATE_LOADED
The extension has been loaded successfully.
Definition extension.h:137
@ STATE_DEACTIVATED
The extension is missing something which makes it unusable.
Definition extension.h:139
@ STATE_UNLOADED
The extension has not been loaded.
Definition extension.h:138
unsigned int widget_visible_count() const
A function to get the number of visible parameters of the extension.
bool get_param_optiongroup_is(char const *name, std::string_view value, bool alt=false) const
Find out if an option is set to specific value.
char const * get_name() const
Get the name of this extension - not a copy don't delete!
std::string const & getErrorReason()
Definition extension.h:190
bool get_param_optiongroup_contains(char const *name, char const *value) const
This is useful to find out, if a given string value is selectable in a optiongroup named \cname.
void paramListString(std::list< std::string > &retlist) const
A function to get the parameters in a string form.
double get_param_float(char const *name) const
Gets a float parameter identified by name with the double placed in value.
bool set_param_bool(char const *name, bool value)
Sets a parameter identified by name with the boolean in the parameter value.
void make_param(Inkscape::XML::Node *paramrepr)
Implementation::Implementation * get_imp()
Definition extension.h:191
void run_processing_actions(SPDocument *doc)
Runs any pre-processing actions and modifies the document.
Inkscape::XML::Node * repr
The XML description of the Extension.
Definition extension.h:156
std::string _id
The unique identifier for the Extension.
Definition extension.h:144
Gtk::Widget * autogui(SPDocument *doc, Inkscape::XML::Node *node, sigc::signal< void()> *changeSignal=nullptr)
A function to automatically generate a GUI from the extensions' widgets.
std::vector< std::unique_ptr< Dependency > > _deps
Dependencies for this extension.
Definition extension.h:148
int set_param_int(char const *name, int value)
Sets a parameter identified by name with the integer in the parameter value.
ImplementationHolder imp
An Implementation object provides the actual implementation of the Extension.
Definition extension.h:162
char const * get_id() const
Get the ID of this extension - not a copy don't delete!
static void error_file_open()
A function to open the error log file.
std::vector< std::unique_ptr< InxWidget > > _widgets
A list of widgets for this extension.
Definition extension.h:206
ModuleImpType get_implementation_type()
Uses the object's type to figure out what the type is.
char const * get_param_string(char const *name, char const *alt) const
Like get_param_string but with a default on param_not_exist error.
virtual bool check()
A function to check the validity of the extension.
void set_state(state_t in_state)
A function to set whether the extension should be loaded or unloaded.
Colors::Color get_param_color(char const *name) const
Gets a parameter identified by name with the unsigned int placed in value.
auto const & get_base_directory() const
Definition extension.h:192
bool _translation_enabled
Attempt translation of strings provided by the extension?
Definition extension.h:166
static void add_val(Glib::ustring const &labelstr, Glib::ustring const &valuestr, Gtk::Grid *table, int *row)
void set_param_color(char const *name, Colors::Color const &color)
char const * set_param_optiongroup(char const *name, char const *value)
Sets a parameter identified by name with the string in the parameter value.
std::string get_dependency_location(char const *name)
Gets the location of the dependency file as an absolute path.
void set_param_hidden(char const *name, bool hidden)
static void error_file_close()
A function to close the error log file.
std::vector< ProcessingAction > _actions
Processing actions.
Definition extension.h:153
void set_base_directory(std::string const &base_directory)
Definition extension.h:193
bool loaded()
A quick function to test the state of the extension.
Inkscape::XML::Node * get_repr()
A getter for the internal Repr, does not add a reference.
std::string _base_directory
Directory containing the .inx file, relative paths in the extension should usually be relative to it.
Definition extension.h:163
void set_sort_priority(int priority)
Definition extension.h:200
char const * _translationdomain
Domainname of gettext textdomain that should be used for translation of the extension's strings.
Definition extension.h:169
void set_environment(SPDocument const *doc=nullptr)
Sets environment suitable for executing this Extension.
void printFailure(Glib::ustring const &reason)
A quick function to print out a standard start of extension errors in the log.
char const * set_param_string(char const *name, char const *value)
Sets a parameter identified by name with the string in the parameter value.
bool deactivated()
Find out the status of the extension.
bool get_param_bool(char const *name) const
Gets a parameter identified by name with the bool placed in value.
std::string _gettext_catalog_dir
Directory containing the gettext catalog for _translationdomain.
Definition extension.h:171
virtual bool prefs()
Create a dialog for preference for this extension.
state_t _state
Which state the Extension is currently in.
Definition extension.h:146
void lookup_translation_catalog()
Searches for a gettext catalog matching the extension's translationdomain.
InxParameter * get_param(char const *name)
Looks up the parameter with the specified name.
void set_param_any(char const *name, std::string const &value)
Parses the given string value and sets a parameter identified by name.
static FILE * error_file
This is the place where errors get reported.
Definition extension.h:149
Base class for all implementations of modules.
A class to represent the parameter of an extension.
Definition parameter.h:38
Interface for refcounted XML nodes.
Definition node.h:80
Typed SVG document implementation.
Definition document.h:103
ModuleImpType
Definition extension.h:88
@ MODULE_UNKNOWN_IMP
Definition extension.h:92
@ MODULE_PLUGIN
Definition extension.h:91
@ MODULE_EXTENSION
Definition extension.h:89
@ MODULE_XSLT
Definition extension.h:90
ModuleFuncType
Definition extension.h:96
@ MODULE_UNKNOWN_FUNC
Definition extension.h:103
@ MODULE_OUTPUT
Definition extension.h:99
@ MODULE_FILTER
Definition extension.h:100
@ MODULE_INPUT
Definition extension.h:98
@ MODULE_PATH_EFFECT
Definition extension.h:102
@ MODULE_PRINT
Definition extension.h:101
@ MODULE_TEMPLATE
Definition extension.h:97
A helper variant type wrapping either an owning pointer (std::unique_ptr) or a non-owning,...
Inkscape::XML::Node * node
Definition desktop.h:50
Helper class to stream background task notifications as a series of messages.
Glib::ustring name
Definition toolbars.cpp:55