]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/GraphicsConverter.h
Remove obsolete (and false) comment.
[lyx.git] / src / graphics / GraphicsConverter.h
index 536a84013d2a66538c15ca0ea9d2756b29ac9018..c038029bd8f99b61559fbfc7b0447e4aab4d9cb0 100644 (file)
 // -*- 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 <a.leeming@ic.ac.uk>
+ * \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 <boost/smart_ptr.hpp>
-#include <boost/utility.hpp>
-#include <sigc++/signal_system.h>
-#include <list>
+#include "support/signals.h"
 
-#ifdef __GNUG__
-#pragma interface
-#endif
 
-namespace grfx {
+namespace lyx {
 
-class GConverter : boost::noncopyable {
-public:
+namespace support { class FileName; }
 
-       /// This is a singleton class. Get the instance.
-       static GConverter & get();
+namespace graphics {
 
+class Converter {
+public:
        /// 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 SigC::Signal1<void, string const &> SignalType;
-       ///
-       typedef boost::shared_ptr<SignalType> 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<ConvProcess> ConvProcessPtr;
+       typedef signals2::signal<void(bool)> sig_type;
+       typedef sig_type::slot_type slot_type;
        ///
-       std::list<ConvProcessPtr> all_processes_;
-};
-
-
-/// Each ConvProcess represents a single conversion process.
-struct ConvProcess : public SigC::Object
-{
-       ///
-       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 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