1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 08:48:51 -05:00

Properly document Linux-specific drag-n-drop workarounds

This commit is contained in:
Reinhard Pointner 2016-07-18 00:10:07 +08:00
parent 90b9c826ac
commit 8654b2008b

View File

@ -17,7 +17,6 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
import java.util.logging.Level;
import net.filebot.gio.GVFS; import net.filebot.gio.GVFS;
@ -89,7 +88,46 @@ public class FileTransferable implements Transferable {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static List<File> getFilesFromTransferable(Transferable tr) throws IOException, UnsupportedFlavorException { public static List<File> 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<File> files = new ArrayList<File>();
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 // file list flavor
Object transferable = tr.getTransferData(DataFlavor.javaFileListFlavor); Object transferable = tr.getTransferData(DataFlavor.javaFileListFlavor);
if (transferable instanceof List) { 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<File> files = new ArrayList<File>();
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 // cannot get files from transferable
throw new UnsupportedFlavorException(null); throw new UnsupportedFlavorException(DataFlavor.javaFileListFlavor);
} }
} }