Append text to a note via the command line.
| 459 | |
| 460 | // Append text to a note via the command line. |
| 461 | int CmdLineTool::appendNote(StartupConfig config) { |
| 462 | |
| 463 | // Windows Check |
| 464 | #ifndef _WIN32 |
| 465 | #ifdef Q_OS_WIN32 |
| 466 | _setmode(_fileno(stdin), _O_BINARY); |
| 467 | #endif |
| 468 | #endif // end windows check |
| 469 | |
| 470 | // If we are reding stdin |
| 471 | if (config.newNote->content == "") { |
| 472 | QByteArray content; |
| 473 | |
| 474 | while(!std::cin.eof()) { |
| 475 | char arr[1024]; |
| 476 | std::cin.read(arr,sizeof(arr)); |
| 477 | int s = std::cin.gcount(); |
| 478 | content.append(arr,s); |
| 479 | content.append("<br>"); |
| 480 | content.replace("\n","<br>"); |
| 481 | } |
| 482 | config.newNote->content = QString::fromAscii(content); |
| 483 | } |
| 484 | |
| 485 | if (!config.newNote->content.contains("<body")) { |
| 486 | config.newNote->content.prepend("<body>"); |
| 487 | } |
| 488 | if (!config.newNote->content.contains("</body")) { |
| 489 | config.newNote->content.append("</body>"); |
| 490 | } |
| 491 | |
| 492 | |
| 493 | EnmlFormatter formatter; |
| 494 | formatter.setHtml(config.newNote->content); |
| 495 | config.newNote->content = formatter.rebuildNoteEnml(); |
| 496 | |
| 497 | bool expectResponse = true; |
| 498 | |
| 499 | // Look to see if another NixNote is running. If so, then we |
| 500 | // expect a response of the LID created. First we detach it so |
| 501 | // we are not talking to ourselves. |
| 502 | global.sharedMemory->unlock(); |
| 503 | global.sharedMemory->detach(); |
| 504 | if (!global.sharedMemory->attach()) { |
| 505 | expectResponse = false; |
| 506 | } else { |
| 507 | global.sharedMemory->detach(); |
| 508 | } |
| 509 | if (expectResponse) { |
| 510 | NUuid uuid; |
| 511 | QString id = uuid.create(); |
| 512 | |
| 513 | // Setup cross memory for response |
| 514 | CrossMemoryMapper crossMemory(id); |
| 515 | if (!crossMemory.allocate(512)) |
| 516 | expectResponse = false; |
| 517 | |
| 518 | // Write out the segment |
no test coverage detected