import java.text.ParseException;\r
import java.text.SimpleDateFormat;\r
import java.util.ArrayList;\r
+import java.util.HashMap;\r
import java.util.List;\r
\r
import com.evernote.edam.type.Note;\r
import com.trolltech.qt.core.QByteArray;\r
import com.trolltech.qt.core.QDateTime;\r
import com.trolltech.qt.core.QTextCodec;\r
+import com.trolltech.qt.gui.QPixmap;\r
\r
import cx.fbn.nevernote.Global;\r
import cx.fbn.nevernote.evernote.EnmlConverter;\r
query.next();\r
return query.valueString(0);\r
}\r
+ // Get a note's content in blob format for index.\r
+ public String getNoteContentNoUTFConversion(String guid) {\r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ query.prepare("Select content from note where guid=:guid");\r
+ query.bindValue(":guid", guid);\r
+ query.exec(); \r
+ query.next();\r
+ return query.valueString(0);\r
+ }\r
// Get a note by Guid\r
public Note getNote(String noteGuid, boolean loadContent, boolean loadResources, boolean loadRecognition, boolean loadBinary, boolean loadTags) {\r
if (noteGuid == null)\r
// Update a note's title\r
public void updateNoteContent(String guid, String content) {\r
NSqlQuery query = new NSqlQuery(db.getConnection());\r
- boolean check = query.prepare("Update Note set content=:content, updated=CURRENT_TIMESTAMP(), isDirty=true, indexNeeded=true " +\r
- " where guid=:guid");\r
+ boolean check = query.prepare("Update Note set content=:content, updated=CURRENT_TIMESTAMP(), isDirty=true, indexNeeded=true, " +\r
+ " thumbnailneeded=true where guid=:guid");\r
if (!check) {\r
logger.log(logger.EXTREME, "Update note content sql prepare has failed.");\r
logger.log(logger.MEDIUM, query.lastError());\r
boolean check; \r
NSqlQuery query = new NSqlQuery(db.getConnection());\r
\r
- check = query.exec("Select guid from Note where isDirty = true and isExpunged = false and notebookGuid not in (select guid from notebook where local = true)");\r
+ check = query.exec("Select guid from Note where isDirty = true and isExpunged = false and notebookGuid not in (select guid from notebook where local = true or linked = true)");\r
if (!check) \r
logger.log(logger.EXTREME, "Note SQL retrieve has failed: " +query.lastError().toString());\r
\r
return notes; \r
}\r
// Get a list of notes that need to be updated\r
+ public List <Note> getDirtyLinked(String notebookGuid) {\r
+ String guid;\r
+ Note tempNote;\r
+ List<Note> notes = new ArrayList<Note>();\r
+ List<String> index = new ArrayList<String>();\r
+ \r
+ boolean check; \r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ \r
+ query.prepare("Select guid from Note where isDirty = true and isExpunged = false and notebookGuid=:notebookGuid");\r
+ query.bindValue(":notebookGuid", notebookGuid);\r
+ check = query.exec();\r
+ if (!check) \r
+ logger.log(logger.EXTREME, "Note SQL retrieve has failed getting dirty linked notes: " +query.lastError().toString());\r
+ \r
+ // Get a list of the notes\r
+ while (query.next()) {\r
+ guid = new String();\r
+ guid = query.valueString(0);\r
+ index.add(guid); \r
+ } \r
+ \r
+ // Start getting notes\r
+ for (int i=0; i<index.size(); i++) {\r
+ tempNote = getNote(index.get(i), true,true,false,true,true);\r
+ notes.add(tempNote);\r
+ }\r
+ return notes; \r
+ }\r
+ // Get a list of notes that need to be updated\r
+ public List <String> getNotesByNotebook(String notebookGuid) {\r
+ List<String> notes = new ArrayList<String>();\r
+ List<String> index = new ArrayList<String>();\r
+ \r
+ boolean check; \r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ \r
+ check = query.prepare("Select guid from Note where notebookguid=:notebookguid");\r
+ if (!check) \r
+ logger.log(logger.EXTREME, "Note SQL retrieve has failed: " +query.lastError().toString());\r
+ query.bindValue(":notebookguid", notebookGuid);\r
+ query. exec();\r
+ \r
+ // Get a list of the notes\r
+ while (query.next()) {\r
+ index.add(query.valueString(0)); \r
+ } \r
+ \r
+ return notes; \r
+ }\r
+ // Get a list of notes that need to be updated\r
public boolean isNoteDirty(String guid) {\r
\r
boolean check; \r
boolean check; \r
NSqlQuery query = new NSqlQuery(db.getConnection());\r
\r
- check = query.exec("Select guid from Note where isDirty = true");\r
+ check = query.exec("Select guid from Note where isDirty=true");\r
if (!check) \r
logger.log(logger.EXTREME, "Note SQL retrieve has failed: " +query.lastError().toString());\r
\r
// Count unsynchronized notes\r
public int getDirtyCount() {\r
NSqlQuery query = new NSqlQuery(db.getConnection());\r
- query.exec("select count(*) from note where isDirty=true and isExpunged = false");\r
+ query.exec("select count(guid) from note where isDirty=true and isExpunged = false");\r
query.next(); \r
int returnValue = new Integer(query.valueString(0));\r
return returnValue;\r
return note.replace("<div/>", "<div> </div>");\r
}\r
\r
+ // Expunge notes that we don't want to synchronize\r
+ public List<String> expungeIgnoreSynchronizedNotes(List<String> notebooks, List<String>tags, List<String> linked) {\r
+ \r
+ List<String> noteGuids = new ArrayList<String>();\r
+ for (int i=0; i<notebooks.size(); i++) {\r
+ List<String> notes = findNotesByNotebook(notebooks.get(i));\r
+ for (int j=0; j<notes.size(); j++) {\r
+ if (!isNoteDirty(notes.get(j))) {\r
+ expungeNote(notes.get(j), true, false);\r
+ noteGuids.add(notes.get(j));\r
+ }\r
+ }\r
+ }\r
+ \r
+ for (int i=0; i<tags.size(); i++) {\r
+ List<String> notes = findNotesByTag(tags.get(i));\r
+ for (int j=0; j<notes.size(); j++) {\r
+ if (!isNoteDirty(notes.get(j))) {\r
+ expungeNote(notes.get(j), true, false);\r
+ noteGuids.add(notes.get(j));\r
+ }\r
+ }\r
+ }\r
+ \r
+ for (int i=0; i<linked.size(); i++) {\r
+ String notebookGuid = db.getLinkedNotebookTable().getNotebookGuid(linked.get(i));\r
+ if (notebookGuid != null && !notebookGuid.trim().equals("")) {\r
+ List<Tag> linkedTags = db.getTagTable().getTagsForNotebook(notebookGuid);\r
+ for (int j=0; j<linkedTags.size(); j++)\r
+ db.getTagTable().expungeTag(linkedTags.get(j).getGuid(), false);\r
+ \r
+ List<String> notes = findNotesByNotebook(notebookGuid);\r
+ for (int j=0; j<notes.size(); j++) {\r
+ if (!isNoteDirty(notes.get(j))) {\r
+ expungeNote(notes.get(j), true, false);\r
+ noteGuids.add(notes.get(j));\r
+ }\r
+ }\r
+ }\r
+ }\r
+ return noteGuids;\r
+ }\r
+ \r
+ // Find a note by its notebook\r
+ // Expunge notes that we don't want to synchronize\r
+ public List<String> findNotesByNotebook(String notebook) {\r
+ List<String> values = new ArrayList<String>();\r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ query.prepare("Select guid from note where notebookguid=:notebook");\r
+\r
+ query.bindValue(":notebook", notebook);\r
+ query.exec();\r
+ while (query.next()) {\r
+ values.add(query.valueString(0));\r
+ }\r
+ return values;\r
+ }\r
+ \r
+ public List<String> findNotesByTag(String tag) {\r
+ List<String> values = new ArrayList<String>();\r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ query.prepare("Select distinct noteguid from notetags where tagguid=:tag");\r
+\r
+ query.bindValue(":tag", tag);\r
+ query.exec();\r
+ while (query.next()) {\r
+ values.add(query.valueString(0));\r
+ }\r
+ return values;\r
+ }\r
+ \r
\r
\r
//********************************************************************************\r
logger.log(logger.MEDIUM, "Note indexNeeded update failed.");\r
logger.log(logger.MEDIUM, query.lastError());\r
} \r
+ List<Resource> r = noteResourceTable.getNoteResources(guid, false);\r
+ for (int i=0; r!= null && i<r.size(); i++) {\r
+ noteResourceTable.setIndexNeeded(r.get(i).getGuid(), true);\r
+ }\r
}\r
// Set all notes to be reindexed\r
public void reindexAllNotes() {\r
List<Pair<String,Integer>> returnValue = new ArrayList<Pair<String,Integer>>();\r
NSqlQuery query = new NSqlQuery(db.getConnection());\r
\r
- if (!query.exec("Select titleColor from Note where titleColor != -1 and guid=:guid"))\r
+ query.prepare("Select titleColor from Note where titleColor != -1 and guid=:guid");\r
+ query.bindValue(":guid", guid);\r
+ if (!query.exec())\r
logger.log(logger.EXTREME, "Note SQL retrieve has failed on getNoteTitleColor(guid).");\r
\r
Integer color = -1;\r
if (!check) \r
logger.log(logger.EXTREME, "Note SQL get thumbail failed: " +query.lastError().toString());\r
// Get a list of the notes\r
- if (query.next()) \r
- if (query.getBlob(0) != null)\r
- return new QByteArray(query.getBlob(0)); \r
+ if (query.next()) {\r
+ try {\r
+ if (query.getBlob(0) != null) {\r
+ return new QByteArray(query.getBlob(0)); \r
+ }\r
+ } catch (java.lang.IllegalArgumentException e) {\r
+ return null;\r
+ }\r
+ }\r
return null;\r
}\r
- \r
+ // Get all thumbnails\r
+ public HashMap<String, QPixmap> getThumbnails() {\r
+ boolean check; \r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ HashMap<String, QPixmap> map = new HashMap<String,QPixmap>();\r
+ \r
+ check = query.prepare("Select guid,thumbnail from note where thumbnailneeded=false and isExpunged=false");\r
+ check = query.exec();\r
+ if (!check) \r
+ logger.log(logger.EXTREME, "Note SQL get thumbail failed: " +query.lastError().toString());\r
+ // Get a list of the notes\r
+ while (query.next()) {\r
+ try {\r
+ if (query.getBlob(1) != null) {\r
+ QByteArray data = new QByteArray(query.getBlob(1));\r
+ QPixmap img = new QPixmap();\r
+ if (img.loadFromData(data)) {\r
+ img = img.scaled(Global.largeThumbnailSize);\r
+ map.put(query.valueString(0), img);\r
+ }\r
+ } \r
+ } catch (java.lang.IllegalArgumentException e) {\r
+ logger.log(logger.HIGH, "Error retrieving thumbnail " +e.getMessage());\r
+ }\r
+ }\r
+ return map;\r
+ }\r
+ // Get a list of notes that need thumbnails\r
+ public List<String> findThumbnailsNeeded() {\r
+ \r
+ boolean check;\r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ \r
+ check = query.prepare("select guid from note where thumbnailneeded=true and isExpunged=false and DATEDIFF('MINUTE',updated,CURRENT_TIMESTAMP)>5 limit 5");\r
+ check = query.exec();\r
+ if (!check) \r
+ logger.log(logger.EXTREME, "Note SQL findThumbnailsNeeded query failed: " +query.lastError().toString());\r
+ \r
+\r
+ // Get a list of the notes\r
+ List<String> values = new ArrayList<String>();\r
+ while (query.next()) {\r
+ values.add(query.valueString(0)); \r
+ }\r
+\r
+ return values; \r
+ }\r
+ // Get a count of thumbnails needed\r
+ public int getThumbnailNeededCount() {\r
+ \r
+ boolean check;\r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ \r
+ check = query.prepare("select count(guid) from note where thumbnailneeded=true and isExpunged=false and DATEDIFF('MINUTE',updated,CURRENT_TIMESTAMP)>5 limit 2");\r
+ check = query.exec();\r
+ if (!check) \r
+ logger.log(logger.EXTREME, "Note SQL findThumbnailNeededCount query failed: " +query.lastError().toString());\r
+ \r
+ if (query.next()) {\r
+ return query.valueInteger(0); \r
+ }\r
+\r
+ return 0; \r
+ }\r
+\r
\r
// Update a note content's hash. This happens if a resource is edited outside of NN\r
public void updateResourceContentHash(String guid, String oldHash, String newHash) {\r
newSegment +\r
n.getContent().substring(endPos);\r
NSqlQuery query = new NSqlQuery(db.getConnection());\r
- query.prepare("update note set isdirty=true, content=:content where guid=:guid");\r
+ query.prepare("update note set isdirty=true, thumbnailneeded=true, content=:content where guid=:guid");\r
query.bindValue(":content", content);\r
query.bindValue(":guid", n.getGuid());\r
query.exec();\r