Description: Fix DND for MTP mounted folders Author: Tsu Jan Bug-Upstream: https://github.com/lxqt/pcmanfm-qt/issues/301 Applied-Upstream: https://github.com/lxqt/libfm-qt/commit/7de18bc89b9b47f66de54a7e347bf8d391d44a48 Last-Update: 2019-08-17 --- a/src/foldermodel.cpp +++ b/src/foldermodel.cpp @@ -384,7 +384,7 @@ QStringList FolderModel::mimeTypes() con // the real implementation is in FolderView::childDropEvent(). types << "XdndDirectSave0"; types << "text/uri-list"; - // types << "x-special/gnome-copied-files"; + types << QStringLiteral("libfm/files"); // see FolderModel::mimeData() below return types; } @@ -407,6 +407,9 @@ QMimeData* FolderModel::mimeData(const Q } } data->setData("text/uri-list", urilist); + // NOTE: The mimetype "text/uri-list" changes the list in QMimeData::setData() to get URLs + // but some protocols (like MTP) may need the original list to query file info. + data->setData(QStringLiteral("libfm/files"), urilist); return data; } @@ -442,10 +445,19 @@ bool FolderModel::dropMimeData(const QMi destPath = path(); } + Fm::FilePathList srcPaths; + // try to get paths from the original data + if(data->hasFormat(QStringLiteral("libfm/files"))) { + QByteArray _data = data->data(QStringLiteral("libfm/files")); + srcPaths = pathListFromUriList(_data.data()); + } + if(srcPaths.empty() && data->hasUrls()) { + srcPaths = Fm::pathListFromQUrls(data->urls()); + } + // FIXME: should we put this in dropEvent handler of FolderView instead? - if(data->hasUrls()) { + if(!srcPaths.empty()) { //qDebug("drop action: %d", action); - auto srcPaths = pathListFromQUrls(data->urls()); switch(action) { case Qt::CopyAction: FileOperation::copyFiles(srcPaths, destPath);