import cx.fbn.nevernote.utilities.Pair;\r
\r
public class Global {\r
- public static String version = "0.98";\r
- public static String[] validVersions = {"0.98", "0.97", "0.96"};\r
+ public static String version = "0.99";\r
+ public static String[] validVersions = {"0.99", "0.98", "0.97", "0.96"};\r
public static String username = ""; \r
public static String password = ""; \r
\r
js.replace("<!DOCTYPE en-note SYSTEM 'http://xml.evernote.com/pub/enml.dtd'>", "");
js.replace("<!DOCTYPE en-note SYSTEM 'http://xml.evernote.com/pub/enml2.dtd'>", "");
js.replace("<?xml version='1.0' encoding='UTF-8'?>", "");
- browser.getBrowser().setContent(js);
+// if (Global.enableHTMLEntitiesFix) {
+// browser.getBrowser().setContent(new QByteArray(StringEscapeUtils.unescapeHtml(js.toString())));
+// } else
+ browser.getBrowser().setContent(js);
noteCache.put(currentNoteGuid, js.toString());
if (formatter.resourceError)
newNote.setUpdateSequenceNum(0);
newNote.setGuid(randint);
newNote.setNotebookGuid(notebook);
- newNote.setTitle("");
+ newNote.setTitle("Untitled Note");
newNote.setContent(noteString.toString());
newNote.setDeleted(0);
newNote.setCreated(System.currentTimeMillis());
// If the window is hidden, then we want to popup this in an external window &
if (!isVisible())
listDoubleClick();
+ waitCursor(false);
logger.log(logger.HIGH, "Leaving NeverNote.addNote");
}
// Restore a note from the trash;
import cx.fbn.nevernote.utilities.ApplicationLogger;\r
import cx.fbn.nevernote.utilities.FileUtils;\r
import cx.fbn.nevernote.utilities.Pair;\r
+import cx.fbn.nevernote.xml.HtmlTagModifier;\r
\r
public class BrowserWindow extends QWidget {\r
\r
logger.log(logger.EXTREME, "Bytes writtes: "+tfile.size());\r
tfile.close();\r
logger.log(logger.EXTREME, "Creating resource");\r
- newRes = createResource(path,0,"image/gif", false);\r
+ int sequence = 0;\r
+ if (currentNote.getResources() != null || currentNote.getResources().size() > 0)\r
+ sequence = currentNote.getResources().size();\r
+ newRes = createResource(path,sequence ,"image/gif", false);\r
+ QImage pix = new QImage();\r
+ pix.loadFromData(image);\r
+ newRes.setHeight(new Integer(pix.height()).shortValue());\r
+ newRes.setWidth(new Integer(pix.width()).shortValue());\r
logger.log(logger.EXTREME, "Renaming temporary file to " +newRes.getGuid()+".gif");\r
path = Global.getFileManager().getResDirPath(newRes.getGuid()+".gif");\r
tfile.rename(path);\r
tfile.write(image);\r
tfile.close();\r
newRes.getData().setBody(image.toByteArray());\r
+ // Calculate the new hash value\r
+ MessageDigest md;\r
+\r
+ logger.log(logger.EXTREME, "Generating MD5");\r
+ try {\r
+ md = MessageDigest.getInstance("MD5");\r
+ md.update(image.toByteArray());\r
+ byte[] hash = md.digest();\r
+ newRes.getData().setBodyHash(hash);\r
+ } catch (NoSuchAlgorithmException e) {\r
+ e.printStackTrace();\r
+ }\r
+ QImage pix = new QImage();\r
+ pix.loadFromData(image);\r
+ newRes.setHeight(new Integer(pix.height()).shortValue());\r
+ newRes.setWidth(new Integer(pix.width()).shortValue());\r
conn.getNoteTable().noteResourceTable.updateNoteResource(newRes, true);\r
}\r
\r
currentNote.getResources().add(newRes);\r
\r
\r
- // do the actual insert into the note. We only do this on new formulas. Existing ones we\r
- // just write out the file (which is aleady done) and reload.\r
+ // do the actual insert into the note. We only do this on new formulas. \r
if (latexGuid == null) {\r
StringBuffer buffer = new StringBuffer(100);\r
String formula = replyUrl.toString().toLowerCase().replace("http://latex.codecogs.com/gif.latex?", "");\r
String script_end = new String("');");\r
browser.page().mainFrame().evaluateJavaScript(\r
script_start + buffer + script_end);\r
+ } else {\r
+ HtmlTagModifier modifier = new HtmlTagModifier(getContent());\r
+ modifier.modifyLatexTagHash(newRes);\r
+ String newContent = modifier.getHtml();\r
+ browser.setContent(new QByteArray(newContent));\r
}\r
\r
logger.log(logger.EXTREME, "New HTML set\n" +browser.page().currentFrame().toHtml());\r
// resourceSignal.contentChanged.emit(path);\r
unblockTime = -1;\r
unblockApplication.emit();\r
-\r
return;\r
\r
}\r
}\r
// Create the table\r
public void createTable() {\r
- getQueryWithContent = new NSqlQuery(db.getConnection());\r
- getQueryWithoutContent = new NSqlQuery(db.getConnection());\r
+ //getQueryWithContent = new NSqlQuery(db.getConnection());\r
+ //getQueryWithoutContent = new NSqlQuery(db.getConnection());\r
NSqlQuery query = new NSqlQuery(db.getConnection());\r
logger.log(logger.HIGH, "Creating table Note...");\r
if (!query.exec("Create table Note (guid varchar primary key, " +\r
for (int i=0; i<n.getTagGuids().size(); i++) \r
noteTagsTable.saveNoteTag(n.getGuid(), n.getTagGuids().get(i));\r
}\r
- \r
logger.log(logger.EXTREME, "Leaving addNote");\r
} \r
// Setup queries for get to save time later\r
private void prepareQueries() {\r
- if (getQueryWithContent != null)\r
- return;\r
- getQueryWithContent = new NSqlQuery(db.getConnection());\r
- getQueryWithoutContent = new NSqlQuery(db.getConnection());\r
- getAllQueryWithoutContent = new NSqlQuery(db.getConnection());\r
- \r
- if (!getQueryWithContent.prepare("Select "\r
- +"guid, updateSequenceNumber, title, "\r
- +"created, updated, deleted, active, notebookGuid, "\r
- +"attributeSubjectDate, attributeLatitude, attributeLongitude, attributeAltitude, "\r
- +"attributeAuthor, attributeSource, attributeSourceUrl, attributeSourceApplication, "\r
- +"content, contentHash, contentLength"\r
- +" from Note where guid=:guid and isExpunged=false")) {\r
- logger.log(logger.EXTREME, "Note SQL select prepare with content has failed.");\r
- logger.log(logger.MEDIUM, getQueryWithContent.lastError());\r
+ if (getQueryWithContent == null) {\r
+ getQueryWithContent = new NSqlQuery(db.getConnection());\r
+ if (!getQueryWithContent.prepare("Select "\r
+ +"guid, updateSequenceNumber, title, "\r
+ +"created, updated, deleted, active, notebookGuid, "\r
+ +"attributeSubjectDate, attributeLatitude, attributeLongitude, attributeAltitude, "\r
+ +"attributeAuthor, attributeSource, attributeSourceUrl, attributeSourceApplication, "\r
+ +"content, contentHash, contentLength"\r
+ +" from Note where guid=:guid and isExpunged=false")) {\r
+ logger.log(logger.EXTREME, "Note SQL select prepare with content has failed.");\r
+ logger.log(logger.MEDIUM, getQueryWithContent.lastError());\r
+ }\r
}\r
\r
- if (!getQueryWithoutContent.prepare("Select "\r
- +"guid, updateSequenceNumber, title, "\r
- +"created, updated, deleted, active, notebookGuid, "\r
- +"attributeSubjectDate, attributeLatitude, attributeLongitude, attributeAltitude, "\r
- +"attributeAuthor, attributeSource, attributeSourceUrl, attributeSourceApplication "\r
- +" from Note where guid=:guid and isExpunged=false")) {\r
- logger.log(logger.EXTREME, "Note SQL select prepare without content has failed.");\r
- logger.log(logger.MEDIUM, getQueryWithoutContent.lastError());\r
+ if (getQueryWithoutContent == null) {\r
+ getQueryWithoutContent = new NSqlQuery(db.getConnection());\r
+ if (!getQueryWithoutContent.prepare("Select "\r
+ +"guid, updateSequenceNumber, title, "\r
+ +"created, updated, deleted, active, notebookGuid, "\r
+ +"attributeSubjectDate, attributeLatitude, attributeLongitude, attributeAltitude, "\r
+ +"attributeAuthor, attributeSource, attributeSourceUrl, attributeSourceApplication "\r
+ +" from Note where guid=:guid and isExpunged=false")) {\r
+ logger.log(logger.EXTREME, "Note SQL select prepare without content has failed.");\r
+ logger.log(logger.MEDIUM, getQueryWithoutContent.lastError());\r
+ }\r
}\r
- if (!getAllQueryWithoutContent.prepare("Select "\r
+ \r
+ if (getAllQueryWithoutContent == null) {\r
+ getAllQueryWithoutContent = new NSqlQuery(db.getConnection());\r
+ \r
+ if (!getAllQueryWithoutContent.prepare("Select "\r
+"guid, updateSequenceNumber, title, "\r
+"created, updated, deleted, active, notebookGuid, "\r
+"attributeSubjectDate, attributeLatitude, attributeLongitude, attributeAltitude, "\r
+"attributeAuthor, attributeSource, attributeSourceUrl, attributeSourceApplication "\r
+" from Note where isExpunged = false")) {\r
- logger.log(logger.EXTREME, "Note SQL select prepare without content has failed.");\r
+ logger.log(logger.EXTREME, "Note SQL select prepare without content has failed.");\r
logger.log(logger.MEDIUM, getQueryWithoutContent.lastError());\r
+ }\r
}\r
}\r
\r
codec = QTextCodec.codecForName("UTF-8");\r
String unicode = codec.fromUnicode(query.valueString(16)).toString();\r
\r
- if (Global.enableHTMLEntitiesFix)\r
- unicode = codec.fromUnicode(StringEscapeUtils.unescapeXml(query.valueString(16).toString())).toString();\r
- \r
+ // This is a hack. Basically I need to convert HTML Entities to "normal" text, but if I\r
+ // convert the < character to < it will mess up the XML parsing. So, to get around this\r
+ // I am "bit stuffing" the < to &< so StringEscapeUtils doesn't unescape it. After\r
+ // I'm done I convert it back.\r
+ if (Global.enableHTMLEntitiesFix && unicode.indexOf("&#") > 0) {\r
+ unicode = query.valueString(16);\r
+ unicode = unicode.replace("<", "&_lt;");\r
+ unicode = codec.fromUnicode(StringEscapeUtils.unescapeHtml(unicode)).toString();\r
+ unicode = unicode.replace("&_lt;", "<");\r
+ }\r
+ \r
n.setContent(unicode);\r
// n.setContent(query.valueString(16).toString());\r
\r
public List<Note> getAllNotes() {\r
List<Note> notes = new ArrayList<Note>();\r
prepareQueries();\r
- boolean check; \r
+ boolean check; \r
+ if (getAllQueryWithoutContent == null) \r
+ prepareQueries();\r
NSqlQuery query = getAllQueryWithoutContent;\r
check = query.exec();\r
if (!check)\r
position = n.getContent().indexOf("<en-media", position+1);\r
}\r
}\r
+\r
} \r
+\r
+\r
+\r
+\r
--- /dev/null
+/*\r
+ * This file is part of NeverNote \r
+ * Copyright 2009 Randy Baumgarte\r
+ * \r
+ * This file may be licensed under the terms of of the\r
+ * GNU General Public License Version 2 (the ``GPL'').\r
+ *\r
+ * Software distributed under the License is distributed\r
+ * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
+ * express or implied. See the GPL for the specific language\r
+ * governing rights and limitations.\r
+ *\r
+ * You should have received a copy of the GPL along with this\r
+ * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
+ * or write to the Free Software Foundation, Inc.,\r
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
+ *\r
+*/\r
+\r
+\r
+package cx.fbn.nevernote.xml;\r
+\r
+import com.evernote.edam.type.Resource;\r
+\r
+import cx.fbn.nevernote.Global;\r
+\r
+public class HtmlTagModifier {\r
+ StringBuffer html;\r
+\r
+ public HtmlTagModifier() {\r
+ html = null;\r
+ }\r
+ \r
+ public HtmlTagModifier(String data) {\r
+ html = new StringBuffer(data);\r
+ }\r
+ \r
+ public void setHtml(String data) {\r
+ html = new StringBuffer(data);\r
+ }\r
+ \r
+ public String getHtml() {\r
+ return html.toString();\r
+ }\r
+ \r
+ public void modifyLatexTagHash(Resource res) {\r
+ \r
+ int position = 0;\r
+ for (; position<html.length();) {\r
+ position = html.indexOf("<img", position);\r
+ if (position > 0) {\r
+ if (matchesGuid(position, res.getGuid())) {\r
+ replaceValue(position, "height", new Integer(res.getHeight()).toString());\r
+ replaceValue(position, "width", new Integer(res.getWidth()).toString());\r
+ replaceValue(position, "hash", Global.byteArrayToHexString(res.getData().getBodyHash()));\r
+ return;\r
+ } \r
+ }\r
+ position = position+1;\r
+ }\r
+ return;\r
+ }\r
+ \r
+ \r
+ private boolean matchesGuid(int position, String guid) {\r
+ int endPosition = html.indexOf(">", position);\r
+ if (endPosition < 0)\r
+ return false;\r
+ \r
+ int guidPos = html.indexOf(guid, position);\r
+ if (guidPos > endPosition) \r
+ return false;\r
+ else\r
+ return true;\r
+ }\r
+ \r
+ public void replaceValue(int position, String attribute, String newValue) {\r
+ int endPosition = html.indexOf(">", position);\r
+ if (endPosition < 0)\r
+ return;\r
+ \r
+ int attributeStart = html.indexOf(attribute, position);\r
+ if (attributeStart < 0)\r
+ return;\r
+ \r
+ int attributeEnd = html.indexOf(" ", attributeStart);\r
+ if (attributeEnd < 0 || endPosition < attributeEnd) \r
+ attributeEnd = endPosition-1;\r
+ \r
+ attributeStart = attributeStart+2+attribute.length();\r
+ html = html.delete(attributeStart, endPosition-1);\r
+ html = html.insert(attributeStart, newValue);\r
+ \r
+ }\r
+}\r