* Copyright 2002 the LyX Team
* Read the file COPYING
*
- * \author Angus Leeming <a.leeming@ic.ac.uk>
+ * \author Angus Leeming <leeming@lyx.org>
*/
#include <config.h>
#include <fstream>
#include <sys/types.h> // 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();
*/
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<void, bool> SignalType;
+ ///
+ SignalType finishedConversion;
+
///
string script_command_;
///
///
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);
}
static string const empty;
return pimpl_->finished_ ? pimpl_->to_file_ : empty;
}
-
+
} // namespace grfx
//------------------------------
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
lyxerr[Debug::GRAPHICS] << "\tConversion script:"
<< "\n--------------------------------------\n"
- << script.str().c_str()
+ << script.str().c_str()
<< "\n--------------------------------------\n";
// Output the script to file.
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
converted(string(), 0, 1);
return;
}
-
+
// Initiate the conversion
Forkedcall::SignalTypePtr convert_ptr;
convert_ptr.reset(new Forkedcall::SignalType);
if (retval > 0) {
lyx::unlink(to_file_);
to_file_.erase();
- parent_.finishedConversion(false);
+ finishedConversion(false);
} else {
- parent_.finishedConversion(true);
+ finishedConversion(true);
}
}
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);
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";
return true;
}
-
+
} // namespace anon