diff options
author | Katarina Behrens <Katarina.Behrens@cib.de> | 2019-01-25 12:24:50 +0100 |
---|---|---|
committer | Katarina Behrens <Katarina.Behrens@cib.de> | 2019-01-30 12:02:30 +0100 |
commit | 67b0fcea9d748c4dd8101036cbb2c587d65f0bf7 (patch) | |
tree | 855b0c4ba7991301cba87ff1a4e74567fbf74966 /vcl/qt5/Qt5DragAndDrop.cxx | |
parent | c902b3a96dcfbc52e53164f108e605547e598bc7 (diff) |
tdf#120772: implement file manager -> LibO DnD
not sure if we should support also other than URL list mimetypes
Change-Id: Ida3f65637247822198b04682a3d1a7c196a24e0c
Reviewed-on: https://gerrit.libreoffice.org/66997
Tested-by: Jenkins
Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
Diffstat (limited to 'vcl/qt5/Qt5DragAndDrop.cxx')
-rw-r--r-- | vcl/qt5/Qt5DragAndDrop.cxx | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/vcl/qt5/Qt5DragAndDrop.cxx b/vcl/qt5/Qt5DragAndDrop.cxx index 092c2b2e10a6..201f251cdefc 100644 --- a/vcl/qt5/Qt5DragAndDrop.cxx +++ b/vcl/qt5/Qt5DragAndDrop.cxx @@ -14,6 +14,9 @@ #include <cppuhelper/supportsservice.hxx> #include <sal/log.hxx> +#include <QtCore/QMimeData> +#include <QtCore/QUrl> + #include <Qt5DragAndDrop.hxx> #include <Qt5Frame.hxx> #include <Qt5Widget.hxx> @@ -22,6 +25,65 @@ using namespace com::sun::star; using namespace com::sun::star::uno; using namespace com::sun::star::lang; +Qt5DnDTransferable::Qt5DnDTransferable(const QMimeData* pMimeData) + : m_pMimeData(pMimeData) +{ +} + +css::uno::Any Qt5DnDTransferable::getTransferData(const css::datatransfer::DataFlavor& rFlavor) +{ + uno::Any aAny; + assert(m_pMimeData); + + // FIXME: not sure if we should support more mimetypes here + // (how to carry out external DnD with anything else than [file] URL?) + if (m_pMimeData->hasUrls()) + { + QList<QUrl> urlList = m_pMimeData->urls(); + + if (urlList.size() > 0) + { + //FIXME: multiple URLs, here we take only 1st one + QString url = urlList.at(0).path(); + std::string aStr = url.toStdString(); + Sequence<sal_Int8> aSeq(reinterpret_cast<const sal_Int8*>(aStr.c_str()), aStr.length()); + aAny <<= aSeq; + } + } + return aAny; +} + +std::vector<css::datatransfer::DataFlavor> Qt5DnDTransferable::getTransferDataFlavorsAsVector() +{ + std::vector<css::datatransfer::DataFlavor> aVector; + css::datatransfer::DataFlavor aFlavor; + + if (m_pMimeData) + { + for (QString& rMimeType : m_pMimeData->formats()) + { + // filter out non-MIME types such as TARGETS, MULTIPLE, TIMESTAMP + if (rMimeType.indexOf('/') == -1) + continue; + + if (rMimeType.startsWith("text/plain")) + { + aFlavor.MimeType = "text/plain;charset=utf-16"; + aFlavor.DataType = cppu::UnoType<OUString>::get(); + aVector.push_back(aFlavor); + } + else + { + aFlavor.MimeType = toOUString(rMimeType); + aFlavor.DataType = cppu::UnoType<Sequence<sal_Int8>>::get(); + aVector.push_back(aFlavor); + } + } + } + + return aVector; +} + Qt5DragSource::~Qt5DragSource() { //if (m_pFrame) |