diff --git a/source/net/filebot/ui/transfer/FileTransferable.java b/source/net/filebot/ui/transfer/FileTransferable.java index c1f80f55..4facbb5e 100644 --- a/source/net/filebot/ui/transfer/FileTransferable.java +++ b/source/net/filebot/ui/transfer/FileTransferable.java @@ -17,7 +17,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Scanner; -import java.util.logging.Level; import net.filebot.gio.GVFS; @@ -89,7 +88,46 @@ public class FileTransferable implements Transferable { @SuppressWarnings("unchecked") public static List getFilesFromTransferable(Transferable tr) throws IOException, UnsupportedFlavorException { - if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor) && !useGVFS()) { + // On Linux, if a file is dragged from a smb share to into a java application (e.g. Ubuntu Files to FileBot) + // the application/x-java-file-list transfer data will be an empty list + // because the native uri-list flavor drop data will be a list of smb URLs (e.g. smb://10.0.0.1/data/file.txt) + // and not local GVFS paths (e.g. /run/user/1000/gvfs/smb-share:server=10.0.01.1,share=data/file.txt) + if (useGVFS()) { + if (tr.isDataFlavorSupported(FileTransferable.uriListFlavor)) { + // file URI list flavor (Linux) + Readable transferData = (Readable) tr.getTransferData(FileTransferable.uriListFlavor); + Scanner scanner = new Scanner(transferData); + List files = new ArrayList(); + + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + + if (line.startsWith("#")) { + // the line is a comment (as per RFC 2483) + continue; + } + + try { + URI uri = new URI(line); + File file = GVFS.getDefaultVFS().getPathForURI(uri); + + if (file == null || !file.exists()) { + throw new FileNotFoundException(line); + } + + files.add(file); + } catch (Throwable e) { + // URISyntaxException, IllegalArgumentException, FileNotFoundException, LinkageError, etc + debug.warning("Invalid file URI: " + line); + } + } + + return sortByUniquePath(files); // FORCE NATURAL FILE ORDER + } + } + + // Windows, Mac and default handling + if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { // file list flavor Object transferable = tr.getTransferData(DataFlavor.javaFileListFlavor); if (transferable instanceof List) { @@ -99,53 +137,7 @@ public class FileTransferable implements Transferable { } } - if (tr.isDataFlavorSupported(FileTransferable.uriListFlavor)) { - // file URI list flavor (Linux) - Readable transferData = (Readable) tr.getTransferData(FileTransferable.uriListFlavor); - Scanner scanner = new Scanner(transferData); - List files = new ArrayList(); - - while (scanner.hasNextLine()) { - String line = scanner.nextLine(); - - if (line.startsWith("#")) { - // the line is a comment (as per RFC 2483) - continue; - } - - try { - URI uri = new URI(line); - File file = null; - - try { - // file URIs - file = new File(uri); - } catch (IllegalArgumentException exception) { - // try handle other GVFS URI schemes - try { - if (useGVFS()) { - file = GVFS.getDefaultVFS().getPathForURI(uri); - } - } catch (LinkageError error) { - debug.log(Level.WARNING, "Unable to resolve GVFS URI: " + uri, error); - } - } - - if (file == null || !file.exists()) { - throw new FileNotFoundException(line); - } - - files.add(file); - } catch (Throwable e) { - // URISyntaxException, IllegalArgumentException, FileNotFoundException, LinkageError, etc - debug.warning("Invalid file URI: " + line); - } - } - - return sortByUniquePath(files); // FORCE NATURAL FILE ORDER - } - // cannot get files from transferable - throw new UnsupportedFlavorException(null); + throw new UnsupportedFlavorException(DataFlavor.javaFileListFlavor); } }