summaryrefslogtreecommitdiffstats
path: root/src/extension/extension.h
blob: 7ac64a842110df0dc42bfc864e82d4ceee81b977 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef INK_EXTENSION_H
#define INK_EXTENSION_H

/** \file
 * Frontend to certain, possibly pluggable, actions.
 */

/*
 * Authors:
 *   Ted Gould <ted@gould.cx>
 *
 * Copyright (C) 2002-2005 Authors
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include <fstream>
#include <ostream>
#include <vector>

#include <glib.h>
#include <sigc++/signal.h>

namespace Glib {
    class ustring;
}

namespace Gtk {
	class Grid;
	class Box;
	class Widget;
}

/** The key that is used to identify that the I/O should be autodetected */
#define SP_MODULE_KEY_AUTODETECT "autodetect"
/** This is the key for the SVG input module */
#define SP_MODULE_KEY_INPUT_SVG "org.inkscape.input.svg"
#define SP_MODULE_KEY_INPUT_SVGZ "org.inkscape.input.svgz"
/** Specifies the input module that should be used if none are selected */
#define SP_MODULE_KEY_INPUT_DEFAULT SP_MODULE_KEY_AUTODETECT
/** The key for outputting standard W3C SVG */
#define SP_MODULE_KEY_OUTPUT_SVG "org.inkscape.output.svg.plain"
#define SP_MODULE_KEY_OUTPUT_SVGZ "org.inkscape.output.svgz.plain"
/** This is an output file that has SVG data with the Sodipodi namespace extensions */
#define SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE "org.inkscape.output.svg.inkscape"
#define SP_MODULE_KEY_OUTPUT_SVGZ_INKSCAPE "org.inkscape.output.svgz.inkscape"
/** Which output module should be used? */
#define SP_MODULE_KEY_OUTPUT_DEFAULT SP_MODULE_KEY_AUTODETECT

/** Internal raster extensions */
#define SP_MODULE_KEY_RASTER_PNG "org.inkscape.output.png.inkscape"

/** Defines the key for Postscript printing */
#define SP_MODULE_KEY_PRINT_PS    "org.inkscape.print.ps"
#define SP_MODULE_KEY_PRINT_CAIRO_PS    "org.inkscape.print.ps.cairo"
#define SP_MODULE_KEY_PRINT_CAIRO_EPS    "org.inkscape.print.eps.cairo"
/** Defines the key for PDF printing */
#define SP_MODULE_KEY_PRINT_PDF    "org.inkscape.print.pdf"
#define SP_MODULE_KEY_PRINT_CAIRO_PDF    "org.inkscape.print.pdf.cairo"
/** Defines the key for LaTeX printing */
#define SP_MODULE_KEY_PRINT_LATEX    "org.inkscape.print.latex"
/** Defines the key for printing with GNOME Print */
#define SP_MODULE_KEY_PRINT_GNOME "org.inkscape.print.gnome"

/** Mime type for SVG */
#define MIME_SVG "image/svg+xml"

/** Name of the extension error file */
#define EXTENSION_ERROR_LOG_FILENAME  "extension-errors.log"


#define INKSCAPE_EXTENSION_URI   "http://www.inkscape.org/namespace/inkscape/extension"
#define INKSCAPE_EXTENSION_NS_NC "extension"
#define INKSCAPE_EXTENSION_NS    "extension:"

enum ModuleImpType
{
    MODULE_EXTENSION,   // implementation/script.h python extensions
    MODULE_XSLT,        // implementation/xslt.h xml transform extensions
    MODULE_PLUGIN,      // plugins/*/*.h C++ extensions
    MODULE_UNKNOWN_IMP  // No implementation, so nothing created.
};
enum ModuleFuncType
{
    MODULE_INPUT,
    MODULE_OUTPUT,
    MODULE_FILTER,
    MODULE_PRINT,
    MODULE_PATH_EFFECT,
    MODULE_UNKNOWN_FUNC
};

class SPDocument;

namespace Inkscape {

namespace XML {
class Node;
}

namespace Extension {

class ExecutionEnv;
class Dependency;
class ExpirationTimer;
class ExpirationTimer;
class InxParameter;
class InxWidget;

namespace Implementation
{
class Implementation;
}


/** The object that is the basis for the Extension system.  This object
    contains all of the information that all Extension have.  The
    individual items are detailed within. This is the interface that
    those who want to _use_ the extensions system should use.  This
    is most likely to be those who are inside the Inkscape program. */
class Extension {
public:
    /** An enumeration to identify if the Extension has been loaded or not. */
    enum state_t {
        STATE_LOADED,      /**< The extension has been loaded successfully */
        STATE_UNLOADED,    /**< The extension has not been loaded */
        STATE_DEACTIVATED  /**< The extension is missing something which makes it unusable */
    };

private:
    gchar     *_id = nullptr;                  /**< The unique identifier for the Extension */
    gchar     *_name = nullptr;                /**< A user friendly name for the Extension */
    state_t    _state = STATE_UNLOADED;        /**< Which state the Extension is currently in */
    std::vector<Dependency *>  _deps;          /**< Dependencies for this extension */
    static FILE *error_file;                   /**< This is the place where errors get reported */
    bool _gui;
    std::string _error_reason;                 /**< Short, textual explanation for the latest error */

protected:
    Inkscape::XML::Node *repr;                 /**< The XML description of the Extension */
    Implementation::Implementation * imp;      /**< An object that holds all the functions for making this work */
    ExecutionEnv * execution_env;              /**< Execution environment of the extension
                                                 *  (currently only used by Effects) */
    std::string _base_directory;               /**< Directory containing the .inx file,
                                                 *  relative paths in the extension should usually be relative to it */
    ExpirationTimer * timer = nullptr;         /**< Timeout to unload after a given time */
    bool _translation_enabled = true;          /**< Attempt translation of strings provided by the extension? */

private:
    const char *_translationdomain = nullptr;  /**< Domainname of gettext textdomain that should
                                                 *  be used for translation of the extension's strings */
    std::string _gettext_catalog_dir;          /**< Directory containing the gettext catalog for _translationdomain */

