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);
95 /**
96 *
97 */
98 virtual void effect(Inkscape::Extension::Effect *module,
99 Inkscape::UI::View::View *doc);
101 virtual bool cancelProcessing (void);
103 private:
104 bool _canceled;
105 Glib::Pid _pid;
106 Glib::RefPtr<Glib::MainLoop> _main_loop;
108 /**
109 * The command that has been dirived from
110 * the configuration file with appropriate directories
111 */
112 std::list<std::string> command;
114 /**
115 * This is the extension that will be used
116 * as the helper to read in or write out the
117 * data
118 */
119 Glib::ustring helper_extension;
121 /**
122 * Just a quick function to find and resolve relative paths for
123 * the incoming scripts
124 */
125 Glib::ustring solve_reldir (Inkscape::XML::Node *reprin);
127 /**
128 *
129 */
130 bool check_existance (const Glib::ustring &command);
132 /**
133 *
134 */
135 void copy_doc (Inkscape::XML::Node * olddoc,
136 Inkscape::XML::Node * newdoc);
138 /**
139 *
140 */
141 void checkStderr (const Glib::ustring &filename,
142 Gtk::MessageType type,
143 const Glib::ustring &message);
146 class file_listener {
147 Glib::ustring _string;
148 sigc::connection _conn;
149 Glib::RefPtr<Glib::IOChannel> _channel;
150 Glib::RefPtr<Glib::MainLoop> _main_loop;
151 bool _dead;
153 public:
154 file_listener () : _dead(false) { };
155 ~file_listener () {
156 _conn.disconnect();
157 };
159 bool isDead () { return _dead; }
161 void init (int fd, Glib::RefPtr<Glib::MainLoop> main) {
162 _channel = Glib::IOChannel::create_from_fd(fd);
163 _channel->set_encoding();
164 _conn = Glib::signal_io().connect(sigc::mem_fun(*this, &file_listener::read), _channel, Glib::IO_IN | Glib::IO_HUP | Glib::IO_ERR);
165 _main_loop = main;
167 return;
168 };
170 bool read (Glib::IOCondition condition) {
171 if (condition != Glib::IO_IN) {
172 _main_loop->quit();
173 return false;
174 }
176 Glib::IOStatus status;
177 Glib::ustring out;
178 status = _channel->read_line(out);
179 _string += out;
181 if (status != Glib::IO_STATUS_NORMAL) {
182 _main_loop->quit();
183 _dead = true;
184 return false;
185 }
187 return true;
188 };
190 // Note, doing a copy here, on purpose
191 Glib::ustring string (void) { return _string; };
193 void toFile (const Glib::ustring &name) {
194 Glib::RefPtr<Glib::IOChannel> stdout_file = Glib::IOChannel::create_from_file(name, "w");
195 stdout_file->write(_string);
196 return;
197 };
198 };
200 int execute (const std::list<std::string> &in_command,
201 const std::list<std::string> &in_params,
202 const Glib::ustring &filein,
203 file_listener &fileout);
204 }; // class Script
210 } // namespace Implementation
211 } // namespace Extension
212 } // namespace Inkscape
214 #endif /* __INKSCAPE_EXTENSION_IMPEMENTATION_SCRIPT_H__ */
216 /*
217 Local Variables:
218 mode:c++
219 c-file-style:"stroustrup"
220 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
221 indent-tabs-mode:nil
222 fill-column:99
223 End:
224 */
225 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :