logger.log(logger.EXTREME, "Creating resource");
int sequence = 0;
if (currentNote.getResources() != null || currentNote.getResources().size() > 0)
sequence = currentNote.getResources().size();
newRes = createResource(path,sequence ,"image/gif", false);
QImage pix = new QImage();
pix.loadFromData(image);
newRes.setHeight(new Integer(pix.height()).shortValue());
newRes.setWidth(new Integer(pix.width()).shortValue());
logger.log(logger.EXTREME, "Renaming temporary file to " +newRes.getGuid()+".gif");
path = Global.getFileManager().getResDirPath(newRes.getGuid()+".gif");
tfile.rename(path);
} else {
newRes = conn.getNoteTable().noteResourceTable.getNoteResource(latexGuid, false);
path = Global.getFileManager().getResDirPath(newRes.getGuid()+".gif");
tfile = new QFile(path);
tfile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.WriteOnly));
tfile.write(image);
tfile.close();
newRes.getData().setBody(image.toByteArray());
// Calculate the new hash value
MessageDigest md;
logger.log(logger.EXTREME, "Generating MD5");
try {
md = MessageDigest.getInstance("MD5");
md.update(image.toByteArray());
byte[] hash = md.digest();
newRes.getData().setBodyHash(hash);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
QImage pix = new QImage();
pix.loadFromData(image);
newRes.setHeight(new Integer(pix.height()).shortValue());
newRes.setWidth(new Integer(pix.width()).shortValue());
conn.getNoteTable().noteResourceTable.updateNoteResource(newRes, true);
}
logger.log(logger.EXTREME, "Setting source: " +replyUrl.toString());
newRes.getAttributes().setSourceURL(replyUrl.toString());