    void lookup_translation_catalog();

public:
    Extension(Inkscape::XML::Node *in_repr, Implementation::Implementation *in_imp, std::string *base_directory);
    virtual ~Extension();

    void          set_state    (state_t in_state);
    state_t       get_state    ();
    bool          loaded       ();
    virtual bool  check        ();
    Inkscape::XML::Node *      get_repr     ();
    gchar *       get_id       () const;
    const gchar * get_name     () const;
    void          deactivate   ();
    bool          deactivated  ();
    void          printFailure (Glib::ustring reason);
    std::string const &getErrorReason() { return _error_reason; };
    Implementation::Implementation * get_imp () { return imp; };
    void          set_execution_env (ExecutionEnv * env) { execution_env = env; };
    ExecutionEnv *get_execution_env () { return execution_env; };
    std::string   get_base_directory() const { return _base_directory; };
    void          set_base_directory(std::string const &base_directory) { _base_directory = base_directory; };
    std::string   get_dependency_location(const char *name);
    const char   *get_translation(const char* msgid, const char *msgctxt=nullptr) const;
    void          set_environment(const SPDocument *doc=nullptr);
    ModuleImpType get_implementation_type();

/* Parameter Stuff */
private:
    std::vector<InxWidget *> _widgets; /**< A list of widgets for this extension. */

public:
    /** \brief  A function to get the number of visible parameters of the extension.
        \return The number of visible parameters. */
    unsigned int widget_visible_count ( );

public:
    /** An error class for when a parameter is looked for that just
     * simply doesn't exist */
    class param_not_exist {};

    /** no valid ID found while parsing XML representation */
    class extension_no_id{};

    /** no valid name found while parsing XML representation */
    class extension_no_name{};

    /** extension is not compatible with the current system and should not be loaded */
    class extension_not_compatible{};

    /** An error class for when a filename already exists, but the user
     * doesn't want to overwrite it */
    class no_overwrite {};

private:
    void             make_param       (Inkscape::XML::Node * paramrepr);

    /**
     * Looks up the parameter with the specified name.
     *
     * Searches the list of parameters attached to this extension,
     * looking for a parameter with a matching name.
     *
     * This function can throw a 'param_not_exist' exception if the
     * name is not found.
     *
     * @param  name Name of the parameter to search for.
     * @return Parameter with matching name.
     */
     InxParameter *get_param(const gchar *name);

     InxParameter const *get_param(const gchar *name) const;

public:
    bool        get_param_bool          (const gchar *name) const;
    bool        get_param_bool          (const gchar *name, bool alt) const;
    int         get_param_int           (const gchar *name) const;
    int         get_param_int           (const gchar *name, int alt) const;
    double      get_param_float         (const gchar *name) const;
    double      get_param_float         (const gchar *name, double alt) const;
    const char *get_param_string        (const gchar *name, const char *alt) const;
    const char *get_param_string        (const gchar *name) const;
    const char *get_param_optiongroup   (const gchar *name, const char *alt) const;
    const char *get_param_optiongroup   (const gchar *name) const;
    guint32     get_param_color         (const gchar *name) const;

    bool get_param_optiongroup_contains (const gchar *name, const char   *value) const;

    bool        set_param_bool          (const gchar *name, const bool    value);
    int         set_param_int           (const gchar *name, const int     value);
    double      set_param_float         (const gchar *name, const double  value);
    const char *set_param_string        (const gchar *name, const char   *value);
    const char *set_param_optiongroup   (const gchar *name, const char   *value);
    guint32     set_param_color         (const gchar *name, const guint32 color);


    /* Error file handling */
public:
    static void      error_file_open  ();
    static void      error_file_close ();
    static void      error_file_write (Glib::ustring text);

public:
    Gtk::Widget *autogui (SPDocument *doc, Inkscape::XML::Node *node, sigc::signal<void> *changeSignal = nullptr);
    void paramListString(std::list <std::string> &retlist);
    void set_gui(bool s) { _gui = s; }
    bool get_gui() { return _gui; }

    /* Extension editor dialog stuff */
public:
    Gtk::Box *get_info_widget();
    Gtk::Box *get_params_widget();
protected:
    inline static void add_val(Glib::ustring labelstr, Glib::ustring valuestr, Gtk::Grid * table, int * row);
};



/*

This is a prototype for how collections should work.  Whoever gets
around to implementing this gets to decide what a 'folder' and an
'item' really is.  That is the joy of implementing it, eh?

class Collection : public Extension {

public:
    folder  get_root (void);
    int     get_count (folder);
    thumbnail get_thumbnail(item);
    item[]  get_items(folder);
    folder[]  get_folders(folder);
    metadata get_metadata(item);
    image   get_image(item);

};
*/

}  /* namespace Extension */
}  /* namespace Inkscape */

#endif // INK_EXTENSION_H

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :