]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetText.cpp
Make undo action no-ops when the buffer is read-only
[lyx.git] / src / insets / InsetText.cpp
index 7bb0c0c8dfd22941dbddd530762d86439a8dfca1..a4521848c310f280d9a0cbb6c9a42fdc9bf2ba75 100644 (file)
@@ -63,6 +63,7 @@
 
 #include "support/convert.h"
 #include "support/debug.h"
+#include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
@@ -72,8 +73,6 @@
 #include <algorithm>
 #include <stack>
 
-#include <QCryptographicHash>
-
 
 using namespace std;
 using namespace lyx::support;
@@ -665,6 +664,8 @@ void InsetText::docbookRenderAsImage(XMLStream & xs, OutputParams const & rp, XH
        // TODO: no real support for Unicode. This code is very similar to RenderPreview::addPreview, the same gotcha applies.
 
        graphics::PreviewLoader* loader = buffer().loader();
+       // This should be OK because we are exporting
+       LASSERT(loader != nullptr, return);
        loader->add(snippet);
        loader->startLoading(true); // Generate the image and wait until done.
        graphics::PreviewImage const * img = loader->preview(snippet);
@@ -679,17 +680,7 @@ void InsetText::docbookRenderAsImage(XMLStream & xs, OutputParams const & rp, XH
        // same hash (by design of cryptographic hash functions). Computing a hash
        // is typically slow, but extremely fast compared to compilation of the
        // preview and image rendering.
-       QString snippetQ = QString(snippet.c_str());
-#if QT_VERSION >= 0x050000
-       QByteArray hash = QCryptographicHash::hash(snippetQ.toLocal8Bit(), QCryptographicHash::Sha256);
-#else
-       QByteArray hash = QCryptographicHash::hash(snippetQ.toLocal8Bit(), QCryptographicHash::Sha1);
-#endif
-       auto newFileBase = QString(hash.toBase64())
-                       .replace("/", "")
-                       .replace("+", "")
-                       .replace("=", "");
-       std::string newFileName = "lyx_" + newFileBase.toStdString() + "." + filename.extension();
+       std::string newFileName = "lyx_" + sanitizeFileName(toHexHash(snippet)) + "." + filename.extension();
 
        // Copy the image into the right folder.
        rp.exportdata->addExternalFile("docbook5", filename, newFileName);