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

Method queryNotes

cmdtools/cmdlinetool.cpp:183–235  ·  view source on GitHub ↗

Query notes via the command line

Source from the content-addressed store, hash-verified

181
182// Query notes via the command line
183int CmdLineTool::queryNotes(StartupConfig config) {
184 bool expectResponse = true;
185
186 // Look to see if another NixNote is running. If so, then we
187 // expect a response of the LID created. First we detach it so
188 // we are not talking to ourselves.
189 global.sharedMemory->unlock();
190 global.sharedMemory->detach();
191 if (!global.sharedMemory->attach()) {
192 expectResponse = false;
193 }
194 if (expectResponse) {
195 NUuid uuid;
196 config.queryNotes->returnUuid = uuid.create();
197 QString queryString = config.queryNotes->wrap();
198 global.sharedMemory->write("CMDLINE_QUERY:" + queryString);
199
200 int cnt = 0;
201 int maxWait=10;
202 QString tmpFile = global.fileManager.getTmpDirPath()+config.queryNotes->returnUuid+".txt";
203 QFile responseFile(tmpFile);
204 while (!responseFile.exists() && cnt<maxWait) {
205 sleep(1);
206 cnt++;
207 }
208 bool goodResponse = false;
209 if (responseFile.exists()) {
210 if (responseFile.open(QIODevice::ReadOnly)) {
211 QTextStream in(&responseFile);
212 while (!in.atEnd()) {
213 QString line = in.readLine();
214 std::cout << line.toStdString() << std::endl;
215 }
216 responseFile.close();
217 goodResponse = true;
218 }
219 }
220 if (!goodResponse)
221 std::cout << QString(tr("No response received from NixNote.")).toStdString() << std::endl;
222 } else {
223 // The other NixNote isn't found, so we do the query ourself
224 global.db = new DatabaseConnection("nixnote"); // Startup the database
225 FilterCriteria *filter = new FilterCriteria();
226 global.filterCriteria.append(filter);
227 global.filterPosition = 0;
228 FilterEngine engine;
229 filter->setSearchString(config.queryNotes->query);
230 QList<qint32> lids;
231 engine.filter(filter, &lids);
232 config.queryNotes->write(lids, "");
233 }
234 return 0;
235}
236
237
238// Add a note via the command line. if Nixnote is running,

Callers

nothing calls this directly

Calls 13

detachMethod · 0.80
attachMethod · 0.80
getTmpDirPathMethod · 0.80
openMethod · 0.80
setSearchStringMethod · 0.80
filterMethod · 0.80
QStringClass · 0.50
unlockMethod · 0.45
createMethod · 0.45
wrapMethod · 0.45
writeMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected