]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/GraphicsConverter.C
* Make the graphics files conform strictly to the Pimpl idiom by moving
[lyx.git] / src / graphics / GraphicsConverter.C
index 1182811e4ddd65820701f11c2e0d7ee73314e90c..5d08e460d56f8b9e80b52ab1d45fbc22cc2376e5 100644 (file)
 #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();
@@ -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<void, bool> 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.
@@ -172,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);
@@ -203,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);
        }
 }
 
@@ -272,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);
 
@@ -292,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";
@@ -329,5 +342,5 @@ bool build_script(string const & from_file,
 
        return true;
 }
+
 } // namespace anon