X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fgraphics%2FGraphicsConverter.C;h=5d08e460d56f8b9e80b52ab1d45fbc22cc2376e5;hb=f643df79a890ec4bc2eb05a3fd3d349ba3994f96;hp=841d6d189103cc3c168dad0922c921125eeca2bc;hpb=888532c465863dc2e1591524bc0815e029c6b99a;p=lyx.git diff --git a/src/graphics/GraphicsConverter.C b/src/graphics/GraphicsConverter.C index 841d6d1891..5d08e460d5 100644 --- a/src/graphics/GraphicsConverter.C +++ b/src/graphics/GraphicsConverter.C @@ -3,7 +3,7 @@ * Copyright 2002 the LyX Team * Read the file COPYING * - * \author Angus Leeming + * \author Angus Leeming */ #include @@ -28,14 +28,15 @@ #include #include // needed for pid_t +extern string system_lyxdir; + using std::endl; namespace grfx { struct Converter::Impl : public boost::signals::trackable { /// - Impl(Converter &, - string const &, string const &, string const &, string const &); + Impl(string const &, string const &, string const &, string const &); /// void startConversion(); @@ -47,6 +48,13 @@ struct Converter::Impl : public boost::signals::trackable { */ void converted(string const & cmd, pid_t pid, int retval); + /** At the end of the conversion process inform the outside world + * by emitting a signal. + */ + typedef boost::signal1 SignalType; + /// + SignalType finishedConversion; + /// string script_command_; /// @@ -54,35 +62,38 @@ struct Converter::Impl : public boost::signals::trackable { /// string to_file_; /// - Converter & parent_; - /// bool valid_process_; /// bool finished_; }; +bool Converter::isReachable(string const & from_format_name, + string const & to_format_name) +{ + return converters.isReachable(from_format_name, to_format_name); +} + + Converter::Converter(string const & from_file, string const & to_file_base, string const & from_format, string const & to_format) - : pimpl_(new Impl(*this, - from_file, to_file_base, from_format, to_format)) + : pimpl_(new Impl(from_file, to_file_base, from_format, to_format)) {} Converter::~Converter() {} - -void Converter::startConversion() + +void Converter::startConversion() const { pimpl_->startConversion(); } -bool Converter::isReachable(string const & from_format_name, - string const & to_format_name) +boost::signals::connection Converter::connect(slot_type const & slot) const { - return converters.isReachable(from_format_name, to_format_name); + return pimpl_->finishedConversion.connect(slot); } @@ -91,7 +102,7 @@ string const & Converter::convertedFile() const static string const empty; return pimpl_->finished_ ? pimpl_->to_file_ : empty; } - + } // namespace grfx //------------------------------ @@ -112,10 +123,9 @@ bool build_script(string const & from_file, string const & to_file_base, namespace grfx { -Converter::Impl::Impl(Converter & p, - string const & from_file, string const & to_file_base, +Converter::Impl::Impl(string const & from_file, string const & to_file_base, string const & from_format, string const & to_format) - : parent_(p), valid_process_(false), finished_(false) + : valid_process_(false), finished_(false) { lyxerr[Debug::GRAPHICS] << "Converter c-tor:\n" << "\tfrom_file: " << from_file @@ -134,7 +144,7 @@ Converter::Impl::Impl(Converter & p, lyxerr[Debug::GRAPHICS] << "\tConversion script:" << "\n--------------------------------------\n" - << script.str().c_str() + << script.str().c_str() << "\n--------------------------------------\n"; // Output the script to file. @@ -150,7 +160,9 @@ Converter::Impl::Impl(Converter & p, fs.close(); // The converted image is to be stored in this file - to_file_ = ChangeExtension(to_file_base, formats.extension(to_format)); + // We do not use ChangeExtension here because this is a + // basename, which may nevertheless contain a dot + to_file_ = to_file_base + '.' + formats.extension(to_format); // The command needed to run the conversion process // We create a dummy command for ease of understanding of the @@ -170,7 +182,7 @@ void Converter::Impl::startConversion() converted(string(), 0, 1); return; } - + // Initiate the conversion Forkedcall::SignalTypePtr convert_ptr; convert_ptr.reset(new Forkedcall::SignalType); @@ -201,9 +213,9 @@ void Converter::Impl::converted(string const & /* cmd */, if (retval > 0) { lyx::unlink(to_file_); to_file_.erase(); - parent_.finishedConversion(false); + finishedConversion(false); } else { - parent_.finishedConversion(true); + finishedConversion(true); } } @@ -270,9 +282,11 @@ bool build_script(string const & from_file, string const token_from("$$i"); string const token_base("$$b"); string const token_to("$$o"); + string const token_lib("$$s"); EdgePath::const_iterator it = edgepath.begin(); EdgePath::const_iterator end = edgepath.end(); + for (; it != end; ++it) { ::Converter const & conv = converters.get(*it); @@ -290,6 +304,7 @@ bool build_script(string const & from_file, command = subst(command, token_from, "${infile}"); command = subst(command, token_base, "${infile_base}"); command = subst(command, token_to, "${outfile}"); + command = subst(command, token_lib, system_lyxdir + "scripts"); // Store in the shell script script << "\n" << command << "\n\n"; @@ -327,5 +342,5 @@ bool build_script(string const & from_file, return true; } - + } // namespace anon