1 /*
2 * Code for handling extensions (i.e., scripts)
3 *
4 * Authors:
5 * Bryce Harrington <bryce@osdl.org>
6 * Ted Gould <ted@gould.cx>
7 *
8 * Copyright (C) 2002-2005 Authors
9 *
10 * Released under GNU GPL, read the file 'COPYING' for more information
11 */
13 #ifndef __INKSCAPE_EXTENSION_IMPEMENTATION_SCRIPT_H__
14 #define __INKSCAPE_EXTENSION_IMPEMENTATION_SCRIPT_H__
16 #include "implementation.h"
17 #include <gtkmm/messagedialog.h>
19 namespace Inkscape {
20 namespace XML {
21 class Node;
22 }
23 }
26 namespace Inkscape {
27 namespace Extension {
28 namespace Implementation {
32 /**
33 * Utility class used for loading and launching script extensions
34 */
35 class Script : public Implementation {
37 public:
39 /**
40 *
41 */
42 Script(void);
44 /**
45 *
46 */
47 virtual ~Script();
50 /**
51 *
52 */
53 virtual bool load(Inkscape::Extension::Extension *module);
55 /**
56 *
57 */
58 virtual void unload(Inkscape::Extension::Extension *module);
60 /**
61 *
62 */
63 virtual bool check(Inkscape::Extension::Extension *module);
65 /**
66 *
67 */
68 virtual Gtk::Widget *prefs_input(Inkscape::Extension::Input *module,
69 gchar const *filename);
71 /**
72 *
73 */
74 virtual SPDocument *open(Inkscape::Extension::Input *module,
75 gchar const *filename);
77 /**
78 *
79 */
80 virtual Gtk::Widget *prefs_output(Inkscape::Extension::Output *module);
82 /**
83 *
84 */
85 virtual void save(Inkscape::Extension::Output *module,
86 SPDocument *doc,
87 gchar const *filename);
88 /**
89 *
90 */
91 virtual Gtk::Widget *prefs_effect(Inkscape::Extension::Effect *module,
92 Inkscape::UI::View::View * view,
93 sigc::signal<void> * changeSignal,
94 ImplementationDocumentCache * docCache);
96 /**
97 *
98 */
99 virtual void effect(Inkscape::Extension::Effect *module,
100 Inkscape::UI::View::View *doc,
101 ImplementationDocumentCache * docCache);
103 virtual bool cancelProcessing (void);
105 private:
106 bool _canceled;
107 Glib::Pid _pid;
108 Glib::RefPtr<Glib::MainLoop> _main_loop;
110 /**
111 * The command that has been dirived from
112 * the configuration file with appropriate directories
113 */
114 std::list<std::string> command;
116 /**
117 * This is the extension that will be used
118 * as the helper to read in or write out the
119 * data
120 */
121 Glib::ustring helper_extension;
123 /**
124 * Just a quick function to find and resolve relative paths for
125 * the incoming scripts
126 */
127 Glib::ustring solve_reldir (Inkscape::XML::Node *reprin);
129 /**
130 *
131 */
132 bool check_existance (const Glib::ustring &command);
134 /**
135 *
136 */
137 void copy_doc (Inkscape::XML::Node * olddoc,
138 Inkscape::XML::Node * newdoc);
140 /**
141 *
142 */
143 void checkStderr (const Glib::ustring &filename,
144 Gtk::MessageType type,
145 const Glib::ustring &message);
148 class file_listener {
149 Glib::ustring _string;
150 sigc::connection _conn;
151 Glib::RefPtr<Glib::IOChannel> _channel;
152 Glib::RefPtr<Glib::MainLoop> _main_loop;
153 bool _dead;
155 public:
156 file_listener () : _dead(false) { };
157 ~file_listener () {
158 _conn.disconnect();
159 };
161 bool isDead () { return _dead; }
163 void init (int fd, Glib::RefPtr<Glib::MainLoop> main) {
164 _channel = Glib::IOChannel::create_from_fd(fd);
165 _channel->set_encoding();
166 _conn = Glib::signal_io().connect(sigc::mem_fun(*this, &file_listener::read), _channel, Glib::IO_IN | Glib::IO_HUP | Glib::IO_ERR);
167 _main_loop = main;
169 return;
170 };
172 bool read (Glib::IOCondition condition) {
173 if (condition != Glib::IO_IN) {
174 _main_loop->quit();
175 return false;
176 }
178 Glib::IOStatus status;
179 Glib::ustring out;
180 status = _channel->read_line(out);
181 _string += out;
183 if (status != Glib::IO_STATUS_NORMAL) {
184 _main_loop->quit();
185 _dead = true;
186 return false;
187 }
189 return true;
190 };
192 // Note, doing a copy here, on purpose
193 Glib::ustring string (void) { return _string; };
195 void toFile (const Glib::ustring &name) {
196 Glib::RefPtr<Glib::IOChannel> stdout_file = Glib::IOChannel::create_from_file(name, "w");
197 stdout_file->write(_string);
198 return;
199 };
200 };
202 int execute (const std::list<std::string> &in_command,
203 const std::list<std::string> &in_params,
204 const Glib::ustring &filein,
205 file_listener &fileout);
206 }; // class Script
212 } // namespace Implementation
213 } // namespace Extension
214 } // namespace Inkscape
216 #endif /* __INKSCAPE_EXTENSION_IMPEMENTATION_SCRIPT_H__ */
218 /*
219 Local Variables:
220 mode:c++
221 c-file-style:"stroustrup"
222 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
223 indent-tabs-mode:nil
224 fill-column:99
225 End:
226 */
227 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :