Delete a note via the command line
| 149 | |
| 150 | // Delete a note via the command line |
| 151 | int CmdLineTool::deleteNote(StartupConfig config) { |
| 152 | bool useCrossMemory = true; |
| 153 | |
| 154 | if (config.delNote->verifyDelete) { |
| 155 | std::string verify; |
| 156 | std::cout << QString(tr("Type DELETE to verify: ")).toStdString(); |
| 157 | std::cin >> verify; |
| 158 | QString qVerify = QString::fromStdString(verify); |
| 159 | if (qVerify.toLower() != "delete") |
| 160 | return 16; |
| 161 | } |
| 162 | |
| 163 | // Look to see if another NixNote is running. If so, then we |
| 164 | // expect a response if the note was delete. Otherwise, we |
| 165 | // do it ourself. |
| 166 | global.sharedMemory->unlock(); |
| 167 | global.sharedMemory->detach(); |
| 168 | if (!global.sharedMemory->attach()) { |
| 169 | useCrossMemory = false; |
| 170 | } |
| 171 | if (useCrossMemory) { |
| 172 | global.sharedMemory->write("DELETE_NOTE:" + QString::number(config.delNote->lid)); |
| 173 | } else { |
| 174 | global.db = new DatabaseConnection("nixnote"); // Startup the database |
| 175 | NoteTable noteTable(global.db); |
| 176 | noteTable.deleteNote(config.delNote->lid,true); |
| 177 | } |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | |
| 182 | // Query notes via the command line |