X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiClipboard.cpp;h=4c8d47e7f8c5eea6c3fb6a8b18acaeacd191f29c;hb=1f10969bb5c5f36017bf5ba8671381b09945cf57;hp=7aad7a95604774d4bb10beb8823f38a26dda3f32;hpb=4521fc757ba5906402e2e46b23b47dfc7f436675;p=lyx.git diff --git a/src/frontends/qt4/GuiClipboard.cpp b/src/frontends/qt4/GuiClipboard.cpp index 7aad7a9560..4c8d47e7f8 100644 --- a/src/frontends/qt4/GuiClipboard.cpp +++ b/src/frontends/qt4/GuiClipboard.cpp @@ -30,9 +30,9 @@ #include "support/lstrings.h" #include "support/lyxtime.h" -#ifdef Q_WS_MACX +#ifdef Q_OS_MAC #include "support/linkback/LinkBackProxy.h" -#endif // Q_WS_MACX +#endif // Q_OS_MAC #include "frontends/alert.h" @@ -46,6 +46,7 @@ #include #include #include +#include #include @@ -61,9 +62,9 @@ namespace lyx { namespace frontend { -static QMimeData const * read_clipboard() +static QMimeData const * read_clipboard() { - LYXERR(Debug::ACTION, "Getting Clipboard"); + LYXERR(Debug::CLIPBOARD, "Getting Clipboard"); QMimeData const * source = qApp->clipboard()->mimeData(QClipboard::Clipboard); if (!source) { @@ -82,7 +83,7 @@ static QMimeData const * read_clipboard() void CacheMimeData::update() { time_t const start_time = current_time(); - LYXERR(Debug::ACTION, "Creating CacheMimeData object"); + LYXERR(Debug::CLIPBOARD, "Creating CacheMimeData object"); cached_formats_ = read_clipboard()->formats(); // Qt times out after 5 seconds if it does not recieve a response. @@ -93,7 +94,7 @@ void CacheMimeData::update() } -QByteArray CacheMimeData::data(QString const & mimeType) const +QByteArray CacheMimeData::data(QString const & mimeType) const { return read_clipboard()->data(mimeType); } @@ -112,23 +113,23 @@ GuiClipboard::GuiClipboard() connect(qApp->clipboard(), SIGNAL(dataChanged()), this, SLOT(on_dataChanged())); // initialize clipboard status. - on_dataChanged(); + update(); } string const GuiClipboard::getAsLyX() const { - LYXERR(Debug::ACTION, "GuiClipboard::getAsLyX(): `"); + LYXERR(Debug::CLIPBOARD, "GuiClipboard::getAsLyX(): `"); // We don't convert encodings here since the encoding of the // clipboard contents is specified in the data itself 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()); - LYXERR(Debug::ACTION, s << "'"); + LYXERR(Debug::CLIPBOARD, s << "'"); return s; } - LYXERR(Debug::ACTION, "'"); + LYXERR(Debug::CLIPBOARD, "'"); return string(); } @@ -267,7 +268,7 @@ FileName GuiClipboard::getAsGraphics(Cursor const & cur, GraphicsType type) cons // get image from QImage from clipboard QImage image = qApp->clipboard()->image(); if (image.isNull()) { - LYXERR(Debug::ACTION, "No image in clipboard"); + LYXERR(Debug::CLIPBOARD, "No image in clipboard"); return FileName(); } @@ -281,10 +282,10 @@ FileName GuiClipboard::getAsGraphics(Cursor const & cur, GraphicsType type) cons image.save(toqstr(filename.absFileName()), "JPEG"); else LATTEST(false); - + return filename; } - + // get mime for type QString mime; switch (type) { @@ -294,26 +295,26 @@ FileName GuiClipboard::getAsGraphics(Cursor const & cur, GraphicsType type) cons case WmfGraphicsType: mime = wmfMimeType(); break; default: LASSERT(false, return FileName()); } - + // get data if (!cache_.hasFormat(mime)) return FileName(); // data from ourself or some other LyX instance QByteArray const ar = cache_.data(mime); - LYXERR(Debug::ACTION, "Getting from clipboard: mime = " << mime.constData() + LYXERR(Debug::CLIPBOARD, "Getting from clipboard: mime = " << mime.constData() << "length = " << ar.count()); QFile f(toqstr(filename.absFileName())); if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - LYXERR(Debug::ACTION, "Error opening file " + LYXERR(Debug::CLIPBOARD, "Error opening file " << filename.absFileName() << " for writing"); return FileName(); } - + // write the (LinkBack) PDF data f.write(ar); if (type == LinkBackGraphicsType) { -#ifdef Q_WS_MACX +#ifdef Q_OS_MAC void const * linkBackData; unsigned linkBackLen; getLinkBackData(&linkBackData, &linkBackLen); @@ -324,7 +325,7 @@ FileName GuiClipboard::getAsGraphics(Cursor const & cur, GraphicsType type) cons #else // only non-Mac this should never happen LATTEST(false); -#endif // Q_WS_MACX +#endif // Q_OS_MAC } f.close(); @@ -405,7 +406,7 @@ docstring const GuiClipboard::getAsText(TextType type) const break; } } - LYXERR(Debug::ACTION, "GuiClipboard::getAsText(" << type << "): `" << str << "'"); + LYXERR(Debug::CLIPBOARD, "GuiClipboard::getAsText(" << type << "): `" << str << "'"); if (str.isNull()) return docstring(); @@ -421,7 +422,7 @@ void GuiClipboard::put(string const & text) const void GuiClipboard::put(string const & lyx, docstring const & html, docstring const & text) { - LYXERR(Debug::ACTION, "GuiClipboard::put(`" << lyx << "' `" + LYXERR(Debug::CLIPBOARD, "GuiClipboard::put(`" << lyx << "' `" << to_utf8(html) << "' `" << to_utf8(text) << "')"); // We don't convert the encoding of lyx since the encoding of the // clipboard contents is specified in the data itself @@ -459,7 +460,7 @@ bool GuiClipboard::hasTextContents(Clipboard::TextType type) const case LyXTextType: return cache_.hasFormat(lyxMimeType()); case PlainTextType: - return cache_.hasText(); + return cache_.hasText(); case HtmlTextType: return cache_.hasHtml(); case LaTeXTextType: @@ -488,17 +489,17 @@ bool GuiClipboard::hasGraphicsContents(Clipboard::GraphicsType type) const // handle LinkBack for Mac if (type == LinkBackGraphicsType) -#ifdef Q_WS_MACX +#ifdef Q_OS_MAC return isLinkBackDataInPasteboard(); #else return false; -#endif // Q_WS_MACX - +#endif // Q_OS_MAC + // get mime data QStringList const & formats = cache_.formats(); - LYXERR(Debug::ACTION, "We found " << formats.size() << " formats"); + LYXERR(Debug::CLIPBOARD, "We found " << formats.size() << " formats"); for (int i = 0; i < formats.size(); ++i) - LYXERR(Debug::ACTION, "Found format " << formats[i]); + LYXERR(Debug::CLIPBOARD, "Found format " << formats[i]); // compute mime for type QString mime; @@ -508,7 +509,7 @@ bool GuiClipboard::hasGraphicsContents(Clipboard::GraphicsType type) const case PdfGraphicsType: mime = pdfMimeType(); break; default: LASSERT(false, return false); } - + return cache_.hasFormat(mime); } @@ -537,11 +538,11 @@ bool GuiClipboard::isInternal() const bool GuiClipboard::hasInternal() const { // Windows and Mac OS X does not have the concept of ownership; - // the clipboard is a fully global resource so all applications + // the clipboard is a fully global resource so all applications // are notified of changes. However, on Windows ownership is // emulated by Qt through the OleIsCurrentClipboard() API, while // on Mac OS X we deal with this issue by ourself. -#if defined(Q_WS_X11) || defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN) +#ifndef Q_OS_MAC return true; #else return false; @@ -550,6 +551,17 @@ bool GuiClipboard::hasInternal() const void GuiClipboard::on_dataChanged() +{ + update(); +#if defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN) + // Retry on Windows (#10109) + if (cache_.formats().count() == 0) { + QTimer::singleShot(100, this, SLOT(update())); + } +#endif +} + +void GuiClipboard::update() { //Note: we do not really need to run cache_.update() unless the //data has been changed *and* the GuiClipboard has been queried. @@ -559,9 +571,9 @@ void GuiClipboard::on_dataChanged() //to time-out waiting for the clipboard. cache_.update(); QStringList l = cache_.formats(); - LYXERR(Debug::ACTION, "Qt Clipboard changed. We found the following mime types:"); + LYXERR(Debug::CLIPBOARD, "Qt Clipboard changed. We found the following mime types:"); for (int i = 0; i < l.count(); i++) - LYXERR(Debug::ACTION, l.value(i)); + LYXERR(Debug::CLIPBOARD, l.value(i)); plaintext_clipboard_empty_ = qApp->clipboard()-> text(QClipboard::Clipboard).isEmpty();