Write out the file to the dbi directory.
| 44 | //* Write out the file to the dbi directory. |
| 45 | //******************************************* |
| 46 | void AddNote::write(QString uuid) { |
| 47 | |
| 48 | QString filename = uuid +".nnex"; |
| 49 | |
| 50 | // We use a temporary file to write to. At the end it will be renamed into |
| 51 | // the DBI directory. We don't write into it because there can be |
| 52 | // timing issues where the FileWatcher picks up the file before |
| 53 | // the entire text is written out and it causes an error. |
| 54 | QFile xmlFile(global.fileManager.getTmpDirPath()+filename); |
| 55 | |
| 56 | |
| 57 | if (!xmlFile.open(QIODevice::WriteOnly)) { |
| 58 | qDebug() << "Unable to open file."; |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | QXmlStreamWriter *writer = new QXmlStreamWriter(&xmlFile); |
| 63 | writer->setAutoFormatting(true); |
| 64 | writer->setCodec("UTF-8"); |
| 65 | writer->writeStartDocument(); |
| 66 | writer->writeDTD("<!DOCTYPE NixNote-Import>"); |
| 67 | writer->writeStartElement("nixnote-import"); |
| 68 | writer->writeAttribute("version", "2"); |
| 69 | writer->writeAttribute("application", "NixNote"); |
| 70 | writer->writeAttribute("applicationVersion", "2.x"); |
| 71 | writer->writeStartElement("NoteAdd"); |
| 72 | |
| 73 | |
| 74 | writer->writeTextElement("Lid", QString::number(lid)); |
| 75 | writer->writeTextElement("Title", title); |
| 76 | |
| 77 | writer->writeStartElement("Content"); |
| 78 | writer->writeCDATA(content); |
| 79 | writer->writeEndElement(); |
| 80 | |
| 81 | if (notebook != "") |
| 82 | writer->writeTextElement("Notebook", notebook); |
| 83 | if (created != "") |
| 84 | writer->writeTextElement("Created", created); |
| 85 | if (updated != "") |
| 86 | writer->writeTextElement("Updated", updated); |
| 87 | if (reminder != "") |
| 88 | writer->writeTextElement("Reminder", reminder); |
| 89 | for (int i=0; i<tags.size(); i++) { |
| 90 | writer->writeTextElement("Tag", tags[i]); |
| 91 | } |
| 92 | for (int i=0; i<attachments.size(); i++) { |
| 93 | writer->writeTextElement("Attachment", attachments[i]); |
| 94 | } |
| 95 | writer->writeTextElement("AttachmentDelimiter", attachmentDelimiter); |
| 96 | writer->writeEndElement(); |
| 97 | writer->writeEndElement(); |
| 98 | writer->writeEndDocument(); |
| 99 | xmlFile.close(); |
| 100 | QFile::rename(global.fileManager.getTmpDirPath()+filename,global.fileManager.getDbiDirPath()+filename); |
| 101 | } |
| 102 | |
| 103 |
no test coverage detected