| 265 | } |
| 266 | |
| 267 | void MainFrame::updateRepository(const QString &text) |
| 268 | { |
| 269 | if (!checkToolInstalled("ll-cli")) |
| 270 | return; |
| 271 | |
| 272 | d->repTable->clearContents(); |
| 273 | d->repTable->setRowCount(0); |
| 274 | |
| 275 | d->process.reset(new QProcess(this)); |
| 276 | d->process->setProgram("ll-cli"); |
| 277 | QStringList args; |
| 278 | args.append("search"); |
| 279 | args.append(text); |
| 280 | args.append("--json"); |
| 281 | d->process->setArguments(args); |
| 282 | |
| 283 | connect(d->process.get(), &QProcess::readyRead, this, [=]() { |
| 284 | auto data = d->process->readAll(); |
| 285 | |
| 286 | QJsonParseError error; |
| 287 | QJsonDocument jsonDocument = QJsonDocument::fromJson(data, &error); |
| 288 | |
| 289 | if (error.error != QJsonParseError::NoError) { |
| 290 | qCritical() << "JSON parse error: " << error.errorString(); |
| 291 | return; |
| 292 | } |
| 293 | |
| 294 | QJsonArray arr = jsonDocument.array(); |
| 295 | int row = 0; |
| 296 | for (auto line : arr) { |
| 297 | d->repTable->setRowCount(row + 1); |
| 298 | auto jsonObject = line.toObject(); |
| 299 | d->repTable->setItem(row, 0, new QTableWidgetItem(jsonObject["appid"].toString())); |
| 300 | d->repTable->setItem(row, 1, new QTableWidgetItem(jsonObject["name"].toString())); |
| 301 | d->repTable->setItem(row, 2, new QTableWidgetItem(jsonObject["version"].toString())); |
| 302 | d->repTable->setItem(row, 3, new QTableWidgetItem(jsonObject["arch"].toString())); |
| 303 | d->repTable->setItem(row, 4, new QTableWidgetItem(jsonObject["channel"].toString())); |
| 304 | d->repTable->setItem(row, 5, new QTableWidgetItem(jsonObject["module"].toString())); |
| 305 | d->repTable->setItem(row, 6, new QTableWidgetItem(jsonObject["description"].toString())); |
| 306 | row++; |
| 307 | } |
| 308 | }); |
| 309 | |
| 310 | d->process->start(); |
| 311 | d->process->waitForFinished(); |
| 312 | } |
| 313 | |
| 314 | void MainFrame::updateRunning() |
| 315 | { |
nothing calls this directly
no test coverage detected