diff options
author | Jan-Marek Glogowski <jan-marek.glogowski@extern.cib.de> | 2019-10-02 13:31:46 +0000 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2019-10-07 16:02:31 +0200 |
commit | 29e12fe99d38ce2a35b946f6a851940e347713dd (patch) | |
tree | 293ce87d4701889562c62e16b347593dac607d0b | |
parent | 1506c5e1f7228b23b8cee461701ab9dc8eccde27 (diff) |
tdf#112368 Qt5 don't lose ownership in flushClipboard
I didn't know that flushClipboard is called for simple text edit
fields for C'n'P operations, and not just on LO shutdown. This way
the simple text is actually secured in the clipboard instandly, as
there aren't complex mime-types to generate and secure.
As a result we also need to protect flushClipboard from loosing
ownership, which wasn't needed for the shutdown-only case, as this
would give up ownership anyway.
Change-Id: Ib3cd4979228fc645a27c658abb3df38ccf8c8956
Reviewed-on: https://gerrit.libreoffice.org/80042
Reviewed-by: Ilmari Lauhakangas <ilmari.lauhakangas@libreoffice.org>
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
-rw-r--r-- | vcl/inc/qt5/Qt5Clipboard.hxx | 4 | ||||
-rw-r--r-- | vcl/qt5/Qt5Clipboard.cxx | 16 |
2 files changed, 12 insertions, 8 deletions
diff --git a/vcl/inc/qt5/Qt5Clipboard.hxx b/vcl/inc/qt5/Qt5Clipboard.hxx index 56d109b2e528..122184b44942 100644 --- a/vcl/inc/qt5/Qt5Clipboard.hxx +++ b/vcl/inc/qt5/Qt5Clipboard.hxx @@ -38,7 +38,9 @@ class Qt5Clipboard final osl::Mutex m_aMutex; const OUString m_aClipboardName; const QClipboard::Mode m_aClipboardMode; - bool m_bInSetContents; + // has to be set, if LO changes the QClipboard itself, so it won't instantly lose + // ownership by it's self-triggered QClipboard::changed handler + bool m_bOwnClipboardChange; // if not empty, this holds the setContents provided XTransferable or a Qt5ClipboardTransferable css::uno::Reference<css::datatransfer::XTransferable> m_aContents; diff --git a/vcl/qt5/Qt5Clipboard.cxx b/vcl/qt5/Qt5Clipboard.cxx index 4b31864bf2bd..cadedbfd327e 100644 --- a/vcl/qt5/Qt5Clipboard.cxx +++ b/vcl/qt5/Qt5Clipboard.cxx @@ -29,7 +29,7 @@ Qt5Clipboard::Qt5Clipboard(const OUString& aModeString, const QClipboard::Mode a XServiceInfo>(m_aMutex) , m_aClipboardName(aModeString) , m_aClipboardMode(aMode) - , m_bInSetContents(false) + , m_bOwnClipboardChange(false) { assert(isSupported(m_aClipboardMode)); // DirectConnection guarantees the changed slot runs in the same thread as the QClipboard @@ -66,7 +66,11 @@ void Qt5Clipboard::flushClipboard() QMimeData* pMimeCopy = nullptr; if (pQt5MimeData && pQt5MimeData->deepCopy(&pMimeCopy)) + { + m_bOwnClipboardChange = true; pClipboard->setMimeData(pMimeCopy, m_aClipboardMode); + m_bOwnClipboardChange = false; + } }); } @@ -106,9 +110,7 @@ void Qt5Clipboard::setContents( m_aContents = xTrans; m_aOwner = xClipboardOwner; - // these QApplication::clipboard() calls will trigger QClipboard::changed / handleChanged. - // we need to prevent freeing the contents, so tell handleChanged about us setting it - m_bInSetContents = true; + m_bOwnClipboardChange = true; if (m_aContents.is()) QApplication::clipboard()->setMimeData(new Qt5MimeData(m_aContents), m_aClipboardMode); else @@ -116,7 +118,7 @@ void Qt5Clipboard::setContents( assert(!m_aOwner.is()); QApplication::clipboard()->clear(m_aClipboardMode); } - m_bInSetContents = false; + m_bOwnClipboardChange = false; aGuard.clear(); @@ -136,7 +138,7 @@ void Qt5Clipboard::handleChanged(QClipboard::Mode aMode) css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner> xOldOwner(m_aOwner); css::uno::Reference<css::datatransfer::XTransferable> xOldContents(m_aContents); // ownership change from LO POV is handled in setContents - if (!m_bInSetContents) + if (!m_bOwnClipboardChange) { m_aContents.clear(); m_aOwner.clear(); @@ -149,7 +151,7 @@ void Qt5Clipboard::handleChanged(QClipboard::Mode aMode) aGuard.clear(); - if (!m_bInSetContents && xOldOwner.is()) + if (!m_bOwnClipboardChange && xOldOwner.is()) xOldOwner->lostOwnership(this, xOldContents); for (auto const& listener : aListeners) listener->changedContents(aEv); |