Add a note via the command line. if Nixnote is running, the new note is copied into the dbi directory and auto-imported. If it is not running it is created directly.
| 239 | // the new note is copied into the dbi directory and |
| 240 | // auto-imported. If it is not running it is created directly. |
| 241 | int CmdLineTool::addNote(StartupConfig config) { |
| 242 | |
| 243 | // Windows Check |
| 244 | #ifndef _WIN32 |
| 245 | #ifdef Q_OS_WIN32 |
| 246 | _setmode(_fileno(stdin), _O_BINARY); |
| 247 | #endif |
| 248 | #endif // End windows check |
| 249 | |
| 250 | // If we are reding stdin |
| 251 | if (config.newNote->content == "") { |
| 252 | QByteArray content; |
| 253 | |
| 254 | while(!std::cin.eof()) { |
| 255 | char arr[1024]; |
| 256 | std::cin.read(arr,sizeof(arr)); |
| 257 | int s = std::cin.gcount(); |
| 258 | content.append(arr,s); |
| 259 | content.append("<br>"); |
| 260 | content.replace("\n","<br>"); |
| 261 | } |
| 262 | config.newNote->content = QString::fromAscii(content); |
| 263 | } |
| 264 | |
| 265 | if (!config.newNote->content.contains("<body")) { |
| 266 | config.newNote->content.prepend("<body>"); |
| 267 | } |
| 268 | if (!config.newNote->content.contains("</body")) { |
| 269 | config.newNote->content.append("</body>"); |
| 270 | } |
| 271 | |
| 272 | |
| 273 | EnmlFormatter formatter; |
| 274 | formatter.setHtml(config.newNote->content); |
| 275 | config.newNote->content = formatter.rebuildNoteEnml(); |
| 276 | |
| 277 | bool expectResponse = true; |
| 278 | |
| 279 | // Look to see if another NixNote is running. If so, then we |
| 280 | // expect a response of the LID created. First we detach it so |
| 281 | // we are not talking to ourselves. |
| 282 | global.sharedMemory->unlock(); |
| 283 | global.sharedMemory->detach(); |
| 284 | if (!global.sharedMemory->attach()) { |
| 285 | expectResponse = false; |
| 286 | } else { |
| 287 | global.sharedMemory->detach(); |
| 288 | } |
| 289 | if (expectResponse) { |
| 290 | NUuid uuid; |
| 291 | QString id = uuid.create(); |
| 292 | |
| 293 | // Setup cross memory for response |
| 294 | CrossMemoryMapper crossMemory(id); |
| 295 | if (!crossMemory.allocate(512)) |
| 296 | expectResponse = false; |
| 297 | |
| 298 | // Write out the segment |
no test coverage detected