]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiClipboard.cpp
cosmetics
[lyx.git] / src / frontends / qt4 / GuiClipboard.cpp
index cd9914cde6aca29bf7610da60d7abafe6692c0e8..0bad26412df02e5fff5e96f88242d26c4363f6c1 100644 (file)
@@ -27,7 +27,6 @@
 using lyx::support::internalLineEnding;
 using lyx::support::externalLineEnding;
 
-using std::endl;
 using std::string;
 
 static char const * const mime_type = "application/x-lyx";
@@ -36,25 +35,34 @@ static char const * const mime_type = "application/x-lyx";
 namespace lyx {
 namespace frontend {
 
+GuiClipboard::GuiClipboard()
+{
+       connect(qApp->clipboard(), SIGNAL(dataChanged()),
+               this, SLOT(on_dataChanged()));
+       // initialize clipboard status.
+       on_dataChanged();
+}
+
+
 string const GuiClipboard::getAsLyX() const
 {
-       LYXERR(Debug::ACTION) << "GuiClipboard::getAsLyX(): `";
+       LYXERR(Debug::ACTION, "GuiClipboard::getAsLyX(): `");
        // We don't convert encodings here since the encoding of the
        // clipboard contents is specified in the data itself
        QMimeData const * source =
                qApp->clipboard()->mimeData(QClipboard::Clipboard);
        if (!source) {
-               LYXERR(Debug::ACTION) << "' (no QMimeData)" << endl;
+               LYXERR(Debug::ACTION, "' (no QMimeData)");
                return string();
        }
        if (source->hasFormat(mime_type)) {
                // data from ourself or some other LyX instance
                QByteArray const ar = source->data(mime_type);
                string const s(ar.data(), ar.count());
-               LYXERR(Debug::ACTION) << s << "'" << endl;
+               LYXERR(Debug::ACTION, s << "'");
                return s;
        }
-       LYXERR(Debug::ACTION) << "'" << endl;
+       LYXERR(Debug::ACTION, "'");
        return string();
 }
 
@@ -64,8 +72,7 @@ docstring const GuiClipboard::getAsText() const
        // text data from other applications
        QString const str = qApp->clipboard()->text(QClipboard::Clipboard)
                                .normalized(QString::NormalizationForm_C);
-       LYXERR(Debug::ACTION) << "GuiClipboard::getAsText(): `"
-                             << fromqstr(str) << "'" << endl;
+       LYXERR(Debug::ACTION, "GuiClipboard::getAsText(): `" << fromqstr(str) << "'");
        if (str.isNull())
                return docstring();
 
@@ -75,8 +82,8 @@ docstring const GuiClipboard::getAsText() const
 
 void GuiClipboard::put(string const & lyx, docstring const & text)
 {
-       LYXERR(Debug::ACTION) << "GuiClipboard::put(`" << lyx << "' `"
-                             << to_utf8(text) << "')" << endl;
+       LYXERR(Debug::ACTION, "GuiClipboard::put(`" << lyx << "' `"
+                             << to_utf8(text) << "')");
        // We don't convert the encoding of lyx since the encoding of the
        // clipboard contents is specified in the data itself
        QMimeData * data = new QMimeData;
@@ -110,16 +117,27 @@ bool GuiClipboard::isInternal() const
 }
 
 
+void GuiClipboard::on_dataChanged()
+{
+       text_clipboard_empty_ = qApp->clipboard()->
+               text(QClipboard::Clipboard).isEmpty();
+
+       has_lyx_contents_ = hasLyXContents();
+}
+
+
 bool GuiClipboard::empty() const
 {
        // We need to check both the plaintext and the LyX version of the
        // clipboard. The plaintext version is empty if the LyX version
-       // contains only one inset, and the LyX version is empry if the
+       // contains only one inset, and the LyX version is empty if the
        // clipboard does not come from LyX.
-       if (!qApp->clipboard()->text(QClipboard::Clipboard).isEmpty())
+       if (!text_clipboard_empty_)
                return false;
-       return !hasLyXContents();
+       return !has_lyx_contents_;
 }
 
 } // namespace frontend
 } // namespace lyx
+
+#include "GuiClipboard_moc.cpp"