QFile file = new QFile(Global.getFileManager().getResDirPath(fileName));
QFile.OpenMode mode = new QFile.OpenMode();
mode.set(QFile.OpenModeFlag.WriteOnly);
boolean openResult = file.open(mode);
logger.log(logger.EXTREME, "File opened:" +openResult);
QDataStream out = new QDataStream(file);
Resource resBinary = conn.getNoteTable().noteResourceTable.getNoteResource(res.getGuid(), true);
QByteArray binData = new QByteArray(resBinary.getData().getBody());
resBinary = null;
logger.log(logger.EXTREME, "Writing resource");
out.writeBytes(binData.toByteArray());
file.close();
String whichOS = System.getProperty("os.name");
if (whichOS.contains("Windows"))
url.setUrl("file:///"+file.fileName());
else
url.setUrl("file://"+file.fileName());
// fileWatcher.removePath(file.fileName());
logger.log(logger.EXTREME, "Adding file watcher " +file.fileName());
fileWatcher.addPath(file.fileName());
// If we can't open it, then prompt the user to save it.
if (!QDesktopServices.openUrl(url)) {
logger.log(logger.EXTREME, "We can't handle this. Where do we put it?");
QFileDialog dialog = new QFileDialog();
dialog.show();
if (dialog.exec()!=0) {
List<String> fileNames = dialog.selectedFiles(); //gets all selected filenames
if (fileNames.size() == 0)
return;
String sf = fileNames.get(0);
QFile saveFile = new QFile(sf);
mode.set(QFile.OpenModeFlag.WriteOnly);
saveFile.open(mode);
QDataStream saveOut = new QDataStream(saveFile);
saveOut.writeBytes(binData.toByteArray());
saveFile.close();
return;
}
}
}