]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt/GuiClipboard.cpp
No need (any longer?) to create a new view for lyxfiles-open
[lyx.git] / src / frontends / qt / GuiClipboard.cpp
index 422315a03eb21a08ea800d807f1a77d47d38d85d..60c8088f3732d1dbfefacee0bcd49ac6b336c2f9 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <config.h>
 
+#include "GuiApplication.h"
 #include "GuiClipboard.h"
 
 #include "Buffer.h"
@@ -35,6 +36,8 @@
 
 #include "frontends/alert.h"
 
+#include "support/checksum.h"
+
 #include <QApplication>
 #include <QBuffer>
 #include <QClipboard>
@@ -47,8 +50,6 @@
 #include <QTextDocument>
 #include <QTimer>
 
-#include <boost/crc.hpp>
-
 #include <memory>
 #include <map>
 #include <iostream>
@@ -111,6 +112,11 @@ GuiClipboard::GuiClipboard()
 {
        connect(qApp->clipboard(), SIGNAL(dataChanged()),
                this, SLOT(on_dataChanged()));
+       if(qApp->clipboard()->supportsFindBuffer()) {
+               connect(qApp->clipboard(), SIGNAL(findBufferChanged()),
+                       this, SLOT(on_findChanged()));
+               on_findChanged();
+       }
        // initialize clipboard status.
        update();
 }
@@ -124,7 +130,7 @@ string const GuiClipboard::getAsLyX() const
        if (cache_.hasFormat(lyxMimeType())) {
                // data from ourself or some other LyX instance
                QByteArray const ar = cache_.data(lyxMimeType());
-               string const s(ar.data(), ar.count());
+               string const s(ar.data(), ar.size());
                LYXERR(Debug::CLIPBOARD, s << "'");
                return s;
        }
@@ -301,7 +307,7 @@ FileName GuiClipboard::getAsGraphics(Cursor const & cur, GraphicsType type) cons
        // data from ourself or some other LyX instance
        QByteArray const ar = cache_.data(mime);
        LYXERR(Debug::CLIPBOARD, "Getting from clipboard: mime = " << mime.constData()
-              << "length = " << ar.count());
+              << "length = " << ar.size());
 
        QFile f(toqstr(filename.absFileName()));
        if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
@@ -345,7 +351,7 @@ namespace {
  * Since we are going to write a HTML file for external converters we need
  * to ensure that it is a well formed HTML file, including all the mentioned tags.
  */
-QString tidyHtml(QString input)
+QString tidyHtml(QString const & input)
 {
        // Misuse QTextDocument to cleanup the HTML.
        // As a side effect, all visual markup like <tt> is converted to CSS,
@@ -355,7 +361,11 @@ QString tidyHtml(QString input)
        // clutter.
        QTextDocument converter;
        converter.setHtml(input);
+#if QT_VERSION < 0x060000
        return converter.toHtml("utf-8");
+#else
+       return converter.toHtml();
+#endif
 }
 } // namespace
 
@@ -431,11 +441,8 @@ void GuiClipboard::put(string const & lyx, docstring const & html, docstring con
                data->setData(lyxMimeType(), qlyx);
                // If the OS has not the concept of clipboard ownership,
                // we recognize internal data through its checksum.
-               if (!hasInternal()) {
-                       boost::crc_32_type crc32;
-                       crc32.process_bytes(lyx.c_str(), lyx.size());
-                       checksum = crc32.checksum();
-               }
+               if (!hasInternal())
+                       checksum = support::checksum(lyx);
        }
        // Don't test for text.empty() since we want to be able to clear the
        // clipboard.
@@ -527,10 +534,8 @@ bool GuiClipboard::isInternal() const
        // We are running on OS X: Check whether clipboard data is from
        // ourself by comparing its checksum with the stored one.
        QByteArray const ar = cache_.data(lyxMimeType());
-       string const data(ar.data(), ar.count());
-       boost::crc_32_type crc32;
-       crc32.process_bytes(data.c_str(), data.size());
-       return checksum == crc32.checksum();
+       string const data(ar.data(), ar.size());
+       return checksum == static_cast<std::uint32_t>(support::checksum(data));
 }
 
 
@@ -549,6 +554,23 @@ bool GuiClipboard::hasInternal() const
 }
 
 
+void GuiClipboard::setFindBuffer(docstring const & text)
+{
+       LYXERR(Debug::CLIPBOARD, "new findbuffer: " << text);
+       Clipboard::setFindBuffer(text);
+       if(qApp->clipboard()->supportsFindBuffer()) {
+               qApp->clipboard()->setText(toqstr(text), QClipboard::FindBuffer);
+       }
+}
+
+
+void GuiClipboard::on_findChanged()
+{
+       Clipboard::setFindBuffer(from_utf8(fromqstr(
+               qApp->clipboard()->text(QClipboard::FindBuffer))));
+}
+
+
 void GuiClipboard::on_dataChanged()
 {
        update();