]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/PreviewLoader.cpp
Use only one file for dummy implementations
[lyx.git] / src / graphics / PreviewLoader.cpp
index 914d7d00d13b9ba7220871b906f33f194a0b21b0..e9b1d47202c2a4a4288a6f97227eeeddce48c66d 100644 (file)
@@ -25,6 +25,7 @@
 #include "output.h"
 #include "OutputParams.h"
 #include "TexRow.h"
+#include "texstream.h"
 
 #include "frontends/Application.h" // hexName
 
 #include "support/bind.h"
 #include "support/TempFile.h"
 
-#include <sstream>
+#include <atomic>
 #include <fstream>
 #include <iomanip>
+#include <memory>
+#include <mutex>
+#include <sstream>
 
 #include <QTimer>
 
@@ -88,13 +92,23 @@ lyx::Converter const * setConverter(string const & from)
                        return ptr;
        }
 
-       // FIXME THREAD
-       static bool first = true;
-       if (first) {
-               first = false;
-               LYXERR0("PreviewLoader::startLoading()\n"
-                       << "No converter from \"" << from << "\" format has been defined.");
-       }
+       // Show the error only once
+#ifdef LYX_USE_STD_CALL_ONCE
+       // This is thread-safe.
+       static once_flag flag;
+       call_once(flag, [&](){
+                       LYXERR0("PreviewLoader::startLoading()\n"
+                               << "No converter from \"" << from
+                               << "\" format has been defined.");
+               });
+#else
+       // This is also thread-safe according to ยง6.7.4 of the C++11 standard.
+       static bool once = ([&]{
+                       LYXERR0("PreviewLoader::startLoading()\n"
+                               << "No converter from \"" << from
+                               << "\" format has been defined.");
+               } (), true);
+#endif
        return 0;
 }
 
@@ -193,7 +207,7 @@ typedef InProgressProcesses::value_type InProgressProcess;
 namespace lyx {
 namespace graphics {
 
-class PreviewLoader::Impl : public boost::signals::trackable {
+class PreviewLoader::Impl : public boost::signals2::trackable {
 public:
        ///
        Impl(PreviewLoader & p, Buffer const & b);
@@ -214,7 +228,7 @@ public:
        void refreshPreviews();
 
        /// Emit this signal when an image is ready for display.
-       boost::signal<void(PreviewImage const &)> imageReady;
+       boost::signals2::signal<void(PreviewImage const &)> imageReady;
 
        Buffer const & buffer() const { return buffer_; }
 
@@ -229,7 +243,7 @@ private:
        /** cache_ allows easy retrieval of already-generated images
         *  using the LaTeX snippet as the identifier.
         */
-       typedef shared_ptr<PreviewImage> PreviewImagePtr;
+       typedef std::shared_ptr<PreviewImage> PreviewImagePtr;
        ///
        typedef map<string, PreviewImagePtr> Cache;
        ///
@@ -320,7 +334,7 @@ void PreviewLoader::refreshPreviews()
 }
 
 
-boost::signals::connection PreviewLoader::connect(slot_type const & slot) const
+boost::signals2::connection PreviewLoader::connect(slot_type const & slot) const
 {
        return pimpl_->imageReady.connect(slot);
 }
@@ -624,8 +638,7 @@ void PreviewLoader::Impl::startLoading(bool wait)
                return;
        }
 
-       TexRow texrow;
-       otexstream os(of, texrow);
+       otexstream os(of);
        OutputParams runparams(&enc);
        LaTeXFeatures features(buffer_, buffer_.params(), runparams);
 
@@ -639,6 +652,11 @@ void PreviewLoader::Impl::startLoading(bool wait)
        }
        of << "\\batchmode\n";
 
+       // Set \jobname of previews to the document name (see bug 9627)
+       of << "\\def\\jobname{"
+          << from_utf8(changeExtension(buffer_.latexName(true), ""))
+          << "}\n";
+
        LYXERR(Debug::LATEX, "Format = " << buffer_.params().getDefaultOutputFormat());
        string latexparam = "";
        bool docformat = !buffer_.params().default_output_format.empty()
@@ -722,8 +740,7 @@ void PreviewLoader::Impl::startLoading(bool wait)
        if (wait) {
                ForkedCall call(buffer_.filePath(), buffer_.layoutPos());
                int ret = call.startScript(ForkedProcess::Wait, command);
-               // FIXME THREAD
-               static int fake = (2^20) + 1;
+               static atomic_int fake((2^20) + 1);
                int pid = fake++;
                inprogress.pid = pid;
                inprogress.command = command;