X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fgraphics%2FGraphicsConverter.cpp;h=c97e76663d3b1d746a37e07627d587b18d196341;hb=e0e548217eb7b3c8728a1af17aa42be496b91281;hp=3201d5d06a05756bd633919aca5fd6dca9814e13;hpb=c86f299a50e33eddf0b013547bc48cfc62c8a715;p=lyx.git diff --git a/src/graphics/GraphicsConverter.cpp b/src/graphics/GraphicsConverter.cpp index 3201d5d06a..c97e76663d 100644 --- a/src/graphics/GraphicsConverter.cpp +++ b/src/graphics/GraphicsConverter.cpp @@ -22,9 +22,7 @@ #include "support/filetools.h" #include "support/ForkedCalls.h" #include "support/lstrings.h" -#include "support/os.h" -#include "support/bind.h" #include "support/TempFile.h" #include @@ -37,10 +35,12 @@ namespace lyx { namespace graphics { -class Converter::Impl : public boost::signals::trackable { +class Converter::Impl { public: /// - Impl(FileName const &, string const &, string const &, string const &); + Impl(Converter const & parent, FileName const & doc_fname, + FileName const & from_file, string const & to_file_base, + string const & from_format, string const & to_format); /// void startConversion(); @@ -55,10 +55,14 @@ public: /** At the end of the conversion process inform the outside world * by emitting a signal. */ - typedef boost::signal SignalType; + typedef signal sig; /// - SignalType finishedConversion; + sig finishedConversion; + /// + Converter const & parent_; + /// + FileName const doc_fname_; /// string script_command_; /// @@ -79,25 +83,20 @@ bool Converter::isReachable(string const & from_format_name, } -Converter::Converter(FileName const & from_file, string const & to_file_base, - string const & from_format, string const & to_format) - : pimpl_(new Impl(from_file, to_file_base, from_format, to_format)) +Converter::Converter(FileName const & doc_fname, + FileName const & from_file, string const & to_file_base, + string const & from_format, string const & to_format) + : pimpl_(make_shared(*this, doc_fname, from_file, to_file_base, from_format, to_format)) {} -Converter::~Converter() -{ - delete pimpl_; -} - - void Converter::startConversion() const { pimpl_->startConversion(); } -boost::signals::connection Converter::connect(slot_type const & slot) const +connection Converter::connect(slot_type const & slot) const { return pimpl_->finishedConversion.connect(slot); } @@ -112,17 +111,20 @@ FileName const & Converter::convertedFile() const /** Build the conversion script. * The script is output to the stream \p script. */ -static void build_script(string const & from_file, string const & to_file_base, +static void build_script(string const & doc_fname, + string const & from_file, string const & to_file_base, string const & from_format, string const & to_format, ostream & script); -Converter::Impl::Impl(FileName const & from_file, string const & to_file_base, +Converter::Impl::Impl(Converter const & parent, FileName const & doc_fname, + FileName const & from_file, string const & to_file_base, string const & from_format, string const & to_format) - : valid_process_(false), finished_(false) + : parent_(parent), doc_fname_(doc_fname), valid_process_(false), finished_(false) { LYXERR(Debug::GRAPHICS, "Converter c-tor:\n" - << "\tfrom_file: " << from_file + << "doc_fname: " << doc_fname + << "\n\tfrom_file: " << from_file << "\n\tto_file_base: " << to_file_base << "\n\tfrom_format: " << from_format << "\n\tto_format: " << to_format); @@ -130,11 +132,11 @@ Converter::Impl::Impl(FileName const & from_file, string const & to_file_base, // The converted image is to be stored in this file (we do not // use ChangeExtension because this is a basename which may // nevertheless contain a '.') - to_file_ = FileName(to_file_base + '.' + formats.extension(to_format)); + to_file_ = FileName(to_file_base + '.' + theFormats().extension(to_format)); // The conversion commands are stored in a stringstream ostringstream script; - build_script(from_file.toFilesystemEncoding(), + build_script(doc_fname_.absFileName(), from_file.toFilesystemEncoding(), to_file_.toFilesystemEncoding(), from_format, to_format, script); LYXERR(Debug::GRAPHICS, "\tConversion script:" @@ -179,9 +181,13 @@ void Converter::Impl::startConversion() return; } - ForkedCall::SignalTypePtr ptr = - ForkedCallQueue::add(script_command_); - ptr->connect(bind(&Impl::converted, this, _1, _2)); + ForkedCall::sigPtr ptr = ForkedCallQueue::add(script_command_); + weak_ptr this_ = parent_.pimpl_; + ptr->connect([this_](pid_t pid, int retval){ + if (auto p = this_.lock()) { + p->converted(pid, retval); + } + }); } @@ -229,7 +235,7 @@ static string const move_file(string const & from_file, string const & to_file) static void build_conversion_command(string const & command, ostream & script) { // Store in the python script - script << "\nif os.system(r'" << command << "') != 0:\n"; + script << "\nif os.system(r'" << commandPrep(command) << "') != 0:\n"; // Test that this was successful. If not, remove // ${outfile} and exit the python script @@ -263,7 +269,8 @@ static string const strip_digit(string const & format) } -static void build_script(string const & from_file, +static void build_script(string const & doc_fname, + string const & from_file, string const & to_file, string const & from_format, string const & to_format, @@ -273,8 +280,7 @@ static void build_script(string const & from_file, LYXERR(Debug::GRAPHICS, "build_script ... "); typedef Graph::EdgePath EdgePath; - script << "#!/usr/bin/env python\n" - "# -*- coding: utf-8 -*-\n" + script << "# -*- coding: utf-8 -*-\n" "import os, shutil, sys\n\n" "def unlinkNoThrow(file):\n" " ''' remove a file, do not throw if an error occurs '''\n" @@ -324,13 +330,15 @@ static void build_script(string const & from_file, ostringstream os; os << os::python() << ' ' << commandPrep("$$s/scripts/convertDefault.py") << ' '; - if (!from_format.empty()) - os << strip_digit(from_format) << ':'; + if (from_format.empty()) + os << "unknown "; + else + os << strip_digit(from_format) << ' '; // The extra " quotes around infile and outfile are needed // because the filename may contain spaces and it is used // as argument of os.system(). os << "' + '\"' + infile + '\"' + ' " - << strip_digit(to_format) << ":' + '\"' + outfile + '\"' + '"; + << strip_digit(to_format) << " ' + '\"' + outfile + '\"' + '"; string const command = os.str(); LYXERR(Debug::GRAPHICS, @@ -365,11 +373,14 @@ static void build_script(string const & from_file, // If two formats share the same extension we may get identical names if (outfile == infile && conv.result_file().empty()) { - TempFile tempfile(addExtension("gconvertXXXXXX", conv.To()->extension())); - tempfile.setAutoRemove(false); - outfile = tempfile.name().toFilesystemEncoding(); + TempFile tmpfile(addExtension("gconvertXXXXXX", conv.To()->extension())); + tmpfile.setAutoRemove(false); + outfile = tmpfile.name().toFilesystemEncoding(); } + if (!theConverters().checkAuth(conv, doc_fname)) + return; + // Store these names in the python script script << "infile = " << quoteName(infile, quote_python) << "\n"