Inkscape
Vector Graphics Editor
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
32namespace Glib {
33class ustring;
34} // namespace Glib
35
36namespace Gtk {
37class Grid;
38class Box;
39class Widget;
40} // namespace Gtk
41
43#define SP_MODULE_KEY_AUTODETECT "autodetect"
45#define SP_MODULE_KEY_INPUT_SVG "org.inkscape.input.svg"
46#define SP_MODULE_KEY_INPUT_SVGZ "org.inkscape.input.svgz"
48#define SP_MODULE_KEY_INPUT_DEFAULT SP_MODULE_KEY_AUTODETECT
50#define SP_MODULE_KEY_OUTPUT_SVG "org.inkscape.output.svg.plain"
51#define SP_MODULE_KEY_OUTPUT_SVGZ "org.inkscape.output.svgz.plain"
53#define SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE "org.inkscape.output.svg.inkscape"
54#define SP_MODULE_KEY_OUTPUT_SVGZ_INKSCAPE "org.inkscape.output.svgz.inkscape"
56#define SP_MODULE_KEY_OUTPUT_DEFAULT SP_MODULE_KEY_AUTODETECT
57
59#define SP_MODULE_KEY_RASTER_PNG "org.inkscape.output.png.inkscape"
60
62#define SP_MODULE_KEY_PRINT_PS "org.inkscape.print.ps"
63#define SP_MODULE_KEY_PRINT_CAIRO_PS "org.inkscape.print.ps.cairo"
64#define SP_MODULE_KEY_PRINT_CAIRO_EPS "org.inkscape.print.eps.cairo"
66#define SP_MODULE_KEY_PRINT_PDF "org.inkscape.print.pdf"
67#define SP_MODULE_KEY_PRINT_CAIRO_PDF "org.inkscape.print.pdf.cairo"
69#define SP_MODULE_KEY_PRINT_LATEX "org.inkscape.print.latex"
71#define SP_MODULE_KEY_PRINT_GNOME "org.inkscape.print.gnome"
72
74#define MIME_SVG "image/svg+xml"
75
77#define EXTENSION_ERROR_LOG_FILENAME "extension-errors.log"
78
79
80#define INKSCAPE_EXTENSION_URI "http://www.inkscape.org/namespace/inkscape/extension"
81#define INKSCAPE_EXTENSION_NS_NC "extension"
82#define INKSCAPE_EXTENSION_NS "extension:"
83
85{
86 MODULE_EXTENSION, // implementation/script.h python extensions
87 MODULE_XSLT, // implementation/xslt.h xml transform extensions
88 MODULE_PLUGIN, // plugins/*/*.h C++ extensions
89 MODULE_UNKNOWN_IMP // No implementation, so nothing created.
90};
91
93{
102
103class SPDocument;
104
105namespace Inkscape {
106
107namespace XML {
108class Node;
109} // namespace XML
110
111namespace Extension {
112
113class ExecutionEnv;
114class Dependency;
115class ProcessingAction;
116class ExpirationTimer;
117class ExpirationTimer;
118class InxParameter;
119class InxWidget;
120
121namespace Implementation {
122class Implementation;
123} // namespace Implementation
124
131public:
133 enum state_t {
137 };
139
140private:
141 std::string _id ;
142 std::string _name;
144 int _priority = 0;
145 std::vector<std::unique_ptr<Dependency>> _deps;
146 static FILE *error_file;
147 std::string _error_reason;
148 bool _gui = true;
149
150 std::vector<ProcessingAction> _actions;
152protected:
162 std::string _base_directory;
164 std::unique_ptr<ExpirationTimer> timer;
167private:
168 char const *_translationdomain = nullptr;
173
174public:
175 Extension(Inkscape::XML::Node *in_repr, ImplementationHolder implementation, std::string *base_directory);
176 virtual ~Extension();
177
178 void set_state (state_t in_state);
180 bool loaded ();
181 virtual bool check ();
182 virtual bool prefs();
184 char const *get_id () const;
185 char const *get_name () const;
186 virtual void deactivate ();
187 bool deactivated ();
188 void printFailure (Glib::ustring const &reason);
189 std::string const &getErrorReason() { return _error_reason; };
193 auto const &get_base_directory() const { return _base_directory; };
194 void set_base_directory(std::string const &base_directory) { _base_directory = base_directory; };
195 std::string get_dependency_location(char const *name);
196 char const *get_translation(char const *msgid, char const *msgctxt = nullptr) const;
197 void set_environment(SPDocument const *doc = nullptr);
199
200 int get_sort_priority() const { return _priority; }
201 void set_sort_priority(int priority) { _priority = priority; }
202
203 virtual void run_processing_actions(SPDocument *doc);
204
205 /* Parameter Stuff */
206private:
207 std::vector<std::unique_ptr<InxWidget>> _widgets;
209public:
212 unsigned int widget_visible_count() const;
213
217
220
223
226
228 class no_implementation_for_extension : public std::exception {};
229
232 class no_overwrite {};
233
234private:
235 void make_param (Inkscape::XML::Node * paramrepr);
236
249 InxParameter *get_param(char const *name);
250
252 InxParameter const *get_param(char const *name) const;
253
254public:
255 bool get_param_bool (char const *name) const;
256 bool get_param_bool (char const *name, bool alt) const;
257 int get_param_int (char const *name) const;
258 int get_param_int (char const *name, int alt) const;
259 double get_param_float (char const *name) const;
260 double get_param_float (char const *name, double alt) const;
261 char const *get_param_string (char const *name, char const *alt) const;
262 char const *get_param_string (char const *name) const;
263 char const *get_param_optiongroup (char const *name, char const *alt) const;
264 char const *get_param_optiongroup (char const *name) const;
265 std::uint32_t get_param_color (char const *name) const;
266
267 bool get_param_optiongroup_contains (char const *name, char const *value) const;
268
269 bool set_param_bool (char const *name, bool value);
270 int set_param_int (char const *name, int value);
271 double set_param_float (char const *name, double value);
272 char const *set_param_string (char const *name, char const *value);
273 char const *set_param_optiongroup (char const *name, char const *value);
274 std::uint32_t set_param_color (char const *name, std::uint32_t color);
275 void set_param_any(char const *name, std::string const &value);
276 void set_param_hidden(char const *name, bool hidden);
277
278 /* Error file handling */
279 static void error_file_open ();
280 static void error_file_close();
281 static void error_file_write(Glib::ustring const &text);
282
283 Gtk::Widget *autogui (SPDocument *doc, Inkscape::XML::Node *node, sigc::signal<void ()> *changeSignal = nullptr);
284 void paramListString(std::list<std::string> &retlist) const;
285 void set_gui(bool s) { _gui = s; }
286 bool get_gui() const { return _gui; }
287
288 /* Extension editor dialog stuff */
289 Gtk::Box *get_info_widget();
290 Gtk::Box *get_params_widget();
291
292protected:
293 inline static void add_val(Glib::ustring const &labelstr, Glib::ustring const &valuestr,
294 Gtk::Grid * table, int * row);
295};
296
297/*
298This is a prototype for how collections should work. Whoever gets
299around to implementing this gets to decide what a 'folder' and an
300'item' really is. That is the joy of implementing it, eh?
301
302class Collection : public Extension {
303
304public:
305 folder get_root (void);
306 int get_count (folder);
307 thumbnail get_thumbnail(item);
308 item[] get_items(folder);
309 folder[] get_folders(folder);
310 metadata get_metadata(item);
311 image get_image(item);
312
313};
314*/
315
316} // namespace Extension
317} // namespace Inkscape
318
319#endif // INK_EXTENSION_H
320
321/*
322 Local Variables:
323 mode:c++
324 c-file-style:"stroustrup"
325 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
326 indent-tabs-mode:nil
327 fill-column:99
328 End:
329*/
330// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
no valid ID found while parsing XML representation
Definition: extension.h:219
no valid name found while parsing XML representation
Definition: extension.h:222
extension is not compatible with the current system and should not be loaded
Definition: extension.h:225
No implementation could be loaded for the extension.
Definition: extension.h:228
An error class for when a filename already exists, but the user doesn't want to overwrite it.
Definition: extension.h:232
An error class for when a parameter is looked for that just simply doesn't exist.
Definition: extension.h:216
The object that is the basis for the Extension system.
Definition: extension.h:130
double set_param_float(char const *name, double value)
Sets a parameter identified by name with the double in the parameter value.
Definition: extension.cpp:836
state_t get_state()
A getter for the state variable.
Definition: extension.cpp:225
int _priority
when sorted, should this come before any others
Definition: extension.h:144
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.
Definition: extension.cpp:757
virtual void deactivate()
This function diactivates the extension (which makes it unusable, but not deleted)
Definition: extension.cpp:347
std::string _name
A user friendly name for the Extension.
Definition: extension.h:142
ExecutionEnv * execution_env
Execution environment of the extension (currently only used by Effects)
Definition: extension.h:160
int get_param_int(char const *name) const
Gets a parameter identified by name with the integer placed in value.
Definition: extension.cpp:662
char const * get_translation(char const *msgid, char const *msgctxt=nullptr) const
Gets a translation within the context of the current extension.
Definition: extension.cpp:498
static void error_file_write(Glib::ustring const &text)
A function to write to the error log file.
Definition: extension.cpp:928
std::unique_ptr< ExpirationTimer > timer
Timeout to unload after a given time.
Definition: extension.h:164
std::string _error_reason
Short, textual explanation for the latest error.
Definition: extension.h:147
state_t
An enumeration to identify if the Extension has been loaded or not.
Definition: extension.h:133
@ STATE_LOADED
The extension has been loaded successfully.
Definition: extension.h:134
@ STATE_DEACTIVATED
The extension is missing something which makes it unusable.
Definition: extension.h:136
@ STATE_UNLOADED
The extension has not been loaded.
Definition: extension.h:135
unsigned int widget_visible_count() const
A function to get the number of visible parameters of the extension.
Definition: extension.cpp:1044
char const * get_name() const
Get the name of this extension - not a copy don't delete!
Definition: extension.cpp:326
std::string const & getErrorReason()
Definition: extension.h:189
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.
Definition: extension.cpp:773
void paramListString(std::list< std::string > &retlist) const
A function to get the parameters in a string form.
Definition: extension.cpp:570
double get_param_float(char const *name) const
Gets a float parameter identified by name with the double placed in value.
Definition: extension.cpp:690
bool set_param_bool(char const *name, bool value)
Sets a parameter identified by name with the boolean in the parameter value.
Definition: extension.cpp:804
void make_param(Inkscape::XML::Node *paramrepr)
Implementation::Implementation * get_imp()
Definition: extension.h:190
std::uint32_t get_param_color(char const *name) const
Gets a parameter identified by name with the unsigned int placed in value.
Definition: extension.cpp:788
virtual void run_processing_actions(SPDocument *doc)
Runs any pre-processing actions and modifies the document.
Definition: extension.cpp:1085
Inkscape::XML::Node * repr
The XML description of the Extension.
Definition: extension.h:153
std::string _id
The unique identifier for the Extension.
Definition: extension.h:141
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.
Definition: extension.cpp:975
std::vector< std::unique_ptr< Dependency > > _deps
Dependencies for this extension.
Definition: extension.h:145
int set_param_int(char const *name, int value)
Sets a parameter identified by name with the integer in the parameter value.
Definition: extension.cpp:820
ImplementationHolder imp
An Implementation object provides the actual implementation of the Extension.
Definition: extension.h:159
char const * get_id() const
Get the ID of this extension - not a copy don't delete!
Definition: extension.cpp:316
static void error_file_open()
A function to open the error log file.
Definition: extension.cpp:908
std::vector< std::unique_ptr< InxWidget > > _widgets
A list of widgets for this extension.
Definition: extension.h:207
ModuleImpType get_implementation_type()
Uses the object's type to figure out what the type is.
Definition: extension.cpp:553
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.
Definition: extension.cpp:729
ExecutionEnv * get_execution_env()
Definition: extension.h:192
std::uint32_t set_param_color(char const *name, std::uint32_t color)
Definition: extension.cpp:884
virtual bool check()
A function to check the validity of the extension.
Definition: extension.cpp:257
void set_state(state_t in_state)
A function to set whether the extension should be loaded or unloaded.
Definition: extension.cpp:190
auto const & get_base_directory() const
Definition: extension.h:193
bool _translation_enabled
Attempt translation of strings provided by the extension?
Definition: extension.h:165
static void add_val(Glib::ustring const &labelstr, Glib::ustring const &valuestr, Gtk::Grid *table, int *row)
Definition: extension.cpp:1024
char const * set_param_optiongroup(char const *name, char const *value)
Sets a parameter identified by name with the string in the parameter value.
Definition: extension.cpp:868
std::string get_dependency_location(char const *name)
Gets the location of the dependency file as an absolute path.
Definition: extension.cpp:379
void set_param_hidden(char const *name, bool hidden)
Definition: extension.cpp:901
static void error_file_close()
A function to close the error log file.
Definition: extension.cpp:919
Extension(Inkscape::XML::Node *in_repr, ImplementationHolder implementation, std::string *base_directory)
Constructs an Extension from a Inkscape::XML::Node.
Definition: extension.cpp:66
std::vector< ProcessingAction > _actions
Processing actions.
Definition: extension.h:150
void set_base_directory(std::string const &base_directory)
Definition: extension.h:194
bool loaded()
A quick function to test the state of the extension.
Definition: extension.cpp:235
void set_execution_env(ExecutionEnv *env)
Definition: extension.h:191
Inkscape::XML::Node * get_repr()
A getter for the internal Repr, does not add a reference.
Definition: extension.cpp:306
std::string _base_directory
Directory containing the .inx file, relative paths in the extension should usually be relative to it.
Definition: extension.h:162
void set_sort_priority(int priority)
Definition: extension.h:201
char const * _translationdomain
Domainname of gettext textdomain that should be used for translation of the extension's strings.
Definition: extension.h:168
void set_environment(SPDocument const *doc=nullptr)
Sets environment suitable for executing this Extension.
Definition: extension.cpp:522
void printFailure(Glib::ustring const &reason)
A quick function to print out a standard start of extension errors in the log.
Definition: extension.cpp:295
char const * set_param_string(char const *name, char const *value)
Sets a parameter identified by name with the string in the parameter value.
Definition: extension.cpp:852
bool deactivated()
Find out the status of the extension.
Definition: extension.cpp:361
bool get_param_bool(char const *name) const
Gets a parameter identified by name with the bool placed in value.
Definition: extension.cpp:634
std::string _gettext_catalog_dir
Directory containing the gettext catalog for _translationdomain.
Definition: extension.h:170
virtual bool prefs()
Create a dialog for preference for this extension.
Definition: extension.cpp:1061
state_t _state
Which state the Extension is currently in.
Definition: extension.h:143
void lookup_translation_catalog()
Searches for a gettext catalog matching the extension's translationdomain.
Definition: extension.cpp:424
InxParameter * get_param(char const *name)
Looks up the parameter with the specified name.
Definition: extension.cpp:597
void set_param_any(char const *name, std::string const &value)
Parses the given string value and sets a parameter identified by name.
Definition: extension.cpp:896
static FILE * error_file
This is the place where errors get reported.
Definition: extension.h:146
Base class for all implementations of modules.
A class to represent the parameter of an extension.
Definition: parameter.h:34
NonOwningPtr get() const
Interface for refcounted XML nodes.
Definition: node.h:80
Typed SVG document implementation.
Definition: document.h:106
ModuleImpType
Definition: extension.h:85
@ MODULE_UNKNOWN_IMP
Definition: extension.h:89
@ MODULE_PLUGIN
Definition: extension.h:88
@ MODULE_EXTENSION
Definition: extension.h:86
@ MODULE_XSLT
Definition: extension.h:87
ModuleFuncType
Definition: extension.h:93
@ MODULE_UNKNOWN_FUNC
Definition: extension.h:100
@ MODULE_OUTPUT
Definition: extension.h:96
@ MODULE_FILTER
Definition: extension.h:97
@ MODULE_INPUT
Definition: extension.h:95
@ MODULE_PATH_EFFECT
Definition: extension.h:99
@ MODULE_PRINT
Definition: extension.h:98
@ MODULE_TEMPLATE
Definition: extension.h:94
A helper variant type wrapping either an owning pointer (std::unique_ptr) or a non-owning,...
Inkscape::XML::Node * node
Definition: imagemagick.cpp:39
Definition: desktop.h:51
CMYK to sRGB conversion routines.