2
* Code for handling extensions (i.e., scripts)
5
* Bryce Harrington <bryce@osdl.org>
6
* Ted Gould <ted@gould.cx>
8
* Copyright (C) 2002-2005 Authors
10
* Released under GNU GPL, read the file 'COPYING' for more information
13
#ifndef __INKSCAPE_EXTENSION_IMPEMENTATION_SCRIPT_H__
14
#define __INKSCAPE_EXTENSION_IMPEMENTATION_SCRIPT_H__
16
#include "implementation.h"
17
#include <gtkmm/messagedialog.h>
28
namespace Implementation {
33
* Utility class used for loading and launching script extensions
35
class Script : public Implementation {
53
virtual bool load(Inkscape::Extension::Extension *module);
58
virtual void unload(Inkscape::Extension::Extension *module);
63
virtual bool check(Inkscape::Extension::Extension *module);
65
ImplementationDocumentCache * newDocCache (Inkscape::Extension::Extension * ext, Inkscape::UI::View::View * view);
70
virtual Gtk::Widget *prefs_input(Inkscape::Extension::Input *module,
71
gchar const *filename);
76
virtual SPDocument *open(Inkscape::Extension::Input *module,
77
gchar const *filename);
82
virtual Gtk::Widget *prefs_output(Inkscape::Extension::Output *module);
87
virtual void save(Inkscape::Extension::Output *module,
89
gchar const *filename);
94
virtual void effect(Inkscape::Extension::Effect *module,
95
Inkscape::UI::View::View *doc,
96
ImplementationDocumentCache * docCache);
98
virtual bool cancelProcessing (void);
103
Glib::RefPtr<Glib::MainLoop> _main_loop;
106
* The command that has been dirived from
107
* the configuration file with appropriate directories
109
std::list<std::string> command;
112
* This is the extension that will be used
113
* as the helper to read in or write out the
116
Glib::ustring helper_extension;
119
* Just a quick function to find and resolve relative paths for
120
* the incoming scripts
122
Glib::ustring solve_reldir (Inkscape::XML::Node *reprin);
127
bool check_existance (const Glib::ustring &command);
132
void copy_doc (Inkscape::XML::Node * olddoc,
133
Inkscape::XML::Node * newdoc);
138
void checkStderr (const Glib::ustring &filename,
139
Gtk::MessageType type,
140
const Glib::ustring &message);
143
class file_listener {
144
Glib::ustring _string;
145
sigc::connection _conn;
146
Glib::RefPtr<Glib::IOChannel> _channel;
147
Glib::RefPtr<Glib::MainLoop> _main_loop;
151
file_listener () : _dead(false) { };
152
virtual ~file_listener () {
156
bool isDead () { return _dead; }
158
void init (int fd, Glib::RefPtr<Glib::MainLoop> main) {
159
_channel = Glib::IOChannel::create_from_fd(fd);
160
_channel->set_encoding();
161
_conn = Glib::signal_io().connect(sigc::mem_fun(*this, &file_listener::read), _channel, Glib::IO_IN | Glib::IO_HUP | Glib::IO_ERR);
167
bool read (Glib::IOCondition condition) {
168
if (condition != Glib::IO_IN) {
173
Glib::IOStatus status;
175
status = _channel->read_line(out);
178
if (status != Glib::IO_STATUS_NORMAL) {
187
// Note, doing a copy here, on purpose
188
Glib::ustring string (void) { return _string; };
190
void toFile (const Glib::ustring &name) {
191
Glib::RefPtr<Glib::IOChannel> stdout_file = Glib::IOChannel::create_from_file(name, "w");
192
stdout_file->set_encoding();
193
stdout_file->write(_string);
198
int execute (const std::list<std::string> &in_command,
199
const std::list<std::string> &in_params,
200
const Glib::ustring &filein,
201
file_listener &fileout);
203
void pump_events (void);
205
/** \brief A definition of an interpreter, which can be specified
206
in the INX file, but we need to know what to call */
207
struct interpreter_t {
208
gchar const *identity; /**< The ID that is in the INX file */
209
gchar const *prefstring; /**< The preferences key that can override the default */
210
gchar const *defaultval; /**< The default value if there are no preferences */
212
static interpreter_t const interpreterTab[];
214
Glib::ustring resolveInterpreterExecutable(const Glib::ustring &interpNameArg);
222
} // namespace Implementation
223
} // namespace Extension
224
} // namespace Inkscape
226
#endif /* __INKSCAPE_EXTENSION_IMPEMENTATION_SCRIPT_H__ */
231
c-file-style:"stroustrup"
232
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
237
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :