From e71478581aea72707723c8559aaa540a16329a07 Mon Sep 17 00:00:00 2001 From: gouldtj Date: Wed, 27 Jun 2007 06:24:50 +0000 Subject: [PATCH] r15432@tres: ted | 2007-05-12 21:24:09 -0700 Cleaning up so that canceling works. --- src/extension/implementation/script.h | 59 ++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/src/extension/implementation/script.h b/src/extension/implementation/script.h index 0e9708926..bac1f7ccb 100644 --- a/src/extension/implementation/script.h +++ b/src/extension/implementation/script.h @@ -97,9 +97,12 @@ public: virtual void effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View *doc); - + virtual bool cancelProcessing (void); private: + bool _canceled; + Glib::Pid _pid; + Glib::RefPtr _main_loop; /** * The command that has been dirived from @@ -139,6 +142,60 @@ private: const Glib::ustring &message); + class file_listener { + Glib::ustring _string; + sigc::connection _conn; + Glib::RefPtr _channel; + Glib::RefPtr _main_loop; + + public: + file_listener () { }; + ~file_listener () { + _conn.disconnect(); + }; + + void init (int fd, Glib::RefPtr main) { + _channel = Glib::IOChannel::create_from_fd(fd); + _channel->set_encoding(); + _conn = Glib::signal_io().connect(sigc::mem_fun(*this, &file_listener::read), _channel, Glib::IO_IN | Glib::IO_HUP | Glib::IO_ERR); + _main_loop = main; + + return; + }; + + bool read (Glib::IOCondition condition) { + if (condition != Glib::IO_IN) { + _main_loop->quit(); + return false; + } + + Glib::IOStatus status; + Glib::ustring out; + status = _channel->read_to_end(out); + + if (status != Glib::IO_STATUS_NORMAL) { + _main_loop->quit(); + return false; + } + + _string += out; + return true; + }; + + // Note, doing a copy here, on purpose + Glib::ustring string (void) { return _string; }; + + void toFile (const Glib::ustring &name) { + Glib::RefPtr stdout_file = Glib::IOChannel::create_from_file(name, "w"); + stdout_file->write(_string); + return; + }; + }; + + int execute (const std::list &in_command, + const std::list &in_params, + const Glib::ustring &filein, + file_listener &fileout); }; // class Script -- 2.30.2