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
// 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
}\r
}\r
\r
-/* \r
- // Check a note to see if it passes the attribute selection criteria\r
- public boolean checkAttributeSelection(Note n) {\r
- if (Global.createdSinceFilter.check(n) &&\r
- Global.createdBeforeFilter.check(n) && \r
- Global.changedSinceFilter.check(n) &&\r
- Global.changedBeforeFilter.check(n) &&\r
- Global.containsFilter.check(this, n))\r
- return true;\r
- \r
- return false;\r
- }\r
-*/\r
// Delete a note\r
public void deleteNote(String guid) {\r
NSqlQuery query = new NSqlQuery(db.getConnection());\r
// Update a note\r
public void updateNote(Note n, boolean isNew) {\r
boolean isExpunged = isNoteExpunged(n.getGuid());\r
- \r
+ int titleColor = getNoteTitleColor(n.getGuid());\r
expungeNote(n.getGuid(), !isExpunged, false);\r
addNote(n, false);\r
+ if (titleColor != -1)\r
+ setNoteTitleColor(n.getGuid(), titleColor);\r
}\r
// Does a note exist?\r
public boolean exists(String guid) {\r
returnValue.add(pair); \r
} \r
\r
- \r
- \r
return returnValue;\r
}\r
// Set a title color\r
- // Reset the dirty bit\r
public void setNoteTitleColor(String guid, int color) {\r
NSqlQuery query = new NSqlQuery(db.getConnection());\r
\r
if (!query.exec())\r
logger.log(logger.EXTREME, "Error updating title color.");\r
}\r
+ // Get in individual note's title color\r
+ // Get the title color of all notes\r
+ public Integer getNoteTitleColor(String guid) {\r
+ List<Pair<String,Integer>> returnValue = new ArrayList<Pair<String,Integer>>();\r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ \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
+ \r
+ // Get a list of the notes\r
+ while (query.next()) {\r
+ Pair<String, Integer> pair = new Pair<String,Integer>();\r
+ guid = query.valueString(0);\r
+ color = query.valueInteger(1);\r
+ pair.setFirst(guid);\r
+ pair.setSecond(color);\r
+ returnValue.add(pair); \r
+ } \r
+\r
+ \r
+ return color;\r
+ }\r
\r
\r
//**********************************************************************************\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
\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