X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fgraphics%2FGraphicsConverter.h;h=c038029bd8f99b61559fbfc7b0447e4aab4d9cb0;hb=1b508fff0332e514847ba87efbc2e1e0d981daa1;hp=4cf51573866813d84270ea19395b8c0c0a1375d4;hpb=1e394731004491d04abe436112b5a89521bbd19a;p=lyx.git diff --git a/src/graphics/GraphicsConverter.h b/src/graphics/GraphicsConverter.h index 4cf5157386..c038029bd8 100644 --- a/src/graphics/GraphicsConverter.h +++ b/src/graphics/GraphicsConverter.h @@ -1,127 +1,79 @@ // -*- C++ -*- -/* +/** * \file GraphicsConverter.h - * Copyright 2002 the LyX Team - * Read the file COPYING + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * \author Angus Leeming + * \author Angus Leeming * - * class grfx::GConverter enables graphics files to be converted asynchronously - * to a loadable format. It does this by building a shell script of all - * the conversion commands needed for the transformation. This script is then - * sent to the forked calls controller for non-blocking execution. When it - * is finished a signal is emitted, thus informing us to proceed with the - * loading of the image. + * Full author contact details are available in file CREDITS. * - * Ultimately, this class should be wrapped back into Dekel's converter class. + * The controller of a conversion process from file AA of format A to + * file BB of format B. + * Once finished, a signal is emitted to inform any listeners (connected + * through the connect() method). */ #ifndef GRAPHICSCONVERTER_H #define GRAPHICSCONVERTER_H -#include "LString.h" -#include "Lsstream.h" +#include "support/signals.h" -#include -#include -#include -#include +namespace lyx { -#include +namespace support { class FileName; } -#include // needed for pid_t +namespace graphics { -#ifdef __GNUG__ -#pragma interface -#endif - -namespace grfx { - -class GConverter : boost::noncopyable { +class Converter { public: - - /// This is a singleton class. Get the instance. - static GConverter & get(); - /// Can the conversion be performed? - bool isReachable(string const & from_format_name, - string const & to_format_name) const; + static bool isReachable(std::string const & from_format_name, + std::string const & to_format_name); - /** Convert the file and at the end return it by emitting this signal - * If successful, the returned string will be the name of the - * converted file (to_file_base + extension(to_format_name)). - * If unsuccessful, the string will be empty. + /** One Converter per conversion ensures that the (hidden) signal + * is always connected to the expected slot. */ - typedef boost::signal1 SignalType; - /// - typedef boost::shared_ptr SignalTypePtr; - /// - void convert(string const & from_file, string const & to_file_base, - string const & from_format, string const & to_format, - SignalTypePtr on_finish); + Converter(support::FileName const & doc_fname, + support::FileName const & from_file, std::string const & to_file_base, + std::string const & from_format, std::string const & to_format); -private: - /** Make the c-tor private so we can control how many objects - * are instantiated. - */ - GConverter() {} + /// Needed for the pimpl + ~Converter(); - /** Build the conversion script, returning true if able to build it. - * The script is output to the ostringstream 'script'. - */ - bool build_script(string const & from_file, string const & to_file_base, - string const & from_format, string const & to_format, - ostringstream & script) const; + /// We are explicit about when we begin the conversion process. + void startConversion() const; - /** Remove the ConvProcess from the list of all processes. - * Called by ConvProcess::converted. + /** Connect and you'll be informed when the conversion process has + * finished. + * If the conversion is successful, then the listener is passed \c true. + * The connection is closed when this is destroyed. */ - friend class ConvProcess; - /// - void erase(ConvProcess *); - - /// The list of all conversion processs - typedef boost::shared_ptr ConvProcessPtr; - /// - std::list all_processes_; -}; - - -/// Each ConvProcess represents a single conversion process. -struct ConvProcess : public boost::signals::trackable -{ + typedef signals2::signal sig_type; + typedef sig_type::slot_type slot_type; /// - typedef GConverter::SignalTypePtr SignalTypePtr; - - /** Each ConvProcess represents a single conversion process. - * It is passed : - * 1. The name of the script_file, which it deletes once the - * conversion is comlpeted; - * 2. The script command itself, which it passes on to the forked - * call process; - * 3. The name of the output file, which it returns to the calling - * process on successfull completion, by emitting - * 4. The signal on_finish. - */ - ConvProcess(string const & script_file, string const & script_command, - string const & to_file, SignalTypePtr on_finish); + signals2::connection connect(slot_type const &) const; - /** This method is connected to a signal passed to the forked call - * class, passing control back here when the conversion is completed. - * Cleans-up the temporary files, emits the on_finish signal and - * removes the ConvProcess from the list of all processes. + /** If the conversion is successful, this returns the name of the + * resulting file. + * If conversion fails or has not been completed, however, it + * returns an empty string. */ - void converted(string const & cmd, pid_t pid, int retval); + support::FileName const & convertedFile() const; - /// - string script_file_; - /// - string to_file_; - /// - SignalTypePtr on_finish_; +private: + /// noncopyable + Converter(Converter const &); + void operator=(Converter const &); + + /// Use the Pimpl idiom to hide the internals. + class Impl; + /// The pointer never changes although *pimpl_'s contents may. + Impl * const pimpl_; }; -} // namespace grfx +} // namespace graphics +} // namespace lyx #endif // GRAPHICSCONVERTER_H