fileName = f;
errorMessage = "";
lastError = 0;
errorMessage = "";
QFile xmlFile = new QFile(fileName);
if (!xmlFile.open(QIODevice.OpenModeFlag.ReadOnly)) {
lastError = 16;
errorMessage = "Cannot open file.";
}
reader = new QXmlStreamReader(xmlFile);
while (!reader.atEnd()) {
reader.readNext();
if (reader.hasError()) {
errorMessage = reader.errorString();
logger.log(logger.LOW, "************************* ERROR READING BACKUP " +reader.errorString());
lastError = 16;
return;
}
if (reader.name().equalsIgnoreCase("nevernote-export") && reader.isStartElement()) {
QXmlStreamAttributes attributes = reader.attributes();
String version = attributes.value("version");
String type = attributes.value("exportType");
String application = attributes.value("application");
if (!version.equalsIgnoreCase("0.85") && !version.equalsIgnoreCase("0.86")
&& !version.equalsIgnoreCase("0.95")) {
lastError = 1;
errorMessage = "Unknown backup version = " +version;
return;
}
if (!application.equalsIgnoreCase("NeverNote")) {
lastError = 2;
errorMessage = "This backup is from an unknown application = " +application;
return;
}
if (!type.equalsIgnoreCase("backup") && backup) {
lastError = 4;
errorMessage = "This is an export file, not a backup file";
return;
}
if (type.equalsIgnoreCase("export") && backup) {
lastError = 5;
errorMessage = "This is a backup file, not an export file";
return;
}
}
if (reader.name().equalsIgnoreCase("Synchronization") && reader.isStartElement() && backup) {
processSynchronizationNode();
conn.getSyncTable().setLastSequenceDate(lastSequenceDate);
conn.getSyncTable().setUpdateSequenceNumber(highUpdateSequenceNumber);
}
if (reader.name().equalsIgnoreCase("note") && reader.isStartElement()) {
processNoteNode();
if (backup)
conn.getNoteTable().addNote(note, noteIsDirty);
else {
note.setUpdateSequenceNum(0);
if (notebookGuid != null)
note.setNotebookGuid(notebookGuid);
for (int i=0; i<note.getResourcesSize(); i++) {
note.getResources().get(i).setUpdateSequenceNum(0);
}
conn.getNoteTable().addNote(note, true);
}
if (metaData.containsKey(note.getGuid()))
conn.getNoteTable().updateNoteMetadata(metaData.get(note.getGuid()));
}
if (reader.name().equalsIgnoreCase("notebook") && reader.isStartElement() && (backup || importNotebooks)) {
processNotebookNode();
String existingGuid = conn.getNotebookTable().findNotebookByName(notebook.getName());
if (existingGuid == null) {
conn.getNotebookTable().addNotebook(notebook, notebookIsDirty, notebookIsLocal);
} else {
conn.getNotebookTable().updateNotebookGuid(existingGuid, notebook.getGuid());
conn.getNotebookTable().updateNotebook(notebook, notebookIsDirty);
}
conn.getNotebookTable().setIcon(notebook.getGuid(), notebookIcon, "PNG");
conn.getNotebookTable().setReadOnly(notebook.getGuid(), notebookIsReadOnly);
}
if (reader.name().equalsIgnoreCase("tag") && reader.isStartElement() && (backup || importTags)) {
processTagNode();
String testGuid = conn.getTagTable().findTagByName(tag.getName());
if (testGuid == null)
conn.getTagTable().addTag(tag, tagIsDirty);
else {
conn.getTagTable().updateTagGuid(testGuid, tag.getGuid());
conn.getTagTable().updateTag(tag,tagIsDirty);
}
}
if (reader.name().equalsIgnoreCase("savedsearch") && reader.isStartElement() && backup) {
processSavedSearchNode();
conn.getSavedSearchTable().addSavedSearch(search, searchIsDirty);
}
if (reader.name().equalsIgnoreCase("LinkedNotebook") && reader.isStartElement() && backup) {
processLinkedNotebookNode();
conn.getLinkedNotebookTable().addNotebook(linkedNotebook, linkedNotebookIsDirty);
}
if (reader.name().equalsIgnoreCase("SharedNotebook") && reader.isStartElement() && backup) {
processSharedNotebookNode();
conn.getSharedNotebookTable().addNotebook(sharedNotebook, sharedNotebookIsDirty);
}
}
xmlFile.close();
}