diff options
| author | Richard White <rwhite8282@gmail.com> | 2016-05-19 01:17:29 +0000 |
|---|---|---|
| committer | Richard White <rwhite8282@gmail.com> | 2016-05-19 01:17:29 +0000 |
| commit | 1fe9c2603c33fddcd9f2688b30e843f91e1a86fa (patch) | |
| tree | 13289cbe033a46a40eb829437e115b5393e2ca84 /src/extension/implementation/script.cpp | |
| parent | Corrected frame extension stroke and fill values on 64 bit machine. (diff) | |
| parent | GTK3: Another widget named. (diff) | |
| download | inkscape-1fe9c2603c33fddcd9f2688b30e843f91e1a86fa.tar.gz inkscape-1fe9c2603c33fddcd9f2688b30e843f91e1a86fa.zip | |
Merge from Inkscape trunk.
(bzr r14668.1.3)
Diffstat (limited to 'src/extension/implementation/script.cpp')
| -rw-r--r-- | src/extension/implementation/script.cpp | 62 |
1 files changed, 48 insertions, 14 deletions
diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index 4cb0c9b73..9aaf4b952 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -152,7 +152,7 @@ Script::Script() : } /** - * brief Destructor + * \brief Destructor */ Script::~Script() { @@ -232,11 +232,7 @@ bool Script::check_existence(const std::string &command) //Don't search when it is an absolute path. */ if (Glib::path_is_absolute(command)) { - if (Glib::file_test(command, Glib::FILE_TEST_EXISTS)) { - return true; - } else { - return false; - } + return Glib::file_test(command, Glib::FILE_TEST_EXISTS); } // First search in the current directory @@ -280,9 +276,9 @@ bool Script::check_existence(const std::string &command) /** \return none - \brief This function 'loads' an extention, basically it determines - the full command for the extention and stores that. - \param module The extention to be loaded. + \brief This function 'loads' an extension, basically it determines + the full command for the extension and stores that. + \param module The extension to be loaded. The most difficult part about this function is finding the actual command through all of the Reprs. Basically it is hidden down a @@ -292,7 +288,7 @@ bool Script::check_existence(const std::string &command) At that point all of the loops are exited, and there is an if statement to make sure they didn't exit because of not finding - the command. If that's the case, the extention doesn't get loaded + the command. If that's the case, the extension doesn't get loaded and should error out at a higher level. */ @@ -545,17 +541,17 @@ SPDocument *Script::open(Inkscape::Extension::Input *module, /** \return none - \brief This function uses an extention to save a document. It first + \brief This function uses an extension to save a document. It first creates an SVG file of the document, and then runs it through the script. - \param module Extention to be used + \param module Extension to be used \param doc Document to be saved \param filename The name to save the final file as \return false in case of any failure writing the file, otherwise true Well, at some point people need to save - it is really what makes the entire application useful. And, it is possible that someone - would want to use an extetion for this, so we need a function to + would want to use an extension for this, so we need a function to do that eh? First things first, the document is saved to a temporary file that @@ -563,7 +559,7 @@ SPDocument *Script::open(Inkscape::Extension::Input *module, ink_ext_ as a prefix. Don't worry, this file gets deleted at the end of the function. - After we have the SVG file, then extention_execute is called with + After we have the SVG file, then Script::execute is called with the temporary file name and the final output filename. This should put the output of the script into the final output file. We then delete the temporary file. @@ -1123,7 +1119,45 @@ int Script::execute (const std::list<std::string> &in_command, } +void Script::file_listener::init(int fd, Glib::RefPtr<Glib::MainLoop> main) { + _channel = Glib::IOChannel::create_from_fd(fd); + _channel->set_encoding(); + _conn = main->get_context()->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 Script::file_listener::read(Glib::IOCondition condition) { + if (condition != Glib::IO_IN) { + _main_loop->quit(); + return false; + } + + Glib::IOStatus status; + Glib::ustring out; + status = _channel->read_line(out); + _string += out; + + if (status != Glib::IO_STATUS_NORMAL) { + _main_loop->quit(); + _dead = true; + return false; + } + + return true; +} + +bool Script::file_listener::toFile(const Glib::ustring &name) { + try { + Glib::RefPtr<Glib::IOChannel> stdout_file = Glib::IOChannel::create_from_file(name, "w"); + stdout_file->set_encoding(); + stdout_file->write(_string); + } catch (Glib::FileError &e) { + return false; + } + return true; +} } // namespace Implementation } // namespace Extension |
