| 367 | } |
| 368 | |
| 369 | bool CDatabase::ImportFromJsonFile(const QString &szFile) |
| 370 | { |
| 371 | bool bRet = false; |
| 372 | SetError(); |
| 373 | QFile file(szFile); |
| 374 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
| 375 | SetError(tr("Failed to open import JSON file: %1; Error: %2").arg(szFile, file.errorString())); |
| 376 | qCritical(log) << GetError(); |
| 377 | return false; |
| 378 | } |
| 379 | |
| 380 | do { |
| 381 | QJsonDocument doc; |
| 382 | doc = QJsonDocument::fromJson(file.readAll()); |
| 383 | if(!doc.isObject()) { |
| 384 | SetError(tr("Not a valid JSON file")); |
| 385 | qCritical(log) << GetError(); |
| 386 | break; |
| 387 | } |
| 388 | auto root = doc.object(); |
| 389 | QString szTitle = root["Title"].toString(); |
| 390 | if(szTitle != "Rabbit Remote Control") { |
| 391 | SetError(tr("File format error. The title: \"%1\" is not \"Rabbit Remote Control\"").arg(szTitle)); |
| 392 | qCritical(log) << GetError(); |
| 393 | break; |
| 394 | } |
| 395 | QString szVersion = root["Version"].toString(); |
| 396 | if(RabbitCommon::CTools::VersionCompare(szVersion, m_MinVersion) < 0) { |
| 397 | SetError(tr("The version is no longer supported: ") |
| 398 | + szVersion + " < " + m_MinVersion); |
| 399 | qCritical(log) << GetError(); |
| 400 | break; |
| 401 | } |
| 402 | bRet = ImportFromJson(doc.object()); |
| 403 | } while(0); |
| 404 | |
| 405 | file.close(); |
| 406 | return bRet; |
| 407 | } |
| 408 | |
| 409 | bool CDatabase::ImportFromJson(const QJsonObject &obj) |
| 410 | { |
no test coverage detected