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.Notebook;\r
+import com.trolltech.qt.core.QBuffer;\r
+import com.trolltech.qt.core.QByteArray;\r
+import com.trolltech.qt.core.QIODevice;\r
+import com.trolltech.qt.gui.QIcon;\r
+import com.trolltech.qt.gui.QImage;\r
+import com.trolltech.qt.gui.QPixmap;\r
\r
import cx.fbn.nevernote.sql.driver.NSqlQuery;\r
import cx.fbn.nevernote.utilities.ApplicationLogger;\r
NSqlQuery query = new NSqlQuery(db.getConnection());\r
logger.log(logger.HIGH, "Creating table Notebook...");\r
if (!query.exec("Create table Notebook (guid varchar primary key, " +\r
- "sequence integer, name varchar, defaultNotebook varchar, "+\r
- "serviceCreated timestamp, serviceUpdated timestamp, published boolean, isDirty boolean, "+\r
- "autoEncrypt boolean, local boolean, archived boolean)")) \r
+ "sequence integer, " +\r
+ "name varchar, "+\r
+ "defaultNotebook varchar, "+\r
+ "serviceCreated timestamp, " +\r
+ "serviceUpdated timestamp, "+\r
+ "published boolean, "+\r
+ "isDirty boolean, "+\r
+ "autoEncrypt boolean, "+\r
+ "local boolean, "+\r
+ "archived boolean)")) \r
logger.log(logger.HIGH, "Table Notebook creation FAILED!!!"); \r
Notebook newnote = new Notebook();\r
newnote.setDefaultNotebook(true);\r
}\r
// Reset the dirty flag. Typically done after a sync.\r
public void resetDirtyFlag(String guid) {\r
- \r
NSqlQuery query = new NSqlQuery(db.getConnection());\r
\r
query.prepare("Update notebook set isdirty='false' where guid=:guid");\r
if (!query.exec())\r
logger.log(logger.EXTREME, "Error resetting notebook dirty field.");\r
}\r
+ // Set the default notebook\r
+ public void setDefaultNotebook(String guid) {\r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ \r
+ query.prepare("Update notebook set defaultNotebook=false");\r
+ if (!query.exec())\r
+ logger.log(logger.EXTREME, "Error removing default notebook.");\r
+ query.prepare("Update notebook set defaultNotebook=true where guid = :guid");\r
+ query.bindValue(":guid", guid);\r
+ if (!query.exec())\r
+ logger.log(logger.EXTREME, "Error setting default notebook.");\r
+ }\r
\r
+ // Get a list of all icons\r
+ public HashMap<String, QIcon> getAllIcons() {\r
+ HashMap<String, QIcon> values = new HashMap<String, QIcon>();\r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
\r
+ if (!query.exec("SELECT guid, icon from notebook where ARCHIVED != true"))\r
+ logger.log(logger.EXTREME, "Error executing notebook getAllIcons select.");\r
+ while (query.next()) {\r
+ if (query.getBlob(1) != null) {\r
+ String guid = query.valueString(0);\r
+ QByteArray blob = new QByteArray(query.getBlob(1));\r
+ QIcon icon = new QIcon(QPixmap.fromImage(QImage.fromData(blob)));\r
+ values.put(guid, icon);\r
+ }\r
+ }\r
+ return values;\r
+ }\r
\r
+ // Get the notebooks custom icon\r
+ public QIcon getIcon(String guid) {\r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ \r
+ if (!query.prepare("Select icon from notebook where guid=:guid"))\r
+ logger.log(logger.EXTREME, "Error preparing notebook icon select.");\r
+ query.bindValue(":guid", guid);\r
+ if (!query.exec())\r
+ logger.log(logger.EXTREME, "Error finding notebook icon.");\r
+ if (!query.next() || query.getBlob(0) == null)\r
+ return null;\r
+ \r
+ QByteArray blob = new QByteArray(query.getBlob(0));\r
+ QIcon icon = new QIcon(QPixmap.fromImage(QImage.fromData(blob)));\r
+ return icon;\r
+ }\r
+ // Set the notebooks custom icon\r
+ public void setIcon(String guid, QIcon icon, String type) {\r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ if (icon == null) {\r
+ if (!query.prepare("update notebook set icon=null where guid=:guid"))\r
+ logger.log(logger.EXTREME, "Error preparing notebook icon select.");\r
+ } else {\r
+ if (!query.prepare("update notebook set icon=:icon where guid=:guid"))\r
+ logger.log(logger.EXTREME, "Error preparing notebook icon select.");\r
+ QBuffer buffer = new QBuffer();\r
+ if (!buffer.open(QIODevice.OpenModeFlag.ReadWrite)) {\r
+ logger.log(logger.EXTREME, "Failure to open buffer. Aborting.");\r
+ return;\r
+ }\r
+ QPixmap p = icon.pixmap(32, 32);\r
+ QImage i = p.toImage();\r
+ i.save(buffer, type.toUpperCase());\r
+ buffer.close();\r
+ QByteArray b = new QByteArray(buffer.buffer());\r
+ if (!b.isNull() && !b.isEmpty())\r
+ query.bindValue(":icon", b.toByteArray());\r
+ else\r
+ return;\r
+ }\r
+ query.bindValue(":guid", guid);\r
+ if (!query.exec()) \r
+ logger.log(logger.LOW, "Error setting notebook icon. " +query.lastError());\r
+ }\r
\r
// does a record exist?\r
public String findNotebookByName(String newname) {\r