MCPcopy Create free account
hub / github.com/baumgarr/nixnote2 / write

Method write

cmdtools/addnote.cpp:46–101  ·  view source on GitHub ↗

Write out the file to the dbi directory.

Source from the content-addressed store, hash-verified

44//* Write out the file to the dbi directory.
45//*******************************************
46void 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

Callers 9

runMethod · 0.45
emailNoteMethod · 0.45
deleteNoteMethod · 0.45
queryNotesMethod · 0.45
addNoteMethod · 0.45
appendNoteMethod · 0.45
readNoteMethod · 0.45
alterNoteMethod · 0.45
signalGuiMethod · 0.45

Calls 4

getTmpDirPathMethod · 0.80
openMethod · 0.80
getDbiDirPathMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected