Skip to content

Commit

Permalink
Fixed DND with MTP
Browse files Browse the repository at this point in the history
Fixes lxqt/pcmanfm-qt#301

We get the drag info as "text/uri-list", which works most of the time. However, that mimetype changes the URL list by parsing its elements (see Qt → qmimedata.cpp → QMimeData::setData), while MTP needs the original list to query file info and support copying through DND. This patch gets the drag info without parsing it by making up the mimetype "libfm/files".
  • Loading branch information
tsujan authored and agaida committed Jul 21, 2019
1 parent 5a04425 commit 7de18bc
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/foldermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ QStringList FolderModel::mimeTypes() const {
// the real implementation is in FolderView::childDropEvent().
types << QStringLiteral("XdndDirectSave0");
types << QStringLiteral("text/uri-list");
// types << "x-special/gnome-copied-files";
types << QStringLiteral("libfm/files"); // see FolderModel::mimeData() below
return types;
}

Expand All @@ -444,6 +444,9 @@ QMimeData* FolderModel::mimeData(const QModelIndexList& indexes) const {
}
}
data->setData(QStringLiteral("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;
}
Expand Down Expand Up @@ -479,10 +482,19 @@ bool FolderModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int
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);
Expand Down

0 comments on commit 7de18bc

Please sign in to comment.